Add tests for sf::err
This commit is contained in:
parent
2a5ce3c989
commit
1e560ababd
@ -14,6 +14,7 @@ target_link_libraries(sfml-test-main PUBLIC SFML::System)
|
|||||||
SET(SYSTEM_SRC
|
SET(SYSTEM_SRC
|
||||||
System/Angle.cpp
|
System/Angle.cpp
|
||||||
System/Clock.cpp
|
System/Clock.cpp
|
||||||
|
System/Err.cpp
|
||||||
System/FileInputStream.cpp
|
System/FileInputStream.cpp
|
||||||
System/Time.cpp
|
System/Time.cpp
|
||||||
System/Vector2.cpp
|
System/Vector2.cpp
|
||||||
|
40
test/System/Err.cpp
Normal file
40
test/System/Err.cpp
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#include <SFML/System/Err.hpp>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#include <doctest.h>
|
||||||
|
|
||||||
|
TEST_CASE("sf::err - [system]")
|
||||||
|
{
|
||||||
|
SUBCASE("Overflow default buffer")
|
||||||
|
{
|
||||||
|
// No assertion macros in this subcase since nothing about this can be directly observed.
|
||||||
|
// Intention is to ensure DefaultErrStreamBuf::overflow gets called.
|
||||||
|
sf::err() << "SFML is a simple, fast, cross-platform and object-oriented multimedia API."
|
||||||
|
"It provides access to windowing, graphics, audio and network."
|
||||||
|
"It is written in C++, and has bindings for various languages such as C, .Net, Ruby, Python.";
|
||||||
|
}
|
||||||
|
|
||||||
|
SUBCASE("Redirect buffer to observe contents")
|
||||||
|
{
|
||||||
|
sf::err() << "We'll never be able to observe this" << std::endl; // Ensure buffer is flushed
|
||||||
|
const auto defaultStreamBuffer = sf::err().rdbuf();
|
||||||
|
CHECK(defaultStreamBuffer != nullptr);
|
||||||
|
|
||||||
|
std::stringstream stream;
|
||||||
|
sf::err().rdbuf(stream.rdbuf());
|
||||||
|
sf::err() << "Something went wrong!\n";
|
||||||
|
CHECK(stream.str() == "Something went wrong!\n");
|
||||||
|
|
||||||
|
sf::err().rdbuf(nullptr);
|
||||||
|
sf::err() << "Sent to the abyss";
|
||||||
|
CHECK(stream.str() == "Something went wrong!\n");
|
||||||
|
|
||||||
|
sf::err().rdbuf(stream.rdbuf());
|
||||||
|
sf::err() << "Back to the stringstream :)\n";
|
||||||
|
CHECK(stream.str() == "Something went wrong!\nBack to the stringstream :)\n");
|
||||||
|
|
||||||
|
// Restore sf::err to default stream defaultStreamBuffer
|
||||||
|
sf::err().rdbuf(defaultStreamBuffer);
|
||||||
|
CHECK(sf::err().rdbuf() == defaultStreamBuffer);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user