changeset 39031:270b6bdddb53

8158520: [TEST_BUG] java/awt/PrintJob/PrinterException.java fails on timeout Reviewed-by: serb
author psadhukhan
date Tue, 07 Jun 2016 11:02:21 +0530
parents 7fb2b97a39ad
children 0df349c99122
files jdk/test/java/awt/PrintJob/PrinterException.java
diffstat 1 files changed, 23 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/test/java/awt/PrintJob/PrinterException.java	Mon Jun 06 13:16:45 2016 -0700
+++ b/jdk/test/java/awt/PrintJob/PrinterException.java	Tue Jun 07 11:02:21 2016 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, 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
@@ -22,7 +22,7 @@
  */
 /*
  * @test
- * @bug 7161283
+ * @bug 7161283 8158520
  * @summary  Toolkit.getPrintJob throws NPE if no printer available
  * @run main PrinterException
  */
@@ -30,9 +30,19 @@
 import java.awt.JobAttributes;
 import java.awt.PrintJob;
 import java.awt.Toolkit;
+import java.awt.Robot;
+import java.awt.event.KeyEvent;
 
 public class PrinterException {
-    public static void main(String[] args) {
+
+    public static void main(String[] args) throws Exception {
+        Robot robot = new Robot();
+        Thread t = new Thread (() -> {
+            robot.waitForIdle();
+            robot.delay(2000);
+            robot.keyPress(KeyEvent.VK_ESCAPE);
+            robot.keyRelease(KeyEvent.VK_ESCAPE);
+           });
         Toolkit tk = Toolkit.getDefaultToolkit();
         PrintJob pj = null;
 
@@ -40,12 +50,19 @@
         JobAttributes ja = new JobAttributes(1,
                 java.awt.JobAttributes.DefaultSelectionType.ALL,
                 JobAttributes.DestinationType.FILE, JobAttributes.DialogType.NATIVE,
-                "", Integer.MAX_VALUE, 1,
+                "filename.ps", Integer.MAX_VALUE, 1,
                 JobAttributes.MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES,
                  pageRange, "", JobAttributes.SidesType.ONE_SIDED);
+
         Frame testFrame = new Frame("print");
-        if (tk != null) {
-            pj = tk.getPrintJob(testFrame, null, ja, null);
+        try {
+            if (tk != null) {
+                t.start();
+                pj = tk.getPrintJob(testFrame, null, ja, null);
+            }
+        } finally {
+            testFrame.dispose();
         }
     }
+
 }