XmlParserTestWrapperTest.cpp 1.8 KB

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