From c6f7fcaa2a1924e6ef6dfee9797ec65decea6a60 Mon Sep 17 00:00:00 2001 From: Bambo-Borris Date: Fri, 24 Jun 2022 02:13:55 +0100 Subject: [PATCH] Add tests for `sf::MemoryInputStream` --- test/CMakeLists.txt | 1 + test/System/MemoryInputStream.cpp | 33 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 test/System/MemoryInputStream.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8c44ae20..968439bb 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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 diff --git a/test/System/MemoryInputStream.cpp b/test/System/MemoryInputStream.cpp new file mode 100644 index 00000000..ae6b724c --- /dev/null +++ b/test/System/MemoryInputStream.cpp @@ -0,0 +1,33 @@ +#include +#include +#include + +#include + +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); + } +}