XMLReaderMockTest.cpp 1.8 KB

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