GtkVersionTest.java revision 15333:28e938880be3
1193323Sed/*
2193323Sed * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3193323Sed * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4193323Sed *
5193323Sed * This code is free software; you can redistribute it and/or modify it
6193323Sed * under the terms of the GNU General Public License version 2 only, as
7193323Sed * published by the Free Software Foundation.
8193323Sed *
9193323Sed * This code is distributed in the hope that it will be useful, but WITHOUT
10193323Sed * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11193323Sed * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12193323Sed * version 2 for more details (a copy is included in the LICENSE file that
13193323Sed * accompanied this code).
14193323Sed *
15193323Sed * You should have received a copy of the GNU General Public License version
16193323Sed * 2 along with this work; if not, write to the Free Software Foundation,
17218893Sdim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18193323Sed *
19249423Sdim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20249423Sdim * or visit www.oracle.com if you need additional information or have any
21249423Sdim * questions.
22249423Sdim */
23193323Sed
24193323Sed/* @test
25193323Sed * @bug 8156121
26193323Sed * @summary "Fail forward" fails for GTK3 if no GTK2 available
27193323Sed * @modules java.desktop/sun.awt
28193323Sed * @requires (os.family == "linux")
29193323Sed * @run main GtkVersionTest
30193323Sed */
31193323Sed
32193323Sedimport sun.awt.UNIXToolkit;
33193323Sed
34193323Sedimport java.awt.*;
35193323Sedimport java.io.*;
36193323Sed
37193323Sedpublic class GtkVersionTest {
38193323Sed    public static class LoadGtk {
39206083Srdivacky        public static void main(String[] args) {
40206083Srdivacky            ((UNIXToolkit)Toolkit.getDefaultToolkit()).loadGTK();
41206083Srdivacky        }
42206083Srdivacky    }
43193323Sed
44206083Srdivacky    public static void main(String[] args) throws Exception {
45206083Srdivacky        test(null, "2");
46206083Srdivacky        test("2", "2");
47206083Srdivacky        test("2.2", "2");
48193323Sed        test("3", "3");
49206083Srdivacky    }
50206083Srdivacky
51206083Srdivacky    private static void test(String version, String expect) throws Exception {
52193323Sed        System.out.println( "Test " +
53206083Srdivacky                (version == null ? "no" : " GTK" + version) + " preference.");
54206083Srdivacky        Process p = Runtime.getRuntime().exec(System.getProperty("java.home") +
55206083Srdivacky                "/bin/java " +
56193323Sed                (version == null ? "" : "-Djdk.gtk.version=" + version) +
57193323Sed                " -Djdk.gtk.verbose=true " +
58234353Sdim                "--add-exports=java.desktop/sun.awt=ALL-UNNAMED " +
59234353Sdim                "-cp " + System.getProperty("java.class.path", ".") +
60234353Sdim                " GtkVersionTest$LoadGtk");
61234353Sdim        p.waitFor();
62234353Sdim
63234353Sdim        try (BufferedReader br = new BufferedReader(
64234353Sdim                new InputStreamReader(p.getErrorStream()))) {
65206083Srdivacky            String line;
66198090Srdivacky            while ((line = br.readLine()) != null) {
67206083Srdivacky                System.out.println(line);
68249423Sdim                if (line.contains("Looking for GTK" + expect + " library")) {
69198090Srdivacky                    return;
70206083Srdivacky                } else if (line.contains("Looking for GTK")) {
71206083Srdivacky                    break;
72206083Srdivacky                }
73206083Srdivacky            }
74206083Srdivacky            throw new RuntimeException("Wrong GTK library version: \n" + line);
75206083Srdivacky        }
76206083Srdivacky    }
77206083Srdivacky
78206083Srdivacky}
79206083Srdivacky