[test] Use FULL_AOT_RUNTIME instead of MONOTOUCH.
[mono.git] / mcs / class / System.Core / Test / System.Linq.Expressions / ExpressionTest_Call.cs
index e4cd69c59778a525e26c09bd89a2c4612a086061..4fca0b34f42e8dd18a75b517a811e6db74e4cc3a 100644 (file)
@@ -29,6 +29,7 @@
 
 using System;
 using System.Reflection;
+using System.Reflection.Emit;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq.Expressions;
@@ -87,11 +88,7 @@ namespace MonoTests.System.Linq.Expressions {
                }
 
                [Test]
-#if NET_4_0
                [ExpectedException (typeof (ArgumentException))]
-#else
-               [ExpectedException (typeof (ArgumentNullException))]
-#endif
                public void ArgInstanceNullForNonStaticMethod ()
                {
                        Expression.Call (null, typeof (object).GetMethod ("ToString"));
@@ -227,7 +224,6 @@ namespace MonoTests.System.Linq.Expressions {
                }
 
                [Test]
-               [Category ("NotWorkingInterpreter")]
                public void CallMethodOnStruct ()
                {
                        var param = Expression.Parameter (typeof (EineStrukt), "s");
@@ -243,6 +239,17 @@ namespace MonoTests.System.Linq.Expressions {
                        return 42;
                }
 
+               [Test]
+               public void CallMethodOnDateTime ()
+               {
+                       var left = Expression.Call (Expression.Constant (DateTime.Now), typeof(DateTime).GetMethod ("AddDays"), Expression.Constant (-5.0));
+                       var right = Expression.Constant (DateTime.Today.AddDays (1));
+                       var expr = Expression.GreaterThan (left, right);
+
+                       var eq = Expression.Lambda<Func<bool>> (expr).Compile ();
+                       Assert.IsFalse (eq ());
+               }
+
                [Test]
                [Category ("NotDotNet")] // http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=339351
                [ExpectedException (typeof (ArgumentException))]
@@ -264,7 +271,6 @@ namespace MonoTests.System.Linq.Expressions {
                }
 
                [Test]
-               [Category ("NotWorkingInterpreter")]
                public void CallStaticMethodWithRefParameter ()
                {
                        var p = Expression.Parameter (typeof (int), "i");
@@ -276,7 +282,6 @@ namespace MonoTests.System.Linq.Expressions {
                }
 
                [Test]
-               [Category ("NotWorkingInterpreter")]
                public void CallStaticMethodWithRefParameterAndOtherParameter ()
                {
                        var i = Expression.Parameter (typeof (int), "i");
@@ -288,22 +293,42 @@ namespace MonoTests.System.Linq.Expressions {
                        Assert.AreEqual ("foo42", lamda (42, "foo"));
                }
 
-               public static int Bang (Expression i)
+#if !FULL_AOT_RUNTIME
+               [Test]
+               public void CallDynamicMethod_ToString ()
                {
-                       return (int) (i as ConstantExpression).Value;
+                       // Regression test for #49686
+                       var m = new DynamicMethod ("intIntId", typeof (int), new Type [] { typeof (int) });
+                       var ilg = m.GetILGenerator ();
+                       ilg.Emit (OpCodes.Ldarg_0);
+                       ilg.Emit (OpCodes.Ret);
+
+                       var i = Expression.Parameter (typeof (int), "i");
+                       var e = Expression.Call (m, i);
+
+                       Assert.IsNotNull (e.ToString ());
                }
-#if !NET_4_0 // dlr bug 5875
+
                [Test]
-               public void CallMethodWithExpressionParameter ()
+               public void CallDynamicMethod_CompileInvoke ()
                {
-                       var call = Expression.Call (GetType ().GetMethod ("Bang"), Expression.Constant (42));
-                       Assert.AreEqual (ExpressionType.Quote, call.Arguments [0].NodeType);
+                       var m = new DynamicMethod ("intIntId", typeof (int), new Type [] { typeof (int) });
+                       var ilg = m.GetILGenerator ();
+                       ilg.Emit (OpCodes.Ldarg_0);
+                       ilg.Emit (OpCodes.Ret);
 
-                       var l = Expression.Lambda<Func<int>> (call).Compile ();
+                       var i = Expression.Parameter (typeof (int), "i");
+                       var e = Expression.Call (m, i);
 
-                       Assert.AreEqual (42, l ());
+                       var lambda = Expression.Lambda<Func<int, int>> (e, i).Compile ();
+                       Assert.AreEqual (42, lambda (42));
                }
 #endif
+
+               public static int Bang (Expression i)
+               {
+                       return (int) (i as ConstantExpression).Value;
+               }
                static bool fout_called = false;
 
                public static int FooOut (out int x)
@@ -313,7 +338,6 @@ namespace MonoTests.System.Linq.Expressions {
                }
 
                [Test]
-               [Category ("NotWorkingInterpreter")]
                public void Connect282729 ()
                {
                        // test from https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=282729
@@ -340,8 +364,6 @@ namespace MonoTests.System.Linq.Expressions {
                }
 
                [Test]
-               [Category ("NotWorking")]
-               [Category ("NotWorkingInterpreter")]
                public void Connect290278 ()
                {
                        // test from https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=290278
@@ -364,7 +386,6 @@ namespace MonoTests.System.Linq.Expressions {
                }
 
                [Test]
-               [Category ("NotWorkingInterpreter")]
                public void Connect297597 ()
                {
                        // test from https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=297597
@@ -382,6 +403,7 @@ namespace MonoTests.System.Linq.Expressions {
 
                [Test]
                [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=319190
+               [Category ("NotWorkingInterpreter")]
                public void Connect319190 ()
                {
                        var lambda = Expression.Lambda<Func<bool>> (
@@ -398,7 +420,6 @@ namespace MonoTests.System.Linq.Expressions {
                }
 
                [Test]
-               [Category ("NotWorkingInterpreter")]
                public void Connect282702 ()
                {
                        var lambda = Expression.Lambda<Func<Func<int>>> (
@@ -488,7 +509,6 @@ namespace MonoTests.System.Linq.Expressions {
                }
 
                [Test]
-               [Category ("NotWorkingInterpreter")]
                public void CallNullableGetValueOrDefault () // #568989
                {
                        var value = Expression.Parameter (typeof (int?), "value");