001: /*
002: * @(#) $Header: /cvs/jai-operators/src/tests/ca/forklabs/media/jai/DescriptorUtilTest.java,v 1.2 2007/06/11 22:00:53 forklabs Exp $
003: *
004: * Copyright (C) 2007 Forklabs Daniel Léonard
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: */
020:
021: package ca.forklabs.media.jai;
022:
023: import java.awt.image.renderable.ParameterBlock;
024: import java.util.Arrays;
025: import java.util.Collection;
026: import java.util.Iterator;
027: import java.util.LinkedList;
028: import javax.media.jai.registry.CollectionRegistryMode;
029: import javax.media.jai.registry.RenderableCollectionRegistryMode;
030: import javax.media.jai.registry.RenderableRegistryMode;
031: import javax.media.jai.registry.RenderedRegistryMode;
032: import junit.framework.TestCase;
033: import ca.forklabs.media.jai.mock.MockRenderableImage;
034: import ca.forklabs.media.jai.mock.MockRenderedImage;
035:
036: /**
037: * Class {@code DescriptorUtilTest} tests class {@link DescriptorUtil}.
038: *
039: * @author <a href="mailto:forklabs at dev.java.net?subject=ca.forklabs.media.jai.DescriptorUtilTest">Daniel Léonard</a>
040: * @version $Revision: 1.2 $
041: */
042: @SuppressWarnings("nls")
043: public class DescriptorUtilTest extends TestCase {
044:
045: //---------------------------
046: // Constructors
047: //---------------------------
048:
049: /**
050: * Constructor.
051: * @param name the name of this test.
052: */
053: public DescriptorUtilTest(String name) {
054: super (name);
055: }
056:
057: //---------------------------
058: // Test methods
059: //---------------------------
060:
061: /**
062: * Tests {@link DescriptorUtil#isRenderedMode(String)}.
063: */
064: public void testIsRenderedMode() {
065: assertTrue(DescriptorUtil.isRenderedMode("rendered"));
066: assertTrue(DescriptorUtil.isRenderedMode("ReNdErEd"));
067: assertTrue(DescriptorUtil
068: .isRenderedMode(RenderedRegistryMode.MODE_NAME));
069: assertFalse(DescriptorUtil.isRenderedMode("foo"));
070: }
071:
072: /**
073: * Tests {@link DescriptorUtil#isRenderableMode(String)}.
074: */
075: public void testIsRenderableMode() {
076: assertTrue(DescriptorUtil.isRenderableMode("renderable"));
077: assertTrue(DescriptorUtil.isRenderableMode("rEnDeRaBlE"));
078: assertTrue(DescriptorUtil
079: .isRenderableMode(RenderableRegistryMode.MODE_NAME));
080: assertFalse(DescriptorUtil.isRenderableMode("foo"));
081: }
082:
083: /**
084: * Tests {@link DescriptorUtil#isCollectionMode(String)}.
085: */
086: public void testIsCollectionMode() {
087: assertTrue(DescriptorUtil.isCollectionMode("collection"));
088: assertTrue(DescriptorUtil.isCollectionMode("CoLLectioN"));
089: assertTrue(DescriptorUtil
090: .isCollectionMode(CollectionRegistryMode.MODE_NAME));
091: assertFalse(DescriptorUtil.isCollectionMode("foo"));
092: }
093:
094: /**
095: * Tests {@link DescriptorUtil#isRenderableCollectionMode(String)}.
096: */
097: public void testIsRenderableCollectionMode() {
098: assertTrue(DescriptorUtil
099: .isRenderableCollectionMode("renderableCollection"));
100: assertTrue(DescriptorUtil
101: .isRenderableCollectionMode("ReNdErAbLeCoLlEcTiOn"));
102: assertTrue(DescriptorUtil
103: .isRenderableCollectionMode(RenderableCollectionRegistryMode.MODE_NAME));
104: assertFalse(DescriptorUtil.isRenderableCollectionMode("foo"));
105: }
106:
107: /**
108: * Tests {@link DescriptorUtil#isSourceRendered(Object)}.
109: */
110: public void testIsSourceRendered() {
111: assertTrue(DescriptorUtil
112: .isSourceRendered(new MockRenderedImage()));
113: assertFalse(DescriptorUtil.isSourceRendered("foo"));
114: }
115:
116: /**
117: * Tests {@link DescriptorUtil#isSourceRenderable(Object)}.
118: */
119: public void testIsSourceRenderable() {
120: assertTrue(DescriptorUtil
121: .isSourceRenderable(new MockRenderableImage()));
122: assertFalse(DescriptorUtil.isSourceRenderable("foo"));
123: }
124:
125: /**
126: * Tests {@link DescriptorUtil#isSourceCollection(Object)}.
127: */
128: public void testIsSourceCollection() {
129: assertTrue(DescriptorUtil.isSourceCollection(Arrays.asList()));
130: assertFalse(DescriptorUtil.isSourceCollection("foo"));
131: }
132:
133: /**
134: * Tests {@link DescriptorUtil#areAllSourceRendered(Iterable)}.
135: */
136: @SuppressWarnings("unchecked")
137: public void testAreAllSourceRendered() {
138: Collection sources = new LinkedList();
139: sources.add(new MockRenderedImage());
140: sources.add(new MockRenderedImage());
141:
142: assertTrue(DescriptorUtil.areAllSourceRendered(sources));
143:
144: sources.add(new MockRenderableImage());
145:
146: assertFalse(DescriptorUtil.areAllSourceRendered(sources));
147: }
148:
149: /**
150: * Tests {@link DescriptorUtil#areAllSourceRenderable(Iterable)}.
151: */
152: @SuppressWarnings("unchecked")
153: public void testAreAllSourceRenderable() {
154: Collection sources = new LinkedList();
155: sources.add(new MockRenderableImage());
156: sources.add(new MockRenderableImage());
157:
158: assertTrue(DescriptorUtil.areAllSourceRenderable(sources));
159:
160: sources.add(new MockRenderedImage());
161:
162: assertFalse(DescriptorUtil.areAllSourceRenderable(sources));
163: }
164:
165: /**
166: * Tests {@link DescriptorUtil#collateSources(ParameterBlock)}.
167: */
168: @SuppressWarnings("unchecked")
169: public void testCollateSources() {
170: Object o1 = new Object();
171: Object o2 = new Object();
172: Object o3 = new Object();
173: Object o4 = new Object();
174: Object o5 = new Object();
175: Object o6 = new Object();
176: Object o7 = new Object();
177:
178: ParameterBlock pb = new ParameterBlock().addSource(o1)
179: .addSource(Arrays.asList(o2, o3)).addSource(o4)
180: .addSource(o5).addSource(new Object[] { o6, o7, });
181:
182: DescriptorUtil.collateSources(pb);
183:
184: assertEquals(1, pb.getNumSources());
185:
186: Collection sources = (Collection) pb.getSource(0);
187:
188: assertEquals(7, sources.size());
189:
190: Iterator iterator = sources.iterator();
191:
192: assertSame(o1, iterator.next());
193: assertSame(o2, iterator.next());
194: assertSame(o3, iterator.next());
195: assertSame(o4, iterator.next());
196: assertSame(o5, iterator.next());
197: assertSame(o6, iterator.next());
198: assertSame(o7, iterator.next());
199: }
200:
201: //---------------------------
202: // Class methods
203: //---------------------------
204:
205: /**
206: * Runs only this test.
207: * @param args ignored.
208: */
209: public static void main(String... args) {
210: junit.swingui.TestRunner.run(DescriptorUtilTest.class);
211: }
212:
213: }
214:
215: /*
216: * $Log: DescriptorUtilTest.java,v $
217: * Revision 1.2 2007/06/11 22:00:53 forklabs
218: * Source collation now takes array and treats them as collection.
219: *
220: * Revision 1.1 2007/06/07 21:44:31 forklabs
221: * Utilities for help descriptor validation.
222: *
223: */
|