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
22package tests.org.w3c.dom;
23
24import dalvik.annotation.TestTargets;
25import dalvik.annotation.TestLevel;
26import dalvik.annotation.TestTargetNew;
27import dalvik.annotation.TestTargetClass;
28
29import java.util.ArrayList;
30import java.util.List;
31
32import org.w3c.dom.DOMImplementation;
33import org.w3c.dom.Document;
34import org.w3c.dom.DocumentType;
35
36import javax.xml.parsers.DocumentBuilder;
37
38/**
39 * The method createDocumentType with valid values for qualifiedName, publicId
40 * and systemId should create an empty DocumentType node.
41 *
42 * Invoke createDocument on this DOMImplementation with a valid qualifiedName
43 * and different publicIds and systemIds. Check if the the DocumentType node was
44 * created with its ownerDocument attribute set to null.
45 *
46 * @author IBM
47 * @author Neil Delima
48 * @see <a
49 *      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>
50 */
51@TestTargetClass(DOMImplementation.class)
52public final class DOMImplementationCreateDocumentType extends DOMTestCase {
53
54    DOMDocumentBuilderFactory factory;
55
56    DocumentBuilder builder;
57
58    protected void setUp() throws Exception {
59        super.setUp();
60        try {
61            factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
62                    .getConfiguration1());
63            builder = factory.getBuilder();
64        } catch (Exception e) {
65            fail("Unexpected exception" + e.getMessage());
66        }
67    }
68
69    protected void tearDown() throws Exception {
70        factory = null;
71        builder = null;
72        super.tearDown();
73    }
74
75    /**
76     * Runs the test case.
77     *
78     * @throws Throwable
79     *             Any uncaught exception causes test to fail
80     */
81    @TestTargetNew(
82        level = TestLevel.PARTIAL,
83        notes = "Doesn't verify DOMException.",
84        method = "createDocumentType",
85        args = {java.lang.String.class, java.lang.String.class, java.lang.String.class}
86    )
87    public void testCreateDocumentType1() throws Throwable {
88        Document doc;
89        DOMImplementation domImpl;
90        DocumentType newDocType;
91        Document ownerDocument;
92        String qualifiedName = "test:root";
93        String publicId;
94        String systemId;
95        List<String> publicIds = new ArrayList<String>();
96        publicIds.add("1234");
97        publicIds.add("test");
98
99        List<String> systemIds = new ArrayList<String>();
100        systemIds.add("");
101        systemIds.add("test");
102
103        doc = (Document) load("staffNS", builder);
104        domImpl = doc.getImplementation();
105        for (int indexN1005D = 0; indexN1005D < publicIds.size(); indexN1005D++) {
106            publicId = (String) publicIds.get(indexN1005D);
107            for (int indexN10061 = 0; indexN10061 < systemIds.size(); indexN10061++) {
108                systemId = (String) systemIds.get(indexN10061);
109                newDocType = domImpl.createDocumentType(qualifiedName,
110                        publicId, systemId);
111                assertNotNull(
112                        "domimplementationcreatedocumenttype01_newDocType",
113                        newDocType);
114                ownerDocument = newDocType.getOwnerDocument();
115                assertNull(
116                        "domimplementationcreatedocumenttype01_ownerDocument",
117                        ownerDocument);
118            }
119        }
120    }
121    @TestTargetNew(
122        level = TestLevel.PARTIAL,
123        notes = "Doesn't verify DOMException.",
124        method = "createDocumentType",
125        args = {java.lang.String.class, java.lang.String.class, java.lang.String.class}
126    )
127    public void testCreateDocumentType2() throws Throwable {
128        Document doc;
129        DOMImplementation domImpl;
130        DocumentType newDocType;
131        Document ownerDocument;
132        String publicId = "http://www.w3.org/DOM/Test/dom2.dtd";
133        String systemId = "dom2.dtd";
134        String qualifiedName;
135        List<String> qualifiedNames = new ArrayList<String>();
136        qualifiedNames.add("_:_");
137        qualifiedNames.add("_:h0");
138        qualifiedNames.add("_:test");
139        qualifiedNames.add("_:_.");
140        qualifiedNames.add("_:a-");
141        qualifiedNames.add("l_:_");
142        qualifiedNames.add("ns:_0");
143        qualifiedNames.add("ns:a0");
144        qualifiedNames.add("ns0:test");
145        qualifiedNames.add("ns:EEE.");
146        qualifiedNames.add("ns:_-");
147        qualifiedNames.add("a.b:c");
148        qualifiedNames.add("a-b:c.j");
149        qualifiedNames.add("a-b:c");
150
151        doc = (Document) load("staffNS", builder);
152        domImpl = doc.getImplementation();
153        for (int indexN10077 = 0; indexN10077 < qualifiedNames.size(); indexN10077++) {
154            qualifiedName = (String) qualifiedNames.get(indexN10077);
155            newDocType = domImpl.createDocumentType(qualifiedName, publicId,
156                    systemId);
157            assertNotNull("domimplementationcreatedocumenttype02_newDocType",
158                    newDocType);
159            ownerDocument = newDocType.getOwnerDocument();
160            assertNull("domimplementationcreatedocumenttype02_ownerDocument",
161                    ownerDocument);
162        }
163    }
164    @TestTargetNew(
165        level = TestLevel.PARTIAL,
166        notes = "Doesn't verify DOMException.",
167        method = "createDocumentType",
168        args = {java.lang.String.class, java.lang.String.class, java.lang.String.class}
169    )
170    public void testCreateDocumentType4() throws Throwable {
171        Document doc;
172        DOMImplementation domImpl;
173        DocumentType newDocType;
174        Document ownerDocument;
175        String publicId = "http://www.w3.org/DOM/Test/dom2.dtd";
176        String systemId = "dom2.dtd";
177        String qualifiedName;
178        List<String> qualifiedNames = new ArrayList<String>();
179        qualifiedNames.add("_:_");
180        qualifiedNames.add("_:h0");
181        qualifiedNames.add("_:test");
182        qualifiedNames.add("_:_.");
183        qualifiedNames.add("_:a-");
184        qualifiedNames.add("l_:_");
185        qualifiedNames.add("ns:_0");
186        qualifiedNames.add("ns:a0");
187        qualifiedNames.add("ns0:test");
188        qualifiedNames.add("ns:EEE.");
189        qualifiedNames.add("ns:_-");
190        qualifiedNames.add("a.b:c");
191        qualifiedNames.add("a-b:c.j");
192        qualifiedNames.add("a-b:c");
193
194        doc = (Document) load("staffNS", builder);
195        domImpl = doc.getImplementation();
196        for (int indexN10077 = 0; indexN10077 < qualifiedNames.size(); indexN10077++) {
197            qualifiedName = (String) qualifiedNames.get(indexN10077);
198            newDocType = domImpl.createDocumentType(qualifiedName, publicId,
199                    systemId);
200            assertNotNull("domimplementationcreatedocumenttype02_newDocType",
201                    newDocType);
202            ownerDocument = newDocType.getOwnerDocument();
203            assertNull("domimplementationcreatedocumenttype02_ownerDocument",
204                    ownerDocument);
205        }
206    }
207
208}
209