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 | |
parent | f92c6c4807c44426b64747e047a3db9791810875 (diff) | |
download | manaplus-fdd94971fc164397bdf18cf7558b91283afc9769.tar.gz manaplus-fdd94971fc164397bdf18cf7558b91283afc9769.tar.bz2 manaplus-fdd94971fc164397bdf18cf7558b91283afc9769.tar.xz manaplus-fdd94971fc164397bdf18cf7558b91283afc9769.zip |
Add more tests for files utils.
-rw-r--r-- | data/test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | data/test/Makefile.am | 3 | ||||
-rw-r--r-- | data/test/simplefile.txt | 2 | ||||
-rw-r--r-- | src/utils/files_unittest.cc | 88 |
4 files changed, 92 insertions, 2 deletions
diff --git a/data/test/CMakeLists.txt b/data/test/CMakeLists.txt index 83bbb8d5d..3336dcf8d 100644 --- a/data/test/CMakeLists.txt +++ b/data/test/CMakeLists.txt @@ -1,5 +1,6 @@ SET(FILES palette.gpl + simplefile.txt ) INSTALL(FILES ${FILES} DESTINATION ${DATA_DIR}/test) diff --git a/data/test/Makefile.am b/data/test/Makefile.am index 904b30852..81e19612b 100644 --- a/data/test/Makefile.am +++ b/data/test/Makefile.am @@ -1,7 +1,8 @@ testdir = $(pkgdatadir)/data/test test_DATA = \ - palette.gpl + palette.gpl \ + simplefile.txt EXTRA_DIST = \ $(test_DATA) \ diff --git a/data/test/simplefile.txt b/data/test/simplefile.txt new file mode 100644 index 000000000..5ba62e4c1 --- /dev/null +++ b/data/test/simplefile.txt @@ -0,0 +1,2 @@ +this is test +file.
\ No newline at end of file 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"); +} |