SerializableJSONStateConnectionTest.cpp 2.3 KB

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