Path: blob/master/test/jdk/javax/print/attribute/ChromaticityValues.java
41149 views
/*1* Copyright (c) 2001, 2009, 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 444610625* @key printer26* @requires (os.family == "windows")27* @summary Test for chromaticity values.28* @run main ChromaticityValues29*/30313233import javax.print.*;34import javax.print.attribute.*;35import javax.print.attribute.standard.*;36import java.util.ArrayList;3738public class ChromaticityValues {3940public static void main(String args[]) {41System.out.println("=======================================================================");42System.out.println("INSTRUCTIONS: This test is only for WINDOWS platform. ");43System.out.println("You should have a printer configured as your default printer in your system.");44System.out.println("=======================================================================");4546String os=System.getProperty("os.name").toLowerCase();4748if (!(os.indexOf("win")>=0)) {49System.out.println("Not a Windows System. TEST ABORTED");50return;51}5253PrintService pservice = PrintServiceLookup.lookupDefaultPrintService();54if (pservice == null) {55throw new RuntimeException("A printer is required for this test.");56}5758System.out.println("Default Service is "+pservice);59ColorSupported psa = (ColorSupported)pservice.getAttribute(ColorSupported.class);60ArrayList cValues = new ArrayList();6162if (pservice.isAttributeCategorySupported(Chromaticity.class)) {63Chromaticity[] values =(Chromaticity[])64(pservice.getSupportedAttributeValues(Chromaticity.class, DocFlavor.SERVICE_FORMATTED.PAGEABLE, null));65if ((values != null) && (values.length > 0)) {66for (int i=0; i<values.length; i++) {67cValues.add(values[i]);68}69} else {70System.out.println("Chromaticity value is unknown. TEST ABORTED");71return;72}7374} else {75System.out.println("Chromaticity is not supported. TEST ABORTED");76return;7778}7980if (psa != null) {81if (psa.equals(ColorSupported.SUPPORTED)) {82if (cValues.size() < 2) {83throw new RuntimeException("ColorSupported is supported, values for Chromaticity should be monochrome and color.");84}85} else {86if ((cValues.size() != 1) ||87(!cValues.contains(Chromaticity.MONOCHROME))) {88throw new RuntimeException("ColorSupported is not supported, values for Chromaticity should only be monochrome.");89}90}91} else { // ColorSupported unknown92if (!cValues.contains(Chromaticity.COLOR)) {93throw new RuntimeException("ColorSupported is unknown, values for Chromaticity should at least include color.");94}9596}97}98}99100101