[threads] Don't ignore abort requests in abort protected blocks
[mono-project.git] / mono / tests / reference-loader.cs
bloba66d3c5de1e852882439c2960d17eae360c6d933
1 //
2 // reference-loader.cs:
3 //
4 // Test for reference assembly loading
6 using System;
7 using System.IO;
8 using System.Reflection;
10 public class Tests {
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
19 try {
20 var a = Assembly.LoadFrom ("./TestingReferenceAssembly.dll");
21 } catch (BadImageFormatException exn) {
22 // .NET Framework 4.6.2 throws BIFE here.
23 return 0;
25 return 1;
28 public static int test_0_load_reference ()
30 // Check that loading a reference assembly for execution is an error
31 try {
32 var an = new AssemblyName ("TestingReferenceAssembly");
33 var a = Assembly.Load (an);
34 } catch (FileNotFoundException exn) {
35 return 0;
36 } catch (BadImageFormatException exn) {
37 // .NET Framework 4.6.2 throws BIFE here.
38 return 0;
40 return 1;
43 public static int test_0_reflection_load_reference ()
45 // Check that reflection-only loading a reference assembly is okay
46 var an = new AssemblyName ("TestingReferenceAssembly");
47 var a = Assembly.ReflectionOnlyLoad (an.FullName);
48 var t = a.GetType ("X");
49 var f = t.GetField ("Y");
50 if (f.FieldType.Equals (typeof (Int32)))
51 return 0;
52 return 1;
55 public static int test_0_load_reference_asm_via_reference ()
57 // Check that loading an assembly that references a reference assembly doesn't succeed.
58 var an = new AssemblyName ("TestingReferenceReferenceAssembly");
59 try {
60 var a = Assembly.Load (an);
61 var t = a.GetType ("Z");
62 } catch (FileNotFoundException){
63 return 0;
65 return 1;
68 public static int test_0_reflection_load_reference_asm_via_reference ()
70 // Check that reflection-only loading an assembly that
71 // references a reference assembly is okay.
72 var an = new AssemblyName ("TestingReferenceReferenceAssembly");
73 var a = Assembly.ReflectionOnlyLoad (an.FullName);
74 var t = a.GetType ("Z");
75 var f = t.GetField ("Y");
76 if (f.FieldType.Equals (typeof (Int32)))
77 return 0;
78 return 1;
82 public static int test_0_load_reference_bytes ()
84 // Check that loading a reference assembly from a byte array for execution is an error
85 byte[] bs = File.ReadAllBytes ("./TestingReferenceAssembly.dll");
86 try {
87 var a = Assembly.Load (bs);
88 } catch (BadImageFormatException) {
89 return 0;
90 } catch (FileNotFoundException exn) {
91 Console.Error.WriteLine ("incorrect exn was {0}", exn);
92 return 2;
94 return 1;
97 public static int test_0_reflection_load_reference_bytes ()
99 // Check that loading a reference assembly from a byte
100 // array for reflection only is okay.
101 byte[] bs = File.ReadAllBytes ("./TestingReferenceAssembly.dll");
102 var a = Assembly.ReflectionOnlyLoad (bs);
103 var t = a.GetType ("X");
104 var f = t.GetField ("Y");
105 if (f.FieldType.Equals (typeof (Int32)))
106 return 0;
107 return 1;