1 #ifndef _RIVE_FILE_READER_HPP_
2 #define _RIVE_FILE_READER_HPP_
4 #include <rive/file.hpp>
5 #include "rive_testing.hpp"
6 #include "no_op_factory.hpp"
8 static inline std::unique_ptr<rive::File>
9 ReadRiveFile(const char path[],
10 rive::Factory* factory = nullptr,
11 rive::FileAssetResolver* resolver = nullptr) {
13 factory = &rive::gNoOpFactory;
16 FILE* fp = fopen(path, "rb");
17 REQUIRE(fp != nullptr);
19 fseek(fp, 0, SEEK_END);
20 const size_t length = ftell(fp);
21 fseek(fp, 0, SEEK_SET);
22 std::vector<uint8_t> bytes(length);
23 REQUIRE(fread(bytes.data(), 1, length, fp) == length);
26 rive::ImportResult result;
27 auto file = rive::File::import(rive::toSpan(bytes), factory, &result, resolver);
28 REQUIRE(result == rive::ImportResult::success);
29 REQUIRE(file.get() != nullptr);
30 REQUIRE(file->artboard() != nullptr);