Skip to content

Commit 65e3d31

Browse files
committed
Test that parsed static fields have correct declaring_class
1 parent 115417a commit 65e3d31

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

jbmc/unit/java_bytecode/inherited_static_fields/inherited_static_fields.cpp

+71
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Author: Diffblue Ltd.
1212
#include <algorithm>
1313

1414
#include <java_bytecode/java_types.h>
15+
#include <java_bytecode/java_utils.h>
1516
#include <util/expr_iterator.h>
1617

1718
/// Check the full tree of expr for any symbol_exprts that have an identifier id
@@ -37,6 +38,12 @@ SCENARIO(
3738
{
3839
REQUIRE(symbol_table.has_symbol("java::Parent1.x"));
3940
}
41+
THEN("Static field 'Parent1.x' should be declared by class Parent1")
42+
{
43+
REQUIRE(
44+
id2string(*declaring_class(
45+
symbol_table.lookup_ref("java::Parent1.x"))) == "java::Parent1");
46+
}
4047
THEN("No static field 'Test1.x' should be created")
4148
{
4249
REQUIRE(!symbol_table.has_symbol("java::Test1.x"));
@@ -62,6 +69,14 @@ SCENARIO(
6269
{
6370
REQUIRE(symbol_table.has_symbol("java::StaticInterface2.x"));
6471
}
72+
THEN(
73+
"Static field 'java::StaticInterface2.x' should be declared by "
74+
"StaticInterface2")
75+
{
76+
REQUIRE(
77+
id2string(*declaring_class(symbol_table.lookup_ref(
78+
"java::StaticInterface2.x"))) == "java::StaticInterface2");
79+
}
6580
THEN("No static field 'Test2.x' should be created")
6681
{
6782
REQUIRE(!symbol_table.has_symbol("java::Test2.x"));
@@ -93,6 +108,14 @@ SCENARIO(
93108
{
94109
REQUIRE(symbol_table.has_symbol("java::OpaqueParent3.x"));
95110
}
111+
THEN(
112+
"Static field 'OpaqueParent3.x' should be declared by class "
113+
"OpaqueParent3")
114+
{
115+
REQUIRE(
116+
id2string(*declaring_class(symbol_table.lookup_ref(
117+
"java::OpaqueParent3.x"))) == "java::OpaqueParent3");
118+
}
96119
THEN("No static field 'Test3.x' should be created")
97120
{
98121
REQUIRE(!symbol_table.has_symbol("java::Test3.x"));
@@ -124,6 +147,14 @@ SCENARIO(
124147
{
125148
REQUIRE(symbol_table.has_symbol("java::OpaqueInterface4.x"));
126149
}
150+
THEN(
151+
"Static field 'OpaqueInterface4.x' should be declared by class "
152+
"OpaqueInterface4")
153+
{
154+
REQUIRE(
155+
id2string(*declaring_class(symbol_table.lookup_ref(
156+
"java::OpaqueInterface4.x"))) == "java::OpaqueInterface4");
157+
}
127158
THEN("No static field 'Test4.x' should be created")
128159
{
129160
REQUIRE(!symbol_table.has_symbol("java::Test4.x"));
@@ -191,6 +222,12 @@ SCENARIO(
191222
{
192223
REQUIRE(symbol_table.has_symbol("java::Parent6.x"));
193224
}
225+
THEN("Static field 'Parent6.x' should be declared by class Parent6")
226+
{
227+
REQUIRE(
228+
id2string(*declaring_class(
229+
symbol_table.lookup_ref("java::Parent6.x"))) == "java::Parent6");
230+
}
194231
THEN("No static field 'Test6.x' should be created")
195232
{
196233
REQUIRE(!symbol_table.has_symbol("java::Test6.x"));
@@ -217,10 +254,26 @@ SCENARIO(
217254
{
218255
REQUIRE(symbol_table.has_symbol("java::otherpackage.Parent7.x"));
219256
}
257+
THEN(
258+
"Static field 'otherpackage.Parent7.x' should be declared by class "
259+
"otherpackage.Parent7")
260+
{
261+
REQUIRE(
262+
id2string(*declaring_class(symbol_table.lookup_ref(
263+
"java::otherpackage.Parent7.x"))) == "java::otherpackage.Parent7");
264+
}
220265
THEN("A static field StaticInterface7.x should exist")
221266
{
222267
REQUIRE(symbol_table.has_symbol("java::StaticInterface7.x"));
223268
}
269+
THEN(
270+
"Static field 'StaticInterface7.x' should be declared by class "
271+
"StaticInterface7")
272+
{
273+
REQUIRE(
274+
id2string(*declaring_class(symbol_table.lookup_ref(
275+
"java::StaticInterface7.x"))) == "java::StaticInterface7");
276+
}
224277
THEN("No static field 'Test7.x' should be created")
225278
{
226279
REQUIRE(!symbol_table.has_symbol("java::Test7.x"));
@@ -253,6 +306,12 @@ SCENARIO(
253306
{
254307
REQUIRE(symbol_table.has_symbol("java::Parent8.x"));
255308
}
309+
THEN("Static field 'Parent8.x' should be declared by class Parent8")
310+
{
311+
REQUIRE(
312+
id2string(*declaring_class(
313+
symbol_table.lookup_ref("java::Parent8.x"))) == "java::Parent8");
314+
}
256315
THEN("No static field 'Test8.x' should be created")
257316
{
258317
REQUIRE(!symbol_table.has_symbol("java::Test8.x"));
@@ -279,10 +338,22 @@ SCENARIO(
279338
{
280339
REQUIRE(symbol_table.has_symbol("java::Parent9.x"));
281340
}
341+
THEN("Static field 'Parent9.x' should be declared by class Parent9")
342+
{
343+
REQUIRE(
344+
id2string(*declaring_class(
345+
symbol_table.lookup_ref("java::Parent9.x"))) == "java::Parent9");
346+
}
282347
THEN("A static field StaticInterface9.x should exist")
283348
{
284349
REQUIRE(symbol_table.has_symbol("java::StaticInterface9.x"));
285350
}
351+
THEN("Static field 'Parent8.x' should be declared by StaticInterface9")
352+
{
353+
REQUIRE(
354+
id2string(*declaring_class(symbol_table.lookup_ref(
355+
"java::StaticInterface9.x"))) == "java::StaticInterface9");
356+
}
286357
THEN("No static field 'Test9.x' should be created")
287358
{
288359
REQUIRE(!symbol_table.has_symbol("java::Test9.x"));

0 commit comments

Comments
 (0)