1731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar/*
2731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar * Copyright (C) 2015 The Android Open Source Project
3731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar *
4731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar * Licensed under the Apache License, Version 2.0 (the "License");
5731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar * you may not use this file except in compliance with the License.
6731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar * You may obtain a copy of the License at
7731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar *
8731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar *      http://www.apache.org/licenses/LICENSE-2.0
9731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar *
10731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar * Unless required by applicable law or agreed to in writing, software
11731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar * distributed under the License is distributed on an "AS IS" BASIS,
12731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar * See the License for the specific language governing permissions and
14731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar * limitations under the License.
15731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar */
16731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar
17731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyarpackage android.databinding.tool.store;
18731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar
19731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar
20731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyarimport org.junit.Test;
21731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar
22731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyarimport static org.junit.Assert.assertEquals;
23731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyarimport static org.junit.Assert.assertFalse;
24731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyarimport static org.junit.Assert.assertTrue;
25731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar
26731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar
27731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyarpublic class LocationTest {
28731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    @Test
29731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    public void testInvalid() {
30731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        assertFalse(new Location().isValid());
31731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    }
32731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar
33731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    @Test
34731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    public void testValid() {
35731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        Location location = new Location(0, 0, 1, 1);
36731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        assertTrue(location.isValid());
37731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    }
38731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar
39731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    @Test
40731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    public void testContains() {
41731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        Location location1 = new Location(0, 0, 10, 1);
42731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        Location location2 = new Location(0, 0, 9, 1);
43731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        assertTrue(location1.contains(location2));
44731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        location2.endLine = 10;
45731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        assertTrue(location1.contains(location2));
46731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        location2.endOffset = 2;
47731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        assertFalse(location1.contains(location2));
48731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    }
49731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar
50731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    @Test
51731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    public void testAbsolute() {
52731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        Location loc = new Location(1, 2, 3, 4);
53731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        assertEquals(loc, loc.toAbsoluteLocation());
54731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    }
55731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar
56731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    @Test
57731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    public void testAbsoluteWithInvalidParent() {
58731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        Location loc = new Location(1, 2, 3, 4);
59731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        loc.setParentLocation(new Location());
60731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        assertEquals(loc, loc.toAbsoluteLocation());
61731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    }
62731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar
63731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    @Test
64731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    public void testAbsoluteWithParent() {
65731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        Location loc = new Location(1, 2, 3, 4);
66731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        loc.setParentLocation(new Location(10, 0, 20, 0));
67731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        assertEquals(new Location(11, 2, 13, 4), loc.toAbsoluteLocation());
68731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    }
69731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar
70731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    @Test
71731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    public void testAbsoluteWith2Parents() {
72731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        Location loc = new Location(1, 2, 3, 4);
73731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        Location parent1 = new Location(5, 6, 10, 11);
74731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        parent1.setParentLocation(new Location(5, 6, 17, 8));
75731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        loc.setParentLocation(parent1);
76731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        assertEquals(new Location(10, 6, 15, 11), parent1.toAbsoluteLocation());
77731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        assertEquals(new Location(11, 2, 13, 4), loc.toAbsoluteLocation());
78731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    }
79731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar
80731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    @Test
81731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    public void testAbsoluteWithSameLine() {
82731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        Location loc = new Location(0, 2, 0, 4);
83731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        loc.setParentLocation(new Location(7, 2, 12, 46));
84731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        assertEquals(new Location(7, 4, 7, 6), loc.toAbsoluteLocation());
85731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar    }
86731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar}
87