SerializableJSONStateConnectionTest.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-14
  6. * Changed: 2020-11-26
  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, getValue)
  40. {
  41. std::shared_ptr<ls_std::StateConnection> x = std::make_shared<ls_std::StateConnection>("AB", "B");
  42. ls_std::SerializableJSONStateConnection serializable {x};
  43. ASSERT_TRUE(serializable.getValue() == x);
  44. }
  45. TEST_F(SerializableJSONStateConnectionTest, setValue)
  46. {
  47. ls_std::StateConnection x {"AB", "B"};
  48. ls_std::SerializableJSONStateConnection serializable {std::make_shared<ls_std::StateConnection>(x)};
  49. ls_std::String jsonString {serializable.marshal()};
  50. ASSERT_STREQ(R"({"condition":false,"connectionId":"AB","stateId":"B"})", jsonString.toString().c_str());
  51. // set value should now reset json
  52. ls_std::StateConnection y {"BC", "C"};
  53. serializable.setValue(std::make_shared<ls_std::StateConnection>(y));
  54. jsonString = serializable.marshal();
  55. ASSERT_STREQ(R"({"condition":false,"connectionId":"BC","stateId":"C"})", jsonString.toString().c_str());
  56. }
  57. }