Skip to content

Commit c53cb29

Browse files
author
svorenova
committed
Adding and updating unit tests
1 parent a1e9d00 commit c53cb29

39 files changed

+1123
-34
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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+
19+
// A class extending a generic class instantiated with a standard library class
20+
class SuperclassInst extends Wrapper<Integer> {
21+
public void foo() {
22+
this.field = 5;
23+
}
24+
}
25+
26+
// A class extending a generic class instantiated with a user-defined class
27+
class SuperclassInst2 extends Wrapper<IntWrapper> {
28+
public void foo() {
29+
this.field.i = 5;
30+
}
31+
}
32+
33+
// A class extending an instantiated nested generic class
34+
class SuperclassInst3 extends Wrapper<Wrapper<IntWrapper>> {
35+
public void foo() {
36+
this.field.field.i = 5;
37+
}
38+
}
39+
40+
// A generic class extending a generic class (must be with the same parameter)
41+
class SuperclassUninst<U> extends Wrapper<U> {
42+
public void foo(U value) {
43+
this.field = value;
44+
}
45+
}
46+
class SuperclassUninstTest
47+
{
48+
SuperclassUninst<Integer> f;
49+
public void foo() {
50+
f.foo(new Integer(1));
51+
}
52+
}
53+
54+
55+
// A generic class extending a generic class with both instantiated and
56+
// uninstantiated parameters
57+
class SuperclassMixed<U> extends TwoWrapper<U,IntWrapper> {
58+
public void foo(U value) {
59+
this.first = value;
60+
this.second.i = 5;
61+
}
62+
}
63+
class SuperclassMixedTest
64+
{
65+
SuperclassMixed<Boolean> f;
66+
public void foo() {
67+
f.foo(true);
68+
}
69+
}
70+
71+
// Inner classes (generic or not) extending generic classes
72+
class SuperclassInnerInst {
73+
class Inner extends Wrapper<Integer> {
74+
public void foo() {
75+
this.field = 5;
76+
}
77+
}
78+
public Inner inner;
79+
80+
class InnerGen<T> extends Wrapper<T> {
81+
public void foo(T value) {
82+
this.field = value;
83+
}
84+
}
85+
public InnerGen<Boolean> inner_gen;
86+
87+
public void foo() {
88+
inner.foo();
89+
inner_gen.foo(true);
90+
}
91+
}
92+
93+
// Implicitly generic inner classes (generic or not) extending generic classes
94+
class SuperclassInnerUninst<U> {
95+
class Inner extends Wrapper<U> {
96+
public void foo(U value) {
97+
this.field = value;
98+
}
99+
}
100+
public Inner inner;
101+
102+
class InnerGen<T> extends TwoWrapper<U,T> {
103+
public void foo(U uvalue, T tvalue) {
104+
this.first = uvalue;
105+
this.second = tvalue;
106+
}
107+
}
108+
public InnerGen<Boolean> inner_gen;
109+
110+
class InnerThree extends Inner {
111+
}
112+
public InnerThree inner_three;
113+
}
114+
class SuperclassInnerUninstTest
115+
{
116+
SuperclassInnerUninst<IntWrapper> f;
117+
public void foo() {
118+
IntWrapper x = new IntWrapper();
119+
f.inner.foo(x);
120+
f.inner_gen.foo(x,true);
121+
f.inner_three.foo(x);
122+
}
123+
}
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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
17+
public class GenericFields
18+
{
19+
IWrapper field;
20+
class SimpleGenericField {
21+
SimpleWrapper<IWrapper> field_input;
22+
public void foo() {
23+
field_input.field.i = 5;
24+
field_input.array_field = new IWrapper[2];
25+
}
26+
}
27+
28+
class MultipleGenericFields {
29+
SimpleWrapper<IWrapper> field_input1;
30+
SimpleWrapper<IWrapper> field_input2;
31+
public void foo() {
32+
field_input1.field.i = 10;
33+
field_input2.field.i = 20;
34+
}
35+
}
36+
37+
class NestedGenericFields {
38+
SimpleWrapper<SimpleWrapper<IWrapper>> field_input1;
39+
public void foo() {
40+
field_input1.field.field.i = 30;
41+
}
42+
}
43+
44+
class PairGenericField {
45+
PairWrapper<IWrapper, IWrapper> field_input;
46+
public void foo() {
47+
field_input.key.i = 40;
48+
field_input.value.i = 50;
49+
}
50+
}
51+
52+
class GenericMethodParameter {
53+
public void foo(SimpleWrapper<IWrapper> v) {
54+
v.field.i = 20;
55+
}
56+
}
57+
58+
class GenericMethodUninstantiatedParameter {
59+
public <T> void foo_unspec(SimpleWrapper<T> v) {
60+
v.int_field=10;
61+
}
62+
}
63+
64+
class GenericInnerOuter {
65+
class Outer<T> {
66+
public class InnerClass
67+
{
68+
T t;
69+
}
70+
71+
public Outer()
72+
{
73+
field = new InnerClass();
74+
}
75+
76+
public InnerClass field;
77+
}
78+
79+
public void foo(Outer<Integer> v) {
80+
Outer t = new Outer<Integer>();
81+
t.field.t = v.field.t;
82+
}
83+
}
84+
85+
class GenericRewriteParameter {
86+
class A<T> {
87+
T value;
88+
A<Boolean> field;
89+
}
90+
91+
public void foo(A<Integer> v) {
92+
if(v.field.value)
93+
{
94+
v.value = 1;
95+
}
96+
}
97+
}
98+
}
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.

0 commit comments

Comments
 (0)