|
| 1 | +/* |
| 2 | + * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +/* |
| 25 | + * @test |
| 26 | + * @bug 4884570 |
| 27 | + * @summary Attribute support reporting should be consistent |
| 28 | +*/ |
| 29 | + |
| 30 | +import java.io.ByteArrayOutputStream; |
| 31 | +import java.io.OutputStream; |
| 32 | + |
| 33 | +import javax.print.DocFlavor; |
| 34 | +import javax.print.StreamPrintService; |
| 35 | +import javax.print.StreamPrintServiceFactory; |
| 36 | +import javax.print.attribute.Attribute; |
| 37 | +import javax.print.attribute.standard.Chromaticity; |
| 38 | +import javax.print.attribute.standard.Media; |
| 39 | +import javax.print.attribute.standard.OrientationRequested; |
| 40 | +import javax.print.attribute.standard.SheetCollate; |
| 41 | +import javax.print.attribute.standard.Sides; |
| 42 | + |
| 43 | +public class StreamServiceAttributeTest { |
| 44 | + |
| 45 | + private static boolean allSupported = true; |
| 46 | + private static Class[] attrClasses = { |
| 47 | + Chromaticity.class, |
| 48 | + Media.class, |
| 49 | + OrientationRequested.class, |
| 50 | + SheetCollate.class, |
| 51 | + Sides.class, |
| 52 | + }; |
| 53 | + |
| 54 | + public static void main(String args[]) { |
| 55 | + |
| 56 | + StreamPrintServiceFactory[] fact = |
| 57 | + StreamPrintServiceFactory.lookupStreamPrintServiceFactories( |
| 58 | + null, null); |
| 59 | + |
| 60 | + if (fact.length == 0) { |
| 61 | + return; |
| 62 | + } |
| 63 | + OutputStream out = new ByteArrayOutputStream(); |
| 64 | + StreamPrintService sps = fact[0].getPrintService(out); |
| 65 | + for (Class<? extends Attribute> ac : attrClasses) { |
| 66 | + test(sps, ac); |
| 67 | + } |
| 68 | + |
| 69 | + if (!allSupported) { |
| 70 | + throw new RuntimeException("Inconsistent support reported"); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + private static void test(StreamPrintService sps, |
| 75 | + Class<? extends Attribute> ac) { |
| 76 | + if (!sps.isAttributeCategorySupported(ac)) { |
| 77 | + return; |
| 78 | + } |
| 79 | + DocFlavor[] dfs = sps.getSupportedDocFlavors(); |
| 80 | + for (DocFlavor f : dfs) { |
| 81 | + Attribute[] attrs = (Attribute[]) |
| 82 | + sps.getSupportedAttributeValues(ac, f, null); |
| 83 | + if (attrs == null) { |
| 84 | + continue; |
| 85 | + } |
| 86 | + for (Attribute a : attrs) { |
| 87 | + if (!sps.isAttributeValueSupported(a, f, null)) { |
| 88 | + allSupported = false; |
| 89 | + System.out.println("Unsupported : " + f + " " + a); |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | +} |
0 commit comments