Mercurial > hg > Members > kono > jpf-core
comparison src/tests/gov/nasa/jpf/test/mc/basic/FinalFieldChoiceTest.java @ 0:61d41facf527
initial v8 import (history reset)
author | Peter Mehlitz <Peter.C.Mehlitz@nasa.gov> |
---|---|
date | Fri, 23 Jan 2015 10:14:01 -0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:61d41facf527 |
---|---|
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.test.mc.basic; | |
20 | |
21 import gov.nasa.jpf.util.test.TestJPF; | |
22 import gov.nasa.jpf.vm.Verify; | |
23 import org.junit.Test; | |
24 | |
25 /** | |
26 * test non-deterministic init of final fields | |
27 */ | |
28 public class FinalFieldChoiceTest extends TestJPF { | |
29 | |
30 | |
31 //--- instance fields | |
32 | |
33 static class X { | |
34 final boolean a; | |
35 final boolean b; | |
36 | |
37 X(){ | |
38 a = Verify.getBoolean(); | |
39 b = Verify.getBoolean(); | |
40 } | |
41 } | |
42 | |
43 @Test | |
44 public void testFinalInstanceFields(){ | |
45 if (!isJPFRun()){ | |
46 Verify.resetCounter(0); | |
47 Verify.resetCounter(1); | |
48 } | |
49 | |
50 if (verifyNoPropertyViolation()){ | |
51 X x = new X(); | |
52 System.out.print("a="); | |
53 System.out.print(x.a); | |
54 System.out.print(", b="); | |
55 System.out.println(x.b); | |
56 | |
57 Verify.incrementCounter(0); | |
58 | |
59 int n = Verify.getCounter(1); | |
60 if (x.a && x.b) Verify.setCounter(1, n+3); | |
61 else if (x.a) Verify.setCounter(1, n+2); | |
62 else if (x.b) Verify.setCounter(1, n+1); | |
63 } | |
64 | |
65 if (!isJPFRun()){ | |
66 assertTrue( "wrong number of choices", Verify.getCounter(0) == 4); | |
67 assertTrue( "wrong choice values", Verify.getCounter(1) == 6); | |
68 } | |
69 } | |
70 | |
71 //--- static fields | |
72 static class Y { | |
73 static final boolean a = Verify.getBoolean(); | |
74 static final boolean b = Verify.getBoolean(); | |
75 } | |
76 | |
77 @Test | |
78 public void testFinalStaticFields(){ | |
79 if (!isJPFRun()){ | |
80 Verify.resetCounter(0); | |
81 Verify.resetCounter(1); | |
82 } | |
83 | |
84 if (verifyNoPropertyViolation()){ | |
85 boolean a = Y.a; | |
86 boolean b = Y.b; | |
87 | |
88 System.out.print("Y.a="); | |
89 System.out.print(a); | |
90 System.out.print(", Y.b="); | |
91 System.out.println(b); | |
92 | |
93 Verify.incrementCounter(0); | |
94 | |
95 int n = Verify.getCounter(1); | |
96 if (Y.a && Y.b) Verify.setCounter(1, n+3); | |
97 else if (Y.a) Verify.setCounter(1, n+2); | |
98 else if (Y.b) Verify.setCounter(1, n+1); | |
99 } | |
100 | |
101 if (!isJPFRun()){ | |
102 assertTrue( "wrong number of choices", Verify.getCounter(0) == 4); | |
103 assertTrue( "wrong choice values", Verify.getCounter(1) == 6); | |
104 } | |
105 } | |
106 } |