SerializableJSONStateConnectionTest.cpp 2.2 KB

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