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