SectionPairFileReaderIT.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-21
  6. * Changed: 2023-02-21
  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. #include <string>
  14. using namespace ls::std::core;
  15. using namespace ls::std::io;
  16. using namespace ::std;
  17. using namespace ls::std::test;
  18. namespace
  19. {
  20. class SectionPairFileReaderIT : public ::testing::Test
  21. {
  22. protected:
  23. SectionPairFileReaderIT() = default;
  24. ~SectionPairFileReaderIT() override = default;
  25. void SetUp() override
  26. {}
  27. void TearDown() override
  28. {}
  29. static string getSectionPairFileLocation()
  30. {
  31. return TestHelper::getResourcesFolderLocation() + "server-settings-unix.txt";
  32. }
  33. };
  34. TEST_F(SectionPairFileReaderIT, constructor_file_does_not_exist)
  35. {
  36. EXPECT_THROW(
  37. {
  38. try
  39. {
  40. SectionPairFileReader reader{SectionPairFileReaderParameter{}};
  41. }
  42. catch (const FileNotFoundException &_exception)
  43. {
  44. throw;
  45. }
  46. },
  47. FileNotFoundException);
  48. }
  49. TEST_F(SectionPairFileReaderIT, getClassName)
  50. {
  51. SectionPairFileReaderParameter parameter{};
  52. parameter.setFilePath(SectionPairFileReaderIT::getSectionPairFileLocation());
  53. ASSERT_STREQ("SectionPairFileReader", SectionPairFileReader{parameter}.getClassName().c_str());
  54. }
  55. TEST_F(SectionPairFileReaderIT, getDocument)
  56. {
  57. SectionPairFileReaderParameter parameter{};
  58. parameter.setFilePath(SectionPairFileReaderIT::getSectionPairFileLocation());
  59. SectionPairFileReader reader{parameter};
  60. ASSERT_FALSE(reader.getDocument() == nullptr);
  61. }
  62. TEST_F(SectionPairFileReaderIT, read)
  63. {
  64. SectionPairFileReaderParameter parameter{};
  65. shared_ptr<SectionPairDocument> document = make_shared<SectionPairDocument>();
  66. document->reserveNewLine(NewLine::getUnixNewLine());
  67. parameter.setDocument(document);
  68. parameter.setFilePath(SectionPairFileReaderIT::getSectionPairFileLocation());
  69. SectionPairFileReader reader{parameter};
  70. reader.read();
  71. ASSERT_TRUE(!reader.getDocument()->getSectionList().empty());
  72. ASSERT_STREQ("general", reader.getDocument()->get(0)->getSectionId().c_str());
  73. ASSERT_EQ(2, reader.getDocument()->get(0)->getRowAmount());
  74. }
  75. }