Skip to content

Commit 4c20b21

Browse files
Updates unit tests for inner class accessibility.
The accessibility is now determined from the inner class and its containing classes
1 parent 8e0744f commit 4c20b21

7 files changed

+35
-22
lines changed
Binary file not shown.

jbmc/unit/java_bytecode/java_bytecode_parser/parse_java_attributes.cpp

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ SCENARIO(
2222
load_java_class("InnerClasses", "./java_bytecode/java_bytecode_parser");
2323
WHEN("Parsing the InnerClasses attribute for a public inner class")
2424
{
25-
THEN("The class should be marked as public")
25+
THEN("The inner class should be marked as public")
2626
{
2727
const symbolt &class_symbol =
2828
new_symbol_table.lookup_ref("java::InnerClasses$PublicInnerClass");
@@ -35,7 +35,7 @@ SCENARIO(
3535
}
3636
WHEN("Parsing the InnerClasses attribute for a package private inner class")
3737
{
38-
THEN("The class should be marked as default")
38+
THEN("The inner class should be marked as default")
3939
{
4040
const symbolt &class_symbol =
4141
new_symbol_table.lookup_ref("java::InnerClasses$DefaultInnerClass");
@@ -48,7 +48,7 @@ SCENARIO(
4848
}
4949
WHEN("Parsing the InnerClasses attribute for a protected inner class")
5050
{
51-
THEN("The class should be marked as protected")
51+
THEN("The inner class should be marked as protected")
5252
{
5353
const symbolt &class_symbol =
5454
new_symbol_table.lookup_ref("java::InnerClasses$ProtectedInnerClass");
@@ -61,7 +61,7 @@ SCENARIO(
6161
}
6262
WHEN("Parsing the InnerClasses attribute for a private inner class")
6363
{
64-
THEN("The class should be marked as private")
64+
THEN("The inner class should be marked as private")
6565
{
6666
const symbolt &class_symbol =
6767
new_symbol_table.lookup_ref("java::InnerClasses$PrivateInnerClass");
@@ -73,26 +73,33 @@ SCENARIO(
7373
}
7474
}
7575
}
76-
GIVEN("Some package-private class files in the class path with inner classes")
76+
GIVEN(
77+
"Some package-private (default) class files in the class path with inner "
78+
"classes")
7779
{
7880
const symbol_tablet &new_symbol_table = load_java_class(
7981
"InnerClassesDefault", "./java_bytecode/java_bytecode_parser");
8082
WHEN("Parsing the InnerClasses attribute for a public inner class")
8183
{
82-
THEN("The class should be marked as public")
84+
THEN(
85+
"The inner class should be marked as package-private (default) because "
86+
"its "
87+
"containing class has stricter access ")
8388
{
8489
const symbolt &class_symbol = new_symbol_table.lookup_ref(
8590
"java::InnerClassesDefault$PublicInnerClass");
8691
const java_class_typet java_class =
8792
to_java_class_type(class_symbol.type);
8893
REQUIRE_FALSE(java_class.get_is_anonymous_class());
8994
REQUIRE(java_class.get_is_inner_class());
90-
REQUIRE(java_class.get_access() == ID_public);
95+
REQUIRE(java_class.get_access() == ID_default);
9196
}
9297
}
93-
WHEN("Parsing the InnerClasses attribute for a package private inner class")
98+
WHEN(
99+
"Parsing the InnerClasses attribute for a package private (default) "
100+
"inner class")
94101
{
95-
THEN("The class should be marked as default")
102+
THEN("The inner class should be marked as package-private (default)")
96103
{
97104
const symbolt &class_symbol = new_symbol_table.lookup_ref(
98105
"java::InnerClassesDefault$DefaultInnerClass");
@@ -105,20 +112,22 @@ SCENARIO(
105112
}
106113
WHEN("Parsing the InnerClasses attribute for a protected inner class")
107114
{
108-
THEN("The class should be marked as protected")
115+
THEN(
116+
"The inner class should be marked as package-private (default) because "
117+
"its containing class has stricter access ")
109118
{
110119
const symbolt &class_symbol = new_symbol_table.lookup_ref(
111120
"java::InnerClassesDefault$ProtectedInnerClass");
112121
const java_class_typet java_class =
113122
to_java_class_type(class_symbol.type);
114123
REQUIRE_FALSE(java_class.get_is_anonymous_class());
115124
REQUIRE(java_class.get_is_inner_class());
116-
REQUIRE(java_class.get_access() == ID_protected);
125+
REQUIRE(java_class.get_access() == ID_default);
117126
}
118127
}
119128
WHEN("Parsing the InnerClasses attribute for a private inner class")
120129
{
121-
THEN("The class should be marked as private")
130+
THEN("The inner class should be marked as private")
122131
{
123132
const symbolt &class_symbol = new_symbol_table.lookup_ref(
124133
"java::InnerClassesDefault$PrivateInnerClass");
@@ -141,7 +150,9 @@ SCENARIO(
141150
"Parsing the InnerClasses attribute for a public doubly-nested inner "
142151
"class")
143152
{
144-
THEN("The class should be marked as public")
153+
THEN(
154+
"The inner class should be marked as package-private (default) because "
155+
"its containing class has stricter access ")
145156
{
146157
const symbolt &class_symbol = new_symbol_table.lookup_ref(
147158
"java::InnerClassesDeeplyNested$SinglyNestedClass$"
@@ -150,14 +161,14 @@ SCENARIO(
150161
to_java_class_type(class_symbol.type);
151162
REQUIRE_FALSE(java_class.get_is_anonymous_class());
152163
REQUIRE(java_class.get_is_inner_class());
153-
REQUIRE(java_class.get_access() == ID_public);
164+
REQUIRE(java_class.get_access() == ID_default);
154165
}
155166
}
156167
WHEN(
157-
"Parsing the InnerClasses attribute for a package private doubly-nested "
158-
"inner class")
168+
"Parsing the InnerClasses attribute for a package private (default) "
169+
"doubly-nested inner class")
159170
{
160-
THEN("The class should be marked as default")
171+
THEN("The inner class should be marked as package-private (default)")
161172
{
162173
const symbolt &class_symbol = new_symbol_table.lookup_ref(
163174
"java::InnerClassesDeeplyNested$SinglyNestedClass$"
@@ -170,10 +181,12 @@ SCENARIO(
170181
}
171182
}
172183
WHEN(
173-
"Parsing the InnerClasses attribute for a protected doubly-nested inner "
174-
"class")
184+
"Parsing the InnerClasses attribute for a package private (default) "
185+
"doubly-nested inner class ")
175186
{
176-
THEN("The class should be marked as protected")
187+
THEN(
188+
"The inner class should be marked as package-private (default) because "
189+
"its containing class has stricter access ")
177190
{
178191
const symbolt &class_symbol = new_symbol_table.lookup_ref(
179192
"java::InnerClassesDeeplyNested$SinglyNestedClass$"
@@ -182,14 +195,14 @@ SCENARIO(
182195
to_java_class_type(class_symbol.type);
183196
REQUIRE_FALSE(java_class.get_is_anonymous_class());
184197
REQUIRE(java_class.get_is_inner_class());
185-
REQUIRE(java_class.get_access() == ID_protected);
198+
REQUIRE(java_class.get_access() == ID_default);
186199
}
187200
}
188201
WHEN(
189202
"Parsing the InnerClasses attribute for a private doubly-nested inner "
190203
"class")
191204
{
192-
THEN("The class should be marked as private")
205+
THEN("The inner class should be marked as private ")
193206
{
194207
const symbolt &class_symbol = new_symbol_table.lookup_ref(
195208
"java::InnerClassesDeeplyNested$SinglyNestedClass$"

0 commit comments

Comments
 (0)