2015-04-29 03:37:01 +08:00
|
|
|
// Header for SFML unit tests.
|
|
|
|
//
|
2021-12-29 13:03:15 +08:00
|
|
|
// For a new system module test case, include this header.
|
2021-12-24 21:31:27 +08:00
|
|
|
// This ensures that string conversions are visible and can be used by doctest for debug output.
|
2015-04-29 03:37:01 +08:00
|
|
|
|
2018-08-19 07:30:53 +08:00
|
|
|
#ifndef SFML_TESTUTILITIES_SYSTEM_HPP
|
|
|
|
#define SFML_TESTUTILITIES_SYSTEM_HPP
|
|
|
|
|
2015-04-29 03:37:01 +08:00
|
|
|
#include <SFML/System/Vector2.hpp>
|
|
|
|
#include <SFML/System/Vector3.hpp>
|
2021-12-29 13:03:15 +08:00
|
|
|
|
2022-05-01 13:20:46 +08:00
|
|
|
#include <iomanip>
|
2022-06-24 07:33:33 +08:00
|
|
|
#include <limits>
|
2021-12-29 13:03:15 +08:00
|
|
|
#include <ostream>
|
2015-04-29 03:37:01 +08:00
|
|
|
|
2021-12-24 21:31:27 +08:00
|
|
|
// String conversions for doctest framework
|
2015-04-29 03:37:01 +08:00
|
|
|
namespace sf
|
|
|
|
{
|
2022-07-05 00:20:58 +08:00
|
|
|
class Angle;
|
|
|
|
class String;
|
|
|
|
class Time;
|
2015-04-29 03:37:01 +08:00
|
|
|
|
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);
|
2015-04-29 03:37:01 +08:00
|
|
|
|
2022-07-05 00:20:58 +08:00
|
|
|
template <typename T>
|
2022-07-05 13:46:34 +08:00
|
|
|
std::ostream& operator<<(std::ostream& os, const Vector2<T>& vector)
|
2022-07-05 00:20:58 +08:00
|
|
|
{
|
|
|
|
os << std::fixed << std::setprecision(std::numeric_limits<T>::max_digits10);
|
|
|
|
os << "(" << vector.x << ", " << vector.y << ")";
|
|
|
|
return os;
|
|
|
|
}
|
2015-04-29 03:37:01 +08:00
|
|
|
|
2022-07-05 00:20:58 +08:00
|
|
|
template <typename T>
|
2022-07-05 13:46:34 +08:00
|
|
|
std::ostream& operator<<(std::ostream& os, const Vector3<T>& vector)
|
2022-07-05 00:20:58 +08:00
|
|
|
{
|
|
|
|
os << "(" << vector.x << ", " << vector.y << ", " << vector.z << ")";
|
|
|
|
return os;
|
2015-04-29 03:37:01 +08:00
|
|
|
}
|
2022-07-05 00:20:58 +08:00
|
|
|
} // namespace sf
|
2015-04-29 03:37:01 +08:00
|
|
|
|
2022-05-03 06:38:33 +08:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// 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-02-18 00:22:00 +08:00
|
|
|
{
|
2022-07-05 00:20:58 +08:00
|
|
|
explicit Approx(const T& t) : value(t)
|
|
|
|
{
|
|
|
|
}
|
2022-05-03 06:38:33 +08:00
|
|
|
const T& value;
|
2022-02-18 00:22:00 +08:00
|
|
|
};
|
|
|
|
|
2022-05-03 06:38:33 +08:00
|
|
|
bool operator==(const float& lhs, const Approx<float>& rhs);
|
|
|
|
bool operator==(const sf::Vector2f& lhs, const Approx<sf::Vector2f>& rhs);
|
|
|
|
bool operator==(const sf::Vector3f& lhs, const Approx<sf::Vector3f>& rhs);
|
|
|
|
bool operator==(const sf::Angle& lhs, const Approx<sf::Angle>& rhs);
|
2022-05-05 01:03:26 +08:00
|
|
|
|
2022-05-03 06:38:33 +08:00
|
|
|
template <typename T>
|
2022-07-05 00:20:58 +08:00
|
|
|
std::ostream& operator<<(std::ostream& os, const Approx<T>& approx)
|
2022-02-18 00:22:00 +08:00
|
|
|
{
|
2022-05-03 06:38:33 +08:00
|
|
|
return os << approx.value;
|
|
|
|
}
|
2022-02-18 00:22:00 +08:00
|
|
|
|
2018-08-19 07:30:53 +08:00
|
|
|
#endif // SFML_TESTUTILITIES_SYSTEM_HPP
|