Skip to content

Commit e8c75ac

Browse files
author
svorenova
committed
Adding unit test for generic array
1 parent de5c040 commit e8c75ac

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed
Binary file not shown.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
interface BasicInterface
2+
{
3+
int getX();
4+
}
5+
6+
class Foo implements BasicInterface
7+
{
8+
public int x;
9+
10+
public int getX() {
11+
return x;
12+
}
13+
}
14+
15+
class Bar extends Foo
16+
{}
17+
18+
class GenericArray<T>
19+
{
20+
public T [] t;
21+
public Integer [] Ia;
22+
public int [] ia;
23+
}
24+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*******************************************************************\
2+
3+
Module: Unit tests for parsing generic classes
4+
5+
Author: DiffBlue Limited. All rights reserved.
6+
7+
\*******************************************************************/
8+
9+
#include <catch.hpp>
10+
11+
#include <util/config.h>
12+
#include <util/cmdline.h>
13+
#include <util/language.h>
14+
#include <util/prefix.h>
15+
16+
#include <java_bytecode/java_bytecode_language.h>
17+
#include <src/java_bytecode/load_java_class.h>
18+
19+
#include <iostream>
20+
#include <util/namespace.h>
21+
22+
SCENARIO(
23+
"java_bytecode_parse_generic_array_class",
24+
"[core][java_bytecode][java_bytecode_parse_generics]")
25+
{
26+
const symbol_tablet &new_symbol_table=
27+
load_java_class("GenericArray", ""
28+
"./java_bytecode/java_bytecode_parse_generics");
29+
30+
std::string class_prefix="java::GenericArray";
31+
32+
REQUIRE(new_symbol_table.has_symbol(class_prefix));
33+
34+
const struct_typet &type=to_struct_type(
35+
new_symbol_table.lookup(class_prefix)
36+
.type);
37+
38+
THEN("There should be a component with name t")
39+
{
40+
REQUIRE(type.has_component("t"));
41+
}
42+
43+
const pointer_typet &t_component=to_pointer_type(
44+
type.get_component("t")
45+
.type());
46+
const symbol_typet &subtype=to_symbol_type(t_component.subtype());
47+
48+
THEN("The t component is a valid java array")
49+
{
50+
const struct_typet &subtype_type=to_struct_type(
51+
new_symbol_table.lookup(subtype.get_identifier())
52+
.type);
53+
REQUIRE(is_valid_java_array(subtype_type));
54+
}
55+
56+
THEN("The elements of the t component have the parametric type T")
57+
{
58+
const typet &element=static_cast<const typet &>(subtype.find(
59+
ID_C_element_type));
60+
REQUIRE(is_java_generic_parameter(element));
61+
62+
REQUIRE(
63+
to_java_generic_parameter(element).type_variable().get_identifier()==
64+
"java::GenericArray::T");
65+
}
66+
}

0 commit comments

Comments
 (0)