XmlReaderTest.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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-22
  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. using namespace ::testing;
  18. namespace
  19. {
  20. class XmlReaderTest : public Test
  21. {
  22. protected:
  23. XmlReaderTest() = default;
  24. ~XmlReaderTest() override = default;
  25. void SetUp() override
  26. {}
  27. void TearDown() override
  28. {}
  29. };
  30. TEST_F(XmlReaderTest, read)
  31. {
  32. string xmlPath = TestHelper::getResourcesFolderLocation() + "state-machine-test.xml";
  33. XmlReader xmlReader{make_shared<XmlDocument>(), xmlPath};
  34. ASSERT_TRUE(!xmlReader.read().empty());
  35. }
  36. TEST_F(XmlReaderTest, getDocument)
  37. {
  38. string xmlPath = TestHelper::getResourcesFolderLocation() + "state-machine-test.xml";
  39. XmlReader xmlReader{make_shared<XmlDocument>(), xmlPath};
  40. ASSERT_TRUE(xmlReader.getDocument() != nullptr);
  41. }
  42. TEST_F(XmlReaderTest, setDocument)
  43. {
  44. string xmlPath = TestHelper::getResourcesFolderLocation() + "state-machine-test.xml";
  45. shared_ptr<XmlDocument> document = make_shared<XmlDocument>();
  46. XmlReader xmlReader{document, xmlPath};
  47. ASSERT_TRUE(xmlReader.getDocument() == document);
  48. document = make_shared<XmlDocument>();
  49. xmlReader.setDocument(document);
  50. ASSERT_TRUE(xmlReader.getDocument() == document);
  51. }
  52. TEST_F(XmlReaderTest, setDocument_no_reference)
  53. {
  54. string xmlPath = TestHelper::getResourcesFolderLocation() + "state-machine-test.xml";
  55. shared_ptr<XmlDocument> document = make_shared<XmlDocument>();
  56. XmlReader xmlReader{document, xmlPath};
  57. EXPECT_THROW(
  58. {
  59. try
  60. {
  61. xmlReader.setDocument(nullptr);
  62. }
  63. catch (const IllegalArgumentException &_exception)
  64. {
  65. throw;
  66. }
  67. },
  68. IllegalArgumentException);
  69. }
  70. TEST_F(XmlReaderTest, setFile)
  71. {
  72. string xmlPath = TestHelper::getResourcesFolderLocation() + "state-machine-test.xml";
  73. XmlReader xmlReader{make_shared<XmlDocument>(), xmlPath};
  74. File xmlFile{xmlPath};
  75. xmlReader.setFile(xmlFile);
  76. ASSERT_TRUE(true);
  77. }
  78. TEST_F(XmlReaderTest, setFile_does_not_exist)
  79. {
  80. string xmlPath = TestHelper::getResourcesFolderLocation() + "state-machine-test.xml";
  81. XmlReader xmlReader{make_shared<XmlDocument>(), xmlPath};
  82. File xmlFile{xmlPath};
  83. EXPECT_THROW(
  84. {
  85. try
  86. {
  87. xmlReader.setFile(File{""});
  88. }
  89. catch (const IllegalArgumentException &_exception)
  90. {
  91. throw;
  92. }
  93. },
  94. IllegalArgumentException);
  95. }
  96. }