Home | History | Annotate | Download | only in store
      1 /*
      2  * Copyright (C) 2015 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 android.databinding.tool.store;
     18 
     19 
     20 import org.junit.Test;
     21 
     22 import static org.junit.Assert.assertEquals;
     23 import static org.junit.Assert.assertFalse;
     24 import static org.junit.Assert.assertTrue;
     25 
     26 
     27 public class LocationTest {
     28     @Test
     29     public void testInvalid() {
     30         assertFalse(new Location().isValid());
     31     }
     32 
     33     @Test
     34     public void testValid() {
     35         Location location = new Location(0, 0, 1, 1);
     36         assertTrue(location.isValid());
     37     }
     38 
     39     @Test
     40     public void testContains() {
     41         Location location1 = new Location(0, 0, 10, 1);
     42         Location location2 = new Location(0, 0, 9, 1);
     43         assertTrue(location1.contains(location2));
     44         location2.endLine = 10;
     45         assertTrue(location1.contains(location2));
     46         location2.endOffset = 2;
     47         assertFalse(location1.contains(location2));
     48     }
     49 
     50     @Test
     51     public void testAbsolute() {
     52         Location loc = new Location(1, 2, 3, 4);
     53         assertEquals(loc, loc.toAbsoluteLocation());
     54     }
     55 
     56     @Test
     57     public void testAbsoluteWithInvalidParent() {
     58         Location loc = new Location(1, 2, 3, 4);
     59         loc.setParentLocation(new Location());
     60         assertEquals(loc, loc.toAbsoluteLocation());
     61     }
     62 
     63     @Test
     64     public void testAbsoluteWithParent() {
     65         Location loc = new Location(1, 2, 3, 4);
     66         loc.setParentLocation(new Location(10, 0, 20, 0));
     67         assertEquals(new Location(11, 2, 13, 4), loc.toAbsoluteLocation());
     68     }
     69 
     70     @Test
     71     public void testAbsoluteWith2Parents() {
     72         Location loc = new Location(1, 2, 3, 4);
     73         Location parent1 = new Location(5, 6, 10, 11);
     74         parent1.setParentLocation(new Location(5, 6, 17, 8));
     75         loc.setParentLocation(parent1);
     76         assertEquals(new Location(10, 6, 15, 11), parent1.toAbsoluteLocation());
     77         assertEquals(new Location(11, 2, 13, 4), loc.toAbsoluteLocation());
     78     }
     79 
     80     @Test
     81     public void testAbsoluteWithSameLine() {
     82         Location loc = new Location(0, 2, 0, 4);
     83         loc.setParentLocation(new Location(7, 2, 12, 46));
     84         assertEquals(new Location(7, 4, 7, 6), loc.toAbsoluteLocation());
     85     }
     86 }
     87