Path: blob/master/test/jdk/javax/print/attribute/SidesPageRangesTest.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 490336627* @summary No crash should occur.28* @run main SidesPageRangesTest29*/3031import java.awt.*;32import javax.print.*;33import javax.print.attribute.standard.*;34import javax.print.attribute.*;35import java.io.*;36import java.util.Locale;37import java.net.URL;3839public class SidesPageRangesTest {40/**41* Constructor42*/43public SidesPageRangesTest() {44super();45}46/**47* Starts the application.48*/49public static void main(java.lang.String[] args) {50SidesPageRangesTest pd = new SidesPageRangesTest();51PrintService defService = null;52DocFlavor flavors[] = null;53PrintService[] pservice;54defService = PrintServiceLookup.lookupDefaultPrintService();55if (defService == null) {56pservice = PrintServiceLookup.lookupPrintServices(null, null);57if (pservice.length == 0) {58throw new RuntimeException("Printer is required for this test. TEST ABORTED");59}60defService = pservice[0];61}62System.out.println("Default Print Service "+defService);636465if (defService.isAttributeCategorySupported(PageRanges.class)) {66System.out.println("\nPageRanges Attribute category is supported");67} else {68System.out.println("\nPageRanges Attribute category is not supported. terminating...");69return;70}7172flavors = defService.getSupportedDocFlavors();73System.out.println("\nGetting Supported values for PageRanges for each supported DocFlavor");74System.out.println("===============================================================\n");75for (int y = 0; y < flavors.length; y ++) {76System.out.println("\n\n");7778System.out.println("Doc Flavor: "+flavors[y]);79System.out.println("-----------------------------");8081Object vals = defService.getSupportedAttributeValues(PageRanges.class, flavors[y], null);82if (vals == null) {83System.out.println("No supported values for PageRanges for this doc flavor. ");84}8586PageRanges[] pr = null;87if (vals instanceof PageRanges[]) {88pr = (PageRanges[]) vals;89for (int x = 0; x < pr.length; x ++) {90System.out.println("\nSupported Value "+pr[x]);91System.out.println("is "+pr[x]+" value supported? "+defService.isAttributeValueSupported(pr[x], flavors[y], null));9293if (!defService.isAttributeValueSupported(pr[x], flavors[y], null)) {94throw new RuntimeException("PageRanges contradicts getSupportedAttributeValues");95}96}97} else if (vals instanceof PageRanges) {98System.out.println(vals);99System.out.println("is "+vals+" value supported? "+defService.isAttributeValueSupported((javax.print.attribute.Attribute)vals, flavors[y], null));100if (!defService.isAttributeValueSupported((javax.print.attribute.Attribute)vals, flavors[y], null)) {101throw new RuntimeException("PageRanges contradicts getSupportedAttributeValues");102}103}104105// SIDES test106vals = defService.getSupportedAttributeValues(Sides.class, flavors[y], null);107if (vals == null) {108System.out.println("No supported values for Sides for this doc flavor. ");109}110111Sides[] s = null;112if (vals instanceof Sides[]) {113s = (Sides[]) vals;114for (int x = 0; x < s.length; x ++) {115System.out.println("\nSupported Value "+s[x]);116System.out.println("is "+s[x]+" value supported? "+defService.isAttributeValueSupported(s[x], flavors[y], null));117if (!defService.isAttributeValueSupported(s[x], flavors[y], null)) {118throw new RuntimeException("Sides contradicts getSupportedAttributeValues");119}120}121}122}123}124}125126127