[netcore] Ongoing work. (#13391)
[mono-project.git] / mono / tests / delegate7.cs
blobdd3a2a3ea27a4cbebd7ccb25cf428109d8afd7ea
1 using System;
2 using System.Runtime.InteropServices;
4 class Tests {
5 delegate void SimpleDelegate ();
7 static void F1 () {
8 v += 1;
9 Console.WriteLine ("Test.F1");
11 static void F2 () {
12 v += 2;
13 Console.WriteLine ("Test.F2");
15 static void F4 () {
16 v += 4;
17 Console.WriteLine ("Test.F4");
19 static void F8 () {
20 v += 8;
21 Console.WriteLine ("Test.F8");
24 public static int Main () {
25 return TestDriver.RunTests (typeof (Tests));
28 static int v = 0;
29 static bool check_is_expected_v (SimpleDelegate d, int expected_v)
31 v = 0;
32 d ();
33 return v == expected_v;
36 static public int test_0_test () {
37 SimpleDelegate d1 = new SimpleDelegate (F1);
38 SimpleDelegate d2 = new SimpleDelegate (F2);
39 SimpleDelegate d4 = new SimpleDelegate (F4);
40 SimpleDelegate d8 = new SimpleDelegate (F8);
42 if (d1 - d1 != null)
43 return 1;
44 if (!check_is_expected_v (d1 - d2, 1))
45 return 2;
46 if (!check_is_expected_v (d1 - d4, 1))
47 return 3;
49 if (!check_is_expected_v (d2 - d1, 2))
50 return 4;
51 if (d2 - d2 != null)
52 return 5;
53 if (!check_is_expected_v (d2 - d4, 2))
54 return 6;
56 if (!check_is_expected_v (d4 - d1, 4))
57 return 7;
58 if (!check_is_expected_v (d4 - d2, 4))
59 return 8;
60 if (d4 - d4 != null)
61 return 9;
63 SimpleDelegate d12 = d1 + d2;
64 SimpleDelegate d14 = d1 + d4;
65 SimpleDelegate d24 = d2 + d4;
67 if (!check_is_expected_v (d12 - d1, 2))
68 return 11;
69 if (!check_is_expected_v (d12 - d2, 1))
70 return 12;
71 if (!check_is_expected_v (d12 - d4, 3))
72 return 13;
74 if (!check_is_expected_v (d14 - d1, 4))
75 return 14;
76 if (!check_is_expected_v (d14 - d2, 5))
77 return 15;
78 if (!check_is_expected_v (d14 - d4, 1))
79 return 16;
81 if (!check_is_expected_v (d14 - d1, 4))
82 return 17;
83 if (!check_is_expected_v (d14 - d2, 5))
84 return 18;
85 if (!check_is_expected_v (d14 - d4, 1))
86 return 19;
88 if (d12 - d12 != null)
89 return 21;
90 if (!check_is_expected_v (d12 - d14, 3))
91 return 22;
92 if (!check_is_expected_v (d12 - d24, 3))
93 return 23;
95 if (!check_is_expected_v (d14 - d12, 5))
96 return 24;
97 if (d14 - d14 != null)
98 return 25;
99 if (!check_is_expected_v (d14 - d24, 5))
100 return 26;
102 if (!check_is_expected_v (d24 - d12, 6))
103 return 27;
104 if (!check_is_expected_v (d24 - d14, 6))
105 return 28;
106 if (d24 - d24 != null)
107 return 29;
109 SimpleDelegate d124 = d1 + d2 + d4;
111 if (!check_is_expected_v (d124 - d1, 6))
112 return 31;
113 if (!check_is_expected_v (d124 - d2, 5))
114 return 32;
115 if (!check_is_expected_v (d124 - d4, 3))
116 return 33;
118 if (!check_is_expected_v (d124 - d12, 4))
119 return 34;
120 if (!check_is_expected_v (d124 - d14, 7))
121 return 35;
122 if (!check_is_expected_v (d124 - d24, 1))
123 return 36;
125 if (d124 - d124 != null)
126 return 37;
128 SimpleDelegate d1248 = d1 + d2 + d4 + d8;
130 if (!check_is_expected_v (d1248 - (d1 + d2), 12))
131 return 41;
132 if (!check_is_expected_v (d1248 - (d1 + d4), 15))
133 return 42;
134 if (!check_is_expected_v (d1248 - (d1 + d8), 15))
135 return 43;
136 if (!check_is_expected_v (d1248 - (d2 + d4), 9))
137 return 44;
138 if (!check_is_expected_v (d1248 - (d2 + d8), 15))
139 return 45;
140 if (!check_is_expected_v (d1248 - (d4 + d8), 3))
141 return 46;
143 if (!check_is_expected_v (d1248 - (d1 + d2 + d4), 8))
144 return 51;
145 if (!check_is_expected_v (d1248 - (d1 + d2 + d8), 15))
146 return 52;
147 if (!check_is_expected_v (d1248 - (d1 + d4 + d8), 15))
148 return 53;
149 if (!check_is_expected_v (d1248 - (d2 + d4 + d8), 1))
150 return 54;
151 if (!check_is_expected_v (d1248 - (d2 + d4 + d8), 1))
152 return 54;
154 if (d1248 - d1248 != null)
155 return 55;
157 return 0;
160 // Regression test for bug #50366
161 static public int test_0_delegate_equality () {
162 if (new SimpleDelegate (F1) == new SimpleDelegate (F1))
163 return 0;
164 else
165 return 1;