Skip to content

Commit ff4e5f5

Browse files
authored
Merge pull request #5231 from smowton/smowton/feature/fix-string-to-int
Fix string solver string-to-int conversion
2 parents 86d36f6 + 3c65c96 commit ff4e5f5

18 files changed

+263
-44
lines changed
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class Test4
2+
{
3+
public static void main(String input_string)
4+
{
5+
if(input_string.length() == 2) {
6+
assert(Integer.parseInt(input_string) != 50);
7+
}
8+
else if(input_string.length() == 4) {
9+
assert(!input_string.equals("XYZW"));
10+
}
11+
}
12+
}
Binary file not shown.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
public class Test5
2+
{
3+
public static void main(String input_string)
4+
{
5+
// Make test outputs readable by constraining length:
6+
if(input_string.length() != 4)
7+
return;
8+
int check = Integer.parseInt(input_string);
9+
boolean pass1 = false, pass2 = false, pass3 = false, throw1 = false, throw2 = false, throw3 = false;
10+
// If we get here input_string should be validated, so parsing again shouldn't throw:
11+
try {
12+
Integer.parseInt(input_string);
13+
pass1 = true;
14+
}
15+
catch(NumberFormatException e) {
16+
throw1 = true;
17+
}
18+
// Make it invalid:
19+
String broken = input_string + "&";
20+
try {
21+
Integer.parseInt(broken);
22+
pass2 = true;
23+
}
24+
catch(NumberFormatException e) {
25+
throw2 = true;
26+
}
27+
// Make it valid again:
28+
String fixed = broken.substring(0, broken.length() - 1);
29+
try {
30+
Integer.parseInt(fixed);
31+
pass3 = true;
32+
}
33+
catch(NumberFormatException e) {
34+
throw3 = true;
35+
}
36+
37+
// Check we followed the expected path:
38+
assert(pass1 && throw2 && pass3 && !throw1 && !pass2 && !throw3);
39+
// Check we can get to the end at all:
40+
assert(false);
41+
}
42+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
Test4
3+
--max-nondet-string-length 1000 --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar` --function Test4.main --trace
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^\[.*assertion.1\].* line 6.* FAILURE$
7+
^\[.*assertion.2\].* line 9.* FAILURE$
8+
dynamic_object2=\{ '5', '0' \}
9+
dynamic_object2=\{ 'X', 'Y', 'Z', 'W' \}
10+
--
11+
non equal types
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
Test5
3+
--max-nondet-string-length 1000 --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar` --function Test5.main
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^\[.*assertion..\].* line 38.* SUCCESS$
7+
^\[.*assertion..\].* line 40.* FAILURE$
8+
--
9+
non equal types
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
public class Test_invalid_number_throws
2+
{
3+
public static void main(String input_string)
4+
{
5+
// Make test outputs readable by constraining length:
6+
if(input_string.length() != 4)
7+
return;
8+
long check = Long.parseLong(input_string);
9+
boolean pass1 = false, pass2 = false, pass3 = false, throw1 = false, throw2 = false, throw3 = false;
10+
// If we get here input_string should be validated, so parsing again shouldn't throw:
11+
try {
12+
Long.parseLong(input_string);
13+
pass1 = true;
14+
}
15+
catch(NumberFormatException e) {
16+
throw1 = true;
17+
}
18+
// Make it invalid:
19+
String broken = input_string + "&";
20+
try {
21+
Long.parseLong(broken);
22+
pass2 = true;
23+
}
24+
catch(NumberFormatException e) {
25+
throw2 = true;
26+
}
27+
// Make it valid again:
28+
String fixed = broken.substring(0, broken.length() - 1);
29+
try {
30+
Long.parseLong(fixed);
31+
pass3 = true;
32+
}
33+
catch(NumberFormatException e) {
34+
throw3 = true;
35+
}
36+
37+
// Check we followed the expected path:
38+
assert(pass1 && throw2 && pass3 && !throw1 && !pass2 && !throw3);
39+
// Check we can get to the end at all:
40+
assert(false);
41+
}
42+
}

0 commit comments

Comments
 (0)