Skip to content

Commit 3c5ca51

Browse files
Nathan PhillipsNathan Phillips
Nathan Phillips
authored and
Nathan Phillips
committed
Unit test to demonstrate issue in make_object_get_class_code
1 parent 133f0f2 commit 3c5ca51

File tree

6 files changed

+55
-2
lines changed

6 files changed

+55
-2
lines changed
Binary file not shown.
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package java.lang;
2+
3+
class Class {
4+
static Class forName(String className) {
5+
return null;
6+
}
7+
}
8+
9+
public class TestObjectGetClass {
10+
void main() {
11+
this.getClass();
12+
}
13+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/// file
2+
/// Test for types in return value of make_object_get_class_code
3+
4+
/// Author: Diffblue Ltd.
5+
6+
#include <testing-utils/catch.hpp>
7+
8+
TEST_CASE("Check types of return value of make_object_get_class_code")
9+
{
10+
GIVEN("")
11+
{
12+
symbol_tablet symbol_table = load_java_class("TestObjectGetClass", ".", true);
13+
for(const symbolt &symbol : symbol_table)
14+
{
15+
symbol.name;
16+
}
17+
18+
code_typet::parametert param;
19+
param.set_identifier("this");
20+
code_typet type;
21+
type.parameters().push_back(param);
22+
source_locationt loc;
23+
loc.
24+
symbol_tablet symbol_table;
25+
WHEN("")
26+
{
27+
THEN("The type of the returned expression is that of refined strings")
28+
{
29+
code_for_function("java::java.lang.Object.getClass:()Ljava/lang/Class;", type, loc, symbol_table);
30+
REQUIRE(string_expr.id() == ID_struct);
31+
}
32+
}
33+
}
34+
}

unit/testing-utils/load_java_class.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
/// \return The symbol table that is generated by parsing this file.
2626
symbol_tablet load_java_class(
2727
const std::string &java_class_name,
28-
const std::string &class_path)
28+
const std::string &class_path,
29+
bool use_string_refinement)
2930
{
3031
return load_java_class(
3132
java_class_name, class_path, new_java_bytecode_language());
@@ -34,6 +35,7 @@ symbol_tablet load_java_class(
3435
symbol_tablet load_java_class(
3536
const std::string &java_class_name,
3637
const std::string &class_path,
38+
bool use_string_refinement,
3739
std::unique_ptr<languaget> java_lang)
3840
{
3941
// We don't expect the .class suffix to allow us to check the name of the
@@ -43,6 +45,8 @@ symbol_tablet load_java_class(
4345
// Configure the path loading
4446
cmdlinet command_line;
4547
command_line.set("java-cp-include-files", class_path);
48+
if(use_string_refinement)
49+
command_line.set("refine-strings", true);
4650
config.java.classpath.clear();
4751
config.java.classpath.push_back(class_path);
4852

unit/testing-utils/load_java_class.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919

2020
symbol_tablet load_java_class(
2121
const std::string &java_class_name,
22-
const std::string &class_path);
22+
const std::string &class_path,
23+
bool use_string_refinement = false);
2324

2425
symbol_tablet load_java_class(
2526
const std::string &java_class_name,
2627
const std::string &class_path,
28+
bool use_string_refinement,
2729
std::unique_ptr<languaget> java_lang);
2830

2931
#endif // CPROVER_TESTING_UTILS_LOAD_JAVA_CLASS_H

0 commit comments

Comments
 (0)