FileWriterTest.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-17
  6. * Changed: 2021-04-23
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls_std/ls_std.hpp>
  11. #include <TestHelper.hpp>
  12. namespace
  13. {
  14. class FileWriterTest : public ::testing::Test
  15. {
  16. protected:
  17. FileWriterTest() = default;
  18. ~FileWriterTest() override = default;
  19. void SetUp() override
  20. {}
  21. void TearDown() override
  22. {}
  23. };
  24. TEST_F(FileWriterTest, reset)
  25. {
  26. std::string path = TestHelper::getResourcesFolderLocation() + "tmp_file_writer_test.txt";
  27. ls_std::File file{path};
  28. file.createNewFile();
  29. ls_std::FileWriter writer{file};
  30. ASSERT_TRUE(writer.write("Testing something!\n"));
  31. // reset
  32. path = TestHelper::getResourcesFolderLocation() + "tmp_file_writer_test2.txt";
  33. ls_std::File anotherFile{path};
  34. anotherFile.createNewFile();
  35. writer.reset(anotherFile);
  36. ASSERT_TRUE(writer.write("Testing something else!\n"));
  37. // remove
  38. file.remove();
  39. ASSERT_FALSE(file.exists());
  40. anotherFile.remove();
  41. ASSERT_FALSE(anotherFile.exists());
  42. }
  43. TEST_F(FileWriterTest, write)
  44. {
  45. std::string path = TestHelper::getResourcesFolderLocation() + "tmp_file_writer_test.txt";
  46. ls_std::File file{path};
  47. ASSERT_FALSE(file.exists());
  48. file.createNewFile();
  49. ASSERT_TRUE(file.exists());
  50. ls_std::FileWriter writer{file};
  51. ASSERT_TRUE(writer.write("Testing something!\n"));
  52. file.remove();
  53. ASSERT_FALSE(file.exists());
  54. }
  55. }