1 19 package org.netbeans.tax; 20 21 import java.util.Arrays ; 22 import java.util.List ; 23 import junit.textui.TestRunner; 24 import org.netbeans.tax.TreeElementDecl.ContentType; 25 import org.netbeans.tax.decl.*; 26 27 31 public class FactoryTest extends AbstractFactoryTest { 32 33 34 public FactoryTest(String testName) { 35 super(testName); 36 } 37 38 42 public void testAttlistDecl() throws Exception { 43 createAttlistDecl("elementName", "<!ATTLIST elementName>"); 44 45 createAttlistDeclInvalid(null); 46 } 47 48 public void testAttribute() throws Exception { 49 createAttribute("name", "value", "name=\"value\""); 50 52 createAttributeInvalid(null, null); 53 createAttributeInvalid("name", null); 54 createAttributeInvalid(null, "value"); 55 createAttributeInvalid("na me", "value"); 56 createAttributeInvalid("na;me", "value"); 57 createAttributeInvalid("1name", "value"); 58 } 59 60 public void testCDATASection() throws Exception { 61 createCDATASection("<cdata ]] > < � data>", "<![CDATA[<cdata ]] > < � data>]]>"); 62 63 createCDATASectionInvalid(null); 64 createCDATASectionInvalid("aa ]]> bbb"); 65 } 66 67 public void testCharacterReference() throws Exception { 68 createCharacterReference("#35", "#"); 69 createCharacterReference("#x35", "5"); 70 71 createCharacterReferenceInvalid(null); 72 createCharacterReferenceInvalid(""); 73 createCharacterReferenceInvalid("#"); 74 createCharacterReferenceInvalid("#x"); 75 createCharacterReferenceInvalid("#xg"); 76 createCharacterReferenceInvalid("#;"); 77 createCharacterReferenceInvalid("# "); 78 } 79 80 public void testComment() throws Exception { 81 createComment("comment - comment", "<!--comment - comment-->"); 82 createComment("", "<!---->"); 83 84 createCommentInvalid(null); 85 createCommentInvalid("bad--bad"); 86 } 87 88 public void testConditionalSection() throws Exception { 89 createConditionalSection(true, "<![ INCLUDE []]>"); 90 createConditionalSection(false, "<![ IGNORE []]>"); 91 } 92 93 public void testDTD() throws Exception { 94 createDTD("1.0", "UTF-16", "<?xml version=\"1.0\" encoding=\"UTF-16\"?>"); 95 createDTD(null, "UTF-8", "<?xml encoding=\"UTF-8\"?>"); 96 createDTD(null, null, ""); 97 98 createDTDInvalid(null, "encodig"); 99 createDTDInvalid("version", null); 100 createDTDInvalid("1.0", "encodig"); 101 createDTDInvalid("version", "UTF-16"); 102 } 103 104 public void testDocument() throws Exception { 105 createDocument(null, null, null, ""); 106 createDocument("1.0", "ISO-8859-2", "no", "<?xml version=\"1.0\" encoding=\"ISO-8859-2\" standalone=\"no\"?>"); 107 createDocument("1.0", null, "yes", "<?xml version=\"1.0\" standalone=\"yes\"?>"); 108 createDocument("1.0", "ASCII", null, "<?xml version=\"1.0\" encoding=\"ASCII\"?>"); 109 createDocument("1.0", null, null, "<?xml version=\"1.0\"?>"); 110 111 createDocumentInvalid("2.0", "ISO-8859-2", "no"); 112 createDocumentInvalid("10", "ISO-8859-2", "no"); 113 createDocumentInvalid("", "ISO-8859-2", "no"); 114 createDocumentInvalid("2.0", null, "no"); 115 createDocumentInvalid(".0", "ISO-8859-2", null); 116 createDocumentInvalid(null, "ISO-8859-2", "no"); 117 createDocumentInvalid(null, null, "no"); 118 createDocumentInvalid(null, "ISO-8859-2", null); 119 } 120 121 public void testDocumentFragment() throws Exception { 122 createDocumentFragment(null, null, ""); 123 createDocumentFragment("1.0", "ISO-8859-2", "<?xml version=\"1.0\" encoding=\"ISO-8859-2\"?>"); 124 createDocumentFragment(null, "ISO-8859-2", "<?xml encoding=\"ISO-8859-2\"?>"); 125 126 createDocumentFragmentInvalid("1.0", null); 127 createDocumentFragmentInvalid("3.0", "UTF-8"); 128 createDocumentFragmentInvalid("1.0", "UTF-80"); 129 } 130 131 public void testDocumentType() throws Exception { 132 createDocumentType("elementName", "<!DOCTYPE elementName>"); 133 134 createDocumentType("element", "pub_id", "sys_id", "<!DOCTYPE element PUBLIC \"pub_id\" \"sys_id\">"); 135 createDocumentType("element", "pub_id", "", "<!DOCTYPE element PUBLIC \"pub_id\" \"\">"); 136 createDocumentType("element", "pub_id", null, "<!DOCTYPE element PUBLIC \"pub_id\" \"\">"); 137 createDocumentType("element", "", "sys_id", "<!DOCTYPE element PUBLIC \"\" \"sys_id\">"); 138 createDocumentType("element", null, "sys_id", "<!DOCTYPE element SYSTEM \"sys_id\">"); 139 140 createDocumentTypeInvalid(null); 141 createDocumentTypeInvalid(""); 142 createDocumentTypeInvalid("a c"); 143 createDocumentTypeInvalid("a>c"); 144 createDocumentTypeInvalid("a%c"); 145 createDocumentTypeInvalid("a%ref;c"); 146 147 createDocumentTypeInvalid("", "pub_id", "sys_id"); 148 createDocumentTypeInvalid(null, "pub_id", "sys_id"); 149 createDocumentTypeInvalid("1element", "pub_id", "sys_id"); 150 createDocumentTypeInvalid("ele ment", "pub_id", "sys_id"); 151 createDocumentTypeInvalid("element", "pub_id", "\'\""); 152 154 155 } 156 157 public void testElement() throws Exception { 158 createElement("element", "<element></element>"); 159 createElement("ns:element", "<ns:element></ns:element>"); 160 161 createElementInvalid(null); 162 createElementInvalid(""); 163 createElementInvalid("1a"); 164 createElementInvalid("a b"); 165 createElementInvalid("a&b"); 166 createElementInvalid("a%b"); 167 } 168 169 public void testElementDecl() throws Exception { 170 List content; 171 ContentType type; 172 173 createElementDecl("element", new ANYType(), "<!ELEMENT element ANY>"); 174 createElementDecl("element", new EMPTYType(), "<!ELEMENT element EMPTY>"); 175 176 content = Arrays.asList(new Object [] {new NameType("ele1"), new NameType("ele2","")}); 177 type = new SequenceType(content); 178 type.setMultiplicity("+"); 179 createElementDecl("element", type, "<!ELEMENT element ( ele1, ele2 )+>"); 180 181 type = new ChoiceType(content); 182 type.setMultiplicity("*"); 183 createElementDecl("element", type, "<!ELEMENT element ( ele1 | ele2 )*>"); 184 185 type = new MixedType(content); 186 type.setMultiplicity("+"); 187 createElementDecl("element", type, "<!ELEMENT element ( #PCDATA | ele1 | ele2 )+>"); 188 189 197 createElementDeclInvalid(null, (ContentType) null); 198 } 199 200 public void testEntityDecl() throws Exception { 201 boolean parameter; 202 String name, text; 203 String publicId, systemId; 204 String notationName; 205 206 createEntityDecl("name", "text", "<!ENTITY name \"text\">"); 208 createEntityDeclInvalid(null, null); 209 createEntityDeclInvalid("name", null); 210 createEntityDeclInvalid(null, "text"); 211 212 createEntityDecl(true, "name", "text", "<!ENTITY % name \"text\">"); 214 215 for (int i = 0; i < 8; i++) { 216 parameter = ((i & 1) == 0) ? false : true; 217 name = ((i & 2) == 0) ? null : "name"; 218 text = ((i & 4) == 0) ? null : "text"; 219 if (name == null || text == null) { 220 createEntityDeclInvalid(parameter, name, text); 221 } 222 } 223 224 createEntityDecl("name", "publicId", "systemId", "<!ENTITY name PUBLIC \"publicId\" \"systemId\">"); 226 createEntityDecl("name", null, "systemId", "<!ENTITY name SYSTEM \"systemId\">"); 227 createEntityDecl(false, "name", "publicId", "systemId", "<!ENTITY name PUBLIC \"publicId\" \"systemId\">"); 228 createEntityDecl(false, "name", null, "systemId", "<!ENTITY name SYSTEM \"systemId\">"); 229 230 for (int i = 0; i < 8; i++) { 231 name = ((i & 1) == 0) ? null : "name"; 232 publicId = ((i & 2) == 0) ? null : "publicId"; 233 systemId = ((i & 4) == 0) ? null : "systemId"; 234 235 if (name == null || systemId == null) { 236 createEntityDeclInvalid(name, publicId, systemId); 237 } 238 } 239 240 createEntityDecl(true, "name", "publicId", "systemId", "<!ENTITY % name PUBLIC \"publicId\" \"systemId\">"); 242 createEntityDecl(true, "name", null, "systemId", "<!ENTITY % name SYSTEM \"systemId\">"); 243 244 for (int i = 0; i < 16; i++) { 245 name = ((i & 1) == 0) ? null : "name"; 246 publicId = ((i & 2) == 0) ? null : "publicId"; 247 systemId = ((i & 4) == 0) ? null : "systemId"; 248 parameter = ((i & 8) == 0) ? true : false; 249 250 if (name == null || systemId == null) { 251 createEntityDeclInvalid(parameter, name, publicId, systemId); 252 } 253 } 254 255 createEntityDecl("name", "publicId", "systemId", "notationName", "<!ENTITY name PUBLIC \"publicId\" \"systemId\" NDATA notationName>"); 257 createEntityDecl("name", null, "systemId", "notationName", "<!ENTITY name SYSTEM \"systemId\" NDATA notationName>"); 258 259 for (int i = 0; i < 16; i++) { 260 name = ((i & 1) == 0) ? null : "name"; 261 publicId = ((i & 2) == 0) ? null : "publicId"; 262 systemId = ((i & 4) == 0) ? null : "systemId"; 263 notationName = ((i & 8) == 0) ? null : "notationName"; 264 265 if (name == null || systemId == null || notationName == null) { 266 createEntityDeclInvalid(name, publicId, systemId, notationName); 267 } 268 } 269 } 270 271 public void testGeneralEntityReference() throws Exception { 272 createGeneralEntityReference(":g1e_r-e.f", "&:g1e_r-e.f;"); 273 274 createGeneralEntityReferenceInvalid(null); 275 createGeneralEntityReferenceInvalid("&"); 276 createGeneralEntityReferenceInvalid(";"); 277 createGeneralEntityReferenceInvalid("%"); 278 } 279 280 public void testNotationDecl() throws Exception { 281 String name; 282 String publicId; 283 String systemId; 284 TreeNotationDecl node; 285 286 createNotationDecl("name", "publicId", "systemId", "<!NOTATION name PUBLIC \"publicId\" \"systemId\">"); 287 createNotationDecl("name", null, "systemId", "<!NOTATION name SYSTEM \"systemId\">"); 288 createNotationDecl("name", "publicId", null, "<!NOTATION name PUBLIC \"publicId\">"); 289 290 for (int i = 0; i < 8; i++) { 291 name = ((i & 1) == 0) ? null : "name"; 292 publicId = ((i & 2) == 0) ? null : "publicId"; 293 systemId = ((i & 4) == 0) ? null : "systemId"; 294 295 if (name == null || (systemId == null && publicId == null)) { 296 createNotationDeclInvalid(name, publicId, systemId); 297 } 298 } 299 } 300 301 public void testParameterEntityReference() throws Exception { 302 createParameterEntityReference(":p1e_r-e.f", "%:p1e_r-e.f;"); 303 304 createParameterEntityReferenceInvalid(null); 305 createParameterEntityReferenceInvalid("&"); 306 createParameterEntityReferenceInvalid(";"); 307 createParameterEntityReferenceInvalid("%"); 308 } 309 310 public void testProcessingInstruction() throws Exception { 311 createProcessingInstruction("target", "pi-data", "<?target pi-data?>"); 312 createProcessingInstruction("target", "&%4;?<<>>]]>--> <!--", "<?target &%4;?<<>>]]>--> <!--?>"); 313 314 createProcessingInstructionInvalid(null, null); 315 createProcessingInstructionInvalid("target", null); 316 createProcessingInstructionInvalid("xml", "pi-data"); 317 createProcessingInstructionInvalid("XmL", "pi-data"); 318 createProcessingInstructionInvalid("&", "pi-data"); 319 } 320 321 public void testText() throws Exception { 322 createText(" text >--> % @ # $ ", " text >--> % @ # $ "); 323 createTextInvalid("<"); 324 createTextInvalid("&"); 325 } 327 328 332 public static void main(String args[]) { 333 TestRunner.run(FactoryTest.class); 334 } 335 } 336 | Popular Tags |