Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ed6763c

Browse files
BadSingletonlostmsu
authored andcommitted
Add more more tests for in, out and ref parameters
1 parent d6c0081 commit ed6763c

File tree

3 files changed

+218
-2
lines changed

3 files changed

+218
-2
lines changed

src/domain_tests/TestRunner.cs

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,210 @@ raise AssertionError('failed to raise')
843843
assert foo is not bar
844844
",
845845
},
846+
847+
new TestCase
848+
{
849+
Name = "ref_to_out_param",
850+
DotNetBefore = @"
851+
namespace TestNamespace
852+
{
853+
854+
[System.Serializable]
855+
public class Data
856+
{
857+
public int num = -1;
858+
}
859+
860+
[System.Serializable]
861+
public class Cls
862+
{
863+
public static void MyFn (ref Data a)
864+
{
865+
a.num = 7;
866+
}
867+
}
868+
}",
869+
DotNetAfter = @"
870+
namespace TestNamespace
871+
{
872+
873+
[System.Serializable]
874+
public class Data
875+
{
876+
public int num = -1;
877+
}
878+
879+
[System.Serializable]
880+
public class Cls
881+
{
882+
public static void MyFn (out Data a)
883+
{
884+
a = new Data();
885+
a.num = 9001;
886+
}
887+
}
888+
}",
889+
PythonCode = @"
890+
import clr
891+
import sys
892+
clr.AddReference('DomainTests')
893+
import TestNamespace
894+
import System
895+
896+
def before_reload():
897+
898+
foo = TestNamespace.Data()
899+
bar = TestNamespace.Cls.MyFn(foo)
900+
# foo should have changed
901+
assert foo.num == 7
902+
assert bar.num == 7
903+
904+
905+
def after_reload():
906+
907+
foo = TestNamespace.Data()
908+
bar = TestNamespace.Cls.MyFn(foo)
909+
assert bar.num == 9001
910+
# foo shouldn't have changed.
911+
assert foo.num == -1
912+
# this should work too
913+
baz = TestNamespace.Cls.MyFn(None)
914+
assert baz.num == 9001
915+
",
916+
},
917+
new TestCase
918+
{
919+
Name = "ref_to_in_param",
920+
DotNetBefore = @"
921+
namespace TestNamespace
922+
{
923+
924+
[System.Serializable]
925+
public class Data
926+
{
927+
public int num = -1;
928+
}
929+
930+
[System.Serializable]
931+
public class Cls
932+
{
933+
public static void MyFn (ref Data a)
934+
{
935+
a.num = 7;
936+
System.Console.Write(""Method with ref parameter: "");
937+
System.Console.WriteLine(a.num);
938+
}
939+
}
940+
}",
941+
DotNetAfter = @"
942+
namespace TestNamespace
943+
{
944+
[System.Serializable]
945+
public class Data
946+
{
947+
public int num = -1;
948+
}
949+
950+
[System.Serializable]
951+
public class Cls
952+
{
953+
public static void MyFn (Data a)
954+
{
955+
System.Console.Write(""Method with in parameter: "");
956+
System.Console.WriteLine(a.num);
957+
}
958+
}
959+
}",
960+
PythonCode = @"
961+
import clr
962+
import sys
963+
clr.AddReference('DomainTests')
964+
import TestNamespace
965+
import System
966+
967+
def before_reload():
968+
969+
foo = TestNamespace.Data()
970+
bar = TestNamespace.Cls.MyFn(foo)
971+
# foo should have changed
972+
assert foo.num == 7
973+
assert bar.num == 7
974+
975+
def after_reload():
976+
977+
foo = TestNamespace.Data()
978+
TestNamespace.Cls.MyFn(foo)
979+
# foo should not have changed
980+
assert foo.num == TestNamespace.Data().num
981+
982+
",
983+
},
984+
new TestCase
985+
{
986+
Name = "in_to_ref_param",
987+
DotNetBefore = @"
988+
namespace TestNamespace
989+
{
990+
[System.Serializable]
991+
public class Data
992+
{
993+
public int num = -1;
994+
}
995+
996+
[System.Serializable]
997+
public class Cls
998+
{
999+
public static void MyFn (Data a)
1000+
{
1001+
System.Console.Write(""Method with in parameter: "");
1002+
System.Console.WriteLine(a.num);
1003+
}
1004+
}
1005+
}",
1006+
DotNetAfter = @"
1007+
namespace TestNamespace
1008+
{
1009+
1010+
[System.Serializable]
1011+
public class Data
1012+
{
1013+
public int num = -1;
1014+
}
1015+
1016+
[System.Serializable]
1017+
public class Cls
1018+
{
1019+
public static void MyFn (ref Data a)
1020+
{
1021+
a.num = 7;
1022+
System.Console.Write(""Method with ref parameter: "");
1023+
System.Console.WriteLine(a.num);
1024+
}
1025+
}
1026+
}",
1027+
PythonCode = @"
1028+
import clr
1029+
import sys
1030+
clr.AddReference('DomainTests')
1031+
import TestNamespace
1032+
import System
1033+
1034+
def before_reload():
1035+
1036+
foo = TestNamespace.Data()
1037+
TestNamespace.Cls.MyFn(foo)
1038+
# foo should not have changed
1039+
assert foo.num == TestNamespace.Data().num
1040+
1041+
def after_reload():
1042+
1043+
foo = TestNamespace.Data()
1044+
bar = TestNamespace.Cls.MyFn(foo)
1045+
# foo should have changed
1046+
assert foo.num == 7
1047+
assert bar.num == 7
1048+
",
1049+
},
8461050
new TestCase
8471051
{
8481052
Name = "nested_type",

src/domain_tests/test_domain_reload.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ def test_construct_removed_class():
8383
def test_out_to_ref_param():
8484
_run_test("out_to_ref_param")
8585

86+
@pytest.mark.skipif(platform.system() == 'Darwin', reason='FIXME: macos can\'t find the python library')
87+
def test_ref_to_out_param():
88+
_run_test("ref_to_out_param")
89+
90+
@pytest.mark.skipif(platform.system() == 'Darwin', reason='FIXME: macos can\'t find the python library')
91+
def test_ref_to_in_param():
92+
_run_test("ref_to_in_param")
93+
94+
@pytest.mark.skipif(platform.system() == 'Darwin', reason='FIXME: macos can\'t find the python library')
95+
def test_in_to_ref_param():
96+
_run_test("in_to_ref_param")
97+
8698
@pytest.mark.skipif(platform.system() == 'Darwin', reason='FIXME: macos can\'t find the python library')
8799
def test_nested_type():
88100
_run_test("nested_type")

src/runtime/StateSerialization/MaybeMethodBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ public ParameterHelper(ParameterInfo tp)
3535
Name = tp.ParameterType.AssemblyQualifiedName;
3636
Modifier = TypeModifier.None;
3737

38-
if (tp.IsIn)
38+
if (tp.IsIn && tp.ParameterType.IsByRef)
3939
{
4040
Modifier = TypeModifier.In;
4141
}
42-
else if (tp.IsOut)
42+
else if (tp.IsOut && tp.ParameterType.IsByRef)
4343
{
4444
Modifier = TypeModifier.Out;
4545
}

0 commit comments

Comments
 (0)