New test.
[mono.git] / mcs / tests / test-141.cs
1 using System;
2
3 class X {
4         public static int Main()
5         {
6                 if (! Test1 ()) return 1;
7                 if (! Test2 ()) return 2;
8                 if (! Test3 ()) return 3;
9                 
10                 return 0;
11         }
12         
13         static bool Test1 ()
14         {
15                 byte num1 = 105;
16                 byte num2 = 150;
17
18                 // should generate OverflowException
19                 try {
20                         checked {
21                                 byte sum = (byte) (num1 - num2);
22                         }
23                         
24                         return false;
25                 } catch (OverflowException) {
26                         return true;
27                 }
28         }
29         
30         static bool Test2 ()
31         {
32                 long l = long.MinValue;
33                 
34                 // should generate OverflowException
35                 try {
36                         checked {
37                                 l = - l;
38                         }
39                         
40                         return false;
41                 } catch (OverflowException) {
42                         return true;
43                 }
44         }
45         
46         static bool Test3 ()
47         {
48                 int i = int.MinValue;
49                 
50                 // should generate OverflowException
51                 try {
52                         checked {
53                                 i = - i;
54                         }
55                         
56                         return false;
57                 } catch (OverflowException) {
58                         return true;
59                 }
60         }
61 }