forked from limbonaut/limboai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_check_trigger.h
65 lines (53 loc) · 1.81 KB
/
test_check_trigger.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* test_check_trigger.h
* =============================================================================
* Copyright (c) 2023-present Serhii Snitsaruk and the LimboAI contributors.
*
* 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<BTCheckTrigger> ct = memnew(BTCheckTrigger);
Node *dummy = memnew(Node);
Ref<Blackboard> bb = memnew(Blackboard);
ct->initialize(dummy, bb, dummy);
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 found") {
ERR_PRINT_OFF;
CHECK(ct->execute(0.01666) == BTTask::FAILURE);
ERR_PRINT_ON;
}
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