mirror of
https://github.com/SFML/SFML.git
synced 2024-11-24 20:31:05 +08:00
Remove default empty state of sf::FileInputStream
This commit is contained in:
parent
37ac80dbe5
commit
304a7c1d69
@ -923,18 +923,17 @@ public:
|
||||
|
||||
// Use the vertex shader SPIR-V code to create a vertex shader module
|
||||
{
|
||||
sf::FileInputStream file;
|
||||
|
||||
if (!file.open("resources/shader.vert.spv"))
|
||||
auto file = sf::FileInputStream::open("resources/shader.vert.spv");
|
||||
if (!file)
|
||||
{
|
||||
vulkanAvailable = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const auto fileSize = file.getSize().value();
|
||||
const auto fileSize = file->getSize().value();
|
||||
std::vector<std::uint32_t> buffer(fileSize / sizeof(std::uint32_t));
|
||||
|
||||
if (file.read(buffer.data(), fileSize) != file.getSize())
|
||||
if (file->read(buffer.data(), fileSize) != file->getSize())
|
||||
{
|
||||
vulkanAvailable = false;
|
||||
return;
|
||||
@ -952,18 +951,17 @@ public:
|
||||
|
||||
// Use the fragment shader SPIR-V code to create a fragment shader module
|
||||
{
|
||||
sf::FileInputStream file;
|
||||
|
||||
if (!file.open("resources/shader.frag.spv"))
|
||||
auto file = sf::FileInputStream::open("resources/shader.frag.spv");
|
||||
if (!file)
|
||||
{
|
||||
vulkanAvailable = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const auto fileSize = file.getSize().value();
|
||||
const auto fileSize = file->getSize().value();
|
||||
std::vector<std::uint32_t> buffer(fileSize / sizeof(std::uint32_t));
|
||||
|
||||
if (file.read(buffer.data(), fileSize) != file.getSize())
|
||||
if (file->read(buffer.data(), fileSize) != file->getSize())
|
||||
{
|
||||
vulkanAvailable = false;
|
||||
return;
|
||||
|
@ -56,12 +56,6 @@ namespace sf
|
||||
class SFML_SYSTEM_API FileInputStream : public InputStream
|
||||
{
|
||||
public:
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
FileInputStream();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default destructor
|
||||
///
|
||||
@ -97,10 +91,10 @@ public:
|
||||
///
|
||||
/// \param filename Name of the file to open
|
||||
///
|
||||
/// \return True on success, false on error
|
||||
/// \return File input stream on success, `std::nullopt` on error
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
[[nodiscard]] bool open(const std::filesystem::path& filename);
|
||||
[[nodiscard]] static std::optional<FileInputStream> open(const std::filesystem::path& filename);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Read data from the stream
|
||||
@ -143,12 +137,6 @@ public:
|
||||
std::optional<std::size_t> getSize() override;
|
||||
|
||||
private:
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
#ifdef SFML_SYSTEM_ANDROID
|
||||
std::unique_ptr<priv::ResourceStream> m_androidFile;
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Deleter for stdio file stream that closes the file stream
|
||||
///
|
||||
@ -158,6 +146,27 @@ private:
|
||||
void operator()(std::FILE* file);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct from file
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
explicit FileInputStream(std::unique_ptr<std::FILE, FileCloser>&& file);
|
||||
|
||||
#ifdef SFML_SYSTEM_ANDROID
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct from resource stream
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
explicit FileInputStream(std::unique_ptr<priv::ResourceStream>&& androidFile);
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
#ifdef SFML_SYSTEM_ANDROID
|
||||
std::unique_ptr<priv::ResourceStream> m_androidFile;
|
||||
#endif
|
||||
|
||||
std::unique_ptr<std::FILE, FileCloser> m_file; //!< stdio file stream
|
||||
};
|
||||
|
||||
@ -188,9 +197,9 @@ private:
|
||||
/// \code
|
||||
/// void process(InputStream& stream);
|
||||
///
|
||||
/// FileInputStream stream;
|
||||
/// if (stream.open("some_file.dat"))
|
||||
/// process(stream);
|
||||
/// std::optional stream = sf::FileInputStream::open("some_file.dat");
|
||||
/// if (stream)
|
||||
/// process(*stream);
|
||||
/// \endcode
|
||||
///
|
||||
/// InputStream, MemoryInputStream
|
||||
|
@ -77,11 +77,9 @@ std::optional<InputSoundFile> InputSoundFile::openFromFile(const std::filesystem
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Wrap the file into a stream
|
||||
auto file = std::make_unique<FileInputStream>();
|
||||
|
||||
// Open it
|
||||
if (!file->open(filename))
|
||||
// Open the file
|
||||
auto fileInputStream = FileInputStream::open(filename);
|
||||
if (!fileInputStream)
|
||||
{
|
||||
err() << "Failed to open input sound file from file (couldn't open file input stream)\n"
|
||||
<< formatDebugPathInfo(filename) << std::endl;
|
||||
@ -89,6 +87,9 @@ std::optional<InputSoundFile> InputSoundFile::openFromFile(const std::filesystem
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Wrap the file into a stream
|
||||
auto file = std::make_unique<FileInputStream>(std::move(*fileInputStream));
|
||||
|
||||
// Pass the stream to the reader
|
||||
auto info = reader->open(*file);
|
||||
if (!info)
|
||||
|
@ -48,8 +48,8 @@ namespace sf
|
||||
std::unique_ptr<SoundFileReader> SoundFileFactory::createReaderFromFilename(const std::filesystem::path& filename)
|
||||
{
|
||||
// Wrap the input file into a file stream
|
||||
FileInputStream stream;
|
||||
if (!stream.open(filename))
|
||||
auto stream = FileInputStream::open(filename);
|
||||
if (!stream)
|
||||
{
|
||||
err() << "Failed to open sound file (couldn't open stream)\n" << formatDebugPathInfo(filename) << std::endl;
|
||||
return nullptr;
|
||||
@ -58,13 +58,13 @@ std::unique_ptr<SoundFileReader> SoundFileFactory::createReaderFromFilename(cons
|
||||
// Test the filename in all the registered factories
|
||||
for (const auto& [fpCreate, fpCheck] : getReaderFactoryMap())
|
||||
{
|
||||
if (!stream.seek(0).has_value())
|
||||
if (!stream->seek(0).has_value())
|
||||
{
|
||||
err() << "Failed to seek sound stream" << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (fpCheck(stream))
|
||||
if (fpCheck(*stream))
|
||||
return fpCreate();
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
#endif
|
||||
#include <memory>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
|
||||
namespace sf
|
||||
@ -43,10 +44,6 @@ void FileInputStream::FileCloser::operator()(std::FILE* file)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
FileInputStream::FileInputStream() = default;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
FileInputStream::~FileInputStream() = default;
|
||||
|
||||
@ -60,21 +57,24 @@ FileInputStream& FileInputStream::operator=(FileInputStream&&) noexcept = defaul
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool FileInputStream::open(const std::filesystem::path& filename)
|
||||
std::optional<FileInputStream> FileInputStream::open(const std::filesystem::path& filename)
|
||||
{
|
||||
#ifdef SFML_SYSTEM_ANDROID
|
||||
if (priv::getActivityStatesPtr() != nullptr)
|
||||
{
|
||||
m_androidFile = std::make_unique<priv::ResourceStream>(filename);
|
||||
return m_androidFile->tell().has_value();
|
||||
auto androidFile = std::make_unique<priv::ResourceStream>(filename);
|
||||
if (androidFile->tell().has_value())
|
||||
return FileInputStream(std::move(androidFile));
|
||||
return std::nullopt;
|
||||
}
|
||||
#endif
|
||||
#ifdef SFML_SYSTEM_WINDOWS
|
||||
m_file.reset(_wfopen(filename.c_str(), L"rb"));
|
||||
if (auto file = std::unique_ptr<std::FILE, FileCloser>(_wfopen(filename.c_str(), L"rb")))
|
||||
#else
|
||||
m_file.reset(std::fopen(filename.c_str(), "rb"));
|
||||
if (auto file = std::unique_ptr<std::FILE, FileCloser>(std::fopen(filename.c_str(), "rb")))
|
||||
#endif
|
||||
return m_file != nullptr;
|
||||
return FileInputStream(std::move(file));
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
||||
@ -84,13 +84,11 @@ std::optional<std::size_t> FileInputStream::read(void* data, std::size_t size)
|
||||
#ifdef SFML_SYSTEM_ANDROID
|
||||
if (priv::getActivityStatesPtr() != nullptr)
|
||||
{
|
||||
if (!m_androidFile)
|
||||
return std::nullopt;
|
||||
assert(m_androidFile);
|
||||
return m_androidFile->read(data, size);
|
||||
}
|
||||
#endif
|
||||
if (!m_file)
|
||||
return std::nullopt;
|
||||
assert(m_file);
|
||||
return std::fread(data, 1, size, m_file.get());
|
||||
}
|
||||
|
||||
@ -101,13 +99,11 @@ std::optional<std::size_t> FileInputStream::seek(std::size_t position)
|
||||
#ifdef SFML_SYSTEM_ANDROID
|
||||
if (priv::getActivityStatesPtr() != nullptr)
|
||||
{
|
||||
if (!m_androidFile)
|
||||
return std::nullopt;
|
||||
assert(m_androidFile);
|
||||
return m_androidFile->seek(position);
|
||||
}
|
||||
#endif
|
||||
if (!m_file)
|
||||
return std::nullopt;
|
||||
assert(m_file);
|
||||
if (std::fseek(m_file.get(), static_cast<long>(position), SEEK_SET))
|
||||
return std::nullopt;
|
||||
|
||||
@ -121,13 +117,11 @@ std::optional<std::size_t> FileInputStream::tell()
|
||||
#ifdef SFML_SYSTEM_ANDROID
|
||||
if (priv::getActivityStatesPtr() != nullptr)
|
||||
{
|
||||
if (!m_androidFile)
|
||||
return std::nullopt;
|
||||
assert(m_androidFile);
|
||||
return m_androidFile->tell();
|
||||
}
|
||||
#endif
|
||||
if (!m_file)
|
||||
return std::nullopt;
|
||||
assert(m_file);
|
||||
const auto position = std::ftell(m_file.get());
|
||||
return position < 0 ? std::nullopt : std::optional<std::size_t>(position);
|
||||
}
|
||||
@ -139,13 +133,11 @@ std::optional<std::size_t> FileInputStream::getSize()
|
||||
#ifdef SFML_SYSTEM_ANDROID
|
||||
if (priv::getActivityStatesPtr() != nullptr)
|
||||
{
|
||||
if (!m_androidFile)
|
||||
return std::nullopt;
|
||||
assert(m_androidFile);
|
||||
return m_androidFile->getSize();
|
||||
}
|
||||
#endif
|
||||
if (!m_file)
|
||||
return std::nullopt;
|
||||
assert(m_file);
|
||||
const auto position = tell().value();
|
||||
std::fseek(m_file.get(), 0, SEEK_END);
|
||||
const std::optional size = tell();
|
||||
@ -156,4 +148,19 @@ std::optional<std::size_t> FileInputStream::getSize()
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
FileInputStream::FileInputStream(std::unique_ptr<std::FILE, FileCloser>&& file) : m_file(std::move(file))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
#ifdef SFML_SYSTEM_ANDROID
|
||||
FileInputStream::FileInputStream(std::unique_ptr<priv::ResourceStream>&& androidFile) :
|
||||
m_androidFile(std::move(androidFile))
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace sf
|
||||
|
@ -90,19 +90,10 @@ TEST_CASE("[Audio] sf::InputSoundFile")
|
||||
}
|
||||
|
||||
SECTION("openFromStream()")
|
||||
{
|
||||
sf::FileInputStream stream;
|
||||
|
||||
SECTION("Invalid stream")
|
||||
{
|
||||
CHECK(!sf::InputSoundFile::openFromStream(stream));
|
||||
}
|
||||
|
||||
SECTION("Valid stream")
|
||||
{
|
||||
SECTION("flac")
|
||||
{
|
||||
REQUIRE(stream.open("Audio/ding.flac"));
|
||||
auto stream = sf::FileInputStream::open("Audio/ding.flac").value();
|
||||
const auto inputSoundFile = sf::InputSoundFile::openFromStream(stream).value();
|
||||
CHECK(inputSoundFile.getSampleCount() == 87'798);
|
||||
CHECK(inputSoundFile.getChannelCount() == 1);
|
||||
@ -114,7 +105,7 @@ TEST_CASE("[Audio] sf::InputSoundFile")
|
||||
|
||||
SECTION("mp3")
|
||||
{
|
||||
REQUIRE(stream.open("Audio/ding.mp3"));
|
||||
auto stream = sf::FileInputStream::open("Audio/ding.mp3").value();
|
||||
const auto inputSoundFile = sf::InputSoundFile::openFromStream(stream).value();
|
||||
CHECK(inputSoundFile.getSampleCount() == 87'798);
|
||||
CHECK(inputSoundFile.getChannelCount() == 1);
|
||||
@ -126,7 +117,7 @@ TEST_CASE("[Audio] sf::InputSoundFile")
|
||||
|
||||
SECTION("ogg")
|
||||
{
|
||||
REQUIRE(stream.open("Audio/doodle_pop.ogg"));
|
||||
auto stream = sf::FileInputStream::open("Audio/doodle_pop.ogg").value();
|
||||
const auto inputSoundFile = sf::InputSoundFile::openFromStream(stream).value();
|
||||
CHECK(inputSoundFile.getSampleCount() == 2'116'992);
|
||||
CHECK(inputSoundFile.getChannelCount() == 2);
|
||||
@ -138,7 +129,7 @@ TEST_CASE("[Audio] sf::InputSoundFile")
|
||||
|
||||
SECTION("wav")
|
||||
{
|
||||
REQUIRE(stream.open("Audio/killdeer.wav"));
|
||||
auto stream = sf::FileInputStream::open("Audio/killdeer.wav").value();
|
||||
const auto inputSoundFile = sf::InputSoundFile::openFromStream(stream).value();
|
||||
CHECK(inputSoundFile.getSampleCount() == 112'941);
|
||||
CHECK(inputSoundFile.getChannelCount() == 1);
|
||||
@ -148,7 +139,6 @@ TEST_CASE("[Audio] sf::InputSoundFile")
|
||||
CHECK(inputSoundFile.getSampleOffset() == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("seek(std::uint64_t)")
|
||||
{
|
||||
|
@ -82,17 +82,7 @@ TEST_CASE("[Audio] sf::Music", runAudioDeviceTests())
|
||||
|
||||
SECTION("openFromStream()")
|
||||
{
|
||||
sf::FileInputStream stream;
|
||||
|
||||
SECTION("Invalid stream")
|
||||
{
|
||||
CHECK(!sf::Music::openFromStream(stream));
|
||||
}
|
||||
|
||||
SECTION("Valid stream")
|
||||
{
|
||||
REQUIRE(stream.open("Audio/doodle_pop.ogg"));
|
||||
|
||||
auto stream = sf::FileInputStream::open("Audio/doodle_pop.ogg").value();
|
||||
const auto music = sf::Music::openFromStream(stream).value();
|
||||
CHECK(music.getDuration() == sf::microseconds(24002176));
|
||||
const auto [offset, length] = music.getLoopPoints();
|
||||
@ -104,7 +94,6 @@ TEST_CASE("[Audio] sf::Music", runAudioDeviceTests())
|
||||
CHECK(music.getPlayingOffset() == sf::Time::Zero);
|
||||
CHECK(!music.getLoop());
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("play/pause/stop")
|
||||
{
|
||||
|
@ -89,16 +89,7 @@ TEST_CASE("[Audio] sf::SoundBuffer", runAudioDeviceTests())
|
||||
|
||||
SECTION("loadFromStream()")
|
||||
{
|
||||
sf::FileInputStream stream;
|
||||
|
||||
SECTION("Invalid stream")
|
||||
{
|
||||
CHECK(!sf::SoundBuffer::loadFromStream(stream));
|
||||
}
|
||||
|
||||
SECTION("Valid stream")
|
||||
{
|
||||
REQUIRE(stream.open("Audio/ding.flac"));
|
||||
auto stream = sf::FileInputStream::open("Audio/ding.flac").value();
|
||||
const auto soundBuffer = sf::SoundBuffer::loadFromStream(stream).value();
|
||||
CHECK(soundBuffer.getSamples() != nullptr);
|
||||
CHECK(soundBuffer.getSampleCount() == 87798);
|
||||
@ -106,7 +97,6 @@ TEST_CASE("[Audio] sf::SoundBuffer", runAudioDeviceTests())
|
||||
CHECK(soundBuffer.getChannelCount() == 1);
|
||||
CHECK(soundBuffer.getDuration() == sf::microseconds(1990884));
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("saveToFile()")
|
||||
{
|
||||
|
@ -110,37 +110,30 @@ TEST_CASE("[Audio] sf::SoundFileFactory")
|
||||
|
||||
SECTION("createReaderFromStream()")
|
||||
{
|
||||
sf::FileInputStream stream;
|
||||
std::optional<sf::FileInputStream> stream;
|
||||
|
||||
SECTION("Invalid stream")
|
||||
{
|
||||
CHECK(!sf::SoundFileFactory::createReaderFromStream(stream));
|
||||
}
|
||||
|
||||
SECTION("Valid file")
|
||||
{
|
||||
SECTION("flac")
|
||||
{
|
||||
REQUIRE(stream.open("Audio/ding.flac"));
|
||||
stream = sf::FileInputStream::open("Audio/ding.flac");
|
||||
}
|
||||
|
||||
SECTION("mp3")
|
||||
{
|
||||
REQUIRE(stream.open("Audio/ding.mp3"));
|
||||
stream = sf::FileInputStream::open("Audio/ding.mp3");
|
||||
}
|
||||
|
||||
SECTION("ogg")
|
||||
{
|
||||
REQUIRE(stream.open("Audio/doodle_pop.ogg"));
|
||||
stream = sf::FileInputStream::open("Audio/doodle_pop.ogg");
|
||||
}
|
||||
|
||||
SECTION("wav")
|
||||
{
|
||||
REQUIRE(stream.open("Audio/killdeer.wav"));
|
||||
stream = sf::FileInputStream::open("Audio/killdeer.wav");
|
||||
}
|
||||
|
||||
CHECK(sf::SoundFileFactory::createReaderFromStream(stream));
|
||||
}
|
||||
REQUIRE(stream);
|
||||
CHECK(sf::SoundFileFactory::createReaderFromStream(*stream));
|
||||
}
|
||||
|
||||
SECTION("createWriterFromFilename()")
|
||||
|
@ -95,16 +95,7 @@ TEST_CASE("[Graphics] sf::Font", runDisplayTests())
|
||||
|
||||
SECTION("loadFromStream()")
|
||||
{
|
||||
sf::FileInputStream stream;
|
||||
|
||||
SECTION("Invalid stream")
|
||||
{
|
||||
CHECK(!sf::Font::loadFromStream(stream));
|
||||
}
|
||||
|
||||
SECTION("Successful load")
|
||||
{
|
||||
REQUIRE(stream.open("Graphics/tuffy.ttf"));
|
||||
auto stream = sf::FileInputStream::open("Graphics/tuffy.ttf").value();
|
||||
const auto font = sf::Font::loadFromStream(stream).value();
|
||||
CHECK(font.getInfo().family == "Tuffy");
|
||||
const auto& glyph = font.getGlyph(0x45, 16, false);
|
||||
@ -128,7 +119,6 @@ TEST_CASE("[Graphics] sf::Font", runDisplayTests())
|
||||
CHECK(texture.getNativeHandle() != 0);
|
||||
CHECK(font.isSmooth());
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Set/get smooth")
|
||||
{
|
||||
|
@ -178,23 +178,13 @@ TEST_CASE("[Graphics] sf::Image")
|
||||
|
||||
SECTION("loadFromStream()")
|
||||
{
|
||||
sf::FileInputStream stream;
|
||||
|
||||
SECTION("Invalid stream")
|
||||
{
|
||||
CHECK(!sf::Image::loadFromStream(stream));
|
||||
}
|
||||
|
||||
SECTION("Successful load")
|
||||
{
|
||||
CHECK(stream.open("Graphics/sfml-logo-big.png"));
|
||||
auto stream = sf::FileInputStream::open("Graphics/sfml-logo-big.png").value();
|
||||
const auto image = sf::Image::loadFromStream(stream).value();
|
||||
CHECK(image.getSize() == sf::Vector2u(1001, 304));
|
||||
CHECK(image.getPixelsPtr() != nullptr);
|
||||
CHECK(image.getPixel({0, 0}) == sf::Color(255, 255, 255, 0));
|
||||
CHECK(image.getPixel({200, 150}) == sf::Color(144, 208, 62));
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("saveToFile()")
|
||||
{
|
||||
|
@ -243,16 +243,11 @@ TEST_CASE("[Graphics] sf::Shader", skipShaderFullTests())
|
||||
|
||||
SECTION("loadFromStream()")
|
||||
{
|
||||
sf::FileInputStream vertexShaderStream;
|
||||
REQUIRE(vertexShaderStream.open("Graphics/shader.vert"));
|
||||
auto vertexShaderStream = sf::FileInputStream::open("Graphics/shader.vert").value();
|
||||
auto fragmentShaderStream = sf::FileInputStream::open("Graphics/shader.frag").value();
|
||||
auto geometryShaderStream = sf::FileInputStream::open("Graphics/shader.geom").value();
|
||||
|
||||
sf::FileInputStream fragmentShaderStream;
|
||||
REQUIRE(fragmentShaderStream.open("Graphics/shader.frag"));
|
||||
|
||||
sf::FileInputStream geometryShaderStream;
|
||||
REQUIRE(geometryShaderStream.open("Graphics/shader.geom"));
|
||||
|
||||
sf::FileInputStream emptyStream;
|
||||
auto emptyStream = sf::FileInputStream::open("Graphics/invalid_shader.vert").value();
|
||||
|
||||
SECTION("One shader")
|
||||
{
|
||||
|
@ -95,8 +95,7 @@ TEST_CASE("[Graphics] sf::Texture", runDisplayTests())
|
||||
|
||||
SECTION("loadFromStream()")
|
||||
{
|
||||
sf::FileInputStream stream;
|
||||
REQUIRE(stream.open("Graphics/sfml-logo-big.png"));
|
||||
auto stream = sf::FileInputStream::open("Graphics/sfml-logo-big.png").value();
|
||||
const auto texture = sf::Texture::loadFromStream(stream).value();
|
||||
CHECK(texture.getSize() == sf::Vector2u(1001, 304));
|
||||
CHECK(!texture.isSmooth());
|
||||
|
0
test/Graphics/invalid_shader.vert
Normal file
0
test/Graphics/invalid_shader.vert
Normal file
@ -66,21 +66,13 @@ TEST_CASE("[System] sf::FileInputStream")
|
||||
|
||||
SECTION("Type traits")
|
||||
{
|
||||
STATIC_CHECK(!std::is_default_constructible_v<sf::FileInputStream>);
|
||||
STATIC_CHECK(!std::is_copy_constructible_v<sf::FileInputStream>);
|
||||
STATIC_CHECK(!std::is_copy_assignable_v<sf::FileInputStream>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::FileInputStream>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::FileInputStream>);
|
||||
}
|
||||
|
||||
SECTION("Default constructor")
|
||||
{
|
||||
sf::FileInputStream fileInputStream;
|
||||
CHECK(fileInputStream.read(nullptr, 0) == std::nullopt);
|
||||
CHECK(fileInputStream.seek(0) == std::nullopt);
|
||||
CHECK(fileInputStream.tell() == std::nullopt);
|
||||
CHECK(fileInputStream.getSize() == std::nullopt);
|
||||
}
|
||||
|
||||
const TemporaryFile temporaryFile("Hello world");
|
||||
char buffer[32];
|
||||
|
||||
@ -88,9 +80,7 @@ TEST_CASE("[System] sf::FileInputStream")
|
||||
{
|
||||
SECTION("Move constructor")
|
||||
{
|
||||
sf::FileInputStream movedFileInputStream;
|
||||
REQUIRE(movedFileInputStream.open(temporaryFile.getPath()));
|
||||
|
||||
auto movedFileInputStream = sf::FileInputStream::open(temporaryFile.getPath()).value();
|
||||
sf::FileInputStream fileInputStream = std::move(movedFileInputStream);
|
||||
CHECK(fileInputStream.read(buffer, 6) == 6);
|
||||
CHECK(fileInputStream.tell() == 6);
|
||||
@ -100,10 +90,9 @@ TEST_CASE("[System] sf::FileInputStream")
|
||||
|
||||
SECTION("Move assignment")
|
||||
{
|
||||
sf::FileInputStream movedFileInputStream;
|
||||
REQUIRE(movedFileInputStream.open(temporaryFile.getPath()));
|
||||
|
||||
sf::FileInputStream fileInputStream;
|
||||
auto movedFileInputStream = sf::FileInputStream::open(temporaryFile.getPath()).value();
|
||||
const TemporaryFile temporaryFile2("Hello world the sequel");
|
||||
auto fileInputStream = sf::FileInputStream::open(temporaryFile2.getPath()).value();
|
||||
fileInputStream = std::move(movedFileInputStream);
|
||||
CHECK(fileInputStream.read(buffer, 6) == 6);
|
||||
CHECK(fileInputStream.tell() == 6);
|
||||
@ -114,8 +103,7 @@ TEST_CASE("[System] sf::FileInputStream")
|
||||
|
||||
SECTION("Temporary file stream")
|
||||
{
|
||||
sf::FileInputStream fileInputStream;
|
||||
REQUIRE(fileInputStream.open(temporaryFile.getPath()));
|
||||
auto fileInputStream = sf::FileInputStream::open(temporaryFile.getPath()).value();
|
||||
CHECK(fileInputStream.read(buffer, 5) == 5);
|
||||
CHECK(fileInputStream.tell() == 5);
|
||||
CHECK(fileInputStream.getSize() == 11);
|
||||
|
@ -25,7 +25,6 @@ int main()
|
||||
|
||||
// System
|
||||
[[maybe_unused]] const sf::Angle angle;
|
||||
[[maybe_unused]] const sf::FileInputStream fileInputStream;
|
||||
[[maybe_unused]] const sf::String string;
|
||||
[[maybe_unused]] const sf::Time time;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user