Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/print/attribute/SidesPageRangesTest.java
38838 views
/*1* Copyright (c) 2003, 2010, 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 490336625* @summary No crash should occur.26* @run main SidesPageRangesTest27*/28import java.awt.*;29import javax.print.*;30import javax.print.attribute.standard.*;31import javax.print.attribute.*;32import java.io.*;33import java.util.Locale;34import java.net.URL;3536public class SidesPageRangesTest {37/**38* Constructor39*/40public SidesPageRangesTest() {41super();42}43/**44* Starts the application.45*/46public static void main(java.lang.String[] args) {47SidesPageRangesTest pd = new SidesPageRangesTest();48PrintService defService = null;49DocFlavor flavors[] = null;50PrintService[] pservice;51defService = PrintServiceLookup.lookupDefaultPrintService();52if (defService == null) {53pservice = PrintServiceLookup.lookupPrintServices(null, null);54if (pservice.length == 0) {55throw new RuntimeException("Printer is required for this test. TEST ABORTED");56}57defService = pservice[0];58}59System.out.println("Default Print Service "+defService);606162if (defService.isAttributeCategorySupported(PageRanges.class)) {63System.out.println("\nPageRanges Attribute category is supported");64} else {65System.out.println("\nPageRanges Attribute category is not supported. terminating...");66return;67}6869flavors = defService.getSupportedDocFlavors();70System.out.println("\nGetting Supported values for PageRanges for each supported DocFlavor");71System.out.println("===============================================================\n");72for (int y = 0; y < flavors.length; y ++) {73System.out.println("\n\n");7475System.out.println("Doc Flavor: "+flavors[y]);76System.out.println("-----------------------------");7778Object vals = defService.getSupportedAttributeValues(PageRanges.class, flavors[y], null);79if (vals == null) {80System.out.println("No supported values for PageRanges for this doc flavor. ");81}8283PageRanges[] pr = null;84if (vals instanceof PageRanges[]) {85pr = (PageRanges[]) vals;86for (int x = 0; x < pr.length; x ++) {87System.out.println("\nSupported Value "+pr[x]);88System.out.println("is "+pr[x]+" value supported? "+defService.isAttributeValueSupported(pr[x], flavors[y], null));8990if (!defService.isAttributeValueSupported(pr[x], flavors[y], null)) {91throw new RuntimeException("PageRanges contradicts getSupportedAttributeValues");92}93}94} else if (vals instanceof PageRanges) {95System.out.println(vals);96System.out.println("is "+vals+" value supported? "+defService.isAttributeValueSupported((javax.print.attribute.Attribute)vals, flavors[y], null));97if (!defService.isAttributeValueSupported((javax.print.attribute.Attribute)vals, flavors[y], null)) {98throw new RuntimeException("PageRanges contradicts getSupportedAttributeValues");99}100}101102// SIDES test103vals = defService.getSupportedAttributeValues(Sides.class, flavors[y], null);104if (vals == null) {105System.out.println("No supported values for Sides for this doc flavor. ");106}107108Sides[] s = null;109if (vals instanceof Sides[]) {110s = (Sides[]) vals;111for (int x = 0; x < s.length; x ++) {112System.out.println("\nSupported Value "+s[x]);113System.out.println("is "+s[x]+" value supported? "+defService.isAttributeValueSupported(s[x], flavors[y], null));114if (!defService.isAttributeValueSupported(s[x], flavors[y], null)) {115throw new RuntimeException("Sides contradicts getSupportedAttributeValues");116}117}118}119}120}121}122123124