Skip to content

Commit 4c5144d

Browse files
Unit test for generic_type_index
1 parent 8f0f780 commit 4c5144d

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
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 java_types
4+
5+
Author: Diffblue Ltd.
6+
7+
\*******************************************************************/
8+
9+
#include <testing-utils/catch.hpp>
10+
#include <java_bytecode/java_types.h>
11+
12+
SCENARIO("generic_type_index", "[core][java_types]")
13+
{
14+
GIVEN("PrefixClassName<X, value> extends GenericClass<X,value>, "
15+
"and parameters X, value, Z")
16+
{
17+
const auto symbol_type = symbol_typet("java::GenericClass");
18+
const auto generic_symbol_type = java_generic_symbol_typet(
19+
symbol_type, "LGenericClass<TX;Tvalue;>;", "PrefixClassName");
20+
java_generic_parametert paramX("PrefixClassName::X", symbol_typet());
21+
java_generic_parametert value("PrefixClassName::value", symbol_typet());
22+
java_generic_parametert paramZ("PrefixClassName::Z", symbol_typet());
23+
24+
WHEN("Looking for parameter indexes")
25+
{
26+
const auto indexX = generic_symbol_type.generic_type_index(paramX);
27+
const auto index_value = generic_symbol_type.generic_type_index(value);
28+
const auto indexZ = generic_symbol_type.generic_type_index(paramZ);
29+
30+
THEN("X has index 0, Y index 1 and Z is not found")
31+
{
32+
REQUIRE(indexX.has_value());
33+
REQUIRE(indexX.value() == 0);
34+
REQUIRE(index_value.has_value());
35+
REQUIRE(index_value.value() == 1);
36+
REQUIRE_FALSE(indexZ.has_value());
37+
}
38+
}
39+
}
40+
41+
GIVEN("HashMap<K,V> extends Map<K,V>, and parameters K, V, T")
42+
{
43+
const auto symbol_type = symbol_typet("java::java.util.Map");
44+
const auto generic_symbol_type = java_generic_symbol_typet(
45+
symbol_type, "Ljava/util/Map<TK;TV;>;", "java.util.HashMap");
46+
java_generic_parametert param0("java.util.HashMap::K", symbol_typet());
47+
java_generic_parametert param1("java.util.HashMap::V", symbol_typet());
48+
java_generic_parametert param2("java.util.HashMap::T", symbol_typet());
49+
50+
WHEN("Looking for parameter indexes")
51+
{
52+
const auto index_param0 = generic_symbol_type.generic_type_index(param0);
53+
const auto index_param1 = generic_symbol_type.generic_type_index(param1);
54+
const auto index_param2 = generic_symbol_type.generic_type_index(param2);
55+
56+
THEN("K has index 0, V index 1 and T is not found")
57+
{
58+
REQUIRE(index_param0.has_value());
59+
REQUIRE(index_param0.value() == 0);
60+
REQUIRE(index_param1.has_value());
61+
REQUIRE(index_param1.value() == 1);
62+
REQUIRE_FALSE(index_param2.has_value());
63+
}
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)