Skip to content

Commit 5874f53

Browse files
committed
Add unit tests on final status of fields
1 parent 03bae45 commit 5874f53

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

jbmc/unit/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ SRC += java_bytecode/ci_lazy_methods/lazy_load_lambdas.cpp \
3838
java_bytecode/java_bytecode_parser/parse_java_annotations.cpp \
3939
java_bytecode/java_bytecode_parser/parse_java_attributes.cpp \
4040
java_bytecode/java_bytecode_parser/parse_java_class.cpp \
41+
java_bytecode/java_bytecode_parser/parse_java_field.cpp \
4142
java_bytecode/java_object_factory/gen_nondet_string_init.cpp \
4243
java_bytecode/java_replace_nondet/replace_nondet.cpp \
4344
java_bytecode/java_string_library_preprocess/convert_exprt_to_string_exprt.cpp \
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
class ClassWithFields {
3+
final boolean final1 = true;
4+
final Boolean final2 = false;
5+
final Object final3 = null;
6+
7+
boolean nonFinal1 = true;
8+
Boolean nonFinal2 = false;
9+
Object nonFinal3 = null;
10+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*******************************************************************\
2+
3+
Module: Unit tests for converting fields
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_field",
17+
"[core][java_bytecode][java_bytecode_parser]")
18+
{
19+
GIVEN("Some class with final and non final fields")
20+
{
21+
const symbol_tablet &symbol_table = load_java_class(
22+
"ClassWithFields", "./java_bytecode/java_bytecode_parser");
23+
24+
WHEN("Parsing the class file structure")
25+
{
26+
THEN("The the final status of the classes fields should be correct.")
27+
{
28+
const symbolt &class_symbol =
29+
symbol_table.lookup_ref("java::ClassWithFields");
30+
const java_class_typet &java_class =
31+
to_java_class_type(class_symbol.type);
32+
REQUIRE(java_class.get_component("final1").get_is_final());
33+
REQUIRE(java_class.get_component("final2").get_is_final());
34+
REQUIRE(java_class.get_component("final3").get_is_final());
35+
REQUIRE(!java_class.get_component("nonFinal1").get_is_final());
36+
REQUIRE(!java_class.get_component("nonFinal1").get_is_final());
37+
REQUIRE(!java_class.get_component("nonFinal1").get_is_final());
38+
}
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)