From 30fcb3523c9d685f5c35eeae829da91daf6ff7ce Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Thu, 11 Apr 2024 18:13:19 -0600 Subject: [PATCH] Use `loadIntoMemory` --- test/Audio/InputSoundFile.test.cpp | 12 +----------- test/TestUtilities/GraphicsUtil.cpp | 15 --------------- test/TestUtilities/GraphicsUtil.hpp | 6 ------ test/TestUtilities/SystemUtil.cpp | 16 ++++++++++++++++ test/TestUtilities/SystemUtil.hpp | 6 ++++++ 5 files changed, 23 insertions(+), 32 deletions(-) diff --git a/test/Audio/InputSoundFile.test.cpp b/test/Audio/InputSoundFile.test.cpp index c6e73da2f..0737ae7e9 100644 --- a/test/Audio/InputSoundFile.test.cpp +++ b/test/Audio/InputSoundFile.test.cpp @@ -91,18 +91,8 @@ TEST_CASE("[Audio] sf::InputSoundFile") SECTION("openFromMemory()") { + const auto memory = loadIntoMemory("Audio/killdeer.wav"); sf::InputSoundFile inputSoundFile; - const auto memory = []() - { - std::ifstream file("Audio/killdeer.wav", std::ios::binary | std::ios::ate); - REQUIRE(file); - const auto size = file.tellg(); - file.seekg(0, std::ios::beg); - std::vector buffer(static_cast(size)); - REQUIRE(file.read(buffer.data(), size)); - return buffer; - }(); - REQUIRE(inputSoundFile.openFromMemory(memory.data(), memory.size())); CHECK(inputSoundFile.getSampleCount() == 112'941); CHECK(inputSoundFile.getChannelCount() == 1); diff --git a/test/TestUtilities/GraphicsUtil.cpp b/test/TestUtilities/GraphicsUtil.cpp index 2530af6ae..05ed0688d 100644 --- a/test/TestUtilities/GraphicsUtil.cpp +++ b/test/TestUtilities/GraphicsUtil.cpp @@ -6,12 +6,9 @@ #include #include -#include #include #include -#include - namespace sf { std::ostream& operator<<(std::ostream& os, const BlendMode& blendMode) @@ -116,15 +113,3 @@ bool operator==(const sf::Transform& lhs, const Approx& rhs) lhs.getMatrix()[7] == Approx(rhs.value.getMatrix()[7]) && lhs.getMatrix()[15] == Approx(rhs.value.getMatrix()[15]); } - -std::vector loadIntoMemory(const std::filesystem::path& path) -{ - std::ifstream file(path, std::ios::binary | std::ios::ate); - assert(file); - const auto size = file.tellg(); - file.seekg(0, std::ios::beg); - std::vector buffer(static_cast(size)); - [[maybe_unused]] const auto& result = file.read(reinterpret_cast(buffer.data()), size); - assert(result); - return buffer; -} diff --git a/test/TestUtilities/GraphicsUtil.hpp b/test/TestUtilities/GraphicsUtil.hpp index 77bfff45d..0ae41b31e 100644 --- a/test/TestUtilities/GraphicsUtil.hpp +++ b/test/TestUtilities/GraphicsUtil.hpp @@ -6,11 +6,7 @@ #pragma once #include -#include #include -#include - -#include namespace sf { @@ -39,5 +35,3 @@ bool operator==(const sf::Rect& lhs, const Approx>& rhs) return lhs.left == Approx(rhs.value.left) && lhs.top == Approx(rhs.value.top) && lhs.width == Approx(rhs.value.width) && lhs.height == Approx(rhs.value.height); } - -[[nodiscard]] std::vector loadIntoMemory(const std::filesystem::path& path); diff --git a/test/TestUtilities/SystemUtil.cpp b/test/TestUtilities/SystemUtil.cpp index d17e4f482..6720de8b8 100644 --- a/test/TestUtilities/SystemUtil.cpp +++ b/test/TestUtilities/SystemUtil.cpp @@ -7,9 +7,13 @@ #include #include +#include #include #include +#include + + namespace sf { void setStreamPrecision(std::ostream& os, int maxDigits10) @@ -75,3 +79,15 @@ bool operator==(const sf::Angle& lhs, const Approx& rhs) { return lhs.asDegrees() == Approx(rhs.value.asDegrees()); } + +std::vector loadIntoMemory(const std::filesystem::path& path) +{ + std::ifstream file(path, std::ios::binary | std::ios::ate); + assert(file); + const auto size = file.tellg(); + file.seekg(0, std::ios::beg); + std::vector buffer(static_cast(size)); + [[maybe_unused]] const auto& result = file.read(reinterpret_cast(buffer.data()), size); + assert(result); + return buffer; +} diff --git a/test/TestUtilities/SystemUtil.hpp b/test/TestUtilities/SystemUtil.hpp index 3267df6f7..de00cc7a9 100644 --- a/test/TestUtilities/SystemUtil.hpp +++ b/test/TestUtilities/SystemUtil.hpp @@ -5,7 +5,11 @@ #pragma once +#include #include +#include + +#include // String conversions for Catch2 namespace sf @@ -58,3 +62,5 @@ std::ostream& operator<<(std::ostream& os, const Approx& approx) { return os << approx.value; } + +[[nodiscard]] std::vector loadIntoMemory(const std::filesystem::path& path);