Skip to content

Commit de5c040

Browse files
Thomas Kileysvorenova
Thomas Kiley
authored and
svorenova
committed
Adding tests for generic functions
1 parent 85c1574 commit de5c040

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
interface BasicInterfaceCopy
2+
{
3+
int getX();
4+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
public class GenericFunctions
2+
{
3+
public static <T> void processSimpleGeneric(SimpleGeneric<T> x) {
4+
assert(x.t==null);
5+
}
6+
7+
// Test a wildcard generic bound by an interface
8+
public static <T extends BasicInterface> void processUpperBoundInterfaceGeneric(SimpleGeneric<T> x) {
9+
assert(x.t.getX() == 4);
10+
}
11+
12+
// Test a wild card generic bound by a class
13+
public static <T extends Foo> void processUpperBoundClassGeneric(SimpleGeneric<T> x) {
14+
assert(x.t.getX() == 4);
15+
}
16+
17+
// Test a wild card generic bound by a class and an interface
18+
public static <T extends Foo & BasicInterface> void processDoubleUpperBoundClassGeneric(SimpleGeneric<T> x) {
19+
assert(x.t.getX() == 4);
20+
}
21+
22+
// Test a wild card generic bound by two interfaces
23+
public static <T extends BasicInterface & BasicInterfaceCopy> void processDoubleUpperBoundInterfaceGeneric(SimpleGeneric<T> x) {
24+
assert(x.t.getX() == 4);
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
18+
#include <iostream>
19+
#include <src/java_bytecode/load_java_class.h>
20+
21+
SCENARIO(
22+
"java_bytecode_parse_generic_function",
23+
"[core][java_bytecode][java_bytecode_parse_generics]")
24+
{
25+
const symbol_tablet &new_symbol_table=
26+
load_java_class(
27+
"GenericFunctions",
28+
"./java_bytecode/java_bytecode_parse_generics");
29+
30+
std::string class_prefix="java::GenericFunctions";
31+
THEN("There should be a symbol for processSimpleGeneric")
32+
{
33+
const std::string func_name=".processSimpleGeneric";
34+
const std::string func_descriptor=":(LSimpleGeneric;)V";
35+
const std::string process_func_name=class_prefix+func_name+func_descriptor;
36+
37+
REQUIRE(new_symbol_table.has_symbol(process_func_name));
38+
}
39+
40+
THEN("There should be a symbol for processUpperBoundInterfaceGeneric")
41+
{
42+
const std::string func_name=".processUpperBoundInterfaceGeneric";
43+
const std::string func_descriptor=":(LSimpleGeneric;)V";
44+
const std::string process_func_name=class_prefix+func_name+func_descriptor;
45+
46+
REQUIRE(new_symbol_table.has_symbol(process_func_name));
47+
}
48+
49+
THEN("There should be a symbol for processUpperBoundClassGeneric")
50+
{
51+
const std::string func_name=".processUpperBoundClassGeneric";
52+
const std::string func_descriptor=":(LSimpleGeneric;)V";
53+
const std::string process_func_name=class_prefix+func_name+func_descriptor;
54+
55+
REQUIRE(new_symbol_table.has_symbol(process_func_name));
56+
}
57+
58+
THEN("There should be a symbol for processDoubleUpperBoundClassGeneric")
59+
{
60+
const std::string func_name=".processDoubleUpperBoundClassGeneric";
61+
const std::string func_descriptor=":(LSimpleGeneric;)V";
62+
const std::string process_func_name=class_prefix+func_name+func_descriptor;
63+
64+
REQUIRE(new_symbol_table.has_symbol(process_func_name));
65+
}
66+
67+
THEN("There should be a symbol for processDoubleUpperBoundInterfaceGeneric")
68+
{
69+
const std::string func_name=".processDoubleUpperBoundInterfaceGeneric";
70+
const std::string func_descriptor=":(LSimpleGeneric;)V";
71+
const std::string process_func_name=class_prefix+func_name+func_descriptor;
72+
73+
REQUIRE(new_symbol_table.has_symbol(process_func_name));
74+
}
75+
}

0 commit comments

Comments
 (0)