Skip to content

Commit f9da0bd

Browse files
committed
Add tests for enums returned by opaque methods
The tests were copied from jbmc/regression/jbmc/NondetEnumArg and adapted for the case where the enum is returned by an opaque method (Opaque.class has been deleted).
1 parent cc6136b commit f9da0bd

9 files changed

+100
-0
lines changed
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public enum Color {
2+
RED,
3+
GREEN,
4+
BLUE
5+
}
Binary file not shown.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
public class NondetEnumOpaqueReturn {
2+
3+
public static void canChooseSomeConstant() {
4+
Opaque o = new Opaque();
5+
Color c = o.getC();
6+
if (c == null)
7+
return;
8+
assert c != null;
9+
boolean isRed = c.name().startsWith("RED") && c.name().length() == 3
10+
&& c.ordinal() == 0;
11+
boolean isGreen = c.name().startsWith("GREEN") && c.name().length() == 5
12+
&& c.ordinal() == 1;
13+
boolean isBlue = c.name().startsWith("BLUE") && c.name().length() == 4
14+
&& c.ordinal() == 2;
15+
assert (isRed || isGreen || isBlue);
16+
}
17+
18+
public static void canChooseRed() {
19+
Opaque o = new Opaque();
20+
Color c = o.getC();
21+
if (c == null)
22+
return;
23+
boolean isGreen = c.name().startsWith("GREEN") && c.name().length() == 5
24+
&& c.ordinal() == 1;
25+
boolean isBlue = c.name().startsWith("BLUE") && c.name().length() == 4
26+
&& c.ordinal() == 2;
27+
assert (isGreen || isBlue);
28+
}
29+
30+
public static void canChooseGreen() {
31+
Opaque o = new Opaque();
32+
Color c = o.getC();
33+
if (c == null)
34+
return;
35+
boolean isRed = c.name().startsWith("RED") && c.name().length() == 3
36+
&& c.ordinal() == 0;
37+
boolean isBlue = c.name().startsWith("BLUE") && c.name().length() == 4
38+
&& c.ordinal() == 2;
39+
assert (isRed || isBlue);
40+
}
41+
42+
public static void canChooseBlue() {
43+
Opaque o = new Opaque();
44+
Color c = o.getC();
45+
if (c == null)
46+
return;
47+
boolean isRed = c.name().startsWith("RED") && c.name().length() == 3
48+
&& c.ordinal() == 0;
49+
boolean isGreen = c.name().startsWith("GREEN") && c.name().length() == 5
50+
&& c.ordinal() == 1;
51+
assert (isRed || isGreen);
52+
}
53+
54+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public class Opaque {
2+
3+
Color c;
4+
5+
public Color getC() {
6+
return c;
7+
}
8+
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
NondetEnumOpaqueReturn.class
3+
--function NondetEnumOpaqueReturn.canChooseSomeConstant --cp `../../../../scripts/format_classpath.sh . ../../../src/java_bytecode/library/core-models.jar`
4+
^VERIFICATION SUCCESSFUL$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
--
9+
The test checks that the name and ordinal fields of nondet-initialized enums
10+
which have been returned by an opaque method correspond to those of an enum
11+
constant of the same type.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
NondetEnumOpaqueReturn.class
3+
--function NondetEnumOpaqueReturn.canChooseRed --cp `../../../../scripts/format_classpath.sh . ../../../src/java_bytecode/library/core-models.jar`
4+
^VERIFICATION FAILED$
5+
--
6+
--
7+
Test 1 of 3 to check that any of the enum constants can be chosen.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
NondetEnumOpaqueReturn.class
3+
--function NondetEnumOpaqueReturn.canChooseGreen --cp `../../../../scripts/format_classpath.sh . ../../../src/java_bytecode/library/core-models.jar`
4+
^VERIFICATION FAILED$
5+
--
6+
--
7+
Test 2 of 3 to check that any of the enum constants can be chosen.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
NondetEnumOpaqueReturn.class
3+
--function NondetEnumOpaqueReturn.canChooseBlue --cp `../../../../scripts/format_classpath.sh . ../../../src/java_bytecode/library/core-models.jar`
4+
^VERIFICATION FAILED$
5+
--
6+
--
7+
Test 3 of 3 to check that any of the enum constants can be chosen.

0 commit comments

Comments
 (0)