serialize.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* serialize.cpp - serializing tests
  2. * Copyright (C) 2017-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 <iostream>
  19. #include <core/util/type_info.h>
  20. #include <core/node_info/macros.h>
  21. #include <core/serialize/node_reader.h>
  22. #include "new_node.h"
  23. REGISTER_NODE(Add);
  24. using namespace rainynite;
  25. using namespace rainynite::core;
  26. TEST_CASE("Read double", "[serialize]") {
  27. auto x = parse_primitive_type_to<double>("Real", "3.5");
  28. CHECK(x == 3.5);
  29. }
  30. TEST_CASE("Deserialize", "[serialize,node]") {
  31. serialize::NodeDeserializer s;
  32. s.object_start("a");
  33. s.type("Add");
  34. s.key("a");
  35. s.object_start("xx");
  36. s.type("Value/Real");
  37. s.object_value_start();
  38. s.value_string("1");
  39. s.object_value_end();
  40. s.object_end();
  41. s.key("b");
  42. s.object_start("yyy");
  43. s.type("Value/Real");
  44. s.object_value_start();
  45. s.value_string("2");
  46. s.object_value_end();
  47. s.object_end();
  48. s.object_end();
  49. auto add = s.get_root();
  50. CHECK(add->get_type() == typeid(double));
  51. CHECK(any_cast<double>(add->get_any({})) == 3);
  52. }