From 1648728e1b315d9d700a0f9b4c74a26e1c7811c9 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Tue, 16 Jan 2024 10:46:42 +0100 Subject: [PATCH] CallMethod: Update unit tests --- blackboard/bb_param/bb_variant.cpp | 5 +++++ blackboard/bb_param/bb_variant.h | 1 + tests/test_call_method.h | 15 +++++++-------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/blackboard/bb_param/bb_variant.cpp b/blackboard/bb_param/bb_variant.cpp index cec0cf4..75379f8 100644 --- a/blackboard/bb_param/bb_variant.cpp +++ b/blackboard/bb_param/bb_variant.cpp @@ -39,5 +39,10 @@ void BBVariant::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, vtypes), "set_type", "get_type"); } +BBVariant::BBVariant(const Variant &p_value) { + set_type(p_value.get_type()); + set_saved_value(p_value); +} + BBVariant::BBVariant() { } diff --git a/blackboard/bb_param/bb_variant.h b/blackboard/bb_param/bb_variant.h index 5634206..8021a39 100644 --- a/blackboard/bb_param/bb_variant.h +++ b/blackboard/bb_param/bb_variant.h @@ -27,6 +27,7 @@ public: virtual Variant::Type get_type() const override; void set_type(Variant::Type p_type); + BBVariant(const Variant &p_value); BBVariant(); }; diff --git a/tests/test_call_method.h b/tests/test_call_method.h index dad3401..c2ccc9b 100644 --- a/tests/test_call_method.h +++ b/tests/test_call_method.h @@ -70,7 +70,7 @@ TEST_CASE("[Modules][LimboAI] BTCallMethod") { SUBCASE("Should fail with 0 arguments") { cm->set_include_delta(false); - cm->set_args(Array()); + cm->set_args(TypedArray()); ERR_PRINT_OFF; CHECK(cm->execute(0.01666) == BTTask::FAILURE); ERR_PRINT_ON; @@ -78,8 +78,8 @@ TEST_CASE("[Modules][LimboAI] BTCallMethod") { } SUBCASE("Should fail with too many arguments") { cm->set_include_delta(true); - Array args; - args.push_back(0.2); + TypedArray args; + args.push_back(memnew(BBVariant(0.2))); cm->set_args(args); ERR_PRINT_OFF; CHECK(cm->execute(0.01666) == BTTask::FAILURE); @@ -88,8 +88,8 @@ TEST_CASE("[Modules][LimboAI] BTCallMethod") { } SUBCASE("Should fail with a wrong type arg") { cm->set_include_delta(false); - Array args; - args.push_back("wrong_data"); + TypedArray args; + args.push_back(memnew(BBVariant("wrong data type"))); cm->set_args(args); ERR_PRINT_OFF; CHECK(cm->execute(0.01666) == BTTask::FAILURE); @@ -98,14 +98,13 @@ TEST_CASE("[Modules][LimboAI] BTCallMethod") { } SUBCASE("Should succeed with delta included") { cm->set_include_delta(true); - cm->set_args(Array()); CHECK(cm->execute(0.01666) == BTTask::SUCCESS); CHECK(callback_counter->num_callbacks == 1); } SUBCASE("Should succeed with one float arg") { cm->set_include_delta(false); - Array args; - args.push_back(0.2); + TypedArray args; + args.push_back(memnew(BBVariant(0.2))); cm->set_args(args); CHECK(cm->execute(0.01666) == BTTask::SUCCESS); CHECK(callback_counter->num_callbacks == 1);