SerializableJsonFloatTest.cpp 1.7 KB

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