Skip to content

Commit aeea8ec

Browse files
author
Matthias Güdemann
committed
Add unit test for is_native of java_method_typet
1 parent 2ec1da8 commit aeea8ec

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public class ClassWithNativeMethod {
2+
native boolean f();
3+
boolean f(int i) {
4+
return false;
5+
}
6+
}

jbmc/unit/java_bytecode/java_bytecode_convert_method/convert_method.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************\
22
3-
Module: Unit tests for converting constructors and static initializers
3+
Module: Unit tests for classes with bridge methods and native methods
44
55
Author: Diffblue Limited.
66
@@ -56,6 +56,45 @@ SCENARIO(
5656
}
5757
}
5858
}
59+
GIVEN("A class with a native method")
60+
{
61+
const symbol_tablet symbol_table = load_java_class(
62+
"ClassWithNativeMethod", "./java_bytecode/java_bytecode_convert_method");
63+
64+
const std::string method_name = "java::ClassWithNativeMethod.f";
65+
66+
WHEN("When parsing the native method")
67+
{
68+
const symbolt function_symbol =
69+
symbol_table.lookup_ref(method_name + ":()Z");
70+
71+
const java_method_typet &function_type =
72+
require_type::require_java_method(function_symbol.type);
73+
THEN("The method symbol should be of java_method_typet")
74+
{
75+
REQUIRE(function_type.get_bool(ID_C_java_method_type));
76+
}
77+
THEN("And the method should be marked as a native method")
78+
{
79+
REQUIRE(to_java_method_type(function_type).get_native());
80+
}
81+
}
82+
WHEN("When parsing a non-native method")
83+
{
84+
THEN("THe method should not be marked as a native method")
85+
{
86+
const symbolt function_symbol =
87+
symbol_table.lookup_ref(method_name + ":(I)Z");
88+
89+
const java_method_typet &function_type =
90+
require_type::require_java_method(function_symbol.type);
91+
THEN("The method should be marked as a native method")
92+
{
93+
REQUIRE_FALSE(to_java_method_type(function_type).get_native());
94+
}
95+
}
96+
}
97+
}
5998
}
6099

61100
SCENARIO(

0 commit comments

Comments
 (0)