01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Igor A. Pyankov
19: * @version $Revision: 1.2 $
20: */package javax.print;
21:
22: import java.net.URI;
23: import java.util.Locale;
24:
25: import javax.print.attribute.Attribute;
26: import javax.print.attribute.standard.Destination;
27: import javax.print.attribute.standard.DocumentName;
28: import javax.print.attribute.standard.Finishings;
29: import javax.print.attribute.standard.JobName;
30: import javax.print.attribute.standard.MediaSizeName;
31: import javax.print.attribute.standard.RequestingUserName;
32: import javax.print.attribute.standard.Sides;
33:
34: import junit.framework.TestCase;
35:
36: public class IsAttributeValueSupportedTest extends TestCase {
37: public void testIsAttributeValueSupported() throws Exception {
38: System.out
39: .println("============= START testIsAttributeValueSupported ================");
40:
41: PrintService[] services;
42: URI uri1, uri2, uri3;
43: boolean supported = false;
44:
45: services = PrintServiceLookup.lookupPrintServices(null, null);
46: TestUtil.checkServices(services);
47: for (int i = 0, ii = services.length; i < ii; i++) {
48: System.out.println("----------- " + services[i].getName()
49: + "----------");
50:
51: uri1 = new URI("file:///foo/bar");
52: uri2 = new URI("file:///F:/printing/tmp/print.out");
53: uri3 = new URI("file:///F:/printing/tmp/xxx/print.out");
54:
55: Attribute[] attrs = { MediaSizeName.ISO_A0,
56: Finishings.NONE, Finishings.EDGE_STITCH,
57: MediaSizeName.ISO_A2, MediaSizeName.ISO_A3,
58: new Destination(uri1), new Destination(uri2),
59: new Destination(uri3),
60: new DocumentName("xyz", Locale.US),
61: new JobName("xyz", Locale.US),
62: new RequestingUserName("xyz", Locale.US),
63: Sides.DUPLEX, Sides.ONE_SIDED, Sides.TUMBLE,
64: Sides.TWO_SIDED_LONG_EDGE,
65: Sides.TWO_SIDED_SHORT_EDGE, null };
66: for (int a = 0, ac = attrs.length; a < ac; a++) {
67: try {
68: supported = services[i].isAttributeValueSupported(
69: attrs[a], DocFlavor.INPUT_STREAM.GIF, null);
70: } catch (NullPointerException e1) {
71: if (attrs[a] != null) {
72: fail(e1.toString());
73: }
74: } catch (IllegalArgumentException e) {
75: if (services[i]
76: .isDocFlavorSupported(DocFlavor.INPUT_STREAM.GIF)) {
77: fail(e.toString());
78: }
79: } catch (Exception e) {
80: fail(e.toString());
81: }
82: System.out.println(attrs[a]
83:
84: + (attrs[a] == null ? "" : "("
85: + attrs[a].getCategory().toString()
86: + ")") + " : " + supported);
87: }
88: }
89:
90: System.out
91: .println("============= END testIsAttributeValueSupported ================");
92: }
93:
94: }
|