SFML/test/System/MemoryInputStream.test.cpp

44 lines
1.3 KiB
C++
Raw Normal View History

2022-06-24 09:13:55 +08:00
#include <SFML/System/MemoryInputStream.hpp>
2023-01-18 12:51:08 +08:00
#include <catch2/catch_test_macros.hpp>
2022-06-24 09:13:55 +08:00
2024-04-17 13:19:52 +08:00
#include <array>
2022-07-05 00:20:58 +08:00
#include <ostream>
#include <string_view>
TEST_CASE("[System] sf::MemoryInputStream")
2022-06-24 09:13:55 +08:00
{
2023-01-18 12:51:08 +08:00
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")
2022-06-24 09:13:55 +08:00
{
sf::MemoryInputStream mis;
CHECK(mis.read(nullptr, 0) == -1);
CHECK(mis.seek(0) == -1);
CHECK(mis.tell() == -1);
CHECK(mis.getSize() == -1);
}
2023-01-18 12:51:08 +08:00
SECTION("Open memory stream")
2022-06-24 09:13:55 +08:00
{
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());
2024-04-17 13:19:52 +08:00
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));
2022-06-24 09:13:55 +08:00
CHECK(mis.seek(10) == 10);
CHECK(mis.tell() == 10);
CHECK(mis.getSize() == 11);
}
}