Skip to content

Commit e107179

Browse files
committed
8367017: Remove legacy checks from WrappedToolkitTest and convert from bash
Reviewed-by: prr
1 parent b75e35c commit e107179

File tree

2 files changed

+34
-258
lines changed

2 files changed

+34
-258
lines changed
Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,55 +22,52 @@
2222
*/
2323

2424
/*
25-
* test
25+
* @test
2626
* @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
3031
*/
3132

32-
import java.awt.*;
33+
import java.awt.Toolkit;
34+
import java.lang.Class;
35+
import java.lang.reflect.Field;
3336

34-
import java.lang.reflect.*;
37+
import jdk.test.lib.Platform;
3538

36-
import sun.awt.*;
39+
public final class TestWrapped {
3740

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;
4754
}
4855

49-
String correctToolkitClassName = args[0];
5056
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");
5762
}
5863

5964
Field f = tkClass.getDeclaredField("tk");
6065
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");
6771
}
68-
catch (Exception z)
69-
{
70-
z.printStackTrace(System.err);
71-
System.exit(-1);
72-
}
73-
74-
System.exit(0);
7572
}
7673
}

test/jdk/java/awt/Toolkit/Headless/WrappedToolkitTest/WrappedToolkitTest.sh

Lines changed: 0 additions & 221 deletions
This file was deleted.

0 commit comments

Comments
 (0)