FileWriterTest.cpp 1.6 KB

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