test_animation_blend_tree.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #pragma once
  31. #include "scene/animation/animation_blend_tree.h"
  32. #include "tests/test_macros.h"
  33. #include "tests/test_utils.h"
  34. namespace TestAnimationBlendTree {
  35. TEST_CASE("[SceneTree][AnimationBlendTree] Create AnimationBlendTree and add AnimationNode") {
  36. Ref<AnimationNodeBlendTree> blend_tree;
  37. blend_tree.instantiate();
  38. // Test initial state.
  39. CHECK(blend_tree->has_node("output"));
  40. CHECK_EQ(blend_tree->get_graph_offset(), Vector2(0, 0));
  41. CHECK_EQ(blend_tree->get_node_list().size(), 1);
  42. // Test adding animation node.
  43. Ref<AnimationNodeAnimation> anim_node;
  44. anim_node.instantiate();
  45. anim_node->set_animation(StringName("test_animation"));
  46. Vector2 position(100, 100);
  47. blend_tree->add_node("test_node", anim_node, position);
  48. // Test node existence.
  49. CHECK(blend_tree->has_node("test_node"));
  50. CHECK_EQ(blend_tree->get_node("test_node"), anim_node);
  51. CHECK_EQ(blend_tree->get_node_position("test_node"), position);
  52. // Test node connection on port 0.
  53. CHECK_EQ(blend_tree->can_connect_node("output", 0, "test_node"), AnimationNodeBlendTree::CONNECTION_OK);
  54. blend_tree->connect_node("output", 0, "test_node");
  55. Vector<StringName> connections = blend_tree->get_node_connection_array("output");
  56. CHECK_EQ(connections.size(), 1);
  57. CHECK_EQ(connections[0], StringName("test_node"));
  58. // Test node rename.
  59. blend_tree->rename_node("test_node", "renamed_node");
  60. CHECK_FALSE(blend_tree->has_node("test_node"));
  61. CHECK(blend_tree->has_node("renamed_node"));
  62. connections = blend_tree->get_node_connection_array("output");
  63. CHECK_EQ(connections[0], StringName("renamed_node"));
  64. // Test node removal.
  65. blend_tree->remove_node("renamed_node");
  66. CHECK_FALSE(blend_tree->has_node("renamed_node"));
  67. connections = blend_tree->get_node_connection_array("output");
  68. CHECK_EQ(connections[0], StringName());
  69. }
  70. } //namespace TestAnimationBlendTree