diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-03-29 19:26:56 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-03-29 19:26:56 +0300 |
commit | fdd94971fc164397bdf18cf7558b91283afc9769 (patch) | |
tree | a4439d5d527ee68e72e9411f4ecbd014580b2a7f /src/utils/files_unittest.cc | |
parent | f92c6c4807c44426b64747e047a3db9791810875 (diff) | |
download | plus-fdd94971fc164397bdf18cf7558b91283afc9769.tar.gz plus-fdd94971fc164397bdf18cf7558b91283afc9769.tar.bz2 plus-fdd94971fc164397bdf18cf7558b91283afc9769.tar.xz plus-fdd94971fc164397bdf18cf7558b91283afc9769.zip |
Add more tests for files utils.
Diffstat (limited to 'src/utils/files_unittest.cc')
-rw-r--r-- | src/utils/files_unittest.cc | 88 |
1 files changed, 87 insertions, 1 deletions
diff --git a/src/utils/files_unittest.cc b/src/utils/files_unittest.cc index 79de6259d..c876e2b72 100644 --- a/src/utils/files_unittest.cc +++ b/src/utils/files_unittest.cc @@ -29,7 +29,7 @@ #include "debug.h" -TEST_CASE("Files renameFile", "files") +TEST_CASE("Files renameFile") { PHYSFS_init("manaplus"); dirSeparator = "/"; @@ -64,3 +64,89 @@ TEST_CASE("Files renameFile", "files") delete [] buf; delete [] buf2; } + +TEST_CASE("Files existsLocal") +{ + PHYSFS_init("manaplus"); + dirSeparator = "/"; + logger = new Logger(); + ResourceManager::init(); + resourceManager->addToSearchPath("data", Append_false); + resourceManager->addToSearchPath("../data", Append_false); + REQUIRE(Files::existsLocal(Files::getPath("help/about.txt")) == true); + REQUIRE_FALSE(Files::existsLocal(Files::getPath("help/about1.txt"))); + REQUIRE_FALSE(Files::existsLocal(Files::getPath("help1/about.txt"))); +} + +TEST_CASE("Files loadTextFileString") +{ + PHYSFS_init("manaplus"); + dirSeparator = "/"; + logger = new Logger(); + ResourceManager::init(); + resourceManager->addToSearchPath("data", Append_false); + resourceManager->addToSearchPath("../data", Append_false); + REQUIRE(Files::loadTextFileString("test/simplefile.txt") == + "this is test \nfile."); +} + +TEST_CASE("Files loadTextFile") +{ + PHYSFS_init("manaplus"); + dirSeparator = "/"; + logger = new Logger(); + ResourceManager::init(); + resourceManager->addToSearchPath("data", Append_false); + resourceManager->addToSearchPath("../data", Append_false); + + StringVect lines; + Files::loadTextFile("test/simplefile.txt", lines); + REQUIRE(lines.size() == 2); + REQUIRE(lines[0] == "this is test "); + REQUIRE(lines[1] == "file."); +} + +TEST_CASE("Files saveTextFile") +{ + PHYSFS_init("manaplus"); + dirSeparator = "/"; + logger = new Logger(); + ResourceManager::init(); + resourceManager->addToSearchPath("data", Append_false); + resourceManager->addToSearchPath("../data", Append_false); + + const std::string dir = Files::getPath("test"); + REQUIRE(dir.size() > 0); + Files::saveTextFile(dir, "tempfile.txt", "test line\ntext line2"); + std::string data = Files::loadTextFileString("test/tempfile.txt"); + ::remove((dir + "/tempfile.txt").c_str()); + REQUIRE(data == "test line\ntext line2\n"); +} + +TEST_CASE("Files getFilesInDir") +{ + PHYSFS_init("manaplus"); + dirSeparator = "/"; + logger = new Logger(); + ResourceManager::init(); + resourceManager->addToSearchPath("data", Append_false); + resourceManager->addToSearchPath("../data", Append_false); + + StringVect list; + Files::getFilesInDir("test", + list, + ".gpl"); + REQUIRE(list.size() == 1); + REQUIRE(list[0] == "test/palette.gpl"); + + list.clear(); + Files::getFilesInDir("perserver/default", + list, + ".xml"); + REQUIRE(list.size() == 5); + REQUIRE(list[0] == "perserver/default/charcreation.xml"); + REQUIRE(list[1] == "perserver/default/deadmessages.xml"); + REQUIRE(list[2] == "perserver/default/defaultcommands.xml"); + REQUIRE(list[3] == "perserver/default/features.xml"); + REQUIRE(list[4] == "perserver/default/weapons.xml"); +} |