From b83417501642838cf9dcc4583a4d3c0029e23cc9 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Sat, 2 Sep 2023 10:50:07 +0200 Subject: [PATCH] Add tests for BTCheckTrigger --- tests/test_check_trigger.h | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tests/test_check_trigger.h diff --git a/tests/test_check_trigger.h b/tests/test_check_trigger.h new file mode 100644 index 0000000..3732082 --- /dev/null +++ b/tests/test_check_trigger.h @@ -0,0 +1,63 @@ +/** + * test_check_trigger.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_CHECK_TRIGGER_H +#define TEST_CHECK_TRIGGER_H + +#include "limbo_test.h" + +#include "modules/limboai/bt/tasks/blackboard/bt_check_trigger.h" +#include "modules/limboai/bt/tasks/bt_task.h" + +namespace TestCheckTrigger { + +TEST_CASE("[Modules][LimboAI] BTCheckTrigger") { + Ref ct = memnew(BTCheckTrigger); + Node *dummy = memnew(Node); + Ref bb = memnew(Blackboard); + + ct->initialize(dummy, bb); + + SUBCASE("Empty") { + ERR_PRINT_OFF; + ct->set_variable(""); + CHECK(ct->execute(0.01666) == BTTask::FAILURE); + ERR_PRINT_ON; + } + + ct->set_variable("trigger"); + + SUBCASE("When variable is not set") { + CHECK(ct->execute(0.01666) == BTTask::FAILURE); + } + SUBCASE("When variable set to false") { + bb->set_var("trigger", false); + CHECK(ct->execute(0.01666) == BTTask::FAILURE); + CHECK(bb->get_var("trigger", false) == Variant(false)); + } + SUBCASE("When variable set to true") { + bb->set_var("trigger", true); + CHECK(bb->get_var("trigger", false) == Variant(true)); + CHECK(ct->execute(0.01666) == BTTask::SUCCESS); + CHECK(bb->get_var("trigger", false) == Variant(false)); + } + SUBCASE("When variable set to non-bool") { + bb->set_var("trigger", "Some text"); + CHECK(ct->execute(0.01666) == BTTask::FAILURE); + CHECK(bb->get_var("trigger", Variant()) == "Some text"); + } + + memdelete(dummy); +} + +} //namespace TestCheckTrigger + +#endif // TEST_CHECK_TRIGGER_H