Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Gtk/GtkVersionTest/GtkVersionTest.java
47626 views
/*1* Copyright (c) 2018, 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* @bug 8156121 820031325* @summary "Fail forward" fails for GTK3 if no GTK2 available26* @modules java.desktop/sun.awt27* @requires (os.family == "linux")28* @run main GtkVersionTest29*/3031import sun.awt.UNIXToolkit;3233import java.awt.Toolkit;34import java.io.BufferedReader;35import java.io.InputStreamReader;3637public class GtkVersionTest {38public static class LoadGtk {39public static void main(String[] args) {40((UNIXToolkit)Toolkit.getDefaultToolkit()).loadGTK();41}42}4344public static void main(String[] args) throws Exception {45test(null, "3");46test("2", "2");47test("2.2", "2");48test("3", "3");49}5051private static void test(String version, String expect) throws Exception {52System.out.println( "Test " +53(version == null ? "no" : " GTK" + version) + " preference.");54System.out.println("java home "+System.getProperty("java.home"));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"-cp " + System.getProperty("java.class.path", ".") +60" GtkVersionTest$LoadGtk");61p.waitFor();6263try (BufferedReader br = new BufferedReader(64new InputStreamReader(p.getErrorStream()))) {65String line;66while ((line = br.readLine()) != null) {67System.out.println(line);68if (line.contains("Looking for GTK" + expect + " library")) {69return;70} else if (line.contains("Looking for GTK")) {71break;72}73}74throw new RuntimeException("Wrong GTK library version: expected: " + expect + " actual: " + line + " version: " + version);75}76}7778}798081