Skip to content

Commit ffcb158

Browse files
anass-bayaSendaoYan
authored andcommitted
8320677: Printer tests use invalid '@run main/manual=yesno
Reviewed-by: aivanov, dnguyen
1 parent 3e20a93 commit ffcb158

File tree

2 files changed

+66
-174
lines changed

2 files changed

+66
-174
lines changed
Lines changed: 33 additions & 28 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, 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
@@ -21,58 +21,63 @@
2121
* questions.
2222
*/
2323

24-
/**
24+
/*
2525
* @test
2626
* @bug 6575331
2727
* @key printer
2828
* @summary The specified pages should be printed.
29-
* @run main/manual=yesno PageRanges
29+
* @library /java/awt/regtesthelpers
30+
* @library /test/lib
31+
* @build PassFailJFrame
32+
* @build jtreg.SkippedException
33+
* @run main/manual PageRanges
3034
*/
3135

32-
import java.awt.*;
33-
import java.awt.print.*;
36+
import java.awt.Graphics;
37+
import java.awt.print.PageFormat;
38+
import java.awt.print.Printable;
39+
import java.awt.print.PrinterException;
40+
import java.awt.print.PrinterJob;
41+
import jtreg.SkippedException;
3442

3543
public class PageRanges implements Printable {
36-
37-
static String[] instr = {
38-
"This test prints two jobs, and tests that the specified range",
39-
"of pages is printed. You must have a printer installed for this test.",
40-
"In the first dialog, select a page range of 2 to 3, and press OK",
41-
"In the second dialog, select ALL, to print all pages (in total 5 pages).",
42-
"Collect the two print outs and confirm the jobs printed correctly",
43-
};
44+
private static final String INSTRUCTIONS = """
45+
This test prints two jobs and tests that the specified range
46+
of pages is printed.
47+
In the first dialog, select a page range of 2 to 3, and press OK.
48+
In the second dialog, select ALL, to print all pages (in total 5 pages).
49+
Collect the two print outs and confirm the jobs are printed correctly.
50+
""";
4451

4552
public static void main(String args[]) throws Exception {
46-
for (int i=0;i<instr.length;i++) {
47-
System.out.println(instr[i]);
48-
}
4953
PrinterJob job = PrinterJob.getPrinterJob();
5054
if (job.getPrintService() == null) {
51-
System.out.println("No printers. Test cannot continue.");
52-
return;
55+
throw new SkippedException("Printer not configured or available.");
5356
}
57+
58+
PassFailJFrame passFailJFrame = PassFailJFrame.builder()
59+
.instructions(INSTRUCTIONS)
60+
.columns(45)
61+
.build();
62+
5463
job.setPrintable(new PageRanges());
55-
if (!job.printDialog()) {
56-
return;
64+
if (job.printDialog()) {
65+
job.print();
5766
}
58-
job.print();
59-
if (!job.printDialog()) {
60-
return;
67+
if (job.printDialog()) {
68+
job.print();
6169
}
62-
job.print();
6370

64-
return;
71+
passFailJFrame.awaitAndCheck();
6572
}
6673

6774
public int print(Graphics g, PageFormat pf, int pi)
68-
throws PrinterException {
69-
75+
throws PrinterException {
7076
if (pi >= 5) {
7177
return NO_SUCH_PAGE;
7278
}
7379

7480
g.drawString("Page : " + (pi+1), 200, 200);
75-
7681
return PAGE_EXISTS;
7782
}
7883
}
Lines changed: 33 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 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
@@ -21,31 +21,56 @@
2121
* questions.
2222
*/
2323

24-
/**
24+
/*
25+
* @test
2526
* @bug 8041902
2627
* @key printer
2728
* @summary Test printing of wide poly lines.
28-
* @run main/manual=yesno PolylinePrintingTest
29+
* @library /java/awt/regtesthelpers
30+
* @library /test/lib
31+
* @build PassFailJFrame
32+
* @build jtreg.SkippedException
33+
* @run main/manual PolylinePrintingTest
2934
*/
3035

31-
import java.awt.Dialog;
32-
import java.awt.Frame;
33-
import java.awt.TextArea;
3436
import java.awt.BasicStroke;
3537
import java.awt.Graphics;
3638
import java.awt.Graphics2D;
3739
import java.awt.geom.Path2D;
3840
import java.awt.print.PageFormat;
39-
import java.awt.print.Paper;
4041
import java.awt.print.Printable;
4142
import java.awt.print.PrinterException;
4243
import java.awt.print.PrinterJob;
44+
import jtreg.SkippedException;
4345

4446
public class PolylinePrintingTest implements Printable {
47+
private static final String INSTRUCTIONS = """
48+
Press OK in the print dialog and collect the printed page.
49+
Passing test : Output should show two identical chevrons.
50+
Failing test : The line joins will appear different.
51+
""";
52+
53+
public static void main(String[] args) throws Exception {
54+
PrinterJob job = PrinterJob.getPrinterJob();
55+
if (job.getPrintService() == null) {
56+
throw new SkippedException("Printer not configured or available.");
57+
}
58+
59+
PassFailJFrame passFailJFrame = PassFailJFrame.builder()
60+
.instructions(INSTRUCTIONS)
61+
.columns(45)
62+
.build();
63+
64+
job.setPrintable(new PolylinePrintingTest());
65+
if (job.printDialog()) {
66+
job.print();
67+
}
68+
69+
passFailJFrame.awaitAndCheck();
70+
}
4571

4672
public int print(Graphics graphics, PageFormat pageFormat,
4773
int pageIndex) throws PrinterException {
48-
4974
if (pageIndex > 0) {
5075
return NO_SUCH_PAGE;
5176
}
@@ -66,7 +91,6 @@ public int print(Graphics graphics, PageFormat pageFormat,
6691

6792
private void drawPolylineGOOD(Graphics2D g2d,
6893
int[] x2Points, int[] y2Points) {
69-
7094
Path2D polyline =
7195
new Path2D.Float(Path2D.WIND_EVEN_ODD, x2Points.length);
7296

@@ -83,141 +107,4 @@ private void drawPolylineBAD(Graphics2D g, int[] xp, int[] yp) {
83107
g.translate(0, offset);
84108
g.drawPolyline(xp, yp, xp.length);
85109
}
86-
87-
public PolylinePrintingTest() throws PrinterException {
88-
PrinterJob job = PrinterJob.getPrinterJob();
89-
PageFormat pf = job.defaultPage();
90-
Paper p = pf.getPaper();
91-
p.setImageableArea(0,0,p.getWidth(), p.getHeight());
92-
pf.setPaper(p);
93-
job.setPrintable(this, pf);
94-
if (job.printDialog()) {
95-
job.print();
96-
}
97-
}
98-
99-
public static void main(String[] args) throws PrinterException {
100-
String[] instructions = {
101-
"You must have a printer available to perform this test.",
102-
"OK the print dialog, and collect the printed page.",
103-
"Passing test : Output should show two identical chevrons.",
104-
"Failing test : The line joins will appear different."
105-
};
106-
Sysout.createDialog();
107-
Sysout.printInstructions(instructions);
108-
new PolylinePrintingTest();
109-
}
110110
}
111-
112-
class Sysout {
113-
private static TestDialog dialog;
114-
115-
public static void createDialogWithInstructions( String[] instructions )
116-
{
117-
dialog = new TestDialog( new Frame(), "Instructions" );
118-
dialog.printInstructions( instructions );
119-
dialog.show();
120-
println( "Any messages for the tester will display here." );
121-
}
122-
123-
public static void createDialog( )
124-
{
125-
dialog = new TestDialog( new Frame(), "Instructions" );
126-
String[] defInstr = { "Instructions will appear here. ", "" } ;
127-
dialog.printInstructions( defInstr );
128-
dialog.show();
129-
println( "Any messages for the tester will display here." );
130-
}
131-
132-
133-
public static void printInstructions( String[] instructions )
134-
{
135-
dialog.printInstructions( instructions );
136-
}
137-
138-
139-
public static void println( String messageIn )
140-
{
141-
dialog.displayMessage( messageIn );
142-
}
143-
144-
}// Sysout class
145-
146-
/**
147-
This is part of the standard test machinery. It provides a place for the
148-
test instructions to be displayed, and a place for interactive messages
149-
to the user to be displayed.
150-
To have the test instructions displayed, see Sysout.
151-
To have a message to the user be displayed, see Sysout.
152-
Do not call anything in this dialog directly.
153-
*/
154-
class TestDialog extends Dialog {
155-
TextArea instructionsText;
156-
TextArea messageText;
157-
int maxStringLength = 80;
158-
159-
//DO NOT call this directly, go through Sysout
160-
public TestDialog( Frame frame, String name )
161-
{
162-
super( frame, name );
163-
int scrollBoth = TextArea.SCROLLBARS_BOTH;
164-
instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
165-
add( "North", instructionsText );
166-
167-
messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
168-
add("Center", messageText);
169-
170-
pack();
171-
172-
show();
173-
}// TestDialog()
174-
175-
//DO NOT call this directly, go through Sysout
176-
public void printInstructions( String[] instructions )
177-
{
178-
//Clear out any current instructions
179-
instructionsText.setText( "" );
180-
181-
//Go down array of instruction strings
182-
183-
String printStr, remainingStr;
184-
for( int i=0; i < instructions.length; i++ )
185-
{
186-
//chop up each into pieces maxSringLength long
187-
remainingStr = instructions[ i ];
188-
while( remainingStr.length() > 0 )
189-
{
190-
//if longer than max then chop off first max chars to print
191-
if( remainingStr.length() >= maxStringLength )
192-
{
193-
//Try to chop on a word boundary
194-
int posOfSpace = remainingStr.
195-
lastIndexOf( ' ', maxStringLength - 1 );
196-
if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
197-
198-
printStr = remainingStr.substring( 0, posOfSpace + 1 );
199-
remainingStr = remainingStr.substring( posOfSpace + 1 );
200-
}
201-
//else just print
202-
else
203-
{
204-
printStr = remainingStr;
205-
remainingStr = "";
206-
}
207-
208-
instructionsText.append( printStr + "\n" );
209-
210-
}// while
211-
212-
}// for
213-
214-
}//printInstructions()
215-
216-
//DO NOT call this directly, go through Sysout
217-
public void displayMessage( String messageIn )
218-
{
219-
messageText.append( messageIn + "\n" );
220-
}
221-
222-
}// TestDialog class
223-

0 commit comments

Comments
 (0)