XmlParserTestWrapperTest.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-10-18
  6. * Changed: 2023-02-23
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls-std-io-test.hpp>
  11. using std::list;
  12. using std::pair;
  13. using std::string;
  14. using test::io::XmlParserTestWrapper;
  15. using testing::Test;
  16. namespace
  17. {
  18. class XmlParserTestWrapperTest : public Test
  19. {
  20. protected:
  21. XmlParserTestWrapperTest() = default;
  22. ~XmlParserTestWrapperTest() override = default;
  23. void SetUp() override
  24. {}
  25. void TearDown() override
  26. {}
  27. };
  28. TEST_F(XmlParserTestWrapperTest, readAttribute)
  29. {
  30. pair<string, string> attribute = XmlParserTestWrapper::readAttribute(R"(name="tim")");
  31. ASSERT_TRUE(attribute.first == "name");
  32. ASSERT_TRUE(attribute.second == "tim");
  33. attribute = XmlParserTestWrapper::readAttribute(R"(id="dialog_001")");
  34. ASSERT_TRUE(attribute.first == "id");
  35. ASSERT_TRUE(attribute.second == "dialog_001");
  36. }
  37. TEST_F(XmlParserTestWrapperTest, readAttributes)
  38. {
  39. // first case
  40. string tag = R"(<?xml version="1.0" encoding="UTF-8" ?>)";
  41. list<pair<string, string>> attributes = XmlParserTestWrapper::readAttributes(tag);
  42. ASSERT_EQ(2, attributes.size());
  43. auto iterator = next(attributes.begin(), 0);
  44. ASSERT_TRUE(iterator->first == "version");
  45. ASSERT_TRUE(iterator->second == "1.0");
  46. iterator = next(attributes.begin(), 1);
  47. ASSERT_TRUE(iterator->first == "encoding");
  48. ASSERT_TRUE(iterator->second == "UTF-8");
  49. // second case
  50. tag = R"(<stateMachine name="test_machine">)";
  51. attributes = XmlParserTestWrapper::readAttributes(tag);
  52. ASSERT_EQ(1, attributes.size());
  53. iterator = next(attributes.begin(), 0);
  54. ASSERT_TRUE(iterator->first == "name");
  55. ASSERT_TRUE(iterator->second == "test_machine");
  56. }
  57. }