Skip to content

Commit 123fbf0

Browse files
Unit test for generic_type_index
1 parent 3aeefeb commit 123fbf0

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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_types.h>
11+
12+
SCENARIO("generic_type_index", "[core][java_types]")
13+
{
14+
GIVEN("Generic type LGenericClass<TX;TY;>; and parameters X, Y, Z")
15+
{
16+
const auto symbol_type = symbol_typet("MyType");
17+
const auto generic_symbol_type = java_generic_symbol_typet(
18+
symbol_type, "LGenericClass<TX;TY;>;", "PrefixClassName");
19+
java_generic_parametert paramX("PrefixClassName::X", symbol_typet());
20+
java_generic_parametert paramY("PrefixClassName::Y", symbol_typet());
21+
java_generic_parametert paramZ("PrefixClassName::Z", symbol_typet());
22+
23+
WHEN("Looking for parameter indexes")
24+
{
25+
const auto indexX = generic_symbol_type.generic_type_index(paramX);
26+
const auto indexY = generic_symbol_type.generic_type_index(paramY);
27+
const auto indexZ = generic_symbol_type.generic_type_index(paramZ);
28+
29+
THEN("X has index 0, Y index 1 and Z is not found")
30+
{
31+
REQUIRE(indexX.has_value());
32+
REQUIRE(indexX.value() == 0);
33+
REQUIRE(indexY.has_value());
34+
REQUIRE(indexY.value() == 1);
35+
REQUIRE_FALSE(indexZ.has_value());
36+
}
37+
}
38+
}
39+
40+
GIVEN("Generic type LGenericClass<Tkey;Tvalue;>; and"
41+
" parameters key, value, x")
42+
{
43+
const auto symbol_type = symbol_typet("MyType");
44+
const auto generic_symbol_type = java_generic_symbol_typet(
45+
symbol_type, "LGenericClass<Tkey;Tvalue;>;", "PrefixClassName");
46+
java_generic_parametert param0("PrefixClassName::key", symbol_typet());
47+
java_generic_parametert param1("PrefixClassName::value", symbol_typet());
48+
java_generic_parametert param2("PrefixClassName::x", 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("key has index 0, value index 1 and x 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+
67+
GIVEN("Generic type Ljava/util/HashMap<TK;TV;>; and parameters K, V, T")
68+
{
69+
const auto symbol_type = symbol_typet("MyType");
70+
const auto generic_symbol_type = java_generic_symbol_typet(
71+
symbol_type, "Ljava/util/HashMap<TK;TV;>;", "java.util.HashMap");
72+
java_generic_parametert param0("java.util.HashMap::K", symbol_typet());
73+
java_generic_parametert param1("java.util.HashMap::V", symbol_typet());
74+
java_generic_parametert param2("java.util.HashMap::T", symbol_typet());
75+
76+
WHEN("Looking for parameter indexes")
77+
{
78+
const auto index_param0 = generic_symbol_type.generic_type_index(param0);
79+
const auto index_param1 = generic_symbol_type.generic_type_index(param1);
80+
const auto index_param2 = generic_symbol_type.generic_type_index(param2);
81+
82+
THEN("K has index 0, V index 1 and T is not found")
83+
{
84+
REQUIRE(index_param0.has_value());
85+
REQUIRE(index_param0.value() == 0);
86+
REQUIRE(index_param1.has_value());
87+
REQUIRE(index_param1.value() == 1);
88+
REQUIRE_FALSE(index_param2.has_value());
89+
}
90+
}
91+
}
92+
}

0 commit comments

Comments
 (0)