Merge pull request #4202 from marek-safar/compression
[mono-project.git] / mcs / tests / gtest-043.cs
blobaee576cab93b4ddc17e04ed5bef97e3178a7b51a
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.
6 using System;
8 public class Test<T>
10 public static int Count;
12 public void Foo ()
14 Count++;
17 public int GetCount ()
19 return Count;
23 class X
25 static int DoTheTest<T> ()
27 Test<T> test = new Test<T> ();
29 test.Foo ();
30 if (test.GetCount () != 1)
31 return 1;
32 if (Test<T>.Count != 1)
33 return 2;
35 test.Foo ();
36 if (test.GetCount () != 2)
37 return 3;
38 if (Test<T>.Count != 2)
39 return 4;
41 test.Foo ();
42 if (test.GetCount () != 3)
43 return 5;
44 if (Test<T>.Count != 3)
45 return 6;
47 return 0;
50 public static int Main ()
52 int result = DoTheTest<int> ();
53 if (result != 0)
54 return result;
56 result = DoTheTest<long> () + 10;
57 if (result != 10)
58 return result;
60 Test<int>.Count = 0;
61 ++Test<long>.Count;
63 result = DoTheTest<int> () + 20;
64 if (result != 20)
65 return result;
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;
77 return 0;