Skip to content

Commit 0680df7

Browse files
author
Satyen Subramaniam
committed
8340354: Open source AWT desktop properties and print related tests
Backport-of: 988f13a3875a6d29d7de07c5e97fcd6e7f9a31ff
1 parent b86d850 commit 0680df7

File tree

5 files changed

+1227
-0
lines changed

5 files changed

+1227
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
import java.awt.Frame;
25+
import java.awt.Toolkit;
26+
import java.beans.PropertyChangeEvent;
27+
import java.beans.PropertyChangeListener;
28+
29+
/*
30+
* @test
31+
* @bug 4808569
32+
* @requires (os.family == "windows")
33+
* @library /java/awt/regtesthelpers
34+
* @build PassFailJFrame
35+
* @summary add desktop property for the Windows XP or later font smoothing settings
36+
* @run main/manual FontSmoothing
37+
*/
38+
39+
public class FontSmoothing {
40+
41+
private static final String PROP_NAME = "win.text.fontSmoothingType";
42+
43+
public static void main(String[] args) throws Exception {
44+
String INSTRUCTIONS = """
45+
This test should be run on Windows XP or later.
46+
47+
On Windows 11:
48+
1. Open Run dialog by typing 'run' in search bar.
49+
2. Type 'cttune' and press Ok.
50+
3. Uncheck the "Turn On ClearType" checkbox and follow next instructions on screen.
51+
4. Repeat Step 1-2.
52+
5. Check the "Turn On ClearType" checkbox and follow next instructions on screen.
53+
6. Take a look at the output window to determine if the test passed or failed.
54+
""";
55+
56+
PassFailJFrame.builder()
57+
.title("FontSmoothing Test Instructions")
58+
.instructions(INSTRUCTIONS)
59+
.rows((int) INSTRUCTIONS.lines().count() + 2)
60+
.columns(40)
61+
.testTimeOut(5)
62+
.testUI(FontSmoothing::createUI)
63+
.logArea(8)
64+
.build()
65+
.awaitAndCheck();
66+
}
67+
68+
private static Frame createUI() {
69+
Frame f = new Frame("FontSmoothing Test");
70+
f.setSize(50, 50);
71+
72+
Object value = Toolkit.getDefaultToolkit().getDesktopProperty(PROP_NAME);
73+
PassFailJFrame.log("toolkit.getDesktopProperty: " + PROP_NAME + " = " + value + "\n");
74+
75+
Toolkit.getDefaultToolkit().addPropertyChangeListener(PROP_NAME, new PropertyChangeListener() {
76+
public void propertyChange(PropertyChangeEvent e) {
77+
PassFailJFrame.log("PropertyChangeEvent: " + e.getPropertyName() +
78+
"\n old value=" + e.getOldValue() +
79+
"\n new value=" + e.getNewValue());
80+
81+
Integer value = (Integer) Toolkit.getDefaultToolkit().getDesktopProperty(PROP_NAME);
82+
PassFailJFrame.log("toolkit.getDesktopProperty:" + PROP_NAME + "=" + value);
83+
84+
if (value.equals((Integer) e.getNewValue())) {
85+
PassFailJFrame.log("test PASSED");
86+
} else {
87+
PassFailJFrame.log("test FAILED");
88+
}
89+
}
90+
});
91+
return f;
92+
}
93+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
import java.awt.Color;
25+
import java.awt.Frame;
26+
import java.awt.Toolkit;
27+
import java.beans.PropertyChangeEvent;
28+
import java.beans.PropertyChangeListener;
29+
30+
/*
31+
* @test
32+
* @bug 4368193
33+
* @library /java/awt/regtesthelpers
34+
* @build PassFailJFrame
35+
* @requires (os.family == "windows")
36+
* @summary Toolkit's getDesktopProperty returns stale values on Microsoft Windows
37+
* @run main/manual ThreeDBackgroundColor
38+
*/
39+
40+
public class ThreeDBackgroundColor {
41+
42+
private static final String PROP_NAME = "win.3d.backgroundColor";
43+
44+
public static void main(String[] args) throws Exception {
45+
String INSTRUCTIONS = """
46+
On Windows 10:
47+
1. Open Windows Settings, in the search bar type
48+
'high contrast', in the list of suggestions choose option
49+
'Turn high contrast on or off'
50+
2. In the High contrast control panel click on the on/off switch
51+
to initialize High contrast mode
52+
3. Wait for the High contrast mode to finish initialization
53+
4. Click on the same switch again to turn off High contrast mode
54+
55+
On Windows 11:
56+
1. Open Windows settings, in the search bar type
57+
'Contrast Theme'.
58+
2. Select any value from 'Contrast themes' dropdown menu and press 'Apply'.
59+
3. Wait for the High contrast mode to finish initialization
60+
4. Select 'None' from 'Contrast themes' dropdown menu to revert the changes.
61+
62+
Take a look at the output window to determine if the test passed or failed.""";
63+
64+
PassFailJFrame.builder()
65+
.title("ThreeDBackgroundColor Test Instructions")
66+
.instructions(INSTRUCTIONS)
67+
.rows((int) INSTRUCTIONS.lines().count() + 2)
68+
.columns(40)
69+
.testTimeOut(5)
70+
.testUI(ThreeDBackgroundColor::createUI)
71+
.logArea(8)
72+
.build()
73+
.awaitAndCheck();
74+
}
75+
76+
private static Frame createUI() {
77+
Frame f = new Frame("ThreeDBackgroundColor Test");
78+
f.setSize(50, 50);
79+
80+
Object value = Toolkit.getDefaultToolkit().getDesktopProperty(PROP_NAME);
81+
PassFailJFrame.log("toolkit.getDesktopProperty:" + PROP_NAME + "=" + value);
82+
83+
Toolkit.getDefaultToolkit().addPropertyChangeListener(PROP_NAME, new PropertyChangeListener() {
84+
public void propertyChange(PropertyChangeEvent e) {
85+
PassFailJFrame.log("PropertyChangeEvent: " + e.getPropertyName() +
86+
"\n old value=" + e.getOldValue() +
87+
"\n new value=" + e.getNewValue());
88+
89+
Color value = (Color) Toolkit.getDefaultToolkit().getDesktopProperty(PROP_NAME);
90+
PassFailJFrame.log("toolkit.getDesktopProperty:" + PROP_NAME + "=" + value);
91+
if (value.equals((Color) e.getNewValue())) {
92+
PassFailJFrame.log("test PASSED");
93+
} else {
94+
PassFailJFrame.log("test FAILED");
95+
}
96+
}
97+
});
98+
return f;
99+
}
100+
}

0 commit comments

Comments
 (0)