File tree 5 files changed +71
-6
lines changed
regression/jbmc-strings/StringEquals
5 files changed +71
-6
lines changed Original file line number Diff line number Diff line change
1
+ // Uses CProverString, must be compiled with ../cprover/CProverString.java
2
+ import org .cprover .*;
3
+
1
4
public class Test {
2
5
public static void check (int i , String s ) {
3
6
String t = "Hello World" ;
@@ -15,4 +18,49 @@ else if (i==4)
15
18
else if (i ==5 )
16
19
assert (s .equals (x ));
17
20
}
21
+
22
+ public static boolean referenceImplementation (String s , Object o ) {
23
+ if (! (o instanceof String ))
24
+ return false ;
25
+
26
+ String s2 = (String ) o ;
27
+ if (s .length () != s2 .length ())
28
+ return false ;
29
+
30
+ for (int i = 0 ; i < s .length (); i ++) {
31
+ if (CProverString .charAt (s , i ) != CProverString .charAt (s2 , i ))
32
+ return false ;
33
+ }
34
+
35
+ return true ;
36
+ }
37
+
38
+ public static boolean verifyNonNull (String s , Object o ) {
39
+ // Filter
40
+ if (s == null || o == null )
41
+ return false ;
42
+
43
+ // Act
44
+ boolean result = s .equals (o );
45
+ boolean referenceResult = referenceImplementation (s , o );
46
+
47
+ // Assert
48
+ assert result == referenceResult ;
49
+
50
+ // Return
51
+ return result ;
52
+ }
53
+
54
+ public static boolean verify (String s , Object o ) {
55
+ // Act
56
+ boolean result = s .equals (o );
57
+ boolean referenceResult = referenceImplementation (s , o );
58
+
59
+ // Assert
60
+ assert result == referenceResult ;
61
+
62
+ // Return
63
+ return result ;
64
+ }
65
+
18
66
}
Original file line number Diff line number Diff line change @@ -3,10 +3,10 @@ Test.class
3
3
--refine-strings --string-max-length 40 --function Test.check
4
4
^EXIT=10$
5
5
^SIGNAL=0$
6
- assertion at file Test.java line 6 .* SUCCESS
7
- assertion at file Test.java line 8 .* FAILURE
8
- assertion at file Test.java line 10 .* SUCCESS
9
- assertion at file Test.java line 12 .* FAILURE
10
- assertion at file Test.java line 14 .* SUCCESS
11
- assertion at file Test.java line 16 .* FAILURE
6
+ assertion at file Test.java line 9 .* SUCCESS
7
+ assertion at file Test.java line 11 .* FAILURE
8
+ assertion at file Test.java line 13 .* SUCCESS
9
+ assertion at file Test.java line 15 .* FAILURE
10
+ assertion at file Test.java line 17 .* SUCCESS
11
+ assertion at file Test.java line 19 .* FAILURE
12
12
--
Original file line number Diff line number Diff line change
1
+ KNOWNBUG
2
+ Test.class
3
+ --refine-strings --string-max-input-length 5 --string-max-length 100 --unwind 10 --function Test.verify --java-throw-runtime-exceptions
4
+ ^EXIT=0$
5
+ ^SIGNAL=0$
6
+ assertion at file Test.java line 60 .* SUCCESS
7
+ --
8
+ --
9
+ null case not handled currently
10
+ TG-2179
11
+
Original file line number Diff line number Diff line change
1
+ CORE
2
+ Test.class
3
+ --refine-strings --string-max-input-length 20 --string-max-length 100 --unwind 30 --function Test.verifyNonNull
4
+ ^EXIT=0$
5
+ ^SIGNAL=0$
6
+ assertion at file Test.java line 48 .* SUCCESS
You can’t perform that action at this time.
0 commit comments