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:
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
17 See W3C License http://www.w3.org/Consortium/Legal/ for more details.
22 package tests.org.w3c.dom;
24 import dalvik.annotation.TestTargets;
25 import dalvik.annotation.TestLevel;
26 import dalvik.annotation.TestTargetNew;
27 import dalvik.annotation.TestTargetClass;
29 import java.util.ArrayList;
30 import java.util.List;
32 import org.w3c.dom.DOMImplementation;
33 import org.w3c.dom.Document;
34 import org.w3c.dom.DocumentType;
35 import org.w3c.dom.DOMException;
37 import javax.xml.parsers.DocumentBuilder;
40 * The "createDocument(namespaceURI,qualifiedName,doctype)" method for a
41 * DOMImplementation should raise NAMESPACE_ERR DOMException if parameter
42 * qualifiedName is malformed.
44 * Retrieve the DOMImplementation on the XMLNS Document. Invoke method
45 * createDocument(namespaceURI,qualifiedName,doctype) on the retrieved
46 * DOMImplementation with namespaceURI being the literal string
47 * "http://www.ecommerce.org/", qualifiedName as "prefix::local", and doctype as
48 * null. Method should raise NAMESPACE_ERR DOMException.
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>
55 * href="http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-DOM-createDocument">http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-DOM-createDocument</a>
57 * href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('Level-2-Core-DOM-createDocument')/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-createDocument')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NAMESPACE_ERR'])</a>
59 @TestTargetClass(DOMImplementation.class)
60 public final class CreateDocument extends DOMTestCase {
62 DOMDocumentBuilderFactory factory;
64 DocumentBuilder builder;
66 protected void setUp() throws Exception {
69 factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
70 .getConfiguration1());
71 builder = factory.getBuilder();
72 } catch (Exception e) {
73 fail("Unexpected exception" + e.getMessage());
77 protected void tearDown() throws Exception {
87 * Any uncaught exception causes test to fail
90 level = TestLevel.PARTIAL,
91 notes = "Doesn't verify null as parameters.",
92 method = "createDocument",
93 args = {java.lang.String.class, java.lang.String.class, org.w3c.dom.DocumentType.class}
95 public void testCreateDocument1() throws Throwable {
96 String namespaceURI = "http://www.ecommerce.org/";
97 String malformedName = "prefix::local";
99 DocumentType docType = null;
101 DOMImplementation domImpl;
103 doc = (Document) load("staffNS", builder);
104 domImpl = doc.getImplementation();
106 boolean success = false;
108 domImpl.createDocument(namespaceURI, malformedName, docType);
109 } catch (DOMException ex) {
110 success = (ex.code == DOMException.NAMESPACE_ERR);
112 assertTrue("throw_NAMESPACE_ERR", success);
116 level = TestLevel.PARTIAL,
117 notes = "Doesn't verify null as parameters.",
118 method = "createDocument",
119 args = {java.lang.String.class, java.lang.String.class, org.w3c.dom.DocumentType.class}
121 public void testCreateDocument2() throws Throwable {
122 String namespaceURI = null;
124 String qualifiedName = "k:local";
126 DocumentType docType = null;
128 DOMImplementation domImpl;
130 doc = (Document) load("staffNS", builder);
131 domImpl = doc.getImplementation();
133 boolean success = false;
135 domImpl.createDocument(namespaceURI, qualifiedName, docType);
136 } catch (DOMException ex) {
137 success = (ex.code == DOMException.NAMESPACE_ERR);
139 assertTrue("throw_NAMESPACE_ERR", success);
143 // public void testCreateDocument3() throws Throwable {
144 // String namespaceURI = "http://www.ecommerce.org/schema";
145 // String qualifiedName = "namespaceURI:x";
147 // DocumentType docType;
148 // DOMImplementation domImpl;
150 // doc = (Document) load("staffNS", builder);
151 // docType = doc.getDoctype();
152 // domImpl = doc.getImplementation();
154 // boolean success = false;
156 // domImpl.createDocument(namespaceURI, qualifiedName, docType);
157 // } catch (DOMException ex) {
158 // success = (ex.code == DOMException.WRONG_DOCUMENT_ERR);
160 // assertTrue("throw_WRONG_DOCUMENT_ERR", success);
164 // public void testCreateDocument4() throws Throwable {
165 // String namespaceURI = "http://www.ecommerce.org/schema";
166 // String qualifiedName = "namespaceURI:x";
168 // DocumentType docType;
169 // DOMImplementation domImpl;
171 // doc = (Document) load("staffNS", builder);
172 // aNewDoc = (Document) load("staffNS", builder);
173 // docType = doc.getDoctype();
174 // domImpl = aNewDoc.getImplementation();
176 // boolean success = false;
178 // aNewDoc = domImpl.createDocument(namespaceURI, qualifiedName,
180 // } catch (DOMException ex) {
181 // success = (ex.code == DOMException.WRONG_DOCUMENT_ERR);
183 // assertTrue("throw_WRONG_DOCUMENT_ERR", success);
187 level = TestLevel.PARTIAL,
188 notes = "Doesn't verify null as parameters.",
189 method = "createDocument",
190 args = {java.lang.String.class, java.lang.String.class, org.w3c.dom.DocumentType.class}
192 public void testCreateDocument5() throws Throwable {
193 String namespaceURI = "http://www.ecommerce.org/schema";
194 String qualifiedName;
196 DocumentType docType = null;
198 DOMImplementation domImpl;
200 List<String> illegalQNames = new ArrayList<String>();
201 illegalQNames.add("namespaceURI:{");
202 illegalQNames.add("namespaceURI:}");
203 illegalQNames.add("namespaceURI:~");
204 illegalQNames.add("namespaceURI:'");
205 illegalQNames.add("namespaceURI:!");
206 illegalQNames.add("namespaceURI:@");
207 illegalQNames.add("namespaceURI:#");
208 illegalQNames.add("namespaceURI:$");
209 illegalQNames.add("namespaceURI:%");
210 illegalQNames.add("namespaceURI:^");
211 illegalQNames.add("namespaceURI:&");
212 illegalQNames.add("namespaceURI:*");
213 illegalQNames.add("namespaceURI:(");
214 illegalQNames.add("namespaceURI:)");
215 illegalQNames.add("namespaceURI:+");
216 illegalQNames.add("namespaceURI:=");
217 illegalQNames.add("namespaceURI:[");
218 illegalQNames.add("namespaceURI:]");
219 illegalQNames.add("namespaceURI:\\");
220 illegalQNames.add("namespaceURI:/");
221 illegalQNames.add("namespaceURI:;");
222 illegalQNames.add("namespaceURI:`");
223 illegalQNames.add("namespaceURI:<");
224 illegalQNames.add("namespaceURI:>");
225 illegalQNames.add("namespaceURI:,");
226 illegalQNames.add("namespaceURI:a ");
227 illegalQNames.add("namespaceURI:\"");
229 doc = (Document) load("staffNS", builder);
230 for (int indexN1009A = 0; indexN1009A < illegalQNames.size(); indexN1009A++) {
231 qualifiedName = (String) illegalQNames.get(indexN1009A);
232 domImpl = doc.getImplementation();
234 boolean success = false;
236 domImpl.createDocument(namespaceURI, qualifiedName, docType);
237 } catch (DOMException ex) {
238 success = (ex.code == DOMException.INVALID_CHARACTER_ERR);
240 assertTrue("throw_INVALID_CHARACTER_ERR", success);
245 level = TestLevel.PARTIAL,
246 notes = "Doesn't verify null as parameters.",
247 method = "createDocument",
248 args = {java.lang.String.class, java.lang.String.class, org.w3c.dom.DocumentType.class}
250 public void testCreateDocument6() throws Throwable {
251 String namespaceURI = "http://ecommerce.org/schema";
252 String qualifiedName = "xml:local";
254 DocumentType docType = null;
256 DOMImplementation domImpl;
258 doc = (Document) load("staffNS", builder);
259 domImpl = doc.getImplementation();
261 boolean success = false;
263 domImpl.createDocument(namespaceURI, qualifiedName, docType);
264 } catch (DOMException ex) {
265 success = (ex.code == DOMException.NAMESPACE_ERR);
267 assertTrue("throw_NAMESPACE_ERR", success);
271 level = TestLevel.PARTIAL,
272 notes = "Doesn't verify null as parameters.",
273 method = "createDocument",
274 args = {java.lang.String.class, java.lang.String.class, org.w3c.dom.DocumentType.class}
276 public void testCreateDocument7() throws Throwable {
277 String namespaceURI = "http://www.ecommerce.org/schema";
278 String qualifiedName = "y:x";
280 DocumentType docType = null;
282 DOMImplementation domImpl;
286 doc = (Document) load("staffNS", builder);
287 domImpl = doc.getImplementation();
288 aNewDoc = domImpl.createDocument(namespaceURI, qualifiedName, docType);
289 nodeName = aNewDoc.getNodeName();
290 nodeValue = aNewDoc.getNodeValue();
291 assertEquals("nodeName", "#document", nodeName);
292 assertNull("nodeValue", nodeValue);
295 level = TestLevel.PARTIAL,
296 notes = "Doesn't verify null as parameters.",
297 method = "createDocument",
298 args = {java.lang.String.class, java.lang.String.class, org.w3c.dom.DocumentType.class}
300 public void testCreateDocument8() throws Throwable {
301 String namespaceURI = "http://www.example.org/schema";
302 DocumentType docType = null;
304 DOMImplementation domImpl;
306 domImpl = builder.getDOMImplementation();
308 // BEGIN android-changed
309 // Our exception priorities differ from the spec
311 domImpl.createDocument(namespaceURI, "", docType);
313 } catch (DOMException ex) {
315 // END android-changed