diff -r 1189480fe090 -r b27edaf0767e jdk/test/javax/print/attribute/SidesPageRangesTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/print/attribute/SidesPageRangesTest.java Mon Apr 20 12:31:36 2009 -0700 @@ -0,0 +1,122 @@ +/* + * Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ +/* + * @test + * @bug 4903366 + * @summary No crash should occur. + * @run main SidesPageRangesTest +*/ +import java.awt.*; +import javax.print.*; +import javax.print.attribute.standard.*; +import javax.print.attribute.*; +import java.io.*; +import java.util.Locale; +import java.net.URL; + +public class SidesPageRangesTest { + /** + * Constructor + */ + public SidesPageRangesTest() { + super(); + } + /** + * Starts the application. + */ + public static void main(java.lang.String[] args) { + SidesPageRangesTest pd = new SidesPageRangesTest(); + PrintService defService = null; + DocFlavor flavors[] = null; + PrintService[] pservice; + defService = PrintServiceLookup.lookupDefaultPrintService(); + if (defService == null) { + pservice = PrintServiceLookup.lookupPrintServices(null, null); + if (pservice.length == 0) { + throw new RuntimeException("Printer is required for this test. TEST ABORTED"); + } + defService = pservice[0]; + } + System.out.println("Default Print Service "+defService); + + + if (defService.isAttributeCategorySupported(PageRanges.class)) { + System.out.println("\nPageRanges Attribute category is supported"); + } else { + System.out.println("\nPageRanges Attribute category is not supported. terminating..."); + System.exit(1); + } + + flavors = defService.getSupportedDocFlavors(); + System.out.println("\nGetting Supported values for PageRanges for each supported DocFlavor"); + System.out.println("===============================================================\n"); + for (int y = 0; y < flavors.length; y ++) { + System.out.println("\n\n"); + + System.out.println("Doc Flavor: "+flavors[y]); + System.out.println("-----------------------------"); + + Object vals = defService.getSupportedAttributeValues(PageRanges.class, flavors[y], null); + if (vals == null) { + System.out.println("No supported values for PageRanges for this doc flavor. "); + } + + PageRanges[] pr = null; + if (vals instanceof PageRanges[]) { + pr = (PageRanges[]) vals; + for (int x = 0; x < pr.length; x ++) { + System.out.println("\nSupported Value "+pr[x]); + System.out.println("is "+pr[x]+" value supported? "+defService.isAttributeValueSupported(pr[x], flavors[y], null)); + + if (!defService.isAttributeValueSupported(pr[x], flavors[y], null)) { + throw new RuntimeException("PageRanges contradicts getSupportedAttributeValues"); + } + } + } else if (vals instanceof PageRanges) { + System.out.println(vals); + System.out.println("is "+vals+" value supported? "+defService.isAttributeValueSupported((javax.print.attribute.Attribute)vals, flavors[y], null)); + if (!defService.isAttributeValueSupported((javax.print.attribute.Attribute)vals, flavors[y], null)) { + throw new RuntimeException("PageRanges contradicts getSupportedAttributeValues"); + } + } + + // SIDES test + vals = defService.getSupportedAttributeValues(Sides.class, flavors[y], null); + if (vals == null) { + System.out.println("No supported values for Sides for this doc flavor. "); + } + + Sides[] s = null; + if (vals instanceof Sides[]) { + s = (Sides[]) vals; + for (int x = 0; x < s.length; x ++) { + System.out.println("\nSupported Value "+s[x]); + System.out.println("is "+s[x]+" value supported? "+defService.isAttributeValueSupported(s[x], flavors[y], null)); + if (!defService.isAttributeValueSupported(s[x], flavors[y], null)) { + throw new RuntimeException("Sides contradicts getSupportedAttributeValues"); + } + } + } + } + } +}