XmlReaderTest.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-10-10
  6. * Changed: 2022-11-09
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls_std/ls_std_core.hpp>
  11. #include <ls_std/ls_std_io.hpp>
  12. #include "TestHelper.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. try
  58. {
  59. xmlReader.setDocument(nullptr);
  60. }
  61. catch (const IllegalArgumentException &_exception)
  62. {
  63. throw;
  64. }
  65. }, IllegalArgumentException);
  66. }
  67. TEST_F(XmlReaderTest, setFile)
  68. {
  69. string xmlPath = TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
  70. XmlReader xmlReader{make_shared<XmlDocument>(), xmlPath};
  71. File xmlFile{xmlPath};
  72. xmlReader.setFile(xmlFile);
  73. ASSERT_TRUE(true);
  74. }
  75. TEST_F(XmlReaderTest, setFile_does_not_exist)
  76. {
  77. string xmlPath = TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
  78. XmlReader xmlReader{make_shared<XmlDocument>(), xmlPath};
  79. File xmlFile{xmlPath};
  80. EXPECT_THROW({
  81. try
  82. {
  83. xmlReader.setFile(File{""});
  84. }
  85. catch (const IllegalArgumentException &_exception)
  86. {
  87. throw;
  88. }
  89. }, IllegalArgumentException);
  90. }
  91. }