Skip to content

Commit 115417a

Browse files
committed
Add unit tests covering method parsing setting declaring_class
1 parent ba971c0 commit 115417a

File tree

3 files changed

+91
-20
lines changed

3 files changed

+91
-20
lines changed
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class ClassWithStaticMethod {
2+
public static int staticFunc() {
3+
return 0;
4+
}
5+
}

jbmc/unit/java_bytecode/java_bytecode_convert_method/convert_method.cpp

Lines changed: 86 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,29 @@ SCENARIO(
4242
{
4343
REQUIRE(function_type.get_bool(ID_is_bridge_method));
4444
}
45+
THEN("The method should be marked as declared by its class")
46+
{
47+
REQUIRE(
48+
id2string(*declaring_class(function_symbol)) ==
49+
"java::ClassWithBridgeMethod");
50+
}
4551
}
4652
WHEN("When parsing a non-bridge method")
4753
{
48-
THEN("THe method should not be marked as a bridge method")
49-
{
50-
const symbolt function_symbol =
51-
symbol_table.lookup_ref(method_name + ":(LClassWithBridgeMethod;)I");
54+
const symbolt function_symbol =
55+
symbol_table.lookup_ref(method_name + ":(LClassWithBridgeMethod;)I");
5256

53-
const java_method_typet &function_type =
54-
require_type::require_java_method(function_symbol.type);
55-
THEN("The method should be marked as a bridge method")
56-
{
57-
REQUIRE_FALSE(function_type.get_bool(ID_is_bridge_method));
58-
}
57+
const java_method_typet &function_type =
58+
require_type::require_java_method(function_symbol.type);
59+
THEN("The method should not be marked as a bridge method.")
60+
{
61+
REQUIRE_FALSE(function_type.get_bool(ID_is_bridge_method));
62+
}
63+
THEN("The method should be marked as declared by its class")
64+
{
65+
REQUIRE(
66+
id2string(*declaring_class(function_symbol)) ==
67+
"java::ClassWithBridgeMethod");
5968
}
6069
}
6170
}
@@ -81,20 +90,29 @@ SCENARIO(
8190
{
8291
REQUIRE(to_java_method_type(function_type).get_native());
8392
}
93+
THEN("The method should be marked as declared by its class")
94+
{
95+
REQUIRE(
96+
id2string(*declaring_class(function_symbol)) ==
97+
"java::ClassWithNativeMethod");
98+
}
8499
}
85100
WHEN("When parsing a non-native method")
86101
{
87-
THEN("THe method should not be marked as a native method")
88-
{
89-
const symbolt function_symbol =
90-
symbol_table.lookup_ref(method_name + ":(I)Z");
102+
const symbolt function_symbol =
103+
symbol_table.lookup_ref(method_name + ":(I)Z");
91104

92-
const java_method_typet &function_type =
93-
require_type::require_java_method(function_symbol.type);
94-
THEN("The method should be marked as a native method")
95-
{
96-
REQUIRE_FALSE(to_java_method_type(function_type).get_native());
97-
}
105+
const java_method_typet &function_type =
106+
require_type::require_java_method(function_symbol.type);
107+
THEN("The method should not be marked as a native method.")
108+
{
109+
REQUIRE_FALSE(to_java_method_type(function_type).get_native());
110+
}
111+
THEN("The method should be marked as declared by its class")
112+
{
113+
REQUIRE(
114+
id2string(*declaring_class(function_symbol)) ==
115+
"java::ClassWithNativeMethod");
98116
}
99117
}
100118
}
@@ -119,6 +137,12 @@ SCENARIO(
119137
{
120138
REQUIRE(function_type.get_is_final());
121139
}
140+
THEN("The method should be marked as declared by its class")
141+
{
142+
REQUIRE(
143+
id2string(*declaring_class(function_symbol)) ==
144+
"java::ClassWithFinalMethod");
145+
}
122146
}
123147
WHEN("When parsing a non-final method")
124148
{
@@ -130,6 +154,12 @@ SCENARIO(
130154
{
131155
REQUIRE(!function_type.get_is_final());
132156
}
157+
THEN("The method should be marked as declared by its class")
158+
{
159+
REQUIRE(
160+
id2string(*declaring_class(function_symbol)) ==
161+
"java::ClassWithFinalMethod");
162+
}
133163
}
134164
WHEN("When parsing an opaque method")
135165
{
@@ -169,6 +199,12 @@ SCENARIO(
169199
{
170200
REQUIRE(method_type.get_is_varargs());
171201
}
202+
THEN("The method should be marked as declared by its class")
203+
{
204+
REQUIRE(
205+
id2string(*declaring_class(method_symbol)) ==
206+
"java::ClassWithVarArgsMethod");
207+
}
172208
}
173209
WHEN("When parsing a method with constant number of arguments")
174210
{
@@ -180,6 +216,36 @@ SCENARIO(
180216
{
181217
REQUIRE_FALSE(method_type.get_is_varargs());
182218
}
219+
THEN("The method should be marked as declared by its class")
220+
{
221+
REQUIRE(
222+
id2string(*declaring_class(method_symbol)) ==
223+
"java::ClassWithVarArgsMethod");
224+
}
225+
}
226+
}
227+
}
228+
229+
SCENARIO(
230+
"java_bytecode_convert_static_method",
231+
"[core][java_bytecode][java_bytecode_convert_method]")
232+
{
233+
GIVEN("A class with a static method.")
234+
{
235+
const symbol_tablet symbol_table = load_java_class(
236+
"ClassWithStaticMethod", "./java_bytecode/java_bytecode_convert_method");
237+
238+
WHEN("Parsing a static method.")
239+
{
240+
const symbolt method_symbol =
241+
symbol_table.lookup_ref("java::ClassWithStaticMethod.staticFunc:()I");
242+
243+
THEN("The method should be marked as declared by its class")
244+
{
245+
REQUIRE(
246+
id2string(*declaring_class(method_symbol)) ==
247+
"java::ClassWithStaticMethod");
248+
}
183249
}
184250
}
185251
}

0 commit comments

Comments
 (0)