XmlParserTestWrapperTest.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-10-18
  6. * Changed: 2023-03-25
  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. public:
  21. XmlParserTestWrapperTest() = default;
  22. ~XmlParserTestWrapperTest() override = default;
  23. };
  24. TEST_F(XmlParserTestWrapperTest, readAttribute)
  25. {
  26. pair<string, string> attribute = XmlParserTestWrapper::readAttribute(R"(name="tim")");
  27. ASSERT_TRUE(attribute.first == "name");
  28. ASSERT_TRUE(attribute.second == "tim");
  29. attribute = XmlParserTestWrapper::readAttribute(R"(id="dialog_001")");
  30. ASSERT_TRUE(attribute.first == "id");
  31. ASSERT_TRUE(attribute.second == "dialog_001");
  32. }
  33. TEST_F(XmlParserTestWrapperTest, readAttributes)
  34. {
  35. // first case
  36. string tag = R"(<?xml version="1.0" encoding="UTF-8" ?>)";
  37. list<pair<string, string>> attributes = XmlParserTestWrapper::readAttributes(tag);
  38. ASSERT_EQ(2, attributes.size());
  39. auto iterator = next(attributes.begin(), 0);
  40. ASSERT_TRUE(iterator->first == "version");
  41. ASSERT_TRUE(iterator->second == "1.0");
  42. iterator = next(attributes.begin(), 1);
  43. ASSERT_TRUE(iterator->first == "encoding");
  44. ASSERT_TRUE(iterator->second == "UTF-8");
  45. // second case
  46. tag = R"(<stateMachine name="test_machine">)";
  47. attributes = XmlParserTestWrapper::readAttributes(tag);
  48. ASSERT_EQ(1, attributes.size());
  49. iterator = next(attributes.begin(), 0);
  50. ASSERT_TRUE(iterator->first == "name");
  51. ASSERT_TRUE(iterator->second == "test_machine");
  52. }
  53. }