Source Code Cross Referenced for ApplyToCollectionDescriptorTest.java in  » 6.0-JDK-Modules » Java-Advanced-Imaging » ca » forklabs » media » jai » operator » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » Java Advanced Imaging » ca.forklabs.media.jai.operator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#) $Header: /cvs/jai-operators/src/tests/ca/forklabs/media/jai/operator/ApplyToCollectionDescriptorTest.java,v 1.2 2007/06/13 18:57:21 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.operator;
022:
023:        import java.awt.RenderingHints;
024:        import java.awt.image.Raster;
025:        import java.awt.image.RenderedImage;
026:        import java.awt.image.renderable.ParameterBlock;
027:        import java.util.Arrays;
028:        import java.util.Collection;
029:        import java.util.Iterator;
030:        import java.util.Locale;
031:        import javax.media.jai.JAI;
032:        import junit.framework.TestCase;
033:        import ca.forklabs.baselib.util.UnaryFunction;
034:        import ca.forklabs.media.jai.ParameterBlockUtil;
035:        import ca.forklabs.media.jai.operator.ApplyToCollectionDescriptor;
036:
037:        /**
038:         * Class {@code ApplyToCollectionDescriptorTest} tests class
039:         * {@link ApplyToCollectionDescriptor}.
040:         *
041:         * @author   <a href="mailto:forklabs at dev.java.net?subject=ca.forklabs.media.jai.operator.ApplyToCollectionDescriptorTest">Daniel Léonard</a>
042:         * @version $Revision: 1.2 $
043:         */
044:        @SuppressWarnings("nls")
045:        public class ApplyToCollectionDescriptorTest extends TestCase {
046:
047:            //---------------------------
048:            // Constructors
049:            //---------------------------
050:
051:            /**
052:             * Constructor.
053:             * @param   name   the name of this test.
054:             */
055:            public ApplyToCollectionDescriptorTest(String name) {
056:                super (name);
057:            }
058:
059:            //---------------------------
060:            // Test methods
061:            //---------------------------
062:
063:            private void checkImage(Object source, float expected) {
064:                assertTrue(source instanceof  RenderedImage);
065:
066:                RenderedImage image = (RenderedImage) source;
067:                Raster raster = image.getData();
068:
069:                assertEquals(0, raster.getMinX());
070:                assertEquals(0, raster.getMinY());
071:                assertEquals(2, raster.getWidth());
072:                assertEquals(2, raster.getHeight());
073:                assertEquals(1, raster.getNumBands());
074:
075:                float[] pixel = new float[] { expected, };
076:                float[] got = null;
077:
078:                assertTrue(Arrays.equals(pixel, raster.getPixel(0, 0, got)));
079:                assertTrue(Arrays.equals(pixel, raster.getPixel(1, 0, got)));
080:                assertTrue(Arrays.equals(pixel, raster.getPixel(2, 0, got)));
081:                assertTrue(Arrays.equals(pixel, raster.getPixel(3, 0, got)));
082:            }
083:
084:            /**
085:             * Tests
086:             * {@link ApplyToCollectionDescriptor#createCollection(java.util.Collection, String, ParameterBlock, RenderingHints)}.
087:             */
088:            @SuppressWarnings("boxing")
089:            public void testCreateCollection() {
090:                RenderedImage[] images = new RenderedImage[] {
091:                        JAI.create("constant", ParameterBlockUtil
092:                                .createConstantParameterBlock(2.0f, 2.0f,
093:                                        new Float[] { 4.0f, })),
094:                        JAI.create("constant", ParameterBlockUtil
095:                                .createConstantParameterBlock(2.0f, 2.0f,
096:                                        new Float[] { 9.0f, })),
097:                        JAI.create("constant", ParameterBlockUtil
098:                                .createConstantParameterBlock(2.0f, 2.0f,
099:                                        new Float[] { 16.0f, })),
100:                        JAI.create("constant", ParameterBlockUtil
101:                                .createConstantParameterBlock(2.0f, 2.0f,
102:                                        new Float[] { 25.0f, })), };
103:                Collection<RenderedImage> sources = Arrays.asList(images);
104:
105:                String name = UnaryFunctionDescriptor.NAME;
106:                ParameterBlock pb = new ParameterBlock()
107:                        .add(new UnaryFunction<Double, Double>() {
108:                            @Override
109:                            public Double invoke(Double value) {
110:                                return Math.sqrt(value);
111:                            }
112:                        });
113:
114:                // check with the convenience method
115:                Collection<?> sinks = ApplyToCollectionDescriptor
116:                        .createCollection(sources, name, pb, null);
117:
118:                assertEquals(4, sinks.size());
119:
120:                Iterator<?> iter = sinks.iterator();
121:                checkImage(iter.next(), 2.0f);
122:                checkImage(iter.next(), 3.0f);
123:                checkImage(iter.next(), 4.0f);
124:                checkImage(iter.next(), 5.0f);
125:
126:                // check with multiple sources
127:                ParameterBlock pb2 = new ParameterBlock().addSource(images[0])
128:                        .addSource(images[1]).addSource(images[2]).addSource(
129:                                images[3]).add(name).add(pb);
130:                sinks = JAI.createCollection("applytocollection", pb2, null);
131:
132:                assertEquals(4, sinks.size());
133:
134:                iter = sinks.iterator();
135:                checkImage(iter.next(), 2.0f);
136:                checkImage(iter.next(), 3.0f);
137:                checkImage(iter.next(), 4.0f);
138:                checkImage(iter.next(), 5.0f);
139:            }
140:
141:            /**
142:             * Tests the English messages.
143:             */
144:            public void testEnglishMessages() {
145:                Locale locale = Locale.getDefault();
146:                Locale.setDefault(Locale.ENGLISH);
147:
148:                try {
149:                    String[] expected = new String[] {
150:                            "Applies the same operator to a collection of images",
151:                            "The operation name", "The parameter block", };
152:
153:                    String[] got = new String[] {
154:                            ApplyToCollectionDescriptor.getDescription(),
155:                            ApplyToCollectionDescriptor.getArg0Description(),
156:                            ApplyToCollectionDescriptor.getArg1Description(), };
157:
158:                    assertEquals(expected.length, got.length);
159:
160:                    for (int i = 0; i < expected.length; i++) {
161:                        assertEquals("[" + i + "]", expected[i], got[i]);
162:                    }
163:                } finally {
164:                    Locale.setDefault(locale);
165:                }
166:            }
167:
168:            /**
169:             * Tests the French messages.
170:             */
171:            public void testFrenchMessages() {
172:                Locale locale = Locale.getDefault();
173:                Locale.setDefault(Locale.FRENCH);
174:
175:                try {
176:                    String[] expected = new String[] {
177:                            "Applique une même opération à une collection d'image",
178:                            "Le nom de l'opération", "Le bloc de paramêtres", };
179:
180:                    String[] got = new String[] {
181:                            ApplyToCollectionDescriptor.getDescription(),
182:                            ApplyToCollectionDescriptor.getArg0Description(),
183:                            ApplyToCollectionDescriptor.getArg1Description(), };
184:
185:                    assertEquals(expected.length, got.length);
186:
187:                    for (int i = 0; i < expected.length; i++) {
188:                        assertEquals("[" + i + "]", expected[i], got[i]);
189:                    }
190:                } finally {
191:                    Locale.setDefault(locale);
192:                }
193:            }
194:
195:            //---------------------------
196:            // Class methods
197:            //---------------------------
198:
199:            /**
200:             * Runs only this test.
201:             * @param   args   ignored.
202:             */
203:            public static void main(String... args) {
204:                junit.swingui.TestRunner
205:                        .run(ApplyToCollectionDescriptorTest.class);
206:            }
207:
208:        }
209:
210:        /*
211:         * $Log: ApplyToCollectionDescriptorTest.java,v $
212:         * Revision 1.2  2007/06/13 18:57:21  forklabs
213:         * Changed parent to use CollectionDescriptor.
214:         *
215:         * Revision 1.1  2007/05/25 21:21:45  forklabs
216:         * Operator "applytocollection"
217:         *
218:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.