SerializableJsonStateConnectionTest.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-14
  6. * Changed: 2021-05-02
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls_std/ls_std.hpp>
  11. namespace
  12. {
  13. class SerializableJsonStateConnectionTest : public ::testing::Test
  14. {
  15. protected:
  16. SerializableJsonStateConnectionTest() = default;
  17. ~SerializableJsonStateConnectionTest() override = default;
  18. void SetUp() override
  19. {}
  20. void TearDown() override
  21. {}
  22. };
  23. // implementation
  24. TEST_F(SerializableJsonStateConnectionTest, marshal)
  25. {
  26. ls_std::StateConnection x{"AB", "B"};
  27. ls_std::SerializableJsonStateConnection serializable{std::make_shared<ls_std::StateConnection>(x)};
  28. ls_std::String jsonString{serializable.marshal()};
  29. ASSERT_STREQ(R"({"condition":false,"connectionId":"AB","stateId":"B"})", jsonString.toString().c_str());
  30. }
  31. TEST_F(SerializableJsonStateConnectionTest, unmarshal)
  32. {
  33. std::shared_ptr<ls_std::StateConnection> x = std::make_shared<ls_std::StateConnection>("AB", "B");
  34. ASSERT_STREQ("AB", x->getConnectionId().c_str());
  35. ASSERT_STREQ("B", x->getStateId().c_str());
  36. ASSERT_FALSE(x->isPassable());
  37. ls_std::SerializableJsonStateConnection serializable{x};
  38. serializable.unmarshal(R"({"condition":true,"connectionId":"BC","stateId":"C"})");
  39. ASSERT_STREQ("BC", x->getConnectionId().c_str());
  40. ASSERT_STREQ("C", x->getStateId().c_str());
  41. ASSERT_TRUE(x->isPassable());
  42. }
  43. TEST_F(SerializableJsonStateConnectionTest, getValue)
  44. {
  45. std::shared_ptr<ls_std::StateConnection> x = std::make_shared<ls_std::StateConnection>("AB", "B");
  46. ls_std::SerializableJsonStateConnection serializable{x};
  47. ASSERT_TRUE(serializable.getValue() == x);
  48. }
  49. TEST_F(SerializableJsonStateConnectionTest, setValue)
  50. {
  51. ls_std::StateConnection x{"AB", "B"};
  52. ls_std::SerializableJsonStateConnection serializable{std::make_shared<ls_std::StateConnection>(x)};
  53. ls_std::String jsonString{serializable.marshal()};
  54. ASSERT_STREQ(R"({"condition":false,"connectionId":"AB","stateId":"B"})", jsonString.toString().c_str());
  55. // set value should now reset json
  56. ls_std::StateConnection y{"BC", "C"};
  57. serializable.setValue(std::make_shared<ls_std::StateConnection>(y));
  58. jsonString = serializable.marshal();
  59. ASSERT_STREQ(R"({"condition":false,"connectionId":"BC","stateId":"C"})", jsonString.toString().c_str());
  60. }
  61. }