Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / internalsvisibleto-compilertest.cs
1 using System;
2
3 #if SIGN2048
4 using System.Reflection;
5 [assembly: AssemblyDelaySign(true)]
6 [assembly: AssemblyKeyFile(@"internalsvisibleto-2048.snk")]
7 #endif
8
9 namespace InternalsVisibleTo {
10     class Program {
11         static void Main (string[] args) {
12             var failCount = 0;
13
14             Console.WriteLine("-- Correct case --");
15
16             try {
17                     var a = new CorrectCaseFriendAssembly.PublicClass ();
18                     a.InternalMethod ();
19                     Console.WriteLine ("Access friend internal method: OK");
20             } catch (MemberAccessException) {
21                     failCount += 1;
22                     Console.WriteLine ("Access friend internal method: Fail");
23             }
24
25             try {
26                 var a = new CorrectCaseFriendAssembly.InternalClass(@internal: 0);
27                 Console.WriteLine("Access internal class internal ctor: OK");
28             } catch (MemberAccessException) {
29                 failCount += 1;
30                 Console.WriteLine("Access friend internal ctor: Fail");
31             }
32
33             Console.WriteLine("-- Wrong case --");
34
35             try {
36                 var a = new WrongCaseFriendAssembly.InternalClass(@internal: 0);
37                 Console.WriteLine("Access internal class internal ctor: OK");
38             } catch (MemberAccessException) {
39                 failCount += 1;
40                 Console.WriteLine("Access friend internal ctor: Fail");
41             }
42
43             try {
44                 // This also works in the Windows CLR. Huh.
45                 WrongCaseFriendAssembly.InternalClass.PrivateStaticMethod();
46                 Console.WriteLine("Access friend private static method: OK");
47             } catch (MemberAccessException) {
48                 Console.WriteLine("Access friend private static method: Fail");
49                 failCount += 1;
50             }
51
52             try {
53                 WrongCaseFriendAssembly.InternalClass.InternalStaticMethod();
54                 Console.WriteLine("Access friend internal static method: OK");
55             } catch (MemberAccessException) {
56                 failCount += 1;
57                 Console.WriteLine("Access friend internal static method: Fail");
58             }
59
60             try {
61                 WrongCaseFriendAssembly.PublicClass.InternalStaticMethod();
62                 Console.WriteLine("Access public internal static method: OK");
63             } catch (MemberAccessException) {
64                 failCount += 1;
65                 Console.WriteLine("Access public internal static method: Fail");
66             }
67
68             if (System.Diagnostics.Debugger.IsAttached)
69                 Console.ReadLine();
70
71             Console.WriteLine("Incorrect results: {0}", failCount);
72             Environment.ExitCode = failCount;
73         }
74     }
75 }