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.mc.data;
20 import gov.nasa.jpf.util.test.TestJPF;
21 import gov.nasa.jpf.vm.Verify;
24 import java.io.Serializable;
25 import java.util.ArrayList;
27 import org.junit.After;
28 import org.junit.Test;
32 * @author Ivan Mushketik
34 public class ObjectStreamTest extends TestJPF {
35 static String osFileName = "file";
38 public void deleteFile(){
39 File osFile = new File(osFileName);
41 if (osFile.exists()) {
48 public void testWriteReadInteger() {
50 Verify.writeObjectToFile(new Integer(123), osFileName);
53 if (verifyNoPropertyViolation()) {
54 Integer i = Verify.readObjectFromFile(Integer.class, osFileName);
61 public void testWriteReadString() {
63 Verify.writeObjectToFile(new String("hello"), osFileName);
66 if (verifyNoPropertyViolation()) {
67 String s = Verify.readObjectFromFile(String.class, osFileName);
68 assert s.equals("hello");
72 static class Sup implements Serializable {
76 static class Inherited extends Sup{
81 public void testWriteReadInheritedClass() {
83 Inherited inh = new Inherited();
87 Verify.writeObjectToFile(inh, osFileName);
90 if (verifyNoPropertyViolation("+jpf-core.native_classpath+=;${jpf-core}/build/tests")) {
91 Inherited inh = Verify.readObjectFromFile(Inherited.class, osFileName);
99 static class WithTransient implements Serializable {
105 public void testWriteReadTransientField() {
107 WithTransient wt = new WithTransient();
110 Verify.writeObjectToFile(wt, osFileName);
113 if (verifyNoPropertyViolation("+jpf-core.native_classpath+=;${jpf-core}/build/tests")) {
114 WithTransient wt = Verify.readObjectFromFile(WithTransient.class, osFileName);
122 class SerializableArrayList<T> extends ArrayList<T> implements Serializable {}
125 public void testWriteReadArrayList() {
127 ArrayList<Integer> al = new ArrayList<Integer>();
131 Verify.writeObjectToFile(al, osFileName);
134 if (verifyNoPropertyViolation()) {
135 ArrayList al = Verify.readObjectFromFile(ArrayList.class, osFileName);
137 assert al.size() == 3;
138 assert al.get(0).equals(1);
139 assert al.get(1).equals(2);
140 assert al.get(2).equals(3);
144 static class MultiDimArr implements Serializable {
149 public void tsetWriteReadObjectWithMultiDimArray() {
151 MultiDimArr mda = new MultiDimArr();
152 mda.arr = new int[2][];
153 mda.arr[0] = new int[3];
154 mda.arr[1] = new int[3];
164 Verify.writeObjectToFile(mda, osFileName);
167 if (verifyNoPropertyViolation("+jpf-core.native_classpath+=;${jpf-core}/build/tests")) {
168 MultiDimArr mda = Verify.readObjectFromFile(MultiDimArr.class, osFileName);
170 assert mda.arr[0][0] == 1;
171 assert mda.arr[0][1] == 2;
172 assert mda.arr[0][2] == 3;
174 assert mda.arr[1][0] == 4;
175 assert mda.arr[1][1] == 5;
176 assert mda.arr[1][2] == 6;
180 static class Inner implements Serializable {
184 static class Outer implements Serializable {
191 public void testReadWriteObjectWithReference() {
193 Outer out = new Outer();
195 out.inner = new Inner();
198 Verify.writeObjectToFile(out, osFileName);
201 if (verifyNoPropertyViolation("+jpf-core.native_classpath+=;${jpf-core}/build/tests")) {
202 Outer out = Verify.readObjectFromFile(Outer.class, osFileName);
205 assert out.inner.i == 2;