Path: blob/master/test/jdk/javax/print/attribute/ServiceDialogValidateTest.java
41149 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/*23* @test24* @bug 5049012 816392225* @summary Verify if PrintToFile option is disabled for flavors that do not26* support Destination27* @requires (os.family == "linux")28* @run main/manual ServiceDialogValidateTest29*/30import java.awt.BorderLayout;31import java.awt.FlowLayout;32import java.awt.event.WindowAdapter;33import java.awt.event.WindowEvent;34import java.io.File;35import javax.print.DocFlavor;36import javax.print.PrintService;37import javax.print.PrintServiceLookup;38import javax.print.ServiceUI;39import javax.print.attribute.HashPrintRequestAttributeSet;40import javax.print.attribute.standard.Destination;41import javax.swing.JButton;42import javax.swing.JDialog;43import javax.swing.JPanel;44import javax.swing.JTextArea;45import javax.swing.SwingUtilities;4647public class ServiceDialogValidateTest {48private static Thread mainThread;49private static boolean testPassed;50private static boolean testGeneratedInterrupt;5152private static void printTest() {53PrintService defService = null, service[] = null;54HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet();55DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG;5657service = PrintServiceLookup.lookupPrintServices(flavor, null);58defService = PrintServiceLookup.lookupDefaultPrintService();5960if ((service == null) || (service.length == 0)) {61throw new RuntimeException("No Printer services found");62}63File f = new File("output.ps");64Destination d = new Destination(f.toURI());65prSet.add(d);66if (defService != null) {67System.out.println("isAttrCategory Supported? " +68defService.isAttributeCategorySupported(Destination.class));69System.out.println("isAttrValue Supported? " +70defService.isAttributeValueSupported(d, flavor, null));71}7273defService = ServiceUI.printDialog(null, 100, 100, service, defService,74flavor, prSet);7576ServiceUI.printDialog(null, 100, 100, service, defService,77DocFlavor.SERVICE_FORMATTED.PAGEABLE,78new HashPrintRequestAttributeSet());79}8081/**82* Starts the application.83*/84public static void main(java.lang.String[] args) throws Exception {85SwingUtilities.invokeAndWait(() -> {86doTest(ServiceDialogValidateTest::printTest);87});88mainThread = Thread.currentThread();89try {90Thread.sleep(60000);91} catch (InterruptedException e) {92if (!testPassed && testGeneratedInterrupt) {93throw new RuntimeException("PrintToFile option is not disabled "94+ "for flavors that do not support destination and/or"95+ " disabled for flavors that supports destination");96}97}98if (!testGeneratedInterrupt) {99throw new RuntimeException("user has not executed the test");100}101}102103public static synchronized void pass() {104testPassed = true;105testGeneratedInterrupt = true;106mainThread.interrupt();107}108109public static synchronized void fail() {110testPassed = false;111testGeneratedInterrupt = true;112mainThread.interrupt();113}114115private static void doTest(Runnable action) {116String description117= " Visual inspection of print dialog is required.\n"118+ " 2 print dialog will be shown.\n "119+ " Please verify Print-To-File option is disabled "120+ " in the 1st print dialog.\n"121+ " Press Cancel to close the print dialog.\n"122+ " Please verify Print-To-File option is enabled "123+ " in 2nd print dialog\n"124+ " Press Cancel to close the print dialog.\n"125+ " If the print dialog's Print-to-File behaves as mentioned, "126+ " press PASS else press FAIL";127128final JDialog dialog = new JDialog();129dialog.setTitle("printSelectionTest");130JTextArea textArea = new JTextArea(description);131textArea.setEditable(false);132final JButton testButton = new JButton("Start Test");133final JButton passButton = new JButton("PASS");134passButton.setEnabled(false);135passButton.addActionListener((e) -> {136dialog.dispose();137pass();138});139final JButton failButton = new JButton("FAIL");140failButton.setEnabled(false);141failButton.addActionListener((e) -> {142dialog.dispose();143fail();144});145testButton.addActionListener((e) -> {146testButton.setEnabled(false);147action.run();148passButton.setEnabled(true);149failButton.setEnabled(true);150});151JPanel mainPanel = new JPanel(new BorderLayout());152mainPanel.add(textArea, BorderLayout.CENTER);153JPanel buttonPanel = new JPanel(new FlowLayout());154buttonPanel.add(testButton);155buttonPanel.add(passButton);156buttonPanel.add(failButton);157mainPanel.add(buttonPanel, BorderLayout.SOUTH);158dialog.add(mainPanel);159dialog.pack();160dialog.setVisible(true);161dialog.addWindowListener(new WindowAdapter() {162@Override163public void windowClosing(WindowEvent e) {164System.out.println("main dialog closing");165testGeneratedInterrupt = false;166mainThread.interrupt();167}168});169}170}171172173174175