OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / test / java / tests / org / w3c / dom / CreateDocument.java
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.DocumentType;
35 import org.w3c.dom.DOMException;
36
37 import javax.xml.parsers.DocumentBuilder;
38
39 /**
40  * The "createDocument(namespaceURI,qualifiedName,doctype)" method for a
41  * DOMImplementation should raise NAMESPACE_ERR DOMException if parameter
42  * qualifiedName is malformed.
43  *
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.
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-createDocument">http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-DOM-createDocument</a>
56  * @see <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>
58  */
59 @TestTargetClass(DOMImplementation.class)
60 public final class CreateDocument 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 = "createDocument",
93         args = {java.lang.String.class, java.lang.String.class, org.w3c.dom.DocumentType.class}
94     )
95     public void testCreateDocument1() throws Throwable {
96         String namespaceURI = "http://www.ecommerce.org/";
97         String malformedName = "prefix::local";
98         Document doc;
99         DocumentType docType = null;
100
101         DOMImplementation domImpl;
102
103         doc = (Document) load("staffNS", builder);
104         domImpl = doc.getImplementation();
105
106         boolean success = false;
107         try {
108             domImpl.createDocument(namespaceURI, malformedName, docType);
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 = "createDocument",
119         args = {java.lang.String.class, java.lang.String.class, org.w3c.dom.DocumentType.class}
120     )
121     public void testCreateDocument2() throws Throwable {
122         String namespaceURI = null;
123
124         String qualifiedName = "k:local";
125         Document doc;
126         DocumentType docType = null;
127
128         DOMImplementation domImpl;
129
130         doc = (Document) load("staffNS", builder);
131         domImpl = doc.getImplementation();
132
133         boolean success = false;
134         try {
135             domImpl.createDocument(namespaceURI, qualifiedName, docType);
136         } catch (DOMException ex) {
137             success = (ex.code == DOMException.NAMESPACE_ERR);
138         }
139         assertTrue("throw_NAMESPACE_ERR", success);
140
141     }
142
143 //    public void testCreateDocument3() throws Throwable {
144 //        String namespaceURI = "http://www.ecommerce.org/schema";
145 //        String qualifiedName = "namespaceURI:x";
146 //        Document doc;
147 //        DocumentType docType;
148 //        DOMImplementation domImpl;
149 //
150 //        doc = (Document) load("staffNS", builder);
151 //        docType = doc.getDoctype();
152 //        domImpl = doc.getImplementation();
153 //
154 //        boolean success = false;
155 //        try {
156 //            domImpl.createDocument(namespaceURI, qualifiedName, docType);
157 //        } catch (DOMException ex) {
158 //            success = (ex.code == DOMException.WRONG_DOCUMENT_ERR);
159 //        }
160 //        assertTrue("throw_WRONG_DOCUMENT_ERR", success);
161 //
162 //    }
163
164 //    public void testCreateDocument4() throws Throwable {
165 //        String namespaceURI = "http://www.ecommerce.org/schema";
166 //        String qualifiedName = "namespaceURI:x";
167 //        Document doc;
168 //        DocumentType docType;
169 //        DOMImplementation domImpl;
170 //        Document aNewDoc;
171 //        doc = (Document) load("staffNS", builder);
172 //        aNewDoc = (Document) load("staffNS", builder);
173 //        docType = doc.getDoctype();
174 //        domImpl = aNewDoc.getImplementation();
175 //
176 //        boolean success = false;
177 //        try {
178 //            aNewDoc = domImpl.createDocument(namespaceURI, qualifiedName,
179 //                    docType);
180 //        } catch (DOMException ex) {
181 //            success = (ex.code == DOMException.WRONG_DOCUMENT_ERR);
182 //        }
183 //        assertTrue("throw_WRONG_DOCUMENT_ERR", success);
184 //
185 //    }
186     @TestTargetNew(
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}
191     )
192     public void testCreateDocument5() throws Throwable {
193         String namespaceURI = "http://www.ecommerce.org/schema";
194         String qualifiedName;
195         Document doc;
196         DocumentType docType = null;
197
198         DOMImplementation domImpl;
199
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:\"");
228
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();
233
234             boolean success = false;
235             try {
236                 domImpl.createDocument(namespaceURI, qualifiedName, docType);
237             } catch (DOMException ex) {
238                 success = (ex.code == DOMException.INVALID_CHARACTER_ERR);
239             }
240             assertTrue("throw_INVALID_CHARACTER_ERR", success);
241
242         }
243     }
244     @TestTargetNew(
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}
249     )
250     public void testCreateDocument6() throws Throwable {
251         String namespaceURI = "http://ecommerce.org/schema";
252         String qualifiedName = "xml:local";
253         Document doc;
254         DocumentType docType = null;
255
256         DOMImplementation domImpl;
257
258         doc = (Document) load("staffNS", builder);
259         domImpl = doc.getImplementation();
260
261         boolean success = false;
262         try {
263             domImpl.createDocument(namespaceURI, qualifiedName, docType);
264         } catch (DOMException ex) {
265             success = (ex.code == DOMException.NAMESPACE_ERR);
266         }
267         assertTrue("throw_NAMESPACE_ERR", success);
268
269     }
270     @TestTargetNew(
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}
275     )
276     public void testCreateDocument7() throws Throwable {
277         String namespaceURI = "http://www.ecommerce.org/schema";
278         String qualifiedName = "y:x";
279         Document doc;
280         DocumentType docType = null;
281
282         DOMImplementation domImpl;
283         Document aNewDoc;
284         String nodeName;
285         String nodeValue;
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);
293     }
294     @TestTargetNew(
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}
299     )
300     public void testCreateDocument8() throws Throwable {
301         String namespaceURI = "http://www.example.org/schema";
302         DocumentType docType = null;
303
304         DOMImplementation domImpl;
305
306         domImpl = builder.getDOMImplementation();
307
308         // BEGIN android-changed
309         //     Our exception priorities differ from the spec
310         try {
311             domImpl.createDocument(namespaceURI, "", docType);
312             fail();
313         } catch (DOMException ex) {
314         }
315         // END android-changed
316     }
317 }