Path: blob/master/test/jdk/javax/print/attribute/TestOrientationSupportForStreamPrnSrv.java
41149 views
/*1* Copyright (c) 2016, 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 488230525* @summary Verifies if StreamPrintServ.getSupportedAttributeValues returns26* valid Orientation attribute and not null for image/jpeg DocFlavor.27* @run main TestOrientationSupportForStreamPrnSrv28*/29import java.io.File;30import java.io.FileOutputStream;31import javax.print.DocFlavor;32import javax.print.PrintService;33import javax.print.PrintServiceLookup;34import javax.print.StreamPrintServiceFactory;35import javax.print.attribute.standard.OrientationRequested;3637public class TestOrientationSupportForStreamPrnSrv {3839public static void main(java.lang.String[] args) throws Exception {40PrintService service = null;41PrintService defService = PrintServiceLookup.lookupDefaultPrintService();42File f = null;43FileOutputStream fos = null;44String mType = "application/postscript";45DocFlavor flavors[] = null;4647f = new File("streamexample1.ps");48fos = new FileOutputStream(f);49StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.50lookupStreamPrintServiceFactories(DocFlavor.INPUT_STREAM.JPEG,51mType);52if (factories.length > 0) {53System.out.println("output format "+factories[0].getOutputFormat());54service = factories[0].getPrintService(fos);55flavors = factories[0].getSupportedDocFlavors();56}57System.out.println("Stream Print Service "+service);5859if (service == null) {60throw new RuntimeException("No Stream Print Service found");61}62System.out.println("is OrientationRequested supported? "+63service.isAttributeCategorySupported(OrientationRequested.class));6465for (int k = 0; k < flavors.length; k ++) {66Object obj = service.getSupportedAttributeValues(OrientationRequested.class,67flavors[k], null);68if (flavors[k].equals(DocFlavor.INPUT_STREAM.JPEG)) {69if (obj == null) {70throw new RuntimeException(""71+ "StreamPrintServ.getSupportedAttributeValues "72+ "returns null for image/jpeg DocFlavor for "73+ "supported Orientation category");74}75}76}77}78}79808182