From 174575154c26a5918d89cd9e0156bd87bf89cc32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Bourbonnais?= Date: Wed, 6 Jan 2021 13:33:48 -0500 Subject: [PATCH] Add more more tests for in, out and ref parameters --- src/domain_tests/TestRunner.cs | 204 ++++++++++++++++++ src/domain_tests/test_domain_reload.py | 12 ++ .../StateSerialization/MaybeMethodBase.cs | 4 +- 3 files changed, 218 insertions(+), 2 deletions(-) diff --git a/src/domain_tests/TestRunner.cs b/src/domain_tests/TestRunner.cs index 924b622c6..a21297829 100644 --- a/src/domain_tests/TestRunner.cs +++ b/src/domain_tests/TestRunner.cs @@ -843,6 +843,210 @@ raise AssertionError('failed to raise') assert foo is not bar ", }, + + new TestCase + { + Name = "ref_to_out_param", + DotNetBefore = @" + namespace TestNamespace + { + + [System.Serializable] + public class Data + { + public int num = -1; + } + + [System.Serializable] + public class Cls + { + public static void MyFn (ref Data a) + { + a.num = 7; + } + } + }", + DotNetAfter = @" + namespace TestNamespace + { + + [System.Serializable] + public class Data + { + public int num = -1; + } + + [System.Serializable] + public class Cls + { + public static void MyFn (out Data a) + { + a = new Data(); + a.num = 9001; + } + } + }", + PythonCode = @" +import clr +import sys +clr.AddReference('DomainTests') +import TestNamespace +import System + +def before_reload(): + + foo = TestNamespace.Data() + bar = TestNamespace.Cls.MyFn(foo) + # foo should have changed + assert foo.num == 7 + assert bar.num == 7 + + +def after_reload(): + + foo = TestNamespace.Data() + bar = TestNamespace.Cls.MyFn(foo) + assert bar.num == 9001 + # foo shouldn't have changed. + assert foo.num == -1 + # this should work too + baz = TestNamespace.Cls.MyFn(None) + assert baz.num == 9001 + ", + }, + new TestCase + { + Name = "ref_to_in_param", + DotNetBefore = @" + namespace TestNamespace + { + + [System.Serializable] + public class Data + { + public int num = -1; + } + + [System.Serializable] + public class Cls + { + public static void MyFn (ref Data a) + { + a.num = 7; + System.Console.Write(""Method with ref parameter: ""); + System.Console.WriteLine(a.num); + } + } + }", + DotNetAfter = @" + namespace TestNamespace + { + [System.Serializable] + public class Data + { + public int num = -1; + } + + [System.Serializable] + public class Cls + { + public static void MyFn (Data a) + { + System.Console.Write(""Method with in parameter: ""); + System.Console.WriteLine(a.num); + } + } + }", + PythonCode = @" +import clr +import sys +clr.AddReference('DomainTests') +import TestNamespace +import System + +def before_reload(): + + foo = TestNamespace.Data() + bar = TestNamespace.Cls.MyFn(foo) + # foo should have changed + assert foo.num == 7 + assert bar.num == 7 + +def after_reload(): + + foo = TestNamespace.Data() + TestNamespace.Cls.MyFn(foo) + # foo should not have changed + assert foo.num == TestNamespace.Data().num + + ", + }, + new TestCase + { + Name = "in_to_ref_param", + DotNetBefore = @" + namespace TestNamespace + { + [System.Serializable] + public class Data + { + public int num = -1; + } + + [System.Serializable] + public class Cls + { + public static void MyFn (Data a) + { + System.Console.Write(""Method with in parameter: ""); + System.Console.WriteLine(a.num); + } + } + }", + DotNetAfter = @" + namespace TestNamespace + { + + [System.Serializable] + public class Data + { + public int num = -1; + } + + [System.Serializable] + public class Cls + { + public static void MyFn (ref Data a) + { + a.num = 7; + System.Console.Write(""Method with ref parameter: ""); + System.Console.WriteLine(a.num); + } + } + }", + PythonCode = @" +import clr +import sys +clr.AddReference('DomainTests') +import TestNamespace +import System + +def before_reload(): + + foo = TestNamespace.Data() + TestNamespace.Cls.MyFn(foo) + # foo should not have changed + assert foo.num == TestNamespace.Data().num + +def after_reload(): + + foo = TestNamespace.Data() + bar = TestNamespace.Cls.MyFn(foo) + # foo should have changed + assert foo.num == 7 + assert bar.num == 7 + ", + }, new TestCase { Name = "nested_type", diff --git a/src/domain_tests/test_domain_reload.py b/src/domain_tests/test_domain_reload.py index 2840cdd58..e24eb6976 100644 --- a/src/domain_tests/test_domain_reload.py +++ b/src/domain_tests/test_domain_reload.py @@ -83,6 +83,18 @@ def test_construct_removed_class(): def test_out_to_ref_param(): _run_test("out_to_ref_param") +@pytest.mark.skipif(platform.system() == 'Darwin', reason='FIXME: macos can\'t find the python library') +def test_ref_to_out_param(): + _run_test("ref_to_out_param") + +@pytest.mark.skipif(platform.system() == 'Darwin', reason='FIXME: macos can\'t find the python library') +def test_ref_to_in_param(): + _run_test("ref_to_in_param") + +@pytest.mark.skipif(platform.system() == 'Darwin', reason='FIXME: macos can\'t find the python library') +def test_in_to_ref_param(): + _run_test("in_to_ref_param") + @pytest.mark.skipif(platform.system() == 'Darwin', reason='FIXME: macos can\'t find the python library') def test_nested_type(): _run_test("nested_type") diff --git a/src/runtime/StateSerialization/MaybeMethodBase.cs b/src/runtime/StateSerialization/MaybeMethodBase.cs index 3f57f0d8a..d18c94059 100644 --- a/src/runtime/StateSerialization/MaybeMethodBase.cs +++ b/src/runtime/StateSerialization/MaybeMethodBase.cs @@ -35,11 +35,11 @@ public ParameterHelper(ParameterInfo tp) Name = tp.ParameterType.AssemblyQualifiedName; Modifier = TypeModifier.None; - if (tp.IsIn) + if (tp.IsIn && tp.ParameterType.IsByRef) { Modifier = TypeModifier.In; } - else if (tp.IsOut) + else if (tp.IsOut && tp.ParameterType.IsByRef) { Modifier = TypeModifier.Out; } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy