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