From 31fc8c9dad1c0c8e16fc5fa604fa1fd5e81dbcf8 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sat, 7 Apr 2018 13:10:55 +0200 Subject: [PATCH] Try to fix units tests on Linux --- tests/Engine/Core/ObjectHandle.cpp | 44 ++++++++++------------ tests/Engine/Lua/LuaClass.cpp | 60 +++++++++++++++--------------- 2 files changed, 50 insertions(+), 54 deletions(-) diff --git a/tests/Engine/Core/ObjectHandle.cpp b/tests/Engine/Core/ObjectHandle.cpp index f5836ae81..cffce4ecd 100644 --- a/tests/Engine/Core/ObjectHandle.cpp +++ b/tests/Engine/Core/ObjectHandle.cpp @@ -2,13 +2,9 @@ #include #include -class Test; - -using TestHandle = Nz::ObjectHandle; - -struct Test : public Nz::HandledObject +struct ObjectHandle_Test : public Nz::HandledObject { - Test(int value) : + ObjectHandle_Test(int value) : i(value) { } @@ -21,10 +17,10 @@ SCENARIO("Handle", "[CORE][HandledObject][ObjectHandle]") GIVEN("One test with two handles") { int defaultValue = 1; - Test test(defaultValue); + ObjectHandle_Test test(defaultValue); - Nz::ObjectHandle handle1 = test.CreateHandle(); - Nz::ObjectHandle handle2 = test.CreateHandle(); + Nz::ObjectHandle handle1 = test.CreateHandle(); + Nz::ObjectHandle handle2 = test.CreateHandle(); WHEN("We modify from one") { @@ -39,8 +35,8 @@ SCENARIO("Handle", "[CORE][HandledObject][ObjectHandle]") WHEN("We copy construct") { - Test other(test); - Nz::ObjectHandle otherHandle = other.CreateHandle(); + ObjectHandle_Test other(test); + Nz::ObjectHandle otherHandle = other.CreateHandle(); THEN("Handles should point to 1") { @@ -54,8 +50,8 @@ SCENARIO("Handle", "[CORE][HandledObject][ObjectHandle]") WHEN("We move construct") { - Test other(std::move(test)); - Nz::ObjectHandle otherHandle = other.CreateHandle(); + ObjectHandle_Test other(std::move(test)); + Nz::ObjectHandle otherHandle = other.CreateHandle(); THEN("Handles should point to 1") { @@ -69,8 +65,8 @@ SCENARIO("Handle", "[CORE][HandledObject][ObjectHandle]") WHEN("We copy assign") { int copyValue = 3; - Test other(copyValue); - Nz::ObjectHandle otherHandle = other.CreateHandle(); + ObjectHandle_Test other(copyValue); + Nz::ObjectHandle otherHandle = other.CreateHandle(); test = other; THEN("Handles should point to 3") @@ -86,8 +82,8 @@ SCENARIO("Handle", "[CORE][HandledObject][ObjectHandle]") WHEN("We move assign") { int moveValue = 4; - Test other(moveValue); - Nz::ObjectHandle otherHandle = other.CreateHandle(); + ObjectHandle_Test other(moveValue); + Nz::ObjectHandle otherHandle = other.CreateHandle(); test = std::move(other); 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") { - Test test(1); - Nz::ObjectHandle invalidHandle(&test); + ObjectHandle_Test test(1); + Nz::ObjectHandle invalidHandle(&test); WHEN("We bind it to a HandledObject which is going to die") { { - Test dyingTest(5); + ObjectHandle_Test dyingTest(5); invalidHandle.Reset(&dyingTest); } @@ -125,10 +121,10 @@ SCENARIO("Handle", "[CORE][HandledObject][ObjectHandle]") GIVEN("Two handle pointing to two different tests") { - Test test1(1); - Nz::ObjectHandle test1Handle = test1.CreateHandle(); - Test test2(2); - Nz::ObjectHandle test2Handle = test2.CreateHandle(); + ObjectHandle_Test test1(1); + Nz::ObjectHandle test1Handle = test1.CreateHandle(); + ObjectHandle_Test test2(2); + Nz::ObjectHandle test2Handle = test2.CreateHandle(); WHEN("We swap their content") { diff --git a/tests/Engine/Lua/LuaClass.cpp b/tests/Engine/Lua/LuaClass.cpp index b6963a3bd..5cddb3cb1 100644 --- a/tests/Engine/Lua/LuaClass.cpp +++ b/tests/Engine/Lua/LuaClass.cpp @@ -3,15 +3,15 @@ #include #include -class Test +class LuaClass_Test { public: - Test() = default; - Test(const Test& other) = default; - Test& operator=(const Test& other) = default; - virtual ~Test() = default; + LuaClass_Test() = default; + LuaClass_Test(const LuaClass_Test& other) = default; + LuaClass_Test& operator=(const LuaClass_Test& other) = default; + virtual ~LuaClass_Test() = default; - Test(int i, bool j = false) : + LuaClass_Test(int i, bool j = false) : m_i(i), m_j(j) { @@ -42,21 +42,21 @@ class Test bool m_j; }; -class InheritTest : public Test +class LuaClass_InheritTest : public LuaClass_Test { public: - InheritTest() : - Test(5, true) + LuaClass_InheritTest() : + LuaClass_Test(5, true) { } int GetI() const override { - return Test::GetI() + 3; + return LuaClass_Test::GetI() + 3; } }; -class TestWithHandle : public Nz::HandledObject +class LuaClass_TestWithHandle : public Nz::HandledObject { public: int GetI() const @@ -73,24 +73,24 @@ class TestWithHandle : public Nz::HandledObject int m_i = 8; }; -inline unsigned int LuaImplQueryArg(const Nz::LuaState& instance, int index, Test* arg, Nz::TypeTag) +inline unsigned int LuaImplQueryArg(const Nz::LuaState& instance, int index, LuaClass_Test* arg, Nz::TypeTag) { REQUIRE(instance.IsOfType(index, "Test")); - *arg = *static_cast(instance.ToUserdata(index)); + *arg = *static_cast(instance.ToUserdata(index)); return 1; } -inline unsigned int LuaImplQueryArg(const Nz::LuaState& instance, int index, Nz::ObjectHandle* arg, Nz::TypeTag>) +inline unsigned int LuaImplQueryArg(const Nz::LuaState& instance, int index, Nz::ObjectHandle* arg, Nz::TypeTag>) { REQUIRE(instance.IsOfType(index, "TestWithHandle")); - *arg = *static_cast*>(instance.ToUserdata(index)); + *arg = *static_cast*>(instance.ToUserdata(index)); return 1; } -inline unsigned int LuaImplQueryArg(const Nz::LuaState& instance, int index, InheritTest* arg, Nz::TypeTag) +inline unsigned int LuaImplQueryArg(const Nz::LuaState& instance, int index, LuaClass_InheritTest* arg, Nz::TypeTag) { REQUIRE(instance.IsOfType(index, "InheritTest")); - *arg = *static_cast(instance.ToUserdata(index)); + *arg = *static_cast(instance.ToUserdata(index)); return 1; } @@ -99,9 +99,9 @@ SCENARIO("LuaClass", "[LUA][LUACLASS]") GIVEN("One lua class for our Test class") { Nz::LuaInstance luaInstance; - Nz::LuaClass test; - Nz::LuaClass inheritTest; - using TestHandle = Nz::ObjectHandle; + Nz::LuaClass test; + Nz::LuaClass inheritTest; + using TestHandle = Nz::ObjectHandle; Nz::LuaClass testHandle; WHEN("We bind the methods") @@ -110,7 +110,7 @@ SCENARIO("LuaClass", "[LUA][LUACLASS]") 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(argumentCount, 2U); @@ -139,14 +139,14 @@ SCENARIO("LuaClass", "[LUA][LUACLASS]") return false; }); - test.BindMethod("GetI", &Test::GetI); - test.BindMethod("GetJ", &Test::GetJ); - test.BindMethod("GetDefault", &Test::GetDefault, 0); + test.BindMethod("GetI", &LuaClass_Test::GetI); + test.BindMethod("GetJ", &LuaClass_Test::GetJ); + test.BindMethod("GetDefault", &LuaClass_Test::GetDefault, 0); test.BindStaticMethod("StaticMethodWithArguments", [] (Nz::LuaState& state) -> int { int argIndex = 1; - int result = Test::StaticMethodWithArguments(state.Check(&argIndex), state.Check(&argIndex)); + int result = LuaClass_Test::StaticMethodWithArguments(state.Check(&argIndex), state.Check(&argIndex)); state.Push(result); return 1; @@ -162,7 +162,7 @@ SCENARIO("LuaClass", "[LUA][LUACLASS]") luaInstance.PushFunction([=](Nz::LuaState& state) -> int { int argIndex = 1; - Test result = state.Check(&argIndex); + LuaClass_Test result = state.Check(&argIndex); CHECK(result.GetI() == value); CHECK_FALSE(result.GetJ()); return 1; @@ -181,7 +181,7 @@ SCENARIO("LuaClass", "[LUA][LUACLASS]") luaInstance.PushFunction([=](Nz::LuaState& state) -> int { int argIndex = 1; - Test result = state.Check(&argIndex); + LuaClass_Test result = state.Check(&argIndex); CHECK(result.GetI() == staticResult); CHECK(result.GetJ()); return 1; @@ -205,7 +205,7 @@ SCENARIO("LuaClass", "[LUA][LUACLASS]") luaInstance.PushFunction([=](Nz::LuaState& state) -> int { int argIndex = 1; - InheritTest result = state.Check(&argIndex); + LuaClass_InheritTest result = state.Check(&argIndex); CHECK(result.GetI() == 8); CHECK(result.GetJ()); return 1; @@ -224,8 +224,8 @@ SCENARIO("LuaClass", "[LUA][LUACLASS]") testHandle.Reset("TestHandle"); testHandle.BindMethod("IsValid", &TestHandle::IsValid); - testHandle.BindMethod("GetI", &TestWithHandle::GetI); - testHandle.BindMethod("GetDefault", &TestWithHandle::GetDefault, defaultValue); + testHandle.BindMethod("GetI", &LuaClass_TestWithHandle::GetI); + testHandle.BindMethod("GetDefault", &LuaClass_TestWithHandle::GetDefault, defaultValue); testHandle.Register(luaInstance); THEN("We can ensure the following properties")