Google testing works now

This commit is contained in:
Thorben Höhne 2025-02-19 21:11:42 +01:00
parent 53dac3537e
commit 61189bdc73
14 changed files with 176 additions and 50 deletions

Binary file not shown.

32
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,32 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug MathTestFPU (gdb)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/1.0.0/Debug/MathTestFPU/MathTestFPU",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}

47
.vscode/settings.json vendored
View File

@ -102,4 +102,51 @@
"__SSE__",
],
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"editor.tokenColorCustomizations": {
"[*Light*]": {
"textMateRules": [
{
"scope": "ref.matchtext",
"settings": {
"foreground": "#000"
}
}
]
},
"[*Dark*]": {
"textMateRules": [
{
"scope": "ref.matchtext",
"settings": {
"foreground": "#fff"
}
}
]
},
"textMateRules": [
{
"scope": "googletest.failed",
"settings": {
"foreground": "#f00"
}
},
{
"scope": "googletest.passed",
"settings": {
"foreground": "#0f0"
}
},
{
"scope": "googletest.run",
"settings": {
"foreground": "#0f0"
}
}
]
},
"gtest-adapter.debugConfig": [
"Debug MathTestFPU (gdb)"
],
"gtest-adapter.supportLocation": true,
"premake.version": "Premake 5.0-beta5",
}

View File

@ -175,8 +175,8 @@ namespace Phanes::Core::Math::Detail
static constexpr bool map(const Phanes::Core::Math::TVector2<T, S>& v1, const Phanes::Core::Math::TVector2<T, S>& v2)
{
return (Phanes::Core::Math::Abs(v1.x - v2.x) < P_FLT_INAC &&
Phanes::Core::Math::Abs(v1.y - v2.y) < P_FLT_INAC);
return (Phanes::Core::Math::Abs(v1.x - v2.x) <= P_FLT_INAC &&
Phanes::Core::Math::Abs(v1.y - v2.y) <= P_FLT_INAC);
}
};

View File

