Add tests for sf::MemoryInputStream

This commit is contained in:
Bambo-Borris 2022-06-24 02:13:55 +01:00 committed by Vittorio Romeo
parent 8c8d97c6c9
commit c6f7fcaa2a
2 changed files with 34 additions and 0 deletions

View File

@ -18,6 +18,7 @@ SET(SYSTEM_SRC
System/Clock.cpp
System/Err.cpp
System/FileInputStream.cpp
System/MemoryInputStream.cpp
System/Time.cpp
System/Vector2.cpp
System/Vector3.cpp

View File

@ -0,0 +1,33 @@
#include <SFML/System/MemoryInputStream.hpp>
#include <string_view>
#include <ostream>
#include <doctest.h>
TEST_CASE("sf::MemoryInputStream class - [system]")
{
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);
}
}