diff --git a/Source/Engine/Tests/TestScripting.cpp b/Source/Engine/Tests/TestScripting.cpp index 506291b36..8a3541def 100644 --- a/Source/Engine/Tests/TestScripting.cpp +++ b/Source/Engine/Tests/TestScripting.cpp @@ -37,9 +37,7 @@ TEST_CASE("Scripting") MMethod* method = klass->GetMethod("TestLibraryImports"); CHECK(method); MObject* result = method->Invoke(nullptr, nullptr, nullptr); - CHECK(result); - int32 resultValue = MUtils::Unbox(result); - CHECK(resultValue == 0); + CHECK(MUtils::Unbox(result) == 0); } SECTION("Test Class") @@ -167,4 +165,15 @@ TEST_CASE("Scripting") CHECK(interfaceObject); CHECK(interfaceObject == object); } + + SECTION("Test Interface Reference") + { + // Test native interface implementation + MClass* klass = Scripting::FindClass("FlaxEngine.Tests.TestScripting"); + CHECK(klass); + MMethod* method = klass->GetMethod("TestInterfaceReference"); + CHECK(method); + MObject* result = method->Invoke(nullptr, nullptr, nullptr); + CHECK(MUtils::Unbox(result) == 0); + } } diff --git a/Source/Engine/Tests/TestScripting.cs b/Source/Engine/Tests/TestScripting.cs index edbe18016..5846b569d 100644 --- a/Source/Engine/Tests/TestScripting.cs +++ b/Source/Engine/Tests/TestScripting.cs @@ -2,6 +2,7 @@ #if FLAX_TESTS using System; +using System.Collections.Generic; using System.Reflection; using System.Runtime.InteropServices; @@ -42,6 +43,33 @@ namespace FlaxEngine.Tests NativeLibrary.Free(library); return result; } + + /// + /// Tests usage with marshalling. + /// + public static int TestInterfaceReference() + { + var native = new TestClassNative(); + native.InterfaceRef = native; + var returned = native.InterfaceRef; + if (returned != native) + return 1; + returned = native.TestPassInterface(native); + if (returned != native) + return 2; + returned = native.TestPassInterfaceArray(new ScriptingObjectInterfaceReference[1] { native })[0]; + if (returned != native) + return 3; + var dic = new Dictionary>(); + dic.Add("key", native); + returned = native.TestPassInterfaceDictionary(dic)["key"]; + if (returned != native) + return 4; + var res = returned.Interface.TestInterfaceMethod("123"); + if (res != 3) + return 5; + return 0; + } } } diff --git a/Source/Engine/Tests/TestScripting.h b/Source/Engine/Tests/TestScripting.h index 70f443346..e9440bb03 100644 --- a/Source/Engine/Tests/TestScripting.h +++ b/Source/Engine/Tests/TestScripting.h @@ -5,6 +5,7 @@ #include "Engine/Core/ISerializable.h" #include "Engine/Core/Math/Vector3.h" #include "Engine/Core/Collections/Array.h" +#include "Engine/Core/Collections/Dictionary.h" #include "Engine/Scripting/ScriptingObject.h" #include "Engine/Scripting/ScriptingObjectInterfaceReference.h" #include "Engine/Scripting/SerializableScriptingObject.h" @@ -204,6 +205,24 @@ public: // Test nameless arguments API_FUNCTION() void TestNamelessArguments(int32, float, bool){} + // Test pass interface ref in function + API_FUNCTION() ScriptingObjectInterfaceReference TestPassInterface(ScriptingObjectInterfaceReference param1) const + { + return param1; + } + + // Test pass interface ref array in function + API_FUNCTION() Array> TestPassInterfaceArray(Array> param1) const + { + return param1; + } + + // Test pass interface ref dictionary in function + API_FUNCTION() Dictionary> TestPassInterfaceDictionary(Dictionary> param1) const + { + return param1; + } + int32 TestInterfaceMethod(const String& str) override { return str.Length();