Skip to content

Commit 51a5845

Browse files
author
svorenova
committed
Pull out common generic classes/interfaces for unit tests
1 parent fc83526 commit 51a5845

39 files changed

+65
-74
lines changed

unit/goto-programs/goto_program_generics/GenericBases.java

+6-24
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
1-
// Helper classes
2-
class Wrapper<T> {
3-
public T field;
4-
}
5-
6-
class IntWrapper {
7-
public int i;
8-
}
9-
10-
class TwoWrapper<K, V> {
11-
public K first;
12-
public V second;
13-
}
14-
15-
interface InterfaceWrapper<T> {
16-
public T method(T t);
17-
}
18-
191
// A class extending a generic class instantiated with a standard library class
202
class SuperclassInst extends Wrapper<Integer> {
213
public void foo() {
@@ -24,14 +6,14 @@ public void foo() {
246
}
257

268
// A class extending a generic class instantiated with a user-defined class
27-
class SuperclassInst2 extends Wrapper<IntWrapper> {
9+
class SuperclassInst2 extends Wrapper<IWrapper> {
2810
public void foo() {
2911
this.field.i = 5;
3012
}
3113
}
3214

3315
// A class extending an instantiated nested generic class
34-
class SuperclassInst3 extends Wrapper<Wrapper<IntWrapper>> {
16+
class SuperclassInst3 extends Wrapper<Wrapper<IWrapper>> {
3517
public void foo() {
3618
this.field.field.i = 5;
3719
}
@@ -54,7 +36,7 @@ public void foo() {
5436

5537
// A generic class extending a generic class with both instantiated and
5638
// uninstantiated parameters
57-
class SuperclassMixed<U> extends TwoWrapper<U,IntWrapper> {
39+
class SuperclassMixed<U> extends PairWrapper<U,IWrapper> {
5840
public void foo(U value) {
5941
this.first = value;
6042
this.second.i = 5;
@@ -99,7 +81,7 @@ public void foo(U value) {
9981
}
10082
public Inner inner;
10183

102-
class InnerGen<T> extends TwoWrapper<U,T> {
84+
class InnerGen<T> extends PairWrapper<U,T> {
10385
public void foo(U uvalue, T tvalue) {
10486
this.first = uvalue;
10587
this.second = tvalue;
@@ -113,9 +95,9 @@ class InnerThree extends Inner {
11395
}
11496
class SuperclassInnerUninstTest
11597
{
116-
SuperclassInnerUninst<IntWrapper> f;
98+
SuperclassInnerUninst<IWrapper> f;
11799
public void foo() {
118-
IntWrapper x = new IntWrapper();
100+
IWrapper x = new IWrapper();
119101
f.inner.foo(x);
120102
f.inner_gen.foo(x,true);
121103
f.inner_three.foo(x);
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

unit/goto-programs/goto_program_generics/GenericFields.java

+8-24
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,25 @@
1-
class SimpleWrapper<T> {
2-
public T field;
3-
public T[] array_field;
4-
5-
public int int_field;
6-
}
7-
8-
class IWrapper {
9-
public int i;
10-
}
11-
12-
class PairWrapper<K, V> {
13-
public K key;
14-
public V value;
15-
}
16-
171
public class GenericFields
182
{
193
IWrapper field;
204
class SimpleGenericField {
21-
SimpleWrapper<IWrapper> field_input;
5+
Wrapper<IWrapper> field_input;
226
public void foo() {
237
field_input.field.i = 5;
248
field_input.array_field = new IWrapper[2];
259
}
2610
}
2711

2812
class MultipleGenericFields {
29-
SimpleWrapper<IWrapper> field_input1;
30-
SimpleWrapper<IWrapper> field_input2;
13+
Wrapper<IWrapper> field_input1;
14+
Wrapper<IWrapper> field_input2;
3115
public void foo() {
3216
field_input1.field.i = 10;
3317
field_input2.field.i = 20;
3418
}
3519
}
3620

3721
class NestedGenericFields {
38-
SimpleWrapper<SimpleWrapper<IWrapper>> field_input1;
22+
Wrapper<Wrapper<IWrapper>> field_input1;
3923
public void foo() {
4024
field_input1.field.field.i = 30;
4125
}
@@ -44,19 +28,19 @@ public void foo() {
4428
class PairGenericField {
4529
PairWrapper<IWrapper, IWrapper> field_input;
4630
public void foo() {
47-
field_input.key.i = 40;
48-
field_input.value.i = 50;
31+
field_input.first.i = 40;
32+
field_input.second.i = 50;
4933
}
5034
}
5135

5236
class GenericMethodParameter {
53-
public void foo(SimpleWrapper<IWrapper> v) {
37+
public void foo(Wrapper<IWrapper> v) {
5438
v.field.i = 20;
5539
}
5640
}
5741

5842
class GenericMethodUninstantiatedParameter {
59-
public <T> void foo_unspec(SimpleWrapper<T> v) {
43+
public <T> void foo_unspec(Wrapper<T> v) {
6044
v.int_field=10;
6145
}
6246
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// int wrapper
2+
class IWrapper {
3+
public int i;
4+
public IWrapper(int ii) {
5+
i = ii;
6+
}
7+
}
8+
9+
// simple generic class
10+
class Wrapper<T> {
11+
public T field;
12+
public T[] array_field;
13+
public int int_field;
14+
}
15+
16+
// generic class with two parameters
17+
class PairWrapper<K, V> {
18+
public K first;
19+
public V second;
20+
}
21+
22+
// simple generic interface
23+
interface InterfaceWrapper<T> {
24+
public T method(T t);
25+
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

unit/goto-programs/goto_program_generics/generic_bases_test.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ SCENARIO(
8686
this_tmp_name,
8787
{"Wrapper"},
8888
"field",
89-
"java::IntWrapper",
89+
"java::IWrapper",
9090
{"java::java.lang.Object"},
9191
entry_point_code);
9292
}
@@ -128,7 +128,7 @@ SCENARIO(
128128
wrapper_tmp_name,
129129
{},
130130
"field",
131-
"java::IntWrapper",
131+
"java::IWrapper",
132132
{},
133133
entry_point_code);
134134
}
@@ -214,17 +214,17 @@ SCENARIO(
214214
{
215215
require_goto_statements::require_struct_component_assignment(
216216
f_tmp_name,
217-
{"TwoWrapper"},
217+
{"PairWrapper"},
218218
"first",
219219
"java::java.lang.Boolean",
220220
{"java::java.lang.Object"},
221221
entry_point_code);
222222

223223
require_goto_statements::require_struct_component_assignment(
224224
f_tmp_name,
225-
{"TwoWrapper"},
225+
{"PairWrapper"},
226226
"second",
227-
"java::IntWrapper",
227+
"java::IWrapper",
228228
{"java::java.lang.Object"},
229229
entry_point_code);
230230
}
@@ -354,7 +354,7 @@ SCENARIO(
354354
inner_tmp_name,
355355
{"Wrapper"},
356356
"field",
357-
"java::IntWrapper",
357+
"java::IWrapper",
358358
{"java::java.lang.Object"},
359359
entry_point_code);
360360
}
@@ -373,14 +373,14 @@ SCENARIO(
373373
{
374374
require_goto_statements::require_struct_component_assignment(
375375
inner_gen_tmp_name,
376-
{"TwoWrapper"},
376+
{"PairWrapper"},
377377
"first",
378-
"java::IntWrapper",
378+
"java::IWrapper",
379379
{"java::java.lang.Object"},
380380
entry_point_code);
381381
require_goto_statements::require_struct_component_assignment(
382382
inner_gen_tmp_name,
383-
{"TwoWrapper"},
383+
{"PairWrapper"},
384384
"second",
385385
"java::java.lang.Boolean",
386386
{"java::java.lang.Object"},
@@ -403,7 +403,7 @@ SCENARIO(
403403
inner_three_tmp_name,
404404
{"Wrapper"},
405405
"field",
406-
"java::IntWrapper",
406+
"java::IWrapper",
407407
{"java::java.lang.Object"},
408408
entry_point_code);
409409
}

unit/goto-programs/goto_program_generics/generic_parameters_test.cpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ SCENARIO(
3939
require_goto_statements::require_entry_point_argument_assignment(
4040
"this", entry_point_code);
4141

42-
THEN("Object 'this' has field 'field_input' of type SimpleWrapper")
42+
THEN("Object 'this' has field 'field_input' of type Wrapper")
4343
{
4444
const auto &field_input_name =
4545
require_goto_statements::require_struct_component_assignment(
4646
tmp_object_name,
4747
{},
4848
"field_input",
49-
"java::SimpleWrapper",
49+
"java::Wrapper",
5050
{},
5151
entry_point_code);
5252

@@ -100,14 +100,14 @@ SCENARIO(
100100
require_goto_statements::require_entry_point_argument_assignment(
101101
"this", entry_point_code);
102102

103-
THEN("Object 'this' has field 'field_input1' of type SimpleWrapper")
103+
THEN("Object 'this' has field 'field_input1' of type Wrapper")
104104
{
105105
const auto &field_input1_name =
106106
require_goto_statements::require_struct_component_assignment(
107107
tmp_object_name,
108108
{},
109109
"field_input1",
110-
"java::SimpleWrapper",
110+
"java::Wrapper",
111111
{},
112112
entry_point_code);
113113

@@ -123,14 +123,14 @@ SCENARIO(
123123
}
124124
}
125125

126-
THEN("Object 'this' has field 'field_input2' of type SimpleWrapper")
126+
THEN("Object 'this' has field 'field_input2' of type Wrapper")
127127
{
128128
const auto &field_input2_name =
129129
require_goto_statements::require_struct_component_assignment(
130130
tmp_object_name,
131131
{},
132132
"field_input2",
133-
"java::SimpleWrapper",
133+
"java::Wrapper",
134134
{},
135135
entry_point_code);
136136

@@ -167,25 +167,25 @@ SCENARIO(
167167
require_goto_statements::require_entry_point_argument_assignment(
168168
"this", entry_point_code);
169169

170-
THEN("Object 'this' has field 'field_input1' of type SimpleWrapper")
170+
THEN("Object 'this' has field 'field_input1' of type Wrapper")
171171
{
172172
const auto &field_input1_name =
173173
require_goto_statements::require_struct_component_assignment(
174174
tmp_object_name,
175175
{},
176176
"field_input1",
177-
"java::SimpleWrapper",
177+
"java::Wrapper",
178178
{},
179179
entry_point_code);
180180

181-
THEN("Object 'field_input1' has field 'field' of type SimpleWrapper")
181+
THEN("Object 'field_input1' has field 'field' of type Wrapper")
182182
{
183183
const auto &field_name =
184184
require_goto_statements::require_struct_component_assignment(
185185
field_input1_name,
186186
{},
187187
"field",
188-
"java::SimpleWrapper",
188+
"java::Wrapper",
189189
{},
190190
entry_point_code);
191191

@@ -233,7 +233,7 @@ SCENARIO(
233233
require_goto_statements::require_struct_component_assignment(
234234
field_input_name,
235235
{},
236-
"key",
236+
"first",
237237
"java::IWrapper",
238238
{},
239239
entry_point_code);
@@ -244,7 +244,7 @@ SCENARIO(
244244
require_goto_statements::require_struct_component_assignment(
245245
field_input_name,
246246
{},
247-
"value",
247+
"second",
248248
"java::IWrapper",
249249
{},
250250
entry_point_code);
@@ -274,7 +274,7 @@ SCENARIO(
274274
require_goto_statements::require_entry_point_argument_assignment(
275275
"v", entry_point_code);
276276

277-
THEN("Object 'v' is of type SimpleWrapper")
277+
THEN("Object 'v' is of type Wrapper")
278278
{
279279
const auto &tmp_object_declaration =
280280
require_goto_statements::require_declaration_of_name(
@@ -284,7 +284,7 @@ SCENARIO(
284284
// and verify that it is what we expect.
285285
const auto &tmp_object_struct =
286286
to_struct_type(tmp_object_declaration.symbol().type());
287-
REQUIRE(tmp_object_struct.get_tag() == "SimpleWrapper");
287+
REQUIRE(tmp_object_struct.get_tag() == "Wrapper");
288288

289289
THEN("Object 'v' has field 'field' of type IWrapper")
290290
{
@@ -323,7 +323,7 @@ SCENARIO(
323323
require_goto_statements::require_entry_point_argument_assignment(
324324
"v", entry_point_code);
325325

326-
THEN("Object 'v' is of type SimpleWrapper")
326+
THEN("Object 'v' is of type Wrapper")
327327
{
328328
const auto &tmp_object_declaration =
329329
require_goto_statements::require_declaration_of_name(
@@ -333,7 +333,7 @@ SCENARIO(
333333
// and verify that it is what we expect.
334334
const auto &tmp_object_struct =
335335
to_struct_type(tmp_object_declaration.symbol().type());
336-
REQUIRE(tmp_object_struct.get_tag() == "SimpleWrapper");
336+
REQUIRE(tmp_object_struct.get_tag() == "Wrapper");
337337

338338
THEN(
339339
"Object 'v' has field 'field' of type Object (upper bound of the "

0 commit comments

Comments
 (0)