XmlReaderTest.cpp 3.2 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: 2022-05-11
  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::io::XmlReader xmlReader{std::make_shared<ls::std::io::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::io::XmlReader xmlReader{std::make_shared<ls::std::io::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::io::XmlDocument> document = std::make_shared<ls::std::io::XmlDocument>();
  40. ls::std::io::XmlReader xmlReader{document, xmlPath};
  41. ASSERT_TRUE(xmlReader.getDocument() == document);
  42. document = std::make_shared<ls::std::io::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::io::XmlDocument> document = std::make_shared<ls::std::io::XmlDocument>();
  50. ls::std::io::XmlReader xmlReader{document, xmlPath};
  51. EXPECT_THROW({
  52. try
  53. {
  54. xmlReader.setDocument(nullptr);
  55. }
  56. catch (const ls::std::core::IllegalArgumentException &_exception)
  57. {
  58. throw;
  59. }
  60. }, ls::std::core::IllegalArgumentException);
  61. }
  62. TEST_F(XmlReaderTest, setFile)
  63. {
  64. std::string xmlPath = TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
  65. ls::std::io::XmlReader xmlReader{std::make_shared<ls::std::io::XmlDocument>(), xmlPath};
  66. ls::std::io::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::io::XmlReader xmlReader{std::make_shared<ls::std::io::XmlDocument>(), xmlPath};
  74. ls::std::io::File xmlFile{xmlPath};
  75. EXPECT_THROW({
  76. try
  77. {
  78. xmlReader.setFile(ls::std::io::File{""});
  79. }
  80. catch (const ls::std::core::IllegalArgumentException &_exception)
  81. {
  82. throw;
  83. }
  84. }, ls::std::core::IllegalArgumentException);
  85. }
  86. }