Merge pull request #4169 from evincarofautumn/fix-xmm-scanning-mac-x86
[mono.git] / mono / tests / verifier / valid_generic_test.cs
1 using System;
2
3 public delegate void GenericDelegate<T>(T a);
4 public delegate void ObjectDelegate(object a);
5
6 public class Tst<T> {
7         T field;
8         static T staticField;
9
10         public Tst() {
11                 TestLoadStore (field);
12                 TestByRef (field);
13                 TestCalls ();
14                 TestTypeOps ();
15                 TestDelegate ();
16         }
17
18         public void TestLoadStore (T arg) {
19                 T local = arg;
20                 T[] array = new T[10];
21
22                 field = arg;
23                 staticField = arg;
24                 arg = local;
25                 arg = field;
26                 arg = staticField;
27                 array[0] = arg;
28                 field = array[1];
29         }
30         
31         public void TestByRef (T arg) {
32                 T local = arg;
33                 T[] array = new T[10];
34                 PassByRef (ref arg);
35                 PassByRef (ref array[0]);
36                 PassByRef (ref field);
37                 PassByRef (ref local);
38                 PassByRef (ref staticField);
39         }
40
41         public void TestCalls () {
42                 this.field.ToString ();
43                 this.field = Static ();
44                 
45                 Virtual (field);
46         }
47
48         public void TestTypeOps () {
49                 object o = typeof (T);
50                 o = field;
51                 o = default(T);
52                 staticField = (T)o;
53                 if (o is T) {
54                         //T x = o as T; test with constraints
55                 }
56         }
57
58         public void TestDelegate () {
59                 GenericDelegate<T> gd = new GenericDelegate<T>(this.Virtual);
60                 gd(field);
61         }
62
63         public void PassByRef (ref T t) {
64                 t = default (T);
65         }
66
67         public virtual void Virtual (T a) {
68         }
69
70         public static T Static() {
71                 return staticField;
72         }
73 }
74
75 public struct Foo {
76         public int dd;
77 }
78
79 public class Driver {
80         public static void Main () {
81                 new Tst<int> ().Virtual (10);
82                 new Tst<string> ().Virtual ("str");
83                 new Tst<Foo> ().Virtual (new Foo ());
84                 
85         }
86 }