Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8270609: [TESTBUG] java/awt/print/Dialog/DialogCopies.java does not s…
…how instruction

Reviewed-by: aivanov
  • Loading branch information
lawrence-andrew authored and aivanov-jdk committed Sep 20, 2021
1 parent 544193a commit 4da45c4
Showing 1 changed file with 56 additions and 23 deletions.
79 changes: 56 additions & 23 deletions test/jdk/java/awt/print/Dialog/DialogCopies.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -21,40 +21,73 @@
* questions.
*/

/**
/*
* @test
* @bug 6357858
* @summary Job must reports the number of copies set in the dialog.
* @run main/manual DialogCopies
*/

import java.awt.print.*;
import java.awt.Frame;
import java.awt.TextArea;
import java.awt.BorderLayout;
import java.awt.print.PrinterJob;

public class DialogCopies {

static String[] instructions = {
"This test assumes and requires that you have a printer installed",
"When the dialog appears, increment the number of copies then press OK.",
"The test will throw an exception if you fail to do this, since",
"it cannot distinguish that from a failure",
""
};
private static Frame createInstructionUI() {
final String instruction = """
This test requires that you have a printer.
Press Cancel if your system has only virtual printers such as
Microsoft Print to PDF or Microsoft XPS Document Writer since
they don't allow setting copies to anything but 1.
If a real printer is installed, select it from the drop-down
list in the Print dialog and increase the number of copies,
then press OK button.""";

public static void main(String[] args) {
TextArea instructionTextArea = new TextArea(instruction);
instructionTextArea.setEditable(false);

for (int i=0;i<instructions.length;i++) {
System.out.println(instructions[i]);
}
Frame instructionFrame = new Frame();
instructionFrame.add(instructionTextArea, BorderLayout.CENTER);
instructionFrame.pack();
instructionFrame.setLocationRelativeTo(null);
instructionFrame.setVisible(true);
return instructionFrame;
}

PrinterJob job = PrinterJob.getPrinterJob();
if (job.getPrintService() == null || !job.printDialog()) {
return;
}
public static void showPrintDialog() {
PrinterJob job = PrinterJob.getPrinterJob();
if (job.getPrintService() == null) {
System.out.println("Looks like printer is not configured. Please install printer " +
" and re-run the test case.");
return;
}
checkNoOfCopies(job, job.printDialog());
}

System.out.println("Job copies is " + job.getCopies());
public static void checkNoOfCopies(PrinterJob job, boolean pdReturnValue) {
if (pdReturnValue) {
System.out.println("User has selected OK/Print button on the PrintDialog");
int copies = job.getCopies();
if (copies <= 1) {
throw new RuntimeException("Expected the number of copies to be more than 1 but got " + copies);
} else {
System.out.println("Total number of copies : " + copies);
}
} else {
System.out.println("User has selected Cancel button on the PrintDialog.");
}
}

if (job.getCopies() == 1) {
throw new RuntimeException("Copies not incremented");
}
}
public static void main(String[] args) throws InterruptedException {
Frame frame = createInstructionUI();
try {
showPrintDialog();
} finally {
frame.dispose();
}
}
}

3 comments on commit 4da45c4

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on 4da45c4 Sep 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 4da45c4 Sep 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin the backport was successfully created on the branch GoeLin-backport-4da45c43 in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 4da45c43 from the openjdk/jdk repository.

The commit being backported was authored by lawrence.andrews on 20 Sep 2021 and was reviewed by Alexey Ivanov.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev GoeLin-backport-4da45c43:GoeLin-backport-4da45c43
$ git checkout GoeLin-backport-4da45c43
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev GoeLin-backport-4da45c43

Please sign in to comment.