From 804ff2dddd34b9902aaade2e7e9b8b5d6c74e8fe Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Mon, 4 Sep 2023 13:45:40 +0200 Subject: [PATCH] Add tests for BTPauseAnimation --- tests/test_await_animation.h | 8 ++-- tests/test_pause_animation.h | 77 ++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 tests/test_pause_animation.h diff --git a/tests/test_await_animation.h b/tests/test_await_animation.h index 5066929..17312a9 100644 --- a/tests/test_await_animation.h +++ b/tests/test_await_animation.h @@ -19,6 +19,7 @@ #include "modules/limboai/bt/tasks/bt_task.h" #include "modules/limboai/bt/tasks/scene/bt_await_animation.h" +#include "scene/animation/animation_player.h" #include "scene/main/window.h" #include "scene/resources/animation.h" #include "scene/resources/animation_library.h" @@ -40,13 +41,12 @@ TEST_CASE("[SceneTree][LimboAI] BTAwaitAnimation") { REQUIRE(player->has_animation("test")); Ref awa = memnew(BTAwaitAnimation); - Node *dummy = memnew(Node); - SceneTree::get_singleton()->get_root()->add_child(dummy); - Ref bb = memnew(Blackboard); - awa->set_animation_name("test"); Ref player_param = memnew(BBNode); awa->set_animation_player(player_param); + Node *dummy = memnew(Node); + SceneTree::get_singleton()->get_root()->add_child(dummy); + Ref bb = memnew(Blackboard); SUBCASE("When AnimationPlayer doesn't exist") { player_param->set_saved_value(NodePath("./NotFound")); diff --git a/tests/test_pause_animation.h b/tests/test_pause_animation.h new file mode 100644 index 0000000..a6bc775 --- /dev/null +++ b/tests/test_pause_animation.h @@ -0,0 +1,77 @@ +/** + * test_pause_animation.h + * ============================================================================= + * Copyright 2021-2023 Serhii Snitsaruk + * + * Use of this source code is governed by an MIT-style + * license that can be found in the LICENSE file or at + * https://opensource.org/licenses/MIT. + * ============================================================================= + */ + +#ifndef TEST_PAUSE_ANIMATION_H +#define TEST_PAUSE_ANIMATION_H + +#include "limbo_test.h" + +#include "modules/limboai/bt/tasks/bt_task.h" +#include "modules/limboai/bt/tasks/scene/bt_pause_animation.h" + +#include "scene/animation/animation_player.h" +#include "scene/main/window.h" +#include "scene/resources/animation.h" +#include "scene/resources/animation_library.h" + +namespace TestPauseAnimation { + +TEST_CASE("[SceneTree][LimboAI] BTPauseAnimation") { + AnimationPlayer *player = memnew(AnimationPlayer); + SceneTree::get_singleton()->get_root()->add_child(player); + player->set_process_callback(AnimationPlayer::AnimationProcessCallback::ANIMATION_PROCESS_IDLE); + + Ref anim_lib = memnew(AnimationLibrary); + Ref anim = memnew(Animation); + anim->set_name("test"); + anim->set_length(0.1); + anim->set_loop_mode(Animation::LOOP_NONE); + REQUIRE(anim_lib->add_animation("test", anim) == OK); + REQUIRE(player->add_animation_library("", anim_lib) == OK); + REQUIRE(player->has_animation("test")); + + Ref pa = memnew(BTPauseAnimation); + Ref player_param = memnew(BBNode); + pa->set_animation_player(player_param); + Node *dummy = memnew(Node); + SceneTree::get_singleton()->get_root()->add_child(dummy); + Ref bb = memnew(Blackboard); + + SUBCASE("When AnimationPlayer doesn't exist") { + player_param->set_saved_value(NodePath("./NotFound")); + ERR_PRINT_OFF; + pa->initialize(dummy, bb); + CHECK(pa->execute(0.01666) == BTTask::FAILURE); + ERR_PRINT_ON; + } + SUBCASE("When AnimationPlayer exists") { + player_param->set_saved_value(player->get_path()); + pa->initialize(dummy, bb); + + SUBCASE("When AnimationPlayer is not playing") { + REQUIRE_FALSE(player->is_playing()); + CHECK(pa->execute(0.01666) == BTTask::SUCCESS); + } + SUBCASE("When AnimationPlayer is playing") { + player->play("test"); + REQUIRE(player->is_playing()); + CHECK(pa->execute(0.01666) == BTTask::SUCCESS); + CHECK_FALSE(player->is_playing()); + } + } + + memdelete(dummy); + memdelete(player); +} + +} //namespace TestPauseAnimation + +#endif // TEST_PAUSE_ANIMATION_H