SerializableJSONDoubleTest.cpp 1.1 KB

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