| 1 | /**************************************************************************/ |
| 2 | /* test_animation_blend_tree.h */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #pragma once |
| 32 | |
| 33 | #include "scene/animation/animation_blend_tree.h" |
| 34 | |
| 35 | #include "tests/test_macros.h" |
| 36 | #include "tests/test_utils.h" |
| 37 | |
| 38 | namespace TestAnimationBlendTree { |
| 39 | TEST_CASE("[SceneTree][AnimationBlendTree] Create AnimationBlendTree and add AnimationNode") { |
| 40 | Ref<AnimationNodeBlendTree> blend_tree; |
| 41 | blend_tree.instantiate(); |
| 42 | |
| 43 | // Test initial state. |
| 44 | CHECK(blend_tree->has_node("output")); |
| 45 | CHECK_EQ(blend_tree->get_graph_offset(), Vector2(0, 0)); |
| 46 | CHECK_EQ(blend_tree->get_node_list().size(), 1); |
| 47 | |
| 48 | // Test adding animation node. |
| 49 | Ref<AnimationNodeAnimation> anim_node; |
| 50 | anim_node.instantiate(); |
| 51 | anim_node->set_animation(StringName("test_animation")); |
| 52 | Vector2 position(100, 100); |
| 53 | blend_tree->add_node("test_node", anim_node, position); |
| 54 | |
| 55 | // Test node existence. |
| 56 | CHECK(blend_tree->has_node("test_node")); |
| 57 | CHECK_EQ(blend_tree->get_node("test_node"), anim_node); |
| 58 | CHECK_EQ(blend_tree->get_node_position("test_node"), position); |
| 59 | |
| 60 | // Test node connection on port 0. |
| 61 | CHECK_EQ(blend_tree->can_connect_node("output", 0, "test_node"), AnimationNodeBlendTree::CONNECTION_OK); |
| 62 | blend_tree->connect_node("output", 0, "test_node"); |
| 63 | |
| 64 | Vector<StringName> connections = blend_tree->get_node_connection_array("output"); |
| 65 | CHECK_EQ(connections.size(), 1); |
| 66 | CHECK_EQ(connections[0], StringName("test_node")); |
| 67 | |
| 68 | // Test node rename. |
| 69 | blend_tree->rename_node("test_node", "renamed_node"); |
| 70 | CHECK_FALSE(blend_tree->has_node("test_node")); |
| 71 | CHECK(blend_tree->has_node("renamed_node")); |
| 72 | |
| 73 | connections = blend_tree->get_node_connection_array("output"); |
| 74 | CHECK_EQ(connections[0], StringName("renamed_node")); |
| 75 | |
| 76 | // Test node removal. |
| 77 | blend_tree->remove_node("renamed_node"); |
| 78 | CHECK_FALSE(blend_tree->has_node("renamed_node")); |
| 79 | |
| 80 | connections = blend_tree->get_node_connection_array("output"); |
| 81 | CHECK_EQ(connections[0], StringName()); |
| 82 | } |
| 83 | |
| 84 | } //namespace TestAnimationBlendTree |