From c6226258dbb29ca24af923b3160b97c68fc783ae Mon Sep 17 00:00:00 2001 From: vittorioromeo Date: Thu, 13 Apr 2023 15:50:19 +0200 Subject: [PATCH] Improve test utility header compilation speed --- test/System/String.test.cpp | 1 + test/TestUtilities/GraphicsUtil.cpp | 21 ++++++++++++++ test/TestUtilities/GraphicsUtil.hpp | 16 ++++------ test/TestUtilities/SystemUtil.cpp | 45 ++++++++++++++++++++++++++++- test/TestUtilities/SystemUtil.hpp | 36 ++++++++++------------- 5 files changed, 86 insertions(+), 33 deletions(-) diff --git a/test/System/String.test.cpp b/test/System/String.test.cpp index f18ec0f4a..20cde7f7c 100644 --- a/test/System/String.test.cpp +++ b/test/System/String.test.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include diff --git a/test/TestUtilities/GraphicsUtil.cpp b/test/TestUtilities/GraphicsUtil.cpp index 10689554b..e5ea8ef4b 100644 --- a/test/TestUtilities/GraphicsUtil.cpp +++ b/test/TestUtilities/GraphicsUtil.cpp @@ -1,8 +1,10 @@ #include #include +#include #include #include +#include #include namespace sf @@ -28,6 +30,19 @@ std::ostream& operator<<(std::ostream& os, const Transform& transform) os << matrix[3] << ", " << matrix[7] << ", " << matrix[15]; return os; } + +template +std::ostream& operator<<(std::ostream& os, const Rect& rect) +{ + const auto flags = os.flags(); + setStreamPrecision(os, std::numeric_limits::max_digits10); + os << "(left=" << rect.left << ", top=" << rect.top << ", width=" << rect.width << ", height=" << rect.height << ")"; + os.flags(flags); + return os; +} + +template std::ostream& operator<<(std::ostream&, const Rect&); +template std::ostream& operator<<(std::ostream&, const Rect&); } // namespace sf bool operator==(const sf::Transform& lhs, const Approx& rhs) @@ -42,3 +57,9 @@ bool operator==(const sf::Transform& lhs, const Approx& rhs) lhs.getMatrix()[7] == Approx(rhs.value.getMatrix()[7]) && lhs.getMatrix()[15] == Approx(rhs.value.getMatrix()[15]); } + +template <> +std::ostream& operator<<(std::ostream& os, const Approx& approx) +{ + return os << approx.value; +} diff --git a/test/TestUtilities/GraphicsUtil.hpp b/test/TestUtilities/GraphicsUtil.hpp index 4b134356b..ea255922a 100644 --- a/test/TestUtilities/GraphicsUtil.hpp +++ b/test/TestUtilities/GraphicsUtil.hpp @@ -5,10 +5,8 @@ #pragma once -#include - #include -#include +#include #include namespace sf @@ -17,19 +15,15 @@ struct BlendMode; class Color; class Transform; +template +class Rect; + std::ostream& operator<<(std::ostream& os, const BlendMode& blendMode); std::ostream& operator<<(std::ostream& os, const Color& color); std::ostream& operator<<(std::ostream& os, const Transform& transform); template -std::ostream& operator<<(std::ostream& os, const Rect& rect) -{ - const auto flags = os.flags(); - os << std::fixed << std::setprecision(std::numeric_limits::max_digits10); - os << "(left=" << rect.left << ", top=" << rect.top << ", width=" << rect.width << ", height=" << rect.height << ")"; - os.flags(flags); - return os; -} +std::ostream& operator<<(std::ostream& os, const Rect& rect); } // namespace sf bool operator==(const sf::Transform& lhs, const Approx& rhs); diff --git a/test/TestUtilities/SystemUtil.cpp b/test/TestUtilities/SystemUtil.cpp index 2c7a349e7..d06789f09 100644 --- a/test/TestUtilities/SystemUtil.cpp +++ b/test/TestUtilities/SystemUtil.cpp @@ -1,16 +1,25 @@ #include #include #include +#include +#include #include #include +#include +#include namespace sf { +void setStreamPrecision(std::ostream& os, int maxDigits10) +{ + os << std::fixed << std::setprecision(maxDigits10); +} + std::ostream& operator<<(std::ostream& os, const Angle& angle) { - os << std::fixed << std::setprecision(std::numeric_limits::max_digits10); + setStreamPrecision(os, std::numeric_limits::max_digits10); return os << angle.asDegrees() << " deg"; } @@ -23,6 +32,28 @@ std::ostream& operator<<(std::ostream& os, Time time) { return os << time.asMicroseconds() << "us"; } + +template +std::ostream& operator<<(std::ostream& os, const Vector2& vector) +{ + setStreamPrecision(os, std::numeric_limits::max_digits10); + return os << "(" << vector.x << ", " << vector.y << ")"; +} + +template +std::ostream& operator<<(std::ostream& os, const Vector3& vector) +{ + setStreamPrecision(os, std::numeric_limits::max_digits10); + return os << "(" << vector.x << ", " << vector.y << ", " << vector.z << ")"; +} + +template std::ostream& operator<<(std::ostream&, const Vector2&); +template std::ostream& operator<<(std::ostream&, const Vector2&); +template std::ostream& operator<<(std::ostream&, const Vector2&); + +template std::ostream& operator<<(std::ostream&, const Vector3&); +template std::ostream& operator<<(std::ostream&, const Vector3&); +template std::ostream& operator<<(std::ostream&, const Vector3&); } // namespace sf bool operator==(const float& lhs, const Approx& rhs) @@ -44,3 +75,15 @@ bool operator==(const sf::Angle& lhs, const Approx& rhs) { return lhs.asDegrees() == Approx(rhs.value.asDegrees()); } + +template +std::ostream& operator<<(std::ostream& os, const Approx& approx) +{ + return os << approx.value; +} + +template std::ostream& operator<<(std::ostream&, const Approx&); +template std::ostream& operator<<(std::ostream&, const Approx&); +template std::ostream& operator<<(std::ostream&, const Approx>&); +template std::ostream& operator<<(std::ostream&, const Approx>&); +template std::ostream& operator<<(std::ostream&, const Approx&); diff --git a/test/TestUtilities/SystemUtil.hpp b/test/TestUtilities/SystemUtil.hpp index ec1982131..c5366816f 100644 --- a/test/TestUtilities/SystemUtil.hpp +++ b/test/TestUtilities/SystemUtil.hpp @@ -5,12 +5,7 @@ #pragma once -#include -#include - -#include -#include -#include +#include // String conversions for doctest framework namespace sf @@ -19,22 +14,23 @@ class Angle; class String; class Time; +template +class Vector2; + +template +class Vector3; + +void setStreamPrecision(std::ostream& os, int maxDigits10); + std::ostream& operator<<(std::ostream& os, const Angle& angle); std::ostream& operator<<(std::ostream& os, const String& string); std::ostream& operator<<(std::ostream& os, Time time); template -std::ostream& operator<<(std::ostream& os, const Vector2& vector) -{ - os << std::fixed << std::setprecision(std::numeric_limits::max_digits10); - return os << "(" << vector.x << ", " << vector.y << ")"; -} +std::ostream& operator<<(std::ostream& os, const Vector2& vector); template -std::ostream& operator<<(std::ostream& os, const Vector3& vector) -{ - return os << "(" << vector.x << ", " << vector.y << ", " << vector.z << ")"; -} +std::ostream& operator<<(std::ostream& os, const Vector3& vector); } // namespace sf //////////////////////////////////////////////////////////// @@ -48,16 +44,14 @@ struct Approx explicit Approx(const T& t) : value(t) { } + const T& value; }; bool operator==(const float& lhs, const Approx& rhs); -bool operator==(const sf::Vector2f& lhs, const Approx& rhs); -bool operator==(const sf::Vector3f& lhs, const Approx& rhs); +bool operator==(const sf::Vector2& lhs, const Approx>& rhs); +bool operator==(const sf::Vector3& lhs, const Approx>& rhs); bool operator==(const sf::Angle& lhs, const Approx& rhs); template -std::ostream& operator<<(std::ostream& os, const Approx& approx) -{ - return os << approx.value; -} +std::ostream& operator<<(std::ostream& os, const Approx& approx);