summaryrefslogtreecommitdiff
path: root/src/fs/virtfs/virtfs1_unittest.cc
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-04-24 19:27:07 +0300
committerAndrei Karas <akaras@inbox.ru>2017-04-24 19:27:07 +0300
commit6f58d1ee37041da28562d09757a9f653109f5677 (patch)
tree494b990338727f2adfdc7d7c6e46558be696aa29 /src/fs/virtfs/virtfs1_unittest.cc
parentd1b635ebf238fac5911fde8982d067ee4ffffe3a (diff)
downloadplus-6f58d1ee37041da28562d09757a9f653109f5677.tar.gz
plus-6f58d1ee37041da28562d09757a9f653109f5677.tar.bz2
plus-6f58d1ee37041da28562d09757a9f653109f5677.tar.xz
plus-6f58d1ee37041da28562d09757a9f653109f5677.zip
Improve VirtFs::getFilesWithDir.
Diffstat (limited to 'src/fs/virtfs/virtfs1_unittest.cc')
-rw-r--r--src/fs/virtfs/virtfs1_unittest.cc96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/fs/virtfs/virtfs1_unittest.cc b/src/fs/virtfs/virtfs1_unittest.cc
index 23255e0c5..b6a928bb6 100644
--- a/src/fs/virtfs/virtfs1_unittest.cc
+++ b/src/fs/virtfs/virtfs1_unittest.cc
@@ -30,6 +30,7 @@
#include "utils/checkutils.h"
#include "utils/delete2.h"
+#include "utils/stringutils.h"
#include <SDL_rwops.h>
@@ -695,6 +696,19 @@ static bool inList(StringVect list,
return false;
}
+static bool inList(StringVect list,
+ const std::string &dir,
+ const std::string &name)
+{
+ const std::string path = pathJoin(dir, name);
+ FOR_EACH (StringVectCIter, it, list)
+ {
+ if (*it == path)
+ return true;
+ }
+ return false;
+}
+
TEST_CASE("VirtFs1 enumerateFiles1")
{
VirtFs::init(".");
@@ -2020,3 +2034,85 @@ TEST_CASE("VirtFs1 getDirs2")
VirtFs::deinit();
delete2(logger);
}
+
+TEST_CASE("VirtFs1 getFilesWithDir1")
+{
+ VirtFs::init(".");
+ logger = new Logger();
+ std::string name("data/test/test.zip");
+ std::string prefix;
+ if (Files::existsLocal(name) == false)
+ prefix = "../" + prefix;
+
+ VirtFs::mountZip(prefix + "data/test/test2.zip",
+ Append_false);
+
+ StringVect list;
+ VirtFs::getFilesWithDir("dir", list);
+ REQUIRE(list.size() == 2);
+ REQUIRE(inList(list, "dir", "dye.png"));
+ REQUIRE(inList(list, "dir", "hide.png"));
+ list.clear();
+
+ VirtFs::getFilesWithDir("dir2", list);
+ REQUIRE(list.size() == 4);
+ REQUIRE(inList(list, "dir2", "hide.png"));
+ REQUIRE(inList(list, "dir2", "paths.xml"));
+ REQUIRE(inList(list, "dir2", "test.txt"));
+ REQUIRE(inList(list, "dir2", "units.xml"));
+ list.clear();
+
+ VirtFs::getFilesWithDir("/", list);
+ REQUIRE(list.size() > 2);
+ REQUIRE(inList(list, "/", "test.txt"));
+ REQUIRE(inList(list, "/", "units.xml"));
+ list.clear();
+
+ VirtFs::unmountZip(prefix + "data/test/test2.zip");
+ VirtFs::deinit();
+ delete2(logger);
+}
+
+TEST_CASE("VirtFs1 getFilesWithDir2")
+{
+ VirtFs::init(".");
+ logger = new Logger();
+ std::string name("data/test/test.zip");
+ std::string prefix;
+ if (Files::existsLocal(name) == false)
+ prefix = "../" + prefix;
+ StringVect list;
+
+ SECTION("dir1")
+ {
+ VirtFs::mountDir(prefix + "data/graphics",
+ Append_false);
+
+ VirtFs::getFilesWithDir("/", list);
+ REQUIRE(list.size() <= 5);
+ VirtFs::unmountDir(prefix + "data/graphics");
+ }
+
+ SECTION("dir2")
+ {
+ VirtFs::mountDir(prefix + "data",
+ Append_false);
+
+ VirtFs::getFilesWithDir("music", list);
+ REQUIRE(list.size() <= 5);
+ REQUIRE(list.size() >= 1);
+ REQUIRE(inList(list, "music", "keprohm.ogg"));
+ list.clear();
+
+ VirtFs::getFilesWithDir(pathJoin("evol", "icons"), list);
+ REQUIRE(list.size() == 3);
+ REQUIRE(inList(list, pathJoin("evol" , "icons"), "evol-client.ico"));
+ REQUIRE(inList(list, pathJoin("evol" , "icons"), "evol-client.png"));
+ REQUIRE(inList(list, pathJoin("evol" , "icons"), "evol-client.xpm"));
+
+ VirtFs::unmountDir(prefix + "data");
+ }
+
+ VirtFs::deinit();
+ delete2(logger);
+}