2022-06-24 09:13:55 +08:00
|
|
|
#include <SFML/System/MemoryInputStream.hpp>
|
|
|
|
|
2022-07-18 06:18:40 +08:00
|
|
|
#include <doctest/doctest.h>
|
2022-06-24 09:13:55 +08:00
|
|
|
|
2022-07-05 00:20:58 +08:00
|
|
|
#include <ostream>
|
|
|
|
#include <string_view>
|
|
|
|
|
2022-07-05 13:51:18 +08:00
|
|
|
TEST_CASE("[System] sf::MemoryInputStream")
|
2022-06-24 09:13:55 +08:00
|
|
|
{
|
|
|
|
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;
|
2022-07-05 00:20:58 +08:00
|
|
|
constexpr auto memoryContents = "hello world"sv;
|
2022-06-24 09:13:55 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|