Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/print/attribute/SupportedPrintableAreas.java
38838 views
/*1* Copyright (c) 2003, 2009, 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*/2223/*24* @test25* @bug 4762773 6289206 6324049 636276526* @summary Tests that get non-null return list of printable areas.27* @run main SupportedPrintableAreas28*/293031import javax.print.*;32import javax.print.event.*;33import javax.print.attribute.*;34import javax.print.attribute.standard.*;3536public class SupportedPrintableAreas {3738public static void main(String[] args) {39PrintService[] svc;40PrintService printer = PrintServiceLookup.lookupDefaultPrintService();41if (printer == null) {42svc = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);43if (svc.length == 0) {44throw new RuntimeException("Printer is required for this test. TEST ABORTED");45}46printer = svc[0];47}48System.out.println("PrintService found : "+printer);4950if (!printer.isAttributeCategorySupported(MediaPrintableArea.class)) {51return;52}53Object value = printer.getSupportedAttributeValues(54MediaPrintableArea.class, null, null);55if (!value.getClass().isArray()) {56throw new RuntimeException("unexpected value");57}5859PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();60value = printer.getSupportedAttributeValues(61MediaPrintableArea.class, null, aset);62if (!value.getClass().isArray()) {63throw new RuntimeException("unexpected value");64}6566Media media = (Media)printer.getDefaultAttributeValue(Media.class);67aset.add(media);68value = printer.getSupportedAttributeValues(69MediaPrintableArea.class, null, aset);70if (!value.getClass().isArray()) {71throw new RuntimeException("unexpected value");72}7374// test for 628920675aset.add(MediaTray.MANUAL);76value = printer.getSupportedAttributeValues(77MediaPrintableArea.class, null, aset);78if ((value != null) && !value.getClass().isArray()) {79throw new RuntimeException("unexpected value");80}81}82}838485