File: Err.test.cpp

package info (click to toggle)
libsfml 3.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 13,704 kB
  • sloc: cpp: 52,754; ansic: 24,944; objc: 668; sh: 172; xml: 25; makefile: 18
file content (41 lines) | stat: -rw-r--r-- 1,600 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <SFML/System/Err.hpp>

#include <catch2/catch_test_macros.hpp>

#include <sstream>

TEST_CASE("[System] sf::err")
{
    SECTION("Overflow default buffer")
    {
        // No assertion macros in this section 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.";
    }

    SECTION("Redirect buffer to observe contents")
    {
        sf::err() << "We'll never be able to observe this" << std::endl; // Ensure buffer is flushed
        auto* const defaultStreamBuffer = sf::err().rdbuf();
        CHECK(defaultStreamBuffer != nullptr);

        const 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);
    }
}