XmlParserTestWrapperTest.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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-05
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls-std-io-test.hpp>
  11. using namespace test::io;
  12. using namespace ::std;
  13. namespace
  14. {
  15. class XmlParserTestWrapperTest : public ::testing::Test
  16. {
  17. protected:
  18. XmlParserTestWrapperTest() = default;
  19. ~XmlParserTestWrapperTest() override = default;
  20. void SetUp() override
  21. {}
  22. void TearDown() override
  23. {}
  24. };
  25. TEST_F(XmlParserTestWrapperTest, readAttribute)
  26. {
  27. pair<string, string> attribute = XmlParserTestWrapper::readAttribute(R"(name="tim")");
  28. ASSERT_TRUE(attribute.first == "name");
  29. ASSERT_TRUE(attribute.second == "tim");
  30. attribute = XmlParserTestWrapper::readAttribute(R"(id="dialog_001")");
  31. ASSERT_TRUE(attribute.first == "id");
  32. ASSERT_TRUE(attribute.second == "dialog_001");
  33. }
  34. TEST_F(XmlParserTestWrapperTest, readAttributes)
  35. {
  36. // first case
  37. string tag = R"(<?xml version="1.0" encoding="UTF-8" ?>)";
  38. list<pair<string, string>> attributes = XmlParserTestWrapper::readAttributes(tag);
  39. ASSERT_EQ(2, attributes.size());
  40. auto iterator = next(attributes.begin(), 0);
  41. ASSERT_TRUE(iterator->first == "version");
  42. ASSERT_TRUE(iterator->second == "1.0");
  43. iterator = next(attributes.begin(), 1);
  44. ASSERT_TRUE(iterator->first == "encoding");
  45. ASSERT_TRUE(iterator->second == "UTF-8");
  46. // second case
  47. tag = R"(<stateMachine name="test_machine">)";
  48. attributes = XmlParserTestWrapper::readAttributes(tag);
  49. ASSERT_EQ(1, attributes.size());
  50. iterator = next(attributes.begin(), 0);
  51. ASSERT_TRUE(iterator->first == "name");
  52. ASSERT_TRUE(iterator->second == "test_machine");
  53. }
  54. }