|
1 | 1 | /* |
2 | | - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
22 | 22 | */ |
23 | 23 |
|
24 | 24 | /* |
25 | | - * test |
| 25 | + * @test |
26 | 26 | * @bug 6282388 |
27 | | - * @summary Tests that AWT use correct toolkit to be wrapped into HeadlessToolkit |
28 | | - * @author artem.ananiev@sun.com: area=awt.headless |
29 | | - * @run shell WrappedToolkitTest.sh |
| 27 | + * @summary Tests that AWT uses correct toolkit wrapped into HeadlessToolkit |
| 28 | + * @modules java.desktop/sun.awt:open |
| 29 | + * @library /test/lib |
| 30 | + * @run main/othervm -Djava.awt.headless=true TestWrapped |
30 | 31 | */ |
31 | 32 |
|
32 | | -import java.awt.*; |
| 33 | +import java.awt.Toolkit; |
| 34 | +import java.lang.Class; |
| 35 | +import java.lang.reflect.Field; |
33 | 36 |
|
34 | | -import java.lang.reflect.*; |
| 37 | +import jdk.test.lib.Platform; |
35 | 38 |
|
36 | | -import sun.awt.*; |
| 39 | +public final class TestWrapped { |
37 | 40 |
|
38 | | -public class TestWrapped |
39 | | -{ |
40 | | - public static void main(String[] args) |
41 | | - { |
42 | | - try |
43 | | - { |
44 | | - if (args.length != 1) { |
45 | | - System.err.println("No correct toolkit class name is specified, test is not run"); |
46 | | - System.exit(0); |
| 41 | + private static final String HEADLESS_TOOLKIT = "sun.awt.HeadlessToolkit"; |
| 42 | + private static final String MACOSX_TOOLKIT = "sun.lwawt.macosx.LWCToolkit"; |
| 43 | + private static final String UNIX_TOOLKIT = "sun.awt.X11.XToolkit"; |
| 44 | + private static final String WINDOWS_TOOLKIT = "sun.awt.windows.WToolkit"; |
| 45 | + |
| 46 | + public static void main(String[] args) throws Exception { |
| 47 | + String expectedToolkitClassName; |
| 48 | + if (Platform.isWindows()) { |
| 49 | + expectedToolkitClassName = WINDOWS_TOOLKIT; |
| 50 | + } else if (Platform.isOSX()) { |
| 51 | + expectedToolkitClassName = MACOSX_TOOLKIT; |
| 52 | + } else { |
| 53 | + expectedToolkitClassName = UNIX_TOOLKIT; |
47 | 54 | } |
48 | 55 |
|
49 | | - String correctToolkitClassName = args[0]; |
50 | 56 | Toolkit tk = Toolkit.getDefaultToolkit(); |
51 | | - Class tkClass = tk.getClass(); |
52 | | - if (!tkClass.getName().equals("sun.awt.HeadlessToolkit")) |
53 | | - { |
54 | | - System.err.println(tkClass.getName()); |
55 | | - System.err.println("Error: default toolkit is not an instance of HeadlessToolkit"); |
56 | | - System.exit(-1); |
| 57 | + Class<?> tkClass = tk.getClass(); |
| 58 | + if (!tkClass.getName().equals(HEADLESS_TOOLKIT)) { |
| 59 | + System.err.println("Expected: " + HEADLESS_TOOLKIT); |
| 60 | + System.err.println("Actual: " + tkClass.getName()); |
| 61 | + throw new RuntimeException("Wrong default toolkit"); |
57 | 62 | } |
58 | 63 |
|
59 | 64 | Field f = tkClass.getDeclaredField("tk"); |
60 | 65 | f.setAccessible(true); |
61 | | - Class wrappedClass = f.get(tk).getClass(); |
62 | | - if (!wrappedClass.getName().equals(correctToolkitClassName)) { |
63 | | - System.err.println(wrappedClass.getName()); |
64 | | - System.err.println("Error: wrapped toolkit is not an instance of " + correctToolkitClassName); |
65 | | - System.exit(-1); |
66 | | - } |
| 66 | + Class<?> wrappedClass = f.get(tk).getClass(); |
| 67 | + if (!wrappedClass.getName().equals(expectedToolkitClassName)) { |
| 68 | + System.err.println("Expected: " + expectedToolkitClassName); |
| 69 | + System.err.println("Actual: " + wrappedClass.getName()); |
| 70 | + throw new RuntimeException("Wrong wrapped toolkit"); |
67 | 71 | } |
68 | | - catch (Exception z) |
69 | | - { |
70 | | - z.printStackTrace(System.err); |
71 | | - System.exit(-1); |
72 | | - } |
73 | | - |
74 | | - System.exit(0); |
75 | 72 | } |
76 | 73 | } |
0 commit comments