diff --git a/Source/Engine/Tests/TestScripting.cpp b/Source/Engine/Tests/TestScripting.cpp index 9df7d10a6..712cc3aaf 100644 --- a/Source/Engine/Tests/TestScripting.cpp +++ b/Source/Engine/Tests/TestScripting.cpp @@ -38,12 +38,15 @@ TEST_CASE("Scripting") CHECK(testClass->SimpleField == 1); CHECK(testClass->SimpleStruct.Object == nullptr); CHECK(testClass->SimpleStruct.Vector == Float3::One); + TestStruct nonPod; Array struct1 = { testClass->SimpleStruct }; Array struct2 = { testClass->SimpleStruct }; Array objects; TestStructPOD pod; - int32 methodResult = testClass->TestMethod(TEXT("123"), pod, struct1, struct2, objects); + int32 methodResult = testClass->TestMethod(TEXT("123"), pod, nonPod, struct1, struct2, objects); CHECK(methodResult == 3); + CHECK(nonPod.Object == testClass); + CHECK(nonPod.Vector == Float3::UnitY); CHECK(objects.Count() == 0); // Test managed class @@ -58,13 +61,16 @@ TEST_CASE("Scripting") CHECK(testClass->SimpleField == 2); CHECK(testClass->SimpleStruct.Object == testClass); CHECK(testClass->SimpleStruct.Vector == Float3::UnitX); + nonPod = TestStruct(); struct1 = { testClass->SimpleStruct }; struct2 = { testClass->SimpleStruct }; objects.Clear(); pod.Vector = Float3::One; - methodResult = testClass->TestMethod(TEXT("123"), pod, struct1, struct2, objects); + methodResult = testClass->TestMethod(TEXT("123"), pod, nonPod, struct1, struct2, objects); CHECK(methodResult == 6); CHECK(pod.Vector == Float3::Half); + CHECK(nonPod.Object == testClass); + CHECK(nonPod.Vector == Float3::UnitY); CHECK(struct2.Count() == 2); CHECK(struct2[0] == testClass->SimpleStruct); CHECK(struct2[1] == testClass->SimpleStruct); @@ -83,11 +89,14 @@ TEST_CASE("Scripting") CHECK(testClass->SimpleField == 2); String str1 = TEXT("1"); String str2 = TEXT("2"); + TestStruct nonPod; Array arr1 = { testClass->SimpleStruct }; Array arr2 = { testClass->SimpleStruct }; - testClass->SimpleEvent(1, Float3::One, str1, str2, arr1, arr2); + testClass->SimpleEvent(1, Float3::One, str1, str2, nonPod, arr1, arr2); CHECK(testClass->SimpleField == 4); CHECK(str2 == TEXT("4")); + CHECK(nonPod.Object == testClass); + CHECK(nonPod.Vector == Float3::UnitY); CHECK(arr2.Count() == 2); CHECK(arr2[0].Vector == Float3::Half); CHECK(arr2[0].Object == nullptr); diff --git a/Source/Engine/Tests/TestScripting.cs b/Source/Engine/Tests/TestScripting.cs index 529ea4f14..fd94b8017 100644 --- a/Source/Engine/Tests/TestScripting.cs +++ b/Source/Engine/Tests/TestScripting.cs @@ -107,7 +107,7 @@ namespace FlaxEngine } /// - public override int TestMethod(string str, ref TestStructPOD pod, TestStruct[] struct1, ref TestStruct[] struct2, out Object[] objects) + public override int TestMethod(string str, ref TestStructPOD pod, ref TestStruct nonPod, TestStruct[] struct1, ref TestStruct[] struct2, out Object[] objects) { objects = new Object[3]; if (struct1 == null || struct1.Length != 1) @@ -124,7 +124,7 @@ namespace FlaxEngine pod.Vector = Float3.Half; // Test C++ base method invocation - return str.Length + base.TestMethod(str, ref pod, struct1, ref struct2, out _); + return str.Length + base.TestMethod(str, ref pod, ref nonPod, struct1, ref struct2, out _); } /// @@ -134,18 +134,22 @@ namespace FlaxEngine return str.Length + base.TestInterfaceMethod(str); } - private void OnSimpleEvent(int arg1, Float3 arg2, string arg3, ref string arg4, TestStruct[] arg5, ref TestStruct[] arg6) + private void OnSimpleEvent(int arg1, Float3 arg2, string arg3, ref string arg4, ref TestStruct nonPod, TestStruct[] arg5, ref TestStruct[] arg6) { // Verify that C++ passed proper data to C# via event bindings if (arg1 == 1 && arg2 == Float3.One && arg3 == "1" && arg4 == "2" && + nonPod.Object == null && + nonPod.Vector == Float3.One && arg5 != null && arg5.Length == 1 && arg5[0] == SimpleStruct && arg6 != null && arg6.Length == 1 && arg6[0] == SimpleStruct) { // Test passing data back from C# to C++ SimpleField = 4; + nonPod.Object = this; + nonPod.Vector = Float3.UnitY; arg4 = "4"; arg6 = new TestStruct[2] { diff --git a/Source/Engine/Tests/TestScripting.h b/Source/Engine/Tests/TestScripting.h index 2cfa4b0d1..23f64353d 100644 --- a/Source/Engine/Tests/TestScripting.h +++ b/Source/Engine/Tests/TestScripting.h @@ -63,11 +63,15 @@ public: API_FIELD() TestStruct SimpleStruct; // Test event - API_EVENT() Delegate&, Array&> SimpleEvent; + API_EVENT() Delegate&, Array&> SimpleEvent; // Test virtual method - API_FUNCTION() virtual int32 TestMethod(const String& str, API_PARAM(Ref) TestStructPOD& pod, const Array& struct1, API_PARAM(Ref) Array& struct2, API_PARAM(Out) Array& objects) + API_FUNCTION() virtual int32 TestMethod(const String& str, API_PARAM(Ref) TestStructPOD& pod, API_PARAM(Ref) TestStruct& nonPod, const Array& struct1, API_PARAM(Ref) Array& struct2, API_PARAM(Out) Array& objects) { + if (nonPod.Vector != Float3::One) + return -1; + nonPod.Object = this; + nonPod.Vector = Float3::UnitY; return str.Length(); }