Skip to content

Commit 663b406

Browse files
fixup! Adding tests for local and anonymous classes
1 parent 7c79977 commit 663b406

25 files changed

+84
-0
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

jbmc/unit/java_bytecode/java_bytecode_parser/InnerClasses.java

+11
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,14 @@ interface InnerInterface {
102102
int i = 4;
103103
};
104104
}
105+
106+
class ContainsLocalClass {
107+
public void test() {
108+
class LocalClass {
109+
int i = 55;
110+
LocalClass(int i) {
111+
this.i = i;
112+
}
113+
}
114+
}
115+
}
Binary file not shown.
Binary file not shown.

jbmc/unit/java_bytecode/java_bytecode_parser/parse_java_attributes.cpp

+73
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ SCENARIO(
120120
}
121121
}
122122
}
123+
123124
GIVEN(
124125
"Some package-private class files in the class path with deeply nested "
125126
"inner classes")
@@ -185,4 +186,76 @@ SCENARIO(
185186
}
186187
}
187188
}
189+
190+
GIVEN(
191+
"Some package-private class files in the class path with anonymous classes")
192+
{
193+
WHEN("Parsing the InnerClasses attribute for a public anonymous class")
194+
{
195+
THEN("The class should be marked as public")
196+
{
197+
const symbolt &class_symbol =
198+
new_symbol_table.lookup_ref("java::ContainsAnonymousClass$1");
199+
const java_class_typet java_class =
200+
to_java_class_type(class_symbol.type);
201+
REQUIRE(java_class.get_is_inner_class());
202+
REQUIRE(java_class.get_access() == ID_public);
203+
}
204+
}
205+
WHEN(
206+
"Parsing the InnerClasses attribute for a package-private anonymous "
207+
"class")
208+
{
209+
THEN("The class should be marked as default")
210+
{
211+
const symbolt &class_symbol =
212+
new_symbol_table.lookup_ref("java::ContainsAnonymousClass$2");
213+
const java_class_typet java_class =
214+
to_java_class_type(class_symbol.type);
215+
REQUIRE(java_class.get_is_inner_class());
216+
REQUIRE(java_class.get_access() == ID_default);
217+
}
218+
}
219+
WHEN("Parsing the InnerClasses attribute for a protected anonymous class")
220+
{
221+
THEN("The class should be marked as protected")
222+
{
223+
const symbolt &class_symbol =
224+
new_symbol_table.lookup_ref("java::ContainsAnonymousClass$3");
225+
const java_class_typet java_class =
226+
to_java_class_type(class_symbol.type);
227+
REQUIRE(java_class.get_is_inner_class());
228+
REQUIRE(java_class.get_access() == ID_protected);
229+
}
230+
}
231+
WHEN("Parsing the InnerClasses attribute for a private anonymous class")
232+
{
233+
THEN("The class should be marked as private")
234+
{
235+
const symbolt &class_symbol =
236+
new_symbol_table.lookup_ref("java::ContainsAnonymousClass$4");
237+
const java_class_typet java_class =
238+
to_java_class_type(class_symbol.type);
239+
REQUIRE(java_class.get_is_inner_class());
240+
REQUIRE(java_class.get_access() == ID_private);
241+
}
242+
}
243+
}
244+
245+
GIVEN(
246+
"Some package-private class files in the class path with local classes ")
247+
{
248+
WHEN("Parsing the InnerClasses attribute for a package-private class ")
249+
{
250+
THEN("The class should be marked as package-private")
251+
{
252+
const symbolt &class_symbol =
253+
new_symbol_table.lookup_ref("java::ContainsLocalClass$LocalClass$");
254+
const java_class_typet java_class =
255+
to_java_class_type(class_symbol.type);
256+
REQUIRE(java_class.get_is_inner_class());
257+
REQUIRE(java_class.get_access() == ID_default);
258+
}
259+
}
260+
}
188261
}

0 commit comments

Comments
 (0)