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.standard;
021:
022: import org.apache.harmony.x.print.attributes.PPDMediaSizeName;
023:
024: import junit.framework.TestCase;
025:
026: @SuppressWarnings("static-access")
027: public class MediaSizeTest extends TestCase {
028:
029: /*
030: * MediaSize constructor testing.
031: */
032: public final void testMediaSize() {
033: MediaSize ms = new MediaSize(200, 300, 1000, MediaSizeName.A);
034: assertEquals(200, (int) ms.getX(1000));
035: assertEquals(300, (int) ms.getY(1000));
036:
037: assertFalse(200 == (int) MediaSize.Engineering.A.getX(1000));
038: assertFalse(300 == (int) MediaSize.Engineering.A.getY(1000));
039: }
040:
041: /*
042: * equals(Object object) method testing.
043: */
044: public final void testEquals() {
045:
046: MediaSize ms1 = MediaSize.ISO.B0;
047: MediaSize ms2 = MediaSize.ISO.B0;
048: assertTrue(ms1.equals(ms1));
049: ms2 = MediaSize.JIS.B0;
050: assertFalse(ms1.equals(ms2));
051: ms2 = null;
052: assertFalse(ms1.equals(ms2));
053: }
054:
055: /*
056: * findMedia(float x, float y, int units) method testing.
057: * Tests that findMedia(..) gives correct results on big figures.
058: */
059: public final void testFindMedia() {
060:
061: MediaSizeName msn1 = new mediaSizeName(111);
062: MediaSizeName msn2 = new mediaSizeName(112);
063: MediaSizeName msn3 = new mediaSizeName(113);
064: MediaSize ms1 = new MediaSize(Integer.MAX_VALUE / 15,
065: Integer.MAX_VALUE / 15, 1, msn1);
066:
067: MediaSize ms2 = new MediaSize(Integer.MAX_VALUE / 5,
068: Integer.MAX_VALUE / 5, 1, msn2);
069: MediaSize ms3 = new MediaSize(Integer.MAX_VALUE,
070: Integer.MAX_VALUE, 1, msn3);
071: assertEquals(msn2, MediaSize.findMedia(Integer.MAX_VALUE / 4,
072: Integer.MAX_VALUE / 4, 1));
073: assertEquals(msn3, MediaSize.findMedia(Float.MAX_VALUE,
074: Float.MAX_VALUE, 1));
075: }
076:
077: /*
078: * findMedia(float x, float y, int units) method testing.
079: * Tests that JIS_B0 is found as the biggest media from all
080: * standard media sheets and ISO_A10 is found as the smallest
081: * media from all standard media sheets.
082: */
083: public final void testFindMedia1() {
084:
085: assertTrue((MediaSizeName.JIS_B0 == MediaSize.findMedia(5000,
086: 5000, MediaSize.MM))
087: || (PPDMediaSizeName.B0 == MediaSize.findMedia(5000,
088: 5000, MediaSize.MM)));
089:
090: assertTrue((MediaSizeName.ISO_A10 == MediaSize.findMedia(20,
091: 20, MediaSize.MM))
092: || (PPDMediaSizeName.A10 == MediaSize.findMedia(20, 20,
093: MediaSize.MM)));
094: }
095:
096: /*
097: * findMedia(float x, float y, int units) method testing.
098: * Simple check on standard media sheets.
099: */
100: public final void testFindMedia2() {
101:
102: assertEquals(MediaSizeName.EXECUTIVE, MediaSize.findMedia(
103: 7.25f, 10.5f, MediaSize.INCH));
104:
105: MediaSizeName found = MediaSize.findMedia(8.5f, 11f,
106: MediaSize.INCH);
107: if (found != MediaSizeName.A
108: && found != MediaSizeName.NA_LETTER) {
109: fail("MediaSize.findMedia(8.5f, 11f, MediaSize.INCH) = "
110: + MediaSize.findMedia(8.5f, 11f, MediaSize.INCH));
111: }
112:
113: assertEquals(MediaSizeName.JAPANESE_DOUBLE_POSTCARD, MediaSize
114: .findMedia(148, 200, MediaSize.MM));
115:
116: found = MediaSize.findMedia(11, 17, MediaSize.INCH);
117: if (found != MediaSizeName.TABLOID
118: && found != MediaSizeName.LEDGER
119: && found != MediaSizeName.B) {
120: fail("MediaSize.findMedia(11, 17, MediaSize.INCH) = "
121: + MediaSize.findMedia(8.5f, 11f, MediaSize.INCH));
122: }
123:
124: assertEquals(MediaSizeName.NA_5X7, MediaSize.findMedia(5, 7,
125: MediaSize.INCH));
126:
127: }
128:
129: /*
130: * findMedia(float x, float y, int units) method testing.
131: * Tests that findMedia(..) finds the closest media sheet.
132: */
133: public final void testFindMedia3() {
134:
135: assertEquals(MediaSizeName.ISO_A4, MediaSize.findMedia(
136: MediaSize.ISO.A4.getX(MediaSize.MM) + 1,
137: MediaSize.ISO.A4.getY(MediaSize.MM) + 1, MediaSize.MM));
138:
139: MediaSizeName msn1 = new mediaSizeName(91);
140: MediaSizeName msn2 = new mediaSizeName(92);
141: MediaSize ms1 = new MediaSize(0.01f, 0.01f, 100, msn1);
142: MediaSize ms2 = new MediaSize(0.02f, 0.02f, 10, msn2);
143:
144: assertEquals(msn2, MediaSize.findMedia(0.00017f, 0.00017f, 1));
145: }
146:
147: /*
148: * getCategory() method testing.
149: */
150: public final void testGetCategory() {
151: MediaSize ms = MediaSize.ISO.A0;
152: assertEquals(MediaSize.class, ms.getCategory());
153: }
154:
155: /*
156: * getMediaSizeForName(MediaSizeName media) method testing.
157: * Tests that getMediaSizeForName(..) did mapping between MediaSize
158: * and MediaSizeName, but standard media sizes didn't remove.
159: */
160: public final void testGetMediaSizeForName() {
161:
162: //new mapping
163: MediaSize ms1 = new MediaSize(1, 1, 100000, MediaSizeName.A);
164:
165: assertEquals(ms1, MediaSize
166: .getMediaSizeForName(MediaSizeName.A));
167:
168: assertEquals(MediaSizeName.A, MediaSize.findMedia(1, 1, 100000));
169: //System.out.println("findMedia(1, 1, 100000) " +
170: //MediaSize.findMedia(1, 1 , 100000));
171:
172: MediaSizeName found = MediaSize.findMedia(8.5f, 11f,
173: MediaSize.INCH);
174: //System.out.println("findMedia(8.5, 11, MediaSize.INCH) = " +
175: //MediaSize.findMedia(8.5f, 11f, MediaSize.INCH));
176: if (found != MediaSizeName.A
177: && found != MediaSizeName.NA_LETTER) {
178: fail("findMedia(8.5, 11, MediaSize.INCH) = "
179: + MediaSize.findMedia(8.5f, 11f, MediaSize.INCH));
180: }
181:
182: assertEquals(MediaSize.NA.LEGAL, MediaSize
183: .getMediaSizeForName(MediaSizeName.NA_LEGAL));
184: assertEquals(MediaSize.Other.LEDGER, MediaSize
185: .getMediaSizeForName(MediaSizeName.LEDGER));
186:
187: }
188:
189: /*
190: * getMediaSizeName() method testing.
191: */
192: public final void testGetMediaSizeName() {
193: MediaSize ms = MediaSize.ISO.A0;
194: assertEquals(MediaSizeName.ISO_A0, ms.getMediaSizeName());
195: ms = MediaSize.JIS.B0;
196: assertEquals(MediaSizeName.JIS_B0, ms.getMediaSizeName());
197:
198: ms = new MediaSize(30, 30, MediaSize.INCH);
199: assertNull(ms.getMediaSizeName());
200: }
201:
202: /*
203: * getName() method testing.
204: */
205: public final void testGetName() {
206: MediaSize ms = MediaSize.ISO.A0;
207: assertEquals("media-size", ms.getName());
208: }
209:
210: /*
211: * Auxiliary class
212: */
213: @SuppressWarnings("serial")
214: public class mediaSizeName extends MediaSizeName {
215:
216: public mediaSizeName(int value) {
217: super(value);
218: }
219: }
220:
221: }
|