mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-19 15:52:53 +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)
|
void TestMethod(StructureInformation* structure)
|
||||||
{
|
{
|
||||||
if (structure->m_non_embedded_reference_exists)
|
/*if (structure->m_non_embedded_reference_exists)
|
||||||
{
|
{*/
|
||||||
LINE("TEST_METHOD(Test_"<<structure->m_definition->m_name<<")");
|
LINE("TEST_CASE(\""<<m_env.m_game<<"::"<<m_env.m_asset->m_definition->GetFullName()<<": Tests for "<<structure->m_definition->GetFullName()<<"\", \"[assetstruct]\")");
|
||||||
LINE("{");
|
LINE("{");
|
||||||
m_intendation++;
|
m_intendation++;
|
||||||
LINE("Assert::AreEqual("<<structure->m_definition->GetSize()<<"u, sizeof("<<structure->m_definition->GetFullName()<<"));");
|
LINE("REQUIRE("<<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->GetAlignment()<<"u == alignof("<<structure->m_definition->GetFullName()<<"));");
|
||||||
m_intendation--;
|
m_intendation--;
|
||||||
LINE("}");
|
LINE("}");
|
||||||
}
|
/*}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -51,19 +51,14 @@ public:
|
|||||||
LINE("// Any changes will be discarded when regenerating.");
|
LINE("// Any changes will be discarded when regenerating.");
|
||||||
LINE("// ====================================================================");
|
LINE("// ====================================================================");
|
||||||
LINE("");
|
LINE("");
|
||||||
LINE("#include \"CppUnitTest.h\"");
|
LINE("#include <catch2/catch.hpp>");
|
||||||
LINE("#include \"Game/" << m_env.m_game << "/" << m_env.m_game << ".h\"");
|
LINE("#include \"Game/" << m_env.m_game << "/" << m_env.m_game << ".h\"");
|
||||||
LINE("");
|
LINE("");
|
||||||
LINE("using namespace Microsoft::VisualStudio::CppUnitTestFramework;");
|
|
||||||
LINE("using namespace " << m_env.m_game << ";");
|
LINE("using namespace " << m_env.m_game << ";");
|
||||||
LINE("");
|
LINE("");
|
||||||
LINE("namespace ZoneCommonTests");
|
LINE("namespace game::"<<m_env.m_game<<"::xassets::asset_"<<m_env.m_asset->m_definition->m_name);
|
||||||
LINE("{");
|
LINE("{");
|
||||||
m_intendation++;
|
m_intendation++;
|
||||||
LINE("TEST_CLASS(AssetStructTest_"<<m_env.m_asset->m_definition->m_name<<")");
|
|
||||||
LINE("{");
|
|
||||||
LINE("public:");
|
|
||||||
m_intendation++;
|
|
||||||
|
|
||||||
TestMethod(m_env.m_asset);
|
TestMethod(m_env.m_asset);
|
||||||
for (auto* structure : m_env.m_used_structures)
|
for (auto* structure : m_env.m_used_structures)
|
||||||
@ -73,8 +68,6 @@ public:
|
|||||||
TestMethod(structure->m_info);
|
TestMethod(structure->m_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_intendation--;
|
|
||||||
LINE("};");
|
|
||||||
m_intendation--;
|
m_intendation--;
|
||||||
LINE("}");
|
LINE("}");
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
ObjCommonTests = {}
|
ObjCommonTests = {}
|
||||||
|
|
||||||
function ObjCommonTests:include()
|
function ObjCommonTests:include()
|
||||||
|
if References:include(self:name()) then
|
||||||
|
includedirs {
|
||||||
|
path.join(TestFolder(), "ObjCommonTests")
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ObjCommonTests:link()
|
function ObjCommonTests:link()
|
||||||
if References:link("ObjCommonTests") then
|
if References:link(self:name()) then
|
||||||
links "ObjCommonTests"
|
links(self:name())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -14,14 +18,18 @@ function ObjCommonTests:use()
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ObjCommonTests:name()
|
||||||
|
return "ObjCommonTests"
|
||||||
|
end
|
||||||
|
|
||||||
function ObjCommonTests:project()
|
function ObjCommonTests:project()
|
||||||
References:reset()
|
References:reset()
|
||||||
local folder = TestFolder();
|
local folder = TestFolder();
|
||||||
|
|
||||||
project "ObjCommonTests"
|
project(self:name())
|
||||||
targetdir(TargetDirectoryTest)
|
targetdir(TargetDirectoryTest)
|
||||||
location "%{wks.location}/test/%{prj.name}"
|
location "%{wks.location}/test/%{prj.name}"
|
||||||
kind "SharedLib"
|
kind "ConsoleApp"
|
||||||
language "C++"
|
language "C++"
|
||||||
|
|
||||||
files {
|
files {
|
||||||
@ -38,6 +46,7 @@ function ObjCommonTests:project()
|
|||||||
|
|
||||||
self:include()
|
self:include()
|
||||||
ObjCommon:include()
|
ObjCommon:include()
|
||||||
|
catch2:include()
|
||||||
|
|
||||||
ObjCommon:link()
|
ObjCommon:link()
|
||||||
end
|
end
|
||||||
|
@ -1,22 +1,17 @@
|
|||||||
#include "CppUnitTest.h"
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
#include "Image/ImageFormat.h"
|
#include "Image/ImageFormat.h"
|
||||||
|
|
||||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
namespace image::image_format
|
||||||
|
|
||||||
namespace ObjCommonTests
|
|
||||||
{
|
{
|
||||||
TEST_CLASS(ImageFormatTests)
|
TEST_CASE("ImageFormat: EnsureAllFormatsArrayIndicesAreIds", "[image]")
|
||||||
{
|
{
|
||||||
public:
|
REQUIRE(static_cast<unsigned int>(ImageFormatId::MAX) == _countof(ImageFormat::ALL_FORMATS));
|
||||||
TEST_METHOD(EnsureAllFormatsArrayIndicesAreIds)
|
|
||||||
{
|
|
||||||
Assert::AreEqual(static_cast<unsigned int>(ImageFormatId::MAX), _countof(ImageFormat::ALL_FORMATS));
|
|
||||||
|
|
||||||
for(unsigned i = 0; i < _countof(ImageFormat::ALL_FORMATS); i++)
|
for(unsigned i = 0; i < _countof(ImageFormat::ALL_FORMATS); i++)
|
||||||
{
|
{
|
||||||
Assert::IsNotNull(ImageFormat::ALL_FORMATS[i]);
|
REQUIRE(ImageFormat::ALL_FORMATS[i] != nullptr);
|
||||||
Assert::AreEqual(i, static_cast<unsigned>(ImageFormat::ALL_FORMATS[i]->GetId()));
|
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 = {}
|
ZoneCommonTests = {}
|
||||||
|
|
||||||
function ZoneCommonTests:include()
|
function ZoneCommonTests:include()
|
||||||
|
if References:include(self:name()) then
|
||||||
|
includedirs {
|
||||||
|
path.join(TestFolder(), "ZoneCommonTests")
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ZoneCommonTests:link()
|
function ZoneCommonTests:link()
|
||||||
if References:link("ZoneCommonTests") then
|
if References:link(self:name()) then
|
||||||
links "ZoneCommonTests"
|
links(self:name())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -14,14 +18,18 @@ function ZoneCommonTests:use()
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ZoneCommonTests:name()
|
||||||
|
return "ZoneCommonTests"
|
||||||
|
end
|
||||||
|
|
||||||
function ZoneCommonTests:project()
|
function ZoneCommonTests:project()
|
||||||
References:reset()
|
References:reset()
|
||||||
local folder = TestFolder();
|
local folder = TestFolder();
|
||||||
|
|
||||||
project "ZoneCommonTests"
|
project(self:name())
|
||||||
targetdir(TargetDirectoryTest)
|
targetdir(TargetDirectoryTest)
|
||||||
location "%{wks.location}/test/%{prj.name}"
|
location "%{wks.location}/test/%{prj.name}"
|
||||||
kind "SharedLib"
|
kind "ConsoleApp"
|
||||||
language "C++"
|
language "C++"
|
||||||
|
|
||||||
files {
|
files {
|
||||||
@ -39,6 +47,7 @@ function ZoneCommonTests:project()
|
|||||||
|
|
||||||
self:include()
|
self:include()
|
||||||
ZoneCommon:include()
|
ZoneCommon:include()
|
||||||
|
catch2:include()
|
||||||
|
|
||||||
ZoneCommon:link()
|
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