SFML/test/System/MemoryInputStream.cpp
Chris Thrasher 25fa30afc6 Make test case names more readable
Test output now shows the module name left-aligned so you can easily
browse to see what modules have what tests and know what module a
failing test is coming from.
2022-10-01 23:19:52 +02:00

35 lines
936 B
C++

#include <SFML/System/MemoryInputStream.hpp>
#include <doctest/doctest.h>
#include <ostream>
#include <string_view>
TEST_CASE("[System] sf::MemoryInputStream")
{
SUBCASE("Empty stream")
{
sf::MemoryInputStream mis;
CHECK(mis.read(nullptr, 0) == -1);
CHECK(mis.seek(0) == -1);
CHECK(mis.tell() == -1);
CHECK(mis.getSize() == -1);
}
SUBCASE("Open memory stream")
{
using namespace std::literals::string_view_literals;
constexpr auto memoryContents = "hello world"sv;
sf::MemoryInputStream mis;
mis.open(memoryContents.data(), sizeof(char) * memoryContents.size());
char buffer[32];
CHECK(mis.read(buffer, 5) == 5);
CHECK(std::string_view(buffer, 5) == std::string_view(memoryContents.data(), 5));
CHECK(mis.seek(10) == 10);
CHECK(mis.tell() == 10);
CHECK(mis.getSize() == 11);
}
}