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; 18 19import junit.framework.TestCase; 20 21import org.xml.sax.AttributeList; 22import org.xml.sax.HandlerBase; 23import org.xml.sax.SAXException; 24import org.xml.sax.SAXParseException; 25import org.xml.sax.helpers.AttributeListImpl; 26import org.xml.sax.helpers.LocatorImpl; 27 28@SuppressWarnings("deprecation") 29public class HandlerBaseTest extends TestCase { 30 31 /* 32 * Note: most of the tests have to check for an empty implementation of the 33 * respective methods and, as a result, are somewhat trivial. 34 */ 35 36 private HandlerBase h = new HandlerBase(); 37 38 public void testResolveEntity() { 39 try { 40 h.resolveEntity("publicID", "systemID"); 41 } catch (SAXException e) { 42 throw new RuntimeException(e); 43 } 44 } 45 46 public void testNotationDecl() { 47 h.notationDecl("name", "publicID", "systemID"); 48 } 49 50 public void testUnparsedEntityDecl() { 51 h.unparsedEntityDecl("name", "publicID", "systemID", "notationName"); 52 } 53 54 public void testSetDocumentLocator() { 55 h.setDocumentLocator(new LocatorImpl()); 56 } 57 58 public void testStartDocument() { 59 try { 60 h.startDocument(); 61 } catch (SAXException e) { 62 throw new RuntimeException(e); 63 } 64 } 65 66 public void testEndDocument() { 67 try { 68 h.endDocument(); 69 } catch (SAXException e) { 70 throw new RuntimeException(e); 71 } 72 } 73 74 public void testStartElement() { 75 try { 76 h.startElement("name", new AttributeListImpl()); 77 } catch (SAXException e) { 78 throw new RuntimeException(e); 79 } 80 } 81 82 public void testEndElement() { 83 try { 84 h.endElement("name"); 85 } catch (SAXException e) { 86 throw new RuntimeException(e); 87 } 88 } 89 90 public void testCharacters() { 91 try { 92 h.characters("The quick brown fox".toCharArray(), 4, 11); 93 } catch (SAXException e) { 94 throw new RuntimeException(e); 95 } 96 } 97 98 public void testIgnorableWhitespace() { 99 try { 100 h.ignorableWhitespace(" ".toCharArray(), 4, 11); 101 } catch (SAXException e) { 102 throw new RuntimeException(e); 103 } 104 } 105 106 public void testProcessingInstruction() { 107 try { 108 h.processingInstruction("target", "data"); 109 } catch (SAXException e) { 110 throw new RuntimeException(e); 111 } 112 } 113 114 public void testWarning() { 115 try { 116 h.warning(new SAXParseException("Foo", new LocatorImpl())); 117 } catch (SAXException e) { 118 throw new RuntimeException(e); 119 } 120 } 121 122 public void testError() { 123 try { 124 h.error(new SAXParseException("Foo", new LocatorImpl())); 125 } catch (SAXException e) { 126 throw new RuntimeException(e); 127 } 128 } 129 130 public void testFatalError() { 131 // Ordinary case 132 try { 133 h.fatalError(new SAXParseException("Foo", new LocatorImpl())); 134 fail("SAXException expected"); 135 } catch (SAXException e) { 136 // Expected 137 } 138 139 // No exception 140 try { 141 h.fatalError(null); 142 fail("NullPointerException expected"); 143 } catch (SAXException e) { 144 fail("NullPointerException expected"); 145 } catch (NullPointerException e) { 146 // Expected 147 } 148 149 } 150 151} 152