Add more test cases for various scripting bindings features
This commit is contained in:
@@ -23,8 +23,13 @@ TEST_CASE("Scripting")
|
||||
CHECK(testClass->SimpleField == 1);
|
||||
CHECK(testClass->SimpleStruct.Object == nullptr);
|
||||
CHECK(testClass->SimpleStruct.Vector == Float3::One);
|
||||
int32 methodResult = testClass->TestMethod(TEXT("123"));
|
||||
Array<TestStruct> struct1 = { testClass->SimpleStruct };
|
||||
Array<TestStruct> struct2 = { testClass->SimpleStruct };
|
||||
Array<ScriptingObject*> objects;
|
||||
TestStructPOD pod;
|
||||
int32 methodResult = testClass->TestMethod(TEXT("123"), pod, struct1, struct2, objects);
|
||||
CHECK(methodResult == 3);
|
||||
CHECK(objects.Count() == 0);
|
||||
|
||||
// Test managed class
|
||||
type = Scripting::FindScriptingType("FlaxEngine.TestClassManaged");
|
||||
@@ -38,8 +43,17 @@ TEST_CASE("Scripting")
|
||||
CHECK(testClass->SimpleField == 2);
|
||||
CHECK(testClass->SimpleStruct.Object == testClass);
|
||||
CHECK(testClass->SimpleStruct.Vector == Float3::UnitX);
|
||||
methodResult = testClass->TestMethod(TEXT("123"));
|
||||
struct1 = { testClass->SimpleStruct };
|
||||
struct2 = { testClass->SimpleStruct };
|
||||
objects.Clear();
|
||||
pod.Vector = Float3::One;
|
||||
methodResult = testClass->TestMethod(TEXT("123"), pod, struct1, struct2, objects);
|
||||
CHECK(methodResult == 6);
|
||||
CHECK(pod.Vector == Float3::Half);
|
||||
CHECK(struct2.Count() == 2);
|
||||
CHECK(struct2[0] == testClass->SimpleStruct);
|
||||
CHECK(struct2[1] == testClass->SimpleStruct);
|
||||
CHECK(objects.Count() == 3);
|
||||
}
|
||||
|
||||
SECTION("Test Event")
|
||||
|
||||
@@ -63,10 +63,24 @@ namespace FlaxEngine
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int TestMethod(string str)
|
||||
public override int TestMethod(string str, ref TestStructPOD pod, TestStruct[] struct1, ref TestStruct[] struct2, out Object[] objects)
|
||||
{
|
||||
objects = new Object[3];
|
||||
if (struct1 == null || struct1.Length != 1)
|
||||
return -1;
|
||||
if (struct2 == null || struct2.Length != 1)
|
||||
return -2;
|
||||
if (pod.Vector != Float3.One)
|
||||
return -3;
|
||||
struct2 = new TestStruct[2]
|
||||
{
|
||||
struct1[0],
|
||||
SimpleStruct,
|
||||
};
|
||||
pod.Vector = Float3.Half;
|
||||
|
||||
// Test C++ base method invocation
|
||||
return str.Length + base.TestMethod(str);
|
||||
return str.Length + base.TestMethod(str, ref pod, struct1, ref struct2, out _);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -17,6 +17,26 @@ API_STRUCT(NoDefault) struct TestStruct : public ISerializable
|
||||
API_FIELD() Float3 Vector = Float3::One;
|
||||
// Ref
|
||||
API_FIELD() ScriptingObject* Object = nullptr;
|
||||
|
||||
friend bool operator==(const TestStruct& lhs, const TestStruct& rhs)
|
||||
{
|
||||
return lhs.Vector == rhs.Vector && lhs.Object == rhs.Object;
|
||||
}
|
||||
};
|
||||
|
||||
// Test structure.
|
||||
API_STRUCT(NoDefault) struct TestStructPOD
|
||||
{
|
||||
DECLARE_SCRIPTING_TYPE_MINIMAL(TestStructPOD);
|
||||
|
||||
// Var
|
||||
API_FIELD() Float3 Vector = Float3::One;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct TIsPODType<TestStructPOD>
|
||||
{
|
||||
enum { Value = true };
|
||||
};
|
||||
|
||||
// Test interface.
|
||||
@@ -46,7 +66,7 @@ public:
|
||||
API_EVENT() Delegate<int32, Float3, const String&, String&, const Array<TestStruct>&, Array<TestStruct>&> SimpleEvent;
|
||||
|
||||
// Test virtual method
|
||||
API_FUNCTION() virtual int32 TestMethod(const String& str)
|
||||
API_FUNCTION() virtual int32 TestMethod(const String& str, API_PARAM(Ref) TestStructPOD& pod, const Array<TestStruct>& struct1, API_PARAM(Ref) Array<TestStruct>& struct2, API_PARAM(Out) Array<ScriptingObject*>& objects)
|
||||
{
|
||||
return str.Length();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user