File tree Expand file tree Collapse file tree 5 files changed +70
-6
lines changed
regression/jbmc-strings/StringEquals Expand file tree Collapse file tree 5 files changed +70
-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+
14public class Test {
25 public static void check (int i , String s ) {
36 String t = "Hello World" ;
@@ -15,4 +18,49 @@ else if (i==4)
1518 else if (i ==5 )
1619 assert (s .equals (x ));
1720 }
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+
1866}
Original file line number Diff line number Diff line change @@ -3,10 +3,10 @@ Test.class
33--refine-strings --string-max-length 40 --function Test.check
44^EXIT=10$
55^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
1212--
Original file line number Diff line number Diff line change 1+ KNOWNBUG
2+ Test.class
3+ --string-max-input-length 20 --string-max-length 100 --unwind 30 --function Test.verify
4+ ^EXIT=0$
5+ ^SIGNAL=0$
6+ assertion at file Test.java line 60 .* SUCCESS
7+ --
8+ --
9+ Our current implementation does not handle the null case
10+ TG-2179
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