Separated test suites into their individual modules

- Building per module only requires to have split test utility sections
- System module tests are always added, as the system module is always built
This commit is contained in:
Lukas Dürrenberger 2018-08-19 01:30:53 +02:00 committed by Lukas Dürrenberger
parent 7d496095a5
commit d402ce5a5d
11 changed files with 154 additions and 73 deletions

View file

@ -0,0 +1,19 @@
// Note: No need to increase compile time by including TestUtilities/Graphics.hpp
#include <SFML/Graphics/Color.hpp>
#include <sstream>
// String conversions for Catch framework
namespace Catch
{
std::string toString(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) << ")";
return stream.str();
}
}

View file

@ -0,0 +1,23 @@
// Header for SFML unit tests.
//
// For a new graphics module test case, include this header and not <catch.hpp> directly.
// This ensures that string conversions are visible and can be used by Catch for debug output.
#ifndef SFML_TESTUTILITIES_GRAPHICS_HPP
#define SFML_TESTUTILITIES_GRAPHICS_HPP
#include "Window.hpp"
// Forward declarations for non-template types
namespace sf
{
class Color;
}
// String conversions for Catch framework
namespace Catch
{
std::string toString(const sf::Color& color);
}
#endif // SFML_TESTUTILITIES_GRAPHICS_HPP

View file

@ -0,0 +1,20 @@
// Note: No need to increase compile time by including TestUtilities/System.hpp
#include <SFML/System/String.hpp>
#include <SFML/System/Time.hpp>
#include <sstream>
// String conversions for Catch framework
namespace Catch
{
std::string toString(const sf::String& string)
{
return string.toAnsiString();
}
std::string toString(sf::Time time)
{
std::ostringstream stream;
stream << time.asMicroseconds() << "us";
return stream.str();
}
}

View file

@ -0,0 +1,45 @@
// Header for SFML unit tests.
//
// For a new system module test case, include this header and not <catch.hpp> directly.
// This ensures that string conversions are visible and can be used by Catch for debug output.
#ifndef SFML_TESTUTILITIES_SYSTEM_HPP
#define SFML_TESTUTILITIES_SYSTEM_HPP
#include <catch.hpp>
#include <SFML/System/Vector2.hpp>
#include <SFML/System/Vector3.hpp>
#include <sstream>
// Forward declarations for non-template types
namespace sf
{
class String;
class Time;
}
// String conversions for Catch framework
namespace Catch
{
std::string toString(const sf::String& string);
std::string toString(sf::Time time);
template <typename T>
std::string toString(const sf::Vector2<T>& vector)
{
std::ostringstream stream;
stream << "(" << vector.x << ", " << vector.y << ")";
return stream.str();
}
template <typename T>
std::string toString(const sf::Vector3<T>& vector)
{
std::ostringstream stream;
stream << "(" << vector.x << ", " << vector.y << ", " << vector.z << ")";
return stream.str();
}
}
#endif // SFML_TESTUTILITIES_SYSTEM_HPP

View file

@ -0,0 +1,14 @@
// Note: No need to increase compile time by including TestUtilities/Window.hpp
#include <SFML/Window/VideoMode.hpp>
#include <sstream>
// String conversions for Catch framework
namespace Catch
{
std::string toString(const sf::VideoMode& videoMode)
{
std::ostringstream stream;
stream << videoMode.width << "x" << videoMode.height << "x" << videoMode.bitsPerPixel;
return stream.str();
}
}

View file

@ -0,0 +1,33 @@
// Header for SFML unit tests.
//
// For a new window module test case, include this header and not <catch.hpp> directly.
// This ensures that string conversions are visible and can be used by Catch for debug output.
#ifndef SFML_TESTUTILITIES_WINDOW_HPP
#define SFML_TESTUTILITIES_WINDOW_HPP
#include "System.hpp"
#include <SFML/Graphics/Rect.hpp>
// Forward declarations for non-template types
namespace sf
{
class VideoMode;
}
// String conversions for Catch framework
namespace Catch
{
std::string toString(const sf::VideoMode& videoMode);
template <typename T>
std::string toString(const sf::Rect<T>& rect)
{
std::ostringstream stream;
stream << "(left=" << rect.left << ", top=" << rect.top << ", width=" << rect.width << ", height=" << rect.height << ")";
return stream.str();
}
}
#endif // SFML_TESTUTILITIES_WINDOW_HPP