Skip to content

Commit 0829225

Browse files
committed
8202836: [macosx] test java/awt/Graphics/TextAAHintsTest.java fails
Backport-of: f399ae558eabdce8960d339ef0758c023aeb89cc
1 parent c9a36b2 commit 0829225

File tree

1 file changed

+110
-22
lines changed

1 file changed

+110
-22
lines changed

test/jdk/java/awt/Graphics/TextAAHintsTest.java

Lines changed: 110 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2022, 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
@@ -21,21 +21,44 @@
2121
* questions.
2222
*/
2323

24-
/**
24+
/*
2525
* @test
2626
* @bug 6263951
2727
* @summary Text should be B&W, grayscale, and LCD.
28-
* @run main/manual=yesno TextAAHintsTest
28+
* @requires (os.family != "mac")
29+
* @run main/manual TextAAHintsTest
2930
*/
30-
import java.awt.*;
31-
import java.awt.geom.*;
32-
import java.awt.image.*;
31+
32+
import java.awt.AWTException;
33+
import java.awt.BorderLayout;
34+
import java.awt.Button;
35+
import java.awt.Color;
36+
import java.awt.Component;
37+
import java.awt.Dialog;
38+
import java.awt.Dimension;
39+
import java.awt.EventQueue;
40+
import java.awt.Frame;
41+
import java.awt.Graphics;
42+
import java.awt.Graphics2D;
43+
import java.awt.ImageCapabilities;
44+
import java.awt.Panel;
45+
import java.awt.RenderingHints;
46+
import java.awt.TextArea;
47+
import java.awt.image.BufferedImage;
48+
import java.awt.image.VolatileImage;
49+
import java.lang.reflect.InvocationTargetException;
50+
import java.util.concurrent.CountDownLatch;
51+
import java.util.concurrent.TimeUnit;
3352

3453
public class TextAAHintsTest extends Component {
3554

36-
String black = "This text should be solid black";
37-
String gray = "This text should be gray scale anti-aliased";
38-
String lcd = "This text should be LCD sub-pixel text (coloured).";
55+
private static final String black = "This text should be solid black";
56+
private static final String gray = "This text should be gray scale anti-aliased";
57+
private static final String lcd = "This text should be LCD sub-pixel text (coloured).";
58+
private static final CountDownLatch countDownLatch = new CountDownLatch(1);
59+
private static volatile String failureReason;
60+
private static volatile boolean testPassed = false;
61+
private static Frame frame;
3962

4063
public void paint(Graphics g) {
4164

@@ -63,28 +86,24 @@ private void drawText(Graphics g) {
6386
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
6487
g2d.drawString(black, 10, 20);
6588

66-
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
67-
RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
68-
g2d.drawString(black, 10, 35);
69-
7089
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
7190
RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
72-
g2d.drawString(gray, 10, 50);
91+
g2d.drawString(gray, 10, 35);
7392

7493
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
7594
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
76-
g2d.drawString(gray, 10, 65);
95+
g2d.drawString(gray, 10, 50);
7796

7897
/* For visual comparison, render grayscale with graphics AA off */
7998
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
8099
RenderingHints.VALUE_ANTIALIAS_OFF);
81-
g2d.drawString(gray, 10, 80);
100+
g2d.drawString(gray, 10, 65);
82101
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
83102
RenderingHints.VALUE_ANTIALIAS_ON);
84103

85104
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
86105
RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
87-
g2d.drawString(lcd, 10, 95);
106+
g2d.drawString(lcd, 10, 80);
88107
}
89108

90109
public void bufferedImageText(Graphics g) {
@@ -139,11 +158,80 @@ public Dimension getPreferredSize() {
139158
return new Dimension(500,300);
140159
}
141160

142-
public static void main(String[] args) throws Exception {
161+
public static void createTestUI() {
162+
frame = new Frame("Composite and Text Test");
163+
TextAAHintsTest textAAHintsTestObject = new TextAAHintsTest();
164+
frame.add(textAAHintsTestObject, BorderLayout.NORTH);
165+
166+
String instructions = """
167+
Note: Texts are rendered with different TEXT_ANTIALIASING &
168+
VALUE_TEXT_ANTIALIAS. Text should be B&W, grayscale, and LCD.
169+
Note: The results may be visually the same.
170+
1. Verify that first set of text are rendered correctly.
171+
2. Second set of text are created using BufferedImage of the first text.
172+
3. Third set of text are created using VolatileImage of the first text.
173+
""";
174+
TextArea instructionTextArea = new TextArea(instructions, 8, 50);
175+
instructionTextArea.setEditable(false);
176+
frame.add(instructionTextArea, BorderLayout.CENTER);
177+
178+
Panel controlPanel = new Panel();
179+
Button passButton = new Button("Pass");
180+
passButton.addActionListener(e -> {
181+
testPassed = true;
182+
countDownLatch.countDown();
183+
frame.dispose();
184+
});
185+
Button failButton = new Button("Fail");
186+
failButton.addActionListener(e -> {
187+
getFailureReason();
188+
testPassed = false;
189+
countDownLatch.countDown();
190+
frame.dispose();
191+
});
192+
controlPanel.add(passButton);
193+
controlPanel.add(failButton);
194+
frame.add(controlPanel, BorderLayout.SOUTH);
195+
frame.pack();
196+
frame.setLocationRelativeTo(null);
197+
frame.setVisible(true);
198+
}
199+
200+
public static void getFailureReason() {
201+
// Show dialog to read why the testcase was failed and append the
202+
// testcase failure reason to the output
203+
final Dialog dialog = new Dialog(frame, "TestCase" +
204+
" failure reason", true);
205+
TextArea textArea = new TextArea("", 5, 60, TextArea.SCROLLBARS_BOTH);
206+
dialog.add(textArea, BorderLayout.CENTER);
207+
208+
Button okButton = new Button("OK");
209+
okButton.addActionListener(e1 -> {
210+
failureReason = textArea.getText();
211+
dialog.dispose();
212+
});
213+
Panel ctlPanel = new Panel();
214+
ctlPanel.add(okButton);
215+
dialog.add(ctlPanel, BorderLayout.SOUTH);
216+
dialog.setLocationRelativeTo(null);
217+
dialog.pack();
218+
dialog.setVisible(true);
219+
}
220+
221+
public static void main(String[] args) throws InterruptedException, InvocationTargetException {
222+
EventQueue.invokeAndWait(TextAAHintsTest::createTestUI);
223+
if (!countDownLatch.await(2, TimeUnit.MINUTES)) {
224+
EventQueue.invokeAndWait(() -> {
225+
if (frame != null) {
226+
frame.dispose();
227+
}
228+
});
229+
throw new RuntimeException("Timeout : No action was taken on the test.");
230+
}
143231

144-
Frame f = new Frame("Composite and Text Test");
145-
f.add(new TextAAHintsTest(), BorderLayout.CENTER);
146-
f.pack();
147-
f.setVisible(true);
232+
if (!testPassed) {
233+
throw new RuntimeException("Test failed : Reason : " + failureReason);
234+
}
148235
}
149236
}
237+

0 commit comments

Comments
 (0)