2 // reference-loader.cs:
4 // Test for reference assembly loading
8 using System.Reflection;
11 public static int Main (string[] args)
13 return TestDriver.RunTests (typeof (Tests), args);
16 public static int test_0_loadFrom_reference ()
18 // Check that loading a reference assembly by filename for execution is an error
20 var a = Assembly.LoadFrom ("./TestingReferenceAssembly.dll");
21 } catch (BadImageFormatException exn) {
22 // Console.Error.WriteLine ("exn was {0}", exn);
28 public static int test_0_load_reference ()
30 // Check that loading a reference assembly for execution is an error
32 var an = new AssemblyName ("TestingReferenceAssembly");
33 var a = Assembly.Load (an);
34 } catch (BadImageFormatException exn) {
35 //Console.Error.WriteLine ("exn was {0}", exn);
37 } catch (FileNotFoundException exn) {
38 Console.Error.WriteLine ("incorrect exn was {0}", exn);
44 public static int test_0_reflection_load_reference ()
46 // Check that reflection-only loading a reference assembly is okay
47 var an = new AssemblyName ("TestingReferenceAssembly");
48 var a = Assembly.ReflectionOnlyLoad (an.FullName);
49 var t = a.GetType ("X");
50 var f = t.GetField ("Y");
51 if (f.FieldType.Equals (typeof (Int32)))
56 public static int test_0_load_reference_asm_via_reference ()
58 // Check that loading an assembly that references a reference assembly doesn't succeed.
59 var an = new AssemblyName ("TestingReferenceReferenceAssembly");
61 var a = Assembly.Load (an);
62 var t = a.GetType ("Z");
63 } catch (FileNotFoundException){
69 public static int test_0_reflection_load_reference_asm_via_reference ()
71 // Check that reflection-only loading an assembly that
72 // references a reference assembly is okay.
73 var an = new AssemblyName ("TestingReferenceReferenceAssembly");
74 var a = Assembly.ReflectionOnlyLoad (an.FullName);
75 var t = a.GetType ("Z");
76 var f = t.GetField ("Y");
77 if (f.FieldType.Equals (typeof (Int32)))
83 public static int test_0_load_reference_bytes ()
85 // Check that loading a reference assembly from a byte array for execution is an error
86 byte[] bs = File.ReadAllBytes ("./TestingReferenceAssembly.dll");
88 var a = Assembly.Load (bs);
89 } catch (BadImageFormatException) {
91 } catch (FileNotFoundException exn) {
92 Console.Error.WriteLine ("incorrect exn was {0}", exn);
98 public static int test_0_reflection_load_reference_bytes ()
100 // Check that loading a reference assembly from a byte
101 // array for reflection only is okay.
102 byte[] bs = File.ReadAllBytes ("./TestingReferenceAssembly.dll");
103 var a = Assembly.ReflectionOnlyLoad (bs);
104 var t = a.GetType ("X");
105 var f = t.GetField ("Y");
106 if (f.FieldType.Equals (typeof (Int32)))