mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 00:02:55 +00:00
Change cpp unit test framework to catch2 for all cpp unit test projects
This commit is contained in:
parent
7ff87c2b73
commit
b4f1e09315
@ -23,16 +23,16 @@ class AssetStructTestsTemplate::Internal
|
||||
|
||||
void TestMethod(StructureInformation* structure)
|
||||
{
|
||||
if (structure->m_non_embedded_reference_exists)
|
||||
{
|
||||
LINE("TEST_METHOD(Test_"<<structure->m_definition->m_name<<")");
|
||||
/*if (structure->m_non_embedded_reference_exists)
|
||||
{*/
|
||||
LINE("TEST_CASE(\""<<m_env.m_game<<"::"<<m_env.m_asset->m_definition->GetFullName()<<": Tests for "<<structure->m_definition->GetFullName()<<"\", \"[assetstruct]\")");
|
||||
LINE("{");
|
||||
m_intendation++;
|
||||
LINE("Assert::AreEqual("<<structure->m_definition->GetSize()<<"u, sizeof("<<structure->m_definition->GetFullName()<<"));");
|
||||
LINE("Assert::AreEqual("<<structure->m_definition->GetAlignment()<<"u, alignof("<<structure->m_definition->GetFullName()<<"));");
|
||||
LINE("REQUIRE("<<structure->m_definition->GetSize()<<"u == sizeof("<<structure->m_definition->GetFullName()<<"));");
|
||||
LINE("REQUIRE("<<structure->m_definition->GetAlignment()<<"u == alignof("<<structure->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 <catch2/catch.hpp>");
|
||||
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_env.m_game<<"::xassets::asset_"<<m_env.m_asset->m_definition->m_name);
|
||||
LINE("{");
|
||||
m_intendation++;
|
||||
LINE("TEST_CLASS(AssetStructTest_"<<m_env.m_asset->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("}");
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -1,22 +1,17 @@
|
||||
#include "CppUnitTest.h"
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
#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<unsigned int>(ImageFormatId::MAX), _countof(ImageFormat::ALL_FORMATS));
|
||||
REQUIRE(static_cast<unsigned int>(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<unsigned>(ImageFormat::ALL_FORMATS[i]->GetId()));
|
||||
REQUIRE(ImageFormat::ALL_FORMATS[i] != nullptr);
|
||||
REQUIRE(i == static_cast<unsigned>(ImageFormat::ALL_FORMATS[i]->GetId()));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
2
test/ObjCommonTests/main.cpp
Normal file
2
test/ObjCommonTests/main.cpp
Normal file
@ -0,0 +1,2 @@
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include <catch2/catch.hpp>
|
@ -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()
|
||||
|
||||
|
2
test/ZoneCommonTests/main.cpp
Normal file
2
test/ZoneCommonTests/main.cpp
Normal file
@ -0,0 +1,2 @@
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include <catch2/catch.hpp>
|
Loading…
x
Reference in New Issue
Block a user