XmlReaderTest.cpp 3.0 KB

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