dlr bug
[mcs.git] / tests / test-682.cs
blob03b59bb4740858814838c289a97a6af50a773c59
1 using System;
3 public class broken_cast
5 public static void report (string str)
7 throw new Exception (str);
10 public static void conv_ovf_i (long val, bool shouldThrow)
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));
22 public static void conv_ovf_i_un (long val, bool shouldThrow)
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));
34 public static void conv_ovf_u (long val, bool shouldThrow)
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));
46 public static void conv_ovf_u_un (long val, bool shouldThrow)
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));
58 public static int Main ()
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;
69 bool is32bits = IntPtr.Size == 4;
70 int i = 1;
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);
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);
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);
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);
116 return 0;
117 } catch (Exception e) {
118 Console.WriteLine (e);
119 return i;