9
9
10
10
#include < testing-utils/catch.hpp>
11
11
#include < testing-utils/load_java_class.h>
12
+ #include < testing-utils/require_type.h>
12
13
13
14
#include < util/symbol_table.h>
14
15
15
16
#include < java_bytecode/generate_java_generic_type.h>
16
17
#include < testing-utils/require_type.h>
18
+ #include < testing-utils/generic_utils.h>
17
19
#include < util/ui_message.h>
18
20
21
+ // / Helper function to specalise a generic class from a named component of a
22
+ // / named class
23
+ // / \param class_name: The name of the class that has a generic component.
24
+ // / \param component_name: The name of the generic component
25
+ // / \param new_symbol_table: The symbol table to use.
26
+ void specialise_generic_from_component (
27
+ const irep_idt &class_name,
28
+ const irep_idt &component_name,
29
+ symbol_tablet &new_symbol_table)
30
+ {
31
+ const symbolt &harness_symbol = new_symbol_table.lookup_ref (class_name);
32
+ const struct_typet::componentt &harness_component =
33
+ require_type::require_component (
34
+ to_struct_type (harness_symbol.type ), component_name);
35
+ generic_utils::specialise_generic (
36
+ to_java_generic_type (harness_component.type ()), new_symbol_table);
37
+ }
38
+
19
39
SCENARIO (
20
40
" generate_java_generic_type_from_file" ,
21
41
" [core][java_bytecode][generate_java_generic_type]" )
@@ -30,6 +50,9 @@ SCENARIO(
30
50
load_java_class (" generic_two_fields" ,
31
51
" ./java_bytecode/generate_concrete_generic_type" );
32
52
53
+ specialise_generic_from_component (
54
+ " java::generic_two_fields" , " belem" , new_symbol_table);
55
+
33
56
REQUIRE (new_symbol_table.has_symbol (expected_symbol));
34
57
THEN (" The class should contain two instantiated fields." )
35
58
{
@@ -77,6 +100,9 @@ SCENARIO(
77
100
load_java_class (" generic_two_parameters" ,
78
101
" ./java_bytecode/generate_concrete_generic_type" );
79
102
103
+ specialise_generic_from_component (
104
+ " java::generic_two_parameters" , " bomb" , new_symbol_table);
105
+
80
106
REQUIRE (new_symbol_table.has_symbol (
81
107
" java::generic_two_parameters$KeyValuePair" ));
82
108
THEN (" The class should have two subtypes in the vector of the types of "
@@ -140,6 +166,11 @@ SCENARIO(
140
166
load_java_class (" generic_two_instances" ,
141
167
" ./java_bytecode/generate_concrete_generic_type" );
142
168
169
+ specialise_generic_from_component (
170
+ " java::generic_two_instances" , " bool_element" , new_symbol_table);
171
+ specialise_generic_from_component (
172
+ " java::generic_two_instances" , " int_element" , new_symbol_table);
173
+
143
174
REQUIRE (new_symbol_table.has_symbol (first_expected_symbol));
144
175
auto first_symbol=new_symbol_table.lookup (first_expected_symbol);
145
176
REQUIRE (first_symbol->type .id ()==ID_struct);
0 commit comments