author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 40261 | jdk/test/java/awt/Gtk/GtkVersionTest/GtkVersionTest.java@86a49ba76f52 |
child 49090 | 82c1fe23c469 |
permissions | -rw-r--r-- |
39033
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
1 |
/* |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
4 |
* |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
8 |
* |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
13 |
* accompanied this code). |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
14 |
* |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
18 |
* |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
21 |
* questions. |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
22 |
*/ |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
23 |
|
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
24 |
/* @test |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
25 |
* @bug 8156121 |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
26 |
* @summary "Fail forward" fails for GTK3 if no GTK2 available |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
27 |
* @modules java.desktop/sun.awt |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
28 |
* @requires (os.family == "linux") |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
29 |
* @run main GtkVersionTest |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
30 |
*/ |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
31 |
|
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
32 |
import sun.awt.UNIXToolkit; |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
33 |
|
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
34 |
import java.awt.*; |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
35 |
import java.io.*; |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
36 |
|
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
37 |
public class GtkVersionTest { |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
38 |
public static class LoadGtk { |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
39 |
public static void main(String[] args) { |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
40 |
((UNIXToolkit)Toolkit.getDefaultToolkit()).loadGTK(); |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
41 |
} |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
42 |
} |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
43 |
|
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
44 |
public static void main(String[] args) throws Exception { |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
45 |
test(null, "2"); |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
46 |
test("2", "2"); |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
47 |
test("2.2", "2"); |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
48 |
test("3", "3"); |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
49 |
} |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
50 |
|
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
51 |
private static void test(String version, String expect) throws Exception { |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
52 |
System.out.println( "Test " + |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
53 |
(version == null ? "no" : " GTK" + version) + " preference."); |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
54 |
Process p = Runtime.getRuntime().exec(System.getProperty("java.home") + |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
55 |
"/bin/java " + |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
56 |
(version == null ? "" : "-Djdk.gtk.version=" + version) + |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
57 |
" -Djdk.gtk.verbose=true " + |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
39033
diff
changeset
|
58 |
"--add-exports=java.desktop/sun.awt=ALL-UNNAMED " + |
39033
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
59 |
"-cp " + System.getProperty("java.class.path", ".") + |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
60 |
" GtkVersionTest$LoadGtk"); |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
61 |
p.waitFor(); |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
62 |
|
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
63 |
try (BufferedReader br = new BufferedReader( |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
64 |
new InputStreamReader(p.getErrorStream()))) { |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
65 |
String line; |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
66 |
while ((line = br.readLine()) != null) { |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
67 |
System.out.println(line); |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
68 |
if (line.contains("Looking for GTK" + expect + " library")) { |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
69 |
return; |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
70 |
} else if (line.contains("Looking for GTK")) { |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
71 |
break; |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
72 |
} |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
73 |
} |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
74 |
throw new RuntimeException("Wrong GTK library version: \n" + line); |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
75 |
} |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
76 |
} |
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
77 |
|
d61135c3795c
8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff
changeset
|
78 |
} |