remove debug writelines
[mcs.git] / tests / gtest-284.cs
blobe5aac17e1a4a32f7dbeaf68b1b0f7de3221c4067
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
5 public interface Y
6 { }
8 public class X : Y
12 public struct Foo : Y
13 { }
15 public static class CollectionTester
17 static int Test<T> (IList<T> list)
19 if (list.Count != 1)
20 return 1;
22 ICollection<T> collection = list;
23 if (collection.Count != 1)
24 return 2;
26 IEnumerable<T> enumerable = list;
27 IEnumerator<T> enumerator = enumerable.GetEnumerator ();
28 if (!enumerator.MoveNext ())
29 return 3;
30 if (enumerator.MoveNext ())
31 return 4;
33 return 0;
36 public static int Test ()
38 #region X
39 X[] xarray = new X [] { new X () };
41 int result;
42 result = Test<X> (xarray);
43 if (result != 0)
44 return result;
46 result = Test<object> (xarray);
47 if (result != 0)
48 return 10 + result;
50 result = Test<Y> (xarray);
51 if (result != 0)
52 return 20 + result;
53 #endregion
55 #region int
56 int[] iarray = new int [] { 5 };
57 result = Test<int> (iarray);
58 if (result != 0)
59 return 30 + result;
61 result = Test<uint> ((IList<uint>) (object) iarray);
62 if (result != 0)
63 return 40 + result;
65 uint[] uiarray = new uint [] { 5 };
66 result = Test<int> ((IList<int>) (object) uiarray);
67 if (result != 0)
68 return 50 + result;
70 result = Test<uint> (uiarray);
71 if (result != 0)
72 return 60 + result;
73 #endregion
75 #region long
76 long[] larray = new long [] { 5 };
77 result = Test<long> (larray);
78 if (result != 0)
79 return 70 + result;
81 result = Test<ulong> ((IList<ulong>) (object) larray);
82 if (result != 0)
83 return 80 + result;
85 ulong[] ularray = new ulong [] { 5 };
86 result = Test<long> ((IList<long>) (object) ularray);
87 if (result != 0)
88 return 90 + result;
90 result = Test<ulong> (ularray);
91 if (result != 0)
92 return 100 + result;
93 #endregion
95 #region short
96 short[] sarray = new short [] { 5 };
97 result = Test<short> (sarray);
98 if (result != 0)
99 return 110 + result;
101 result = Test<ushort> ((IList<ushort>) (object) sarray);
102 if (result != 0)
103 return 120 + result;
105 ushort[] usarray = new ushort [] { 5 };
106 result = Test<short> ((IList<short>) (object) usarray);
107 if (result != 0)
108 return 130 + result;
110 result = Test<ushort> (usarray);
111 if (result != 0)
112 return 140 + result;
113 #endregion
115 #region byte
116 byte[] barray = new byte [] { 5 };
117 result = Test<byte> (barray);
118 if (result != 0)
119 return 150 + result;
121 result = Test<sbyte> ((IList<sbyte>) (object) barray);
122 if (result != 0)
123 return 160 + result;
125 sbyte[] sbarray = new sbyte [] { 5 };
126 result = Test<byte> ((IList<byte>) (object) sbarray);
127 if (result != 0)
128 return 170 + result;
130 result = Test<sbyte> (sbarray);
131 if (result != 0)
132 return 180 + result;
133 #endregion
135 return 0;
139 public static class InterfaceTester
141 public const bool Debug = false;
143 static readonly Type ilist_type;
144 static readonly Type icollection_type;
145 static readonly Type ienumerable_type;
146 static readonly Type generic_ilist_type;
147 static readonly Type generic_icollection_type;
148 static readonly Type generic_ienumerable_type;
149 static readonly Type icloneable_type;
150 #if NET_4_0
151 static readonly Type istructuralequatable_type = typeof (IStructuralEquatable);
152 static readonly Type istructuralcomparable_type = typeof (IStructuralComparable);
153 #endif
155 static InterfaceTester ()
157 ilist_type = typeof (IList);
158 icollection_type = typeof (ICollection);
159 ienumerable_type = typeof (IEnumerable);
160 generic_ilist_type = typeof (IList<>);
161 generic_icollection_type = typeof (ICollection<>);
162 generic_ienumerable_type = typeof (IEnumerable<>);
163 icloneable_type = typeof (ICloneable);
166 enum State {
167 Missing,
168 Found,
169 Extra
172 static int Test (Type t, params Type[] iface_types)
174 Hashtable ifaces = new Hashtable ();
175 ifaces.Add (ilist_type, State.Missing);
176 ifaces.Add (icollection_type, State.Missing);
177 ifaces.Add (ienumerable_type, State.Missing);
178 ifaces.Add (icloneable_type, State.Missing);
179 #if NET_4_0
180 ifaces.Add (istructuralequatable_type, State.Missing);
181 ifaces.Add (istructuralcomparable_type, State.Missing);
182 #endif
184 Type array_type = t.MakeArrayType ();
186 if (Debug) {
187 Console.WriteLine ("Checking {0}", t);
188 foreach (Type iface in t.GetInterfaces ())
189 Console.WriteLine (" {0}", iface);
192 foreach (Type iface in iface_types) {
193 Type[] gargs = new Type[] { iface };
194 ifaces.Add (generic_ilist_type.MakeGenericType (gargs), State.Missing);
195 ifaces.Add (generic_icollection_type.MakeGenericType (gargs), State.Missing);
196 ifaces.Add (generic_ienumerable_type.MakeGenericType (gargs), State.Missing);
199 foreach (Type iface in array_type.GetInterfaces ()) {
200 if (ifaces.Contains (iface))
201 ifaces [iface] = State.Found;
202 else
203 ifaces.Add (iface, State.Extra);
206 int errors = 0;
208 foreach (Type iface in ifaces.Keys) {
209 State state = (State) ifaces [iface];
210 if (state == State.Found) {
211 if (Debug)
212 Console.WriteLine ("Found {0}", iface);
213 continue;
214 } else {
215 if (Debug)
216 Console.WriteLine ("ERROR: {0} {1}", iface, state);
217 errors++;
221 if (Debug)
222 Console.WriteLine ();
224 return errors;
227 public static int Test ()
229 int result = Test (typeof (X), typeof (X));
230 if (result != 0)
231 return result;
233 result = Test (typeof (Y), typeof (Y));
234 if (result != 0)
235 return 100 + result;
237 result = Test (typeof (DateTime), typeof (DateTime));
238 if (result != 0)
239 return 200 + result;
241 result = Test (typeof (float), typeof (float));
242 if (result != 0)
243 return 300 + result;
245 result = Test (typeof (int), typeof (int));
246 if (result != 0)
247 return 400 + result;
249 result = Test (typeof (uint), typeof (uint));
250 if (result != 0)
251 return 500 + result;
253 result = Test (typeof (long), typeof (long));
254 if (result != 0)
255 return 600 + result;
257 result = Test (typeof (ulong), typeof (ulong));
258 if (result != 0)
259 return 700 + result;
261 result = Test (typeof (short), typeof (short));
262 if (result != 0)
263 return 800 + result;
265 result = Test (typeof (ushort), typeof (ushort));
266 if (result != 0)
267 return 900 + result;
269 result = Test (typeof (Foo), typeof (Foo));
270 if (result != 0)
271 return 1000 + result;
273 return 0;
277 class Z
279 static int Test ()
281 int result;
282 result = CollectionTester.Test ();
283 if (result != 0)
284 return result;
285 result = InterfaceTester.Test ();
286 if (result != 0)
287 return 10000 + result;
288 return 0;
291 static int Main ()
293 int result = Test ();
294 if (result == 0)
295 Console.WriteLine ("OK");
296 else
297 Console.WriteLine ("ERROR: {0}", result);
298 return result;