Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / rive-cpp / test / rive_file_reader.hpp
1 #ifndef _RIVE_FILE_READER_HPP_
2 #define _RIVE_FILE_READER_HPP_
3
4 #include <rive/file.hpp>
5 #include "rive_testing.hpp"
6 #include "no_op_factory.hpp"
7
8 static inline std::unique_ptr<rive::File>
9 ReadRiveFile(const char path[],
10              rive::Factory* factory = nullptr,
11              rive::FileAssetResolver* resolver = nullptr) {
12     if (!factory) {
13         factory = &rive::gNoOpFactory;
14     }
15
16     FILE* fp = fopen(path, "rb");
17     REQUIRE(fp != nullptr);
18
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);
24     fclose(fp);
25
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);
31
32     return file;
33 }
34
35 #endif