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