From b4f1e0931512023b1c08e3cf2c14c52e953360d5 Mon Sep 17 00:00:00 2001 From: Jan Date: Sat, 20 Feb 2021 10:44:33 +0100 Subject: [PATCH] Change cpp unit test framework to catch2 for all cpp unit test projects --- .../Templates/AssetStructTestsTemplate.cpp | 23 ++++++----------- test/ObjCommonTests.lua | 19 ++++++++++---- .../ObjCommonTests/Image/ImageFormatTests.cpp | 25 ++++++++----------- test/ObjCommonTests/main.cpp | 2 ++ test/ZoneCommonTests.lua | 19 ++++++++++---- test/ZoneCommonTests/.gitkeep | 0 test/ZoneCommonTests/main.cpp | 2 ++ 7 files changed, 50 insertions(+), 40 deletions(-) create mode 100644 test/ObjCommonTests/main.cpp delete mode 100644 test/ZoneCommonTests/.gitkeep create mode 100644 test/ZoneCommonTests/main.cpp diff --git a/src/ZoneCodeGeneratorLib/Generating/Templates/AssetStructTestsTemplate.cpp b/src/ZoneCodeGeneratorLib/Generating/Templates/AssetStructTestsTemplate.cpp index 32bfb09e..7ef35e41 100644 --- a/src/ZoneCodeGeneratorLib/Generating/Templates/AssetStructTestsTemplate.cpp +++ b/src/ZoneCodeGeneratorLib/Generating/Templates/AssetStructTestsTemplate.cpp @@ -23,16 +23,16 @@ class AssetStructTestsTemplate::Internal void TestMethod(StructureInformation* structure) { - if (structure->m_non_embedded_reference_exists) - { - LINE("TEST_METHOD(Test_"<m_definition->m_name<<")"); + /*if (structure->m_non_embedded_reference_exists) + {*/ + LINE("TEST_CASE(\""<m_definition->GetFullName()<<": Tests for "<m_definition->GetFullName()<<"\", \"[assetstruct]\")"); LINE("{"); m_intendation++; - LINE("Assert::AreEqual("<m_definition->GetSize()<<"u, sizeof("<m_definition->GetFullName()<<"));"); - LINE("Assert::AreEqual("<m_definition->GetAlignment()<<"u, alignof("<m_definition->GetFullName()<<"));"); + LINE("REQUIRE("<m_definition->GetSize()<<"u == sizeof("<m_definition->GetFullName()<<"));"); + LINE("REQUIRE("<m_definition->GetAlignment()<<"u == alignof("<m_definition->GetFullName()<<"));"); m_intendation--; LINE("}"); - } + /*}*/ } public: @@ -51,19 +51,14 @@ public: LINE("// Any changes will be discarded when regenerating."); LINE("// ===================================================================="); LINE(""); - LINE("#include \"CppUnitTest.h\""); + LINE("#include "); LINE("#include \"Game/" << m_env.m_game << "/" << m_env.m_game << ".h\""); LINE(""); - LINE("using namespace Microsoft::VisualStudio::CppUnitTestFramework;"); LINE("using namespace " << m_env.m_game << ";"); LINE(""); - LINE("namespace ZoneCommonTests"); + LINE("namespace game::"<m_definition->m_name); LINE("{"); m_intendation++; - LINE("TEST_CLASS(AssetStructTest_"<m_definition->m_name<<")"); - LINE("{"); - LINE("public:"); - m_intendation++; TestMethod(m_env.m_asset); for (auto* structure : m_env.m_used_structures) @@ -73,8 +68,6 @@ public: TestMethod(structure->m_info); } - m_intendation--; - LINE("};"); m_intendation--; LINE("}"); } diff --git a/test/ObjCommonTests.lua b/test/ObjCommonTests.lua index 91b5c1ce..7106f9aa 100644 --- a/test/ObjCommonTests.lua +++ b/test/ObjCommonTests.lua @@ -1,12 +1,16 @@ ObjCommonTests = {} function ObjCommonTests:include() - + if References:include(self:name()) then + includedirs { + path.join(TestFolder(), "ObjCommonTests") + } + end end function ObjCommonTests:link() - if References:link("ObjCommonTests") then - links "ObjCommonTests" + if References:link(self:name()) then + links(self:name()) end end @@ -14,14 +18,18 @@ function ObjCommonTests:use() end +function ObjCommonTests:name() + return "ObjCommonTests" +end + function ObjCommonTests:project() References:reset() local folder = TestFolder(); - project "ObjCommonTests" + project(self:name()) targetdir(TargetDirectoryTest) location "%{wks.location}/test/%{prj.name}" - kind "SharedLib" + kind "ConsoleApp" language "C++" files { @@ -38,6 +46,7 @@ function ObjCommonTests:project() self:include() ObjCommon:include() + catch2:include() ObjCommon:link() end diff --git a/test/ObjCommonTests/Image/ImageFormatTests.cpp b/test/ObjCommonTests/Image/ImageFormatTests.cpp index 6acbc169..9baef30f 100644 --- a/test/ObjCommonTests/Image/ImageFormatTests.cpp +++ b/test/ObjCommonTests/Image/ImageFormatTests.cpp @@ -1,22 +1,17 @@ -#include "CppUnitTest.h" +#include + #include "Image/ImageFormat.h" -using namespace Microsoft::VisualStudio::CppUnitTestFramework; - -namespace ObjCommonTests +namespace image::image_format { - TEST_CLASS(ImageFormatTests) + TEST_CASE("ImageFormat: EnsureAllFormatsArrayIndicesAreIds", "[image]") { - public: - TEST_METHOD(EnsureAllFormatsArrayIndicesAreIds) - { - Assert::AreEqual(static_cast(ImageFormatId::MAX), _countof(ImageFormat::ALL_FORMATS)); + REQUIRE(static_cast(ImageFormatId::MAX) == _countof(ImageFormat::ALL_FORMATS)); - for(unsigned i = 0; i < _countof(ImageFormat::ALL_FORMATS); i++) - { - Assert::IsNotNull(ImageFormat::ALL_FORMATS[i]); - Assert::AreEqual(i, static_cast(ImageFormat::ALL_FORMATS[i]->GetId())); - } + for(unsigned i = 0; i < _countof(ImageFormat::ALL_FORMATS); i++) + { + REQUIRE(ImageFormat::ALL_FORMATS[i] != nullptr); + REQUIRE(i == static_cast(ImageFormat::ALL_FORMATS[i]->GetId())); } - }; + } } \ No newline at end of file diff --git a/test/ObjCommonTests/main.cpp b/test/ObjCommonTests/main.cpp new file mode 100644 index 00000000..2380d6bf --- /dev/null +++ b/test/ObjCommonTests/main.cpp @@ -0,0 +1,2 @@ +#define CATCH_CONFIG_MAIN +#include \ No newline at end of file diff --git a/test/ZoneCommonTests.lua b/test/ZoneCommonTests.lua index cb6c0f78..146d8ccf 100644 --- a/test/ZoneCommonTests.lua +++ b/test/ZoneCommonTests.lua @@ -1,12 +1,16 @@ ZoneCommonTests = {} function ZoneCommonTests:include() - + if References:include(self:name()) then + includedirs { + path.join(TestFolder(), "ZoneCommonTests") + } + end end function ZoneCommonTests:link() - if References:link("ZoneCommonTests") then - links "ZoneCommonTests" + if References:link(self:name()) then + links(self:name()) end end @@ -14,14 +18,18 @@ function ZoneCommonTests:use() end +function ZoneCommonTests:name() + return "ZoneCommonTests" +end + function ZoneCommonTests:project() References:reset() local folder = TestFolder(); - project "ZoneCommonTests" + project(self:name()) targetdir(TargetDirectoryTest) location "%{wks.location}/test/%{prj.name}" - kind "SharedLib" + kind "ConsoleApp" language "C++" files { @@ -39,6 +47,7 @@ function ZoneCommonTests:project() self:include() ZoneCommon:include() + catch2:include() ZoneCommon:link() diff --git a/test/ZoneCommonTests/.gitkeep b/test/ZoneCommonTests/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/test/ZoneCommonTests/main.cpp b/test/ZoneCommonTests/main.cpp new file mode 100644 index 00000000..2380d6bf --- /dev/null +++ b/test/ZoneCommonTests/main.cpp @@ -0,0 +1,2 @@ +#define CATCH_CONFIG_MAIN +#include \ No newline at end of file