XmlReaderTest.cpp 3.3 KB

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