FileReaderTest.cpp 1.7 KB

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