summaryrefslogtreecommitdiff
path: root/src/fs/virtfs
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-03-07 22:02:59 +0300
committerAndrei Karas <akaras@inbox.ru>2017-03-07 22:02:59 +0300
commitbbd71d4a8c95092deb9cbf4aef86722a1e9628db (patch)
tree59566c4baa2e32287fe5867e5616ca560d3f3bf5 /src/fs/virtfs
parent6f7f469430ea05946a11dd41f62010961be6285e (diff)
downloadmanaverse-bbd71d4a8c95092deb9cbf4aef86722a1e9628db.tar.gz
manaverse-bbd71d4a8c95092deb9cbf4aef86722a1e9628db.tar.bz2
manaverse-bbd71d4a8c95092deb9cbf4aef86722a1e9628db.tar.xz
manaverse-bbd71d4a8c95092deb9cbf4aef86722a1e9628db.zip
Fix unit tests on windows.
Diffstat (limited to 'src/fs/virtfs')
-rw-r--r--src/fs/virtfs/virtfs_unittest.cc202
-rw-r--r--src/fs/virtfs/virtfszip.cpp2
-rw-r--r--src/fs/virtfs/zip.cpp6
-rw-r--r--src/fs/virtfs/zip_unittest.cc29
4 files changed, 130 insertions, 109 deletions
diff --git a/src/fs/virtfs/virtfs_unittest.cc b/src/fs/virtfs/virtfs_unittest.cc
index cece63a04..8047c879c 100644
--- a/src/fs/virtfs/virtfs_unittest.cc
+++ b/src/fs/virtfs/virtfs_unittest.cc
@@ -55,14 +55,15 @@ TEST_CASE("VirtFs1 addDirToSearchPath")
{
VirtFs::init(".");
logger = new Logger();
+ const std::string sep = dirSeparator;
SECTION("simple 1")
{
REQUIRE(VirtFs::addDirToSearchPathSilent2("dir1",
Append_false));
- REQUIRE(VirtFs::searchEntryByRootInternal("dir1/") != nullptr);
- REQUIRE(VirtFs::searchEntryByRootInternal("test/") == nullptr);
+ REQUIRE(VirtFs::searchEntryByRootInternal("dir1" + sep) != nullptr);
+ REQUIRE(VirtFs::searchEntryByRootInternal("test" + sep) == nullptr);
REQUIRE(VirtFs::getEntries().size() == 1);
- REQUIRE(VirtFs::getEntries()[0]->root == "dir1/");
+ REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(static_cast<VirtDirEntry*>(
VirtFs::getEntries()[0])->userDir == "dir1");
@@ -72,13 +73,13 @@ TEST_CASE("VirtFs1 addDirToSearchPath")
{
REQUIRE(VirtFs::addDirToSearchPathSilent2("dir1/",
Append_true));
- REQUIRE(VirtFs::searchEntryByRootInternal("dir1/") != nullptr);
- REQUIRE(VirtFs::searchEntryByRootInternal("test/") == nullptr);
+ REQUIRE(VirtFs::searchEntryByRootInternal("dir1" + sep) != nullptr);
+ REQUIRE(VirtFs::searchEntryByRootInternal("test" + sep) == nullptr);
REQUIRE(VirtFs::getEntries().size() == 1);
- REQUIRE(VirtFs::getEntries()[0]->root == "dir1/");
+ REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(static_cast<VirtDirEntry*>(
- VirtFs::getEntries()[0])->userDir == "dir1/");
+ VirtFs::getEntries()[0])->userDir == "dir1" + sep);
}
SECTION("simple 3")
@@ -87,12 +88,12 @@ TEST_CASE("VirtFs1 addDirToSearchPath")
Append_false));
REQUIRE(VirtFs::addDirToSearchPathSilent2("dir2",
Append_false));
- REQUIRE(VirtFs::searchEntryByRootInternal("dir1/") != nullptr);
- REQUIRE(VirtFs::searchEntryByRootInternal("dir2/") != nullptr);
- REQUIRE(VirtFs::searchEntryByRootInternal("test/") == nullptr);
+ REQUIRE(VirtFs::searchEntryByRootInternal("dir1" + sep) != nullptr);
+ REQUIRE(VirtFs::searchEntryByRootInternal("dir2" + sep) != nullptr);
+ REQUIRE(VirtFs::searchEntryByRootInternal("test" + sep) == nullptr);
REQUIRE(VirtFs::getEntries().size() == 2);
- REQUIRE(VirtFs::getEntries()[0]->root == "dir2/");
- REQUIRE(VirtFs::getEntries()[1]->root == "dir1/");
+ REQUIRE(VirtFs::getEntries()[0]->root == "dir2" + sep);
+ REQUIRE(VirtFs::getEntries()[1]->root == "dir1" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
REQUIRE(static_cast<VirtDirEntry*>(
@@ -107,16 +108,16 @@ TEST_CASE("VirtFs1 addDirToSearchPath")
Append_true));
REQUIRE(VirtFs::addDirToSearchPathSilent2("dir2",
Append_true));
- REQUIRE(VirtFs::searchEntryByRootInternal("dir1/") != nullptr);
- REQUIRE(VirtFs::searchEntryByRootInternal("dir2/") != nullptr);
- REQUIRE(VirtFs::searchEntryByRootInternal("test/") == nullptr);
+ REQUIRE(VirtFs::searchEntryByRootInternal("dir1" + sep) != nullptr);
+ REQUIRE(VirtFs::searchEntryByRootInternal("dir2" + sep) != nullptr);
+ REQUIRE(VirtFs::searchEntryByRootInternal("test" + sep) == nullptr);
REQUIRE(VirtFs::getEntries().size() == 2);
- REQUIRE(VirtFs::getEntries()[0]->root == "dir1/");
- REQUIRE(VirtFs::getEntries()[1]->root == "dir2/");
+ REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
+ REQUIRE(VirtFs::getEntries()[1]->root == "dir2" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
REQUIRE(static_cast<VirtDirEntry*>(
- VirtFs::getEntries()[0])->userDir == "dir1/");
+ VirtFs::getEntries()[0])->userDir == "dir1" + sep);
REQUIRE(static_cast<VirtDirEntry*>(
VirtFs::getEntries()[1])->userDir == "dir2");
}
@@ -129,14 +130,15 @@ TEST_CASE("VirtFs1 addDirToSearchPath")
Append_true));
REQUIRE(VirtFs::addDirToSearchPathSilent2("dir3/test",
Append_true));
- REQUIRE(VirtFs::searchEntryByRootInternal("dir1/") != nullptr);
- REQUIRE(VirtFs::searchEntryByRootInternal("dir2/") != nullptr);
- REQUIRE(VirtFs::searchEntryByRootInternal("dir3/test/") != nullptr);
- REQUIRE(VirtFs::searchEntryByRootInternal("test/") == nullptr);
+ REQUIRE(VirtFs::searchEntryByRootInternal("dir1" + sep) != nullptr);
+ REQUIRE(VirtFs::searchEntryByRootInternal("dir2" + sep) != nullptr);
+ REQUIRE(VirtFs::searchEntryByRootInternal(
+ "dir3" + sep + "test" + sep) != nullptr);
+ REQUIRE(VirtFs::searchEntryByRootInternal("test" + sep) == nullptr);
REQUIRE(VirtFs::getEntries().size() == 3);
- REQUIRE(VirtFs::getEntries()[0]->root == "dir1/");
- REQUIRE(VirtFs::getEntries()[1]->root == "dir2/");
- REQUIRE(VirtFs::getEntries()[2]->root == "dir3/test/");
+ REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
+ REQUIRE(VirtFs::getEntries()[1]->root == "dir2" + sep);
+ REQUIRE(VirtFs::getEntries()[2]->root == "dir3" + sep + "test" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Dir);
@@ -145,7 +147,7 @@ TEST_CASE("VirtFs1 addDirToSearchPath")
REQUIRE(static_cast<VirtDirEntry*>(
VirtFs::getEntries()[1])->userDir == "dir2");
REQUIRE(static_cast<VirtDirEntry*>(
- VirtFs::getEntries()[2])->userDir == "dir3/test");
+ VirtFs::getEntries()[2])->userDir == "dir3" + sep + "test");
}
SECTION("simple 6")
@@ -154,21 +156,25 @@ TEST_CASE("VirtFs1 addDirToSearchPath")
Append_true));
REQUIRE(VirtFs::addDirToSearchPathSilent2("dir2",
Append_true));
- REQUIRE(VirtFs::addDirToSearchPathSilent2("dir3/test",
+ REQUIRE(VirtFs::addDirToSearchPathSilent2("dir3\\test",
Append_false));
- REQUIRE(VirtFs::searchEntryByRootInternal("dir1/") != nullptr);
- REQUIRE(VirtFs::searchEntryByRootInternal("dir2/") != nullptr);
- REQUIRE(VirtFs::searchEntryByRootInternal("dir3/test/") != nullptr);
- REQUIRE(VirtFs::searchEntryByRootInternal("test/") == nullptr);
+ REQUIRE(VirtFs::searchEntryByRootInternal(
+ "dir1" + sep + "") != nullptr);
+ REQUIRE(VirtFs::searchEntryByRootInternal(
+ "dir2" + sep + "") != nullptr);
+ REQUIRE(VirtFs::searchEntryByRootInternal(
+ "dir3" + sep + "test" + sep) != nullptr);
+ REQUIRE(VirtFs::searchEntryByRootInternal(
+ "test" + sep + "") == nullptr);
REQUIRE(VirtFs::getEntries().size() == 3);
- REQUIRE(VirtFs::getEntries()[0]->root == "dir3/test/");
- REQUIRE(VirtFs::getEntries()[1]->root == "dir1/");
- REQUIRE(VirtFs::getEntries()[2]->root == "dir2/");
+ REQUIRE(VirtFs::getEntries()[0]->root == "dir3" + sep + "test" + sep);
+ REQUIRE(VirtFs::getEntries()[1]->root == "dir1" + sep);
+ REQUIRE(VirtFs::getEntries()[2]->root == "dir2" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Dir);
REQUIRE(static_cast<VirtDirEntry*>(
- VirtFs::getEntries()[0])->userDir == "dir3/test");
+ VirtFs::getEntries()[0])->userDir == "dir3" + sep + "test");
REQUIRE(static_cast<VirtDirEntry*>(
VirtFs::getEntries()[1])->userDir == "dir1");
REQUIRE(static_cast<VirtDirEntry*>(
@@ -185,6 +191,7 @@ TEST_CASE("VirtFs1 addZipToSearchPath")
logger = new Logger();
std::string name("data/test/test.zip");
std::string prefix;
+ const std::string sep = dirSeparator;
std::vector<ZipLocalHeader*> headers;
if (Files::existsLocal(name) == false)
prefix = "../";
@@ -194,12 +201,12 @@ TEST_CASE("VirtFs1 addZipToSearchPath")
REQUIRE(VirtFs::addZipToSearchPath(prefix + "data/test/test.zip",
Append_false));
REQUIRE(VirtFs::searchEntryByRootInternal(
- prefix + "data/test/test.zip") != nullptr);
+ prefix + "data" + sep + "test" + sep + "test.zip") != nullptr);
REQUIRE(VirtFs::searchEntryByRootInternal(
- prefix + "data/test/test2.zip") == nullptr);
+ prefix + "data" + sep + "test" + sep + "test2.zip") == nullptr);
REQUIRE(VirtFs::getEntries().size() == 1);
REQUIRE(VirtFs::getEntries()[0]->root ==
- prefix + "data/test/test.zip");
+ prefix + "data" + sep + "test" + sep + "test.zip");
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip);
}
@@ -210,15 +217,15 @@ TEST_CASE("VirtFs1 addZipToSearchPath")
REQUIRE(VirtFs::addZipToSearchPath(prefix + "data/test/test2.zip",
Append_false));
REQUIRE(VirtFs::searchEntryByRootInternal(
- prefix + "data/test/test.zip") != nullptr);
+ prefix + "data" + sep + "test" + sep + "test.zip") != nullptr);
REQUIRE(VirtFs::searchEntryByRootInternal(
- prefix + "data/test/test2.zip") != nullptr);
+ prefix + "data" + sep + "test" + sep + "test2.zip") != nullptr);
REQUIRE(VirtFs::getEntries().size() == 2);
REQUIRE(VirtFs::getEntries()[0]->root ==
- prefix + "data/test/test2.zip");
+ prefix + "data" + sep + "test" + sep + "test2.zip");
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip);
REQUIRE(VirtFs::getEntries()[1]->root ==
- prefix + "data/test/test.zip");
+ prefix + "data" + sep + "test" + sep + "test.zip");
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Zip);
}
@@ -229,15 +236,15 @@ TEST_CASE("VirtFs1 addZipToSearchPath")
REQUIRE(VirtFs::addZipToSearchPath(prefix + "data/test/test2.zip",
Append_true));
REQUIRE(VirtFs::searchEntryByRootInternal(
- prefix + "data/test/test.zip") != nullptr);
+ prefix + "data" + sep + "test" + sep + "test.zip") != nullptr);
REQUIRE(VirtFs::searchEntryByRootInternal(
- prefix + "data/test/test2.zip") != nullptr);
+ prefix + "data" + sep + "test" + sep + "test2.zip") != nullptr);
REQUIRE(VirtFs::getEntries().size() == 2);
REQUIRE(VirtFs::getEntries()[0]->root ==
- prefix + "data/test/test.zip");
+ prefix + "data" + sep + "test" + sep + "test.zip");
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip);
REQUIRE(VirtFs::getEntries()[1]->root ==
- prefix + "data/test/test2.zip");
+ prefix + "data" + sep + "test" + sep + "test2.zip");
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Zip);
}
@@ -250,20 +257,20 @@ TEST_CASE("VirtFs1 addZipToSearchPath")
REQUIRE(VirtFs::addZipToSearchPath(prefix + "data/test/test2.zip",
Append_false));
REQUIRE(VirtFs::searchEntryByRootInternal(
- prefix + "data/test/test.zip") != nullptr);
+ prefix + "data" + sep + "test" + sep + "test.zip") != nullptr);
REQUIRE(VirtFs::searchEntryByRootInternal(
- prefix + "data/test/test2.zip") != nullptr);
+ prefix + "data" + sep + "test" + sep + "test2.zip") != nullptr);
REQUIRE(VirtFs::searchEntryByRootInternal(
- prefix + "data/test/") != nullptr);
+ prefix + "data" + sep + "test" + sep + "") != nullptr);
REQUIRE(VirtFs::getEntries().size() == 3);
REQUIRE(VirtFs::getEntries()[0]->root ==
- prefix + "data/test/test2.zip");
+ prefix + "data" + sep + "test" + sep + "test2.zip");
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip);
REQUIRE(VirtFs::getEntries()[1]->root ==
- prefix + "data/test/");
+ prefix + "data" + sep + "test" + sep + "");
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
REQUIRE(VirtFs::getEntries()[2]->root ==
- prefix + "data/test/test.zip");
+ prefix + "data" + sep + "test" + sep + "test.zip");
REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Zip);
}
@@ -276,20 +283,20 @@ TEST_CASE("VirtFs1 addZipToSearchPath")
REQUIRE(VirtFs::addZipToSearchPath(prefix + "data/test/test2.zip",
Append_true));
REQUIRE(VirtFs::searchEntryByRootInternal(
- prefix + "data/test/test.zip") != nullptr);
+ prefix + "data" + sep + "test" + sep + "test.zip") != nullptr);
REQUIRE(VirtFs::searchEntryByRootInternal(
- prefix + "data/test/test2.zip") != nullptr);
+ prefix + "data" + sep + "test" + sep + "test2.zip") != nullptr);
REQUIRE(VirtFs::searchEntryByRootInternal(
- prefix + "data/test/") != nullptr);
+ prefix + "data" + sep + "test" + sep + "") != nullptr);
REQUIRE(VirtFs::getEntries().size() == 3);
REQUIRE(VirtFs::getEntries()[0]->root ==
- prefix + "data/test/");
+ prefix + "data" + sep + "test" + sep + "");
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(VirtFs::getEntries()[1]->root ==
- prefix + "data/test/test.zip");
+ prefix + "data" + sep + "test" + sep + "test.zip");
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Zip);
REQUIRE(VirtFs::getEntries()[2]->root ==
- prefix + "data/test/test2.zip");
+ prefix + "data" + sep + "test" + sep + "test2.zip");
REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Zip);
}
@@ -303,6 +310,7 @@ TEST_CASE("VirtFs1 removeFromSearchPath")
logger = new Logger();
std::string name("data/test/test.zip");
std::string prefix;
+ const std::string sep = dirSeparator;
std::vector<ZipLocalHeader*> headers;
if (Files::existsLocal(name) == false)
prefix = "../";
@@ -333,28 +341,28 @@ TEST_CASE("VirtFs1 removeFromSearchPath")
REQUIRE_THROWS(VirtFs::removeDirFromSearchPath("dir2"));
REQUIRE(VirtFs::removeDirFromSearchPath("dir1"));
REQUIRE(VirtFs::getEntries().size() == 2);
- REQUIRE(VirtFs::getEntries()[0]->root == "dir3/");
+ REQUIRE(VirtFs::getEntries()[0]->root == "dir3" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(static_cast<VirtDirEntry*>(
VirtFs::getEntries()[0])->userDir == "dir3");
- REQUIRE(VirtFs::getEntries()[1]->root == "dir2/dir3/");
+ REQUIRE(VirtFs::getEntries()[1]->root == "dir2" + sep + "dir3" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(static_cast<VirtDirEntry*>(
- VirtFs::getEntries()[1])->userDir == "dir2/dir3");
+ VirtFs::getEntries()[1])->userDir == "dir2" + sep + "dir3");
REQUIRE_THROWS(VirtFs::removeDirFromSearchPath("dir1"));
REQUIRE(VirtFs::getEntries().size() == 2);
- REQUIRE(VirtFs::getEntries()[0]->root == "dir3/");
+ REQUIRE(VirtFs::getEntries()[0]->root == "dir3" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(static_cast<VirtDirEntry*>(
VirtFs::getEntries()[0])->userDir == "dir3");
- REQUIRE(VirtFs::getEntries()[1]->root == "dir2/dir3/");
+ REQUIRE(VirtFs::getEntries()[1]->root == "dir2" + sep + "dir3" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(static_cast<VirtDirEntry*>(
- VirtFs::getEntries()[1])->userDir == "dir2/dir3");
+ VirtFs::getEntries()[1])->userDir == "dir2" + sep + "dir3");
REQUIRE(VirtFs::removeDirFromSearchPath("dir2/dir3"));
- REQUIRE_THROWS(VirtFs::removeDirFromSearchPath("dir2/dir3/"));
+ REQUIRE_THROWS(VirtFs::removeDirFromSearchPath("dir2/dir3" + sep));
REQUIRE(VirtFs::getEntries().size() == 1);
- REQUIRE(VirtFs::getEntries()[0]->root == "dir3/");
+ REQUIRE(VirtFs::getEntries()[0]->root == "dir3" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(static_cast<VirtDirEntry*>(
VirtFs::getEntries()[0])->userDir == "dir3");
@@ -365,7 +373,7 @@ TEST_CASE("VirtFs1 removeFromSearchPath")
REQUIRE(VirtFs::addDirToSearchPathSilent2("dir1",
Append_true));
REQUIRE(VirtFs::getEntries().size() == 1);
- REQUIRE(VirtFs::getEntries()[0]->root == "dir1/");
+ REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(static_cast<VirtDirEntry*>(
VirtFs::getEntries()[0])->userDir == "dir1");
@@ -375,7 +383,7 @@ TEST_CASE("VirtFs1 removeFromSearchPath")
REQUIRE(VirtFs::addDirToSearchPathSilent2("dir1",
Append_true));
REQUIRE(VirtFs::getEntries().size() == 1);
- REQUIRE(VirtFs::getEntries()[0]->root == "dir1/");
+ REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(static_cast<VirtDirEntry*>(
VirtFs::getEntries()[0])->userDir == "dir1");
@@ -389,25 +397,25 @@ TEST_CASE("VirtFs1 removeFromSearchPath")
Append_true));
REQUIRE(VirtFs::searchEntryByRootInternal(
- prefix + "data/test/test.zip") != nullptr);
+ prefix + "data" + sep + "test" + sep + "test.zip") != nullptr);
REQUIRE(VirtFs::searchEntryByRootInternal(
- prefix + "data/test/test2.zip") != nullptr);
+ prefix + "data" + sep + "test" + sep + "test2.zip") != nullptr);
REQUIRE(VirtFs::getEntries().size() == 2);
REQUIRE(VirtFs::getEntries()[0]->root ==
- prefix + "data/test/test.zip");
+ prefix + "data" + sep + "test" + sep + "test.zip");
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip);
REQUIRE(VirtFs::getEntries()[1]->root ==
- prefix + "data/test/test2.zip");
+ prefix + "data" + sep + "test" + sep + "test2.zip");
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Zip);
VirtFs::removeZipFromSearchPath(prefix + "data/test/test.zip");
REQUIRE(VirtFs::searchEntryByRootInternal(
- prefix + "data/test/test.zip") == nullptr);
+ prefix + "data" + sep + "test" + sep + "test.zip") == nullptr);
REQUIRE(VirtFs::searchEntryByRootInternal(
- prefix + "data/test/test2.zip") != nullptr);
+ prefix + "data" + sep + "test" + sep + "test2.zip") != nullptr);
REQUIRE(VirtFs::getEntries().size() == 1);
REQUIRE(VirtFs::getEntries()[0]->root ==
- prefix + "data/test/test2.zip");
+ prefix + "data" + sep + "test" + sep + "test2.zip");
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip);
}
@@ -417,39 +425,39 @@ TEST_CASE("VirtFs1 removeFromSearchPath")
Append_false));
REQUIRE(VirtFs::addDirToSearchPath(prefix + "data/test",
Append_false));
- REQUIRE(VirtFs::addZipToSearchPath(prefix + "data/test/test2.zip",
+ REQUIRE(VirtFs::addZipToSearchPath(prefix + "data\\test/test2.zip",
Append_false));
REQUIRE(VirtFs::searchEntryByRootInternal(
- prefix + "data/test/test.zip") != nullptr);
+ prefix + "data" + sep + "test" + sep + "test.zip") != nullptr);
REQUIRE(VirtFs::searchEntryByRootInternal(
- prefix + "data/test/test2.zip") != nullptr);
+ prefix + "data" + sep + "test" + sep + "test2.zip") != nullptr);
REQUIRE(VirtFs::searchEntryByRootInternal(
- prefix + "data/test/") != nullptr);
+ prefix + "data" + sep + "test" + sep + "") != nullptr);
REQUIRE(VirtFs::getEntries().size() == 3);
REQUIRE(VirtFs::getEntries()[0]->root ==
- prefix + "data/test/test2.zip");
+ prefix + "data" + sep + "test" + sep + "test2.zip");
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip);
REQUIRE(VirtFs::getEntries()[1]->root ==
- prefix + "data/test/");
+ prefix + "data" + sep + "test" + sep);
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
REQUIRE(VirtFs::getEntries()[2]->root ==
- prefix + "data/test/test.zip");
+ prefix + "data" + sep + "test" + sep + "test.zip");
REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Zip);
VirtFs::removeZipFromSearchPath(prefix + "data/test/test.zip");
REQUIRE(VirtFs::searchEntryByRootInternal(
- prefix + "data/test/test.zip") == nullptr);
+ prefix + "data" + sep + "test" + sep + "test.zip") == nullptr);
REQUIRE(VirtFs::searchEntryByRootInternal(
- prefix + "data/test/test2.zip") != nullptr);
+ prefix + "data" + sep + "test" + sep + "test2.zip") != nullptr);
REQUIRE(VirtFs::searchEntryByRootInternal(
- prefix + "data/test/") != nullptr);
+ prefix + "data" + sep + "test" + sep + "") != nullptr);
REQUIRE(VirtFs::getEntries().size() == 2);
REQUIRE(VirtFs::getEntries()[0]->root ==
- prefix + "data/test/test2.zip");
+ prefix + "data" + sep + "test" + sep + "test2.zip");
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip);
REQUIRE(VirtFs::getEntries()[1]->root ==
- prefix + "data/test/");
+ prefix + "data" + sep + "test" + sep);
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
}
@@ -547,6 +555,7 @@ TEST_CASE("VirtFs1 getRealDir1")
{
VirtFs::init(".");
logger = new Logger();
+ const std::string sep = dirSeparator;
REQUIRE(VirtFs::getRealDir(".") == "");
REQUIRE(VirtFs::getRealDir("..") == "");
const bool dir1 = VirtFs::addDirToSearchPathSilent("data",
@@ -587,17 +596,17 @@ TEST_CASE("VirtFs1 getRealDir1")
REQUIRE(VirtFs::getRealDir("test\\test.txt") ==
"data");
REQUIRE(VirtFs::getRealDir("test.txt") ==
- "data/test");
+ "data" + sep + "test");
}
else
{
- REQUIRE(VirtFs::getRealDir("test") == "../data");
+ REQUIRE(VirtFs::getRealDir("test") == ".." + sep + "data");
REQUIRE(VirtFs::getRealDir("test/test.txt") ==
- "../data");
+ ".." + sep + "data");
REQUIRE(VirtFs::getRealDir("test\\test.txt") ==
- "../data");
+ ".." + sep + "data");
REQUIRE(VirtFs::getRealDir("test.txt") ==
- "../data/test");
+ ".." + sep + "data" + sep + "test");
}
REQUIRE(VirtFs::getRealDir("zzz") == "");
@@ -612,9 +621,9 @@ TEST_CASE("VirtFs1 getRealDir1")
}
else
{
- REQUIRE(VirtFs::getRealDir("test") == "../data");
+ REQUIRE(VirtFs::getRealDir("test") == ".." + sep + "data");
REQUIRE(VirtFs::getRealDir("test/test.txt") ==
- "../data");
+ ".." + sep + "data");
}
REQUIRE(VirtFs::getRealDir("zzz") == "");
@@ -628,10 +637,11 @@ TEST_CASE("VirtFs1 getRealDir2")
{
VirtFs::init(".");
logger = new Logger();
+ const std::string sep = dirSeparator;
std::string name("data/test/test.zip");
- std::string prefix("data/test/");
+ std::string prefix("data" + sep + "test" + sep);
if (Files::existsLocal(name) == false)
- prefix = "../" + prefix;
+ prefix = ".." + sep + prefix;
VirtFs::addZipToSearchPath(prefix + "test2.zip",
Append_false);
diff --git a/src/fs/virtfs/virtfszip.cpp b/src/fs/virtfs/virtfszip.cpp
index eac4a2535..0f1021793 100644
--- a/src/fs/virtfs/virtfszip.cpp
+++ b/src/fs/virtfs/virtfszip.cpp
@@ -136,7 +136,7 @@ namespace VirtFsZip
StringVect &names)
{
VirtZipEntry *const zipEntry = static_cast<VirtZipEntry*>(entry);
- if (dirName == "/")
+ if (dirName == dirSeparator)
{
FOR_EACH (std::vector<ZipLocalHeader*>::const_iterator,
it2,
diff --git a/src/fs/virtfs/zip.cpp b/src/fs/virtfs/zip.cpp
index 8dd7d8080..0556af1f8 100644
--- a/src/fs/virtfs/zip.cpp
+++ b/src/fs/virtfs/zip.cpp
@@ -36,6 +36,8 @@
#include "debug.h"
+extern const char *dirSeparator;
+
#define readVal(val, sz, msg) \
cnt = fread(static_cast<void*>(val), 1, sz, arcFile); \
if (cnt != sz) \
@@ -131,7 +133,7 @@ namespace Zip
header->dataOffset = ftell(arcFile) + extraFieldLen;
fseek(arcFile, extraFieldLen + header->compressSize, SEEK_CUR);
// pointer on 30 + fileNameLen + extraFieldLen + compressSize
- if (findLast(header->fileName, "/") == false)
+ if (findLast(header->fileName, dirSeparator) == false)
{
headers.push_back(header);
logger->log(" file name: %s",
@@ -145,6 +147,8 @@ namespace Zip
}
else
{
+ logger->log(" dir name: %s",
+ header->fileName.c_str());
dirs.push_back(header->fileName);
delete header;
}
diff --git a/src/fs/virtfs/zip_unittest.cc b/src/fs/virtfs/zip_unittest.cc
index 4b9258ec5..27d4bc1f9 100644
--- a/src/fs/virtfs/zip_unittest.cc
+++ b/src/fs/virtfs/zip_unittest.cc
@@ -35,11 +35,14 @@
#include "debug.h"
+extern const char *dirSeparator;
+
TEST_CASE("Zip readArchiveInfo")
{
logger = new Logger();
std::string name("data/test/test.zip");
std::string prefix;
+ const std::string sep = dirSeparator;
if (Files::existsLocal(name) == false)
prefix = "../";
@@ -54,10 +57,10 @@ TEST_CASE("Zip readArchiveInfo")
REQUIRE(Zip::readArchiveInfo(entry));
REQUIRE(headers.size() == 2);
REQUIRE(entry->root == name);
- REQUIRE(headers[0]->fileName == "dir/hide.png");
+ REQUIRE(headers[0]->fileName == "dir" + sep + "hide.png");
REQUIRE(headers[0]->compressSize == 365);
REQUIRE(headers[0]->uncompressSize == 368);
- REQUIRE(headers[1]->fileName == "dir/brimmedhat.png");
+ REQUIRE(headers[1]->fileName == "dir" + sep + "brimmedhat.png");
REQUIRE(headers[1]->compressSize == 1959);
REQUIRE(headers[1]->uncompressSize == 1959);
@@ -79,39 +82,43 @@ TEST_CASE("Zip readArchiveInfo")
REQUIRE(headers[0]->compressSize == 17);
REQUIRE(headers[0]->uncompressSize == 23);
- REQUIRE(headers[1]->fileName == "dir2/hide.png");
+ REQUIRE(headers[1]->fileName == "dir2" + sep + "hide.png");
REQUIRE(headers[1]->compressSize == 365);
REQUIRE(headers[1]->uncompressSize == 368);
- REQUIRE(headers[2]->fileName == "dir2/test.txt");
+ REQUIRE(headers[2]->fileName == "dir2" + sep + "test.txt");
REQUIRE(headers[2]->compressSize == 17);
REQUIRE(headers[2]->uncompressSize == 23);
- REQUIRE(headers[3]->fileName == "dir2/paths.xml");
+ REQUIRE(headers[3]->fileName == "dir2" + sep + "paths.xml");
REQUIRE(headers[3]->compressSize == 154);
REQUIRE(headers[3]->uncompressSize == 185);
- REQUIRE(headers[4]->fileName == "dir2/units.xml");
+ REQUIRE(headers[4]->fileName == "dir2" + sep + "units.xml");
REQUIRE(headers[4]->compressSize == 202);
REQUIRE(headers[4]->uncompressSize == 306);
- REQUIRE(headers[5]->fileName == "dir/hide.png");
+ REQUIRE(headers[5]->fileName == "dir" + sep + "hide.png");
REQUIRE(headers[5]->compressSize == 365);
REQUIRE(headers[5]->uncompressSize == 368);
- REQUIRE(headers[6]->fileName == "dir/1/test.txt");
+ REQUIRE(headers[6]->fileName ==
+ "dir" + sep + "1" + sep + "test.txt");
REQUIRE(headers[6]->compressSize == 17);
REQUIRE(headers[6]->uncompressSize == 23);
- REQUIRE(headers[7]->fileName == "dir/1/file1.txt");
+ REQUIRE(headers[7]->fileName ==
+ "dir" + sep + "1" + sep + "file1.txt");
REQUIRE(headers[7]->compressSize == 17);
REQUIRE(headers[7]->uncompressSize == 23);
- REQUIRE(headers[8]->fileName == "dir/gpl/palette.gpl");
+ REQUIRE(headers[8]->fileName ==
+ "dir" + sep + "gpl" + sep + "palette.gpl");
REQUIRE(headers[8]->compressSize == 128);
REQUIRE(headers[8]->uncompressSize == 213);
- REQUIRE(headers[9]->fileName == "dir/dye.png");
+ REQUIRE(headers[9]->fileName ==
+ "dir" + sep + "dye.png");
REQUIRE(headers[9]->compressSize == 794);
REQUIRE(headers[9]->uncompressSize == 794);