Use operator<< for printing during test failure

This commit is contained in:
Chris Thrasher 2021-12-28 22:03:15 -07:00 committed by Vittorio Romeo
parent cd84b19669
commit 3d01efb80a
14 changed files with 53 additions and 53 deletions

View File

@ -1,6 +1,8 @@
#include <SFML/Graphics/Color.hpp>
#include "GraphicsUtil.hpp"
#include <doctest.h>
TEST_CASE("sf::Color class - [graphics]")
{
SUBCASE("Construction")

View File

@ -2,6 +2,8 @@
#include <SFML/System/Vector2.hpp>
#include "GraphicsUtil.hpp"
#include <doctest.h>
TEST_CASE("sf::Rect class template - [graphics]")
{
SUBCASE("Construction")

View File

@ -1,6 +1,8 @@
#include <SFML/Graphics/Vertex.hpp>
#include "GraphicsUtil.hpp"
#include <doctest.h>
TEST_CASE("sf::Vertex class - [graphics]")
{
SUBCASE("Construction")

View File

@ -3,6 +3,8 @@
#include <string_view>
#include <utility>
#include <doctest.h>
TEST_CASE("sf::FileInputStream class - [system]")
{
SUBCASE("Empty stream")

View File

@ -1,6 +1,8 @@
#include <SFML/System/Time.hpp>
#include "SystemUtil.hpp"
#include <doctest.h>
using doctest::Approx;
TEST_CASE("sf::Time class - [system]")

View File

@ -2,6 +2,8 @@
#include "SystemUtil.hpp"
#include <type_traits>
#include <doctest.h>
// Use sf::Vector2i for tests. Test coverage is given, as there are no template specializations.
TEST_CASE("sf::Vector2 class template - [system]")

View File

@ -2,6 +2,8 @@
#include "SystemUtil.hpp"
#include <type_traits>
#include <doctest.h>
// Use sf::Vector3i for tests. Test coverage is given, as there are no template specializations.
TEST_CASE("sf::Vector3 class template - [system]")

View File

@ -1,19 +1,17 @@
// Note: No need to increase compile time by including TestUtilities/Graphics.hpp
#include <SFML/Graphics/Color.hpp>
#include <sstream>
#include <doctest.h>
#include <ostream>
namespace sf
{
doctest::String toString(const sf::Color& color)
std::ostream& operator <<(std::ostream& os, const sf::Color& color)
{
std::ostringstream stream;
stream << "0x" << std::hex << color.toInteger() << std::dec
<< " (r=" << static_cast<int>(color.r)
<< ", g=" << static_cast<int>(color.g)
<< ", b=" << static_cast<int>(color.b)
<< ", a=" << static_cast<int>(color.a) << ")";
os << "0x" << std::hex << color.toInteger() << std::dec
<< " (r=" << static_cast<int>(color.r)
<< ", g=" << static_cast<int>(color.g)
<< ", b=" << static_cast<int>(color.b)
<< ", a=" << static_cast<int>(color.a) << ")";
return stream.str().c_str();
return os;
}
}

View File

@ -1,6 +1,6 @@
// Header for SFML unit tests.
//
// For a new graphics module test case, include this header and not <doctest.h> directly.
// For a new graphics module test case, include this header.
// This ensures that string conversions are visible and can be used by doctest for debug output.
#ifndef SFML_TESTUTILITIES_GRAPHICS_HPP
@ -8,15 +8,10 @@
#include "WindowUtil.hpp"
namespace doctest
{
class String;
}
namespace sf
{
class Color;
doctest::String toString(const Color& color);
std::ostream& operator <<(std::ostream& os, const Color& color);
}
#endif // SFML_TESTUTILITIES_GRAPHICS_HPP

View File

@ -9,23 +9,22 @@
#endif // !defined(__GNUC__) || (__GNUC__ >= 9)
#include <fstream>
#include <ostream>
#include <sstream>
#include <cassert>
#include <doctest.h>
namespace sf
{
doctest::String toString(const sf::String& string)
std::ostream& operator <<(std::ostream& os, const sf::String& string)
{
return string.toAnsiString().c_str();
os << string.toAnsiString();
return os;
}
doctest::String toString(sf::Time time)
std::ostream& operator <<(std::ostream& os, sf::Time time)
{
std::ostringstream stream;
stream << time.asMicroseconds() << "us";
return stream.str().c_str();
os << time.asMicroseconds() << "us";
return os;
}
}

View File

@ -1,15 +1,15 @@
// Header for SFML unit tests.
//
// For a new system module test case, include this header and not <doctest.h> directly.
// For a new system module test case, include this header.
// This ensures that string conversions are visible and can be used by doctest for debug output.
#ifndef SFML_TESTUTILITIES_SYSTEM_HPP
#define SFML_TESTUTILITIES_SYSTEM_HPP
#include <doctest.h>
#include <SFML/System/Vector2.hpp>
#include <SFML/System/Vector3.hpp>
#include <ostream>
#include <sstream>
#include <string>
@ -19,23 +19,21 @@ namespace sf
class String;
class Time;
doctest::String toString(const sf::String& string);
doctest::String toString(sf::Time time);
std::ostream& operator <<(std::ostream& os, const sf::String& string);
std::ostream& operator <<(std::ostream& os, sf::Time time);
template <typename T>
doctest::String toString(const sf::Vector2<T>& vector)
std::ostream& operator <<(std::ostream& os, const sf::Vector2<T>& vector)
{
std::ostringstream stream;
stream << "(" << vector.x << ", " << vector.y << ")";
return stream.str().c_str();
os << "(" << vector.x << ", " << vector.y << ")";
return os;
}
template <typename T>
doctest::String toString(const sf::Vector3<T>& vector)
std::ostream& operator <<(std::ostream& os, const sf::Vector3<T>& vector)
{
std::ostringstream stream;
stream << "(" << vector.x << ", " << vector.y << ", " << vector.z << ")";
return stream.str().c_str();
os << "(" << vector.x << ", " << vector.y << ", " << vector.z << ")";
return os;
}
}

View File

@ -1,15 +1,12 @@
// Note: No need to increase compile time by including TestUtilities/Window.hpp
#include <SFML/Window/VideoMode.hpp>
#include <sstream>
#include <doctest.h>
#include <ostream>
namespace sf
{
doctest::String toString(const sf::VideoMode& videoMode)
std::ostream& operator <<(std::ostream& os, const sf::VideoMode& videoMode)
{
std::ostringstream stream;
stream << videoMode.width << "x" << videoMode.height << "x" << videoMode.bitsPerPixel;
return stream.str().c_str();
os << videoMode.width << "x" << videoMode.height << "x" << videoMode.bitsPerPixel;
return os;
}
}

View File

@ -1,6 +1,6 @@
// Header for SFML unit tests.
//
// For a new window module test case, include this header and not <doctest.h> directly.
// For a new window module test case, include this header.
// This ensures that string conversions are visible and can be used by doctest for debug output.
#ifndef SFML_TESTUTILITIES_WINDOW_HPP
@ -10,21 +10,18 @@
#include <SFML/Graphics/Rect.hpp>
#include <doctest.h>
// String conversions for doctest framework
namespace sf
{
class VideoMode;
doctest::String toString(const sf::VideoMode& videoMode);
std::ostream& operator <<(std::ostream& os, const sf::VideoMode& videoMode);
template <typename T>
doctest::String toString(const sf::Rect<T>& rect)
std::ostream& operator <<(std::ostream& os, const sf::Rect<T>& rect)
{
std::ostringstream stream;
stream << "(left=" << rect.left << ", top=" << rect.top << ", width=" << rect.width << ", height=" << rect.height << ")";
return stream.str().c_str();
os << "(left=" << rect.left << ", top=" << rect.top << ", width=" << rect.width << ", height=" << rect.height << ")";
return os;
}
}

View File

@ -1,6 +1,8 @@
#include <SFML/Window/VideoMode.hpp>
#include "WindowUtil.hpp"
#include <doctest.h>
TEST_CASE("sf::VideoMode class - [window]")
{
SUBCASE("Construction")