Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / internalsvisibleto-runtimetest.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(@private: false);
27                 Console.WriteLine("Access internal class private ctor: OK");
28                 // Microsoft behaves this way
29             } catch (MemberAccessException) {
30                 Console.WriteLine("Access internal class private ctor: Fail");
31                 // FIXME: Mono behaves this way
32                 // failCount += 1;
33             }
34
35             try {
36                 var a = new CorrectCaseFriendAssembly.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                 var b = new CorrectCaseFriendAssembly.InternalClass(@public: 'a');
45                 Console.WriteLine("Access internal class public ctor: OK");
46                 b.InternalMethod();
47                 Console.WriteLine("Access friend internal method: OK");
48             } catch (MemberAccessException) {
49                 failCount += 1;
50                 Console.WriteLine("Access friend internal method with wrong case: Fail");
51             }
52
53             Console.WriteLine("-- Wrong case --");
54
55             try {
56                 var a = new WrongCaseFriendAssembly.InternalClass(@private: false);
57                 // Microsoft behaves this way
58                 Console.WriteLine("Access internal class private ctor: OK");
59             } catch (MemberAccessException) {
60                 // FIXME: Mono behaves this way
61                 Console.WriteLine("Access internal class private ctor: Fail");
62                 // failCount += 1;
63             }
64
65             try {
66                 var a = new WrongCaseFriendAssembly.InternalClass(@internal: 0);
67                 Console.WriteLine("Access internal class internal ctor: OK");
68             } catch (MemberAccessException) {
69                 failCount += 1;
70                 Console.WriteLine("Access friend internal ctor: Fail");
71             }
72
73             try {
74                 var b = new WrongCaseFriendAssembly.InternalClass(@public: 'a');
75                 Console.WriteLine("Access internal class public ctor: OK");
76                 b.InternalMethod();
77                 Console.WriteLine("Access friend internal method: OK");
78             } catch (MemberAccessException) {
79                 failCount += 1;
80                 Console.WriteLine("Access friend internal method: Fail");
81             }
82
83             try {
84                 // Surprisingly this works in the Windows CLR, even though it seems like it shouldn't
85                 WrongCaseFriendAssembly.InternalClass.PrivateStaticMethod();
86                 Console.WriteLine("Access friend private static method: OK");
87             } catch (MemberAccessException) {
88                 Console.WriteLine("Access friend private static method: Fail");
89                 failCount += 1;
90             }
91
92             try {
93                 WrongCaseFriendAssembly.InternalClass.InternalStaticMethod();
94                 Console.WriteLine("Access friend internal static method: OK");
95             } catch (MemberAccessException) {
96                 failCount += 1;
97                 Console.WriteLine("Access friend internal static method: Fail");
98             }
99
100             try {
101                 WrongCaseFriendAssembly.PublicClass.InternalStaticMethod();
102                 Console.WriteLine("Access public internal static method: OK");
103             } catch (MemberAccessException) {
104                 failCount += 1;
105                 Console.WriteLine("Access public internal static method: Fail");
106             }
107
108             if (System.Diagnostics.Debugger.IsAttached)
109                 Console.ReadLine();
110
111             Console.WriteLine("Incorrect results: {0}", failCount);
112             Environment.ExitCode = failCount;
113         }
114     }
115 }