SFML/test/TestUtilities/SystemUtil.hpp

67 lines
1.8 KiB
C++
Raw Normal View History

// Header for SFML unit tests.
//
// For a new system module test case, include this header.
2023-01-18 12:51:08 +08:00
// This ensures that string conversions are visible and can be used by Catch2 for debug output.
#pragma once
2024-04-12 08:13:19 +08:00
#include <filesystem>
#include <iosfwd>
2024-04-12 08:13:19 +08:00
#include <vector>
#include <cstddef>
2023-01-18 12:51:08 +08:00
// String conversions for Catch2
namespace sf
{
2022-07-05 00:20:58 +08:00
class Angle;
class String;
class Time;
template <typename>
class Vector2;
template <typename>
class Vector3;
void setStreamPrecision(std::ostream& os, int maxDigits10);
2022-07-05 13:46:34 +08:00
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);
2022-07-05 00:20:58 +08:00
template <typename T>
std::ostream& operator<<(std::ostream& os, Vector2<T> vector);
2022-07-05 00:20:58 +08:00
template <typename T>
std::ostream& operator<<(std::ostream& os, const Vector3<T>& vector);
2022-07-05 00:20:58 +08:00
} // namespace sf
////////////////////////////////////////////////////////////
/// Class template for creating custom approximate comparisons.
/// To register a new type, simply implement a custom operator==
/// overload for that type.
////////////////////////////////////////////////////////////
template <typename T>
struct Approx
{
2022-07-05 00:20:58 +08:00
explicit Approx(const T& t) : value(t)
{
}
const T& value;
};
bool operator==(const float& lhs, const Approx<float>& rhs);
bool operator==(sf::Vector2<float> lhs, const Approx<sf::Vector2<float>>& rhs);
bool operator==(const sf::Vector3<float>& lhs, const Approx<sf::Vector3<float>>& rhs);
bool operator==(const sf::Angle& lhs, const Approx<sf::Angle>& rhs);
template <typename T>
2023-09-28 12:27:20 +08:00
std::ostream& operator<<(std::ostream& os, const Approx<T>& approx)
{
return os << approx.value;
}
2024-04-12 08:13:19 +08:00
[[nodiscard]] std::vector<std::byte> loadIntoMemory(const std::filesystem::path& path);