FileWriterTest.cpp 1.6 KB

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