Wed Aug 20 19:02:22 CEST 2003 Paolo Molaro <lupus@ximian.com>
[mono.git] / mono / mini / basic-calls.cs
1 using System;
2 using System.Reflection;
3
4 /*
5  * Regression tests for the mono JIT.
6  *
7  * Each test needs to be of the form:
8  *
9  * static int test_<result>_<name> ();
10  *
11  * where <result> is an integer (the value that needs to be returned by
12  * the method to make it pass.
13  * <name> is a user-displayed name used to identify the test.
14  *
15  * The tests can be driven in two ways:
16  * *) running the program directly: Main() uses reflection to find and invoke
17  *      the test methods (this is useful mostly to check that the tests are correct)
18  * *) with the --regression switch of the jit (this is the preferred way since
19  *      all the tests will be run with optimizations on and off)
20  *
21  * The reflection logic could be moved to a .dll since we need at least another
22  * regression test file written in IL code to have better control on how
23  * the IL code looks.
24  */
25
26 class Tests {
27
28         static int Main () {
29                 return TestDriver.RunTests (typeof (Tests));
30         }
31
32         static void dummy () {
33         }
34
35         static int test_0_return () {
36                 dummy ();
37                 return 0;
38         }
39
40         static int dummy1 () {
41                 return 1;
42         }
43
44         static int test_2_int_return () {
45                 int r = dummy1 ();
46                 if (r == 1)
47                         return 2;
48                 return 0;
49         }
50
51         static int add1 (int val) {
52                 return val + 1;
53         }
54
55         static int test_1_int_pass () {
56                 int r = add1 (5);
57                 if (r == 6)
58                         return 1;
59                 return 0;
60         }
61
62         static int add_many (int val, short t, byte b, int da) {
63                 return val + t + b + da;
64         }
65
66         static int test_1_int_pass_many () {
67                 byte b = 6;
68                 int r = add_many (5, 2, b, 1);
69                 if (r == 14)
70                         return 1;
71                 return 0;
72         }
73
74         unsafe static float GetFloat (byte *ptr) {
75                 return *(float*)ptr;
76         }
77
78         unsafe public static float GetFloat(float value)
79                 {
80                         return GetFloat((byte *)&value);
81                 }
82
83         /* bug #42134 */
84         static int test_2_inline_saved_arg_type () {
85                 float f = 100.0f;
86                 return GetFloat (f) == f? 2: 1;
87         }
88
89
90 }
91