SerializableJSONFloatTest.cpp 1.7 KB

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