Add tests for BBNode param

This commit is contained in:
Serhii Snitsaruk 2023-09-10 10:54:59 +02:00
parent 7767d7c72a
commit 3e8a158835
1 changed files with 54 additions and 0 deletions

View File

@ -12,7 +12,9 @@
#ifndef TEST_BB_PARAM_H #ifndef TEST_BB_PARAM_H
#define TEST_BB_PARAM_H #define TEST_BB_PARAM_H
#include "core/object/ref_counted.h"
#include "core/string/node_path.h" #include "core/string/node_path.h"
#include "core/variant/variant.h"
#include "limbo_test.h" #include "limbo_test.h"
#include "modules/limboai/blackboard/bb_param/bb_node.h" #include "modules/limboai/blackboard/bb_param/bb_node.h"
@ -66,6 +68,58 @@ TEST_CASE("[Modules][LimboAI] BBParam") {
memdelete(dummy); memdelete(dummy);
} }
TEST_CASE("[Modules][LimboAI] BBNode") {
Ref<BBNode> param = memnew(BBNode);
Node *dummy = memnew(Node);
Ref<Blackboard> bb = memnew(Blackboard);
Node *other = memnew(Node);
other->set_name("Other");
dummy->add_child(other);
SUBCASE("With a valid path") {
param->set_value_source(BBParam::SAVED_VALUE);
param->set_saved_value(NodePath("./Other"));
CHECK(param->get_value(dummy, bb).get_type() == Variant::Type::OBJECT);
CHECK(param->get_value(dummy, bb) == Variant(other));
}
SUBCASE("With an invalid path") {
param->set_value_source(BBParam::SAVED_VALUE);
param->set_saved_value(NodePath("./SomeOther"));
ERR_PRINT_OFF;
CHECK(param->get_value(dummy, bb, Variant()).is_null());
ERR_PRINT_ON;
}
SUBCASE("With an object on the blackboard") {
param->set_value_source(BBParam::BLACKBOARD_VAR);
param->set_variable("test_var");
SUBCASE("When variable exists") {
bb->set_var("test_var", other);
CHECK(param->get_value(dummy, bb).get_type() == Variant::Type::OBJECT);
CHECK(param->get_value(dummy, bb) == Variant(other));
}
SUBCASE("When variable doesn't exist") {
CHECK(param->get_value(dummy, bb, Variant()).is_null());
}
SUBCASE("When variable has wrong type") {
bb->set_var("test_var", 123);
ERR_PRINT_OFF;
CHECK(param->get_value(dummy, bb, Variant()).is_null());
ERR_PRINT_ON;
}
SUBCASE("When variable is an object") {
// * Note: We allow also fetching objects on the blackboard.
Ref<RefCounted> some_other = memnew(RefCounted);
bb->set_var("test_var", some_other);
CHECK(param->get_value(dummy, bb) == some_other);
}
}
memdelete(other);
memdelete(dummy);
}
} //namespace TestBBParam } //namespace TestBBParam
#endif // TEST_BB_PARAM_H #endif // TEST_BB_PARAM_H