SerializableJsonStringTest.cpp 1.7 KB

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