-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8316412: javax/print tests fail without printer set up #15821
Conversation
For NullClipARGB we are throwing SkippedException only if instance of caught exception is PrinterException. All other exceptions are considered unrelated to printer configuration. For CountPrintServices we want to throw SkippedException in the case when lpstat is not installed, where an IOException is caught in that case. For ExceptionTest we want to throw SkippedException for all PrinterExceptions which were not caused by IndexOutOfBoundsException. For rest of the tests if PrintService was not created instead RuntimeException we are throwing now SkippedException. Tested on environment without printer installed. Test are passing with skipped exception as expected. Passed: java/awt/print/PrinterJob/ExceptionTest.java Passed: java/awt/print/PrinterJob/ImagePrinting/NullClipARGB.java Passed: java/awt/print/PrinterJob/PrtException.java Passed: javax/print/attribute/AttributeTest.java Passed: javax/print/attribute/GetCopiesSupported.java Passed: javax/print/attribute/SidesPageRangesTest.java Passed: javax/print/attribute/SupportedPrintableAreas.java Passed: javax/print/PrintServiceLookup/CountPrintServices.java Passed: javax/print/CheckDupFlavor.java
Hi @msobiers, welcome to this OpenJDK project and thanks for contributing! We do not recognize you as Contributor and need to ensure you have signed the Oracle Contributor Agreement (OCA). If you have not signed the OCA, please follow the instructions. Please fill in your GitHub username in the "Username" field of the application. Once you have signed the OCA, please let us know by writing If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please use "Add GitHub user msobiers" as summary for the issue. If you are contributing this work on behalf of your employer and your employer has signed the OCA, please let us know by writing |
/covered |
Thank you! Please allow for a few business days to verify that your employer has signed the OCA. Also, please note that pull requests that are pending an OCA check will not usually be evaluated, so your patience is appreciated! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The copyright years need to be adjusted a bit.
Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
...should become:
Copyright (c) 2007, 2023, Oracle and/or its affiliates. All rights reserved.
throw new RuntimeException(ex); | ||
} catch (Exception ex) { | ||
if (ex instanceof PrinterException) { | ||
throw new SkippedException("Printer is required for this test. TEST ABORTED"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for this test, we need to check PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);
, like other tests do it. Let's not assume that PrinterException
is thrown here only when printer is not configured. Add the block right at the beginning of main
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from stylistic comments, this looks good.
} | ||
} | ||
|
||
public int print(Graphics g, PageFormat pf, int pageIndex) | ||
throws PrinterException{ | ||
throws PrinterException{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant whitespace change.
@@ -59,7 +68,7 @@ public int print(Graphics g, PageFormat pf, int pageIndex) | |||
g2.setColor( Color.BLACK ); | |||
g2.drawString("This text should be visible through the image", 0, 20); | |||
BufferedImage bi = new BufferedImage(100, 100, | |||
BufferedImage.TYPE_INT_ARGB ); | |||
BufferedImage.TYPE_INT_ARGB ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant whitespace change.
|
||
public class NullClipARGB implements Printable { | ||
|
||
public static void main( String[] args ) { | ||
PrintService[] svc = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to ask for DocFlavor.SERVICE_FORMATTED.PRINTABLE
here? Can we just ask for null
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct me if I'm wrong, but I think if we ask for null here it may find a PrintService that does not support PRINTABLE flavor so SkippedException will not be thrown because svc.length will be greater than 0 and we may end up with an exception thrown later in pj.print().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, OK. So the idea is that if we use setPrintable
, we need to lookup the service that accepts .PRINTABLE
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is my understanding.
|
||
try { | ||
PrinterJob pj = PrinterJob.getPrinterJob(); | ||
pj.setPrintable(new NullClipARGB()); | ||
pj.print(); | ||
} catch (Exception ex) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this is a cleanup, but we don't need to do it here, to keep patch simple and backportable.
* @run main CheckDupFlavor | ||
*/ | ||
|
||
import javax.print.*; | ||
import javax.print.attribute.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and later, keep the imports in place, for the same reason: targeted backportable patch.
|
||
try { | ||
PrinterJob pj = PrinterJob.getPrinterJob(); | ||
pj.setPrintable(new NullClipARGB()); | ||
pj.print(); | ||
} catch (Exception ex) { | ||
throw new RuntimeException(ex); | ||
throw new RuntimeException(ex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more redundant whitespace change.
} | ||
} | ||
|
||
public int print(Graphics g, PageFormat pf, int pageIndex) | ||
throws PrinterException{ | ||
throws PrinterException{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more redundant whitespace change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Once OCA clears, someone familiar with this area would need to take a look too.
/reviewers 2
Just like jtreg -k:!printer ... In other words none of these changes should be necessary and I'm fairly sure are actually undesirable in some cases. |
Right! Argh, I missed that the tests have keywords on them. I think we can close this as WNF, @msobiers. Sorry for leading you the wrong way here. |
Np. Closing now. |
For NullClipARGB we are throwing SkippedException only if instance of caught exception is PrinterException. All other exceptions are considered unrelated to printer configuration.
For CountPrintServices we want to throw SkippedException in the case when lpstat is not installed, where an IOException is caught in that case.
For ExceptionTest we want to throw SkippedException for all PrinterExceptions which were not caused by IndexOutOfBoundsException.
For rest of the tests if PrintService was not created instead RuntimeException we are throwing now SkippedException.
Tested on environment without printer installed.
Test are passing with skipped exception as expected.
Passed: java/awt/print/PrinterJob/ExceptionTest.java
Passed: java/awt/print/PrinterJob/ImagePrinting/NullClipARGB.java
Passed: java/awt/print/PrinterJob/PrtException.java
Passed: javax/print/attribute/AttributeTest.java
Passed: javax/print/attribute/GetCopiesSupported.java
Passed: javax/print/attribute/SidesPageRangesTest.java
Passed: javax/print/attribute/SupportedPrintableAreas.java
Passed: javax/print/PrintServiceLookup/CountPrintServices.java
Passed: javax/print/CheckDupFlavor.java
Additionally unused imports have been removed.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/15821/head:pull/15821
$ git checkout pull/15821
Update a local copy of the PR:
$ git checkout pull/15821
$ git pull https://git.openjdk.org/jdk.git pull/15821/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 15821
View PR using the GUI difftool:
$ git pr show -t 15821
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/15821.diff
Webrev
Link to Webrev Comment