mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Use loadIntoMemory
This commit is contained in:
parent
8ccf534993
commit
30fcb3523c
@ -91,18 +91,8 @@ TEST_CASE("[Audio] sf::InputSoundFile")
|
|||||||
|
|
||||||
SECTION("openFromMemory()")
|
SECTION("openFromMemory()")
|
||||||
{
|
{
|
||||||
|
const auto memory = loadIntoMemory("Audio/killdeer.wav");
|
||||||
sf::InputSoundFile inputSoundFile;
|
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()));
|
REQUIRE(inputSoundFile.openFromMemory(memory.data(), memory.size()));
|
||||||
CHECK(inputSoundFile.getSampleCount() == 112'941);
|
CHECK(inputSoundFile.getSampleCount() == 112'941);
|
||||||
CHECK(inputSoundFile.getChannelCount() == 1);
|
CHECK(inputSoundFile.getChannelCount() == 1);
|
||||||
|
@ -6,12 +6,9 @@
|
|||||||
|
|
||||||
#include <GraphicsUtil.hpp>
|
#include <GraphicsUtil.hpp>
|
||||||
#include <SystemUtil.hpp>
|
#include <SystemUtil.hpp>
|
||||||
#include <fstream>
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
std::ostream& operator<<(std::ostream& os, const BlendMode& blendMode)
|
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()[7] == Approx(rhs.value.getMatrix()[7]) &&
|
||||||
lhs.getMatrix()[15] == Approx(rhs.value.getMatrix()[15]);
|
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
|
#pragma once
|
||||||
|
|
||||||
#include <SystemUtil.hpp>
|
#include <SystemUtil.hpp>
|
||||||
#include <filesystem>
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <cstddef>
|
|
||||||
|
|
||||||
namespace sf
|
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) &&
|
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);
|
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 <catch2/catch_approx.hpp>
|
||||||
|
|
||||||
#include <SystemUtil.hpp>
|
#include <SystemUtil.hpp>
|
||||||
|
#include <fstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
void setStreamPrecision(std::ostream& os, int maxDigits10)
|
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());
|
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
|
#pragma once
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
// String conversions for Catch2
|
// String conversions for Catch2
|
||||||
namespace sf
|
namespace sf
|
||||||
@ -58,3 +62,5 @@ std::ostream& operator<<(std::ostream& os, const Approx<T>& approx)
|
|||||||
{
|
{
|
||||||
return os << approx.value;
|
return os << approx.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] std::vector<std::byte> loadIntoMemory(const std::filesystem::path& path);
|
||||||
|
Loading…
Reference in New Issue
Block a user