OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / test / java / tests / api / org / xml / sax / HandlerBaseTest.java
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package tests.api.org.xml.sax;
18
19 import dalvik.annotation.TestLevel;
20 import dalvik.annotation.TestTargetClass;
21 import dalvik.annotation.TestTargetNew;
22
23 import junit.framework.TestCase;
24
25 import org.xml.sax.AttributeList;
26 import org.xml.sax.HandlerBase;
27 import org.xml.sax.SAXException;
28 import org.xml.sax.SAXParseException;
29 import org.xml.sax.helpers.AttributeListImpl;
30 import org.xml.sax.helpers.LocatorImpl;
31
32 @SuppressWarnings("deprecation")
33 @TestTargetClass(HandlerBase.class)
34 public class HandlerBaseTest extends TestCase {
35
36     /*
37      * Note: most of the tests have to check for an empty implementation of the
38      * respective methods and, as a result, are somewhat trivial.
39      */
40
41     private HandlerBase h = new HandlerBase();
42
43     @TestTargetNew(
44         level = TestLevel.COMPLETE,
45         method = "resolveEntity",
46         args = { String.class, String.class }
47     )
48     public void testResolveEntity() {
49         try {
50             h.resolveEntity("publicID", "systemID");
51         } catch (SAXException e) {
52             throw new RuntimeException(e);
53         }
54     }
55
56     @TestTargetNew(
57         level = TestLevel.COMPLETE,
58         method = "notationDecl",
59         args = { String.class, String.class, String.class }
60     )
61     public void testNotationDecl() {
62         h.notationDecl("name", "publicID", "systemID");
63     }
64
65     @TestTargetNew(
66         level = TestLevel.COMPLETE,
67         method = "unparsedEntityDecl",
68         args = { String.class, String.class, String.class, String.class }
69     )
70     public void testUnparsedEntityDecl() {
71         h.unparsedEntityDecl("name", "publicID", "systemID", "notationName");
72     }
73
74     @TestTargetNew(
75         level = TestLevel.COMPLETE,
76         method = "setDocumentLocator",
77         args = { org.xml.sax.Locator.class }
78     )
79     public void testSetDocumentLocator() {
80         h.setDocumentLocator(new LocatorImpl());
81     }
82
83     @TestTargetNew(
84         level = TestLevel.COMPLETE,
85         method = "startDocument",
86         args = { }
87     )
88     public void testStartDocument() {
89         try {
90             h.startDocument();
91         } catch (SAXException e) {
92             throw new RuntimeException(e);
93         }
94     }
95
96     @TestTargetNew(
97         level = TestLevel.COMPLETE,
98         method = "endDocument",
99         args = { }
100     )
101     public void testEndDocument() {
102         try {
103             h.endDocument();
104         } catch (SAXException e) {
105             throw new RuntimeException(e);
106         }
107     }
108
109     @TestTargetNew(
110         level = TestLevel.COMPLETE,
111         method = "startElement",
112         args = { String.class, AttributeList.class }
113     )
114     public void testStartElement() {
115         try {
116             h.startElement("name", new AttributeListImpl());
117         } catch (SAXException e) {
118             throw new RuntimeException(e);
119         }
120     }
121
122     @TestTargetNew(
123         level = TestLevel.COMPLETE,
124         method = "endElement",
125         args = { String.class }
126     )
127     public void testEndElement() {
128         try {
129             h.endElement("name");
130         } catch (SAXException e) {
131             throw new RuntimeException(e);
132         }
133     }
134
135     @TestTargetNew(
136         level = TestLevel.COMPLETE,
137         method = "characters",
138         args = { char[].class, int.class, int.class }
139     )
140     public void testCharacters() {
141         try {
142             h.characters("The quick brown fox".toCharArray(), 4, 11);
143         } catch (SAXException e) {
144             throw new RuntimeException(e);
145         }
146     }
147
148     @TestTargetNew(
149         level = TestLevel.COMPLETE,
150         method = "ignorableWhitespace",
151         args = { char[].class, int.class, int.class }
152     )
153     public void testIgnorableWhitespace() {
154         try {
155             h.ignorableWhitespace("                   ".toCharArray(), 4, 11);
156         } catch (SAXException e) {
157             throw new RuntimeException(e);
158         }
159     }
160
161     @TestTargetNew(
162         level = TestLevel.COMPLETE,
163         method = "processingInstruction",
164         args = { String.class, String.class }
165     )
166     public void testProcessingInstruction() {
167         try {
168             h.processingInstruction("target", "data");
169         } catch (SAXException e) {
170             throw new RuntimeException(e);
171         }
172     }
173
174     @TestTargetNew(
175         level = TestLevel.COMPLETE,
176         method = "warning",
177         args = { org.xml.sax.SAXParseException.class }
178     )
179     public void testWarning() {
180         try {
181             h.warning(new SAXParseException("Foo", new LocatorImpl()));
182         } catch (SAXException e) {
183             throw new RuntimeException(e);
184         }
185     }
186
187     @TestTargetNew(
188         level = TestLevel.COMPLETE,
189         method = "error",
190         args = { org.xml.sax.SAXParseException.class }
191     )
192     public void testError() {
193         try {
194             h.error(new SAXParseException("Foo", new LocatorImpl()));
195         } catch (SAXException e) {
196             throw new RuntimeException(e);
197         }
198     }
199
200     @TestTargetNew(
201         level = TestLevel.COMPLETE,
202         method = "fatalError",
203         args = { org.xml.sax.SAXParseException.class }
204     )
205     public void testFatalError() {
206         // Ordinary case
207         try {
208             h.fatalError(new SAXParseException("Foo", new LocatorImpl()));
209             fail("SAXException expected");
210         } catch (SAXException e) {
211             // Expected
212         }
213
214         // No exception
215         try {
216             h.fatalError(null);
217             fail("NullPointerException expected");
218         } catch (SAXException e) {
219             fail("NullPointerException expected");
220         } catch (NullPointerException e) {
221             // Expected
222         }
223
224     }
225
226 }