1 #include <rive/file.hpp>
2 #include <rive/node.hpp>
3 #include <rive/shapes/rectangle.hpp>
4 #include <rive/shapes/shape.hpp>
5 #include "no_op_renderer.hpp"
6 #include "rive_file_reader.hpp"
10 TEST_CASE("file can be read", "[file]") {
11 auto file = ReadRiveFile("../../test/assets/two_artboards.riv");
13 // Default artboard should be named Two.
14 REQUIRE(file->artboard()->name() == "Two");
16 // There should be a second artboard named One.
17 REQUIRE(file->artboard("One") != nullptr);
20 TEST_CASE("file with animation can be read", "[file]") {
21 auto file = ReadRiveFile("../../test/assets/juice.riv");
23 auto artboard = file->artboard();
24 REQUIRE(artboard->name() == "New Artboard");
26 auto shin = artboard->find("shin_right");
27 REQUIRE(shin != nullptr);
28 REQUIRE(shin->is<rive::Node>());
30 auto shinNode = shin->as<rive::Node>();
31 REQUIRE(shinNode->parent() != nullptr);
32 REQUIRE(shinNode->parent()->name() == "leg_right");
33 REQUIRE(shinNode->parent()->parent() != nullptr);
34 REQUIRE(shinNode->parent()->parent()->name() == "root");
35 REQUIRE(shinNode->parent()->parent() != nullptr);
36 REQUIRE(shinNode->parent()->parent()->parent() != nullptr);
37 REQUIRE(shinNode->parent()->parent()->parent() == artboard);
39 auto walkAnimation = artboard->animation("walk");
40 REQUIRE(walkAnimation != nullptr);
41 REQUIRE(walkAnimation->numKeyedObjects() == 22);
44 TEST_CASE("artboards can be counted and accessed via index or name", "[file]") {
45 auto file = ReadRiveFile("../../test/assets/dependency_test.riv");
47 // The artboards caqn be counted
48 REQUIRE(file->artboardCount() == 1);
50 // Artboards can be access by index
51 REQUIRE(file->artboard(0) != nullptr);
53 // Artboards can be accessed by name
54 REQUIRE(file->artboard("Blue") != nullptr);
57 TEST_CASE("dependencies are as expected", "[file]") {
76 auto file = ReadRiveFile("../../test/assets/dependency_test.riv");
78 auto artboard = file->artboard();
79 REQUIRE(artboard->name() == "Blue");
81 auto nodeA = artboard->find<rive::Node>("A");
82 auto nodeB = artboard->find<rive::Node>("B");
83 auto nodeC = artboard->find<rive::Node>("C");
84 auto shape = artboard->find<rive::Shape>("Rectangle");
85 auto path = artboard->find<rive::Path>("Rectangle Path");
86 REQUIRE(nodeA != nullptr);
87 REQUIRE(nodeB != nullptr);
88 REQUIRE(nodeC != nullptr);
89 REQUIRE(shape != nullptr);
90 REQUIRE(path != nullptr);
92 REQUIRE(nodeA->parent() == artboard);
93 REQUIRE(nodeB->parent() == nodeA);
94 REQUIRE(nodeC->parent() == nodeB);
95 REQUIRE(shape->parent() == nodeB);
96 REQUIRE(path->parent() == shape);
98 REQUIRE(nodeB->dependents().size() == 2);
100 REQUIRE(artboard->graphOrder() == 0);
101 REQUIRE(nodeA->graphOrder() > artboard->graphOrder());
102 REQUIRE(nodeB->graphOrder() > nodeA->graphOrder());
103 REQUIRE(nodeC->graphOrder() > nodeB->graphOrder());
104 REQUIRE(shape->graphOrder() > nodeB->graphOrder());
105 REQUIRE(path->graphOrder() > shape->graphOrder());
107 artboard->advance(0.0f);
109 auto world = shape->worldTransform();
110 REQUIRE(world[4] == 39.203125f);
111 REQUIRE(world[5] == 29.535156f);
114 TEST_CASE("long name in object is parsed correctly", "[file]") {
115 auto file = ReadRiveFile("../../test/assets/long_name.riv");
116 auto artboard = file->artboard();
118 // Expect all object in file to be loaded, in this case 7
119 REQUIRE(artboard->objects().size() == 7);
123 // ShapePaint (fill/stroke) needs to be implemented in WASM (jsFill/jsStroke) in
124 // order to create Paint objects as necessary.
126 // Mutators need to be implemented in WASM (solid/linear/radial) and get access
127 // to their ShapePaint so they can mutate any extra objects they create on it
128 // (like a paint object for skia).
130 // Paths need to be implemented in WASM but not so much as a core path (like
131 // parametric/pointspath, etc) but more as a general rendering path. Handed
132 // their commands so they can generate/store a re-usable path. This would be a
133 // Path2D in context2D and a SkPath in CanvasKit.
135 // PathComposer is the factory for the Paths. But they do need to surive so they
136 // can be reset/reused as available by the rendering lib.
138 // PathComposer needs to be implemented in WASM to compose the paths together
139 // and be accessible from the Shape (jsShape) which will need a call
140 // setupFill/restoreFill and setupStroke/restoreStroke.
142 // Draw will be called by C++ on the Shape, the Shape will call draw on the
143 // fill/stroke (propagates to jsFill/jsStroke)