test_skeleton_3d.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**************************************************************************/
  2. /* test_skeleton_3d.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. #ifndef TEST_SKELETON_3D_H
  31. #define TEST_SKELETON_3D_H
  32. #include "tests/test_macros.h"
  33. #include "scene/3d/skeleton_3d.h"
  34. namespace TestSkeleton3D {
  35. TEST_CASE("[Skeleton3D] Test per-bone meta") {
  36. Skeleton3D *skeleton = memnew(Skeleton3D);
  37. skeleton->add_bone("root");
  38. skeleton->set_bone_rest(0, Transform3D());
  39. // Adding meta to bone.
  40. skeleton->set_bone_meta(0, "key1", "value1");
  41. skeleton->set_bone_meta(0, "key2", 12345);
  42. CHECK_MESSAGE(skeleton->get_bone_meta(0, "key1") == "value1", "Bone meta missing.");
  43. CHECK_MESSAGE(skeleton->get_bone_meta(0, "key2") == Variant(12345), "Bone meta missing.");
  44. // Rename bone and check if meta persists.
  45. skeleton->set_bone_name(0, "renamed_root");
  46. CHECK_MESSAGE(skeleton->get_bone_meta(0, "key1") == "value1", "Bone meta missing.");
  47. CHECK_MESSAGE(skeleton->get_bone_meta(0, "key2") == Variant(12345), "Bone meta missing.");
  48. // Retrieve list of keys.
  49. List<StringName> keys;
  50. skeleton->get_bone_meta_list(0, &keys);
  51. CHECK_MESSAGE(keys.size() == 2, "Wrong number of bone meta keys.");
  52. CHECK_MESSAGE(keys.find("key1"), "key1 not found in bone meta list");
  53. CHECK_MESSAGE(keys.find("key2"), "key2 not found in bone meta list");
  54. // Removing meta.
  55. skeleton->set_bone_meta(0, "key1", Variant());
  56. skeleton->set_bone_meta(0, "key2", Variant());
  57. CHECK_MESSAGE(!skeleton->has_bone_meta(0, "key1"), "Bone meta key1 should be deleted.");
  58. CHECK_MESSAGE(!skeleton->has_bone_meta(0, "key2"), "Bone meta key2 should be deleted.");
  59. List<StringName> should_be_empty_keys;
  60. skeleton->get_bone_meta_list(0, &should_be_empty_keys);
  61. CHECK_MESSAGE(should_be_empty_keys.size() == 0, "Wrong number of bone meta keys.");
  62. // Deleting non-existing key should succeed.
  63. skeleton->set_bone_meta(0, "non-existing-key", Variant());
  64. memdelete(skeleton);
  65. }
  66. } // namespace TestSkeleton3D
  67. #endif // TEST_SKELETON_3D_H