mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
44 lines
1.3 KiB
C++
44 lines
1.3 KiB
C++
#include <SFML/System/MemoryInputStream.hpp>
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
#include <array>
|
|
#include <ostream>
|
|
#include <string_view>
|
|
|
|
TEST_CASE("[System] sf::MemoryInputStream")
|
|
{
|
|
SECTION("Type traits")
|
|
{
|
|
STATIC_CHECK(std::is_copy_constructible_v<sf::MemoryInputStream>);
|
|
STATIC_CHECK(std::is_copy_assignable_v<sf::MemoryInputStream>);
|
|
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::MemoryInputStream>);
|
|
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::MemoryInputStream>);
|
|
}
|
|
|
|
SECTION("Empty stream")
|
|
{
|
|
sf::MemoryInputStream mis;
|
|
|
|
CHECK(mis.read(nullptr, 0) == -1);
|
|
CHECK(mis.seek(0) == -1);
|
|
CHECK(mis.tell() == -1);
|
|
CHECK(mis.getSize() == -1);
|
|
}
|
|
|
|
SECTION("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());
|
|
|
|
std::array<char, 32> buffer{};
|
|
CHECK(mis.read(buffer.data(), 5) == 5);
|
|
CHECK(std::string_view(buffer.data(), 5) == std::string_view(memoryContents.data(), 5));
|
|
CHECK(mis.seek(10) == 10);
|
|
CHECK(mis.tell() == 10);
|
|
CHECK(mis.getSize() == 11);
|
|
}
|
|
}
|