Path: blob/master/test/jdk/javax/print/attribute/SupportedPrintableAreas.java
41152 views
/*1* Copyright (c) 2003, 2017, 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* @key printer26* @bug 4762773 6289206 6324049 636276527* @summary Tests that get non-null return list of printable areas.28* @run main SupportedPrintableAreas29*/303132import javax.print.*;33import javax.print.event.*;34import javax.print.attribute.*;35import javax.print.attribute.standard.*;3637public class SupportedPrintableAreas {3839public static void main(String[] args) {40PrintService[] svc;41PrintService printer = PrintServiceLookup.lookupDefaultPrintService();42if (printer == null) {43svc = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);44if (svc.length == 0) {45throw new RuntimeException("Printer is required for this test. TEST ABORTED");46}47printer = svc[0];48}49System.out.println("PrintService found : "+printer);5051if (!printer.isAttributeCategorySupported(MediaPrintableArea.class)) {52return;53}54Object value = printer.getSupportedAttributeValues(55MediaPrintableArea.class, null, null);56if (!value.getClass().isArray()) {57throw new RuntimeException("unexpected value");58}5960PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();61value = printer.getSupportedAttributeValues(62MediaPrintableArea.class, null, aset);63if (!value.getClass().isArray()) {64throw new RuntimeException("unexpected value");65}6667Media media = (Media)printer.getDefaultAttributeValue(Media.class);68aset.add(media);69value = printer.getSupportedAttributeValues(70MediaPrintableArea.class, null, aset);71if (!value.getClass().isArray()) {72throw new RuntimeException("unexpected value");73}7475// test for 628920676aset.add(MediaTray.MANUAL);77value = printer.getSupportedAttributeValues(78MediaPrintableArea.class, null, aset);79if ((value != null) && !value.getClass().isArray()) {80throw new RuntimeException("unexpected value");81}82}83}848586