Initial import
[jpf-core.git] / src / tests / gov / nasa / jpf / util / LocationSpecTest.java
1 /*
2  * Copyright (C) 2014, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The Java Pathfinder core (jpf-core) platform is licensed under the
7  * Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  * 
10  *        http://www.apache.org/licenses/LICENSE-2.0. 
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and 
16  * limitations under the License.
17  */
18
19 package gov.nasa.jpf.util;
20
21 import gov.nasa.jpf.util.test.TestJPF;
22
23 import org.junit.Test;
24
25 /**
26  * unit test for gov.nasa.jpf.util.LocationSpec
27  */
28 public class LocationSpecTest extends TestJPF {
29
30   @Test
31   public void testSingleLocation() {
32     LocationSpec ls = LocationSpec.createLocationSpec("Foobar.java:42");
33     System.out.println("# testing: " + ls);
34
35     assertTrue(ls.matchesFile("Foobar.java"));
36     assertTrue(!ls.isLineInterval());
37     assertTrue(ls.getLine() == 42);
38
39     assertFalse(ls.matchesFile("Bull"));
40
41     assertTrue(ls.matchesFile("/x/y/Foobar.java"));
42   }
43
44   @Test
45   public void testAbsoluteLocation() {
46     LocationSpec ls = LocationSpec.createLocationSpec("/x/y/z/Foobar.java:42");
47     System.out.println("# testing: " + ls);
48
49     assertTrue(ls.matchesFile("/x/y/z/Foobar.java"));
50   }
51
52   @Test
53   public void testPlatformLocation() {
54     LocationSpec ls = LocationSpec.createLocationSpec("C:\\x\\y\\z\\Foobar.java:42");
55     System.out.println("# testing: " + ls);
56
57     assertTrue(ls.matchesFile("C:\\x\\y\\z\\Foobar.java"));
58     assertTrue(ls.getLine() == 42);
59   }
60
61
62   @Test
63   public void testRelativeLocation() {
64     LocationSpec ls = LocationSpec.createLocationSpec("x/y/z/Foobar.java:42");
65     System.out.println("# testing: " + ls);
66
67     assertTrue(ls.matchesFile("x/y/z/Foobar.java"));
68   }
69
70   @Test
71   public void testWildcards() {
72     LocationSpec ls = LocationSpec.createLocationSpec("x/*/Foo*.java:42");
73     System.out.println("# testing: " + ls);
74
75     assertTrue(ls.matchesFile("x/y/z/Foobar.java"));
76     assertTrue(ls.matchesFile("Fooboo.java"));
77   }
78
79   @Test
80   public void testAbsoluteRange(){
81     LocationSpec ls = LocationSpec.createLocationSpec("Foobar.java:42-48");
82     System.out.println("# testing: " + ls);
83
84     assertTrue(ls.isLineInterval());
85     assertTrue(ls.getFromLine() == 42);
86     assertTrue(ls.getToLine() == 48);
87   }
88
89   @Test
90   public void testRelativeRange(){
91     LocationSpec ls = LocationSpec.createLocationSpec("Foobar.java:42+6");
92     System.out.println("# testing: " + ls);
93
94     assertTrue(ls.isLineInterval());
95     assertTrue(ls.getFromLine() == 42);
96     assertTrue(ls.getToLine() == 48);
97   }
98
99   @Test
100   public void testOpenRange(){
101     LocationSpec ls = LocationSpec.createLocationSpec("Foobar.java:42+");
102     System.out.println("# testing: " + ls);
103
104     assertTrue(ls.isLineInterval());
105     assertTrue(ls.getFromLine() == 42);
106     assertTrue(ls.getToLine() == Integer.MAX_VALUE);
107   }
108
109 }