diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-04-21 23:48:08 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-04-22 00:04:12 +0300 |
commit | c99419ad2458153e3bf7f6463baf7a93ee6ed57f (patch) | |
tree | 51a6d94212475655f7661ef2e41a4111b847f1d7 /src | |
parent | 155b8814e84a4f5cfa3f91f8dcc096c6f8136dcd (diff) | |
download | manaverse-c99419ad2458153e3bf7f6463baf7a93ee6ed57f.tar.gz manaverse-c99419ad2458153e3bf7f6463baf7a93ee6ed57f.tar.bz2 manaverse-c99419ad2458153e3bf7f6463baf7a93ee6ed57f.tar.xz manaverse-c99419ad2458153e3bf7f6463baf7a93ee6ed57f.zip |
Add tests for some functions in files.
Diffstat (limited to 'src')
-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(); |