Added catch2

This commit is contained in:
Antoine Pilote
2025-05-02 16:50:34 -04:00
parent 4aa33b6a20
commit 70141a7ee6
9 changed files with 26148 additions and 0 deletions

View File

@@ -85,6 +85,11 @@ namespace Nuake
cursor["file" + displayName] = value.file->GetRelativePath();
}
}
else if (dataType.type() == entt::resolve<std::string>())
{
std::string value = fieldVal.cast<std::string>();
cursor[displayName] = value;
}
}
return jsonSnippet;

10
Test/.runsettings Normal file
View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<Catch2Adapter>
<CombinedTimeout>30000</CombinedTimeout><!-- 30s in Milliseconds -->
<FilenameFilter>.*</FilenameFilter>
<DllRunnerCommandline>${catch2} ${dll}</DllRunnerCommandline>
</Catch2Adapter>
</RunSettings>

View File

@@ -0,0 +1,79 @@
#include "catch2/catch_amalgamated.hpp"
#include "Nuake/Scene/Components/Component.h"
#include "Nuake/Resource/Serializer/ComponentSerializer.h"
#include "entt/entt.hpp"
namespace Serialization
{
using namespace Nuake;
class TestData : public Component
{
NUAKECOMPONENT(TestData, "TestData");
public:
int myInt;
bool myBool;
std::string myString;
Vector2 myVec2;
Vector3 myVec3;
Vector4 myVec4;
static void InitializeComponentClass()
{
BindComponentField<&TestData::myInt>("myInt", "myInt");
BindComponentField<&TestData::myBool>("myBool", "myBool");
BindComponentField<&TestData::myString>("myString", "myString");
BindComponentField<&TestData::myVec2>("myVec2", "myVec2");
BindComponentField<&TestData::myVec3>("myVec3", "myVec3");
BindComponentField<&TestData::myVec4>("myVec4", "myVec4");
}
};
TEST_CASE("Serialize Struct", "[Serialization]")
{
// Initialize component
TestData::InternalInitializeClass();
TestData testData =
{
.myInt = 1337,
.myBool = true,
.myString = "Hello World",
.myVec2 = Vector2(1, 2),
.myVec3 = Vector3(3, 4, 5),
.myVec4 = Vector4(6, 7, 8, 9)
};
// Serialize into json
ComponentSerializer serializer;
json result = serializer.Serialize(testData);
// Test JSON result
REQUIRE(result.contains("TestData"));
REQUIRE(result["TestData"].contains("myInt"));
REQUIRE(result["TestData"]["myInt"] == testData.myInt);
REQUIRE(result["TestData"].contains("myBool"));
REQUIRE(result["TestData"]["myBool"] == testData.myBool);
REQUIRE(result["TestData"].contains("myString"));
REQUIRE(result["TestData"]["myString"] == testData.myString);
REQUIRE(result["TestData"].contains("myVec2"));
REQUIRE(result["TestData"]["myVec2"]["x"] == testData.myVec2.x);
REQUIRE(result["TestData"]["myVec2"]["y"] == testData.myVec2.y);
REQUIRE(result["TestData"].contains("myVec3"));
REQUIRE(result["TestData"]["myVec3"]["x"] == testData.myVec3.x);
REQUIRE(result["TestData"]["myVec3"]["y"] == testData.myVec3.y);
REQUIRE(result["TestData"]["myVec3"]["z"] == testData.myVec3.z);
REQUIRE(result["TestData"].contains("myVec4"));
REQUIRE(result["TestData"]["myVec4"]["x"] == testData.myVec4.x);
REQUIRE(result["TestData"]["myVec4"]["y"] == testData.myVec4.y);
REQUIRE(result["TestData"]["myVec4"]["z"] == testData.myVec4.z);
REQUIRE(result["TestData"]["myVec4"]["w"] == testData.myVec4.w);
}
}

View File

@@ -0,0 +1,24 @@
#include "catch2/catch_amalgamated.hpp"
#define CATCH_CONFIG_MAIN
#include "Engine.h"
namespace Engine
{
TEST_CASE("Window creation", "[window]")
{
Nuake::Engine::Init();
REQUIRE(Nuake::Engine::GetCurrentWindow() != nullptr);
}
TEST_CASE("Window shutdown", "[window]")
{
Nuake::Engine::Init();
Nuake::Engine::GetCurrentWindow()->Close();
REQUIRE(Nuake::Engine::GetCurrentWindow()->ShouldClose());
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,76 @@
project "NuakeTest"
kind "ConsoleApp"
staticruntime "On"
language "C++"
cppdialect "C++20"
defines
{
table.unpack(globalDefines),
"_MBCS",
"IMGUI_DEFINE_MATH_OPERATORS",
"NK_VK",
"IMGUI_IMPL_VULKAN_NO_PROTOTYPES"
}
targetdir (binaryOutputDir)
objdir (intBinaryOutputDir)
debugdir (binaryOutputDir)
files
{
-- Main Sources
"Source/**.cpp",
"Source/**.h",
"Vendors/**.h",
"Vendors/**.cpp",
}
includedirs
{
".",
"Source",
"Vendors",
"../../Nuake/Source",
"../../Nuake/Vendors",
"../../Nuake/Thirdparty/entt/src"
}
links
{
"Nuake",
"glad",
"GLFW",
"assimp",
"JoltPhysics",
"soloud",
"Coral.Native",
"DebugUtils",
"Detour",
"DetourCrowd",
"DetourTileCache",
"Recast",
"tracy",
"yoga",
"msdf-gen",
"msdf-atlas-gen",
"Freetype",
"vma"
}
filter { "system:windows", "action:vs*"}
flags
{
"MultiProcessorCompile",
}
filter "configurations:Debug"
runtime "Debug"
symbols "on"
buildoptions { "/Zi" }
filter "configurations:Release"
runtime "Release"
optimize "on"

1
Test/premake5.lua Normal file
View File

@@ -0,0 +1 @@
include "NuakeTest/premake5.lua"

View File

@@ -84,3 +84,4 @@ include "Runtime/premake5.lua"
include "NuakeNet/premake5.lua"
include "NuakeNetGenerator/premake5.lua"
include "EditorNet/premake5.lua"
include "Test/premake5.lua"