1 2 17 18 19 package org.apache.poi.poifs.filesystem; 20 21 import junit.framework.*; 22 23 28 29 public class TestDocumentDescriptor 30 extends TestCase 31 { 32 33 38 39 public TestDocumentDescriptor(String name) 40 { 41 super(name); 42 } 43 44 47 48 public void testEquality() 49 { 50 String [] names = 51 { 52 "c1", "c2", "c3", "c4", "c5" 53 }; 54 POIFSDocumentPath a1 = new POIFSDocumentPath(); 55 POIFSDocumentPath a2 = new POIFSDocumentPath(null); 56 POIFSDocumentPath a3 = new POIFSDocumentPath(new String [ 0 ]); 57 POIFSDocumentPath a4 = new POIFSDocumentPath(a1, null); 58 POIFSDocumentPath a5 = new POIFSDocumentPath(a1, 59 new String [ 0 ]); 60 POIFSDocumentPath[] paths = 61 { 62 a1, a2, a3, a4, a5 63 }; 64 65 for (int j = 0; j < paths.length; j++) 66 { 67 for (int k = 0; k < paths.length; k++) 68 { 69 for (int m = 0; m < names.length; m++) 70 { 71 DocumentDescriptor d1 = new DocumentDescriptor(paths[ j ], 72 names[ m ]); 73 74 for (int n = 0; n < names.length; n++) 75 { 76 DocumentDescriptor d2 = 77 new DocumentDescriptor(paths[ k ], names[ n ]); 78 79 if (m == n) 80 { 81 assertEquals("" + j + "," + k + "," + m + "," 82 + n, d1, d2); 83 } 84 else 85 { 86 assertTrue("" + j + "," + k + "," + m + "," + n, 87 !d1.equals(d2)); 88 } 89 } 90 } 91 } 92 } 93 a2 = new POIFSDocumentPath(a1, new String [] 94 { 95 "foo" 96 }); 97 a3 = new POIFSDocumentPath(a2, new String [] 98 { 99 "bar" 100 }); 101 a4 = new POIFSDocumentPath(a3, new String [] 102 { 103 "fubar" 104 }); 105 a5 = new POIFSDocumentPath(a4, new String [] 106 { 107 "foobar" 108 }); 109 POIFSDocumentPath[] builtUpPaths = 110 { 111 a1, a2, a3, a4, a5 112 }; 113 POIFSDocumentPath[] fullPaths = 114 { 115 new POIFSDocumentPath(), new POIFSDocumentPath(new String [] 116 { 117 "foo" 118 }), new POIFSDocumentPath(new String [] 119 { 120 "foo", "bar" 121 }), new POIFSDocumentPath(new String [] 122 { 123 "foo", "bar", "fubar" 124 }), new POIFSDocumentPath(new String [] 125 { 126 "foo", "bar", "fubar", "foobar" 127 }) 128 }; 129 130 for (int k = 0; k < builtUpPaths.length; k++) 131 { 132 for (int j = 0; j < fullPaths.length; j++) 133 { 134 for (int m = 0; m < names.length; m++) 135 { 136 DocumentDescriptor d1 = 137 new DocumentDescriptor(fullPaths[ j ], names[ m ]); 138 139 for (int n = 0; n < names.length; n++) 140 { 141 DocumentDescriptor d2 = 142 new DocumentDescriptor(builtUpPaths[ k ], 143 names[ n ]); 144 145 if ((k == j) && (m == n)) 146 { 147 assertEquals("" + j + "," + k + "," + m + "," 148 + n, d1, d2); 149 } 150 else 151 { 152 assertTrue("" + j + "," + k + "," + m + "," + n, 153 !(d1.equals(d2))); 154 } 155 } 156 } 157 } 158 } 159 POIFSDocumentPath[] badPaths = 160 { 161 new POIFSDocumentPath(new String [] 162 { 163 "_foo" 164 }), new POIFSDocumentPath(new String [] 165 { 166 "foo", "_bar" 167 }), new POIFSDocumentPath(new String [] 168 { 169 "foo", "bar", "_fubar" 170 }), new POIFSDocumentPath(new String [] 171 { 172 "foo", "bar", "fubar", "_foobar" 173 }) 174 }; 175 176 for (int k = 0; k < builtUpPaths.length; k++) 177 { 178 for (int j = 0; j < badPaths.length; j++) 179 { 180 for (int m = 0; m < names.length; m++) 181 { 182 DocumentDescriptor d1 = 183 new DocumentDescriptor(badPaths[ j ], names[ m ]); 184 185 for (int n = 0; n < names.length; n++) 186 { 187 DocumentDescriptor d2 = 188 new DocumentDescriptor(builtUpPaths[ k ], 189 names[ n ]); 190 191 assertTrue("" + j + "," + k + "," + m + "," + n, 192 !(d1.equals(d2))); 193 } 194 } 195 } 196 } 197 } 198 199 204 205 public static void main(String [] ignored_args) 206 { 207 System.out.println( 208 "Testing org.apache.poi.poifs.eventfilesystem.DocumentDescriptor"); 209 junit.textui.TestRunner.run(TestDocumentDescriptor.class); 210 } 211 } 212 | Popular Tags |