Skip to content

Commit a7aa427

Browse files
Unit tests method get_super_class
1 parent 85aef75 commit a7aa427

File tree

6 files changed

+92
-0
lines changed

6 files changed

+92
-0
lines changed

jbmc/unit/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ SRC += java_bytecode/goto-programs/class_hierarchy_output.cpp \
1212
java_bytecode/java_bytecode_convert_class/convert_java_annotations.cpp \
1313
java_bytecode/java_bytecode_convert_method/convert_invoke_dynamic.cpp \
1414
java_bytecode/java_bytecode_parse_generics/parse_generic_class.cpp \
15+
java_bytecode/java_bytecode_parser/parse_java_class.cpp \
1516
java_bytecode/java_bytecode_parser/parse_java_attributes.cpp \
1617
java_bytecode/java_object_factory/gen_nondet_string_init.cpp \
1718
java_bytecode/java_bytecode_parse_lambdas/java_bytecode_parse_lambda_method_table.cpp \
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public class ChildClass extends ParentClass {
2+
}
3+
4+
class ParentClass extends GrandparentClass {
5+
}
6+
7+
class GrandparentClass {
8+
}
Binary file not shown.
Binary file not shown.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*******************************************************************\
2+
3+
Module: Unit tests for converting annotations
4+
5+
Author: Diffblue Ltd.
6+
7+
\*******************************************************************/
8+
9+
#include <java-testing-utils/load_java_class.h>
10+
#include <java_bytecode/java_bytecode_convert_class.h>
11+
#include <java_bytecode/java_bytecode_parse_tree.h>
12+
#include <java_bytecode/java_types.h>
13+
#include <testing-utils/catch.hpp>
14+
15+
SCENARIO(
16+
"java_bytecode_parse_class",
17+
"[core][java_bytecode][java_bytecode_parser]")
18+
{
19+
GIVEN("Some class with a class hierarchy")
20+
{
21+
const symbol_tablet &new_symbol_table =
22+
load_java_class("ChildClass", "./java_bytecode/java_bytecode_parser");
23+
WHEN("Parsing the class file structure")
24+
{
25+
THEN("We should be able to get the first super class")
26+
{
27+
const symbolt &class_symbol =
28+
new_symbol_table.lookup_ref("java::ChildClass");
29+
const java_class_typet &java_class =
30+
to_java_class_type(class_symbol.type);
31+
REQUIRE(java_class.get_super_class() == "ParentClass");
32+
}
33+
THEN("We should be able to get the second super class")
34+
{
35+
const symbolt &class_symbol =
36+
new_symbol_table.lookup_ref("java::ChildClass");
37+
const java_class_typet &java_class =
38+
to_java_class_type(class_symbol.type);
39+
const symbolt &class_symbol1 = new_symbol_table.lookup_ref(
40+
"java::" + id2string(java_class.get_super_class()));
41+
const java_class_typet &java_class1 =
42+
to_java_class_type(class_symbol1.type);
43+
REQUIRE(java_class1.get_super_class() == "GrandparentClass");
44+
}
45+
THEN("We should be able to get the third super class")
46+
{
47+
const symbolt &class_symbol =
48+
new_symbol_table.lookup_ref("java::ChildClass");
49+
const java_class_typet &java_class =
50+
to_java_class_type(class_symbol.type);
51+
const symbolt &class_symbol1 = new_symbol_table.lookup_ref(
52+
"java::" + id2string(java_class.get_super_class()));
53+
const java_class_typet &java_class1 =
54+
to_java_class_type(class_symbol1.type);
55+
const symbolt &class_symbol2 = new_symbol_table.lookup_ref(
56+
"java::" + id2string(java_class1.get_super_class()));
57+
const java_class_typet &java_class2 =
58+
to_java_class_type(class_symbol2.type);
59+
REQUIRE(java_class2.get_super_class() == "java.lang.Object");
60+
}
61+
THEN("We should be able to get the fourth super class")
62+
{
63+
const symbolt &class_symbol =
64+
new_symbol_table.lookup_ref("java::ChildClass");
65+
const java_class_typet &java_class =
66+
to_java_class_type(class_symbol.type);
67+
const symbolt &class_symbol1 = new_symbol_table.lookup_ref(
68+
"java::" + id2string(java_class.get_super_class()));
69+
const java_class_typet &java_class1 =
70+
to_java_class_type(class_symbol1.type);
71+
const symbolt &class_symbol2 = new_symbol_table.lookup_ref(
72+
"java::" + id2string(java_class1.get_super_class()));
73+
const java_class_typet &java_class2 =
74+
to_java_class_type(class_symbol2.type);
75+
const symbolt &class_symbol3 = new_symbol_table.lookup_ref(
76+
"java::" + id2string(java_class2.get_super_class()));
77+
const java_class_typet &java_class3 =
78+
to_java_class_type(class_symbol3.type);
79+
REQUIRE(java_class3.get_super_class().empty());
80+
}
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)