Path: blob/master/test/jdk/java/awt/Gtk/GtkVersionTest/GtkVersionTest.java
41153 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @key headful25* @bug 8156121 820031326* @summary "Fail forward" fails for GTK3 if no GTK2 available27* @modules java.desktop/sun.awt28* @requires (os.family == "linux")29* @run main GtkVersionTest30*/3132import sun.awt.UNIXToolkit;3334import java.awt.Toolkit;35import java.io.BufferedReader;36import java.io.InputStreamReader;3738public class GtkVersionTest {39public static class LoadGtk {40public static void main(String[] args) {41((UNIXToolkit)Toolkit.getDefaultToolkit()).loadGTK();42}43}4445public static void main(String[] args) throws Exception {46test(null, "3");47test("2", "2");48test("2.2", "2");49test("3", "3");50}5152private static void test(String version, String expect) throws Exception {53System.out.println( "Test " +54(version == null ? "no" : " GTK" + version) + " preference.");55Process p = Runtime.getRuntime().exec(System.getProperty("java.home") +56"/bin/java " +57(version == null ? "" : "-Djdk.gtk.version=" + version) +58" -Djdk.gtk.verbose=true " +59"--add-exports=java.desktop/sun.awt=ALL-UNNAMED " +60"-cp " + System.getProperty("java.class.path", ".") +61" GtkVersionTest$LoadGtk");62p.waitFor();6364try (BufferedReader br = new BufferedReader(65new InputStreamReader(p.getErrorStream()))) {66String line;67while ((line = br.readLine()) != null) {68System.out.println(line);69if (line.contains("Looking for GTK" + expect + " library")) {70return;71} else if (line.contains("Looking for GTK")) {72break;73}74}75throw new RuntimeException("Wrong GTK library version: \n" + line);76}77}7879}808182