2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
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
10 * http://www.apache.org/licenses/LICENSE-2.0.
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.
21 import gov.nasa.jpf.util.test.TestJPF;
24 import java.util.regex.Matcher;
26 import org.junit.Test;
30 * unit test for Config
32 public class ConfigTest extends TestJPF {
35 public void testDefaultAppPropertyInit () {
37 String dir = "src/tests/gov/nasa/jpf";
38 String[] args = {dir + "/configTestApp.jpf"};
40 Config conf = new Config(args);
42 String val = conf.getString("vm.class");
43 assert "gov.nasa.jpf.vm.SingleProcessVM".equals(val);
45 val = conf.getString("target"); // from configTest.jpf
46 assert "urgh.org.MySystemUnderTest".equals(val);
48 // that's testing key expansion and the builtin "config_path"
49 val = conf.getString("mySUT.location");
53 if (!File.separator.equals("/"))
54 dir = dir.replaceAll("/", Matcher.quoteReplacement(File.separator)); // On UNIX Config returns / and on Windows Config returns \\
56 assert val.endsWith(dir);
60 public void testDefaultExplicitTargetInit () {
61 String[] args = {"urgh.org.MySystemUnderTest"};
63 Config conf = new Config( args);
64 String[] freeArgs = conf.getFreeArgs();
65 assertTrue( freeArgs.length == 1);
66 assertTrue( "urgh.org.MySystemUnderTest".equals(freeArgs[0]));
70 public void testExplicitLocations () {
71 String dir = "src/tests/gov/nasa/jpf/";
72 String[] args = {"+site=" + dir + "configTestSite.properties",
73 "+app=" + dir + "configTestApp.jpf" };
75 Config conf = new Config( args);
78 assert "urgh.org.MySystemUnderTest".equals(conf.getString("target"));
82 public void testTargetArgsOverride () {
84 String dir = "src/tests/gov/nasa/jpf/";
85 String[] args = { dir + "configTestApp.jpf",
88 Config conf = new Config(args);
91 String[] ta = conf.getStringArray("target.args");
93 assert ta.length == 3;
94 assert "a".equals(ta[0]);
95 assert "b".equals(ta[1]);
96 assert "c".equals(ta[2]);
98 String[] freeArgs = conf.getFreeArgs();
99 assert freeArgs != null;
100 assert freeArgs.length == 2;
101 assert "x".equals(freeArgs[0]);
102 assert "y".equals(freeArgs[1]);
106 public void testClassPaths () {
107 String dir = "src/tests/gov/nasa/jpf/";
108 String[] args = {"+site=" + dir + "configTestSite.properties",
109 "+app=" + dir + "configTestApp.jpf" };
111 Config conf = new Config( args);
114 // those properties are very weak!
115 String[] bootCpEntries = conf.asStringArray("boot_classpath");
116 assert bootCpEntries.length > 0;
118 String[] nativeCpEntries = conf.asStringArray("native_classpath");
119 assert nativeCpEntries.length > 0;
123 public void testRequiresOk () {
124 String dir = "src/tests/gov/nasa/jpf/";
125 String[] args = { "+site=" + dir + "configTestSite.properties",
126 dir + "configTestRequires.jpf" };
128 Config.enableLogging(true);
129 Config conf = new Config( args);
130 String v = conf.getString("whoa");
131 System.out.println("got whoa = " + v);
133 assert (v != null) && v.equals("boa");
137 public void testRequiresFail () {
138 String dir = "src/tests/gov/nasa/jpf/";
139 String[] args = { "+site=" + dir + "configTestSite.properties",
140 dir + "configTestRequiresFail.jpf" };
142 Config.enableLogging(true);
143 Config conf = new Config( args);
144 String v = conf.getString("whoa");
145 System.out.println("got whoa = " + v);
151 public void testIncludes () {
152 String dir = "src/tests/gov/nasa/jpf/";
153 String[] args = { "+site=" + dir + "configTestSite.properties",
154 dir + "configTestIncludes.jpf" };
156 Config.enableLogging(true);
157 Config conf = new Config( args);
158 String v = conf.getString("my.common");
159 System.out.println("got my.common = " + v);
161 assert (v != null) && v.equals("whatever");
165 public void testIntArray(){
166 String dir = "src/tests/gov/nasa/jpf/";
167 String[] args = { "+site=" + dir + "configTestSite.properties",
170 Config.enableLogging(true);
171 Config conf = new Config( args);
172 int[] a = conf.getIntArray("arr");
174 assertTrue(a != null);
175 assertTrue(a.length == 3);
176 assertTrue(a[0] == -42 && a[1] == 0xff && a[2] == 0);