XmlReaderTest.cpp 2.8 KB

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