FileReaderTest.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-18
  6. * Changed: 2021-04-23
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <TestHelper.hpp>
  11. #include <ls_std/ls_std.hpp>
  12. namespace
  13. {
  14. class FileReaderTest : public ::testing::Test
  15. {
  16. protected:
  17. FileReaderTest() = default;
  18. ~FileReaderTest() override = default;
  19. void SetUp() override
  20. {}
  21. void TearDown() override
  22. {}
  23. };
  24. TEST_F(FileReaderTest, read)
  25. {
  26. ls_std::File file{TestHelper::getResourcesFolderLocation() + "simple.txt"};
  27. ls_std::FileReader reader{file};
  28. std::string expectedUnix = "Hello!" + ls_std::NewLine::getUnixNewLine();
  29. std::string expectedWindows = "Hello!" + ls_std::NewLine::getWindowsNewLine();
  30. ls_std::byte_field content = reader.read();
  31. ASSERT_TRUE(content == expectedUnix || content == expectedWindows);
  32. }
  33. TEST_F(FileReaderTest, reset)
  34. {
  35. ls_std::File file{TestHelper::getResourcesFolderLocation() + "simple.txt"};
  36. ls_std::FileReader reader{file};
  37. std::string expectedUnix = "Hello!" + ls_std::NewLine::getUnixNewLine();
  38. std::string expectedWindows = "Hello!" + ls_std::NewLine::getWindowsNewLine();
  39. ls_std::byte_field content = reader.read();
  40. ASSERT_TRUE(content == expectedUnix || content == expectedWindows);
  41. ls_std::File anotherFile{TestHelper::getResourcesFolderLocation() + "list_test/bla.txt"};
  42. reader.reset(anotherFile);
  43. expectedUnix = "nothing to say!" + ls_std::NewLine::getUnixNewLine();
  44. expectedWindows = "nothing to say!" + ls_std::NewLine::getWindowsNewLine();
  45. content = reader.read();
  46. ASSERT_TRUE(content == expectedUnix || content == expectedWindows);
  47. }
  48. }