|
@@ -0,0 +1,87 @@
|
|
|
+/*
|
|
|
+ * Author: Patrick-Christopher Mattulat
|
|
|
+ * Company: Lynar Studios
|
|
|
+ * E-Mail: webmaster@lynarstudios.com
|
|
|
+ * Created: 2020-08-19
|
|
|
+ * Changed: 2020-08-19
|
|
|
+ *
|
|
|
+ * */
|
|
|
+
|
|
|
+#include <gtest/gtest.h>
|
|
|
+#include "../../TestHelper.hpp"
|
|
|
+#include "../../../source/io/StorableFile.hpp"
|
|
|
+#include "../../../source/io/NewLine.hpp"
|
|
|
+
|
|
|
+namespace {
|
|
|
+ class StorableFileTest : public ::testing::Test {
|
|
|
+ protected:
|
|
|
+
|
|
|
+ StorableFileTest() = default;
|
|
|
+ ~StorableFileTest() override = default;
|
|
|
+
|
|
|
+ std::string fileLocation = TestHelper::getResourcesFolderLocation() + "simple.txt";
|
|
|
+
|
|
|
+ void SetUp() override {}
|
|
|
+ void TearDown() override {}
|
|
|
+ };
|
|
|
+
|
|
|
+ TEST_F(StorableFileTest, getContent)
|
|
|
+ {
|
|
|
+ ls_std::StorableFile storableFile {this->fileLocation};
|
|
|
+ ASSERT_TRUE(storableFile.getContent().empty());
|
|
|
+ }
|
|
|
+
|
|
|
+ TEST_F(StorableFileTest, load)
|
|
|
+ {
|
|
|
+ ls_std::StorableFile storableFile {this->fileLocation};
|
|
|
+ storableFile.load();
|
|
|
+ std::string expected = "Hello!" + ls_std::NewLine::get();
|
|
|
+
|
|
|
+ ASSERT_STREQ(expected.c_str(), storableFile.getContent().c_str());
|
|
|
+ }
|
|
|
+
|
|
|
+ TEST_F(StorableFileTest, reset)
|
|
|
+ {
|
|
|
+ ls_std::StorableFile storableFile {this->fileLocation};
|
|
|
+ storableFile.load();
|
|
|
+ std::string expected = "Hello!" + ls_std::NewLine::get();
|
|
|
+
|
|
|
+ ASSERT_STREQ(expected.c_str(), storableFile.getContent().c_str());
|
|
|
+
|
|
|
+ // reset
|
|
|
+
|
|
|
+ std::string anotherFileLocation = TestHelper::getResourcesFolderLocation() + "list_test/bla.txt";
|
|
|
+ storableFile.reset(anotherFileLocation);
|
|
|
+ storableFile.load();
|
|
|
+ expected = "nothing to say!" + ls_std::NewLine::get();
|
|
|
+
|
|
|
+ ASSERT_STREQ(expected.c_str(), storableFile.getContent().c_str());
|
|
|
+ }
|
|
|
+
|
|
|
+ TEST_F(StorableFileTest, save)
|
|
|
+ {
|
|
|
+ std::string path = TestHelper::getResourcesFolderLocation() + "tmp_storable_file.txt";
|
|
|
+ ls_std::File file {path};
|
|
|
+ file.createNewFile();
|
|
|
+
|
|
|
+ ls_std::StorableFile storableFile {path};
|
|
|
+ std::string text = "Testing save method!" + ls_std::NewLine::get();
|
|
|
+
|
|
|
+ ASSERT_TRUE(storableFile.getContent().empty());
|
|
|
+ storableFile.setContent(text);
|
|
|
+ ASSERT_STREQ(text.c_str(), storableFile.getContent().c_str());
|
|
|
+ storableFile.save();
|
|
|
+ storableFile.load();
|
|
|
+ ASSERT_STREQ(text.c_str(), storableFile.getContent().c_str());
|
|
|
+
|
|
|
+ file.remove();
|
|
|
+ }
|
|
|
+
|
|
|
+ TEST_F(StorableFileTest, setContent)
|
|
|
+ {
|
|
|
+ ls_std::StorableFile storableFile {this->fileLocation};
|
|
|
+ storableFile.setContent("Testing!");
|
|
|
+
|
|
|
+ ASSERT_STREQ("Testing!", storableFile.getContent().c_str());
|
|
|
+ }
|
|
|
+}
|