@ -707,7 +707,7 @@ namespace Phanes::Core::Math {
*/
template<RealType T, bool S>
TVector3<T, S>& ClampToCubeV(TVector3<T, S> v1, T cubeRadius);
TVector3<T, S>& ClampToCubeV(TVector3<T, S>& v1, T cubeRadius);
/**
* Rotates vector around axis

View File

@ -292,7 +292,7 @@ namespace Phanes::Core::Math
}
template<RealType T, bool S>
TVector3<T, S>& ClampToCubeV(TVector3<T, S> v1, T cubeRadius)
TVector3<T, S>& ClampToCubeV(TVector3<T, S>& v1, T cubeRadius)
{
Detail::compute_vec3_clamp<T, S>::map(v1, v1, cubeRadius);
return v1;

View File

@ -0,0 +1,7 @@
//
// pch.h
//
#pragma once
#include "googletest/googletest/include/gtest/gtest.h"

View File

@ -0,0 +1,39 @@
project "gtest"
language "C++"
kind "StaticLib"
third_party_boilerplate()
includedirs {
PhanesThirdParty .. "/googletest/googletest/include",
PhanesThirdParty .. "/googletest/googletest/include/gtest",
PhanesThirdParty .. "/googletest/googletest"
}
files {
PhanesThirdParty .. "/googletest/googletest/src/**.cc",
PhanesThirdParty .. "/googletest/googletest/include/gtest/**.h"
}
project "MathTestFPU"
kind "ConsoleApp"
boilerplate()
files {
PhanesRuntime .. "/Core/Tests/Math/MathTestFPU/test.cpp"
}
buildoptions {"-Wno-unused-variable", "-w", "-fpermissive"}
pchheader (PhanesRuntime .. "/Core/Tests/Math/MathTestFPU/pch.h")
pchsource (PhanesRuntime .. "/Core/Tests/Math/MathTestFPU/pch.cpp")
links { "gtest" }
dependson { "gtest" }
includedirs {
PhanesRuntime .. "/Core/Tests/Math/MathTestFPU",
PhanesThirdParty .. "/googletest/googletest/include",
PhanesThirdParty,
PhanesRuntime
}

View File

@ -740,7 +740,8 @@ namespace VectorTests
EXPECT_TRUE(PMath::CompInverseV(v0) == PMath::Vector3(1.0f / 2.4f, 1.0f / 3.1f, 1.0f / 5.6f));
v0 = PMath::Vector3(2.4f, 3.1f, 5.6f);
EXPECT_TRUE(PMath::ClampToCubeV(v0, 3.2f) == PMath::Vector3(2.4f, 3.1f, 3.2f));
PMath::Vector3 test = PMath::ClampToCubeV(v0, 3.2f);
EXPECT_TRUE(test == PMath::Vector3(2.4f, 3.1f, 3.2f));
v0 = PMath::Vector3(2.4f, 3.1f, 5.6f);
EXPECT_TRUE(PMath::RotateAroundAxisV(v0, PMath::Vector3(0.0f, 0.0f, 1.0f), (float)30.0_deg) == PMath::Vector3(3.628461f, 1.484679f, 5.600000f)) << PMath::ToString(PMath::RotateAroundAxisV(v0, PMath::Vector3(0.0f, 0.0f, 1.0f), (float)30.0_deg));
@ -933,16 +934,16 @@ namespace MatrixTests
PMath::Matrix2 m0 = PMath::Matrix2(1.0f, 5.0f, 3.0f, 2.0f);
m0 += 2.0f;
EXPECT_TRUE(m0 == PMath::Matrix2(3.0f, 7.0f, 5.0f, 4.0f));
EXPECT_TRUE(m0 == PMath::Matrix2(3.0f, 7.0f, 5.0f, 4.0f)) << PMath::ToString(m0);
m0 -= 2.0f;
EXPECT_TRUE(m0 == PMath::Matrix2(1.0f, 5.0f, 3.0f, 2.0f));
EXPECT_TRUE(m0 == PMath::Matrix2(1.0f, 5.0f, 3.0f, 2.0f)) << PMath::ToString(m0);
m0 *= 2.0f;
EXPECT_TRUE(m0 == PMath::Matrix2(2.0f, 10.0f, 6.0f, 4.0f));
EXPECT_TRUE(m0 == PMath::Matrix2(2.0f, 10.0f, 6.0f, 4.0f)) << PMath::ToString(m0);
m0 /= 2.0f;
EXPECT_TRUE(m0 == PMath::Matrix2(1.0f, 5.0f, 3.0f, 2.0f));
EXPECT_TRUE(m0 == PMath::Matrix2(1.0f, 5.0f, 3.0f, 2.0f)) << PMath::ToString(m0);
m0 = m0 + 2.0f;
@ -998,7 +999,7 @@ namespace MatrixTests
EXPECT_FLOAT_EQ(PMath::Determinant(m0), -13.0f);
EXPECT_TRUE(PMath::InverseV(m0) == PMath::Matrix2(-2.0f / 13.0f, 5.0f / 13.0f, 3.0f / 13.0f, -1.0f / 13.0f));
EXPECT_TRUE(PMath::InverseV(m0) == PMath::Matrix2(-2.0f / 13.0f, 5.0f / 13.0f, 3.0f / 13.0f, -1.0f / 13.0f)) << PMath::ToString(m0);
m0 = PMath::Matrix2(1.0f, 5.0f, 3.0f, 2.0f);
EXPECT_TRUE(PMath::TransposeV(m0) == PMath::Matrix2(1.0f, 3.0f, 5.0f, 2.0f));
@ -1269,4 +1270,11 @@ namespace Plane
PMath::Plane pl2 = PMath::Plane(-0.526316f, -0.442105f, -0.726316f, 6.0f);
}
}
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -1,7 +0,0 @@
//
// pch.h
//
#pragma once
#include "gtest/gtest.h"

View File

@ -1,29 +0,0 @@
project "MathTestFPU"
kind "ConsoleApp"
boilerplate()
files {
phanesRoot .. "/MathTestFPU/test.cpp"
}
buildoptions {"-Wno-unused-variable", "-w", "-fpermissive"}
pchheader "pch.h"
pchsource "pch.cpp"
includedirs {
phanesRoot .. "/MathTestFPU",
PhanesRuntime
}
project "Test"
kind "ConsoleApp"
boilerplate()
files {
phanesRoot .. "/MathTestFPU/main.cpp"
}
includedirs {
PhanesRuntime
}

View File

@ -33,7 +33,8 @@ workspace "PhanesEngine"
toolset "gcc"
flags { "MultiProcessorCompile" }
clangtidy "On"
llvmversion "19.0"
debugger "gdb"
startproject "MathTestFPU"
configurations { "Debug", "Release" }
@ -62,6 +63,7 @@ function boilerplate()
if PLATFORM == "linux" then
defines { "P_LINUX_BUILD" }
buildoptions {"-Wall", "-Wextra", "-Werror"}
linux_sse()
buildoptions { "-Wno-unused-parameter" , "-fms-extensions" }
end
@ -81,6 +83,33 @@ function boilerplate()
filter{}
end
function third_party_boilerplate()
language "C++"
location (phanesBuildFiles .. "/%{prj.name}")
targetdir (phanesBin .. "/" .. VERSION .. "/%{cfg.buildcfg}/%{prj.name}")
objdir (phanesInt .. "/" .. VERSION .. "/%{cfg.buildcfg}/%{prj.name}")
if PLATFORM == "linux" then
buildoptions {"-Wall", "-Wextra", "-Werror"}
linux_sse()
end
filter "configurations:Debug"
defines { "DEBUG", "TRACE", "P_DEBUG"}
symbols "On"
buildmessage("Building %{prj.name} in debug mode")
filter "configurations:Release"
defines { "NDEBUG", "P_RELEASE" }
linktimeoptimization "On"
optimize "On"
intrinsics "On"
buildmessage("Building %{prj.name} in release mode")
filter{}
end
-- actions
function action_clean()
@ -97,6 +126,6 @@ newaction {
}
-- includeProjects here
include "Engine/Source/Runtime/Core/premake5.lua"
include "DevPlayground/premake5.lua"
include "MathTestFPU/premake5.lua"
include (phanesRoot .. "/Engine/Source/Runtime/Core/premake5.lua")
include (phanesRoot .. "/DevPlayground/premake5.lua")
include (PhanesRuntime .. "/Core/Tests/Math/MathTestFPU/premake5.lua")