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.ext; 18 19 import junit.framework.TestCase; 20 21 import org.xml.sax.Locator; 22 import org.xml.sax.ext.Locator2Impl; 23 import org.xml.sax.helpers.LocatorImpl; 24 25 public class Locator2ImplTest extends TestCase { 26 27 public static final String SYS = "mySystemID"; 28 29 public static final String PUB = "myPublicID"; 30 31 public static final int ROW = 1; 32 33 public static final int COL = 2; 34 35 public static final String ENC = "Klingon"; 36 37 public static final String XML = "1.0"; 38 39 public void testLocatorImpl() { 40 Locator2Impl l = new Locator2Impl(); 41 42 assertEquals(null, l.getPublicId()); 43 assertEquals(null, l.getSystemId()); 44 assertEquals(0, l.getLineNumber()); 45 assertEquals(0, l.getColumnNumber()); 46 47 assertEquals(null, l.getEncoding()); 48 assertEquals(null, l.getXMLVersion()); 49 } 50 51 public void testLocatorImplLocator() { 52 Locator2Impl inner = new Locator2Impl(); 53 54 inner.setPublicId(PUB); 55 inner.setSystemId(SYS); 56 inner.setLineNumber(ROW); 57 inner.setColumnNumber(COL); 58 59 inner.setEncoding(ENC); 60 inner.setXMLVersion(XML); 61 62 // Ordinary case 63 Locator2Impl outer = new Locator2Impl(inner); 64 65 assertEquals(PUB, outer.getPublicId()); 66 assertEquals(SYS, outer.getSystemId()); 67 assertEquals(ROW, outer.getLineNumber()); 68 assertEquals(COL, outer.getColumnNumber()); 69 70 assertEquals(ENC, outer.getEncoding()); 71 assertEquals(XML, outer.getXMLVersion()); 72 73 // Instance of old locator 74 outer = new Locator2Impl(new LocatorImpl(inner)); 75 76 assertEquals(PUB, outer.getPublicId()); 77 assertEquals(SYS, outer.getSystemId()); 78 assertEquals(ROW, outer.getLineNumber()); 79 assertEquals(COL, outer.getColumnNumber()); 80 81 assertEquals(null, outer.getEncoding()); 82 assertEquals(null, outer.getXMLVersion()); 83 84 // No locator 85 try { 86 outer = new Locator2Impl(null); 87 fail("NullPointerException expected"); 88 } catch (NullPointerException e) { 89 // Expected 90 } 91 } 92 93 public void testSetXMLVersionGetXMLVersion() { 94 Locator2Impl l = new Locator2Impl(); 95 96 l.setXMLVersion(XML); 97 assertEquals(XML, l.getXMLVersion()); 98 99 l.setXMLVersion(null); 100 assertEquals(null, l.getXMLVersion()); 101 } 102 103 public void testSetEncodingGetEncoding() { 104 Locator2Impl l = new Locator2Impl(); 105 106 l.setEncoding(ENC); 107 assertEquals(ENC, l.getEncoding()); 108 109 l.setEncoding(null); 110 assertEquals(null, l.getEncoding()); 111 } 112 113 } 114