diff options
Diffstat (limited to 'src/fs')
-rw-r--r-- | src/fs/files_unittest.cc | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/fs/files_unittest.cc b/src/fs/files_unittest.cc index bc4c2dbf6..f6d1c91df 100644 --- a/src/fs/files_unittest.cc +++ b/src/fs/files_unittest.cc @@ -27,6 +27,7 @@ #include "fs/virtfs/virtfstools.h" #include "utils/delete2.h" +#include "utils/stringutils.h" #include "resources/resourcemanager/resourcemanager.h" @@ -142,6 +143,67 @@ TEST_CASE("Files saveTextFile") // VirtFs::deinit(); } +TEST_CASE("Files copyFile1") +{ + logger = new Logger(); + VirtFs::mountDirSilent("data", Append_false); + VirtFs::mountDirSilent("../data", Append_false); + + const std::string dir = VirtFs::getPath("test"); + REQUIRE(dir.size() > 0); + SECTION("copy") + { + REQUIRE(Files::copyFile(pathJoin(dir, "test.txt"), + pathJoin(dir, "tempfile.txt")) == 0); + std::string data = VirtFs::loadTextFileString("test/tempfile.txt"); + ::remove((dir + "/tempfile.txt").c_str()); +#ifdef WIN32 + REQUIRE(data == "test line 1\r\ntest line 2"); +#else // WIN32 + + REQUIRE(data == "test line 1\ntest line 2"); +#endif // WIN32 + } + + SECTION("errors") + { + REQUIRE(Files::copyFile(pathJoin(dir, "test_not_exists.txt"), + pathJoin(dir, "tempfile.txt")) == -1); + REQUIRE(Files::copyFile(pathJoin(dir, "test.txt"), + "/nonexist/root/dir123") == -1); + } + + ResourceManager::deleteInstance(); + VirtFs::unmountDirSilent("data"); + VirtFs::unmountDirSilent("../data"); + delete2(logger); +// VirtFs::deinit(); +} + +TEST_CASE("Files loadTextFileLocal") +{ + logger = new Logger(); + VirtFs::mountDirSilent("data", Append_false); + VirtFs::mountDirSilent("../data", Append_false); + + const std::string dir = VirtFs::getPath("test"); + REQUIRE(dir.size() > 0); + Files::saveTextFile(dir, "tempfile.txt", "test line\ntext line2"); + StringVect lines; + REQUIRE(Files::loadTextFileLocal(pathJoin(dir, "tempfile.txt"), + lines)); + ::remove((dir + "/tempfile.txt").c_str()); + REQUIRE(lines.size() == 2); + REQUIRE(lines[0] == "test line"); + REQUIRE(lines[1] == "text line2"); + + ResourceManager::deleteInstance(); + VirtFs::unmountDirSilent("data"); + VirtFs::unmountDirSilent("../data"); + delete2(logger); +// VirtFs::deinit(); +} + TEST_CASE("Files getFilesInDir") { logger = new Logger(); |