Merge pull request #4431 from vkargov/vk-leaking-points
[mono.git] / mcs / tests / test-682.cs
1 using System;
2
3 public class broken_cast
4 {
5         public static void report (string str)
6         {
7                 throw new Exception (str);
8         }
9
10         public static void conv_ovf_i (long val, bool shouldThrow)
11         {
12                 try {
13                         System.IntPtr x = (System.IntPtr) val;
14                         if (shouldThrow)
15                                 report (String.Format ("conv_ovf_i did not throw for {0} ", val));
16                 } catch (OverflowException exception) {
17                         if (!shouldThrow)
18                                 report (String.Format ("conv_ovf_i did throw for {0}", val));
19                 }
20         }
21
22         public static void conv_ovf_i_un (long val, bool shouldThrow)
23         {
24                 try {
25                         System.IntPtr x = (System.IntPtr) val;
26                         if (shouldThrow)
27                                 report (String.Format ("conv_ovf_i_un did not throw for {0} ", val));
28                 } catch (OverflowException exception) {
29                         if (!shouldThrow)
30                                 report (String.Format ("conv_ovf_i_un did throw for {0}", val));
31                 }
32         }
33
34         public static void conv_ovf_u (long val, bool shouldThrow)
35         {
36                 try {
37                         System.IntPtr x = (System.IntPtr) val;
38                         if (shouldThrow)
39                                 report (String.Format ("conv_ovf_u did not throw for {0} ", val));
40                 } catch (OverflowException exception) {
41                         if (!shouldThrow)
42                                 report (String.Format ("conv_ovf_u did throw for {0}", val));
43                 }
44         }
45
46         public static void conv_ovf_u_un (long val, bool shouldThrow)
47         {
48                 try {
49                         System.IntPtr x = (System.IntPtr) val;
50                         if (shouldThrow)
51                                 report (String.Format ("conv_ovf_u_un did not throw for {0} ", val));
52                 } catch (OverflowException exception) {
53                         if (!shouldThrow)
54                                 report (String.Format ("conv_ovf_u_un did throw for {0}", val));
55                 }
56         }
57
58         public static int Main ()
59         {
60                 long ok_number = 9;
61                 long negative = -1;
62                 long biggerThanI4 = int.MaxValue;
63                 ++biggerThanI4;
64                 long smallerThanI4 = int.MinValue;
65                 --smallerThanI4;
66                 long biggerThanU4 = uint.MaxValue;
67                 ++biggerThanU4;
68
69                 bool is32bits = IntPtr.Size == 4;
70                 int i = 1;
71
72                 try {
73                         conv_ovf_i (ok_number, false);
74                         ++i;
75                         conv_ovf_i (negative, false);
76 //                      ++i;
77 //                      conv_ovf_i (biggerThanI4, true && is32bits);
78 //                      ++i;
79 //                      conv_ovf_i (smallerThanI4, true && is32bits);
80 //                      ++i;
81 //                      conv_ovf_i (biggerThanU4, true && is32bits);
82
83                         ++i;
84                         conv_ovf_i_un (ok_number, false);
85                         ++i;
86                         conv_ovf_i_un (negative, false);
87                         ++i;
88 //                      conv_ovf_i_un (biggerThanI4, true && is32bits);
89 //                      ++i;
90 //                      conv_ovf_i_un (smallerThanI4, true && is32bits);
91 //                      ++i;
92 //                      conv_ovf_i_un (biggerThanU4, true && is32bits);
93
94                         ++i;
95                         conv_ovf_u (ok_number, false);
96                         ++i;
97                         conv_ovf_u (negative, false);
98 //                      ++i;
99 //                      conv_ovf_u (biggerThanI4, true && is32bits);
100 //                      ++i;
101 //                      conv_ovf_u (smallerThanI4, true && is32bits);
102 //                      ++i;
103 //                      conv_ovf_u (biggerThanU4, true && is32bits);
104
105                         ++i;
106                         conv_ovf_u_un (ok_number, false);
107                         ++i;
108                         conv_ovf_u_un (negative, false);
109 //                      ++i;
110 //                      conv_ovf_u_un (biggerThanI4, true && is32bits);
111 //                      ++i;
112 //                      conv_ovf_u_un (smallerThanI4, true && is32bits);
113 //                      ++i;
114 //                      conv_ovf_u_un (biggerThanU4, true && is32bits);
115
116                         return 0;
117                 } catch (Exception e) {
118                         Console.WriteLine (e);
119                         return i;
120                 }
121         }
122
123 }