KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xmlpull > v1 > tests > TestEvent


1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/
2 // for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
3

4 package org.xmlpull.v1.tests;
5
6 //import junit.framework.Test;
7
import junit.framework.TestCase;
8 import junit.framework.TestSuite;
9
10 import java.io.StringReader JavaDoc;
11
12 import org.xmlpull.v1.XmlPullParser;
13 import org.xmlpull.v1.XmlPullParserFactory;
14 import org.xmlpull.v1.XmlPullParserException;
15
16 /**
17  * More complete test to verify paring.
18  *
19  * @author <a HREF="http://www.extreme.indiana.edu/~aslom/">Aleksander Slominski</a>
20  */

21 public class TestEvent extends UtilTestCase {
22     public static void main (String JavaDoc[] args) {
23         junit.textui.TestRunner.run (new TestSuite(TestEvent.class));
24     }
25
26     public TestEvent(String JavaDoc name) {
27         super(name);
28     }
29
30     protected XmlPullParserFactory newFactory() throws XmlPullParserException {
31         XmlPullParserFactory factory = factoryNewInstance();
32         factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
33         assertEquals(true, factory.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
34         assertEquals(false, factory.getFeature(XmlPullParser.FEATURE_VALIDATION));
35         return factory;
36     }
37
38     protected void tearDown() {
39     }
40
41     public void testEvent() throws Exception JavaDoc {
42         XmlPullParserFactory factory = newFactory();
43         XmlPullParser xpp = factory.newPullParser();
44         xpp.setInput(new StringReader JavaDoc(TEST_XML));
45
46         checkParserStateNs(xpp, 0, xpp.START_DOCUMENT, null, 0, null, null, null, false, -1);
47
48         xpp.next();
49         checkParserStateNs(xpp, 1, xpp.START_TAG, null, 0, "", "root", null, false, 0);
50         xpp.next();
51         checkParserStateNs(xpp, 1, xpp.TEXT, null, 0, null, null, "\n", false, -1);
52
53         xpp.next();
54         checkParserStateNs(xpp, 2, xpp.START_TAG, null, 0, "", "foo", null, false, 0);
55         xpp.next();
56         checkParserStateNs(xpp, 2, xpp.TEXT, null, 0, null, null, "bar", false, -1);
57         xpp.next();
58         checkParserStateNs(xpp, 2, xpp.END_TAG, null, 0, "", "foo", null, false, -1);
59         xpp.next();
60         checkParserStateNs(xpp, 1, xpp.TEXT, null, 0, null, null, "\n", false, -1);
61
62         xpp.next();
63         checkParserStateNs(xpp, 2, xpp.START_TAG,
64                            null, 1, "http://www.xmlpull.org/temp", "hugo", null, false, 0);
65         checkNamespace(xpp, 0, null, "http://www.xmlpull.org/temp", true);
66
67         xpp.next();
68         checkParserStateNs(xpp, 2, xpp.TEXT, null, 1, null, null, " \n\n \n ", false, -1);
69
70         xpp.next();
71         checkParserStateNs(xpp, 3, xpp.START_TAG,
72                            null, 1, "http://www.xmlpull.org/temp", "hugochild", null, false, 0);
73         xpp.next();
74         checkParserStateNs(xpp, 3, xpp.TEXT, null, 1, null, null,
75                            "This is in a new namespace", false, -1);
76         xpp.next();
77         checkParserStateNs(xpp, 3, xpp.END_TAG,
78                            null, 1, "http://www.xmlpull.org/temp", "hugochild", null, false, -1);
79
80         xpp.next();
81         checkParserStateNs(xpp, 2, xpp.END_TAG,
82                            null, 1, "http://www.xmlpull.org/temp", "hugo", null, false, -1);
83         xpp.next();
84         checkParserStateNs(xpp, 1, xpp.TEXT, null, 0, null, null, "\t\n", false, -1);
85
86         xpp.next();
87         checkParserStateNs(xpp, 2, xpp.START_TAG, null, 0, "", "bar", null, true, 1);
88         checkAttribNs(xpp, 0, null, "", "testattr", "123abc");
89         xpp.next();
90         checkParserStateNs(xpp, 2, xpp.END_TAG, null, 0, "", "bar", null, false, -1);
91         xpp.next();
92         checkParserStateNs(xpp, 1, xpp.END_TAG, null, 0, "", "root", null, false, -1);
93         xpp.next();
94         checkParserStateNs(xpp, 0, xpp.END_DOCUMENT, null, 0, null, null, null, false, -1);
95     }
96
97     public void testMultiNs() throws Exception JavaDoc {
98         XmlPullParserFactory factory = newFactory();
99         XmlPullParser xpp = factory.newPullParser();
100         xpp.setInput(new StringReader JavaDoc("<foo><bar xmlns=''/><char xmlns=''></char></foo>"));
101
102         checkParserStateNs(xpp, 0, xpp.START_DOCUMENT, null, 0, null, null, null, false, -1);
103
104         xpp.next();
105         checkParserStateNs(xpp, 1, xpp.START_TAG, null, 0, "", "foo", null, false, 0);
106         xpp.next();
107         checkParserStateNs(xpp, 2, xpp.START_TAG, null, 1, "", "bar", null, true, 0);
108         xpp.next();
109         checkParserStateNs(xpp, 2, xpp.END_TAG, null, 1, "", "bar", null, false, -1);
110         xpp.next();
111         checkParserStateNs(xpp, 2, xpp.START_TAG, null, 1, "", "char", null, false, 0);
112         xpp.next();
113         checkParserStateNs(xpp, 2, xpp.END_TAG, null, 1, "", "char", null, false, -1);
114         xpp.next();
115         checkParserStateNs(xpp, 1, xpp.END_TAG, null, 0, "", "foo", null, false, -1);
116         xpp.next();
117         checkParserStateNs(xpp, 0, xpp.END_DOCUMENT, null, 0, null, null, null, false, -1);
118
119         xpp.setInput(new StringReader JavaDoc("<foo><bar xmlns=''></bar><char xmlns=''></char></foo>"));
120
121         checkParserStateNs(xpp, 0, xpp.START_DOCUMENT, null, 0, null, null, null, false, -1);
122         xpp.next();
123         checkParserStateNs(xpp, 1, xpp.START_TAG, null, 0, "", "foo", null, false, 0);
124         xpp.next();
125         checkParserStateNs(xpp, 2, xpp.START_TAG, null, 1, "", "bar", null, false, 0);
126         xpp.next();
127         checkParserStateNs(xpp, 2, xpp.END_TAG, null, 1, "", "bar", null, false, -1);
128         xpp.next();
129         checkParserStateNs(xpp, 2, xpp.START_TAG, null, 1, "", "char", null, false, 0);
130         xpp.next();
131         checkParserStateNs(xpp, 2, xpp.END_TAG, null, 1, "", "char", null, false, -1);
132         xpp.next();
133         checkParserStateNs(xpp, 1, xpp.END_TAG, null, 0, "", "foo", null, false, -1);
134         xpp.next();
135         checkParserStateNs(xpp, 0, xpp.END_DOCUMENT, null, 0, null, null, null, false, -1);
136
137     }
138
139 }
140
141
Popular Tags