SerializableJSONFloatTest.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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/Float.hpp"
  11. #include "../../../../source/serialization/boxing/SerializableJSONFloat.hpp"
  12. #include "../../../../source/boxing/String.hpp"
  13. namespace {
  14. class SerializableJSONFloatTest : public ::testing::Test {
  15. protected:
  16. SerializableJSONFloatTest() = default;
  17. ~SerializableJSONFloatTest() override = default;
  18. void SetUp() override {}
  19. void TearDown() override {}
  20. };
  21. TEST_F(SerializableJSONFloatTest, marshal)
  22. {
  23. ls_std::Float x {3.14159f};
  24. ls_std::SerializableJSONFloat serializable {std::make_shared<ls_std::Float>(x)};
  25. ls_std::String jsonString {serializable.marshal()};
  26. ASSERT_TRUE(jsonString.contains(R"({"class":"Float","value":3.14159)"));
  27. }
  28. TEST_F(SerializableJSONFloatTest, unmarshal)
  29. {
  30. std::shared_ptr<ls_std::Float> x = std::make_shared<ls_std::Float>(14.2234f);
  31. ASSERT_FLOAT_EQ(14.2234f, *x);
  32. ls_std::SerializableJSONFloat serializable {x};
  33. serializable.unmarshal(R"({"class":"Float","value":3.14159})");
  34. ASSERT_FLOAT_EQ(3.14159f, *x);
  35. }
  36. }