001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Elena V. Sayapina
019: * @version $Revision: 1.3 $
020: */package javax.print.attribute;
021:
022: import junit.framework.TestCase;
023:
024: public class ResolutionSyntaxTest extends TestCase {
025:
026: static {
027: System.out.println("ResolutionSyntax testing...");
028: }
029:
030: public static void main(String[] args) {
031: junit.textui.TestRunner.run(ResolutionSyntaxTest.class);
032: }
033:
034: resolutionSyntax rs1, rs2;
035:
036: /*
037: * ResolutionSyntax(int crossFeedResolution, int feedResolution,
038: * int units) constructor testing.
039: */
040: public final void testResolutionSyntax() {
041: try {
042: rs1 = new resolutionSyntax(1, 1, 0);
043: fail("ResolutionSyntax(int crossFeedResolution, "
044: + "int feedResolution, int units) doesn't throw "
045: + "IllegalArgumentException if units < 1");
046: } catch (IllegalArgumentException e) {
047: }
048:
049: try {
050: rs1 = new resolutionSyntax(-1, 1, 1);
051: fail("ResolutionSyntax(int crossFeedResolution, "
052: + "int feedResolution, int units) doesn't throw "
053: + "IllegalArgumentException if "
054: + "crossFeedResolution < 1");
055: } catch (IllegalArgumentException e) {
056: }
057: try {
058: rs1 = new resolutionSyntax(1, 0, 10);
059: fail("ResolutionSyntax(int crossFeedResolution, "
060: + "int feedResolution, int units) doesn't throw "
061: + "IllegalArgumentException if "
062: + "or feedResolution < 1");
063: } catch (IllegalArgumentException e) {
064: }
065:
066: rs1 = new resolutionSyntax(10001, 1507, resolutionSyntax.DPI);
067: assertEquals(10001, rs1
068: .getCrossFeedResolution(resolutionSyntax.DPI));
069: assertEquals(1507, rs1.getFeedResolution(resolutionSyntax.DPI));
070: }
071:
072: /*
073: * hashCode() method testing. Tests if two object aren't equal they should
074: * have different hash codes.
075: */
076: public final void testHashCode() {
077: rs1 = new resolutionSyntax(4444, 333, resolutionSyntax.DPCM);
078: rs2 = new resolutionSyntax(333, 444, resolutionSyntax.DPCM);
079: assertTrue(rs1.hashCode() != rs2.hashCode());
080: }
081:
082: /*
083: * hashCode() method testing. Tests if two object are equal they must have
084: * the same hash code.
085: */
086: public final void testHashCode1() {
087: rs1 = new resolutionSyntax(1, 1, resolutionSyntax.DPCM);
088: rs2 = new resolutionSyntax(1, 1, resolutionSyntax.DPCM);
089: assertTrue(rs1.hashCode() == rs2.hashCode());
090: }
091:
092: /*
093: * equals(Object object) method testing. Tests if two object are equal
094: * they must have the same hash code.
095: */
096: public final void testEqualsObject() {
097: rs1 = new resolutionSyntax(1, 1, resolutionSyntax.DPCM);
098: rs2 = new resolutionSyntax(1, 1, resolutionSyntax.DPCM);
099: assertTrue(rs1.equals(rs2));
100:
101: rs1 = new resolutionSyntax(1, 1, resolutionSyntax.DPCM);
102: rs2 = new resolutionSyntax(1, 1, resolutionSyntax.DPI);
103: assertFalse(rs1.equals(rs2));
104:
105: rs1 = new resolutionSyntax(1000, 2000, resolutionSyntax.DPCM);
106: rs2 = new resolutionSyntax(1000, 2000, resolutionSyntax.DPCM);
107: assertTrue(rs1.equals(rs2));
108:
109: rs1 = new resolutionSyntax(1000, 2000, resolutionSyntax.DPI);
110: rs2 = new resolutionSyntax(1000, 2000 - 1,
111: resolutionSyntax.DPCM);
112: assertFalse(rs1.equals(rs2));
113:
114: rs2 = null;
115: assertFalse("equals(object o) returns true if o is null", rs1
116: .equals(rs2));
117: }
118:
119: public final void testGetCrossFeedResolution() {
120: rs1 = new resolutionSyntax(1000, 2000, 1);
121: assertEquals(1000, rs1.getCrossFeedResolution(1));
122: try {
123: rs1.getCrossFeedResolution(0);
124: fail("getCrossFeedResolution(int units) doesn't throw "
125: + "IllegalArgumentException if units < 1");
126: } catch (IllegalArgumentException e) {
127: }
128: }
129:
130: public final void testGetCrossFeedResolutionDphi() {
131: rs1 = new resolutionSyntax(1000, 2000, 3);
132: assertEquals(3000, rs1.getCrossFeedResolutionDphiEx());
133: rs1 = new resolutionSyntax(1000, 2000, 1);
134: assertEquals("bad rounding", 333, rs1.getCrossFeedResolution(3));
135: }
136:
137: public final void testGetFeedResolution() {
138: rs1 = new resolutionSyntax(1000, 2000, 1);
139: assertEquals(2000, rs1.getFeedResolution(1));
140: try {
141: rs1.getFeedResolution(-100);
142: fail("getFeedResolution(int units) doesn't throw "
143: + "IllegalArgumentException if units < 1");
144: } catch (IllegalArgumentException e) {
145: }
146: }
147:
148: public final void testGetFeedResolutionDphi() {
149: rs1 = new resolutionSyntax(1000, 2000, 3);
150: assertEquals(6000, rs1.getFeedResolutionDphiEx());
151: rs1 = new resolutionSyntax(1000, 500, 1);
152: assertEquals("bad rounding", 63, rs1.getFeedResolution(8));
153: }
154:
155: public final void testGetResolution() {
156: rs1 = new resolutionSyntax(1000, 2000, resolutionSyntax.DPCM);
157: assertEquals(1000, rs1.getResolution(resolutionSyntax.DPCM)[0]);
158: assertEquals(2000, rs1.getResolution(resolutionSyntax.DPCM)[1]);
159: try {
160: rs1.getResolution(0);
161: fail("getResolution(int units) doesn't throw "
162: + "IllegalArgumentException if units < 1");
163: } catch (IllegalArgumentException e) {
164: }
165: }
166:
167: public final void testLessThanOrEquals() {
168: rs1 = new resolutionSyntax(1000, 1000, 1);
169: rs2 = new resolutionSyntax(999, 1000, 1);
170: assertTrue(rs2.lessThanOrEquals(rs1));
171:
172: rs1 = new resolutionSyntax(1, 1, resolutionSyntax.DPCM);
173: rs2 = new resolutionSyntax(1, 2, resolutionSyntax.DPCM);
174: assertFalse(rs2.lessThanOrEquals(rs1));
175:
176: try {
177: rs2 = null;
178: rs1.lessThanOrEquals(rs2);
179: fail("lessThanOrEquals(ResolutionSyntax other) "
180: + "doesn't throw NullPointerException "
181: + "if other is null");
182: } catch (NullPointerException e) {
183: }
184: }
185:
186: public final void testToString() {
187: rs1 = new resolutionSyntax(500, 50, 10);
188: assertEquals("5000x500 dphi", rs1.toString());
189: //System.out.println(rs1.toString());
190: }
191:
192: public final void testToStringintString() {
193: rs1 = new resolutionSyntax(1024, 1034, 254);
194: assertEquals("1024x1034 dpcm", rs1.toString(254, "dpcm"));
195: //System.out.println(rs1.toString(254, "dpcm"));
196: }
197:
198: /*
199: * Auxiliary class
200: */
201: public class resolutionSyntax extends ResolutionSyntax {
202:
203: public resolutionSyntax(int a, int b, int c) {
204: super (a, b, c);
205: }
206:
207: public int getCrossFeedResolutionDphiEx() {
208: return getCrossFeedResolutionDphi();
209: }
210:
211: public int getFeedResolutionDphiEx() {
212: return getFeedResolutionDphi();
213: }
214: }
215:
216: }
|