1183N/A/*
3261N/A * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
1183N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1183N/A *
1183N/A * This code is free software; you can redistribute it and/or modify it
1183N/A * under the terms of the GNU General Public License version 2 only, as
1183N/A * published by the Free Software Foundation.
1183N/A *
1183N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1183N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1183N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1183N/A * version 2 for more details (a copy is included in the LICENSE file that
1183N/A * accompanied this code).
1183N/A *
1183N/A * You should have received a copy of the GNU General Public License version
1183N/A * 2 along with this work; if not, write to the Free Software Foundation,
1183N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1183N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1183N/A */
1183N/A/*
1183N/A * @test
1183N/A * @bug 4903366
1183N/A * @summary No crash should occur.
1183N/A * @run main SidesPageRangesTest
1183N/A*/
1183N/Aimport java.awt.*;
1183N/Aimport javax.print.*;
1183N/Aimport javax.print.attribute.standard.*;
1183N/Aimport javax.print.attribute.*;
1183N/Aimport java.io.*;
1183N/Aimport java.util.Locale;
1183N/Aimport java.net.URL;
1183N/A
1183N/Apublic class SidesPageRangesTest {
1183N/A /**
1183N/A * Constructor
1183N/A */
1183N/A public SidesPageRangesTest() {
1183N/A super();
1183N/A }
1183N/A /**
1183N/A * Starts the application.
1183N/A */
1183N/A public static void main(java.lang.String[] args) {
1183N/A SidesPageRangesTest pd = new SidesPageRangesTest();
1183N/A PrintService defService = null;
1183N/A DocFlavor flavors[] = null;
1183N/A PrintService[] pservice;
1183N/A defService = PrintServiceLookup.lookupDefaultPrintService();
1183N/A if (defService == null) {
1183N/A pservice = PrintServiceLookup.lookupPrintServices(null, null);
1183N/A if (pservice.length == 0) {
1183N/A throw new RuntimeException("Printer is required for this test. TEST ABORTED");
1183N/A }
1183N/A defService = pservice[0];
1183N/A }
1183N/A System.out.println("Default Print Service "+defService);
1183N/A
1183N/A
1183N/A if (defService.isAttributeCategorySupported(PageRanges.class)) {
1183N/A System.out.println("\nPageRanges Attribute category is supported");
1183N/A } else {
1183N/A System.out.println("\nPageRanges Attribute category is not supported. terminating...");
2043N/A return;
1183N/A }
1183N/A
1183N/A flavors = defService.getSupportedDocFlavors();
1183N/A System.out.println("\nGetting Supported values for PageRanges for each supported DocFlavor");
1183N/A System.out.println("===============================================================\n");
1183N/A for (int y = 0; y < flavors.length; y ++) {
1183N/A System.out.println("\n\n");
1183N/A
1183N/A System.out.println("Doc Flavor: "+flavors[y]);
1183N/A System.out.println("-----------------------------");
1183N/A
1183N/A Object vals = defService.getSupportedAttributeValues(PageRanges.class, flavors[y], null);
1183N/A if (vals == null) {
1183N/A System.out.println("No supported values for PageRanges for this doc flavor. ");
1183N/A }
1183N/A
1183N/A PageRanges[] pr = null;
1183N/A if (vals instanceof PageRanges[]) {
1183N/A pr = (PageRanges[]) vals;
1183N/A for (int x = 0; x < pr.length; x ++) {
1183N/A System.out.println("\nSupported Value "+pr[x]);
1183N/A System.out.println("is "+pr[x]+" value supported? "+defService.isAttributeValueSupported(pr[x], flavors[y], null));
1183N/A
1183N/A if (!defService.isAttributeValueSupported(pr[x], flavors[y], null)) {
1183N/A throw new RuntimeException("PageRanges contradicts getSupportedAttributeValues");
1183N/A }
1183N/A }
1183N/A } else if (vals instanceof PageRanges) {
1183N/A System.out.println(vals);
1183N/A System.out.println("is "+vals+" value supported? "+defService.isAttributeValueSupported((javax.print.attribute.Attribute)vals, flavors[y], null));
1183N/A if (!defService.isAttributeValueSupported((javax.print.attribute.Attribute)vals, flavors[y], null)) {
1183N/A throw new RuntimeException("PageRanges contradicts getSupportedAttributeValues");
1183N/A }
1183N/A }
1183N/A
1183N/A // SIDES test
1183N/A vals = defService.getSupportedAttributeValues(Sides.class, flavors[y], null);
1183N/A if (vals == null) {
1183N/A System.out.println("No supported values for Sides for this doc flavor. ");
1183N/A }
1183N/A
1183N/A Sides[] s = null;
1183N/A if (vals instanceof Sides[]) {
1183N/A s = (Sides[]) vals;
1183N/A for (int x = 0; x < s.length; x ++) {
1183N/A System.out.println("\nSupported Value "+s[x]);
1183N/A System.out.println("is "+s[x]+" value supported? "+defService.isAttributeValueSupported(s[x], flavors[y], null));
1183N/A if (!defService.isAttributeValueSupported(s[x], flavors[y], null)) {
1183N/A throw new RuntimeException("Sides contradicts getSupportedAttributeValues");
1183N/A }
1183N/A }
1183N/A }
1183N/A }
1183N/A }
1183N/A}