Add a test.
[mono.git] / mono / tests / dtest-app.cs
index 235ce87f0c768416eb8911817bab618c9cdf6465..fe6e4529495f9faea9b3dfa48bd0afcd64ee851b 100644 (file)
@@ -51,6 +51,7 @@ public struct AStruct {
        public int i;
        public string s;
        public byte k;
+       public IntPtr j;
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public int foo (int val) {
@@ -66,6 +67,16 @@ public struct AStruct {
        public int invoke_return_int () {
                return i;
        }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static int invoke_static () {
+               return 5;
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public IntPtr invoke_return_intptr () {
+               return j;
+       }
 }
 
 public class GClass<T> {
@@ -79,6 +90,13 @@ public class GClass<T> {
 
 public struct GStruct<T> {
        public T i;
+
+       public int j;
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public int invoke_return_int () {
+               return j;
+       }
 }
 
 public class Tests : TestsBase
@@ -98,6 +116,7 @@ public class Tests : TestsBase
        float field_float;
        double field_double;
        Thread field_class;
+       IntPtr field_intptr;
        static int static_i = 55;
        static string static_s = "A";
        public const int literal_i = 56;
@@ -112,7 +131,7 @@ public class Tests : TestsBase
 
 #pragma warning restore 0414
 
-       class NestedClass {
+       public class NestedClass {
        }
 
        public int IntProperty {
@@ -159,6 +178,10 @@ public class Tests : TestsBase
                        domains ();
                if (args.Length > 0 && args [0] == "ref-emit-test")
                        ref_emit ();
+               if (args.Length > 0 && args [0] == "frames-in-native")
+                       frames_in_native ();
+               if (args.Length >0 && args [0] == "invoke-single-threaded")
+                       new Tests ().invoke_single_threaded ();
                return 3;
        }
 
@@ -213,8 +236,13 @@ public class Tests : TestsBase
                ss1 ();
                ss2 ();
                ss3 ();
+               ss3_2 ();
                ss4 ();
                ss5 (new int [] { 1, 2, 3 }, new Func<int, bool> (is_even));
+               try {
+                       ss6 (true);
+               } catch {
+               }
        }
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
@@ -235,6 +263,15 @@ public class Tests : TestsBase
                return sum;
        }
 
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void ss3_2 () {
+               ss3_2_2 ();
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void ss3_2_2 () {
+       }
+
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public static int ss4 () {
                ss1 (); ss1 ();
@@ -248,6 +285,18 @@ public class Tests : TestsBase
                arr.Count (selector);
        }
 
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void ss6 (bool b) {
+               if (b) {
+                       ss7 ();
+                       throw new Exception ();
+               }
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void ss7 () {
+       }
+
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public static bool is_even (int i) {
                return i % 2 == 0;
@@ -287,7 +336,7 @@ public class Tests : TestsBase
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public static void objects () {
-               Tests t = new Tests () { field_i = 42, field_bool1 = true, field_bool2 = false, field_char = 'A', field_byte = 129, field_sbyte = -33, field_short = Int16.MaxValue - 5, field_ushort = UInt16.MaxValue - 5, field_long = Int64.MaxValue - 5, field_ulong = UInt64.MaxValue - 5, field_float = 3.14f, field_double = 3.14f, field_s = "S", base_field_i = 43, base_field_s = "T", field_enum = AnEnum.B, field_class = null };
+               Tests t = new Tests () { field_i = 42, field_bool1 = true, field_bool2 = false, field_char = 'A', field_byte = 129, field_sbyte = -33, field_short = Int16.MaxValue - 5, field_ushort = UInt16.MaxValue - 5, field_long = Int64.MaxValue - 5, field_ulong = UInt64.MaxValue - 5, field_float = 3.14f, field_double = 3.14f, field_s = "S", base_field_i = 43, base_field_s = "T", field_enum = AnEnum.B, field_class = null, field_intptr = new IntPtr (Int32.MaxValue - 5) };
                t.o1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
                o2 (new string [] { "BAR", "BAZ" }, new int[] { 42, 43 }, new int [,] { { 1, 2 }, { 3, 4 }}, (int[,])Array.CreateInstance (typeof (int), new int [] { 2, 2}, new int [] { 1, 3}), new int[] { 0 });
        }
@@ -405,7 +454,7 @@ public class Tests : TestsBase
                unsafe {
                        AStruct s = new AStruct () { i = 42, s = "S", k = 43 };
 
-                       ti2 (new string [] { "BAR", "BAZ" }, new int[] { 42, 43 }, new int [,] { { 1, 2 }, { 3, 4 }}, ref val, (int*)IntPtr.Zero, 5, s, new Tests (), new Tests2 (), new GClass <int> ());
+                       ti2 (new string [] { "BAR", "BAZ" }, new int[] { 42, 43 }, new int [,] { { 1, 2 }, { 3, 4 }}, ref val, (int*)IntPtr.Zero, 5, s, new Tests (), new Tests2 (), new GClass <int> (), AnEnum.B);
                }
        }
 
@@ -418,7 +467,7 @@ public class Tests : TestsBase
        }
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
-       public static unsafe string ti2 (string[] s2, int[] s3, int[,] s4, ref int ri, int* ptr, int i, AStruct s, Tests t, Tests2 t2, GClass<int> g) {
+       public static unsafe string ti2 (string[] s2, int[] s3, int[,] s4, ref int ri, int* ptr, int i, AStruct s, Tests t, Tests2 t2, GClass<int> g, AnEnum ae) {
                return s2 [0] + s3 [0] + s4 [0, 0];
        }
 
@@ -435,11 +484,11 @@ public class Tests : TestsBase
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public static void invoke () {
-               new Tests ().invoke1 (new Tests2 (), new AStruct () { i = 42 });
+               new Tests ().invoke1 (new Tests2 (), new AStruct () { i = 42, j = (IntPtr)43 }, new GStruct<int> { j = 42 });
        }
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
-       public void invoke1 (Tests2 t, AStruct s) {
+       public void invoke1 (Tests2 t, AStruct s, GStruct<int> g) {
                invoke2 ();
        }
 
@@ -447,6 +496,29 @@ public class Tests : TestsBase
        public void invoke2 () {
        }
 
+       int counter;
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public void invoke_single_threaded () {
+               // Spawn a thread incrementing a counter
+               bool finished = false;
+
+               new Thread (delegate () {
+                               while (!finished)
+                                       counter ++;
+               }).Start ();
+
+               Thread.Sleep (100);
+
+               invoke_single_threaded_2 ();
+
+               finished = true;
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public void invoke_single_threaded_2 () {
+       }
+
        public void invoke_return_void () {
        }
 
@@ -462,6 +534,13 @@ public class Tests : TestsBase
                return 42;
        }
 
+       public void invoke_type_load () {
+               new Class3 ();
+       }
+
+       class Class3 {
+       }
+
        public long invoke_pass_primitive (byte ub, sbyte sb, short ss, ushort us, int i, uint ui, long l, ulong ul, char c, bool b, float f, double d) {
                return ub + sb + ss + us + i + ui + l + (long)ul + (int)c + (b ? 1 : 0) + (int)f + (int)d;
        }
@@ -478,6 +557,9 @@ public class Tests : TestsBase
                return s;
        }
 
+       public static void invoke_static_return_void () {
+       }
+
        public static void invoke_throws () {
                throw new Exception ();
        }
@@ -496,6 +578,10 @@ public class Tests : TestsBase
                        throw new ArgumentException ();
                } catch (Exception) {
                }
+               try {
+                       throw new OverflowException ();
+               } catch (Exception) {
+               }
 
                object o = null;
                try {
@@ -577,6 +663,11 @@ public class Tests : TestsBase
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public static void ref_emit_call (string s) {
        }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void frames_in_native () {
+               Thread.Sleep (500);
+       }
 }
 
 public class CrossDomain : MarshalByRefObject