2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package tests.api.org.xml.sax;
19 import dalvik.annotation.TestLevel;
20 import dalvik.annotation.TestTargetClass;
21 import dalvik.annotation.TestTargetNew;
23 import junit.framework.TestCase;
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;
32 @SuppressWarnings("deprecation")
33 @TestTargetClass(HandlerBase.class)
34 public class HandlerBaseTest extends TestCase {
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.
41 private HandlerBase h = new HandlerBase();
44 level = TestLevel.COMPLETE,
45 method = "resolveEntity",
46 args = { String.class, String.class }
48 public void testResolveEntity() {
50 h.resolveEntity("publicID", "systemID");
51 } catch (SAXException e) {
52 throw new RuntimeException(e);
57 level = TestLevel.COMPLETE,
58 method = "notationDecl",
59 args = { String.class, String.class, String.class }
61 public void testNotationDecl() {
62 h.notationDecl("name", "publicID", "systemID");
66 level = TestLevel.COMPLETE,
67 method = "unparsedEntityDecl",
68 args = { String.class, String.class, String.class, String.class }
70 public void testUnparsedEntityDecl() {
71 h.unparsedEntityDecl("name", "publicID", "systemID", "notationName");
75 level = TestLevel.COMPLETE,
76 method = "setDocumentLocator",
77 args = { org.xml.sax.Locator.class }
79 public void testSetDocumentLocator() {
80 h.setDocumentLocator(new LocatorImpl());
84 level = TestLevel.COMPLETE,
85 method = "startDocument",
88 public void testStartDocument() {
91 } catch (SAXException e) {
92 throw new RuntimeException(e);
97 level = TestLevel.COMPLETE,
98 method = "endDocument",
101 public void testEndDocument() {
104 } catch (SAXException e) {
105 throw new RuntimeException(e);
110 level = TestLevel.COMPLETE,
111 method = "startElement",
112 args = { String.class, AttributeList.class }
114 public void testStartElement() {
116 h.startElement("name", new AttributeListImpl());
117 } catch (SAXException e) {
118 throw new RuntimeException(e);
123 level = TestLevel.COMPLETE,
124 method = "endElement",
125 args = { String.class }
127 public void testEndElement() {
129 h.endElement("name");
130 } catch (SAXException e) {
131 throw new RuntimeException(e);
136 level = TestLevel.COMPLETE,
137 method = "characters",
138 args = { char[].class, int.class, int.class }
140 public void testCharacters() {
142 h.characters("The quick brown fox".toCharArray(), 4, 11);
143 } catch (SAXException e) {
144 throw new RuntimeException(e);
149 level = TestLevel.COMPLETE,
150 method = "ignorableWhitespace",
151 args = { char[].class, int.class, int.class }
153 public void testIgnorableWhitespace() {
155 h.ignorableWhitespace(" ".toCharArray(), 4, 11);
156 } catch (SAXException e) {
157 throw new RuntimeException(e);
162 level = TestLevel.COMPLETE,
163 method = "processingInstruction",
164 args = { String.class, String.class }
166 public void testProcessingInstruction() {
168 h.processingInstruction("target", "data");
169 } catch (SAXException e) {
170 throw new RuntimeException(e);
175 level = TestLevel.COMPLETE,
177 args = { org.xml.sax.SAXParseException.class }
179 public void testWarning() {
181 h.warning(new SAXParseException("Foo", new LocatorImpl()));
182 } catch (SAXException e) {
183 throw new RuntimeException(e);
188 level = TestLevel.COMPLETE,
190 args = { org.xml.sax.SAXParseException.class }
192 public void testError() {
194 h.error(new SAXParseException("Foo", new LocatorImpl()));
195 } catch (SAXException e) {
196 throw new RuntimeException(e);
201 level = TestLevel.COMPLETE,
202 method = "fatalError",
203 args = { org.xml.sax.SAXParseException.class }
205 public void testFatalError() {
208 h.fatalError(new SAXParseException("Foo", new LocatorImpl()));
209 fail("SAXException expected");
210 } catch (SAXException e) {
217 fail("NullPointerException expected");
218 } catch (SAXException e) {
219 fail("NullPointerException expected");
220 } catch (NullPointerException e) {