Try to fix units tests on Linux

This commit is contained in:
Lynix 2018-04-07 13:10:55 +02:00
parent 830dae1b27
commit 31fc8c9dad
2 changed files with 50 additions and 54 deletions

View File

@ -2,13 +2,9 @@
#include <Nazara/Core/ObjectHandle.hpp> #include <Nazara/Core/ObjectHandle.hpp>
#include <Catch/catch.hpp> #include <Catch/catch.hpp>
class Test; struct ObjectHandle_Test : public Nz::HandledObject<ObjectHandle_Test>
using TestHandle = Nz::ObjectHandle<Test>;
struct Test : public Nz::HandledObject<Test>
{ {
Test(int value) : ObjectHandle_Test(int value) :
i(value) i(value)
{ {
} }
@ -21,10 +17,10 @@ SCENARIO("Handle", "[CORE][HandledObject][ObjectHandle]")
GIVEN("One test with two handles") GIVEN("One test with two handles")
{ {
int defaultValue = 1; int defaultValue = 1;
Test test(defaultValue); ObjectHandle_Test test(defaultValue);
Nz::ObjectHandle<Test> handle1 = test.CreateHandle(); Nz::ObjectHandle<ObjectHandle_Test> handle1 = test.CreateHandle();
Nz::ObjectHandle<Test> handle2 = test.CreateHandle(); Nz::ObjectHandle<ObjectHandle_Test> handle2 = test.CreateHandle();
WHEN("We modify from one") WHEN("We modify from one")
{ {
@ -39,8 +35,8 @@ SCENARIO("Handle", "[CORE][HandledObject][ObjectHandle]")
WHEN("We copy construct") WHEN("We copy construct")
{ {
Test other(test); ObjectHandle_Test other(test);
Nz::ObjectHandle<Test> otherHandle = other.CreateHandle(); Nz::ObjectHandle<ObjectHandle_Test> otherHandle = other.CreateHandle();
THEN("Handles should point to 1") THEN("Handles should point to 1")
{ {
@ -54,8 +50,8 @@ SCENARIO("Handle", "[CORE][HandledObject][ObjectHandle]")
WHEN("We move construct") WHEN("We move construct")
{ {
Test other(std::move(test)); ObjectHandle_Test other(std::move(test));
Nz::ObjectHandle<Test> otherHandle = other.CreateHandle(); Nz::ObjectHandle<ObjectHandle_Test> otherHandle = other.CreateHandle();
THEN("Handles should point to 1") THEN("Handles should point to 1")
{ {
@ -69,8 +65,8 @@ SCENARIO("Handle", "[CORE][HandledObject][ObjectHandle]")
WHEN("We copy assign") WHEN("We copy assign")
{ {
int copyValue = 3; int copyValue = 3;
Test other(copyValue); ObjectHandle_Test other(copyValue);
Nz::ObjectHandle<Test> otherHandle = other.CreateHandle(); Nz::ObjectHandle<ObjectHandle_Test> otherHandle = other.CreateHandle();
test = other; test = other;
THEN("Handles should point to 3") THEN("Handles should point to 3")
@ -86,8 +82,8 @@ SCENARIO("Handle", "[CORE][HandledObject][ObjectHandle]")
WHEN("We move assign") WHEN("We move assign")
{ {
int moveValue = 4; int moveValue = 4;
Test other(moveValue); ObjectHandle_Test other(moveValue);
Nz::ObjectHandle<Test> otherHandle = other.CreateHandle(); Nz::ObjectHandle<ObjectHandle_Test> otherHandle = other.CreateHandle();
test = std::move(other); test = std::move(other);
THEN("Handles to previous objects should be invalid") THEN("Handles to previous objects should be invalid")
@ -106,13 +102,13 @@ SCENARIO("Handle", "[CORE][HandledObject][ObjectHandle]")
GIVEN("One handle pointing to a default test") GIVEN("One handle pointing to a default test")
{ {
Test test(1); ObjectHandle_Test test(1);
Nz::ObjectHandle<Test> invalidHandle(&test); Nz::ObjectHandle<ObjectHandle_Test> invalidHandle(&test);
WHEN("We bind it to a HandledObject which is going to die") WHEN("We bind it to a HandledObject which is going to die")
{ {
{ {
Test dyingTest(5); ObjectHandle_Test dyingTest(5);
invalidHandle.Reset(&dyingTest); invalidHandle.Reset(&dyingTest);
} }
@ -125,10 +121,10 @@ SCENARIO("Handle", "[CORE][HandledObject][ObjectHandle]")
GIVEN("Two handle pointing to two different tests") GIVEN("Two handle pointing to two different tests")
{ {
Test test1(1); ObjectHandle_Test test1(1);
Nz::ObjectHandle<Test> test1Handle = test1.CreateHandle(); Nz::ObjectHandle<ObjectHandle_Test> test1Handle = test1.CreateHandle();
Test test2(2); ObjectHandle_Test test2(2);
Nz::ObjectHandle<Test> test2Handle = test2.CreateHandle(); Nz::ObjectHandle<ObjectHandle_Test> test2Handle = test2.CreateHandle();
WHEN("We swap their content") WHEN("We swap their content")
{ {

View File

@ -3,15 +3,15 @@
#include <Nazara/Core/HandledObject.hpp> #include <Nazara/Core/HandledObject.hpp>
#include <Nazara/Core/ObjectHandle.hpp> #include <Nazara/Core/ObjectHandle.hpp>
class Test class LuaClass_Test
{ {
public: public:
Test() = default; LuaClass_Test() = default;
Test(const Test& other) = default; LuaClass_Test(const LuaClass_Test& other) = default;
Test& operator=(const Test& other) = default; LuaClass_Test& operator=(const LuaClass_Test& other) = default;
virtual ~Test() = default; virtual ~LuaClass_Test() = default;
Test(int i, bool j = false) : LuaClass_Test(int i, bool j = false) :
m_i(i), m_i(i),
m_j(j) m_j(j)
{ {
@ -42,21 +42,21 @@ class Test
bool m_j; bool m_j;
}; };
class InheritTest : public Test class LuaClass_InheritTest : public LuaClass_Test
{ {
public: public:
InheritTest() : LuaClass_InheritTest() :
Test(5, true) LuaClass_Test(5, true)
{ {
} }
int GetI() const override int GetI() const override
{ {
return Test::GetI() + 3; return LuaClass_Test::GetI() + 3;
} }
}; };
class TestWithHandle : public Nz::HandledObject<TestWithHandle> class LuaClass_TestWithHandle : public Nz::HandledObject<LuaClass_TestWithHandle>
{ {
public: public:
int GetI() const int GetI() const
@ -73,24 +73,24 @@ class TestWithHandle : public Nz::HandledObject<TestWithHandle>
int m_i = 8; int m_i = 8;
}; };
inline unsigned int LuaImplQueryArg(const Nz::LuaState& instance, int index, Test* arg, Nz::TypeTag<Test>) inline unsigned int LuaImplQueryArg(const Nz::LuaState& instance, int index, LuaClass_Test* arg, Nz::TypeTag<LuaClass_Test>)
{ {
REQUIRE(instance.IsOfType(index, "Test")); REQUIRE(instance.IsOfType(index, "Test"));
*arg = *static_cast<Test*>(instance.ToUserdata(index)); *arg = *static_cast<LuaClass_Test*>(instance.ToUserdata(index));
return 1; return 1;
} }
inline unsigned int LuaImplQueryArg(const Nz::LuaState& instance, int index, Nz::ObjectHandle<TestWithHandle>* arg, Nz::TypeTag<Nz::ObjectHandle<TestWithHandle>>) inline unsigned int LuaImplQueryArg(const Nz::LuaState& instance, int index, Nz::ObjectHandle<LuaClass_TestWithHandle>* arg, Nz::TypeTag<Nz::ObjectHandle<LuaClass_TestWithHandle>>)
{ {
REQUIRE(instance.IsOfType(index, "TestWithHandle")); REQUIRE(instance.IsOfType(index, "TestWithHandle"));
*arg = *static_cast<Nz::ObjectHandle<TestWithHandle>*>(instance.ToUserdata(index)); *arg = *static_cast<Nz::ObjectHandle<LuaClass_TestWithHandle>*>(instance.ToUserdata(index));
return 1; return 1;
} }
inline unsigned int LuaImplQueryArg(const Nz::LuaState& instance, int index, InheritTest* arg, Nz::TypeTag<InheritTest>) inline unsigned int LuaImplQueryArg(const Nz::LuaState& instance, int index, LuaClass_InheritTest* arg, Nz::TypeTag<LuaClass_InheritTest>)
{ {
REQUIRE(instance.IsOfType(index, "InheritTest")); REQUIRE(instance.IsOfType(index, "InheritTest"));
*arg = *static_cast<InheritTest*>(instance.ToUserdata(index)); *arg = *static_cast<LuaClass_InheritTest*>(instance.ToUserdata(index));
return 1; return 1;
} }
@ -99,9 +99,9 @@ SCENARIO("LuaClass", "[LUA][LUACLASS]")
GIVEN("One lua class for our Test class") GIVEN("One lua class for our Test class")
{ {
Nz::LuaInstance luaInstance; Nz::LuaInstance luaInstance;
Nz::LuaClass<Test> test; Nz::LuaClass<LuaClass_Test> test;
Nz::LuaClass<InheritTest> inheritTest; Nz::LuaClass<LuaClass_InheritTest> inheritTest;
using TestHandle = Nz::ObjectHandle<TestWithHandle>; using TestHandle = Nz::ObjectHandle<LuaClass_TestWithHandle>;
Nz::LuaClass<TestHandle> testHandle; Nz::LuaClass<TestHandle> testHandle;
WHEN("We bind the methods") WHEN("We bind the methods")
@ -110,7 +110,7 @@ SCENARIO("LuaClass", "[LUA][LUACLASS]")
test.BindDefaultConstructor(); test.BindDefaultConstructor();
test.SetConstructor([] (Nz::LuaState& lua, Test* instance, std::size_t argumentCount) test.SetConstructor([] (Nz::LuaState& lua, LuaClass_Test* instance, std::size_t argumentCount)
{ {
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U); std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
@ -139,14 +139,14 @@ SCENARIO("LuaClass", "[LUA][LUACLASS]")
return false; return false;
}); });
test.BindMethod("GetI", &Test::GetI); test.BindMethod("GetI", &LuaClass_Test::GetI);
test.BindMethod("GetJ", &Test::GetJ); test.BindMethod("GetJ", &LuaClass_Test::GetJ);
test.BindMethod("GetDefault", &Test::GetDefault, 0); test.BindMethod("GetDefault", &LuaClass_Test::GetDefault, 0);
test.BindStaticMethod("StaticMethodWithArguments", [] (Nz::LuaState& state) -> int test.BindStaticMethod("StaticMethodWithArguments", [] (Nz::LuaState& state) -> int
{ {
int argIndex = 1; int argIndex = 1;
int result = Test::StaticMethodWithArguments(state.Check<int>(&argIndex), state.Check<int>(&argIndex)); int result = LuaClass_Test::StaticMethodWithArguments(state.Check<int>(&argIndex), state.Check<int>(&argIndex));
state.Push(result); state.Push(result);
return 1; return 1;
@ -162,7 +162,7 @@ SCENARIO("LuaClass", "[LUA][LUACLASS]")
luaInstance.PushFunction([=](Nz::LuaState& state) -> int luaInstance.PushFunction([=](Nz::LuaState& state) -> int
{ {
int argIndex = 1; int argIndex = 1;
Test result = state.Check<Test>(&argIndex); LuaClass_Test result = state.Check<LuaClass_Test>(&argIndex);
CHECK(result.GetI() == value); CHECK(result.GetI() == value);
CHECK_FALSE(result.GetJ()); CHECK_FALSE(result.GetJ());
return 1; return 1;
@ -181,7 +181,7 @@ SCENARIO("LuaClass", "[LUA][LUACLASS]")
luaInstance.PushFunction([=](Nz::LuaState& state) -> int luaInstance.PushFunction([=](Nz::LuaState& state) -> int
{ {
int argIndex = 1; int argIndex = 1;
Test result = state.Check<Test>(&argIndex); LuaClass_Test result = state.Check<LuaClass_Test>(&argIndex);
CHECK(result.GetI() == staticResult); CHECK(result.GetI() == staticResult);
CHECK(result.GetJ()); CHECK(result.GetJ());
return 1; return 1;
@ -205,7 +205,7 @@ SCENARIO("LuaClass", "[LUA][LUACLASS]")
luaInstance.PushFunction([=](Nz::LuaState& state) -> int luaInstance.PushFunction([=](Nz::LuaState& state) -> int
{ {
int argIndex = 1; int argIndex = 1;
InheritTest result = state.Check<InheritTest>(&argIndex); LuaClass_InheritTest result = state.Check<LuaClass_InheritTest>(&argIndex);
CHECK(result.GetI() == 8); CHECK(result.GetI() == 8);
CHECK(result.GetJ()); CHECK(result.GetJ());
return 1; return 1;
@ -224,8 +224,8 @@ SCENARIO("LuaClass", "[LUA][LUACLASS]")
testHandle.Reset("TestHandle"); testHandle.Reset("TestHandle");
testHandle.BindMethod("IsValid", &TestHandle::IsValid); testHandle.BindMethod("IsValid", &TestHandle::IsValid);
testHandle.BindMethod("GetI", &TestWithHandle::GetI); testHandle.BindMethod("GetI", &LuaClass_TestWithHandle::GetI);
testHandle.BindMethod("GetDefault", &TestWithHandle::GetDefault, defaultValue); testHandle.BindMethod("GetDefault", &LuaClass_TestWithHandle::GetDefault, defaultValue);
testHandle.Register(luaInstance); testHandle.Register(luaInstance);
THEN("We can ensure the following properties") THEN("We can ensure the following properties")