summaryrefslogtreecommitdiff
path: root/src/fs
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
parent6f7f469430ea05946a11dd41f62010961be6285e (diff)
downloadplus-bbd71d4a8c95092deb9cbf4aef86722a1e9628db.tar.gz
plus-bbd71d4a8c95092deb9cbf4aef86722a1e9628db.tar.bz2
plus-bbd71d4a8c95092deb9cbf4aef86722a1e9628db.tar.xz
plus-bbd71d4a8c95092deb9cbf4aef86722a1e9628db.zip
Fix unit tests on windows.
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/files.cpp16
-rw-r--r--src/fs/files_unittest.cc12
-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
-rw-r--r--src/fs/virtfs_unittest.cc39
7 files changed, 175 insertions, 131 deletions
diff --git a/src/fs/files.cpp b/src/fs/files.cpp
index d8a6e76ec..f6a138475 100644
--- a/src/fs/files.cpp
+++ b/src/fs/files.cpp
@@ -38,6 +38,8 @@
#include "debug.h"
+extern const char *dirSeparator;
+
#ifdef ANDROID
void Files::extractLocale()
{
@@ -211,7 +213,21 @@ int Files::copyFile(const std::string &restrict srcName,
bool Files::existsLocal(const std::string &path)
{
struct stat statbuf;
+#ifdef WIN32
+ // in windows path\file.ext\ by default detected as exists
+ // if file.ext is not directory, need return false
+ const bool res = (stat(path.c_str(), &statbuf) == 0);
+ if (res == false)
+ return false;
+ if ((findLast(path, "/") == true || findLast(path, "\\") == true) &&
+ S_ISDIR(statbuf.st_mode) == 0)
+ {
+ return false;
+ }
+ return true;
+#else // WIN32
return stat(path.c_str(), &statbuf) == 0;
+#endif // WIN32
}
bool Files::loadTextFileLocal(const std::string &fileName,
diff --git a/src/fs/files_unittest.cc b/src/fs/files_unittest.cc
index 19fd40ec1..d2bac3256 100644
--- a/src/fs/files_unittest.cc
+++ b/src/fs/files_unittest.cc
@@ -34,7 +34,6 @@
TEST_CASE("Files renameFile")
{
- dirSeparator = "/";
logger = new Logger();
ResourceManager::init();
VirtFs::addDirToSearchPathSilent("data", Append_false);
@@ -74,7 +73,6 @@ TEST_CASE("Files renameFile")
TEST_CASE("Files existsLocal")
{
- dirSeparator = "/";
logger = new Logger();
ResourceManager::init();
VirtFs::addDirToSearchPathSilent("data", Append_false);
@@ -91,7 +89,6 @@ TEST_CASE("Files existsLocal")
TEST_CASE("Files loadTextFileString")
{
- dirSeparator = "/";
logger = new Logger();
ResourceManager::init();
VirtFs::addDirToSearchPathSilent("data", Append_false);
@@ -107,7 +104,6 @@ TEST_CASE("Files loadTextFileString")
TEST_CASE("Files loadTextFile")
{
- dirSeparator = "/";
logger = new Logger();
ResourceManager::init();
VirtFs::addDirToSearchPathSilent("data", Append_false);
@@ -127,7 +123,6 @@ TEST_CASE("Files loadTextFile")
TEST_CASE("Files saveTextFile")
{
- dirSeparator = "/";
logger = new Logger();
ResourceManager::init();
VirtFs::addDirToSearchPathSilent("data", Append_false);
@@ -138,7 +133,13 @@ TEST_CASE("Files saveTextFile")
Files::saveTextFile(dir, "tempfile.txt", "test line\ntext line2");
std::string data = VirtFs::loadTextFileString("test/tempfile.txt");
::remove((dir + "/tempfile.txt").c_str());
+#ifdef WIN32
+ REQUIRE(data == "test line\r\ntext line2\r\n");
+#else // WIN32
+
REQUIRE(data == "test line\ntext line2\n");
+#endif // WIN32
+
ResourceManager::deleteInstance();
VirtFs::removeDirFromSearchPathSilent("data");
VirtFs::removeDirFromSearchPathSilent("../data");
@@ -148,7 +149,6 @@ TEST_CASE("Files saveTextFile")
TEST_CASE("Files getFilesInDir")
{
- dirSeparator = "/";
logger = new Logger();
ResourceManager::init();
VirtFs::addDirToSearchPathSilent("data", Append_false);
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);
diff --git a/src/fs/virtfs_unittest.cc b/src/fs/virtfs_unittest.cc
index c1dcc4fd0..b3f07daa1 100644
--- a/src/fs/virtfs_unittest.cc
+++ b/src/fs/virtfs_unittest.cc
@@ -599,6 +599,7 @@ TEST_CASE("VirtFs openRead3")
TEST_CASE("VirtFs getRealDir1")
{
logger = new Logger();
+ const std::string sep = dirSeparator;
REQUIRE(VirtFs::getRealDir(".") == "");
REQUIRE(VirtFs::getRealDir("..") == "");
const bool dir1 = VirtFs::addDirToSearchPathSilent("data", Append_false);
@@ -626,15 +627,15 @@ TEST_CASE("VirtFs 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.txt") ==
- "../data/test");
+ ".." + sep + "data" + sep + "test");
}
REQUIRE(VirtFs::getRealDir("zzz") == "");
@@ -642,15 +643,17 @@ TEST_CASE("VirtFs getRealDir1")
{
VirtFs::addZipToSearchPath("data/test/test.zip", Append_false);
REQUIRE(VirtFs::getRealDir("dir/brimmedhat.png") ==
- "data/test/test.zip");
- REQUIRE(VirtFs::getRealDir("hide.png") == "data/test");
+ "data" + sep + "test" + sep + "test.zip");
+ REQUIRE(VirtFs::getRealDir("hide.png") ==
+ "data" + sep + "test");
}
else
{
VirtFs::addZipToSearchPath("../data/test/test.zip", Append_false);
REQUIRE(VirtFs::getRealDir("dir/brimmedhat.png") ==
- "../data/test/test.zip");
- REQUIRE(VirtFs::getRealDir("hide.png") == "../data/test");
+ ".." + sep + "data" + sep + "test" + sep + "test.zip");
+ REQUIRE(VirtFs::getRealDir("hide.png") ==
+ ".." + sep + "data" + sep + "test");
}
VirtFs::removeDirFromSearchPathSilent("data/test");
@@ -661,14 +664,16 @@ TEST_CASE("VirtFs getRealDir1")
REQUIRE(VirtFs::getRealDir("test") == "data");
REQUIRE(VirtFs::getRealDir("test/test.txt") ==
"data");
- REQUIRE(VirtFs::getRealDir("dir/hide.png") == "data/test/test.zip");
+ REQUIRE(VirtFs::getRealDir("dir/hide.png") ==
+ "data" + sep + "test" + sep + "test.zip");
}
else
{
- REQUIRE(VirtFs::getRealDir("test") == "../data");
+ REQUIRE(VirtFs::getRealDir("test") == ".." + sep + "data");
REQUIRE(VirtFs::getRealDir("test/test.txt") ==
- "../data");
- REQUIRE(VirtFs::getRealDir("dir/hide.png") == "../data/test/test.zip");
+ ".." + sep + "data");
+ REQUIRE(VirtFs::getRealDir("dir/hide.png") ==
+ ".." + sep + "data" + sep + "test" + sep + "test.zip");
}
REQUIRE(VirtFs::exists("dir/hide.png"));
REQUIRE(VirtFs::getRealDir("zzz") == "");
@@ -685,6 +690,7 @@ TEST_CASE("VirtFs getRealDir1")
TEST_CASE("VirtFs getrealDir2")
{
logger = new Logger();
+ const std::string sep = dirSeparator;
std::string name("data/test/test.zip");
std::string prefix;
if (Files::existsLocal(name) == false)
@@ -697,12 +703,13 @@ TEST_CASE("VirtFs getrealDir2")
REQUIRE(VirtFs::getRealDir("zzz") == "");
REQUIRE(VirtFs::getRealDir("dir1/file1.txt") ==
- prefix + "data/test");
- REQUIRE(VirtFs::getRealDir("hide.png") == prefix + "data/test");
+ prefix + "data" + sep + "test");
+ REQUIRE(VirtFs::getRealDir("hide.png") ==
+ prefix + "data" + sep + "test");
REQUIRE(VirtFs::getRealDir("dir//hide.png") ==
- prefix + "data/test/test2.zip");
+ prefix + "data" + sep + "test" + sep + "test2.zip");
REQUIRE(VirtFs::getRealDir("dir/1//test.txt") ==
- prefix + "data/test/test2.zip");
+ prefix + "data" + sep + "test" + sep + "test2.zip");
VirtFs::removeZipFromSearchPath(prefix + "data/test/test2.zip");
VirtFs::removeDirFromSearchPath(prefix + "data/test");