Skip to content

Commit f56d98d

Browse files
committed
8328154: Convert sun/java2d/loops/CopyAreaSpeed.java applet test to main
Backport-of: 652fb3aa48fdfe09e827c2a06f76b3a69c711b74
1 parent 9c7ee11 commit f56d98d

File tree

2 files changed

+59
-223
lines changed

2 files changed

+59
-223
lines changed

test/jdk/sun/java2d/loops/CopyAreaSpeed.html

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 59 additions & 184 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2024, 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
@@ -20,53 +20,72 @@
2020
* or visit www.oracle.com if you need additional information or have any
2121
* questions.
2222
*/
23+
24+
import java.awt.Color;
25+
import java.awt.Container;
26+
import java.awt.Dimension;
27+
import java.awt.Graphics;
28+
import java.awt.Rectangle;
29+
import javax.swing.JFrame;
30+
import javax.swing.JOptionPane;
31+
32+
import java.util.Date;
33+
2334
/*
2435
* @test
2536
* @bug 4189070
2637
* @summary This test prints out the time it takes for a certain amount of
2738
* copyArea calls to be completed. Because the performance measurement is
2839
* relative, this code only provides a benchmark to run with different releases
2940
* to compare the outcomes.
30-
* @run applet/manual=done CopyAreaSpeed.html
41+
* @library /java/awt/regtesthelpers
42+
* @build PassFailJFrame
43+
* @run main/manual CopyAreaSpeed
3144
*/
3245

