Skip to content

Commit f42eeb2

Browse files
author
Matthias Güdemann
committed
Add unit test for generic superclass with unsupported signature
1 parent e760d6b commit f42eeb2

File tree

6 files changed

+84
-0
lines changed

6 files changed

+84
-0
lines changed

unit/java_bytecode/java_bytecode_parse_generics/DerivedGenerics.java

+20
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,23 @@ public T someMethod() {
169169
return f;
170170
}
171171
}
172+
173+
class GenericBounds extends Generic<Class<?>> {
174+
// references exist only to load these class files, too
175+
GenericBoundsUpper gen_upper;
176+
GenericBoundsLower gen_lower;
177+
GenericInterface gen_interface;
178+
179+
}
180+
181+
class GenericBoundsUpper extends Generic<Class<? extends Class>> {
182+
}
183+
184+
class GenericBoundsLower extends Generic<Class<? super Class>> {
185+
}
186+
187+
class GenericInterface implements InterfaceGeneric<Class<? extends Class>> {
188+
public Class<? extends Class> someMethod(){
189+
return null;
190+
}
191+
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*******************************************************************\
2+
3+
Module: Unit tests for parsing classes with generic superclasses or interfaces
4+
with unsupported signatures, falling back to using the raw type
5+
descriptors
6+
7+
Author: DiffBlue Limited. All rights reserved.
8+
9+
\*******************************************************************/
10+
11+
#include <testing-utils/catch.hpp>
12+
#include <testing-utils/load_java_class.h>
13+
#include <testing-utils/require_type.h>
14+
15+
SCENARIO(
16+
"parse generic superclass signature",
17+
"[core][java_byte code[java_bytecode_parse_generics]]")
18+
{
19+
const symbol_tablet &new_symbol_table = load_java_class(
20+
"GenericBounds", "./java_bytecode/java_bytecode_parse_generics");
21+
22+
const std::string base_generic = "java::Generic";
23+
const irep_idt base_generic_interface = "java::InterfaceGeneric";
24+
25+
const std::string load_class("java::GenericBounds");
26+
THEN(
27+
"these fields have a non-generic base class / interface as their real "
28+
"generic signature is unsupported at the moment")
29+
{
30+
// once bounds in generic signatures are supported, this test must be
31+
// changed to check for the correct generic types, TODO(mgudemann),
32+
// cf. TG-1286, TG-675
33+
{
34+
const symbolt &upper_symbol =
35+
new_symbol_table.lookup_ref("java::GenericBoundsUpper");
36+
const java_class_typet &upper_type =
37+
to_java_class_type(upper_symbol.type);
38+
REQUIRE(upper_type.bases().size() == 1);
39+
const symbol_typet base_type = require_type::require_symbol(
40+
upper_type.bases().at(0).type(), base_generic);
41+
REQUIRE_FALSE(is_java_generic_symbol_type(base_type));
42+
}
43+
{
44+
const symbolt &lower_symbol =
45+
new_symbol_table.lookup_ref("java::GenericBoundsLower");
46+
const java_class_typet &lower_type =
47+
to_java_class_type(lower_symbol.type);
48+
REQUIRE(lower_type.bases().size() == 1);
49+
const symbol_typet base_type = require_type::require_symbol(
50+
lower_type.bases().at(0).type(), base_generic);
51+
REQUIRE_FALSE(is_java_generic_symbol_type(base_type));
52+
}
53+
{
54+
const symbolt &interface_symbol =
55+
new_symbol_table.lookup_ref("java::GenericInterface");
56+
const java_class_typet &interface_type =
57+
to_java_class_type(interface_symbol.type);
58+
REQUIRE(interface_type.bases().size() == 2);
59+
const symbol_typet base_type = require_type::require_symbol(
60+
interface_type.bases().at(1).type(), base_generic_interface);
61+
REQUIRE_FALSE(is_java_generic_symbol_type(base_type));
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)