test/jdk/java/awt/Gtk/GtkVersionTest/GtkVersionTest.java
author serb
Fri, 16 Feb 2018 12:24:38 -0800
changeset 49090 82c1fe23c469
parent 47216 71c04702a3d5
child 50000 a4a0d0ece022
permissions -rw-r--r--
8196196: Headful tests should not be run in headless mode Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
49090
82c1fe23c469 8196196: Headful tests should not be run in headless mode
serb
parents: 47216
diff changeset
    25
 * @key headful
39033
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    26
 * @bug 8156121
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    27
 * @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
    28
 * @modules java.desktop/sun.awt
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    29
 * @requires (os.family == "linux")
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    30
 * @run main GtkVersionTest
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
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    33
import sun.awt.UNIXToolkit;
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    34
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    35
import java.awt.*;
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    36
import java.io.*;
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    37
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    38
public class GtkVersionTest {
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    39
    public static class LoadGtk {
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    40
        public static void main(String[] args) {
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    41
            ((UNIXToolkit)Toolkit.getDefaultToolkit()).loadGTK();
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
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    45
    public static void main(String[] args) throws Exception {
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    46
        test(null, "2");
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    47
        test("2", "2");
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    48
        test("2.2", "2");
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    49
        test("3", "3");
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
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    52
    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
    53
        System.out.println( "Test " +
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    54
                (version == null ? "no" : " GTK" + version) + " preference.");
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    55
        Process p = Runtime.getRuntime().exec(System.getProperty("java.home") +
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    56
                "/bin/java " +
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    57
                (version == null ? "" : "-Djdk.gtk.version=" + version) +
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    58
                " -Djdk.gtk.verbose=true " +
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 39033
diff changeset
    59
                "--add-exports=java.desktop/sun.awt=ALL-UNNAMED " +
39033
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    60
                "-cp " + System.getProperty("java.class.path", ".") +
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    61
                " GtkVersionTest$LoadGtk");
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    62
        p.waitFor();
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    63
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    64
        try (BufferedReader br = new BufferedReader(
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    65
                new InputStreamReader(p.getErrorStream()))) {
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    66
            String line;
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    67
            while ((line = br.readLine()) != null) {
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    68
                System.out.println(line);
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    69
                if (line.contains("Looking for GTK" + expect + " library")) {
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    70
                    return;
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    71
                } else if (line.contains("Looking for GTK")) {
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    72
                    break;
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
            }
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    75
            throw new RuntimeException("Wrong GTK library version: \n" + line);
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
d61135c3795c 8156121: "Fail forward" fails for GTK3 if no GTK2 available
ssadetsky
parents:
diff changeset
    79
}