SerializableJSONDoubleTest.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-04
  6. * Changed: 2020-09-04
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include "../../../../source/boxing/Double.hpp"
  11. #include "../../../../source/serialization/boxing/SerializableJSONDouble.hpp"
  12. #include "../../../../source/boxing/String.hpp"
  13. namespace {
  14. class SerializableJSONDoubleTest : public ::testing::Test {
  15. protected:
  16. SerializableJSONDoubleTest() = default;
  17. ~SerializableJSONDoubleTest() override = default;
  18. void SetUp() override {}
  19. void TearDown() override {}
  20. };
  21. TEST_F(SerializableJSONDoubleTest, marshal)
  22. {
  23. ls_std::Double x {3.14159};
  24. ls_std::SerializableJSONDouble serializable {std::make_shared<ls_std::Double>(x)};
  25. ls_std::String jsonString {serializable.marshal()};
  26. ASSERT_TRUE(jsonString.contains(R"({"class":"Double","value":3.14159)"));
  27. }
  28. TEST_F(SerializableJSONDoubleTest, unmarshal)
  29. {
  30. std::shared_ptr<ls_std::Double> x = std::make_shared<ls_std::Double>(14.2234);
  31. ASSERT_DOUBLE_EQ(14.2234, *x);
  32. ls_std::SerializableJSONDouble serializable {x};
  33. serializable.unmarshal(R"({"class":"Double","value":3.14159})");
  34. ASSERT_DOUBLE_EQ(3.14159, *x);
  35. }
  36. }