2015-04-28 21:37:01 +02:00
|
|
|
// Header for SFML unit tests.
|
|
|
|
//
|
2021-12-28 22:03:15 -07:00
|
|
|
// For a new system module test case, include this header.
|
2021-12-24 14:31:27 +01:00
|
|
|
// This ensures that string conversions are visible and can be used by doctest for debug output.
|
2015-04-28 21:37:01 +02:00
|
|
|
|
2018-08-19 01:30:53 +02:00
|
|
|
#ifndef SFML_TESTUTILITIES_SYSTEM_HPP
|
|
|
|
#define SFML_TESTUTILITIES_SYSTEM_HPP
|
|
|
|
|
2015-04-28 21:37:01 +02:00
|
|
|
#include <SFML/System/Vector2.hpp>
|
|
|
|
#include <SFML/System/Vector3.hpp>
|
2021-12-28 22:03:15 -07:00
|
|
|
|
2022-04-30 23:20:46 -06:00
|
|
|
#include <iomanip>
|
2021-12-28 22:03:15 -07:00
|
|
|
#include <ostream>
|
2015-04-28 21:37:01 +02:00
|
|
|
#include <sstream>
|
2021-12-24 17:16:06 +01:00
|
|
|
#include <string>
|
2015-04-28 21:37:01 +02:00
|
|
|
|
2021-12-24 14:31:27 +01:00
|
|
|
// String conversions for doctest framework
|
2015-04-28 21:37:01 +02:00
|
|
|
namespace sf
|
|
|
|
{
|
2022-01-22 18:11:08 -07:00
|
|
|
class Angle;
|
2015-04-28 21:37:01 +02:00
|
|
|
class String;
|
|
|
|
class Time;
|
|
|
|
|
2022-01-22 18:11:08 -07:00
|
|
|
std::ostream& operator <<(std::ostream& os, const sf::Angle& angle);
|
2021-12-28 22:03:15 -07:00
|
|
|
std::ostream& operator <<(std::ostream& os, const sf::String& string);
|
|
|
|
std::ostream& operator <<(std::ostream& os, sf::Time time);
|
2015-04-28 21:37:01 +02:00
|
|
|
|
|
|
|
template <typename T>
|
2021-12-28 22:03:15 -07:00
|
|
|
std::ostream& operator <<(std::ostream& os, const sf::Vector2<T>& vector)
|
2015-04-28 21:37:01 +02:00
|
|
|
{
|
2022-04-30 23:20:46 -06:00
|
|
|
os << std::fixed << std::setprecision(std::numeric_limits<T>::max_digits10);
|
2021-12-28 22:03:15 -07:00
|
|
|
os << "(" << vector.x << ", " << vector.y << ")";
|
|
|
|
return os;
|
2015-04-28 21:37:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2021-12-28 22:03:15 -07:00
|
|
|
std::ostream& operator <<(std::ostream& os, const sf::Vector3<T>& vector)
|
2015-04-28 21:37:01 +02:00
|
|
|
{
|
2021-12-28 22:03:15 -07:00
|
|
|
os << "(" << vector.x << ", " << vector.y << ", " << vector.z << ")";
|
|
|
|
return os;
|
2015-04-28 21:37:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-02 16:38:33 -06: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-17 17:22:00 +01:00
|
|
|
{
|
2022-05-02 16:38:33 -06:00
|
|
|
explicit Approx(const T& t) : value(t) {}
|
|
|
|
const T& value;
|
2022-02-17 17:22:00 +01:00
|
|
|
};
|
|
|
|
|
2022-05-02 16:38:33 -06: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-04 18:03:26 +01:00
|
|
|
|
2022-05-02 16:38:33 -06:00
|
|
|
template <typename T>
|
|
|
|
std::ostream& operator <<(std::ostream& os, const Approx<T>& approx)
|
2022-02-17 17:22:00 +01:00
|
|
|
{
|
2022-05-02 16:38:33 -06:00
|
|
|
return os << approx.value;
|
|
|
|
}
|
2022-02-17 17:22:00 +01:00
|
|
|
|
2021-12-24 17:16:06 +01:00
|
|
|
namespace sf::Testing
|
|
|
|
{
|
|
|
|
class TemporaryFile
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::string m_path;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// Create a temporary file with a randomly generated path, containing 'contents'.
|
|
|
|
TemporaryFile(const std::string& contents);
|
|
|
|
|
|
|
|
// Close and delete the generated file.
|
|
|
|
~TemporaryFile();
|
|
|
|
|
|
|
|
// Prevent copies.
|
|
|
|
TemporaryFile(const TemporaryFile&) = delete;
|
|
|
|
TemporaryFile& operator=(const TemporaryFile&) = delete;
|
|
|
|
|
|
|
|
// Return the randomly generated path.
|
|
|
|
const std::string& getPath() const;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-08-19 01:30:53 +02:00
|
|
|
#endif // SFML_TESTUTILITIES_SYSTEM_HPP
|