SerializableJsonLongTest.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-26
  6. * Changed: 2021-05-02
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls_std/ls_std.hpp>
  11. namespace
  12. {
  13. class SerializableJsonLongTest : public ::testing::Test
  14. {
  15. protected:
  16. SerializableJsonLongTest() = default;
  17. ~SerializableJsonLongTest() override = default;
  18. void SetUp() override
  19. {}
  20. void TearDown() override
  21. {}
  22. };
  23. TEST_F(SerializableJsonLongTest, marshal)
  24. {
  25. ls_std::Long x{(ls_std::long_type) 31983771009271};
  26. ls_std::SerializableJsonLong serializable{std::make_shared<ls_std::Long>(x)};
  27. ls_std::byte_field content = serializable.marshal();
  28. ASSERT_STREQ(R"({"value":31983771009271})", content.c_str());
  29. }
  30. TEST_F(SerializableJsonLongTest, unmarshal)
  31. {
  32. std::shared_ptr<ls_std::Long> x = std::make_shared<ls_std::Long>(31983771009271);
  33. ASSERT_EQ(31983771009271, *x);
  34. ls_std::SerializableJsonLong serializable{x};
  35. serializable.unmarshal(R"({"value":1989})");
  36. ASSERT_EQ(1989, *x);
  37. }
  38. TEST_F(SerializableJsonLongTest, getValue)
  39. {
  40. std::shared_ptr<ls_std::Long> x = std::make_shared<ls_std::Long>(31983771009271);
  41. ls_std::SerializableJsonLong serializable{x};
  42. ASSERT_TRUE(serializable.getValue() == x);
  43. }
  44. TEST_F(SerializableJsonLongTest, setValue)
  45. {
  46. std::shared_ptr<ls_std::Long> x = std::make_shared<ls_std::Long>(31983771009271);
  47. ls_std::SerializableJsonLong serializable{x};
  48. ASSERT_TRUE(serializable.getValue() == x);
  49. x = std::make_shared<ls_std::Long>(31983771009221);
  50. serializable.setValue(x);
  51. ASSERT_TRUE(serializable.getValue() == x);
  52. }
  53. }