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

@ -85,7 +85,7 @@ if(SFML_BUILD_WINDOW)
endif()
# add an option for building the test suite
sfml_set_option(SFML_BUILD_TEST TRUE BOOL "TRUE to build the SFML test suite, FALSE to ignore them")
sfml_set_option(SFML_BUILD_TEST_SUITE TRUE BOOL "TRUE to build the SFML test suite, FALSE to ignore it")
# macOS specific options
if(SFML_OS_MACOSX)
@ -284,7 +284,7 @@ endif()
if(SFML_BUILD_DOC)
add_subdirectory(doc)
endif()
if(SFML_BUILD_TEST)
if(SFML_BUILD_TEST_SUITE)
add_subdirectory(test)
endif()

View File

@ -1,20 +1,46 @@
set(SRCROOT "${PROJECT_SOURCE_DIR}/test/src")
SET(SRC
"${SRCROOT}/Main.cpp"
"${SRCROOT}/UnitTests.hpp"
"${SRCROOT}/UnitTests.cpp"
"${SRCROOT}/Vector2.cpp"
"${SRCROOT}/Rect.cpp"
)
include_directories("${PROJECT_SOURCE_DIR}/include")
include_directories("${PROJECT_SOURCE_DIR}/extlibs/headers")
# System is always built
SET(SYSTEM_SRC
"${SRCROOT}/Vector2.cpp"
"${SRCROOT}/TestUtilities/System.hpp"
"${SRCROOT}/TestUtilities/System.cpp"
)
SET(SYSTEM_LIB "sfml-system")
if(SFML_BUILD_WINDOW)
SET(WINDOW_SRC
"${SRCROOT}/TestUtilities/Window.hpp"
"${SRCROOT}/TestUtilities/Window.cpp"
)
SET(WINDOW_LIB "sfml-window")
endif()
if(SFML_BUILD_GRAPHICS)
SET(GRAPHICS_SRC
"${SRCROOT}/Rect.cpp"
"${SRCROOT}/TestUtilities/Graphics.hpp"
"${SRCROOT}/TestUtilities/Graphics.cpp"
)
SET(WINDOW_LIB "sfml-graphics")
endif()
SET(SRC
"${SRCROOT}/Main.cpp"
"${SYSTEM_SRC}"
"${WINDOW_SRC}"
"${GRAPHICS_SRC}"
"${AUDIO_SRC}"
"${NETWORK_SRC}"
)
# Using sfmltest instead of test because the latter is reserved.
add_executable(sfmltest ${SRC})
target_link_libraries(sfmltest sfml-graphics sfml-window sfml-audio sfml-network sfml-system)
target_link_libraries(sfmltest ${GRAPHICS_LIB} ${WINDOW_LIB} ${AUDIO_LIB} ${NETWORK_LIB} ${SYSTEM_LIB})
add_custom_target(runtests ALL
DEPENDS sfmltest

View File

@ -1,6 +1,6 @@
#include <SFML/Graphics/Rect.hpp>
#include <SFML/System/Vector2.hpp>
#include "UnitTests.hpp"
#include "TestUtilities/Graphics.hpp"
TEST_CASE("sf::Rect class template", "[graphics]")
{

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

@ -1,25 +1,22 @@
// Header for SFML unit tests.
//
// For a new test case, include this header and not <catch.hpp> directly.
// 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_UNITTESTS_HPP
#define SFML_UNITTESTS_HPP
#ifndef SFML_TESTUTILITIES_SYSTEM_HPP
#define SFML_TESTUTILITIES_SYSTEM_HPP
#include <catch.hpp>
#include <SFML/System/Vector2.hpp>
#include <SFML/System/Vector3.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <sstream>
#include <catch.hpp>
// Forward declarations for non-template types
namespace sf
{
class Color;
class String;
class Time;
class VideoMode;
}
// String conversions for Catch framework
@ -27,8 +24,6 @@ namespace Catch
{
std::string toString(const sf::String& string);
std::string toString(sf::Time time);
std::string toString(const sf::VideoMode& videoMode);
std::string toString(const sf::Color& color);
template <typename T>
std::string toString(const sf::Vector2<T>& vector)
@ -45,14 +40,6 @@ namespace Catch
stream << "(" << vector.x << ", " << vector.y << ", " << vector.z << ")";
return stream.str();
}
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_UNITTESTS_HPP
#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

View File

@ -1,41 +0,0 @@
// Note: No need to increase compile time by including UnitTests.hpp
#include <SFML/System/String.hpp>
#include <SFML/System/Time.hpp>
#include <SFML/Window/VideoMode.hpp>
#include <SFML/Graphics/Color.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();
}
std::string toString(const sf::VideoMode& videoMode)
{
std::ostringstream stream;
stream << videoMode.width << "x" << videoMode.height << "x" << videoMode.bitsPerPixel;
return stream.str();
}
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

@ -1,5 +1,5 @@
#include <SFML/System/Vector2.hpp>
#include "UnitTests.hpp"
#include "TestUtilities/System.hpp"
// Use sf::Vector2i for tests. Test coverage is given, as there are no template specializations.