001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * Portions Copyrighted 2007 Sun Microsystems, Inc.
027: */
028:
029: package org.netbeans.nbbuild;
030:
031: import junit.framework.TestCase;
032: import org.apache.tools.ant.types.FileSet;
033: import org.netbeans.junit.NbTestCase;
034:
035: /**
036: *
037: * @author Jaroslav Tulach
038: */
039: public class PrintIconTest extends NbTestCase {
040:
041: public PrintIconTest(String testName) {
042: super (testName);
043: }
044:
045: protected void setUp() throws Exception {
046: clearWorkDir();
047: super .setUp();
048: }
049:
050: protected void tearDown() throws Exception {
051: super .tearDown();
052: }
053:
054: public void testPrintOutSameIcons() throws Exception {
055: java.io.File img = PublicPackagesInProjectizedXMLTest
056: .extractResource("data/instanceBroken.gif");
057: java.io.File img2 = PublicPackagesInProjectizedXMLTest
058: .extractResource("data/instanceObject.gif");
059: java.io.File img3 = PublicPackagesInProjectizedXMLTest
060: .extractResource("data/instanceBroken.gif");
061: java.io.File out = PublicPackagesInProjectizedXMLTest
062: .extractString("");
063: out.delete();
064:
065: java.io.File f = PublicPackagesInProjectizedXMLTest
066: .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
067: + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
068: + " <taskdef name=\"printicon\" classname=\"org.netbeans.nbbuild.PrintIcon\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
069: + "<target name=\"all\" >"
070: + " <printicon duplicates='"
071: + out
072: + "'>"
073: + " <firstpool dir='"
074: + img.getParent()
075: + "'>"
076: + " <include name='"
077: + img.getName()
078: + "'/>"
079: + " <include name='"
080: + img2.getName()
081: + "'/>"
082: + " </firstpool>"
083: + " <secondpool dir='"
084: + img3.getParent()
085: + "'>"
086: + " <include name='"
087: + img3.getName()
088: + "'/>"
089: + " </secondpool>"
090: + " </printicon>" + "</target>" + "</project>");
091: PublicPackagesInProjectizedXMLTest.execute(f,
092: new String[] { "-verbose" });
093:
094: assertTrue("Exists: " + out, out.canRead());
095:
096: String file = PublicPackagesInProjectizedXMLTest.readFile(out);
097:
098: String[] threeParts = file.split("( |\n)+");
099: assertEquals(file, 6, threeParts.length);
100:
101: {
102: long hash = Long.parseLong(threeParts[0], 16);
103: assertEquals("Hash code is ee2ab8d3:\n" + file,
104: 0xee2ab8d3L, hash);
105: assertEquals("Name is from img:\n" + file, img.getName(),
106: threeParts[1]);
107: assertEquals("Full name is img:\n" + file, img.toURL()
108: .toExternalForm(), threeParts[2]);
109: }
110:
111: {
112: long hash = Long.parseLong(threeParts[3], 16);
113: assertEquals("Hash code is ee2ab8d3:\n" + file,
114: 0xee2ab8d3L, hash);
115: assertEquals("Name is from img:\n" + file, img3.getName(),
116: threeParts[4]);
117: assertEquals("Full name is img:\n" + file, img3.toURL()
118: .toExternalForm(), threeParts[5]);
119: }
120:
121: }
122:
123: public void testDuplicatesFromTheSameSet() throws Exception {
124: java.io.File img = PublicPackagesInProjectizedXMLTest
125: .extractResource("data/instanceBroken.gif");
126: java.io.File img2 = PublicPackagesInProjectizedXMLTest
127: .extractResource("data/instanceObject.gif");
128: java.io.File img3 = PublicPackagesInProjectizedXMLTest
129: .extractResource("data/instanceBroken.gif");
130: java.io.File out = PublicPackagesInProjectizedXMLTest
131: .extractString("");
132: out.delete();
133:
134: java.io.File f = PublicPackagesInProjectizedXMLTest
135: .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
136: + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
137: + " <taskdef name=\"printicon\" classname=\"org.netbeans.nbbuild.PrintIcon\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
138: + "<target name=\"all\" >"
139: + " <printicon duplicates='"
140: + out
141: + "'>"
142: + " <firstpool dir='"
143: + img.getParent()
144: + "'>"
145: + " <include name='"
146: + img.getName()
147: + "'/>"
148: + " <include name='"
149: + img2.getName()
150: + "'/>"
151: + " <include name='"
152: + img3.getName()
153: + "'/>"
154: + " </firstpool>"
155: + " </printicon>" + "</target>" + "</project>");
156: PublicPackagesInProjectizedXMLTest.execute(f,
157: new String[] { "-verbose" });
158:
159: assertTrue("Exists: " + out, out.canRead());
160:
161: String file = PublicPackagesInProjectizedXMLTest.readFile(out);
162:
163: String[] threeParts = file.split("( |\n)+");
164: assertEquals(file, 6, threeParts.length);
165:
166: {
167: long hash = Long.parseLong(threeParts[0], 16);
168: assertEquals("Hash code is ee2ab8d3:\n" + file,
169: 0xee2ab8d3L, hash);
170: assertEquals("Name is from img:\n" + file, img.getName(),
171: threeParts[1]);
172: assertEquals("Full name is img:\n" + file, img.toURL()
173: .toExternalForm(), threeParts[2]);
174: }
175:
176: {
177: long hash = Long.parseLong(threeParts[3], 16);
178: assertEquals("Hash code is ee2ab8d3:\n" + file,
179: 0xee2ab8d3L, hash);
180: assertEquals("Name is from img:\n" + file, img3.getName(),
181: threeParts[4]);
182: assertEquals("Full name is img:\n" + file, img3.toURL()
183: .toExternalForm(), threeParts[5]);
184: }
185:
186: }
187:
188: public void testBrokenImageThatCould() throws Exception {
189: doBrokenImageTest("data/columnIndex.gif");
190: }
191:
192: public void testBrokenImageThatCoul2() throws Exception {
193: doBrokenImageTest("data/Category.png");
194: }
195:
196: private void doBrokenImageTest(String res) throws Exception {
197: java.io.File img = PublicPackagesInProjectizedXMLTest
198: .extractResource(res);
199: java.io.File img2 = PublicPackagesInProjectizedXMLTest
200: .extractResource("data/instanceObject.gif");
201: java.io.File img3 = PublicPackagesInProjectizedXMLTest
202: .extractResource(res);
203: java.io.File out = PublicPackagesInProjectizedXMLTest
204: .extractString("");
205: out.delete();
206:
207: java.io.File f = PublicPackagesInProjectizedXMLTest
208: .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
209: + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
210: + " <taskdef name=\"printicon\" classname=\"org.netbeans.nbbuild.PrintIcon\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
211: + "<target name=\"all\" >"
212: + " <printicon duplicates='"
213: + out
214: + "'>"
215: + " <firstpool dir='"
216: + img.getParent()
217: + "'>"
218: + " <include name='"
219: + img.getName()
220: + "'/>"
221: + " <include name='"
222: + img2.getName()
223: + "'/>"
224: + " <include name='"
225: + img3.getName()
226: + "'/>"
227: + " </firstpool>"
228: + " </printicon>" + "</target>" + "</project>");
229: PublicPackagesInProjectizedXMLTest.execute(f,
230: new String[] { "-verbose" });
231:
232: assertTrue("Exists: " + out, out.canRead());
233:
234: String file = PublicPackagesInProjectizedXMLTest.readFile(out);
235:
236: String[] threeParts = file.split("( |\n)+");
237: assertEquals(file, 6, threeParts.length);
238:
239: long prevHash;
240: {
241: prevHash = Long.parseLong(threeParts[0], 16);
242: assertEquals("Name is from img:\n" + file, img.getName(),
243: threeParts[1]);
244: assertEquals("Full name is img:\n" + file, img.toURL()
245: .toExternalForm(), threeParts[2]);
246: }
247:
248: {
249: long hash = Long.parseLong(threeParts[3], 16);
250: assertEquals("Hash code is the same:\n" + file, prevHash,
251: hash);
252: assertEquals("Name is from img:\n" + file, img3.getName(),
253: threeParts[4]);
254: assertEquals("Full name is img:\n" + file, img3.toURL()
255: .toExternalForm(), threeParts[5]);
256: }
257:
258: }
259:
260: public void testPrintExtra() throws Exception {
261: java.io.File img = PublicPackagesInProjectizedXMLTest
262: .extractResource("data/instanceBroken.gif");
263: java.io.File img2 = PublicPackagesInProjectizedXMLTest
264: .extractResource("data/instanceObject.gif");
265: java.io.File img3 = PublicPackagesInProjectizedXMLTest
266: .extractResource("data/instanceBroken.gif");
267: java.io.File out = PublicPackagesInProjectizedXMLTest
268: .extractString("");
269: out.delete();
270:
271: java.io.File f = PublicPackagesInProjectizedXMLTest
272: .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
273: + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
274: + " <taskdef name=\"printicon\" classname=\"org.netbeans.nbbuild.PrintIcon\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
275: + "<target name=\"all\" >"
276: + " <printicon difference='"
277: + out
278: + "'>"
279: + " <firstpool dir='"
280: + img.getParent()
281: + "'>"
282: + " <include name='"
283: + img.getName()
284: + "'/>"
285: + " <include name='"
286: + img2.getName()
287: + "'/>"
288: + " </firstpool>"
289: + " <secondpool dir='"
290: + img3.getParent()
291: + "'>"
292: + " <include name='"
293: + img3.getName()
294: + "'/>"
295: + " </secondpool>"
296: + " </printicon>" + "</target>" + "</project>");
297: PublicPackagesInProjectizedXMLTest.execute(f,
298: new String[] { "-verbose" });
299:
300: assertTrue("Exists: " + out, out.canRead());
301:
302: String file = PublicPackagesInProjectizedXMLTest.readFile(out);
303:
304: if (!file.startsWith("-")) {
305: fail("Should start with - as one icon is missing in new version:\n"
306: + file);
307: } else {
308: file = file.substring(1);
309: }
310:
311: String[] threeParts = file.split("( |\n)+");
312: assertEquals(file, 3, threeParts.length);
313:
314: long hash = Long.parseLong(threeParts[0], 16);
315: assertEquals("Hash code is 10ba4f25:\n" + file, 0x10ba4f25L,
316: hash);
317: assertEquals("Name is from img2:\n" + file, img2.getName(),
318: threeParts[1]);
319: assertEquals("Full name is img2:\n" + file, img2.toURL()
320: .toExternalForm(), threeParts[2]);
321: }
322: }
|