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 17package org.apache.harmony.tests.org.xml.sax.helpers; 18 19import junit.framework.TestCase; 20 21import org.xml.sax.Attributes; 22import org.xml.sax.SAXException; 23import org.xml.sax.SAXParseException; 24import org.xml.sax.helpers.AttributesImpl; 25import org.xml.sax.helpers.DefaultHandler; 26import org.xml.sax.helpers.LocatorImpl; 27 28import java.io.IOException; 29 30public class DefaultHandlerTest extends TestCase { 31 32 /* 33 * Note: most of the tests have to check for an empty implementation of the 34 * respective methods and, as a result, are somewhat trivial. 35 */ 36 37 private DefaultHandler h = new DefaultHandler(); 38 39 public void testResolveEntity() { 40 try { 41 h.resolveEntity("publicID", "systemID"); 42 } catch (SAXException e) { 43 throw new RuntimeException(e); 44 } catch (IOException e) { 45 throw new RuntimeException(e); 46 } 47 } 48 49 public void testNotationDecl() { 50 try { 51 h.notationDecl("name", "publicID", "systemID"); 52 } catch (SAXException e) { 53 throw new RuntimeException(e); 54 } 55 } 56 57 public void testUnparsedEntityDecl() { 58 try { 59 h.unparsedEntityDecl("name", "publicID", "systemID", 60 "notationName"); 61 } catch (SAXException e) { 62 throw new RuntimeException(e); 63 } 64 } 65 66 public void testSetDocumentLocator() { 67 h.setDocumentLocator(new LocatorImpl()); 68 } 69 70 public void testStartDocument() { 71 try { 72 h.startDocument(); 73 } catch (SAXException e) { 74 throw new RuntimeException(e); 75 } 76 } 77 78 public void testEndDocument() { 79 try { 80 h.endDocument(); 81 } catch (SAXException e) { 82 throw new RuntimeException(e); 83 } 84 } 85 86 public void testStartPrefixMapping() { 87 try { 88 h.startPrefixMapping("prefix", "uri"); 89 } catch (SAXException e) { 90 throw new RuntimeException(e); 91 } 92 } 93 94 public void testEndPrefixMapping() { 95 try { 96 h.endPrefixMapping("prefix"); 97 } catch (SAXException e) { 98 throw new RuntimeException(e); 99 } 100 } 101 102 public void testStartElement() { 103 try { 104 h.startElement("uri", "name", "qname", new AttributesImpl()); 105 } catch (SAXException e) { 106 throw new RuntimeException(e); 107 } 108 } 109 110 public void testEndElement() { 111 try { 112 h.endElement("uri", "name", "qname"); 113 } catch (SAXException e) { 114 throw new RuntimeException(e); 115 } 116 } 117 118 public void testCharacters() { 119 try { 120 h.characters("The quick brown fox".toCharArray(), 4, 11); 121 } catch (SAXException e) { 122 throw new RuntimeException(e); 123 } 124 } 125 126 public void testIgnorableWhitespace() { 127 try { 128 h.ignorableWhitespace(" ".toCharArray(), 4, 11); 129 } catch (SAXException e) { 130 throw new RuntimeException(e); 131 } 132 } 133 134 public void testProcessingInstruction() { 135 try { 136 h.processingInstruction("target", "data"); 137 } catch (SAXException e) { 138 throw new RuntimeException(e); 139 } 140 } 141 142 public void testSkippedEntity() { 143 try { 144 h.skippedEntity("name"); 145 } catch (SAXException e) { 146 throw new RuntimeException(e); 147 } 148 } 149 150 public void testWarning() { 151 try { 152 h.warning(new SAXParseException("Foo", new LocatorImpl())); 153 } catch (SAXException e) { 154 throw new RuntimeException(e); 155 } 156 } 157 158 public void testError() { 159 try { 160 h.error(new SAXParseException("Foo", new LocatorImpl())); 161 } catch (SAXException e) { 162 throw new RuntimeException(e); 163 } 164 } 165 166 public void testFatalError() { 167 // Ordinary case 168 try { 169 h.fatalError(new SAXParseException("Foo", new LocatorImpl())); 170 fail("SAXException expected"); 171 } catch (SAXException e) { 172 // Expected 173 } 174 175 // No exception 176 try { 177 h.fatalError(null); 178 fail("NullPointerException expected"); 179 } catch (SAXException e) { 180 fail("NullPointerException expected"); 181 } catch (NullPointerException e) { 182 // Expected 183 } 184 185 } 186 187} 188