Add more tests to compare our cast code
[mono.git] / mcs / tests / gen-cast-test.cs
1 using System;
2
3 class Stress {
4
5         static string [] types = {
6                 "int",   "uint",
7                 "short", "ushort",
8                 "long",  "ulong",
9                 "sbyte", "byte",
10                 "char" };
11         
12
13         static void w (string s)
14         {
15                 Console.Write (s);
16         }
17
18         static void wl (string s)
19         {
20                 Console.WriteLine (s);
21         }
22         
23         static void generate_receptors ()
24         {
25                 foreach (string t in types){
26                         w ("\tstatic void receive_" + t + " (" + t + " a)\n\t{\n");
27                         w ("\t\tConsole.Write (\"        \");\n");
28                         w ("\t\tConsole.WriteLine (a);\n");
29                         w ("\t}\n\n");
30                 }
31                 
32         }
33
34         static void var (string type, string name, string init)
35         {
36                 w ("\t\t" + type + " " + name + " = (" + type + ") " + init + ";\n");
37         }
38
39         static void call (string type, string name)
40         {
41                 w ("\t\treceive_" + type + " (unchecked ((" + type + ") " + name + "));\n");
42         }
43         
44         static void generate_emision ()
45         {
46                 foreach (string type in types){
47                         w ("\tstatic void probe_" + type + "()\n\t{\n");
48                         var (type, "zero", "0");
49                         var (type, "min", type + ".MinValue");
50                         var (type, "max", type + ".MaxValue");
51                         wl ("");
52
53                         wl ("\t\tConsole.WriteLine (\"Testing: " + type + "\");\n");
54                         foreach (string t in types){
55                                 wl ("\t\tConsole.WriteLine (\"   arg: " + t + "\");\n");
56                                 call (t, "zero");
57                                 call (t, "min");
58                                 call (t, "max");
59                         }
60                         
61                         w ("\t}\n\n");
62                 }
63         }
64
65         static void generate_main ()
66         {
67                 wl ("\tstatic void Main ()\n\t{");
68
69                 foreach (string t in types){
70                         w ("\t\tprobe_" + t + " ();\n");
71                 }
72                 wl ("\t}");
73         }
74         
75         static void Main ()
76         {
77                 wl ("using System;\nclass Test {\n");
78
79                 generate_receptors ();
80                 generate_emision ();
81
82                 generate_main ();
83                                
84                 wl ("}\n");
85         }
86 }