FileReaderTest.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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-19
  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* data = reader.read();
  28. std::string content {data, (size_t) file.getSize()};
  29. ASSERT_TRUE(content == expectedUnix || content == expectedWindows);
  30. }
  31. TEST_F(FileReaderTest, reset)
  32. {
  33. ls_std::File file {TestHelper::getResourcesFolderLocation() + "simple.txt"};
  34. ls_std::FileReader reader {file};
  35. std::string expectedUnix = "Hello!" + ls_std::NewLine::getUnixNewLine();
  36. std::string expectedWindows = "Hello!" + ls_std::NewLine::getWindowsNewLine();
  37. ls_std::byte* data = reader.read();
  38. std::string content {data, (size_t) file.getSize()};
  39. ASSERT_TRUE(content == expectedUnix || content == expectedWindows);
  40. ls_std::File anotherFile {TestHelper::getResourcesFolderLocation() + "list_test/bla.txt"};
  41. reader.reset(anotherFile);
  42. expectedUnix = "nothing to say!" + ls_std::NewLine::getUnixNewLine();
  43. expectedWindows = "nothing to say!" + ls_std::NewLine::getWindowsNewLine();
  44. data = reader.read();
  45. content = {data, (size_t) anotherFile.getSize()};
  46. ASSERT_TRUE(content == expectedUnix || content == expectedWindows);
  47. }
  48. }