[HttpConnection] Bug fix: HttpListener's "IgnoreWriteExceptions" property value is...
[mono.git] / mono / tests / delegate7.cs
1 using System;
2 using System.Runtime.InteropServices;
3
4 class Tests {
5         delegate void SimpleDelegate ();
6
7         static void F1 () {
8                 v += 1;
9                 Console.WriteLine ("Test.F1");
10         }
11         static void F2 () {
12                 v += 2;
13                 Console.WriteLine ("Test.F2");
14         }
15         static void F4 () {
16                 v += 4;
17                 Console.WriteLine ("Test.F4");
18         }
19
20         public static int Main () {
21                 return TestDriver.RunTests (typeof (Tests));
22         }
23
24         static int v = 0;
25         static bool check_is_expected_v (SimpleDelegate d, int expected_v)
26         {
27                 v = 0;
28                 d ();
29                 return v == expected_v;
30         }
31
32         static public int test_0_test () {
33                 SimpleDelegate d1 = new SimpleDelegate (F1);
34                 SimpleDelegate d2 = new SimpleDelegate (F2);
35                 SimpleDelegate d4 = new SimpleDelegate (F4);
36
37                 if (d1 - d1 != null)
38                         return 1;
39                 if (!check_is_expected_v (d1 - d2, 1))
40                         return 2;
41                 if (!check_is_expected_v (d1 - d4, 1))
42                         return 3;
43
44                 if (!check_is_expected_v (d2 - d1, 2))
45                         return 4;
46                 if (d2 - d2 != null)
47                         return 5;
48                 if (!check_is_expected_v (d2 - d4, 2))
49                         return 6;
50
51                 if (!check_is_expected_v (d4 - d1, 4))
52                         return 7;
53                 if (!check_is_expected_v (d4 - d2, 4))
54                         return 8;
55                 if (d4 - d4 != null)
56                         return 9;
57
58                 SimpleDelegate d12 = d1 + d2;
59                 SimpleDelegate d14 = d1 + d4;
60                 SimpleDelegate d24 = d2 + d4;
61
62                 if (!check_is_expected_v (d12 - d1, 2))
63                         return 11;
64                 if (!check_is_expected_v (d12 - d2, 1))
65                         return 12;
66                 if (!check_is_expected_v (d12 - d4, 3))
67                         return 13;
68
69                 if (!check_is_expected_v (d14 - d1, 4))
70                         return 14;
71                 if (!check_is_expected_v (d14 - d2, 5))
72                         return 15;
73                 if (!check_is_expected_v (d14 - d4, 1))
74                         return 16;
75
76                 if (!check_is_expected_v (d14 - d1, 4))
77                         return 17;
78                 if (!check_is_expected_v (d14 - d2, 5))
79                         return 18;
80                 if (!check_is_expected_v (d14 - d4, 1))
81                         return 19;
82
83                 if (d12 - d12 != null)
84                         return 21;
85                 if (!check_is_expected_v (d12 - d14, 2))
86                         return 22;
87                 if (!check_is_expected_v (d12 - d24, 1))
88                         return 23;
89
90                 if (!check_is_expected_v (d14 - d12, 4))
91                         return 24;
92                 if (d14 - d14 != null)
93                         return 25;
94                 if (!check_is_expected_v (d14 - d24, 1))
95                         return 26;
96
97                 if (!check_is_expected_v (d24 - d12, 4))
98                         return 27;
99                 if (!check_is_expected_v (d24 - d14, 2))
100                         return 28;
101                 if (d24 - d24 != null)
102                         return 29;
103
104                 SimpleDelegate d124 = d1 + d2 + d4;
105
106                 if (!check_is_expected_v (d124 - d1, 6))
107                         return 31;
108                 if (!check_is_expected_v (d124 - d2, 5))
109                         return 32;
110                 if (!check_is_expected_v (d124 - d4, 3))
111                         return 33;
112
113                 if (!check_is_expected_v (d124 - d12, 4))
114                         return 34;
115                 if (!check_is_expected_v (d124 - d14, 2))
116                         return 35;
117                 if (!check_is_expected_v (d124 - d24, 1))
118                         return 36;
119
120                 if (d124 - d124 != null)
121                         return 37;
122
123                 return 0;
124         }
125
126         // Regression test for bug #50366
127         static public int test_0_delegate_equality () {
128                 if (new SimpleDelegate (F1) == new SimpleDelegate (F1))
129                         return 0;
130                 else
131                         return 1;
132         }
133 }