33-
import java.applet.Applet;
34-
import java.awt.*;
35-
import java.awt.event.*;
36-
import java.util.*;
37-
38-
public class CopyAreaSpeed extends Applet implements Runnable {
39-
int top = 0;
46+
public class CopyAreaSpeed {
47+
public static void main(String args[]) throws Exception {
48+
String instructions = """
49+
This test prints out the time it takes for a certain amount
50+
of copyArea calls to be completed. Because the performance
51+
measurement is relative, this code only provides a benchmark
52+
to run with different releases to compare the outcomes.
53+
""";
54+
55+
PassFailJFrame.builder()
56+
.title("Test Instructions")
57+
.instructions(instructions)
58+
.rows(5)
59+
.columns(35)
60+
.testUI(CopyAreaSpeed::initialize)
61+
.build()
62+
.awaitAndCheck();
63+
}
4064

41-
public void init() {
65+
public static JFrame initialize() {
66+
JFrame frame = new JFrame("Copy Area Test");
67+
frame.add(new CopyAreaSpeedTest());
68+
frame.setSize(300, 320);
69+
frame.setVisible(true);
70+
return frame;
4271
}
72+
}
73+
74+
class CopyAreaSpeedTest extends Container implements Runnable {
75+
int top = 0;
76+
public static String result;
4377

44-
public CopyAreaSpeed()
45-
{
78+
public CopyAreaSpeedTest() {
4679
super();
47-
String[] instructions =
48-
{
49-
"This test prints out the time it takes for a certain amount ",
50-
"of copyArea calls to be completed. Because the performance ",
51-
"measurement is relative, this code only provides a benchmark ",
52-
"to run with different releases to compare the outcomes."
53-
};
54-
Sysout.createDialogWithInstructions( instructions );
5580
(new Thread(this)).start();
56-
Button bt = new Button("Hello");
57-
bt.setBounds(50, 10, 50, 22);
58-
bt.setVisible(false);
59-
add(bt);
6081
}
6182

62-
public void update(Graphics g)
63-
{
83+
public void update(Graphics g) {
6484
paint(g);
6585
}
6686

67-
public void paint(Graphics g)
68-
{
69-
synchronized(this) {
87+
public void paint(Graphics g) {
88+
synchronized (this) {
7089
Rectangle rct = g.getClipBounds();
7190
g.setColor(Color.white);
7291
g.fillRect(rct.x, rct.y, rct.width, rct.height);
@@ -78,19 +97,18 @@ public void paint(Graphics g)
7897
if (y > rct.y) {
7998
int z = y / 20 + top;
8099
g.drawString("" + z, 10, y);
81-
} /* endif */
82-
} // endfor
100+
}
101+
}
83102
}
84103
}
85104

86105
static long millsec(Date s, Date e) {
87106
long ts = s.getTime();
88107
long te = e.getTime();
89-
return te-ts;
108+
return te - ts;
90109
}
91110

92-
public void run()
93-
{
111+
public void run() {
94112
int count = 1000;
95113
int loops = count;
96114
Date start;
@@ -100,7 +118,7 @@ public void run()
100118
while (count-- > 0) {
101119
Dimension dm = getSize();
102120
if (dm != null && dm.width != 0 && dm.height != 0) {
103-
synchronized(this) {
121+
synchronized (this) {
104122
top++;
105123
Graphics g = getGraphics();
106124
g.copyArea(0, 20, dm.width, dm.height - 20, 0, -20);
@@ -111,158 +129,15 @@ public void run()
111129
}
112130
try {
113131
Thread.sleep(1);
114-
} catch(Exception ex) {
132+
} catch (Exception ex) {
115133
ex.printStackTrace();
116134
}
117135
}
118136
end = new Date();
119-
Sysout.println("copyArea X "+loops+" = "+ millsec(start, end) + " msec");
120-
}
121-
122-
public static void main(String args[]) {
123-
Frame frm = new Frame("CopyAreaSpeed");
124-
frm.add(new CopyAreaSpeed());
125-
frm.addWindowListener(new WindowAdapter() {
126-
public void windowClosing(WindowEvent ev) {
127-
System.exit(0);
128-
}
129-
});
130-
frm.setSize(500, 500);
131-
frm.show();
137+
Graphics g = getGraphics();
138+
g.setFont(getFont());
139+
g.setColor(Color.black);
140+
result = "copyArea X " + loops + " = " + millsec(start, end) + " msec";
141+
JOptionPane.showMessageDialog(null, result);
132142
}
133143
}
134-
/****************************************************
135-
Standard Test Machinery
136-
DO NOT modify anything below -- it's a standard
137-
chunk of code whose purpose is to make user
138-
interaction uniform, and thereby make it simpler
139-
to read and understand someone else's test.
140-
****************************************************/
141-
142-
/**
143-
This is part of the standard test machinery.
144-
It creates a dialog (with the instructions), and is the interface
145-
for sending text messages to the user.
146-
To print the instructions, send an array of strings to Sysout.createDialog
147-
WithInstructions method. Put one line of instructions per array entry.
148-
To display a message for the tester to see, simply call Sysout.println
149-
with the string to be displayed.
150-
This mimics System.out.println but works within the test harness as well
151-
as standalone.
152-
*/
153-
class Sysout
154-
{
155-
private static TestDialog dialog;
156-
157-
public static void createDialogWithInstructions( String[] instructions )
158-
{
159-
dialog = new TestDialog( new Frame(), "Instructions" );
160-
dialog.printInstructions( instructions );
161-
dialog.show();
162-
println( "Any messages for the tester will display here." );
163-
}
164-
165-
public static void createDialog( )
166-
{
167-
dialog = new TestDialog( new Frame(), "Instructions" );
168-
String[] defInstr = { "Instructions will appear here. ", "" } ;
169-
dialog.printInstructions( defInstr );
170-
dialog.show();
171-
println( "Any messages for the tester will display here." );
172-
}
173-
174-
175-
public static void printInstructions( String[] instructions )
176-
{
177-
dialog.printInstructions( instructions );
178-
}
179-
180-
181-
public static void println( String messageIn )
182-
{
183-
dialog.displayMessage( messageIn );
184-
}
185-
186-
}// Sysout class
187-
188-
/**
189-
This is part of the standard test machinery. It provides a place for the
190-
test instructions to be displayed, and a place for interactive messages
191-
to the user to be displayed.
192-
To have the test instructions displayed, see Sysout.
193-
To have a message to the user be displayed, see Sysout.
194-
Do not call anything in this dialog directly.
195-
*/
196-
class TestDialog extends Dialog
197-
{
198-
199-
TextArea instructionsText;
200-
TextArea messageText;
201-
int maxStringLength = 80;
202-
203-
//DO NOT call this directly, go through Sysout
204-
public TestDialog( Frame frame, String name )
205-
{
206-
super( frame, name );
207-
int scrollBoth = TextArea.SCROLLBARS_BOTH;
208-
instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
209-
add( "North", instructionsText );
210-
211-
messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
212-
add("South", messageText);
213-
214-
pack();
215-
216-
show();
217-
}// TestDialog()
218-
219-
//DO NOT call this directly, go through Sysout
220-
public void printInstructions( String[] instructions )
221-
{
222-
//Clear out any current instructions
223-
instructionsText.setText( "" );
224-
225-
//Go down array of instruction strings
226-
227-
String printStr, remainingStr;
228-
for( int i=0; i < instructions.length; i++ )
229-
{
230-
//chop up each into pieces maxSringLength long
231-
remainingStr = instructions[ i ];
232-
while( remainingStr.length() > 0 )
233-
{
234-
//if longer than max then chop off first max chars to print
235-
if( remainingStr.length() >= maxStringLength )
236-
{
237-
//Try to chop on a word boundary
238-
int posOfSpace = remainingStr.
239-
lastIndexOf( ' ', maxStringLength - 1 );
240-
241-
if( posOfSpace <= 0 ) {
242-
posOfSpace = maxStringLength - 1;
243-
}
244-
245-
printStr = remainingStr.substring( 0, posOfSpace + 1 );
246-
remainingStr = remainingStr.substring( posOfSpace + 1 );
247-
}
248-
else //else just print
249-
{
250-
printStr = remainingStr;
251-
remainingStr = "";
252-
}
253-
254-
instructionsText.append( printStr + "\n" );
255-
256-
}// while
257-
258-
}// for
259-
260-
}//printInstructions()
261-
262-
//DO NOT call this directly, go through Sysout
263-
public void displayMessage( String messageIn )
264-
{
265-
messageText.append( messageIn + "\n" );
266-
}
267-
268-
}// TestDialog class

0 commit comments

Comments
 (0)