Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/print/attribute/ChromaticityValues.java
38838 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* @summary Test for chromaticity values.26* @run main ChromaticityValues27*/28293031import javax.print.*;32import javax.print.attribute.*;33import javax.print.attribute.standard.*;34import java.util.ArrayList;3536public class ChromaticityValues {3738public static void main(String args[]) {39System.out.println("=======================================================================");40System.out.println("INSTRUCTIONS: This test is only for WINDOWS platform. ");41System.out.println("You should have a printer configured as your default printer in your system.");42System.out.println("=======================================================================");4344String os=System.getProperty("os.name").toLowerCase();4546if (!(os.indexOf("win")>=0)) {47System.out.println("Not a Windows System. TEST ABORTED");48return;49}5051PrintService pservice = PrintServiceLookup.lookupDefaultPrintService();52if (pservice == null) {53throw new RuntimeException("A printer is required for this test.");54}5556System.out.println("Default Service is "+pservice);57ColorSupported psa = (ColorSupported)pservice.getAttribute(ColorSupported.class);58ArrayList cValues = new ArrayList();5960if (pservice.isAttributeCategorySupported(Chromaticity.class)) {61Chromaticity[] values =(Chromaticity[])62(pservice.getSupportedAttributeValues(Chromaticity.class, DocFlavor.SERVICE_FORMATTED.PAGEABLE, null));63if ((values != null) && (values.length > 0)) {64for (int i=0; i<values.length; i++) {65cValues.add(values[i]);66}67} else {68System.out.println("Chromaticity value is unknown. TEST ABORTED");69return;70}7172} else {73System.out.println("Chromaticity is not supported. TEST ABORTED");74return;7576}7778if (psa != null) {79if (psa.equals(ColorSupported.SUPPORTED)) {80if (cValues.size() < 2) {81throw new RuntimeException("ColorSupported is supported, values for Chromaticity should be monochrome and color.");82}83} else {84if ((cValues.size() != 1) ||85(!cValues.contains(Chromaticity.MONOCHROME))) {86throw new RuntimeException("ColorSupported is not supported, values for Chromaticity should only be monochrome.");87}88}89} else { // ColorSupported unknown90if (!cValues.contains(Chromaticity.COLOR)) {91throw new RuntimeException("ColorSupported is unknown, values for Chromaticity should at least include color.");92}9394}95}96}979899