1 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 28 public class PrintIconTest extends NbTestCase { 29 30 public PrintIconTest(String testName) { 31 super(testName); 32 } 33 34 protected void setUp() throws Exception { 35 clearWorkDir(); 36 super.setUp(); 37 } 38 39 protected void tearDown() throws Exception { 40 super.tearDown(); 41 } 42 43 public void testPrintOutSameIcons() throws Exception { 44 java.io.File img = PublicPackagesInProjectizedXMLTest.extractResource("data/instanceBroken.gif"); 45 java.io.File img2 = PublicPackagesInProjectizedXMLTest.extractResource("data/instanceObject.gif"); 46 java.io.File img3 = PublicPackagesInProjectizedXMLTest.extractResource("data/instanceBroken.gif"); 47 java.io.File out = PublicPackagesInProjectizedXMLTest.extractString(""); 48 out.delete(); 49 50 java.io.File 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 [] { "-verbose" }); 68 69 assertTrue("Exists: " + out, out.canRead()); 70 71 String file = PublicPackagesInProjectizedXMLTest.readFile(out); 72 73 String [] 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 { 94 java.io.File img = PublicPackagesInProjectizedXMLTest.extractResource("data/instanceBroken.gif"); 95 java.io.File img2 = PublicPackagesInProjectizedXMLTest.extractResource("data/instanceObject.gif"); 96 java.io.File img3 = PublicPackagesInProjectizedXMLTest.extractResource("data/instanceBroken.gif"); 97 java.io.File out = PublicPackagesInProjectizedXMLTest.extractString(""); 98 out.delete(); 99 100 java.io.File 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 [] { "-verbose" }); 116 117 assertTrue("Exists: " + out, out.canRead()); 118 119 String file = PublicPackagesInProjectizedXMLTest.readFile(out); 120 121 String [] 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 { 141 doBrokenImageTest("data/columnIndex.gif"); 142 } 143 public void testBrokenImageThatCoul2() throws Exception { 144 doBrokenImageTest("data/Category.png"); 145 } 146 147 private void doBrokenImageTest(String res) throws Exception { 148 java.io.File img = PublicPackagesInProjectizedXMLTest.extractResource(res); 149 java.io.File img2 = PublicPackagesInProjectizedXMLTest.extractResource("data/instanceObject.gif"); 150 java.io.File img3 = PublicPackagesInProjectizedXMLTest.extractResource(res); 151 java.io.File out = PublicPackagesInProjectizedXMLTest.extractString(""); 152 out.delete(); 153 154 java.io.File 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 [] { "-verbose" }); 170 171 assertTrue("Exists: " + out, out.canRead()); 172 173 String file = PublicPackagesInProjectizedXMLTest.readFile(out); 174 175 String [] 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 { 195 java.io.File img = PublicPackagesInProjectizedXMLTest.extractResource("data/instanceBroken.gif"); 196 java.io.File img2 = PublicPackagesInProjectizedXMLTest.extractResource("data/instanceObject.gif"); 197 java.io.File img3 = PublicPackagesInProjectizedXMLTest.extractResource("data/instanceBroken.gif"); 198 java.io.File out = PublicPackagesInProjectizedXMLTest.extractString(""); 199 out.delete(); 200 201 java.io.File 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 [] { "-verbose" }); 219 220 assertTrue("Exists: " + out, out.canRead()); 221 222 String 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 [] 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 |