Skip to content

Commit 7b07a2c

Browse files
committed
8343118: [TESTBUG] java/awt/PrintJob/PrintCheckboxTest/PrintCheckboxManualTest.java fails with rror. Can't find HTML file PrintCheckboxManualTest.html
Backport-of: f12c370d73363f384e3425857a663d855660f33a
1 parent 683a626 commit 7b07a2c

File tree

1 file changed

+62
-253
lines changed

1 file changed

+62
-253
lines changed
Lines changed: 62 additions & 253 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, 2007, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 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
@@ -22,84 +22,52 @@
2222
*/
2323

2424
/*
25-
@test
26-
@bug 5045936 5055171
27-
@summary Tests that there is no ClassCastException thrown in printing
28-
checkbox and scrollbar with XAWT
29-
@key printer
30-
@run applet/manual=yesno PrintCheckboxManualTest.html
31-
*/
32-
33-
// Note there is no @ in front of test above. This is so that the
34-
// harness will not mistake this file as a test file. It should
35-
// only see the html file as a test file. (the harness runs all
36-
// valid test files, so it would run this test twice if this file
37-
// were valid as well as the html file.)
38-
// Also, note the area= after Your Name in the author tag. Here, you
39-
// should put which functional area the test falls in. See the
40-
// AWT-core home page -> test areas and/or -> AWT team for a list of
41-
// areas.
42-
43-
44-
45-
import java.awt.*;
46-
import java.awt.event.*;
47-
48-
49-
//Manual tests should run as applet tests if possible because they
50-
// get their environments cleaned up, including AWT threads, any
51-
// test created threads, and any system resources used by the test
52-
// such as file descriptors. (This is normally not a problem as
53-
// main tests usually run in a separate VM, however on some platforms
54-
// such as the Mac, separate VMs are not possible and non-applet
55-
// tests will cause problems). Also, you don't have to worry about
56-
// synchronisation stuff in Applet tests the way you do in main
57-
// tests...
58-
59-
60-
public class PrintCheckboxManualTest extends Panel
61-
{
62-
//Declare things used in the test, like buttons and labels here
63-
Frame f;
64-
65-
public static void main(String[] args) {
66-
PrintCheckboxManualTest a = new PrintCheckboxManualTest();
25+
* @test
26+
* @bug 5045936 5055171
27+
* @summary Tests that there is no ClassCastException thrown in printing
28+
* checkbox and scrollbar with XAWT
29+
* @key printer
30+
* @requires (os.family == "linux")
31+
* @library /java/awt/regtesthelpers
32+
* @build PassFailJFrame
33+
* @run main/manual PrintCheckboxManualTest
34+
*/
6735

68-
a.init();
69-
a.start();
36+
import java.awt.Button;
37+
import java.awt.Checkbox;
38+
import java.awt.Frame;
39+
import java.awt.Graphics;
40+
import java.awt.GridLayout;
41+
import java.awt.Panel;
42+
import java.awt.PrintJob;
43+
import java.awt.Scrollbar;
44+
import java.awt.Toolkit;
45+
import java.awt.event.ActionEvent;
46+
import java.awt.event.ActionListener;
47+
48+
public class PrintCheckboxManualTest extends Panel {
49+
50+
private static final String INSTRUCTIONS = """
51+
This test is for Linux with XToolkit ONLY!,
52+
1. Click the 'Print' button on the frame
53+
2. Select a printer in the print dialog and proceed
54+
3. If the frame with checkbox and button on it
55+
is printed without any exception test PASSED else FAILED.
56+
""";
57+
58+
public static void main(String[] args) throws Exception {
59+
PassFailJFrame.builder()
60+
.title("Instructions")
61+
.instructions(INSTRUCTIONS)
62+
.columns(40)
63+
.testUI(PrintCheckboxManualTest::createTestUI)
64+
.build()
65+
.awaitAndCheck();
7066
}
7167

72-
public void init()
73-
{
74-
//Create instructions for the user here, as well as set up
75-
// the environment -- set the layout manager, add buttons,
76-
// etc.
77-
this.setLayout (new BorderLayout ());
78-
79-
String[] instructions =
80-
{
81-
"Linux or Solaris with XToolkit ONLY!",
82-
"1. Click the 'Print' button on the frame",
83-
"2. Select a printer in the print dialog and proceed",
84-
"3. If the frame with checkbox and button on it is printed successfully test PASSED else FAILED"
85-
};
86-
Sysout.createDialogWithInstructions( instructions );
87-
88-
}//End init()
68+
private static Frame createTestUI() {
8969

90-
public void start ()
91-
{
92-
//Get things going. Request focus, set size, et cetera
93-
setSize (200,200);
94-
setVisible(true);
95-
validate();
96-
97-
//What would normally go into main() will probably go here.
98-
//Use System.out.println for diagnostic messages that you want
99-
// to read after the test is done.
100-
//Use Sysout.println for messages you want the tester to read.
101-
102-
f = new Frame("Print checkbox");
70+
Frame f = new Frame("Print checkbox");
10371
f.setLayout(new GridLayout(2, 2));
10472
f.setSize(200, 100);
10573

@@ -111,185 +79,26 @@ public void start ()
11179
f.add(sb);
11280

11381
Button b = new Button("Print");
114-
b.addActionListener(new ActionListener()
115-
{
116-
public void actionPerformed(ActionEvent ev)
117-
{
118-
PrintJob pj = Toolkit.getDefaultToolkit().getPrintJob(f, "PrintCheckboxManualTest", null);
119-
if (pj != null)
120-
{
121-
try
122-
{
123-
Graphics g = pj.getGraphics();
124-
f.printAll(g);
125-
g.dispose();
126-
pj.end();
127-
Sysout.println("Test PASSED");
128-
}
129-
catch (ClassCastException cce)
130-
{
131-
Sysout.println("Test FAILED: ClassCastException");
132-
// throw new RuntimeException("Test FAILED: ClassCastException", cce);
133-
}
134-
catch (Exception e)
135-
{
136-
Sysout.println("Test FAILED: unknown Exception");
137-
// throw new Error("Test FAILED: unknown exception", e);
138-
}
82+
b.addActionListener(new ActionListener() {
83+
public void actionPerformed(ActionEvent ev) {
84+
PrintJob pj = Toolkit.getDefaultToolkit().
85+
getPrintJob(f, "PrintCheckboxManualTest",
86+
null);
87+
if (pj != null) {
88+
try {
89+
Graphics g = pj.getGraphics();
90+
f.printAll(g);
91+
g.dispose();
92+
pj.end();
93+
} catch (ClassCastException cce) {
94+
throw new RuntimeException("Test FAILED: ClassCastException", cce);
95+
} catch (Exception e) {
96+
throw new Error("Test FAILED: unknown exception", e);
97+
}
13998
}
140-
}
99+
}
141100
});
142101
f.add(b);
143-
144-
f.setVisible(true);
145-
}// start()
146-
147-
//The rest of this class is the actions which perform the test...
148-
149-
//Use Sysout.println to communicate with the user NOT System.out!!
150-
//Sysout.println ("Something Happened!");
151-
152-
}
153-
154-
/* Place other classes related to the test after this line */
155-
156-
157-
158-
159-
160-
/****************************************************
161-
Standard Test Machinery
162-
DO NOT modify anything below -- it's a standard
163-
chunk of code whose purpose is to make user
164-
interaction uniform, and thereby make it simpler
165-
to read and understand someone else's test.
166-
****************************************************/
167-
168-
/**
169-
This is part of the standard test machinery.
170-
It creates a dialog (with the instructions), and is the interface
171-
for sending text messages to the user.
172-
To print the instructions, send an array of strings to Sysout.createDialog
173-
WithInstructions method. Put one line of instructions per array entry.
174-
To display a message for the tester to see, simply call Sysout.println
175-
with the string to be displayed.
176-
This mimics System.out.println but works within the test harness as well
177-
as standalone.
178-
*/
179-
180-
class Sysout
181-
{
182-
private static TestDialog dialog;
183-
184-
public static void createDialogWithInstructions( String[] instructions )
185-
{
186-
dialog = new TestDialog( new Frame(), "Instructions" );
187-
dialog.printInstructions( instructions );
188-
dialog.setVisible(true);
189-
println( "Any messages for the tester will display here." );
102+
return f;
190103
}
191-
192-
public static void createDialog( )
193-
{
194-
dialog = new TestDialog( new Frame(), "Instructions" );
195-
String[] defInstr = { "Instructions will appear here. ", "" } ;
196-
dialog.printInstructions( defInstr );
197-
dialog.setVisible(true);
198-
println( "Any messages for the tester will display here." );
199-
}
200-
201-
202-
public static void printInstructions( String[] instructions )
203-
{
204-
dialog.printInstructions( instructions );
205-
}
206-
207-
208-
public static void println( String messageIn )
209-
{
210-
dialog.displayMessage( messageIn );
211-
}
212-
213-
}// Sysout class
214-
215-
/**
216-
This is part of the standard test machinery. It provides a place for the
217-
test instructions to be displayed, and a place for interactive messages
218-
to the user to be displayed.
219-
To have the test instructions displayed, see Sysout.
220-
To have a message to the user be displayed, see Sysout.
221-
Do not call anything in this dialog directly.
222-
*/
223-
class TestDialog extends Dialog
224-
{
225-
226-
TextArea instructionsText;
227-
TextArea messageText;
228-
int maxStringLength = 80;
229-
230-
//DO NOT call this directly, go through Sysout
231-
public TestDialog( Frame frame, String name )
232-
{
233-
super( frame, name );
234-
int scrollBoth = TextArea.SCROLLBARS_BOTH;
235-
instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
236-
add( "North", instructionsText );
237-
238-
messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
239-
add("Center", messageText);
240-
241-
pack();
242-
243-
setVisible(true);
244-
}// TestDialog()
245-
246-
//DO NOT call this directly, go through Sysout
247-
public void printInstructions( String[] instructions )
248-
{
249-
//Clear out any current instructions
250-
instructionsText.setText( "" );
251-
252-
//Go down array of instruction strings
253-
254-
String printStr, remainingStr;
255-
for( int i=0; i < instructions.length; i++ )
256-
{
257-
//chop up each into pieces maxSringLength long
258-
remainingStr = instructions[ i ];
259-
while( remainingStr.length() > 0 )
260-
{
261-
//if longer than max then chop off first max chars to print
262-
if( remainingStr.length() >= maxStringLength )
263-
{
264-
//Try to chop on a word boundary
265-
int posOfSpace = remainingStr.
266-
lastIndexOf( ' ', maxStringLength - 1 );
267-
268-
if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
269-
270-
printStr = remainingStr.substring( 0, posOfSpace + 1 );
271-
remainingStr = remainingStr.substring( posOfSpace + 1 );
272-
}
273-
//else just print
274-
else
275-
{
276-
printStr = remainingStr;
277-
remainingStr = "";
278-
}
279-
280-
instructionsText.append( printStr + "\n" );
281-
282-
}// while
283-
284-
}// for
285-
286-
}//printInstructions()
287-
288-
//DO NOT call this directly, go through Sysout
289-
public void displayMessage( String messageIn )
290-
{
291-
messageText.append( messageIn + "\n" );
292-
System.out.println(messageIn);
293-
}
294-
295-
}// TestDialog class
104+
}

0 commit comments

Comments
 (0)