FileReaderTest.cpp 1.8 KB

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