KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > nbbuild > PrintIconTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * Portions Copyrighted 2007 Sun Microsystems, Inc.
16  */

17
18 package org.netbeans.nbbuild;
19
20 import junit.framework.TestCase;
21 import org.apache.tools.ant.types.FileSet;
22 import org.netbeans.junit.NbTestCase;
23
24 /**
25  *
26  * @author Jaroslav Tulach
27  */

28 public class PrintIconTest extends NbTestCase {
29     
30     public PrintIconTest(String JavaDoc testName) {
31         super(testName);
32     }
33     
34     protected void setUp() throws Exception JavaDoc {
35         clearWorkDir();
36         super.setUp();
37     }
38
39     protected void tearDown() throws Exception JavaDoc {
40         super.tearDown();
41     }
42
43     public void testPrintOutSameIcons() throws Exception JavaDoc {
44         java.io.File JavaDoc img = PublicPackagesInProjectizedXMLTest.extractResource("data/instanceBroken.gif");
45         java.io.File JavaDoc img2 = PublicPackagesInProjectizedXMLTest.extractResource("data/instanceObject.gif");
46         java.io.File JavaDoc img3 = PublicPackagesInProjectizedXMLTest.extractResource("data/instanceBroken.gif");
47         java.io.File JavaDoc out = PublicPackagesInProjectizedXMLTest.extractString("");
48         out.delete();
49         
50         java.io.File JavaDoc f = PublicPackagesInProjectizedXMLTest.extractString (
51             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
52             "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
53             " <taskdef name=\"printicon\" classname=\"org.netbeans.nbbuild.PrintIcon\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
54             "<target name=\"all\" >" +
55             " <printicon duplicates='" + out + "'>" +
56             " <firstpool dir='" + img.getParent() + "'>" +
57             " <include name='" + img.getName() + "'/>" +
58             " <include name='" + img2.getName() + "'/>" +
59             " </firstpool>" +
60             " <secondpool dir='" + img3.getParent() + "'>" +
61             " <include name='" + img3.getName() + "'/>" +
62             " </secondpool>" +
63             " </printicon>" +
64             "</target>" +
65             "</project>"
66         );
67         PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose" });
68         
69         assertTrue("Exists: " + out, out.canRead());
70         
71         String JavaDoc file = PublicPackagesInProjectizedXMLTest.readFile(out);
72         
73         String JavaDoc[] threeParts = file.split("( |\n)+");
74         assertEquals(file, 6, threeParts.length);
75
76         {
77             long hash = Long.parseLong(threeParts[0], 16);
78             assertEquals("Hash code is ee2ab8d3:\n" + file, 0xee2ab8d3L, hash);
79             assertEquals("Name is from img:\n" + file, img.getName(), threeParts[1]);
80             assertEquals("Full name is img:\n" + file, img.toURL().toExternalForm(), threeParts[2]);
81         }
82         
83         {
84             long hash = Long.parseLong(threeParts[3], 16);
85             assertEquals("Hash code is ee2ab8d3:\n" + file, 0xee2ab8d3L, hash);
86             assertEquals("Name is from img:\n" + file, img3.getName(), threeParts[4]);
87             assertEquals("Full name is img:\n" + file, img3.toURL().toExternalForm(), threeParts[5]);
88         }
89         
90     }
91     
92     
93     public void testDuplicatesFromTheSameSet() throws Exception JavaDoc {
94         java.io.File JavaDoc img = PublicPackagesInProjectizedXMLTest.extractResource("data/instanceBroken.gif");
95         java.io.File JavaDoc img2 = PublicPackagesInProjectizedXMLTest.extractResource("data/instanceObject.gif");
96         java.io.File JavaDoc img3 = PublicPackagesInProjectizedXMLTest.extractResource("data/instanceBroken.gif");
97         java.io.File JavaDoc out = PublicPackagesInProjectizedXMLTest.extractString("");
98         out.delete();
99         
100         java.io.File JavaDoc f = PublicPackagesInProjectizedXMLTest.extractString (
101             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
102             "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
103             " <taskdef name=\"printicon\" classname=\"org.netbeans.nbbuild.PrintIcon\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
104             "<target name=\"all\" >" +
105             " <printicon duplicates='" + out + "'>" +
106             " <firstpool dir='" + img.getParent() + "'>" +
107             " <include name='" + img.getName() + "'/>" +
108             " <include name='" + img2.getName() + "'/>" +
109             " <include name='" + img3.getName() + "'/>" +
110             " </firstpool>" +
111             " </printicon>" +
112             "</target>" +
113             "</project>"
114         );
115         PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose" });
116         
117         assertTrue("Exists: " + out, out.canRead());
118         
119         String JavaDoc file = PublicPackagesInProjectizedXMLTest.readFile(out);
120         
121         String JavaDoc[] threeParts = file.split("( |\n)+");
122         assertEquals(file, 6, threeParts.length);
123
124         {
125             long hash = Long.parseLong(threeParts[0], 16);
126             assertEquals("Hash code is ee2ab8d3:\n" + file, 0xee2ab8d3L, hash);
127             assertEquals("Name is from img:\n" + file, img.getName(), threeParts[1]);
128             assertEquals("Full name is img:\n" + file, img.toURL().toExternalForm(), threeParts[2]);
129         }
130         
131         {
132             long hash = Long.parseLong(threeParts[3], 16);
133             assertEquals("Hash code is ee2ab8d3:\n" + file, 0xee2ab8d3L, hash);
134             assertEquals("Name is from img:\n" + file, img3.getName(), threeParts[4]);
135             assertEquals("Full name is img:\n" + file, img3.toURL().toExternalForm(), threeParts[5]);
136         }
137         
138     }
139
140     public void testBrokenImageThatCould() throws Exception JavaDoc {
141         doBrokenImageTest("data/columnIndex.gif");
142     }
143     public void testBrokenImageThatCoul2() throws Exception JavaDoc {
144         doBrokenImageTest("data/Category.png");
145     }
146     
147     private void doBrokenImageTest(String JavaDoc res) throws Exception JavaDoc {
148         java.io.File JavaDoc img = PublicPackagesInProjectizedXMLTest.extractResource(res);
149         java.io.File JavaDoc img2 = PublicPackagesInProjectizedXMLTest.extractResource("data/instanceObject.gif");
150         java.io.File JavaDoc img3 = PublicPackagesInProjectizedXMLTest.extractResource(res);
151         java.io.File JavaDoc out = PublicPackagesInProjectizedXMLTest.extractString("");
152         out.delete();
153         
154         java.io.File JavaDoc f = PublicPackagesInProjectizedXMLTest.extractString (
155             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
156             "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
157             " <taskdef name=\"printicon\" classname=\"org.netbeans.nbbuild.PrintIcon\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
158             "<target name=\"all\" >" +
159             " <printicon duplicates='" + out + "'>" +
160             " <firstpool dir='" + img.getParent() + "'>" +
161             " <include name='" + img.getName() + "'/>" +
162             " <include name='" + img2.getName() + "'/>" +
163             " <include name='" + img3.getName() + "'/>" +
164             " </firstpool>" +
165             " </printicon>" +
166             "</target>" +
167             "</project>"
168         );
169         PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose" });
170         
171         assertTrue("Exists: " + out, out.canRead());
172         
173         String JavaDoc file = PublicPackagesInProjectizedXMLTest.readFile(out);
174         
175         String JavaDoc[] threeParts = file.split("( |\n)+");
176         assertEquals(file, 6, threeParts.length);
177
178         long prevHash;
179         {
180             prevHash = Long.parseLong(threeParts[0], 16);
181             assertEquals("Name is from img:\n" + file, img.getName(), threeParts[1]);
182             assertEquals("Full name is img:\n" + file, img.toURL().toExternalForm(), threeParts[2]);
183         }
184         
185         {
186             long hash = Long.parseLong(threeParts[3], 16);
187             assertEquals("Hash code is the same:\n" + file, prevHash, hash);
188             assertEquals("Name is from img:\n" + file, img3.getName(), threeParts[4]);
189             assertEquals("Full name is img:\n" + file, img3.toURL().toExternalForm(), threeParts[5]);
190         }
191         
192     }
193     
194     public void testPrintExtra() throws Exception JavaDoc {
195         java.io.File JavaDoc img = PublicPackagesInProjectizedXMLTest.extractResource("data/instanceBroken.gif");
196         java.io.File JavaDoc img2 = PublicPackagesInProjectizedXMLTest.extractResource("data/instanceObject.gif");
197         java.io.File JavaDoc img3 = PublicPackagesInProjectizedXMLTest.extractResource("data/instanceBroken.gif");
198         java.io.File JavaDoc out = PublicPackagesInProjectizedXMLTest.extractString("");
199         out.delete();
200         
201         java.io.File JavaDoc f = PublicPackagesInProjectizedXMLTest.extractString (
202             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
203             "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
204             " <taskdef name=\"printicon\" classname=\"org.netbeans.nbbuild.PrintIcon\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
205             "<target name=\"all\" >" +
206             " <printicon difference='" + out + "'>" +
207             " <firstpool dir='" + img.getParent() + "'>" +
208             " <include name='" + img.getName() + "'/>" +
209             " <include name='" + img2.getName() + "'/>" +
210             " </firstpool>" +
211             " <secondpool dir='" + img3.getParent() + "'>" +
212             " <include name='" + img3.getName() + "'/>" +
213             " </secondpool>" +
214             " </printicon>" +
215             "</target>" +
216             "</project>"
217         );
218         PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose" });
219         
220         assertTrue("Exists: " + out, out.canRead());
221         
222         String JavaDoc file = PublicPackagesInProjectizedXMLTest.readFile(out);
223         
224         if (!file.startsWith("-")) {
225             fail("Should start with - as one icon is missing in new version:\n" + file);
226         } else {
227             file = file.substring(1);
228         }
229         
230         String JavaDoc[] threeParts = file.split("( |\n)+");
231         assertEquals(file, 3, threeParts.length);
232         
233         long hash = Long.parseLong(threeParts[0], 16);
234         assertEquals("Hash code is 10ba4f25:\n" + file, 0x10ba4f25L, hash);
235         assertEquals("Name is from img2:\n" + file, img2.getName(), threeParts[1]);
236         assertEquals("Full name is img2:\n" + file, img2.toURL().toExternalForm(), threeParts[2]);
237     }
238 }
239
Popular Tags