Merge pull request #2740 from lambdageek/dev/monoerror-reflection-icalls1
[mono.git] / mono / tests / assembly-load-remap.cs
1 using System;
2 using System.IO;
3 using System.Reflection;
4
5 public class Tests
6 {
7         public static void Main (string[] args)
8         {
9                 var ver40 = new Version (4, 0, 0, 0);
10                 var ver140 = new Version (14, 0, 0, 0);
11                 var util20 = Assembly.ReflectionOnlyLoad ("Microsoft.Build.Utilities, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
12                 var util35 = Assembly.ReflectionOnlyLoad ("Microsoft.Build.Utilities.v3.5, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
13                 var task20 = Assembly.ReflectionOnlyLoad ("Microsoft.Build.Tasks, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
14                 var task35 = Assembly.ReflectionOnlyLoad ("Microsoft.Build.Tasks.v3.5, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
15                 var engn20 = Assembly.ReflectionOnlyLoad ("Microsoft.Build.Engine, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
16                 var engn35 = Assembly.ReflectionOnlyLoad ("Microsoft.Build.Engine, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
17                 var frwk20 = Assembly.ReflectionOnlyLoad ("Microsoft.Build.Framework, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
18                 var frwk35 = Assembly.ReflectionOnlyLoad ("Microsoft.Build.Framework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
19
20                 // when run as part of the test suite, we need to register the xbuild 14.0 path or v14 assembly lookup will fail 
21                 if (!String.IsNullOrEmpty (Environment.GetEnvironmentVariable ("MONO_PATH"))) {
22                         var p = Path.Combine (new DirectoryInfo (Environment.GetEnvironmentVariable ("MONO_PATH")).Parent.FullName, "xbuild_14");
23                         Console.WriteLine("Adding private bin path " + p);
24                         AppDomain.CurrentDomain.AppendPrivatePath (p);
25                 }
26
27                 var engn140 = Assembly.ReflectionOnlyLoad ("Microsoft.Build.Engine, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
28                 var frwk140 = Assembly.ReflectionOnlyLoad ("Microsoft.Build.Framework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
29
30                 if (util20 == null)
31                         throw new Exception ("#1 assembly couldn't be loaded.");
32
33                 if (util35 == null)
34                         throw new Exception ("#2 assembly couldn't be loaded.");
35
36                 if (util20.GetName ().Version != ver40)
37                         throw new Exception ("#3 expected remap to v4.0.0.0, but got " + util20);
38
39                 if (util35.GetName ().Version != ver40)
40                         throw new Exception ("#4 expected remap to v4.0.0.0, but got " + util35);
41
42                 if (task20 == null)
43                         throw new Exception ("#5 assembly couldn't be loaded.");
44
45                 if (task35 == null)
46                         throw new Exception ("#6 assembly couldn't be loaded.");
47
48                 if (task20.GetName ().Version != ver40)
49                         throw new Exception ("#7 expected remap to v4.0.0.0, but got " + task20);
50
51                 if (task35.GetName ().Version != ver40)
52                         throw new Exception ("#8 expected remap to v4.0.0.0, but got " + task35);
53
54                 if (engn20 == null)
55                         throw new Exception ("#9 assembly couldn't be loaded.");
56
57                 if (engn35 == null)
58                         throw new Exception ("#10 assembly couldn't be loaded.");
59
60                 if (engn140 == null)
61                         throw new Exception ("#11 assembly couldn't be loaded.");
62
63                 if (engn20.GetName ().Version != ver40)
64                         throw new Exception ("#12 expected remap to v4.0.0.0, but got " + engn20);
65
66                 if (engn35.GetName ().Version != ver40)
67                         throw new Exception ("#13 expected remap to v4.0.0.0, but got " + engn35);
68         
69                 if (engn140.GetName ().Version != ver140)
70                         throw new Exception ("#14 expected v14.0.0.0, but got " + engn140);
71
72                 if (frwk20 == null)
73                         throw new Exception ("#15 assembly couldn't be loaded.");
74
75                 if (frwk35 == null)
76                         throw new Exception ("#16 assembly couldn't be loaded.");
77
78                 if (frwk140 == null)
79                         throw new Exception ("#17 assembly couldn't be loaded.");
80
81                 if (frwk20.GetName ().Version != ver40)
82                         throw new Exception ("#18 expected remap to v4.0.0.0, but got " + frwk20);
83
84                 if (frwk35.GetName ().Version != ver40)
85                         throw new Exception ("#19 expected remap to v4.0.0.0, but got " + frwk35);
86
87                 if (frwk140.GetName ().Version != ver140)
88                         throw new Exception ("#20 expected v14.0.0.0, but got " + frwk140);
89         }
90 }