Skip to content

Commit a069e94

Browse files
Nathan PhillipsNathanJPhillips
Nathan Phillips
authored andcommitted
Unit test to demonstrate issue in make_object_get_class_code
1 parent 133f0f2 commit a069e94

File tree

6 files changed

+57
-2
lines changed

6 files changed

+57
-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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
#include <util/symbol_table.h>
8+
#include <testing-utils/load_java_class.h>
9+
10+
TEST_CASE("Check types of return value of make_object_get_class_code")
11+
{
12+
GIVEN("")
13+
{
14+
symbol_tablet symbol_table = load_java_class("TestObjectGetClass", ".", true);
15+
for(auto &named_symbol : symbol_table.symbols)
16+
{
17+
named_symbol.first;
18+
}
19+
20+
code_typet::parametert param;
21+
param.set_identifier("this");
22+
code_typet type;
23+
type.parameters().push_back(param);
24+
source_locationt loc;
25+
loc.
26+
symbol_tablet symbol_table;
27+
WHEN("")
28+
{
29+
THEN("The type of the returned expression is that of refined strings")
30+
{
31+
code_for_function("java::java.lang.Object.getClass:()Ljava/lang/Class;", type, loc, symbol_table);
32+
REQUIRE(string_expr.id() == ID_struct);
33+
}
34+
}
35+
}
36+
}

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)