Merge pull request #5675 from mono/glib-debug-symbols
[mono.git] / mcs / tests / gtest-142.cs
1 using System;
2
3 public static class Assert
4 {
5         public static int Errors {
6                 get { return errors; }
7         }
8
9         static int errors = 0;
10
11         static void Error (string method, string text)
12         {
13                 Console.WriteLine ("Assert failed: {0} ({1})", method, text);
14                 errors++;
15         }
16
17         public static void IsTrue (string text, bool b)
18         {
19                 if (!b)
20                         Error ("IsTrue", text);
21         }
22
23         public static void IsFalse (string text, bool b)
24         {
25                 if (b)
26                         Error ("IsFalse", text);
27         }
28
29         public static void IsNull<T> (string text, Nullable<T> nullable)
30                 where T : struct
31         {
32                 if (nullable.HasValue)
33                         Error ("IsNull", text);
34         }
35
36         public static void IsNotNull<T> (string text, Nullable<T> nullable)
37                 where T : struct
38         {
39                 if (!nullable.HasValue)
40                         Error ("IsNotNull", text);
41         }
42
43         public static void IsTrue (string text, Nullable<bool> b)
44         {
45                 if (!b.HasValue || !b.Value)
46                         Error ("IsTrue", text);
47         }
48
49         public static void IsFalse (string text, Nullable<bool> b)
50         {
51                 if (!b.HasValue || b.Value)
52                         Error ("IsFalse", text);
53         }
54 }
55
56 class X
57 {
58         public static int Main ()
59         {
60                 bool? a = null, b = false, c = true;
61                 bool? d = null, e = false, f = true;
62
63                 Assert.IsNull ("a", a);
64                 Assert.IsFalse ("b", b);
65                 Assert.IsTrue ("c", c);
66                 Assert.IsTrue ("a == d", a == d);
67                 Assert.IsTrue ("b == e", b == e);
68                 Assert.IsTrue ("c == f", c == f);
69
70                 Assert.IsFalse ("a != d", a != d);
71                 Assert.IsFalse ("a == b", a == b);
72                 Assert.IsTrue ("a != b", a != b);
73
74                 Assert.IsNull ("d & a", d & a);
75                 Assert.IsFalse ("d & b", d & b);
76                 Assert.IsNull ("d & c", d & c);
77                 Assert.IsFalse ("e & a", e & a);
78                 Assert.IsFalse ("e & b", e & b);
79                 Assert.IsFalse ("e & c", e & c);
80                 Assert.IsNull ("f & a", f & a);
81                 Assert.IsFalse ("f & b", f & b);
82                 Assert.IsTrue ("f & c", f & c);
83
84                 Assert.IsNull ("d | a", d | a);
85                 Assert.IsNull ("d | b", d | b);
86                 Assert.IsTrue ("d | c", d | c);
87                 Assert.IsNull ("e | a", e | a);
88                 Assert.IsFalse ("e | b", e | b);
89                 Assert.IsTrue ("e | c", e | c);
90                 Assert.IsTrue ("f | a", f | a);
91                 Assert.IsTrue ("f | b", f | b);
92                 Assert.IsTrue ("f | c", f | c);
93
94                 Assert.IsNull ("d ^ a", d ^ a);
95                 Assert.IsNull ("d ^ b", d ^ b);
96                 Assert.IsNull ("d ^ c", d ^ c);
97                 Assert.IsNull ("e ^ a", e ^ a);
98                 Assert.IsFalse ("e ^ b", e ^ b);
99                 Assert.IsTrue ("e ^ c", e ^ c);
100                 Assert.IsNull ("f ^ a", f ^ a);
101                 Assert.IsTrue ("f ^ b", f ^ b);
102                 Assert.IsFalse ("f ^ c", f ^ c);
103                 
104                 int? g = 3, h = null, i = 3, j = null;
105
106                 Assert.IsFalse ("g == null", g == null);
107                 Assert.IsTrue ("g != null", g != null);
108                 Assert.IsTrue ("h == null", h == null);
109                 Assert.IsFalse ("h != null", h != null);
110
111                 Assert.IsTrue ("g == i", g == i);
112                 Assert.IsFalse ("g != i", g != i);
113                 Assert.IsFalse ("g == j", g == j);
114                 Assert.IsTrue ("g != j", g != j);
115                 Assert.IsFalse ("h == i", h == i);
116                 Assert.IsTrue ("h != i", h != i);
117                 Assert.IsTrue ("h == j", h == j);
118                 Assert.IsFalse ("h != j", h != j);
119
120                 Console.WriteLine ("{0} errors.", Assert.Errors);
121                 return Assert.Errors;
122         }
123 }