@@ -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<int32>(result);
|
||||
CHECK(resultValue == 0);
|
||||
CHECK(MUtils::Unbox<int32>(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<int32>(result) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests <see cref="ScriptingObjectInterfaceReference{T}"/> usage with marshalling.
|
||||
/// </summary>
|
||||
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<ITestInterface>[1] { native })[0];
|
||||
if (returned != native)
|
||||
return 3;
|
||||
var dic = new Dictionary<string, ScriptingObjectInterfaceReference<ITestInterface>>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<ITestInterface> TestPassInterface(ScriptingObjectInterfaceReference<ITestInterface> param1) const
|
||||
{
|
||||
return param1;
|
||||
}
|
||||
|
||||
// Test pass interface ref array in function
|
||||
API_FUNCTION() Array<ScriptingObjectInterfaceReference<ITestInterface>> TestPassInterfaceArray(Array<ScriptingObjectInterfaceReference<ITestInterface>> param1) const
|
||||
{
|
||||
return param1;
|
||||
}
|
||||
|
||||
// Test pass interface ref dictionary in function
|
||||
API_FUNCTION() Dictionary<String, ScriptingObjectInterfaceReference<ITestInterface>> TestPassInterfaceDictionary(Dictionary<String, ScriptingObjectInterfaceReference<ITestInterface>> param1) const
|
||||
{
|
||||
return param1;
|
||||
}
|
||||
|
||||
int32 TestInterfaceMethod(const String& str) override
|
||||
{
|
||||
return str.Length();
|
||||
|
||||
Reference in New Issue
Block a user