From d402ce5a5df18b27bcfc77e51753488b23f76099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20D=C3=BCrrenberger?= Date: Sun, 19 Aug 2018 01:30:53 +0200 Subject: [PATCH] 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 --- CMakeLists.txt | 4 +- test/CMakeLists.txt | 44 +++++++++++++++---- test/src/Rect.cpp | 2 +- test/src/TestUtilities/Graphics.cpp | 19 ++++++++ test/src/TestUtilities/Graphics.hpp | 23 ++++++++++ test/src/TestUtilities/System.cpp | 20 +++++++++ .../System.hpp} | 25 +++-------- test/src/TestUtilities/Window.cpp | 14 ++++++ test/src/TestUtilities/Window.hpp | 33 ++++++++++++++ test/src/UnitTests.cpp | 41 ----------------- test/src/Vector2.cpp | 2 +- 11 files changed, 154 insertions(+), 73 deletions(-) create mode 100644 test/src/TestUtilities/Graphics.cpp create mode 100644 test/src/TestUtilities/Graphics.hpp create mode 100644 test/src/TestUtilities/System.cpp rename test/src/{UnitTests.hpp => TestUtilities/System.hpp} (60%) create mode 100644 test/src/TestUtilities/Window.cpp create mode 100644 test/src/TestUtilities/Window.hpp delete mode 100644 test/src/UnitTests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index dea32edb7..5bbea9886 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7249c8479..932f0fdb6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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 diff --git a/test/src/Rect.cpp b/test/src/Rect.cpp index 70bd48382..7ac8933ab 100644 --- a/test/src/Rect.cpp +++ b/test/src/Rect.cpp @@ -1,6 +1,6 @@ #include #include -#include "UnitTests.hpp" +#include "TestUtilities/Graphics.hpp" TEST_CASE("sf::Rect class template", "[graphics]") { diff --git a/test/src/TestUtilities/Graphics.cpp b/test/src/TestUtilities/Graphics.cpp new file mode 100644 index 000000000..e323bb767 --- /dev/null +++ b/test/src/TestUtilities/Graphics.cpp @@ -0,0 +1,19 @@ +// Note: No need to increase compile time by including TestUtilities/Graphics.hpp +#include +#include + +// 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(color.r) + << ", g=" << static_cast(color.g) + << ", b=" << static_cast(color.b) + << ", a=" << static_cast(color.a) << ")"; + + return stream.str(); + } +} diff --git a/test/src/TestUtilities/Graphics.hpp b/test/src/TestUtilities/Graphics.hpp new file mode 100644 index 000000000..a251bc566 --- /dev/null +++ b/test/src/TestUtilities/Graphics.hpp @@ -0,0 +1,23 @@ +// Header for SFML unit tests. +// +// For a new graphics module test case, include this header and not 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 diff --git a/test/src/TestUtilities/System.cpp b/test/src/TestUtilities/System.cpp new file mode 100644 index 000000000..21a92d68b --- /dev/null +++ b/test/src/TestUtilities/System.cpp @@ -0,0 +1,20 @@ +// Note: No need to increase compile time by including TestUtilities/System.hpp +#include +#include +#include + +// 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(); + } +} diff --git a/test/src/UnitTests.hpp b/test/src/TestUtilities/System.hpp similarity index 60% rename from test/src/UnitTests.hpp rename to test/src/TestUtilities/System.hpp index 0e11c9525..8a48f2253 100644 --- a/test/src/UnitTests.hpp +++ b/test/src/TestUtilities/System.hpp @@ -1,25 +1,22 @@ // Header for SFML unit tests. // -// For a new test case, include this header and not directly. +// For a new system module test case, include this header and not 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 #include #include -#include #include -#include - // 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 std::string toString(const sf::Vector2& vector) @@ -45,14 +40,6 @@ namespace Catch stream << "(" << vector.x << ", " << vector.y << ", " << vector.z << ")"; return stream.str(); } - - template - std::string toString(const sf::Rect& 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 diff --git a/test/src/TestUtilities/Window.cpp b/test/src/TestUtilities/Window.cpp new file mode 100644 index 000000000..52b363578 --- /dev/null +++ b/test/src/TestUtilities/Window.cpp @@ -0,0 +1,14 @@ +// Note: No need to increase compile time by including TestUtilities/Window.hpp +#include +#include + +// 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(); + } +} diff --git a/test/src/TestUtilities/Window.hpp b/test/src/TestUtilities/Window.hpp new file mode 100644 index 000000000..3ddc158f9 --- /dev/null +++ b/test/src/TestUtilities/Window.hpp @@ -0,0 +1,33 @@ +// Header for SFML unit tests. +// +// For a new window module test case, include this header and not 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 + +// 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 + std::string toString(const sf::Rect& 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 diff --git a/test/src/UnitTests.cpp b/test/src/UnitTests.cpp deleted file mode 100644 index a4fc9b229..000000000 --- a/test/src/UnitTests.cpp +++ /dev/null @@ -1,41 +0,0 @@ -// Note: No need to increase compile time by including UnitTests.hpp -#include -#include -#include -#include -#include - -// 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(color.r) - << ", g=" << static_cast(color.g) - << ", b=" << static_cast(color.b) - << ", a=" << static_cast(color.a) << ")"; - - return stream.str(); - } -} diff --git a/test/src/Vector2.cpp b/test/src/Vector2.cpp index 556a49522..1dd4c5f64 100644 --- a/test/src/Vector2.cpp +++ b/test/src/Vector2.cpp @@ -1,5 +1,5 @@ #include -#include "UnitTests.hpp" +#include "TestUtilities/System.hpp" // Use sf::Vector2i for tests. Test coverage is given, as there are no template specializations.