interpolate_node.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* interpolate_node.cpp - node tree / interpolate frame tests
  2. * Copyright (C) 2018 caryoscelus
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <catch.hpp>
  18. #include <core/node_info/node_info.h>
  19. #include <core/node_tree/actions.h>
  20. #include <core/node_tree/traverse.h>
  21. #include <core/node/abstract_node.h>
  22. #include "zero_context.h"
  23. using namespace rainynite;
  24. using namespace rainynite::core;
  25. class EmptyTraverser : public TreeTraverser {
  26. public:
  27. EmptyTraverser(NodeTree& tree) :
  28. TreeTraverser(tree)
  29. {}
  30. protected:
  31. bool object_start(NodeTree::Index /*index*/) override {
  32. return true;
  33. }
  34. void object_end(NodeTree::Index /*index*/) override {
  35. }
  36. };
  37. TEST_CASE("Interpolate / node tree / add frames", "[node]") {
  38. auto root = make_node_with_name_as<BaseValue<double>>("Interpolate/Real");
  39. auto root_node = abstract_node_cast(root);
  40. root_node->get_property("interpolate_with")->set_any(string{"WeightedAverage/Real"});
  41. CHECK(root->value(zero_context()) == 0.0);
  42. auto tree = NodeTree(root);
  43. root->set_any_at(4.5, zero_context());
  44. CHECK(root->value(zero_context()) == 4.5);
  45. CHECK(tree.get_node_count(root) == 1);
  46. auto frame_list = list_cast(root_node->get_property("keyframes"));
  47. CHECK(tree.get_node_count(frame_list->get_link(0)) == 1);
  48. EmptyTraverser traverser(tree);
  49. traverser.traverse_tree();
  50. }