do not check order sequence if option /order was not used
[mono.git] / mcs / tests / gtest-043.cs
1 // Static fields in generic types: this is a runtime/JIT-only test
2 //
3 // We need to make sure that we're instantiating each closed generic
4 // type (ie. "Test<int>") only once.
5
6 using System;
7
8 public class Test<T>
9 {
10         public static int Count;
11
12         public void Foo ()
13         {
14                 Count++;
15         }
16
17         public int GetCount ()
18         {
19                 return Count;
20         }
21 }
22
23 class X
24 {
25         static int DoTheTest<T> ()
26         {
27                 Test<T> test = new Test<T> ();
28
29                 test.Foo ();
30                 if (test.GetCount () != 1)
31                         return 1;
32                 if (Test<T>.Count != 1)
33                         return 2;
34
35                 test.Foo ();
36                 if (test.GetCount () != 2)
37                         return 3;
38                 if (Test<T>.Count != 2)
39                         return 4;
40
41                 test.Foo ();
42                 if (test.GetCount () != 3)
43                         return 5;
44                 if (Test<T>.Count != 3)
45                         return 6;
46
47                 return 0;
48         }
49
50         static int Main ()
51         {
52                 int result = DoTheTest<int> ();
53                 if (result != 0)
54                         return result;
55
56                 result = DoTheTest<long> () + 10;
57                 if (result != 10)
58                         return result;
59
60                 Test<int>.Count = 0;
61                 ++Test<long>.Count;
62
63                 result = DoTheTest<int> () + 20;
64                 if (result != 20)
65                         return result;
66
67                 if (Test<int>.Count != 3)
68                         return 31;
69                 if (Test<long>.Count != 4)
70                         return 32;
71                 Test<float>.Count = 5;
72                 if (Test<int>.Count != 3)
73                         return 33;
74                 if (Test<long>.Count != 4)
75                         return 34;
76
77                 return 0;
78         }
79 }