up-to-date submodule(rive-cpp)
[platform/core/uifw/rive-tizen.git] / submodule / test / bound_bones_test.cpp
1 #include "bones/skin.hpp"
2 #include "bones/tendon.hpp"
3 #include "catch.hpp"
4 #include "core/binary_reader.hpp"
5 #include "file.hpp"
6 #include "no_op_renderer.hpp"
7 #include "node.hpp"
8 #include "shapes/clipping_shape.hpp"
9 #include "shapes/path_vertex.hpp"
10 #include "shapes/points_path.hpp"
11 #include "shapes/rectangle.hpp"
12 #include "shapes/shape.hpp"
13 #include <cstdio>
14
15 TEST_CASE("bound bones load correctly", "[bones]")
16 {
17         FILE* fp = fopen("../../test/assets/off_road_car.riv", "r");
18         REQUIRE(fp != nullptr);
19
20         fseek(fp, 0, SEEK_END);
21         auto length = ftell(fp);
22         fseek(fp, 0, SEEK_SET);
23         uint8_t* bytes = new uint8_t[length];
24         REQUIRE(fread(bytes, 1, length, fp) == length);
25         auto reader = rive::BinaryReader(bytes, length);
26         rive::File* file = nullptr;
27
28         auto result = rive::File::import(reader, &file);
29
30         REQUIRE(result == rive::ImportResult::success);
31
32         REQUIRE(file != nullptr);
33         REQUIRE(file->artboard() != nullptr);
34
35         auto node = file->artboard()->find("transmission_front_testing");
36         REQUIRE(node != nullptr);
37         REQUIRE(node->is<rive::Shape>());
38         REQUIRE(node->as<rive::Shape>()->paths().size() == 1);
39         auto path = node->as<rive::Shape>()->paths()[0];
40         REQUIRE(path->is<rive::PointsPath>());
41         auto pointsPath = path->as<rive::PointsPath>();
42         REQUIRE(pointsPath->skin() != nullptr);
43         REQUIRE(pointsPath->skin()->tendons().size() == 2);
44         REQUIRE(pointsPath->skin()->tendons()[0]->bone() != nullptr);
45         REQUIRE(pointsPath->skin()->tendons()[1]->bone() != nullptr);
46
47         for (auto vertex : path->vertices())
48         {
49                 REQUIRE(vertex->weight() != nullptr);
50         }
51
52         // Ok seems like bones are set up ok.
53
54         delete file;
55         delete[] bytes;
56 }