2010-04-14 Jb Evain <jbevain@novell.com>
[mcs.git] / tests / test-46.cs
blob6a4aa000a0b3ec4c393326f76543f50904eb8e72
1 //
2 // This test probes the various explicit unboxing casts
3 //
4 using System;
6 class X {
7 static int cast_int (object o) { return (int) o; }
8 static uint cast_uint (object o) { return (uint) o; }
9 static short cast_short (object o) { return (short) o; }
10 static char cast_char (object o) { return (char) o; }
11 static ushort cast_ushort (object o) { return (ushort) o; }
12 static byte cast_byte (object o) { return (byte) o; }
13 static sbyte cast_sbyte (object o) { return (sbyte) o; }
14 static long cast_long (object o) { return (long) o; }
15 static ulong cast_ulong (object o) { return (ulong) o; }
16 static float cast_float (object o) { return (float) o; }
17 static double cast_double (object o) { return (double) o; }
18 static bool cast_bool (object o) { return (bool) o; }
20 static int Main ()
22 if (cast_int ((object) -1) != -1)
23 return 1;
24 if (cast_int ((object) 1) != 1)
25 return 2;
26 if (cast_int ((object) Int32.MaxValue) != Int32.MaxValue)
27 return 1;
28 if (cast_int ((object) Int32.MinValue) != Int32.MinValue)
29 return 2;
30 if (cast_int ((object) 0) != 0)
31 return 3;
33 if (cast_uint ((object) (uint)0) != 0)
34 return 4;
35 if (cast_uint ((object) (uint) 1) != 1)
36 return 5;
37 if (cast_uint ((object) (uint) UInt32.MaxValue) != UInt32.MaxValue)
38 return 6;
39 if (cast_uint ((object) (uint) UInt32.MinValue) != UInt32.MinValue)
40 return 7;
42 if (cast_ushort ((object) (ushort) 1) != 1)
43 return 8;
44 if (cast_ushort ((object) (ushort) UInt16.MaxValue) != UInt16.MaxValue)
45 return 9;
46 if (cast_ushort ((object) (ushort) UInt16.MinValue) != UInt16.MinValue)
47 return 10;
48 if (cast_ushort ((object) (ushort) 0) != 0)
49 return 11;
51 if (cast_short ((object) (short)-1) != -1)
52 return 12;
53 if (cast_short ((object) (short) 1) != 1)
54 return 13;
55 if (cast_short ((object) (short) Int16.MaxValue) != Int16.MaxValue)
56 return 14;
57 if (cast_short ((object) (short) Int16.MinValue) != Int16.MinValue)
58 return 15;
59 if (cast_short ((object) (short) 0) != 0)
60 return 16;
62 if (cast_byte ((object) (byte)1) != 1)
63 return 17;
64 if (cast_byte ((object) (byte) Byte.MaxValue) != Byte.MaxValue)
65 return 18;
66 if (cast_byte ((object) (byte) Byte.MinValue) != Byte.MinValue)
67 return 19;
68 if (cast_byte ((object) (byte) 0) != 0)
69 return 20;
71 if (cast_sbyte ((object) (sbyte) -1) != -1)
72 return 21;
73 if (cast_sbyte ((object) (sbyte) 1) != 1)
74 return 22;
75 if (cast_sbyte ((object) (sbyte) SByte.MaxValue) != SByte.MaxValue)
76 return 23;
77 if (cast_sbyte ((object) (sbyte)SByte.MinValue) != SByte.MinValue)
78 return 24;
79 if (cast_sbyte ((object) (sbyte) 0) != 0)
80 return 25;
83 if (cast_long ((object) (long) -1) != -1)
84 return 26;
85 if (cast_long ((object) (long) 1) != 1)
86 return 27;
87 if (cast_long ((object) (long) Int64.MaxValue) != Int64.MaxValue)
88 return 28;
89 if (cast_long ((object) (long) Int64.MinValue) != Int64.MinValue)
90 return 29;
91 if (cast_long ((object) (long) 0) != 0)
92 return 30;
94 if (cast_ulong ((object) (ulong) 0) != 0)
95 return 31;
96 if (cast_ulong ((object) (ulong) 1) != 1)
97 return 32;
98 if (cast_ulong ((object) (ulong) UInt64.MaxValue) != UInt64.MaxValue)
99 return 33;
100 if (cast_ulong ((object) (ulong) UInt64.MinValue) != UInt64.MinValue)
101 return 34;
103 if (cast_double ((object) (double) -1) != -1)
104 return 35;
105 if (cast_double ((object) (double) 1) != 1)
106 return 36;
107 if (cast_double ((object) (double) Double.MaxValue) != Double.MaxValue)
108 return 37;
109 if (cast_double ((object) (double) Double.MinValue) != Double.MinValue)
110 return 38;
111 if (cast_double ((object) (double) 0) != 0)
112 return 39;
114 if (cast_float ((object) (float) -1) != -1)
115 return 40;
116 if (cast_float ((object) (float) 1) != 1)
117 return 41;
118 if (cast_float ((object) (float)Single.MaxValue) != Single.MaxValue)
119 return 42;
120 if (cast_float ((object) (float) Single.MinValue) != Single.MinValue)
121 return 43;
122 if (cast_float ((object) (float) 0) != 0)
123 return 44;
125 return 0;