SerializableXMLStateConnectionTest.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-20
  6. * Changed: 2020-09-20
  7. *
  8. * *//*
  9. #include <gtest/gtest.h>
  10. #include "../../../../../source/serialization/xml/logic/SerializableXMLStateConnection.hpp"
  11. #include "../../../../../source/boxing/String.hpp"
  12. namespace {
  13. class SerializableXMLStateConnectionTest : public ::testing::Test {
  14. protected:
  15. SerializableXMLStateConnectionTest() = default;
  16. ~SerializableXMLStateConnectionTest() override = default;
  17. void SetUp() override {}
  18. void TearDown() override {}
  19. };
  20. TEST_F(SerializableXMLStateConnectionTest, marshal)
  21. {
  22. ls_std::SerializableXMLStateConnection serializable {std::make_shared<ls_std::StateConnection>("AB", "B")};
  23. ls_std::String data {serializable.marshal()};
  24. ASSERT_TRUE(!data.toString().empty());
  25. ls_std::String expected {R"(<connection connectionId="AB" id="B" condition="false"/>)"};
  26. ASSERT_TRUE(data.contains(expected));
  27. }
  28. TEST_F(SerializableXMLStateConnectionTest, unmarshal)
  29. {
  30. ls_std::SerializableXMLStateConnection serializable {std::make_shared<ls_std::StateConnection>("AB", "B")};
  31. std::string xmlString = R"(<connection connectionId="DE" id="E" condition="true"></connection>)";
  32. serializable.unmarshal(xmlString);
  33. ASSERT_STREQ("DE", serializable.getValue()->getConnectionId().c_str());
  34. ASSERT_STREQ("E", serializable.getValue()->getStateId().c_str());
  35. ASSERT_TRUE(serializable.getValue()->isPassable());
  36. }
  37. // additional functionality
  38. TEST_F(SerializableXMLStateConnectionTest, getValue)
  39. {
  40. std::shared_ptr<ls_std::StateConnection> x = std::make_shared<ls_std::StateConnection>("AB", "B");
  41. ls_std::SerializableXMLStateConnection serializable {x};
  42. ASSERT_STREQ("AB", serializable.getValue()->getConnectionId().c_str());
  43. ASSERT_STREQ("B", serializable.getValue()->getStateId().c_str());
  44. ASSERT_FALSE(serializable.getValue()->isPassable());
  45. }
  46. TEST_F(SerializableXMLStateConnectionTest, setValue)
  47. {
  48. ls_std::SerializableXMLStateConnection serializable {std::make_shared<ls_std::StateConnection>("AB", "B")};
  49. ASSERT_STREQ("AB", serializable.getValue()->getConnectionId().c_str());
  50. ASSERT_STREQ("B", serializable.getValue()->getStateId().c_str());
  51. ASSERT_FALSE(serializable.getValue()->isPassable());
  52. serializable.setValue(std::make_shared<ls_std::StateConnection>("BC", "C"));
  53. ASSERT_STREQ("BC", serializable.getValue()->getConnectionId().c_str());
  54. ASSERT_STREQ("C", serializable.getValue()->getStateId().c_str());
  55. ASSERT_FALSE(serializable.getValue()->isPassable());
  56. }
  57. }
  58. */