SerializableJSONStateConnectionTest.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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-15
  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. }