1 /* 2 This Java source file was generated by test-to-java.xsl 3 and is a derived work from the source document. 4 The source document contained the following notice: 5 6 7 8 Copyright (c) 2001 World Wide Web Consortium, 9 (Massachusetts Institute of Technology, Institut National de 10 Recherche en Informatique et en Automatique, Keio University). All 11 Rights Reserved. This program is distributed under the W3C's Software 12 Intellectual Property License. This program is distributed in the 13 hope that it will be useful, but WITHOUT ANY WARRANTY; without even 14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15 PURPOSE. 16 17 See W3C License http://www.w3.org/Consortium/Legal/ for more details. 18 19 20 */ 21 22 package tests.org.w3c.dom; 23 24 import dalvik.annotation.TestTargets; 25 import dalvik.annotation.TestLevel; 26 import dalvik.annotation.TestTargetNew; 27 import dalvik.annotation.TestTargetClass; 28 29 import java.util.ArrayList; 30 import java.util.List; 31 32 import org.w3c.dom.DOMImplementation; 33 import org.w3c.dom.Document; 34 import org.w3c.dom.DOMException; 35 import org.w3c.dom.DocumentType; 36 37 import javax.xml.parsers.DocumentBuilder; 38 39 /** 40 * The "createDocumentType(qualifiedName,publicId,systemId)" method for a 41 * DOMImplementation should raise NAMESPACE_ERR DOMException if qualifiedName is 42 * malformed. 43 * 44 * Retrieve the DOMImplementation on the XMLNS Document. Invoke method 45 * createDocumentType(qualifiedName,publicId,systemId) on the retrieved 46 * DOMImplementation with qualifiedName being the literal string 47 * "prefix::local", publicId as "STAFF", and systemId as "staff". Method should 48 * raise NAMESPACE_ERR DOMException. 49 * 50 * @author NIST 51 * @author Mary Brady 52 * @see <a 53 * href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NAMESPACE_ERR'])">http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NAMESPACE_ERR'])</a> 54 * @see <a 55 * href="http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-DOM-createDocType">http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-DOM-createDocType</a> 56 * @see <a 57 * href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('Level-2-Core-DOM-createDocType')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NAMESPACE_ERR'])">http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('Level-2-Core-DOM-createDocType')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NAMESPACE_ERR'])</a> 58 */ 59 @TestTargetClass(DOMImplementation.class) 60 public final class CreateDocumentType extends DOMTestCase { 61 62 DOMDocumentBuilderFactory factory; 63 64 DocumentBuilder builder; 65 66 protected void setUp() throws Exception { 67 super.setUp(); 68 try { 69 factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory 70 .getConfiguration1()); 71 builder = factory.getBuilder(); 72 } catch (Exception e) { 73 fail("Unexpected exception" + e.getMessage()); 74 } 75 } 76 77 protected void tearDown() throws Exception { 78 factory = null; 79 builder = null; 80 super.tearDown(); 81 } 82 83 /** 84 * Runs the test case. 85 * 86 * @throws Throwable 87 * Any uncaught exception causes test to fail 88 */ 89 @TestTargetNew( 90 level = TestLevel.PARTIAL, 91 notes = "Doesn't verify null as parameters.", 92 method = "createDocumentType", 93 args = {java.lang.String.class, java.lang.String.class, java.lang.String.class} 94 ) 95 public void testCreateDocumentType1() throws Throwable { 96 String publicId = "STAFF"; 97 String systemId = "staff.xml"; 98 String malformedName = "prefix::local"; 99 Document doc; 100 DOMImplementation domImpl; 101 102 doc = (Document) load("staffNS", builder); 103 domImpl = doc.getImplementation(); 104 105 { 106 boolean success = false; 107 try { 108 domImpl.createDocumentType(malformedName, publicId, systemId); 109 } catch (DOMException ex) { 110 success = (ex.code == DOMException.NAMESPACE_ERR); 111 } 112 assertTrue("throw_NAMESPACE_ERR", success); 113 } 114 } 115 @TestTargetNew( 116 level = TestLevel.PARTIAL, 117 notes = "Doesn't verify null as parameters.", 118 method = "createDocumentType", 119 args = {java.lang.String.class, java.lang.String.class, java.lang.String.class} 120 ) 121 public void testCreateDocumentType2() throws Throwable { 122 String publicId = "http://www.localhost.com/"; 123 String systemId = "myDoc.dtd"; 124 String qualifiedName; 125 Document doc; 126 127 DOMImplementation domImpl; 128 List<String> illegalQNames = new ArrayList<String>(); 129 illegalQNames.add("edi:{"); 130 illegalQNames.add("edi:}"); 131 illegalQNames.add("edi:~"); 132 illegalQNames.add("edi:'"); 133 illegalQNames.add("edi:!"); 134 illegalQNames.add("edi:@"); 135 illegalQNames.add("edi:#"); 136 illegalQNames.add("edi:$"); 137 illegalQNames.add("edi:%"); 138 illegalQNames.add("edi:^"); 139 illegalQNames.add("edi:&"); 140 illegalQNames.add("edi:*"); 141 illegalQNames.add("edi:("); 142 illegalQNames.add("edi:)"); 143 illegalQNames.add("edi:+"); 144 illegalQNames.add("edi:="); 145 illegalQNames.add("edi:["); 146 illegalQNames.add("edi:]"); 147 illegalQNames.add("edi:\\"); 148 illegalQNames.add("edi:/"); 149 illegalQNames.add("edi:;"); 150 illegalQNames.add("edi:`"); 151 illegalQNames.add("edi:<"); 152 illegalQNames.add("edi:>"); 153 illegalQNames.add("edi:,"); 154 illegalQNames.add("edi:a "); 155 illegalQNames.add("edi:\""); 156 157 doc = (Document) load("staffNS", builder); 158 for (int indexN1009A = 0; indexN1009A < illegalQNames.size(); indexN1009A++) { 159 qualifiedName = (String) illegalQNames.get(indexN1009A); 160 domImpl = doc.getImplementation(); 161 162 { 163 boolean success = false; 164 try { 165 domImpl.createDocumentType(qualifiedName, publicId, 166 systemId); 167 } catch (DOMException ex) { 168 success = (ex.code == DOMException.INVALID_CHARACTER_ERR); 169 } 170 assertTrue("throw_INVALID_CHARACTER_ERR", success); 171 } 172 } 173 } 174 @TestTargetNew( 175 level = TestLevel.PARTIAL, 176 notes = "Doesn't verify null as parameters.", 177 method = "createDocumentType", 178 args = {java.lang.String.class, java.lang.String.class, java.lang.String.class} 179 ) 180 public void testCreateDocumentType3() throws Throwable { 181 182 String qualifiedName = "prefix:myDoc"; 183 String publicId = "http://www.localhost.com"; 184 String systemId = "myDoc.dtd"; 185 Document doc; 186 DOMImplementation domImpl; 187 DocumentType newType = null; 188 189 String nodeName; 190 String nodeValue; 191 doc = (Document) load("staffNS", builder); 192 domImpl = doc.getImplementation(); 193 newType = domImpl.createDocumentType(qualifiedName, publicId, systemId); 194 nodeName = newType.getNodeName(); 195 assertEquals("nodeName", "prefix:myDoc", nodeName); 196 nodeValue = newType.getNodeValue(); 197 assertNull("nodeValue", nodeValue); 198 } 199 @TestTargetNew( 200 level = TestLevel.PARTIAL, 201 notes = "Doesn't verify null as parameters.", 202 method = "createDocumentType", 203 args = {java.lang.String.class, java.lang.String.class, java.lang.String.class} 204 ) 205 public void testCreateDocumentType4() throws Throwable { 206 String publicId = "http://www.example.com/"; 207 String systemId = "myDoc.dtd"; 208 209 DOMImplementation domImpl; 210 domImpl = builder.getDOMImplementation(); 211 212 { 213 boolean success = false; 214 try { 215 domImpl.createDocumentType("", publicId, systemId); 216 } catch (DOMException ex) { 217 success = (ex.code == DOMException.NAMESPACE_ERR); 218 } 219 assertTrue("throw_NAMESPACE_ERR", success); 220 } 221 } 222 } 223