2010-05-27 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / tests / dtest-001.cs
1 //
2 // dynamic type attribute decoration
3 //
4
5 using System;
6 using System.Collections;
7 using System.Runtime.CompilerServices;
8 using System.Collections.Generic;
9 using System.Linq;
10
11 class C
12 {
13         public C (dynamic d)
14         {
15         }
16
17         public dynamic a;
18         public const dynamic c = default (dynamic);
19
20         public dynamic Prop { set; get; }
21         public dynamic Prop2 { set { } }
22
23         public dynamic this[dynamic d] { set { } get { return 1; } }
24
25         public dynamic Method (dynamic d)
26         {
27                 return null;
28         }
29
30         // Transformation handling required
31         public dynamic[] t;
32         public dynamic[,] t2;
33         public Func<dynamic, int, dynamic[]> v;
34 }
35
36 delegate dynamic Del (dynamic d);
37
38 class Test
39 {
40         public static int Main ()
41         {
42                 Type t = typeof (C);
43                 Type ca = typeof (System.Runtime.CompilerServices.DynamicAttribute);
44
45                 if (t.GetMember ("a")[0].GetCustomAttributes (ca, false).Length != 1)
46                         return 1;
47
48                 if (t.GetMember ("c")[0].GetCustomAttributes (ca, false).Length != 1)
49                         return 3;
50
51                 if (t.GetMember ("Prop")[0].GetCustomAttributes (ca, false).Length != 1)
52                         return 4;
53
54                 if (t.GetMember ("get_Prop")[0].GetCustomAttributes (ca, false).Length != 0)
55                         return 5;
56
57                 if (t.GetMethod ("get_Prop").ReturnParameter.GetCustomAttributes (ca, false).Length != 1)
58                         return 6;
59
60                 if (t.GetMember ("set_Prop")[0].GetCustomAttributes (ca, false).Length != 0)
61                         return 7;
62
63                 if (t.GetMethod ("set_Prop").ReturnParameter.GetCustomAttributes (ca, false).Length != 0)
64                         return 8;
65
66                 if (t.GetMethod ("set_Prop").GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
67                         return 9;
68
69                 if (t.GetMember ("Prop2")[0].GetCustomAttributes (ca, false).Length != 1)
70                         return 10;
71
72                 if (t.GetMember ("set_Prop2")[0].GetCustomAttributes (ca, false).Length != 0)
73                         return 11;
74
75                 if (t.GetMember ("Item")[0].GetCustomAttributes (ca, false).Length != 1)
76                         return 12;
77
78                 if (t.GetMethod ("get_Item").ReturnParameter.GetCustomAttributes (ca, false).Length != 1)
79                         return 13;
80
81                 if (t.GetMethod ("get_Item").GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
82                         return 14;
83
84                 if (t.GetMethod ("set_Item").ReturnParameter.GetCustomAttributes (ca, false).Length != 0)
85                         return 15;
86
87                 if (t.GetMethod ("set_Item").GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
88                         return 16;
89
90                 if (t.GetMethod ("set_Item").GetParameters ()[1].GetCustomAttributes (ca, false).Length != 1)
91                         return 17;
92
93                 if (t.GetMember ("Method")[0].GetCustomAttributes (ca, false).Length != 0)
94                         return 18;
95
96                 if (t.GetMethod ("Method").GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
97                         return 19;
98
99                 if (t.GetConstructors ()[0].GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
100                         return 20;
101
102                 if (t.GetConstructors ()[0].GetCustomAttributes (ca, false).Length != 0)
103                         return 21;
104
105                 // Transformations
106                 DynamicAttribute da;
107                 da = t.GetMember ("t")[0].GetCustomAttributes (ca, false)[0] as DynamicAttribute;
108                 if (da == null)
109                         return 40;
110
111                 if (!da.TransformFlags.SequenceEqual (new bool[] { false, true }))
112                         return 41;
113
114                 da = t.GetMember ("t2")[0].GetCustomAttributes (ca, false)[0] as DynamicAttribute;
115                 if (da == null)
116                         return 42;
117
118                 if (!da.TransformFlags.SequenceEqual (new bool[] { false, true }))
119                         return 43;
120
121                 da = t.GetMember ("v")[0].GetCustomAttributes (ca, false)[0] as DynamicAttribute;
122                 if (da == null)
123                         return 44;
124                 if (!da.TransformFlags.SequenceEqual (new bool[] { false, true, false, false, true }))
125                         return 45;
126
127                 t = typeof (Del);
128
129                 if (t.GetMember ("Invoke")[0].GetCustomAttributes (ca, false).Length != 0)
130                         return 100;
131
132                 if (t.GetMethod ("Invoke").GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
133                         return 101;
134
135                 if (t.GetMethod ("Invoke").ReturnParameter.GetCustomAttributes (ca, false).Length != 1)
136                         return 102;
137
138                 Console.WriteLine ("ok");
139                 return 0;
140         }
141 }