jdk/test/javax/print/attribute/SidesPageRangesTest.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 5506 202f599c92aa
child 46151 5fa789776f7d
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2697
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 5506
diff changeset
     2
 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
2697
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
     4
 *
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
     8
 *
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    13
 * accompanied this code).
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    14
 *
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4595
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4595
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4595
diff changeset
    21
 * questions.
2697
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    22
 */
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    23
/*
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    24
 * @test
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    25
 * @bug 4903366
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    26
 * @summary No crash should occur.
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    27
 * @run main SidesPageRangesTest
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    28
*/
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    29
import java.awt.*;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    30
import javax.print.*;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    31
import javax.print.attribute.standard.*;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    32
import javax.print.attribute.*;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    33
import java.io.*;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    34
import java.util.Locale;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    35
import java.net.URL;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    36
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    37
public class SidesPageRangesTest {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    38
        /**
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    39
         * Constructor
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    40
         */
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    41
         public SidesPageRangesTest() {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    42
                super();
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    43
        }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    44
        /**
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    45
         * Starts the application.
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    46
         */
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    47
        public static void main(java.lang.String[] args) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    48
                SidesPageRangesTest pd = new SidesPageRangesTest();
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    49
                PrintService defService = null;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    50
                DocFlavor flavors[]  = null;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    51
                PrintService[] pservice;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    52
                defService = PrintServiceLookup.lookupDefaultPrintService();
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    53
                if (defService == null) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    54
                    pservice = PrintServiceLookup.lookupPrintServices(null, null);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    55
                    if (pservice.length == 0) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    56
                        throw new RuntimeException("Printer is required for this test.  TEST ABORTED");
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    57
                    }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    58
                    defService = pservice[0];
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    59
                }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    60
                System.out.println("Default Print Service "+defService);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    61
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    62
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    63
                if (defService.isAttributeCategorySupported(PageRanges.class)) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    64
                        System.out.println("\nPageRanges Attribute category is supported");
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    65
                } else {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    66
                        System.out.println("\nPageRanges Attribute category is not supported. terminating...");
4595
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents: 2697
diff changeset
    67
                        return;
2697
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    68
                }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    69
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    70
                flavors = defService.getSupportedDocFlavors();
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    71
                System.out.println("\nGetting Supported values for PageRanges for each supported DocFlavor");
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    72
                System.out.println("===============================================================\n");
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    73
                for (int y = 0; y < flavors.length; y ++) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    74
                    System.out.println("\n\n");
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    75
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    76
                    System.out.println("Doc Flavor: "+flavors[y]);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    77
                    System.out.println("-----------------------------");
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    78
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    79
                    Object vals = defService.getSupportedAttributeValues(PageRanges.class, flavors[y], null);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    80
                    if (vals == null) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    81
                        System.out.println("No supported values for PageRanges for this doc flavor. ");
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    82
                    }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    83
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    84
                    PageRanges[] pr = null;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    85
                    if (vals instanceof PageRanges[]) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    86
                        pr = (PageRanges[]) vals;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    87
                        for (int x = 0; x < pr.length; x ++) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    88
                            System.out.println("\nSupported Value "+pr[x]);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    89
                            System.out.println("is "+pr[x]+" value supported? "+defService.isAttributeValueSupported(pr[x], flavors[y], null));
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    90
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    91
                            if (!defService.isAttributeValueSupported(pr[x], flavors[y], null)) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    92
                                throw new RuntimeException("PageRanges contradicts getSupportedAttributeValues");
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    93
                            }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    94
                        }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    95
                    } else if (vals instanceof PageRanges) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    96
                        System.out.println(vals);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    97
                        System.out.println("is "+vals+" value supported? "+defService.isAttributeValueSupported((javax.print.attribute.Attribute)vals, flavors[y], null));
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    98
                        if (!defService.isAttributeValueSupported((javax.print.attribute.Attribute)vals, flavors[y], null)) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    99
                            throw new RuntimeException("PageRanges contradicts getSupportedAttributeValues");
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   100
                        }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   101
                    }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   102
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   103
                    // SIDES test
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   104
                    vals = defService.getSupportedAttributeValues(Sides.class, flavors[y], null);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   105
                    if (vals == null) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   106
                        System.out.println("No supported values for Sides for this doc flavor. ");
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   107
                    }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   108
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   109
                    Sides[] s = null;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   110
                    if (vals instanceof Sides[]) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   111
                        s = (Sides[]) vals;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   112
                        for (int x = 0; x < s.length; x ++) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   113
                            System.out.println("\nSupported Value "+s[x]);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   114
                            System.out.println("is "+s[x]+" value supported? "+defService.isAttributeValueSupported(s[x], flavors[y], null));
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   115
                            if  (!defService.isAttributeValueSupported(s[x], flavors[y], null)) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   116
                                throw new RuntimeException("Sides contradicts getSupportedAttributeValues");
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   117
                            }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   118
                        }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   119
                    }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   120
                }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   121
        }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   122
}