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.
18 package gov.nasa.jpf.test.java.lang;
20 import gov.nasa.jpf.util.test.TestJPF;
21 import gov.nasa.jpf.vm.Verify;
23 import java.io.IOException;
25 import org.junit.Test;
28 * raw test for java.lang.System functionality
30 public class SystemTest extends TestJPF {
32 final Object lock = new Object(); // need a shared object
36 public void testExit() {
37 if (verifyNoPropertyViolation()) {
38 Thread t = new Thread(new Runnable() {
43 assert !exitCalled : "thread not stopped by System.exit()";
48 } catch (InterruptedException x) {
49 System.out.println("wait interrupted");
60 System.out.println("calling System.exit(0)");
64 assert false : "main not stopped by System.exit()";
69 * just needs a gazillion more cases (different sizes, slices, overruns,
70 * incompatible types etc.)
73 public void testSimpleArrayCopy() {
74 if (verifyNoPropertyViolation()) {
75 int[] a = {0, 1, 2, 3, 4, 5, 6, 7};
76 int[] b = new int[a.length];
78 System.arraycopy(a, 0, b, 0, a.length);
80 for (int i = 0; i < a.length; i++) {
87 public void testSelfArrayCopy(){
88 if (verifyNoPropertyViolation()){
89 int[] a = {0, 1, 2, 3, 4, 5, 6, 7};
91 System.arraycopy(a, 3, a, 0, 5);
93 // the overwritten ones
94 assertTrue(a[0] == 3);
95 assertTrue(a[1] == 4);
96 assertTrue(a[2] == 5);
97 assertTrue(a[3] == 6);
98 assertTrue(a[4] == 7);
101 assertTrue(a[5] == 5);
102 assertTrue(a[6] == 6);
103 assertTrue(a[7] == 7);
108 public void testOverlappingSelfArrayCopy(){
109 if (verifyNoPropertyViolation()){
110 int[] a = {0, 1, 2, 3, 4, 5, 6, 7};
112 System.arraycopy(a, 0, a, 2, 3);
114 // copying should proceed as if using a temporary destination
115 assertTrue(a[0] == 0);
116 assertTrue(a[1] == 1);
117 assertTrue(a[2] == 0);
118 assertTrue(a[3] == 1);
119 assertTrue(a[4] == 2);
120 assertTrue(a[5] == 5);
121 assertTrue(a[6] == 6);
122 assertTrue(a[7] == 7);
127 public void testIncompatibleReferencesArrayCopy(){
128 if (verifyUnhandledException("java.lang.ArrayStoreException")){
129 String[] dst = new String[2];
130 Object[] src = { "one", new Integer(2) };
132 System.arraycopy(src,0,dst,0,src.length);
137 public void testRestoredArrayCopy(){
138 if (verifyNoPropertyViolation()){
139 Object[] src = { "one", "two" };
140 Object[] dst = new Object[2];
142 int n = Verify.getInt(0, 1);
143 System.out.println("processing choice: " + n);
146 System.out.println("copying array");
147 System.arraycopy(src,0,dst,0,src.length);
149 System.out.println("checking if non-copied dst[0] is still null");
150 assertTrue( dst[0] == null);
156 public void testSystemIn() {
158 if (verifyNoPropertyViolation()) {
159 assert(System.in.available() == 0);
161 } catch (IOException e) {
162 fail(e.getMessage());