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