SerializableJSONDoubleTest.cpp 1.7 KB

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