test/lottie: Add the segment use case

This commit is contained in:
Jinny You 2024-04-13 23:24:49 +09:00 committed by Hermet Park
parent e9bd05bad5
commit 22513b2fea
6 changed files with 182 additions and 0 deletions

View file

@ -96,4 +96,59 @@ TEST_CASE("Animation Lottie", "[capiAnimation]")
REQUIRE(tvg_engine_term(TVG_ENGINE_SW) == TVG_RESULT_SUCCESS); REQUIRE(tvg_engine_term(TVG_ENGINE_SW) == TVG_RESULT_SUCCESS);
} }
TEST_CASE("Animation Segment", "[capiAnimation]")
{
REQUIRE(tvg_engine_init(TVG_ENGINE_SW, 0) == TVG_RESULT_SUCCESS);
Tvg_Animation* animation = tvg_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);
float begin, end;
//Segment by range before loaded
REQUIRE(tvg_animation_set_segment(animation, 0, 0.5) == TVG_RESULT_INSUFFICIENT_CONDITION);
//Get current segment before loaded
REQUIRE(tvg_animation_get_segment(animation, &begin, &end) == TVG_RESULT_INSUFFICIENT_CONDITION);
//Animation load
REQUIRE(tvg_picture_load(picture, TEST_DIR"/lottiemarker.json") == TVG_RESULT_SUCCESS);
//Get current segment before segment
REQUIRE(tvg_animation_get_segment(animation, &begin, &end) == TVG_RESULT_SUCCESS);
REQUIRE(begin == 0.0f);
REQUIRE(end == 1.0f);
//Get only segment begin
REQUIRE(tvg_animation_get_segment(animation, &begin) == TVG_RESULT_SUCCESS);
REQUIRE(begin == 0.0f);
//Get only segment end
REQUIRE(tvg_animation_get_segment(animation, nullptr, &end) == TVG_RESULT_SUCCESS);
REQUIRE(end == 1.0f);
//Segment by range
REQUIRE(tvg_animation_set_segment(animation, 0.25, 0.5) == TVG_RESULT_SUCCESS);
//Get current segment before segment
REQUIRE(tvg_animation_get_segment(animation, &begin, &end) == TVG_RESULT_SUCCESS);
REQUIRE(begin == 0.25);
REQUIRE(end == 0.5);
//Segment by invalid range
REQUIRE(tvg_animation_set_segment(animation, -0.5, 1.5) == TVG_RESULT_INVALID_ARGUMENT);
REQUIRE(tvg_animation_del(animation) == TVG_RESULT_SUCCESS);
REQUIRE(tvg_engine_term(TVG_ENGINE_SW) == TVG_RESULT_SUCCESS);
}
#endif #endif

View file

@ -69,4 +69,48 @@ TEST_CASE("Lottie Slot", "[capiLottie]")
REQUIRE(tvg_engine_term(TVG_ENGINE_SW) == TVG_RESULT_SUCCESS); REQUIRE(tvg_engine_term(TVG_ENGINE_SW) == TVG_RESULT_SUCCESS);
} }
TEST_CASE("Lottie Marker", "[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);
//Set marker before loaded
REQUIRE(tvg_lottie_animation_set_marker(animation, "sectionC") == TVG_RESULT_INSUFFICIENT_CONDITION);
//Animation load
REQUIRE(tvg_picture_load(picture, TEST_DIR"/lottiemarker.json") == TVG_RESULT_SUCCESS);
//Set marker
REQUIRE(tvg_lottie_animation_set_marker(animation, "sectionA") == TVG_RESULT_SUCCESS);
//Set marker by invalid name
REQUIRE(tvg_lottie_animation_set_marker(animation, "") == TVG_RESULT_INVALID_ARGUMENT);
//Get marker count
uint32_t cnt = 0;
REQUIRE(tvg_lottie_animation_get_markers_cnt(animation, &cnt) == TVG_RESULT_SUCCESS);
REQUIRE(cnt == 3);
//Get marker name by index
const char* name = nullptr;
REQUIRE(tvg_lottie_animation_get_marker(animation, 1, &name) == TVG_RESULT_SUCCESS);
REQUIRE(!strcmp(name, "sectionB"));
//Get marker name by invalid index
REQUIRE(tvg_lottie_animation_get_marker(animation, -1, &name) == TVG_RESULT_INVALID_ARGUMENT);
REQUIRE(tvg_animation_del(animation) == TVG_RESULT_SUCCESS);
REQUIRE(tvg_engine_term(TVG_ENGINE_SW) == TVG_RESULT_SUCCESS);
}
#endif #endif

File diff suppressed because one or more lines are too long

Binary file not shown.

View file

@ -190,4 +190,52 @@ TEST_CASE("Animation Lottie9", "[tvgAnimation]")
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success); REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
} }
TEST_CASE("Animation Segment", "[tvgAnimation]")
{
REQUIRE(Initializer::init(tvg::CanvasEngine::Sw, 0) == Result::Success);
auto animation = Animation::gen();
REQUIRE(animation);
auto picture = animation->picture();
REQUIRE(picture->identifier == Picture::identifier);
float begin, end;
//Segment by range before loaded
REQUIRE(animation->segment(0, 0.5) == Result::InsufficientCondition);
//Get current segment before loaded
REQUIRE(animation->segment(&begin, &end) == Result::InsufficientCondition);
//Animation load
REQUIRE(picture->load(TEST_DIR"/lottiemarker.json") == Result::Success);
//Get current segment before segment
REQUIRE(animation->segment(&begin, &end) == Result::Success);
REQUIRE(begin == 0.0f);
REQUIRE(end == 1.0f);
//Segment by range
REQUIRE(animation->segment(0.25, 0.5) == Result::Success);
//Get current segment
REQUIRE(animation->segment(&begin, &end) == Result::Success);
REQUIRE(begin == 0.25);
REQUIRE(end == 0.5);
//Get only segment begin
REQUIRE(animation->segment(&begin) == Result::Success);
REQUIRE(begin == 0.25);
//Get only segment end
REQUIRE(animation->segment(nullptr, &end) == Result::Success);
REQUIRE(end == 0.5);
//Segment by invalid range
REQUIRE(animation->segment(-0.5, 1.5) == Result::InvalidArguments);
REQUIRE(Initializer::term(tvg::CanvasEngine::Sw) == Result::Success);
}
#endif #endif

View file

@ -68,4 +68,38 @@ TEST_CASE("Lottie Slot", "[tvgLottie]")
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success); REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
} }
TEST_CASE("Lottie Marker", "[tvgLottie]")
{
REQUIRE(Initializer::init(tvg::CanvasEngine::Sw, 0) == Result::Success);
auto animation = LottieAnimation::gen();
REQUIRE(animation);
auto picture = animation->picture();
REQUIRE(picture->identifier == Picture::identifier);
//Set marker name before loaded
REQUIRE(animation->segment("sectionC") == Result::InsufficientCondition);
//Animation load
REQUIRE(picture->load(TEST_DIR"/lottiemarker.json") == Result::Success);
//Set marker
REQUIRE(animation->segment("sectionA") == Result::Success);
//Set marker by invalid name
REQUIRE(animation->segment("") == Result::InvalidArguments);
//Get marker count
REQUIRE(animation->markersCnt() == 3);
//Get marker name by index
REQUIRE(!strcmp(animation->marker(1), "sectionB"));
//Get marker name by invalid index
REQUIRE(animation->marker(-1) == nullptr);
REQUIRE(Initializer::term(tvg::CanvasEngine::Sw) == Result::Success);
}
#endif #endif