File tree Expand file tree Collapse file tree 4 files changed +67
-0
lines changed
regression/jbmc-strings/StringEquals Expand file tree Collapse file tree 4 files changed +67
-0
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,51 @@ 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 (s == null )
24+ return o == null ;
25+ if (! (o instanceof String ))
26+ return false ;
27+
28+ String s2 = (String ) o ;
29+ if (s .length () != s2 .length ())
30+ return false ;
31+
32+ for (int i = 0 ; i < s .length (); i ++) {
33+ if (CProverString .charAt (s , i ) != CProverString .charAt (s2 , i ))
34+ return false ;
35+ }
36+
37+ return true ;
38+ }
39+
40+ public static boolean verifyNonNull (String s , Object o ) {
41+ // Filter
42+ if (s == null || o == null )
43+ return false ;
44+
45+ // Act
46+ boolean result = s .equals (o );
47+ boolean referenceResult = referenceImplementation (s , o );
48+
49+ // Assert
50+ assert result == referenceResult ;
51+
52+ // Return
53+ return result ;
54+ }
55+
56+ public static boolean verify (String s , Object o ) {
57+ // Act
58+ boolean result = s .equals (o );
59+ boolean referenceResult = referenceImplementation (s , o );
60+
61+ // Assert
62+ assert result == referenceResult ;
63+
64+ // Return
65+ return result ;
66+ }
67+
1868}
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 62 .* 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+ --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 50 .* SUCCESS
7+ --
You can’t perform that action at this time.
0 commit comments