Skip to content

Commit 13eac31

Browse files
Add tests for inheritance of cproverNondetInitialize
1 parent 40ffd7d commit 13eac31

16 files changed

+129
-0
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import org.cprover.CProver;
2+
3+
class A {
4+
int x;
5+
6+
public void cproverNondetInitialize() { CProver.assume(x == 42); }
7+
}
8+
9+
class B extends A {}
10+
11+
class C extends B {}
12+
13+
class F extends A {
14+
public void cproverNondetInitialize() {}
15+
}
16+
17+
interface I {
18+
}
19+
20+
class J extends A implements I {
21+
}
22+
23+
class K extends A {
24+
int y;
25+
26+
public void cproverNondetInitialize() {
27+
super.cproverNondetInitialize();
28+
CProver.assume(y == 6);
29+
}
30+
}
31+
32+
abstract class M {
33+
int x;
34+
35+
public void cproverNondetInitialize() { CProver.assume(x == 42); }
36+
}
37+
38+
class N extends M {}
39+
40+
public class Test {
41+
42+
void inheritanceTwoLevels(C c) {
43+
if (c != null)
44+
assert (c.x == 42);
45+
}
46+
47+
void override(F f) {
48+
if (f != null)
49+
assert (f.x == 42);
50+
}
51+
52+
void callingSuperCproverNondetInitialize(K k) {
53+
if (k != null) {
54+
assert (k.x == 42);
55+
assert (k.y == 6);
56+
}
57+
}
58+
59+
void inheritanceFromAbstractClass(N n) {
60+
if (n != null)
61+
assert (n.x == 42);
62+
}
63+
64+
void alsoImplementsInterface(J j) {
65+
if (j != null)
66+
assert (j.x == 42);
67+
}
68+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
Test.class
3+
--function Test.alsoImplementsInterface --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--
10+
Check that if J extends A and implements the interface I,
11+
J.cproverNondetInitialize doesn't exist and A.cproverNondetInitialize does then
12+
a nondet J gets the constraints specified in A.cproverNondetInitialize.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
Test.class
3+
--function Test.callingSuperCproverNondetInitialize --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--
10+
Check that calls to super.cproverNondetInitialize call cproverNondetInitialize
11+
in the base class.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
Test.class
3+
--function Test.inheritanceFromAbstractClass --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--
10+
Check that if N extends the abstract class M, N.cproverNondetInitialize doesn't
11+
exist and M.cproverNondetInitialize does and is defined then a
12+
nondet N gets the constraints specified in M.cproverNondetInitialize.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
Test.class
3+
--function Test.inheritanceTwoLevels --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--
10+
Check that if C extends B, B extends A, B.cproverNondetInitialize and
11+
C.cproverNondetInitialize don't exist and A.cproverNondetInitialize does then a
12+
nondet C gets the constraints specified in A.cproverNondetInitialize.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CORE
2+
Test.class
3+
--function Test.override --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
^warning: ignoring
9+
--
10+
Check that if F extends A, and A.cproverNondetInitialize and
11+
F.cproverNondetInitialize both exist then a nondet F doesn't get the constraint
12+
specified in A.cproverNondetInitialize. Specifically, it doesn't get the
13+
constraint that x must be 42, so when we assert that x is 42 jbmc is able to
14+
falsify it.

0 commit comments

Comments
 (0)