99
1010#include < testing-utils/catch.hpp>
1111#include < testing-utils/load_java_class.h>
12+ #include < testing-utils/require_type.h>
1213
1314#include < util/symbol_table.h>
1415
1516#include < java_bytecode/generate_java_generic_type.h>
1617#include < testing-utils/require_type.h>
18+ #include < testing-utils/generic_utils.h>
1719#include < util/ui_message.h>
1820
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+
1939SCENARIO (
2040 " generate_java_generic_type_from_file" ,
2141 " [core][java_bytecode][generate_java_generic_type]" )
@@ -30,6 +50,9 @@ SCENARIO(
3050 load_java_class (" generic_two_fields" ,
3151 " ./java_bytecode/generate_concrete_generic_type" );
3252
53+ specialise_generic_from_component (
54+ " java::generic_two_fields" , " belem" , new_symbol_table);
55+
3356 REQUIRE (new_symbol_table.has_symbol (expected_symbol));
3457 THEN (" The class should contain two instantiated fields." )
3558 {
@@ -77,6 +100,9 @@ SCENARIO(
77100 load_java_class (" generic_two_parameters" ,
78101 " ./java_bytecode/generate_concrete_generic_type" );
79102
103+ specialise_generic_from_component (
104+ " java::generic_two_parameters" , " bomb" , new_symbol_table);
105+
80106 REQUIRE (new_symbol_table.has_symbol (
81107 " java::generic_two_parameters$KeyValuePair" ));
82108 THEN (" The class should have two subtypes in the vector of the types of "
@@ -140,6 +166,11 @@ SCENARIO(
140166 load_java_class (" generic_two_instances" ,
141167 " ./java_bytecode/generate_concrete_generic_type" );
142168
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+
143174 REQUIRE (new_symbol_table.has_symbol (first_expected_symbol));
144175 auto first_symbol=new_symbol_table.lookup (first_expected_symbol);
145176 REQUIRE (first_symbol->type .id ()==ID_struct);
0 commit comments