001: /*
002: * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003: * Copyright (C) 2002-2005 NextApp, Inc.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package nextapp.echo2.app.test;
031:
032: import nextapp.echo2.app.Extent;
033: import junit.framework.TestCase;
034:
035: /**
036: * Unit test(s) for the <code>nextapp.echo2.app.Extent</code> property
037: * value object.
038: */
039: public class ExtentTest extends TestCase {
040:
041: private static final Extent _50_CENTIMETERS = new Extent(50,
042: Extent.CM);
043: private static final Extent _50_EM = new Extent(50, Extent.EM);
044: private static final Extent _50_EX = new Extent(50, Extent.EX);
045: private static final Extent _50_INCHES = new Extent(50, Extent.IN);
046: private static final Extent _50_MILLIMETERS = new Extent(50,
047: Extent.MM);
048: private static final Extent _50_PERCENT = new Extent(50,
049: Extent.PERCENT);
050: private static final Extent _50_PICAS = new Extent(50, Extent.PC);
051: private static final Extent _50_PIXELS = new Extent(50, Extent.PX);
052: private static final Extent _50_POINT = new Extent(50, Extent.PT);
053:
054: /**
055: * Test extent addition.
056: */
057: public void testAdd() {
058: assertEquals(Extent.add(_50_EM, _50_EM), new Extent(100,
059: Extent.EM));
060: }
061:
062: /**
063: * Test equality.
064: */
065: public void testEquals() {
066: assertEquals(new Extent(20, Extent.CM), new Extent(20,
067: Extent.CM));
068: assertFalse(new Extent(20, Extent.CM).equals(new Extent(21,
069: Extent.CM)));
070: assertFalse(new Extent(20, Extent.MM).equals(new Extent(21,
071: Extent.CM)));
072: }
073:
074: /**
075: * Test <code>Comparable</code> implementation.
076: */
077: public void testCompareTo() {
078: assertTrue(_50_INCHES.compareTo(_50_INCHES) == 0);
079: assertTrue(_50_CENTIMETERS.compareTo(_50_INCHES) < 0);
080: assertTrue(_50_MILLIMETERS.compareTo(_50_INCHES) < 0);
081: assertTrue(_50_PICAS.compareTo(_50_INCHES) < 0);
082: assertTrue(_50_POINT.compareTo(_50_INCHES) < 0);
083: assertTrue(_50_INCHES.compareTo(_50_CENTIMETERS) == 0 - _50_CENTIMETERS
084: .compareTo(_50_INCHES));
085: assertTrue(_50_POINT.compareTo(_50_INCHES) == 0 - _50_INCHES
086: .compareTo(_50_POINT));
087:
088: assertTrue(_50_EX.compareTo(_50_PIXELS) != 0);
089: assertTrue(_50_EX.compareTo(_50_PIXELS) == 0 - _50_PIXELS
090: .compareTo(_50_EX));
091: }
092:
093: /**
094: * Test <code>isComparableTo()</code>.
095: */
096: public void testIsComparableTo() {
097: assertTrue(_50_CENTIMETERS.isComparableTo(_50_MILLIMETERS));
098: assertTrue(_50_INCHES.isComparableTo(_50_MILLIMETERS));
099: assertTrue(_50_PICAS.isComparableTo(_50_MILLIMETERS));
100: assertTrue(_50_POINT.isComparableTo(_50_MILLIMETERS));
101: assertTrue(_50_PIXELS.isComparableTo(_50_PIXELS));
102: assertFalse(_50_PERCENT.isComparableTo(_50_MILLIMETERS));
103: assertFalse(_50_PERCENT.isComparableTo(_50_PIXELS));
104: }
105:
106: /**
107: * Test <code>isEnglish()</code>.
108: */
109: public void testIsEnglish() {
110: assertFalse(_50_CENTIMETERS.isEnglish());
111: assertFalse(_50_EM.isEnglish());
112: assertFalse(_50_EX.isEnglish());
113: assertTrue(_50_INCHES.isEnglish());
114: assertFalse(_50_MILLIMETERS.isEnglish());
115: assertFalse(_50_PERCENT.isEnglish());
116: assertTrue(_50_PICAS.isEnglish());
117: assertFalse(_50_PIXELS.isEnglish());
118: assertTrue(_50_POINT.isEnglish());
119: }
120:
121: /**
122: * Test <code>isSI()</code>.
123: */
124: public void testIsSI() {
125: assertTrue(_50_CENTIMETERS.isSI());
126: assertFalse(_50_EM.isSI());
127: assertFalse(_50_EX.isSI());
128: assertFalse(_50_INCHES.isSI());
129: assertTrue(_50_MILLIMETERS.isSI());
130: assertFalse(_50_PERCENT.isSI());
131: assertFalse(_50_PICAS.isSI());
132: assertFalse(_50_PIXELS.isSI());
133: assertFalse(_50_POINT.isSI());
134: }
135:
136: /**
137: * Test <code>isPercentage()</code>.
138: */
139: public void testIsPercentage() {
140: assertFalse(_50_CENTIMETERS.isPercentage());
141: assertFalse(_50_EM.isPercentage());
142: assertFalse(_50_EX.isPercentage());
143: assertFalse(_50_INCHES.isPercentage());
144: assertFalse(_50_MILLIMETERS.isPercentage());
145: assertTrue(_50_PERCENT.isPercentage());
146: assertFalse(_50_PICAS.isPercentage());
147: assertFalse(_50_PIXELS.isPercentage());
148: assertFalse(_50_POINT.isPercentage());
149: }
150:
151: /**
152: * Test <code>isPrint()</code>.
153: */
154: public void testIsPrint() {
155: assertTrue(_50_CENTIMETERS.isPrint());
156: assertFalse(_50_EM.isPrint());
157: assertFalse(_50_EX.isPrint());
158: assertTrue(_50_INCHES.isPrint());
159: assertTrue(_50_MILLIMETERS.isPrint());
160: assertFalse(_50_PERCENT.isPrint());
161: assertTrue(_50_PICAS.isPrint());
162: assertFalse(_50_PIXELS.isPrint());
163: assertTrue(_50_POINT.isPrint());
164: }
165:
166: /**
167: * Test conversion to millimeters.
168: */
169: public void testToMm() {
170: assertEquals(20, new Extent(20, Extent.MM).toMm());
171: assertEquals(20, new Extent(2, Extent.CM).toMm());
172: assertEquals(2540, new Extent(100, Extent.IN).toMm());
173: assertEquals(2540, new Extent(7200, Extent.PT).toMm());
174: assertEquals(2540, new Extent(600, Extent.PC).toMm());
175:
176: try {
177: new Extent(1, Extent.EM).toMm();
178: fail("Did not throw IllegalStateException.");
179: } catch (IllegalStateException ex) {
180: // Expected.
181: }
182:
183: try {
184: new Extent(1, Extent.EX).toMm();
185: fail("Did not throw IllegalStateException.");
186: } catch (IllegalStateException ex) {
187: // Expected.
188: }
189:
190: try {
191: new Extent(1, Extent.PERCENT).toMm();
192: fail("Did not throw IllegalStateException.");
193: } catch (IllegalStateException ex) {
194: // Expected.
195: }
196:
197: try {
198: new Extent(1, Extent.PX).toMm();
199: fail("Did not throw IllegalStateException.");
200: } catch (IllegalStateException ex) {
201: // Expected.
202: }
203: }
204:
205: /**
206: * Test conversion to points.
207: */
208: public void testToPoint() {
209: assertEquals(20, new Extent(20, Extent.PT).toPoint());
210: assertEquals(7200, new Extent(2540, Extent.MM).toPoint());
211: assertEquals(7200, new Extent(254, Extent.CM).toPoint());
212: assertEquals(7200, new Extent(100, Extent.IN).toPoint());
213: assertEquals(7200, new Extent(600, Extent.PC).toPoint());
214:
215: try {
216: new Extent(1, Extent.EM).toPoint();
217: fail("Did not throw IllegalStateException.");
218: } catch (IllegalStateException ex) {
219: // Expected.
220: }
221:
222: try {
223: new Extent(1, Extent.EX).toPoint();
224: fail("Did not throw IllegalStateException.");
225: } catch (IllegalStateException ex) {
226: // Expected.
227: }
228:
229: try {
230: new Extent(1, Extent.PERCENT).toPoint();
231: fail("Did not throw IllegalStateException.");
232: } catch (IllegalStateException ex) {
233: // Expected.
234: }
235:
236: try {
237: new Extent(1, Extent.PX).toPoint();
238: fail("Did not throw IllegalStateException.");
239: } catch (IllegalStateException ex) {
240: // Expected.
241: }
242: }
243: }
|