Mark tests as not working under TARGET_JVM
[mono.git] / mcs / class / corlib / Test / System / TypeTest.cs
1 // TypeTest.cs - NUnit Test Cases for the System.Type class
2 //
3 // Authors:
4 //      Zoltan Varga (vargaz@freemail.hu)
5 //  Patrik Torstensson
6 //
7 // (C) 2003 Ximian, Inc.  http://www.ximian.com
8 // 
9
10 using NUnit.Framework;
11 using System;
12 using System.Collections;
13 using System.IO;
14 using System.Reflection;
15 using System.Reflection.Emit;
16 using System.Runtime.InteropServices;
17
18 class NoNamespaceClass {
19 }
20
21 namespace MonoTests.System
22 {
23         class Super : ICloneable {
24                 public virtual object Clone () {
25                         return null;
26                 }
27         }
28         class Duper: Super {
29         }
30
31         interface IFace1 {
32                 void foo ();
33         }
34
35         interface IFace2 : IFace1 {
36                 void bar ();
37         }
38
39         interface IFace3 : IFace2 {
40         }
41
42         enum TheEnum { A, B, C };
43
44         abstract class Base {
45                 public int level;
46
47                 public abstract int this [byte i] { get; }
48                 public abstract int this [int i] { get; }
49                 public abstract void TestVoid();
50                 public abstract void TestInt(int i);
51         }
52
53         class DeriveVTable : Base {
54                 public override int this [byte i] { get { return 1; } }
55                 public override int this [int i] { get { return 1; } }
56                 public override void TestVoid() { level = 1; }
57                 public override void TestInt(int i) { level = 1; }
58         }
59
60         class NewVTable : DeriveVTable {
61                 public new int this [byte i] { get { return 2; } }
62                 public new int this [int i] { get { return 2; } }
63                 public new void TestVoid() { level = 2; }
64                 public new void TestInt(int i) { level = 2; }
65
66                 public void Overload () { }
67                 public void Overload (int i) { }
68
69                 public NewVTable (out int i) {
70                         i = 0;
71                 }
72
73                 public void byref_method (out int i) {
74                         i = 0;
75                 }
76
77         }
78
79         class Base1 {
80                 public virtual int Foo {
81                         get {
82                                 return 1;
83                         }
84                         set {
85                         }
86                 }
87         }
88
89         class Derived1 : Base1 {
90                 public override int Foo {
91                         set {
92                         }
93                 }
94         }
95
96 #if NET_2_0
97         public class Foo<T> {
98                 public T Whatever;
99         
100                 public T Test {
101                         get { throw new NotImplementedException (); }
102                 }
103
104                 public T Execute(T a) {
105                         return a;
106                 }
107         }
108
109         public interface IBar<T> { }
110         public class Baz<T> : IBar<T> { }
111 #endif
112
113         [TestFixture]
114         public class TypeTest
115         {
116                 private void ByrefMethod (ref int i, ref Derived1 j, ref Base1 k) {
117                 }
118
119                 [Test]
120                 public void TestIsAssignableFrom () {
121                         // Simple tests for inheritance
122                         Assert.AreEqual (typeof (Super).IsAssignableFrom (typeof (Duper)) , true, "#01");
123                         Assert.AreEqual (typeof (Duper).IsAssignableFrom (typeof (Duper)), true, "#02");
124                         Assert.AreEqual (typeof (Object).IsAssignableFrom (typeof (Duper)), true, "#03");
125                         Assert.AreEqual (typeof (ICloneable).IsAssignableFrom (typeof (Duper)), true, "#04");
126
127                         // Tests for arrays
128                         Assert.AreEqual (typeof (Super[]).IsAssignableFrom (typeof (Duper[])), true, "#05");
129                         Assert.AreEqual (typeof (Duper[]).IsAssignableFrom (typeof (Super[])), false, "#06");
130                         Assert.AreEqual (typeof (Object[]).IsAssignableFrom (typeof (Duper[])), true, "#07");
131                         Assert.AreEqual (typeof (ICloneable[]).IsAssignableFrom (typeof (Duper[])), true, "#08");
132
133                         // Tests for multiple dimensional arrays
134                         Assert.AreEqual (typeof (Super[][]).IsAssignableFrom (typeof (Duper[][])), true, "#09");
135                         Assert.AreEqual (typeof (Duper[][]).IsAssignableFrom (typeof (Super[][])), false, "#10");
136                         Assert.AreEqual (typeof (Object[][]).IsAssignableFrom (typeof (Duper[][])), true, "#11");
137                         Assert.AreEqual (typeof (ICloneable[][]).IsAssignableFrom (typeof (Duper[][])), true, "#12");
138
139                         // Tests for vectors<->one dimensional arrays */
140 #if TARGET_JVM // Lower bounds arrays are not supported for TARGET_JVM.
141                         Array arr1 = Array.CreateInstance (typeof (int), new int[] {1});
142                         Assert.AreEqual (typeof (int[]).IsAssignableFrom (arr1.GetType ()), true, "#13");
143 #else
144                         Array arr1 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0});
145                         Array arr2 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {10});
146
147                         Assert.AreEqual (typeof (int[]).IsAssignableFrom (arr1.GetType ()), true, "#13");
148                         Assert.AreEqual (typeof (int[]).IsAssignableFrom (arr2.GetType ()), false, "#14");
149 #endif // TARGET_JVM
150
151                         // Test that arrays of enums can be cast to their base types
152                         Assert.AreEqual (typeof (int[]).IsAssignableFrom (typeof (TypeCode[])), true, "#15");
153
154                         // Test that arrays of valuetypes can't be cast to arrays of
155                         // references
156                         Assert.AreEqual (typeof (object[]).IsAssignableFrom (typeof (TypeCode[])), false, "#16");
157                         Assert.AreEqual (typeof (ValueType[]).IsAssignableFrom (typeof (TypeCode[])), false, "#17");
158                         Assert.AreEqual (typeof (Enum[]).IsAssignableFrom (typeof (TypeCode[])), false, "#18");
159
160                         // Test that arrays of enums can't be cast to arrays of references
161                         Assert.AreEqual (typeof (object[]).IsAssignableFrom (typeof (TheEnum[])), false, "#19");
162                         Assert.AreEqual (typeof (ValueType[]).IsAssignableFrom (typeof (TheEnum[])), false, "#20");
163                         Assert.AreEqual (typeof (Enum[]).IsAssignableFrom (typeof (TheEnum[])), false, "#21");
164
165                         // Check that ValueType and Enum are recognized as reference types
166                         Assert.AreEqual (typeof (object).IsAssignableFrom (typeof (ValueType)), true, "#22");
167                         Assert.AreEqual (typeof (object).IsAssignableFrom (typeof (Enum)), true, "#23");
168                         Assert.AreEqual (typeof (ValueType).IsAssignableFrom (typeof (Enum)), true, "#24");
169
170                         Assert.AreEqual (typeof (object[]).IsAssignableFrom (typeof (ValueType[])), true, "#25");
171                         Assert.AreEqual (typeof (ValueType[]).IsAssignableFrom (typeof (ValueType[])), true, "#26");
172                         Assert.AreEqual (typeof (Enum[]).IsAssignableFrom (typeof (ValueType[])), false, "#27");
173
174                         Assert.AreEqual (typeof (object[]).IsAssignableFrom (typeof (Enum[])), true, "#28");
175                         Assert.AreEqual (typeof (ValueType[]).IsAssignableFrom (typeof (Enum[])), true, "#29");
176                         Assert.AreEqual (typeof (Enum[]).IsAssignableFrom (typeof (Enum[])), true, "#30");
177
178                         // Tests for byref types
179                         MethodInfo mi = typeof (TypeTest).GetMethod ("ByrefMethod", BindingFlags.Instance|BindingFlags.NonPublic);
180                         Assert.IsTrue (mi.GetParameters ()[2].ParameterType.IsAssignableFrom (mi.GetParameters ()[1].ParameterType));
181                         Assert.IsTrue (mi.GetParameters ()[1].ParameterType.IsAssignableFrom (mi.GetParameters ()[1].ParameterType));
182                 }
183
184                 [Test]
185                 public void TestIsSubclassOf () {
186                         Assert.IsTrue (typeof (ICloneable).IsSubclassOf (typeof (object)), "#01");
187
188                         // Tests for byref types
189                         Type paramType = typeof (TypeTest).GetMethod ("ByrefMethod", BindingFlags.Instance|BindingFlags.NonPublic).GetParameters () [0].ParameterType;
190                         Assert.IsTrue (!paramType.IsSubclassOf (typeof (ValueType)), "#02");
191                         //Assert.IsTrue (paramType.IsSubclassOf (typeof (Object)), "#03");
192                         Assert.IsTrue (!paramType.IsSubclassOf (paramType), "#04");
193                 }
194
195                 [Test]
196                 public void TestGetMethodImpl() {
197                         // Test binding of new slot methods (using no types)
198                         Assert.AreEqual (typeof (Base), typeof (Base).GetMethod("TestVoid").DeclaringType, "#01");
199                         Assert.AreEqual (typeof (NewVTable), typeof (NewVTable).GetMethod ("TestVoid").DeclaringType, "#02");
200
201                         // Test binding of new slot methods (using types)
202                         Assert.AreEqual (typeof (Base), typeof (Base).GetMethod ("TestInt", new Type[] { typeof (int) }).DeclaringType, "#03");
203                         Assert.AreEqual (typeof (NewVTable), typeof (NewVTable).GetMethod ("TestInt", new Type[] { typeof (int) }).DeclaringType, "#04");
204
205                         // Test overload resolution
206                         Assert.AreEqual (0, typeof (NewVTable).GetMethod ("Overload", new Type[0]).GetParameters ().Length, "#05");
207
208                         // Test byref parameters
209                         Assert.AreEqual (null, typeof (NewVTable).GetMethod ("byref_method", new Type[] { typeof (int) }), "#06");
210                         Type byrefInt = typeof (NewVTable).GetMethod ("byref_method").GetParameters ()[0].ParameterType;
211                         Assert.IsNotNull (typeof (NewVTable).GetMethod ("byref_method", new Type[] { byrefInt }), "#07");
212                 }
213
214                 [Test]
215                 [Category ("TargetJvmNotWorking")]
216                 public void TestGetPropertyImpl() {
217                         // Test getting property that is exact
218                         Assert.AreEqual (typeof (NewVTable), typeof (NewVTable).GetProperty ("Item", new Type[1] { typeof (Int32) }).DeclaringType, "#01");
219
220                         // Test getting property that is not exact
221                         Assert.AreEqual (typeof (NewVTable), typeof (NewVTable).GetProperty ("Item", new Type[1] { typeof (Int16) }).DeclaringType, "#02");
222
223                         // Test overriding of properties when only the set accessor is overriden
224                         Assert.AreEqual (1, typeof (Derived1).GetProperties ().Length, "#03");
225                 }
226
227 #if !TARGET_JVM // StructLayout not supported for TARGET_JVM
228                 [StructLayout(LayoutKind.Explicit, Pack = 4, Size = 64)]
229                 public class Class1 {
230                 }
231
232                 [StructLayout(LayoutKind.Explicit, CharSet=CharSet.Unicode)]
233                 public class Class2 {
234                 }
235
236 #if NET_2_0
237                 [Test]
238                 public void StructLayoutAttribute () {
239                         StructLayoutAttribute attr1 = typeof (TypeTest).StructLayoutAttribute;
240                         Assert.AreEqual (LayoutKind.Auto, attr1.Value);
241
242                         StructLayoutAttribute attr2 = typeof (Class1).StructLayoutAttribute;
243                         Assert.AreEqual (LayoutKind.Explicit, attr2.Value);
244                         Assert.AreEqual (4, attr2.Pack);
245                         Assert.AreEqual (64, attr2.Size);
246
247                         StructLayoutAttribute attr3 = typeof (Class2).StructLayoutAttribute;
248                         Assert.AreEqual (LayoutKind.Explicit, attr3.Value);
249                         Assert.AreEqual (CharSet.Unicode, attr3.CharSet);
250                 }
251 #endif
252 #endif // TARGET_JVM
253
254                 [Test]
255                 public void Namespace () {
256                         Assert.AreEqual (null, typeof (NoNamespaceClass).Namespace);
257                 }
258
259                 public static void Reflected (ref int a) {
260                 }
261
262                 [Test]
263                 public void Name ()
264                 {
265                         Assert.AreEqual ("Int32&", typeof (TypeTest).GetMethod ("Reflected").GetParameters () [0].ParameterType.Name);
266                 }
267
268                 [Test]
269                 public void GetInterfaces () {
270                         Type[] t = typeof (Duper).GetInterfaces ();
271                         Assert.AreEqual (1, t.Length);
272                         Assert.AreEqual (typeof (ICloneable), t[0]);
273
274                         Type[] t2 = typeof (IFace3).GetInterfaces ();
275                         Assert.AreEqual (2, t2.Length);
276                 }
277
278                 public int AField;
279
280                 [Test]
281                 public void GetFieldIgnoreCase () {
282                         Assert.IsNotNull (typeof (TypeTest).GetField ("afield", BindingFlags.Instance|BindingFlags.Public|BindingFlags.IgnoreCase));
283                 }
284
285 #if NET_2_0
286                 public int Count {
287                         internal get {
288                                 return 0;
289                         }
290
291                         set {
292                         }
293                 }
294
295                 [Test]
296                 public void GetPropertyAccessorModifiers () {
297                         Assert.IsNotNull (typeof (TypeTest).GetProperty ("Count", BindingFlags.Instance | BindingFlags.Public));
298                         Assert.IsNull (typeof (TypeTest).GetProperty ("Count", BindingFlags.Instance | BindingFlags.NonPublic));
299                 }
300 #endif
301
302                 [Test]
303                 public void IsPrimitive () {
304                         Assert.IsTrue (typeof (IntPtr).IsPrimitive);
305                 }
306
307                 [Test]
308                 [Category("NotDotNet")]
309                 // Depends on the GAC working, which it doesn't durring make distcheck.
310                 [Category ("NotWorking")]
311                 public void GetTypeWithWhitespace () {
312                         Assert.IsNotNull (Type.GetType
313                                                    (@"System.Configuration.NameValueSectionHandler,
314                         System,
315 Version=1.0.5000.0,
316 Culture=neutral
317 ,
318 PublicKeyToken=b77a5c561934e089"));
319                 }
320                 
321                 [Test]
322                 public void ExerciseFilterName() {
323                         MemberInfo[] mi = typeof(Base).FindMembers(
324                                 MemberTypes.Method, 
325                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
326                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
327                             Type.FilterName, "*");
328                         Assert.AreEqual (4, mi.Length);
329                         mi = typeof(Base).FindMembers(
330                                 MemberTypes.Method, 
331                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
332                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
333                             Type.FilterName, "Test*");
334                         Assert.AreEqual (2, mi.Length);
335                         mi = typeof(Base).FindMembers(
336                                 MemberTypes.Method, 
337                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
338                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
339                             Type.FilterName, "TestVoid");
340                         Assert.AreEqual (1, mi.Length);
341                         mi = typeof(Base).FindMembers(
342                                 MemberTypes.Method, 
343                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
344                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
345                             Type.FilterName, "NonExistingMethod");
346                         Assert.AreEqual (0, mi.Length);
347                 }
348                 
349                 [Test]
350                 public void ExerciseFilterNameIgnoreCase() {
351                         MemberInfo[] mi = typeof(Base).FindMembers(
352                                 MemberTypes.Method, 
353                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
354                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
355                             Type.FilterNameIgnoreCase, "*");
356                         Assert.AreEqual (4, mi.Length);
357                         mi = typeof(Base).FindMembers(
358                                 MemberTypes.Method, 
359                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
360                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
361                             Type.FilterNameIgnoreCase, "test*");
362                         Assert.AreEqual (2, mi.Length);
363                         mi = typeof(Base).FindMembers(
364                                 MemberTypes.Method, 
365                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
366                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
367                             Type.FilterNameIgnoreCase, "TESTVOID");
368                         Assert.AreEqual (1, mi.Length);
369                         mi = typeof(Base).FindMembers(
370                                 MemberTypes.Method, 
371                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
372                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
373                             Type.FilterNameIgnoreCase, "NonExistingMethod");
374                         Assert.AreEqual (0, mi.Length);
375                 }
376
377                 public class ByRef0 {
378                         public int field;
379                         public int property {
380                                 get { return 0; }
381                         }
382                         public ByRef0 (int i) {}
383                         public void f (int i) {}
384                 }
385
386                 [Test]
387                 public void ByrefTypes ()
388                 {
389                         Type t = Type.GetType ("MonoTests.System.TypeTest+ByRef0&");
390                         Assert.IsNotNull (t);
391                         Assert.IsTrue (t.IsByRef);
392                         Assert.AreEqual (0, t.GetMethods (BindingFlags.Public | BindingFlags.Instance).Length);
393                         Assert.AreEqual (0, t.GetConstructors (BindingFlags.Public | BindingFlags.Instance).Length);
394                         Assert.AreEqual (0, t.GetEvents (BindingFlags.Public | BindingFlags.Instance).Length);
395                         Assert.AreEqual (0, t.GetProperties (BindingFlags.Public | BindingFlags.Instance).Length);
396
397                         Assert.IsNull (t.GetMethod ("f"));
398                         Assert.IsNull (t.GetField ("field"));
399                         Assert.IsNull (t.GetProperty ("property"));
400                 }
401
402                 struct B
403                 {
404                         int value;
405                 }
406
407                 [Test]
408                 public void CreateValueTypeNoCtor () {
409                         typeof(B).InvokeMember ("", BindingFlags.CreateInstance, null, null, null);
410                 }
411
412                 [Test]
413                 [ExpectedException (typeof (MissingMethodException))]
414                 public void CreateValueTypeNoCtorArgs () {
415                         typeof(B).InvokeMember ("", BindingFlags.CreateInstance, null, null, new object [] { 1 });
416                 }
417
418                 class X
419                 {
420                         public static int Value;
421                 }
422
423                 class Y  : X
424                 {
425                 }
426
427                 [Test]
428                 public void InvokeMemberGetSetField () {
429                         typeof (X).InvokeMember ("Value", BindingFlags.Public|BindingFlags.Static|BindingFlags.FlattenHierarchy|BindingFlags.SetField, null, null, new object [] { 5 });
430
431                         Assert.AreEqual (5, X.Value);
432                         Assert.AreEqual (5, typeof (X).InvokeMember ("Value", BindingFlags.Public|BindingFlags.Static|BindingFlags.FlattenHierarchy|BindingFlags.GetField, null, null, new object [0]));
433                         Assert.AreEqual (5, Y.Value);
434                         Assert.AreEqual (5, typeof (Y).InvokeMember ("Value", BindingFlags.Public|BindingFlags.Static|BindingFlags.FlattenHierarchy|BindingFlags.GetField, null, null, new object [0]));
435                 }                       
436
437                 class Z {
438                         public Z (IComparable value) {}
439                 }
440         
441                 [Test]
442                 public void InvokeMemberMatchPrimitiveTypeWithInterface () {
443                         object[] invokeargs = {1};
444                         typeof (Z).InvokeMember( "", 
445                                                                                         BindingFlags.DeclaredOnly |
446                                                                                         BindingFlags.Public |
447                                                                                         BindingFlags.NonPublic |
448                                                                                         BindingFlags.Instance |
449                                                                                         BindingFlags.CreateInstance,
450                                                                                         null, null, invokeargs 
451                                                                                         );
452                 }
453
454                 class TakesInt {
455                         private int i;
456
457                         public TakesInt (int x)
458                         {
459                                 i = x;
460                         }
461
462                         public int Integer {
463                                 get { return i; }
464                         }
465                 }
466
467                 class TakesObject {
468                         public TakesObject (object x) {}
469                 }
470
471                 // Filed as bug #75241
472                 [Test]
473                 public void GetConstructorNullInTypes ()
474                 {
475                         // This ends up calling type.GetConstructor ()
476                         Activator.CreateInstance (typeof (TakesInt), new object [] { null });
477                         Activator.CreateInstance (typeof (TakesObject), new object [] { null });
478                 }
479
480                 [Test]
481                 [ExpectedException (typeof (ArgumentNullException))]
482                 public void GetConstructorNullInTypes_Bug71300 ()
483                 {
484                         typeof (TakesInt).GetConstructor (new Type[1] { null });
485                         // so null in types isn't valid for GetConstructor!
486                 }
487
488                 [Test]
489                 public void GetConstructor_TakeInt_Object ()
490                 {
491                         Assert.IsNull (typeof (TakesInt).GetConstructor (new Type[1] { typeof (object) }));
492                 }
493
494                 // bug #76150
495                 [Test]
496                 public void IsDefined ()
497                 {
498                         Assert.IsTrue (typeof (A).IsDefined (typeof (NemerleAttribute), false), "#1");
499                         Assert.IsTrue (typeof (A).IsDefined (typeof (VolatileModifier), false), "#2");
500                 }
501
502                 [Test]
503                 public void GetTypeCode ()
504                 {
505                         Assert.AreEqual (TypeCode.Boolean, Type.GetTypeCode (typeof (bool)), "#1");
506                         Assert.AreEqual (TypeCode.Byte, Type.GetTypeCode (typeof (byte)), "#2");
507                         Assert.AreEqual (TypeCode.Char, Type.GetTypeCode (typeof (char)), "#3");
508                         Assert.AreEqual (TypeCode.DateTime, Type.GetTypeCode (typeof (DateTime)), "#4");
509                         Assert.AreEqual (TypeCode.DBNull, Type.GetTypeCode (typeof (DBNull)), "#5");
510                         Assert.AreEqual (TypeCode.Decimal, Type.GetTypeCode (typeof (decimal)), "#6");
511                         Assert.AreEqual (TypeCode.Double, Type.GetTypeCode (typeof (double)), "#7");
512                         Assert.AreEqual (TypeCode.Empty, Type.GetTypeCode (null), "#8");
513                         Assert.AreEqual (TypeCode.Int16, Type.GetTypeCode (typeof (short)), "#9");
514                         Assert.AreEqual (TypeCode.Int32, Type.GetTypeCode (typeof (int)), "#10");
515                         Assert.AreEqual (TypeCode.Int64, Type.GetTypeCode (typeof (long)), "#11");
516                         Assert.AreEqual (TypeCode.Object, Type.GetTypeCode (typeof (TakesInt)), "#12");
517                         Assert.AreEqual (TypeCode.SByte, Type.GetTypeCode (typeof (sbyte)), "#13");
518                         Assert.AreEqual (TypeCode.Single, Type.GetTypeCode (typeof (float)), "#14");
519                         Assert.AreEqual (TypeCode.String, Type.GetTypeCode (typeof (string)), "#15");
520                         Assert.AreEqual (TypeCode.UInt16, Type.GetTypeCode (typeof (ushort)), "#16");
521                         Assert.AreEqual (TypeCode.UInt32, Type.GetTypeCode (typeof (uint)), "#17");
522                         Assert.AreEqual (TypeCode.UInt64, Type.GetTypeCode (typeof (ulong)), "#18");
523                 }
524
525                 [Test]
526                 [ExpectedException (typeof (ArgumentNullException))]
527                 public void GetConstructor1a_Bug71300 ()
528                 {
529                         typeof (BindingFlags).GetConstructor (null);
530                 }
531
532                 [Test]
533                 [ExpectedException (typeof (ArgumentNullException))]
534                 public void GetConstructor1b_Bug71300 ()
535                 {
536                         typeof (BindingFlags).GetConstructor (new Type[1] { null });
537                 }
538
539                 [Test]
540                 [ExpectedException (typeof (ArgumentNullException))]
541                 public void GetConstructor4_Bug71300 ()
542                 {
543                         typeof (BindingFlags).GetConstructor (BindingFlags.Default, null, new Type[1] { null }, null);
544                 }
545
546                 [Test]
547                 [ExpectedException (typeof (ArgumentNullException))]
548                 public void GetConstructor5_Bug71300 ()
549                 {
550                         typeof (BindingFlags).GetConstructor (BindingFlags.Default, null, CallingConventions.Any, new Type[1] { null }, null);
551                 }
552
553                 [Test]
554                 public void GetMethod_Bug77367 ()
555                 {
556                         MethodInfo i = typeof (Bug77367).GetMethod ("Run", Type.EmptyTypes);
557                         Assert.IsNull (i);
558                 }
559
560 #if !TARGET_JVM // Reflection.Emit is not supported for TARGET_JVM
561                 [Test]
562                 public void EqualsUnderlyingType ()
563                 {
564                         AssemblyBuilderAccess access = AssemblyBuilderAccess.RunAndSave;
565                         TypeAttributes attribs = TypeAttributes.Public;
566
567                         AssemblyName name = new AssemblyName ();
568                         name.Name = "enumtest";
569                         AssemblyBuilder assembly = 
570                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
571                                                                                                                            name, access);
572
573                         ModuleBuilder module = assembly.DefineDynamicModule 
574                                 ("m", "enumtest.dll");
575                         EnumBuilder e = module.DefineEnum ("E", attribs, typeof (int));
576
577                         Assert.IsTrue (typeof (int).Equals (e));
578                 }
579 #endif // TARGET_JVM
580
581                 [Test]
582                 public void GetElementType_Bug63841 ()
583                 {
584                         Assert.IsNull (typeof (TheEnum).GetElementType (), "#1");
585                 }
586
587 #if NET_2_0
588                 [Test]
589                 public void FullNameGenerics ()
590                 {
591                         Type fooType = typeof (Foo<>);
592                         FieldInfo [] fields = fooType.GetFields ();
593
594                         Assert.AreEqual (1, fields.Length, "#0");
595
596                         Assert.IsNotNull (fooType.FullName, "#1");
597                         Assert.IsNotNull (fooType.AssemblyQualifiedName, "#1a");
598
599                         FieldInfo field = fooType.GetField ("Whatever");
600                         Assert.IsNotNull (field, "#2");
601                         Assert.AreEqual (field, fields [0], "#2a");
602                         Assert.IsNull (field.FieldType.FullName, "#3");
603                         Assert.IsNull (field.FieldType.AssemblyQualifiedName, "#3a");
604                         Assert.IsNotNull (field.FieldType.ToString (), "#4");
605
606                         PropertyInfo prop = fooType.GetProperty ("Test");
607                         Assert.IsNotNull (prop, "#5");
608                         Assert.IsNull (prop.PropertyType.FullName, "#6");
609                         Assert.IsNull (prop.PropertyType.AssemblyQualifiedName, "#6a");
610                         Assert.IsNotNull (prop.PropertyType.ToString (), "#7");
611
612                         MethodInfo method = fooType.GetMethod("Execute");
613                         Assert.IsNotNull (method, "#8");
614                         Assert.IsNull (method.ReturnType.FullName, "#9");
615                         Assert.IsNull (method.ReturnType.AssemblyQualifiedName, "#9a");
616                         Assert.IsNotNull (method.ReturnType.ToString (), "#10");
617
618                         ParameterInfo[] parameters = method.GetParameters();
619                         Assert.AreEqual (1, parameters.Length, "#11");
620                         Assert.IsNull (parameters[0].ParameterType.FullName, "#12");
621                         Assert.IsNull (parameters[0].ParameterType.AssemblyQualifiedName, "#12a");
622                         Assert.IsNotNull (parameters[0].ParameterType.ToString (), "#13");
623                 }
624
625                 [Test]
626                 public void TypeParameterIsNotGeneric ()
627                 {
628                         Type fooType = typeof (Foo<>);
629                         Type type_param = fooType.GetGenericArguments () [0];
630                         Assert.IsTrue (type_param.IsGenericParameter);
631                         Assert.IsFalse (type_param.IsGenericType);
632                         Assert.IsFalse (type_param.IsGenericTypeDefinition);
633
634                         // LAMESPEC: MSDN claims that this should be false, but .NET v2.0.50727 says it's true
635                         // http://msdn2.microsoft.com/en-us/library/system.type.isgenerictype.aspx
636                         Assert.IsTrue (type_param.ContainsGenericParameters);
637                 }
638
639                 [Test]
640                 public void IsAssignable ()
641                 {
642                         Type foo_type = typeof (Foo<>);
643                         Type foo_int_type = typeof (Foo<int>);
644                         Assert.IsFalse (foo_type.IsAssignableFrom (foo_int_type), "Foo<int> -!-> Foo<>");
645                         Assert.IsFalse (foo_int_type.IsAssignableFrom (foo_type), "Foo<> -!-> Foo<int>");
646
647                         Type ibar_short_type = typeof (IBar<short>);
648                         Type ibar_int_type = typeof (IBar<int>);
649                         Type baz_short_type = typeof (Baz<short>);
650                         Type baz_int_type = typeof (Baz<int>);
651
652                         Assert.IsTrue (ibar_int_type.IsAssignableFrom (baz_int_type), "Baz<int> -> IBar<int>");
653                         Assert.IsTrue (ibar_short_type.IsAssignableFrom (baz_short_type), "Baz<short> -> IBar<short>");
654
655                         Assert.IsFalse (ibar_int_type.IsAssignableFrom (baz_short_type), "Baz<short> -!-> IBar<int>");
656                         Assert.IsFalse (ibar_short_type.IsAssignableFrom (baz_int_type), "Baz<int> -!-> IBar<short>");
657
658                         // Nullable tests
659                         Assert.IsTrue (typeof (Nullable<int>).IsAssignableFrom (typeof (int)));
660                         Assert.IsFalse (typeof (int).IsAssignableFrom (typeof (Nullable<int>)));
661                         Assert.IsTrue (typeof (Nullable<FooStruct>).IsAssignableFrom (typeof (FooStruct)));
662                 }
663
664                 [Test]
665                 public void IsInstanceOf ()
666                 {
667                         Assert.IsTrue (typeof (Nullable<int>).IsInstanceOfType (5));
668                 }
669
670                 [Test]
671                 public void ByrefType ()
672                 {
673                         Type foo_type = typeof (Foo<>);
674                         Type type_param = foo_type.GetGenericArguments () [0];
675                         Type byref_type_param = type_param.MakeByRefType ();
676                         Assert.IsFalse (byref_type_param.IsGenericParameter);
677                         Assert.IsNull (byref_type_param.DeclaringType);
678                 }
679
680                 [Test]
681                 [Category ("NotWorking")] // BindingFlags.SetField throws since args.Length != 1, even though we have SetProperty
682                 public void Bug79023 ()
683                 {
684                         ArrayList list = new ArrayList();
685                         list.Add("foo");
686
687                         // The next line used to throw because we had SetProperty
688                         list.GetType().InvokeMember("Item",
689                                                     BindingFlags.SetField|BindingFlags.SetProperty|
690                                                     BindingFlags.Instance|BindingFlags.Public,
691                                                     null, list, new object[] { 0, "bar" });
692                         Assert.AreEqual ("bar", list[0]);
693                 }
694                 
695                 [ComVisible (true)]
696                 public class ComFoo<T> {
697                 }
698
699                 [Test]
700                 public void GetCustomAttributesGenericInstance ()
701                 {
702                         Assert.AreEqual (1, typeof (ComFoo<int>).GetCustomAttributes (typeof (ComVisibleAttribute), true).Length);
703                 }
704
705                 interface ByRef1<T> { void f (ref T t); }
706                 interface ByRef2 { void f<T> (ref T t); }
707
708                 interface ByRef3<T> where T:struct { void f (ref T? t); }
709                 interface ByRef4 { void f<T> (ref T? t) where T:struct; }
710
711                 void CheckGenericByRef (Type t)
712                 {
713                         string name = t.Name;
714                         t = t.GetMethod ("f").GetParameters () [0].ParameterType;
715
716                         Assert.IsFalse (t.IsGenericType, name);
717                         Assert.IsFalse (t.IsGenericTypeDefinition, name);
718                         Assert.IsFalse (t.IsGenericParameter, name);
719                 }
720
721                 [Test]
722                 public void GenericByRef ()
723                 {
724                         CheckGenericByRef (typeof (ByRef1<>));
725                         CheckGenericByRef (typeof (ByRef2));
726                         CheckGenericByRef (typeof (ByRef3<>));
727                         CheckGenericByRef (typeof (ByRef4));
728                 }
729
730                 public class Bug80242<T> {
731                         public interface IFoo { }
732                         public class Bar : IFoo { }
733                         public class Baz : Bar { }
734                 }
735
736                 [Test]
737                 public void TestNestedTypes ()
738                 {
739                         Type t = typeof (Bug80242<object>);
740                         Assert.IsFalse (t.IsGenericTypeDefinition);
741                         foreach (Type u in t.GetNestedTypes ()) {
742                                 Assert.IsTrue (u.IsGenericTypeDefinition, "{0} isn't a generic definition", u);
743                                 Assert.AreEqual (u, u.GetGenericArguments () [0].DeclaringType);
744                         }
745                 }
746 #endif
747
748                 public class NemerleAttribute : Attribute
749                 { }
750
751                 public class VolatileModifier : NemerleAttribute
752                 { }
753
754                 [VolatileModifier]
755                 class A { }
756
757                 struct FooStruct {
758                 }
759
760                 public class Bug77367
761                 {
762                         public void Run (bool b)
763                         {
764                         }
765                 }
766
767         }
768 }