SerializableJSONStateConnectionTest.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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-14
  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. TEST_F(SerializableJSONStateConnectionTest, marshal)
  22. {
  23. ls_std::StateConnection x {"AB", "B"};
  24. ls_std::SerializableJSONStateConnection serializable {std::make_shared<ls_std::StateConnection>(x)};
  25. ls_std::String jsonString {serializable.marshal()};
  26. ASSERT_STREQ(R"({"condition":false,"connectionId":"AB","stateId":"B"})", jsonString.toString().c_str());
  27. }
  28. TEST_F(SerializableJSONStateConnectionTest, unmarshal)
  29. {
  30. std::shared_ptr<ls_std::StateConnection> x = std::make_shared<ls_std::StateConnection>("AB", "B");
  31. ASSERT_STREQ("AB", x->getConnectionId().c_str());
  32. ASSERT_STREQ("B", x->getStateId().c_str());
  33. ASSERT_FALSE(x->isPassable());
  34. ls_std::SerializableJSONStateConnection serializable {x};
  35. serializable.unmarshal(R"({"condition":true,"connectionId":"BC","stateId":"C"})");
  36. ASSERT_STREQ("BC", x->getConnectionId().c_str());
  37. ASSERT_STREQ("C", x->getStateId().c_str());
  38. ASSERT_TRUE(x->isPassable());
  39. }
  40. }