New test.
[mono.git] / mcs / tests / test-34.cs
1 //
2 // This test tests both how arguments are selected in the presence
3 // of ref/out modifiers and the params arguments.
4 //
5 using System;
6
7 public struct FancyInt {
8         public int value;
9
10         public FancyInt (int v)
11         {
12                 value = v;
13         }
14         
15 }
16
17 public class Blah {
18         static int got;
19         
20         public static void Foo (ref int i, ref int j)
21         {
22                 got = 1;
23         }
24
25         public static int Bar (int j, params int [] args)
26         {
27                 got = 2;
28                 int total = 0;
29                 
30                 foreach (int i in args){
31                         Console.WriteLine ("My argument: " + i);
32                         total += i;
33                 }
34
35                 return total;
36         }
37
38         public static void Foo (int i, int j)
39         {
40                 got = 3;
41         }
42
43         static void In (ref int a)
44         {
45                 a++;
46         }
47
48         static void Out (ref int a)
49         {
50                 In (ref a);
51         }
52
53         static int AddArray (params int [] valores)
54         {
55                 int total = 0;
56                 
57                 for (int i = 0; i < valores.Length; i++)
58                         total += valores [i];
59
60                 return total;
61         }
62
63         static int AddFancy (params FancyInt [] vals)
64         {
65                 int total = 0;
66                 
67                 for (int i = 0; i < vals.Length; i++)
68                         total += vals [i].value;
69
70                 return total;
71         }
72         
73         
74         public static int Main ()
75         {
76                 int i = 1;
77                 int j = 2;
78
79                 int [] arr = new int [2] { 0, 1 };
80
81                 Foo (i, j);
82                 if (got != 3)
83                         return 1;
84                 
85                 Foo (ref i, ref j);
86                 if (got != 1)
87                         return 2;
88
89                 if (Bar (i, j, 5, 4, 3, 3, 2) != 19)
90                         return 4;
91
92                 //if (Bar (1, arr) != 1)
93                 //      return 5;
94                 
95                 if (got != 2)
96                         return 3;
97
98                 int k = 10;
99
100                 Out (ref k);
101                 if (k != 11)
102                         return 10;
103
104                 int [] arr2 = new int [2] {1, 2};
105
106                 if (AddArray (arr2) != 3)
107                         return 11;
108
109                 FancyInt f_one = new FancyInt (1);
110                 FancyInt f_two = new FancyInt (2);
111
112                 if (AddFancy (f_one) != 1)
113                         return 12;
114
115                 if (AddFancy (f_one, f_two) != 3)
116                         return 13;
117
118                 Console.WriteLine ("Test passes");
119                 return  0;
120         }
121 }