From 5695f84307f4aa3da3b1ef64dad469f2e0b2badc Mon Sep 17 00:00:00 2001 From: Jinny You Date: Wed, 6 Mar 2024 17:36:45 +0900 Subject: [PATCH] test: Added test code for the lottie slot This patch adds the test case for the recently introduced lottie slot API. @Issues: https://github.com/thorvg/thorvg/issues/2029 --- test/capi/capiLottie.cpp | 61 ++++++++++++++++++++++++++++++++++ test/capi/meson.build | 1 + test/meson.build | 1 + test/resources/lottieslot.json | 1 + test/testLottie.cpp | 60 +++++++++++++++++++++++++++++++++ 5 files changed, 124 insertions(+) create mode 100644 test/capi/capiLottie.cpp create mode 100644 test/resources/lottieslot.json create mode 100644 test/testLottie.cpp diff --git a/test/capi/capiLottie.cpp b/test/capi/capiLottie.cpp new file mode 100644 index 00000000..fd99bb4e --- /dev/null +++ b/test/capi/capiLottie.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 the ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include "config.h" +#include "../catch.hpp" + +#ifdef THORVG_LOTTIE_LOADER_SUPPORT + +TEST_CASE("Lottie Slot", "[capiLottie]") +{ + REQUIRE(tvg_engine_init(TVG_ENGINE_SW, 0) == TVG_RESULT_SUCCESS); + + Tvg_Animation* animation = tvg_lottie_animation_new(); + REQUIRE(animation); + + Tvg_Paint* picture = tvg_animation_get_picture(animation); + REQUIRE(picture); + + Tvg_Identifier id = TVG_IDENTIFIER_UNDEF; + REQUIRE(tvg_paint_get_identifier(picture, &id) == TVG_RESULT_SUCCESS); + REQUIRE(id == TVG_IDENTIFIER_PICTURE); + + const char* slotJson = R"({"gradient_fill":{"p":{"a":0,"k":[0,0.1,0.1,0.2,1,1,0.1,0.2,0.1,1]}}})"; + + //Slot override before loaded + REQUIRE(tvg_lottie_animation_override(animation, slotJson) == TVG_RESULT_INSUFFICIENT_CONDITION); + + //Slot override + REQUIRE(tvg_picture_load(picture, TEST_DIR"/lottieslot.json") == TVG_RESULT_SUCCESS); + REQUIRE(tvg_lottie_animation_override(animation, slotJson) == TVG_RESULT_SUCCESS); + + //Slot override with invalid JSON + REQUIRE(tvg_lottie_animation_override(animation, "") == TVG_RESULT_INVALID_ARGUMENT); + + REQUIRE(tvg_animation_del(animation) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_engine_term(TVG_ENGINE_SW) == TVG_RESULT_SUCCESS); +} + +#endif \ No newline at end of file diff --git a/test/capi/meson.build b/test/capi/meson.build index d098d657..e3bf5a5a 100644 --- a/test/capi/meson.build +++ b/test/capi/meson.build @@ -3,6 +3,7 @@ test_file = [ 'capiInitializer.cpp', 'capiFill.cpp', 'capiLinearGradient.cpp', + 'capiLottie.cpp', 'capiMain.cpp', 'capiPaint.cpp', 'capiPicture.cpp', diff --git a/test/meson.build b/test/meson.build index b7a00397..37ea0232 100644 --- a/test/meson.build +++ b/test/meson.build @@ -7,6 +7,7 @@ test_file = [ 'testAnimation.cpp', 'testFill.cpp', 'testInitializer.cpp', + 'testLottie.cpp', 'testMain.cpp', 'testPaint.cpp', 'testPicture.cpp', diff --git a/test/resources/lottieslot.json b/test/resources/lottieslot.json new file mode 100644 index 00000000..ecd25f57 --- /dev/null +++ b/test/resources/lottieslot.json @@ -0,0 +1 @@ +{"v":"4.8.0","meta":{"g":"LottieFiles AE 3.0.2","a":"","k":"","d":"","tc":""},"fr":60,"ip":0,"op":121,"w":550,"h":550,"nm":"C","assets":[],"layers":[{"ind":1,"ty":4,"nm":"S","sr":1,"ks":{"o":{"a":0,"k":100},"r":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[0]},{"t":120,"s":[360]}]},"p":{"a":0,"k":[275,275,0]},"a":{"a":0,"k":[-7.886,88.719,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"gr","it":[{"ty":"rc","d":1,"s":{"a":0,"k":[282.019,134.888]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"nm":"R"},{"ty":"st","c":{"a":0,"k":[0.991,0,1,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":3},"lc":1,"lj":1,"ml":4,"nm":"S"},{"ty":"gf","o":{"a":0,"k":100},"r":1,"g":{"p":9,"k":{"a":0,"k":[0,0.514,0.373,0.984,0.141,0.478,0.412,0.984,0.283,0.443,0.451,0.984,0.379,0.408,0.49,0.984,0.475,0.373,0.529,0.984,0.606,0.278,0.647,0.925,0.737,0.184,0.765,0.867,0.868,0.092,0.882,0.808,1,0,1,0.749],"sid":"gradient_fill"}},"s":{"a":0,"k":[-159.51,23.531]},"e":{"a":0,"k":[183.084,8.059]},"t":1,"nm":"G"},{"ty":"tr","p":{"a":0,"k":[-7.886,88.719]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100},"sk":{"a":0,"k":0},"sa":{"a":0,"k":0},"nm":"T"}],"nm":"R"}],"ip":0,"op":300,"st":0}],"slots":{"gradient_fill":{"p":{"a":0,"k":[0,0.1,0.1,0.2,1,1,0.1,0.2,0.1,1]}}},"markers":[]} \ No newline at end of file diff --git a/test/testLottie.cpp b/test/testLottie.cpp new file mode 100644 index 00000000..6bb59721 --- /dev/null +++ b/test/testLottie.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2024 the ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include "config.h" +#include "catch.hpp" + +using namespace tvg; +using namespace std; + +#ifdef THORVG_LOTTIE_LOADER_SUPPORT + +TEST_CASE("Lottie Slot", "[tvgLottie]") +{ + REQUIRE(Initializer::init(0) == Result::Success); + + auto animation = LottieAnimation::gen(); + REQUIRE(animation); + + auto picture = animation->picture(); + REQUIRE(picture->identifier == Picture::identifier); + + const char* slotJson = R"({"gradient_fill":{"p":{"a":0,"k":[0,0.1,0.1,0.2,1,1,0.1,0.2,0.1,1]}}})"; + + //Slot override before loaded + REQUIRE(animation->override(slotJson) == Result::InsufficientCondition); + + //Slot override + REQUIRE(picture->load(TEST_DIR"/lottieslot.json") == Result::Success); + REQUIRE(animation->override(slotJson) == Result::Success); + + //Slot override with invalid JSON + REQUIRE(animation->override("") == Result::InvalidArguments); + + REQUIRE(Initializer::term() == Result::Success); +} + +#endif \ No newline at end of file