blob: 19001f0319e3df7da8859a2f81ebd38e868d8683 [file] [log] [blame]
#ifndef _RIVE_FILE_READER_HPP_
#define _RIVE_FILE_READER_HPP_
#include <rive/file.hpp>
#include "rive_testing.hpp"
#include "utils/no_op_factory.hpp"
static rive::NoOpFactory gNoOpFactory;
static inline std::vector<uint8_t> ReadFile(const char path[])
{
FILE* fp = fopen(path, "rb");
REQUIRE(fp != nullptr);
fseek(fp, 0, SEEK_END);
const size_t length = ftell(fp);
fseek(fp, 0, SEEK_SET);
std::vector<uint8_t> bytes(length);
REQUIRE(fread(bytes.data(), 1, length, fp) == length);
fclose(fp);
return bytes;
}
static inline std::unique_ptr<rive::File> ReadRiveFile(const char path[],
rive::Factory* factory = nullptr,
rive::FileAssetLoader* loader = nullptr,
bool loadInBandAssets = true)
{
if (!factory)
{
factory = &gNoOpFactory;
}
std::vector<uint8_t> bytes = ReadFile(path);
rive::ImportResult result;
auto file = rive::File::import(bytes, factory, &result, loader);
REQUIRE(result == rive::ImportResult::success);
REQUIRE(file.get() != nullptr);
REQUIRE(file->artboard() != nullptr);
return file;
}
#endif