mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
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
This commit is contained in:
parent
118a82df54
commit
5695f84307
5 changed files with 124 additions and 0 deletions
61
test/capi/capiLottie.cpp
Normal file
61
test/capi/capiLottie.cpp
Normal file
|
@ -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 <thorvg_capi.h>
|
||||
#include <string.h>
|
||||
#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
|
|
@ -3,6 +3,7 @@ test_file = [
|
|||
'capiInitializer.cpp',
|
||||
'capiFill.cpp',
|
||||
'capiLinearGradient.cpp',
|
||||
'capiLottie.cpp',
|
||||
'capiMain.cpp',
|
||||
'capiPaint.cpp',
|
||||
'capiPicture.cpp',
|
||||
|
|
|
@ -7,6 +7,7 @@ test_file = [
|
|||
'testAnimation.cpp',
|
||||
'testFill.cpp',
|
||||
'testInitializer.cpp',
|
||||
'testLottie.cpp',
|
||||
'testMain.cpp',
|
||||
'testPaint.cpp',
|
||||
'testPicture.cpp',
|
||||
|
|
1
test/resources/lottieslot.json
Normal file
1
test/resources/lottieslot.json
Normal file
|
@ -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":[]}
|
60
test/testLottie.cpp
Normal file
60
test/testLottie.cpp
Normal file
|
@ -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 <thorvg.h>
|
||||
#include <thorvg_lottie.h>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#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
|
Loading…
Add table
Reference in a new issue