1 /* 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 /* 24 * @test 25 * @bug 6357905 26 * @summary JobAttributes.getFromPage() and getToPage() always returns 1 27 * @run main/manual JobAttrUpdateTest 28 */ 29 import java.awt.BorderLayout; 30 import java.awt.FlowLayout; 31 import java.awt.JobAttributes; 32 import java.awt.PrintJob; 33 import java.awt.Toolkit; 34 import javax.swing.JButton; 35 import javax.swing.JDialog; 36 import javax.swing.JFrame; 37 import javax.swing.JPanel; 38 import javax.swing.JTextArea; 39 import javax.swing.SwingUtilities; 40 41 public class JobAttrUpdateTest { 42 43 private static Thread mainThread; 44 private static boolean testPassed; 45 private static boolean testGeneratedInterrupt; 46 47 public static void main(String[] args) throws Exception { 48 SwingUtilities.invokeAndWait(() -> { 49 doTest(JobAttrUpdateTest::printTest); 50 }); 51 mainThread = Thread.currentThread(); 52 try { 53 Thread.sleep(30000); 54 } catch (InterruptedException e) { 55 if (!testPassed && testGeneratedInterrupt) { 56 throw new RuntimeException("" 57 + "JobAttributes.getFromPage(),getToPage() not updated correctly"); 58 } 59 } 60 if (!testGeneratedInterrupt) { 61 throw new RuntimeException("user has not executed the test"); 62 } 63 } 64 65 private static void printTest() { 66 JobAttributes ja = new JobAttributes(); 67 68 Toolkit tk = Toolkit.getDefaultToolkit(); 69 // show dialog 70 PrintJob pjob = tk.getPrintJob(new JFrame(), "test", ja, null); 71 if (pjob == null) { 72 return; 73 } 74 75 if (ja.getDefaultSelection() == JobAttributes.DefaultSelectionType.RANGE) { 76 int fromPage = ja.getFromPage(); 77 int toPage = ja.getToPage(); 78 if (fromPage != 2 || toPage != 3) { 79 fail(); 80 } else { 81 pass(); 82 } 83 } 84 } 85 86 public static synchronized void pass() { 87 testPassed = true; 88 testGeneratedInterrupt = true; 89 mainThread.interrupt(); 90 } 91 92 public static synchronized void fail() { 93 testPassed = false; 94 testGeneratedInterrupt = true; 95 mainThread.interrupt(); 96 } 97 98 private static void doTest(Runnable action) { 99 String description 100 = " A print dialog will be shown.\n " 101 + " Please select Pages within Page-range.\n" 102 + " and enter From 2 and To 3. Then Select OK."; 103 104 final JDialog dialog = new JDialog(); 105 dialog.setTitle("JobAttribute Updation Test"); 106 JTextArea textArea = new JTextArea(description); 107 textArea.setEditable(false); 108 final JButton testButton = new JButton("Start Test"); 109 110 testButton.addActionListener((e) -> { 111 testButton.setEnabled(false); 112 action.run(); 113 }); 114 JPanel mainPanel = new JPanel(new BorderLayout()); 115 mainPanel.add(textArea, BorderLayout.CENTER); 116 JPanel buttonPanel = new JPanel(new FlowLayout()); 117 buttonPanel.add(testButton); 118 mainPanel.add(buttonPanel, BorderLayout.SOUTH); 119 dialog.add(mainPanel); 120 dialog.pack(); 121 dialog.setVisible(true); 122 } 123 }