Skip to content

Commit dafa2e5

Browse files
committed
8343124: Tests fails with java.lang.IllegalAccessException: class com.sun.javatest.regtest.agent.MainWrapper$MainTask cannot access
Reviewed-by: abhiscxk
1 parent 0f7dd98 commit dafa2e5

File tree

2 files changed

+169
-162
lines changed

2 files changed

+169
-162
lines changed

Diff for: test/jdk/java/awt/print/Dialog/PrintDlgPageable.java

+77-84
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, 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
@@ -25,105 +25,98 @@
2525
* @test
2626
* @bug 4869502 4869539
2727
* @key printer
28-
* @summary Confirm that ToPage is populated for argument =2. Range is disabled for argument = 0.
29-
* @run main/manual PrintDlgPageable
28+
* @summary Confirm that ToPage is populated for argument = 2. Range is disabled for argument = 0.
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual PrintDlgPageable 0
32+
* @run main/manual PrintDlgPageable 2
3033
*/
31-
import java.awt.*;
32-
import java.awt.print.*;
33-
import java.util.Locale;
3434

35-
import javax.print.*;
35+
import java.awt.Color;
36+
import java.awt.Graphics;
37+
import java.awt.Graphics2D;
38+
import java.awt.print.PageFormat;
39+
import java.awt.print.Pageable;
40+
import java.awt.print.Printable;
41+
import java.awt.print.PrinterJob;
42+
import java.awt.print.PrinterException;
43+
44+
public class PrintDlgPageable implements Printable {
3645

37-
class PrintDlgPageable implements Printable {
3846
public static int arg;
39-
/**
40-
* Constructor
41-
*/
42-
public PrintDlgPageable() {
43-
super();
47+
public PrintDlgPageable() {
48+
super();
49+
}
50+
51+
public static void main(String[] args) throws Exception {
52+
if (args.length < 1) {
53+
System.out.println("usage: java PrintDlgPageable { 0 | 2}");
54+
return;
4455
}
45-
/**
46-
* Starts the application.
47-
*/
48-
public static void main(java.lang.String[] args) {
49-
if (args.length < 1) {
50-
System.out.println("usage: java PrintDlgPageable { 0 | 2}");
51-
return;
52-
}
53-
arg = Integer.parseInt(args[0]);
54-
PrintDlgPageable pd = new PrintDlgPageable();
55-
PrinterJob pj = PrinterJob.getPrinterJob();
56-
PageableHandler handler = new PageableHandler();
57-
pj.setPageable(handler);
58-
59-
System.out.println("open PrintDialog..");
60-
if (pj.printDialog()) {
61-
try {
62-
System.out.println("About to print the data ...");
63-
pj.print();
64-
System.out.println("Printed");
65-
}
66-
catch (PrinterException pe) {
67-
pe.printStackTrace();
68-
}
69-
}
56+
arg = Integer.parseInt(args[0]);
7057

58+
String INSTRUCTIONS = " A pagedialog will be shown.";
59+
60+
if (arg == 0) {
61+
INSTRUCTIONS += "\n Confirm that page range is disabled.";
62+
} else if (arg == 2) {
63+
INSTRUCTIONS += "\n Confirm ToPage is populated with pagerange 2";
7164
}
65+
INSTRUCTIONS += "\nCancel the print dialog. Press PASS if it so seen else press FAIL.";
66+
67+
PrinterJob pj = PrinterJob.getPrinterJob();
68+
PageableHandler handler = new PageableHandler();
69+
pj.setPageable(handler);
70+
71+
PassFailJFrame passFailJFrame = PassFailJFrame.builder()
72+
.title("Instructions")
73+
.instructions(INSTRUCTIONS)
74+
.columns(35)
75+
.build();
7276

73-
//printable interface
74-
public int print(Graphics g, PageFormat pf, int pi) throws
75-
PrinterException {
76-
77-
/*if (pi > 0) {
78-
System.out.println("pi is greater than 0");
79-
return Printable.NO_SUCH_PAGE;
80-
}*/
81-
// Simply draw two rectangles
82-
Graphics2D g2 = (Graphics2D)g;
83-
g2.setColor(Color.black);
84-
g2.translate(pf.getImageableX(), pf.getImageableY());
85-
g2.drawRect(1,1,200,300);
86-
g2.drawRect(1,1,25,25);
87-
System.out.println("print method called "+pi + " Orientation "+pf.getOrientation());
88-
return Printable.PAGE_EXISTS;
77+
if (pj.printDialog()) {
78+
try {
79+
pj.print();
80+
} catch (PrinterException pe) {
81+
pe.printStackTrace();
82+
}
8983
}
84+
passFailJFrame.awaitAndCheck();
85+
}
86+
87+
//printable interface
88+
public int print(Graphics g, PageFormat pf, int pi) throws PrinterException {
89+
90+
// Simply draw two rectangles
91+
Graphics2D g2 = (Graphics2D) g;
92+
g2.setColor(Color.black);
93+
g2.translate(pf.getImageableX(), pf.getImageableY());
94+
g2.drawRect(1, 1, 200, 300);
95+
g2.drawRect(1, 1, 25, 25);
96+
return Printable.PAGE_EXISTS;
97+
}
9098
}
9199

92100
class PageableHandler implements Pageable {
93101

94-
PageFormat pf = new PageFormat();
102+
PageFormat pf = new PageFormat();
95103

96-
public int getNumberOfPages() {
97-
return PrintDlgPageable.arg;
98-
//return 0;
99-
}
104+
public int getNumberOfPages() {
105+
return PrintDlgPageable.arg;
106+
}
100107

101-
public Printable getPrintable(int pageIndex) {
102-
return new PrintDlgPageable();
103-
}
108+
public Printable getPrintable(int pageIndex) {
109+
return new PrintDlgPageable();
110+
}
104111

105-
public PageFormat getPageFormat(int pageIndex) {
106-
System.out.println("getPageFormat called "+pageIndex);
107-
if (pageIndex == 0) {
108-
pf.setOrientation(PageFormat.PORTRAIT);
109-
System.out.println("Orientation returned from Pageable "+findOrientation(pf.getOrientation()));
110-
return pf;
111-
} else {
112-
pf.setOrientation(PageFormat.LANDSCAPE);
113-
System.out.println("Orientation returned from Pageable "+findOrientation(pf.getOrientation()));
114-
return pf;
115-
}
112+
public PageFormat getPageFormat(int pageIndex) {
113+
if (pageIndex == 0) {
114+
pf.setOrientation(PageFormat.PORTRAIT);
115+
return pf;
116+
} else {
117+
pf.setOrientation(PageFormat.LANDSCAPE);
118+
return pf;
116119
}
120+
}
117121

118-
public String findOrientation(int orient) {
119-
if (orient == PageFormat.LANDSCAPE) {
120-
return "LANDSCAPE";
121-
}else if (orient == PageFormat.PORTRAIT) {
122-
return "PORTRAIT";
123-
} else if (orient == PageFormat.REVERSE_LANDSCAPE) {
124-
return "REVERSE LANDSCAPE";
125-
} else {
126-
return null;
127-
}
128-
}
129122
}

Diff for: test/jdk/javax/print/StreamPrintingOrientation.java

+92-78
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 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
@@ -24,95 +24,109 @@
2424
/*
2525
* @test
2626
* @bug 4904236
27-
* @summary You would see a cross-platform print dialog being popped up. Check whether orientation is shown as LANDSCAPE. Click 'OK'. 'streamexample.ps' will be created in the same dir where this application was executed. Pass if the orientation in the ps file is landscape.
28-
* @run main/manual StreamPrintingOrientation
27+
* @key printer
28+
* @summary StreamPrintService ignores the PrintReqAttrSet when printing through 2D Printing
29+
* @run main StreamPrintingOrientation
2930
*/
3031

31-
import java.awt.*;
32-
import java.awt.print.*;
33-
import javax.print.*;
34-
import javax.print.attribute.standard.*;
35-
import javax.print.attribute.*;
36-
import java.io.FileOutputStream;
3732
import java.io.File;
38-
import java.util.Locale;
33+
import java.io.FileOutputStream;
34+
import java.nio.file.Files;
35+
36+
import java.awt.Color;
37+
import java.awt.Graphics;
38+
import java.awt.Graphics2D;
39+
import java.awt.print.PageFormat;
40+
import java.awt.print.Printable;
41+
import java.awt.print.PrinterException;
42+
import java.awt.print.PrinterJob;
43+
import javax.print.attribute.Attribute;
44+
import javax.print.PrintService;
45+
import javax.print.StreamPrintServiceFactory;
46+
import javax.print.attribute.standard.Copies;
47+
import javax.print.attribute.standard.JobName;
48+
import javax.print.attribute.standard.OrientationRequested;
49+
import javax.print.attribute.HashPrintRequestAttributeSet;
50+
51+
public class StreamPrintingOrientation implements Printable {
52+
53+
public static void main(String[] args) throws Exception {
54+
StreamPrintingOrientation pd = new StreamPrintingOrientation();
55+
PrinterJob pj = PrinterJob.getPrinterJob();
56+
HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet();
57+
PrintService service = null;
58+
59+
FileOutputStream fos = null;
60+
String mType = "application/postscript";
3961

40-
class StreamPrintingOrientation implements Printable {
41-
/**
42-
* Constructor
43-
*/
44-
public StreamPrintingOrientation() {
45-
super();
62+
File fl = new File("stream_landscape.ps");
63+
fl.deleteOnExit();
64+
fos = new FileOutputStream(fl);
65+
StreamPrintServiceFactory[] factories = PrinterJob.lookupStreamPrintServices(mType);
66+
if (factories.length > 0) {
67+
service = factories[0].getPrintService(fos);
4668
}
47-
/**
48-
* Starts the application.
49-
*/
50-
public static void main(java.lang.String[] args) {
51-
StreamPrintingOrientation pd = new StreamPrintingOrientation();
52-
PrinterJob pj = PrinterJob.getPrinterJob();
53-
HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet();
54-
PrintService service = null;
5569

56-
FileOutputStream fos = null;
57-
File f = null, f1 = null;
58-
String mType = "application/postscript";
70+
if (service != null) {
71+
System.out.println("Stream Print Service " + service);
72+
pj.setPrintService(service);
73+
} else {
74+
throw new RuntimeException("No stream Print Service available.");
75+
}
76+
77+
pj.setPrintable(pd);
78+
prSet.add(OrientationRequested.LANDSCAPE);
79+
prSet.add(new Copies(1));
80+
prSet.add(new JobName("orientation test", null));
81+
System.out.println("open PrintDialog..");
5982

60-
try {
61-
f = new File("streamexample.ps");
62-
fos = new FileOutputStream(f);
63-
StreamPrintServiceFactory[] factories = PrinterJob.lookupStreamPrintServices(mType);
64-
if (factories.length > 0)
65-
service = factories[0].getPrintService(fos);
83+
System.out.println("\nValues in attr set passed to print method");
84+
Attribute attr[] = prSet.toArray();
85+
for (int x = 0; x < attr.length; x++) {
86+
System.out.println("Name " + attr[x].getName() + " " + attr[x]);
87+
}
88+
System.out.println("About to print the data ...");
89+
if (service != null) {
90+
System.out.println("TEST: calling Print");
91+
pj.print(prSet);
92+
System.out.println("TEST: Printed");
93+
}
6694

67-
if (service != null) {
68-
System.out.println("Stream Print Service "+service);
69-
pj.setPrintService(service);
70-
} else {
71-
throw new RuntimeException("No stream Print Service available.");
72-
}
73-
} catch (Exception e) {
74-
e.printStackTrace();
75-
}
95+
File fp = new File("stream_portrait.ps");
96+
fp.deleteOnExit();
97+
fos = new FileOutputStream(fp);
98+
if (factories.length > 0) {
99+
service = factories[0].getPrintService(fos);
100+
}
76101

77-
pj.setPrintable(pd);
78-
prSet.add(OrientationRequested.LANDSCAPE);
79-
prSet.add(new Copies(3));
80-
prSet.add(new JobName("orientation test", null));
81-
System.out.println("open PrintDialog..");
82-
if (pj.printDialog(prSet)) {
83-
try {
84-
System.out.println("\nValues in attr set passed to print method");
85-
Attribute attr[] = prSet.toArray();
86-
for (int x = 0; x < attr.length; x ++) {
87-
System.out.println("Name "+attr[x].getName()+" "+attr[x]);
88-
}
89-
System.out.println("About to print the data ...");
90-
if (service != null) {
91-
System.out.println("TEST: calling Print");
92-
pj.print(prSet);
93-
System.out.println("TEST: Printed");
94-
}
95-
}
96-
catch (PrinterException pe) {
97-
pe.printStackTrace();
98-
}
99-
}
102+
pj.setPrintService(service);
103+
pj.setPrintable(pd);
104+
prSet.add(OrientationRequested.PORTRAIT);
105+
prSet.add(new Copies(1));
106+
prSet.add(new JobName("orientation test", null));
107+
if (service != null) {
108+
pj.print(prSet);
109+
}
100110

111+
if (Files.mismatch(fl.toPath(), fp.toPath()) == -1) {
112+
throw new RuntimeException("Printing stream orientation is same " +
113+
"for both PORTRAIT and LANDSCAPE");
101114
}
115+
}
102116

103-
//printable interface
104-
public int print(Graphics g, PageFormat pf, int pi) throws PrinterException {
117+
//printable interface
118+
public int print(Graphics g, PageFormat pf, int pi) throws PrinterException {
105119

106-
if (pi > 0) {
107-
return Printable.NO_SUCH_PAGE;
108-
}
109-
// Simply draw two rectangles
110-
Graphics2D g2 = (Graphics2D)g;
111-
g2.setColor(Color.black);
112-
g2.translate(pf.getImageableX(), pf.getImageableY());
113-
System.out.println("StreamPrinting Test Width "+pf.getWidth()+" Height "+pf.getHeight());
114-
g2.drawRect(1,1,200,300);
115-
g2.drawRect(1,1,25,25);
116-
return Printable.PAGE_EXISTS;
120+
if (pi > 0) {
121+
return Printable.NO_SUCH_PAGE;
117122
}
123+
// Simply draw two rectangles
124+
Graphics2D g2 = (Graphics2D) g;
125+
g2.setColor(Color.black);
126+
g2.translate(pf.getImageableX(), pf.getImageableY());
127+
System.out.println("StreamPrinting Test Width " + pf.getWidth() + " Height " + pf.getHeight());
128+
g2.drawRect(1, 1, 200, 300);
129+
g2.drawRect(1, 1, 25, 25);
130+
return Printable.PAGE_EXISTS;
131+
}
118132
}

0 commit comments

Comments
 (0)