mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
Use loadIntoMemory
This commit is contained in:
parent
8ccf534993
commit
30fcb3523c
@ -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<char> buffer(static_cast<std::size_t>(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);
|
||||
|
@ -6,12 +6,9 @@
|
||||
|
||||
#include <GraphicsUtil.hpp>
|
||||
#include <SystemUtil.hpp>
|
||||
#include <fstream>
|
||||
#include <limits>
|
||||
#include <ostream>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace sf
|
||||
{
|
||||
std::ostream& operator<<(std::ostream& os, const BlendMode& blendMode)
|
||||
@ -116,15 +113,3 @@ bool operator==(const sf::Transform& lhs, const Approx<sf::Transform>& rhs)
|
||||
lhs.getMatrix()[7] == Approx(rhs.value.getMatrix()[7]) &&
|
||||
lhs.getMatrix()[15] == Approx(rhs.value.getMatrix()[15]);
|
||||
}
|
||||
|
||||
std::vector<std::byte> 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<std::byte> buffer(static_cast<std::size_t>(size));
|
||||
[[maybe_unused]] const auto& result = file.read(reinterpret_cast<char*>(buffer.data()), size);
|
||||
assert(result);
|
||||
return buffer;
|
||||
}
|
||||
|
@ -6,11 +6,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <SystemUtil.hpp>
|
||||
#include <filesystem>
|
||||
#include <iosfwd>
|
||||
#include <vector>
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace sf
|
||||
{
|
||||
@ -39,5 +35,3 @@ bool operator==(const sf::Rect<T>& lhs, const Approx<sf::Rect<T>>& 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<std::byte> loadIntoMemory(const std::filesystem::path& path);
|
||||
|
@ -7,9 +7,13 @@
|
||||
#include <catch2/catch_approx.hpp>
|
||||
|
||||
#include <SystemUtil.hpp>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <limits>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
void setStreamPrecision(std::ostream& os, int maxDigits10)
|
||||
@ -75,3 +79,15 @@ bool operator==(const sf::Angle& lhs, const Approx<sf::Angle>& rhs)
|
||||
{
|
||||
return lhs.asDegrees() == Approx(rhs.value.asDegrees());
|
||||
}
|
||||
|
||||
std::vector<std::byte> 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<std::byte> buffer(static_cast<std::size_t>(size));
|
||||
[[maybe_unused]] const auto& result = file.read(reinterpret_cast<char*>(buffer.data()), size);
|
||||
assert(result);
|
||||
return buffer;
|
||||
}
|
||||
|
@ -5,7 +5,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <iosfwd>
|
||||
#include <vector>
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
// String conversions for Catch2
|
||||
namespace sf
|
||||
@ -58,3 +62,5 @@ std::ostream& operator<<(std::ostream& os, const Approx<T>& approx)
|
||||
{
|
||||
return os << approx.value;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::vector<std::byte> loadIntoMemory(const std::filesystem::path& path);
|
||||
|
Loading…
Reference in New Issue
Block a user