OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / test / java / tests / org / w3c / dom / GetElementsByTagNameNS.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.Document;
33 import org.w3c.dom.NodeList;
34 import org.w3c.dom.Element;
35 import org.w3c.dom.Node;
36
37 import javax.xml.parsers.DocumentBuilder;
38
39 /**
40  * The "getElementsByTagNameNS(namespaceURI,localName)" method for a Document
41  * should return a new NodeList of all Elements that have a namespace when local
42  * name is specified as ' '.
43  *
44  * Invoke method getElementsByTagNameNS(namespaceURI,localName) on this document
45  * with namespaceURI and localName as " ". Method should return a new NodeList
46  * of 37 elements.
47  *
48  * @author NIST
49  * @author Mary Brady
50  * @see <a
51  *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-getElBTNNS">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-getElBTNNS</a>
52  */
53 @TestTargetClass(Document.class)
54 public final class GetElementsByTagNameNS extends DOMTestCase {
55     DOMDocumentBuilderFactory factory;
56
57     DocumentBuilder builder;
58
59     protected void setUp() throws Exception {
60         super.setUp();
61         try {
62             factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
63                     .getConfiguration2());
64             builder = factory.getBuilder();
65         } catch (Exception e) {
66             fail("Unexpected exception" + e.getMessage());
67         }
68     }
69
70     protected void tearDown() throws Exception {
71         factory = null;
72         builder = null;
73         super.tearDown();
74     }
75     @TestTargetNew(
76         level = TestLevel.PARTIAL_COMPLETE,
77         notes = "Verifies getElementsByTagNameNS method with * as parameters.",
78         method = "getElementsByTagNameNS",
79         args = {java.lang.String.class, java.lang.String.class}
80     )
81     public void testGetElementsByTagNameNS1() throws Throwable {
82         String namespaceURI = "*";
83         String localName = "*";
84         Document doc;
85         NodeList newList;
86         doc = (Document) load("staffNS", builder);
87         newList = doc.getElementsByTagNameNS(namespaceURI, localName);
88         // BEGIN android-changed: Was 37, but that assumed validation.
89         assertEquals("throw_Size", 36, newList.getLength());
90         // END android-changed
91     }
92     @TestTargetNew(
93         level = TestLevel.PARTIAL_COMPLETE,
94         notes = "Verifies getElementsByTagNameNS with '*' as the first parameter.",
95         method = "getElementsByTagNameNS",
96         args = {java.lang.String.class, java.lang.String.class}
97     )
98     public void testGetElementsByTagNameNS2() throws Throwable {
99         Document doc;
100         NodeList newList;
101         Element newElement;
102         String prefix;
103         String lname;
104         doc = (Document) load("staffNS", builder);
105         newList = doc.getElementsByTagNameNS("*", "employee");
106         assertEquals("employeeCount", 5, newList.getLength());
107         newElement = (Element) newList.item(3);
108         prefix = newElement.getPrefix();
109         assertEquals("prefix", "emp", prefix);
110         lname = newElement.getLocalName();
111         assertEquals("lname", "employee", lname);
112     }
113     @TestTargetNew(
114         level = TestLevel.PARTIAL_COMPLETE,
115         notes = "Verifies getElementsByTagNameNS with '*' as the second parameter.",
116         method = "getElementsByTagNameNS",
117         args = {java.lang.String.class, java.lang.String.class}
118     )
119     public void testGetElementsByTagNameNS3() throws Throwable {
120         Document doc;
121         NodeList elementList;
122         Node child;
123         String childName;
124         List<String> result = new ArrayList<String>();
125
126         List<String> expectedResult = new ArrayList<String>();
127         expectedResult.add("employee");
128         expectedResult.add("employeeId");
129         expectedResult.add("name");
130         expectedResult.add("position");
131         expectedResult.add("salary");
132         expectedResult.add("gender");
133         expectedResult.add("address");
134         expectedResult.add("emp:employee");
135         expectedResult.add("emp:employeeId");
136         expectedResult.add("emp:position");
137         expectedResult.add("emp:salary");
138         expectedResult.add("emp:gender");
139         expectedResult.add("emp:address");
140         expectedResult.add("address");
141
142         doc = (Document) load("staffNS", builder);
143         elementList = doc.getElementsByTagNameNS("http://www.nist.gov", "*");
144         for (int indexN10076 = 0; indexN10076 < elementList.getLength(); indexN10076++) {
145             child = (Node) elementList.item(indexN10076);
146             childName = child.getNodeName();
147             result.add(childName);
148         }
149         assertEquals("nodeNames", expectedResult, result);
150     }
151     @TestTargetNew(
152         level = TestLevel.PARTIAL_COMPLETE,
153         notes = "Verifies getElementsByTagNameNS with '*' as the first parameter.",
154         method = "getElementsByTagNameNS",
155         args = {java.lang.String.class, java.lang.String.class}
156     )
157     public void testGetElementsByTagNameNS4() throws Throwable {
158         Document doc;
159         NodeList elementList;
160         Node child;
161         String childName;
162         List<String> result = new ArrayList<String>();
163
164         List<String> expectedResult = new ArrayList<String>();
165         expectedResult.add("address");
166         expectedResult.add("address");
167         expectedResult.add("address");
168         expectedResult.add("emp:address");
169         expectedResult.add("address");
170
171         doc = (Document) load("staffNS", builder);
172         elementList = doc.getElementsByTagNameNS("*", "address");
173         for (int indexN10059 = 0; indexN10059 < elementList.getLength(); indexN10059++) {
174             child = (Node) elementList.item(indexN10059);
175             childName = child.getNodeName();
176             result.add(childName);
177         }
178         assertEquals("nodeNames", expectedResult, result);
179     }
180     @TestTargetNew(
181         level = TestLevel.PARTIAL_COMPLETE,
182         notes = "Verifies negative case of getElementsByTagNameNS method.",
183         method = "getElementsByTagNameNS",
184         args = {java.lang.String.class, java.lang.String.class}
185     )
186     public void testGetElementsByTagNameNS5() throws Throwable {
187         String namespaceURI = "http://www.nist.gov";
188         String localName = "nomatch";
189         Document doc;
190         NodeList elementList;
191         doc = (Document) load("staffNS", builder);
192         elementList = doc.getElementsByTagNameNS(namespaceURI, localName);
193         assertEquals("throw_Size", 0, elementList.getLength());
194     }
195     @TestTargetNew(
196         level = TestLevel.PARTIAL_COMPLETE,
197         notes = "Verifies negative case of getElementsByTagNameNS method.",
198         method = "getElementsByTagNameNS",
199         args = {java.lang.String.class, java.lang.String.class}
200     )
201     public void testGetElementsByTagNameNS6() throws Throwable {
202         Document doc;
203         NodeList elementList;
204         doc = (Document) load("staffNS", builder);
205         elementList = doc.getElementsByTagNameNS("http://www.nomatch.com",
206                 "address");
207         assertEquals("matchSize", 0, elementList.getLength());
208     }
209     @TestTargetNew(
210         level = TestLevel.PARTIAL_COMPLETE,
211         notes = "Verifies positive case of getElementsByTagNameNS method.",
212         method = "getElementsByTagNameNS",
213         args = {java.lang.String.class, java.lang.String.class}
214     )
215     public void testGetElementsByTagNameNS7() throws Throwable {
216         Document doc;
217         NodeList elementList;
218         doc = (Document) load("staffNS", builder);
219         elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
220                 "address");
221         assertEquals("addresses", 3, elementList.getLength());
222     }
223     @TestTargetNew(
224         level = TestLevel.PARTIAL_COMPLETE,
225         notes = "Verifies getElementsByTagNameNS method with '*' as parameters; positive case.",
226         method = "getElementsByTagNameNS",
227         args = {java.lang.String.class, java.lang.String.class}
228     )
229     public void testGetElementsByTagNameNS8() throws Throwable {
230         Document doc;
231         Element docElem;
232         NodeList newList;
233         doc = (Document) load("staffNS", builder);
234         docElem = doc.getDocumentElement();
235         newList = docElem.getElementsByTagNameNS("*", "*");
236         assertEquals("listSize", 36, newList.getLength());
237     }
238     @TestTargetNew(
239         level = TestLevel.PARTIAL_COMPLETE,
240         notes = "Verifies getElementsByTagNameNS method with '*' as the first parameter.",
241         method = "getElementsByTagNameNS",
242         args = {java.lang.String.class, java.lang.String.class}
243     )
244     public void testGetElementsByTagNameNS9() throws Throwable {
245         Document doc;
246         NodeList newList;
247         Element newElement;
248         String prefix;
249         String lname;
250         Element docElem;
251         doc = (Document) load("staffNS", builder);
252         docElem = doc.getDocumentElement();
253         newList = docElem.getElementsByTagNameNS("*", "employee");
254         assertEquals("employeeCount", 5, newList.getLength());
255         newElement = (Element) newList.item(3);
256         prefix = newElement.getPrefix();
257         assertEquals("prefix", "emp", prefix);
258         lname = newElement.getLocalName();
259         assertEquals("lname", "employee", lname);
260     }
261     @TestTargetNew(
262         level = TestLevel.PARTIAL_COMPLETE,
263         notes = "Verifies getElementsByTagNameNS method with '*' as the second parameter.",
264         method = "getElementsByTagNameNS",
265         args = {java.lang.String.class, java.lang.String.class}
266     )
267     public void testGetElementsByTagNameNS10() throws Throwable {
268         Document doc;
269         Element docElem;
270         NodeList elementList;
271         Node child;
272         String childName;
273         List<String> result = new ArrayList<String>();
274
275         List<String> expectedResult = new ArrayList<String>();
276         expectedResult.add("employee");
277         expectedResult.add("employeeId");
278         expectedResult.add("name");
279         expectedResult.add("position");
280         expectedResult.add("salary");
281         expectedResult.add("gender");
282         expectedResult.add("address");
283         expectedResult.add("emp:employee");
284         expectedResult.add("emp:employeeId");
285         expectedResult.add("emp:position");
286         expectedResult.add("emp:salary");
287         expectedResult.add("emp:gender");
288         expectedResult.add("emp:address");
289         expectedResult.add("address");
290
291         doc = (Document) load("staffNS", builder);
292         docElem = doc.getDocumentElement();
293         elementList = docElem
294                 .getElementsByTagNameNS("http://www.nist.gov", "*");
295         for (int indexN1007E = 0; indexN1007E < elementList.getLength(); indexN1007E++) {
296             child = (Node) elementList.item(indexN1007E);
297             childName = child.getNodeName();
298             result.add(childName);
299         }
300         assertEquals("nodeNames", expectedResult, result);
301     }
302     @TestTargetNew(
303         level = TestLevel.PARTIAL_COMPLETE,
304         notes = "Verifies getElementsByTagNameNS method with '*' as the first parameter.",
305         method = "getElementsByTagNameNS",
306         args = {java.lang.String.class, java.lang.String.class}
307     )
308     public void testGetElementsByTagNameNS11() throws Throwable {
309         Document doc;
310         Element docElem;
311         NodeList elementList;
312         Node child;
313         String childName;
314         List<String> result = new ArrayList<String>();
315
316         List<String> expectedResult = new ArrayList<String>();
317         expectedResult.add("address");
318         expectedResult.add("address");
319         expectedResult.add("address");
320         expectedResult.add("emp:address");
321         expectedResult.add("address");
322
323         doc = (Document) load("staffNS", builder);
324         docElem = doc.getDocumentElement();
325         elementList = docElem.getElementsByTagNameNS("*", "address");
326         for (int indexN1005E = 0; indexN1005E < elementList.getLength(); indexN1005E++) {
327             child = (Node) elementList.item(indexN1005E);
328             childName = child.getNodeName();
329             result.add(childName);
330         }
331         assertEquals("nodeNames", expectedResult, result);
332     }
333     @TestTargetNew(
334         level = TestLevel.PARTIAL_COMPLETE,
335         notes = "Verifies negative case for getElementsByTagNameNS method.",
336         method = "getElementsByTagNameNS",
337         args = {java.lang.String.class, java.lang.String.class}
338     )
339     public void testGetElementsByTagNameNS12() throws Throwable {
340         Document doc;
341         Element docElem;
342         NodeList elementList;
343         doc = (Document) load("staffNS", builder);
344         docElem = doc.getDocumentElement();
345         elementList = docElem.getElementsByTagNameNS("http://www.nist.gov",
346                 "nomatch");
347         assertEquals("size", 0, elementList.getLength());
348     }
349     @TestTargetNew(
350         level = TestLevel.PARTIAL_COMPLETE,
351         notes = "Verifies negative case for getElementsByTagNameNS method.",
352         method = "getElementsByTagNameNS",
353         args = {java.lang.String.class, java.lang.String.class}
354     )
355     public void testGetElementsByTagNameNS13() throws Throwable {
356         Document doc;
357         Element docElem;
358         NodeList elementList;
359         doc = (Document) load("staffNS", builder);
360         docElem = doc.getDocumentElement();
361         elementList = docElem.getElementsByTagNameNS("http://www.nomatch.com",
362                 "address");
363         assertEquals("matchSize", 0, elementList.getLength());
364     }
365     @TestTargetNew(
366         level = TestLevel.PARTIAL_COMPLETE,
367         notes = "Verifies positive case for getElementsByTagNameNS method.",
368         method = "getElementsByTagNameNS",
369         args = {java.lang.String.class, java.lang.String.class}
370     )
371     public void testGetElementsByTagNameNS14() throws Throwable {
372         Document doc;
373         Element docElem;
374         NodeList elementList;
375         doc = (Document) load("staffNS", builder);
376         docElem = doc.getDocumentElement();
377         elementList = docElem.getElementsByTagNameNS("http://www.nist.gov",
378                 "address");
379         assertEquals("addresses", 3, elementList.getLength());
380     }
381 }