XmlReaderTest.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-10-10
  6. * Changed: 2021-09-17
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls_std/ls_std.hpp>
  11. #include <TestHelper.hpp>
  12. namespace
  13. {
  14. class XmlReaderTest : public ::testing::Test
  15. {
  16. protected:
  17. XmlReaderTest() = default;
  18. ~XmlReaderTest() override = default;
  19. void SetUp() override
  20. {}
  21. void TearDown() override
  22. {}
  23. };
  24. TEST_F(XmlReaderTest, read)
  25. {
  26. std::string xmlPath = TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
  27. ls_std::XmlReader xmlReader{std::make_shared<ls_std::XmlDocument>(), xmlPath};
  28. ASSERT_TRUE(!xmlReader.read().empty());
  29. }
  30. TEST_F(XmlReaderTest, getDocument)
  31. {
  32. std::string xmlPath = TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
  33. ls_std::XmlReader xmlReader{std::make_shared<ls_std::XmlDocument>(), xmlPath};
  34. ASSERT_TRUE(xmlReader.getDocument() != nullptr);
  35. }
  36. TEST_F(XmlReaderTest, setDocument)
  37. {
  38. std::string xmlPath = TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
  39. std::shared_ptr<ls_std::XmlDocument> document = std::make_shared<ls_std::XmlDocument>();
  40. ls_std::XmlReader xmlReader{document, xmlPath};
  41. ASSERT_TRUE(xmlReader.getDocument() == document);
  42. document = std::make_shared<ls_std::XmlDocument>();
  43. xmlReader.setDocument(document);
  44. ASSERT_TRUE(xmlReader.getDocument() == document);
  45. }
  46. TEST_F(XmlReaderTest, setDocument_no_reference)
  47. {
  48. std::string xmlPath = TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
  49. std::shared_ptr<ls_std::XmlDocument> document = std::make_shared<ls_std::XmlDocument>();
  50. ls_std::XmlReader xmlReader{document, xmlPath};
  51. EXPECT_THROW({
  52. try
  53. {
  54. xmlReader.setDocument(nullptr);
  55. }
  56. catch (const ls_std::IllegalArgumentException &_exception)
  57. {
  58. throw;
  59. }
  60. }, ls_std::IllegalArgumentException);
  61. }
  62. TEST_F(XmlReaderTest, setFile)
  63. {
  64. std::string xmlPath = TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
  65. ls_std::XmlReader xmlReader{std::make_shared<ls_std::XmlDocument>(), xmlPath};
  66. ls_std::File xmlFile{xmlPath};
  67. xmlReader.setFile(xmlFile);
  68. ASSERT_TRUE(true);
  69. }
  70. TEST_F(XmlReaderTest, setFile_does_not_exist)
  71. {
  72. std::string xmlPath = TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
  73. ls_std::XmlReader xmlReader{std::make_shared<ls_std::XmlDocument>(), xmlPath};
  74. ls_std::File xmlFile{xmlPath};
  75. EXPECT_THROW({
  76. try
  77. {
  78. xmlReader.setFile(ls_std::File{""});
  79. }
  80. catch (const ls_std::IllegalArgumentException &_exception)
  81. {
  82. throw;
  83. }
  84. }, ls_std::IllegalArgumentException);
  85. }
  86. }