summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-03-04 02:25:51 +0300
committerAndrei Karas <akaras@inbox.ru>2017-03-04 02:25:51 +0300
commit40c50ec4e137a038dd3a9b660e55e6c2710cc446 (patch)
tree1a5bee838334a4bded0c43c63dc3fc1310f8a11e
parentb625bb7201ba2633fe0247ad6a1577c3cd6860cb (diff)
downloadmv-40c50ec4e137a038dd3a9b660e55e6c2710cc446.tar.gz
mv-40c50ec4e137a038dd3a9b660e55e6c2710cc446.tar.bz2
mv-40c50ec4e137a038dd3a9b660e55e6c2710cc446.tar.xz
mv-40c50ec4e137a038dd3a9b660e55e6c2710cc446.zip
Remove unused files with unit tests.
-rw-r--r--src/Makefile.am4
-rw-r--r--src/fs/virtfs/virtfsdir_unittest.cc735
-rw-r--r--src/fs/virtfs/virtfszip_unittest.cc753
3 files changed, 1 insertions, 1491 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index fddf3f101..99ade7528 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1961,9 +1961,7 @@ manaplustests_SOURCES += \
else
manaplustests_SOURCES += \
fs/virtfs/virtfs_unittest.cc \
- fs/virtfs/virtfsdir_unittest.cc \
- fs/virtfs/zip_unittest.cc \
- fs/virtfs/virtfszip_unittest.cc
+ fs/virtfs/zip_unittest.cc
endif
manaplustests_SOURCES += \
diff --git a/src/fs/virtfs/virtfsdir_unittest.cc b/src/fs/virtfs/virtfsdir_unittest.cc
deleted file mode 100644
index 8986ccdc5..000000000
--- a/src/fs/virtfs/virtfsdir_unittest.cc
+++ /dev/null
@@ -1,735 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2016-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef USE_PHYSFS
-
-#include "catch.hpp"
-
-#include "fs/virtfs/virtdirentry.h"
-#include "fs/virtfs/virtfsdir.h"
-#include "fs/virtfstools.h"
-#include "fs/virtlist.h"
-
-#include "utils/checkutils.h"
-#include "utils/delete2.h"
-
-#include "debug.h"
-/*
-TEST_CASE("VirtFsDir getEntries")
-{
- VirtFsDir::init(".");
- REQUIRE(VirtFsDir::getEntries().empty());
- REQUIRE(VirtFsDir::searchEntryByRoot("test") == nullptr);
- VirtFsDir::deinit();
-}
-
-TEST_CASE("VirtFsDir getBaseDir")
-{
- VirtFsDir::init(".");
- REQUIRE(VirtFsDir::getBaseDir() != nullptr);
- VirtFsDir::deinit();
-}
-
-TEST_CASE("VirtFsDir addToSearchPath")
-{
- VirtFsDir::init(".");
- logger = new Logger();
- SECTION("simple 1")
- {
- REQUIRE(VirtFsDir::addToSearchPathSilent("dir1",
- Append_false,
- SkipError_true));
- REQUIRE(VirtFsDir::searchEntryByRoot("dir1/") != nullptr);
- REQUIRE(VirtFsDir::searchEntryByRoot("test/") == nullptr);
- REQUIRE(VirtFsDir::getEntries().size() == 1);
- REQUIRE(VirtFsDir::getEntries()[0]->root == "dir1/");
- REQUIRE(VirtFsDir::getEntries()[0]->userDir == "dir1");
- }
-
- SECTION("simple 2")
- {
- REQUIRE(VirtFsDir::addToSearchPathSilent("dir1/",
- Append_true,
- SkipError_true));
- REQUIRE(VirtFsDir::searchEntryByRoot("dir1/") != nullptr);
- REQUIRE(VirtFsDir::searchEntryByRoot("test/") == nullptr);
- REQUIRE(VirtFsDir::getEntries().size() == 1);
- REQUIRE(VirtFsDir::getEntries()[0]->root == "dir1/");
- REQUIRE(VirtFsDir::getEntries()[0]->userDir == "dir1/");
- }
-
- SECTION("simple 3")
- {
- REQUIRE(VirtFsDir::addToSearchPathSilent("dir1",
- Append_false,
- SkipError_true));
- REQUIRE(VirtFsDir::addToSearchPathSilent("dir2",
- Append_false,
- SkipError_true));
- REQUIRE(VirtFsDir::searchEntryByRoot("dir1/") != nullptr);
- REQUIRE(VirtFsDir::searchEntryByRoot("dir2/") != nullptr);
- REQUIRE(VirtFsDir::searchEntryByRoot("test/") == nullptr);
- REQUIRE(VirtFsDir::getEntries().size() == 2);
- REQUIRE(VirtFsDir::getEntries()[0]->root == "dir2/");
- REQUIRE(VirtFsDir::getEntries()[1]->root == "dir1/");
- REQUIRE(VirtFsDir::getEntries()[0]->userDir == "dir2");
- REQUIRE(VirtFsDir::getEntries()[1]->userDir == "dir1");
- }
-
- SECTION("simple 4")
- {
- REQUIRE(VirtFsDir::addToSearchPathSilent("dir1\\",
- Append_true,
- SkipError_true));
- REQUIRE(VirtFsDir::addToSearchPathSilent("dir2",
- Append_true,
- SkipError_true));
- REQUIRE(VirtFsDir::searchEntryByRoot("dir1/") != nullptr);
- REQUIRE(VirtFsDir::searchEntryByRoot("dir2/") != nullptr);
- REQUIRE(VirtFsDir::searchEntryByRoot("test/") == nullptr);
- REQUIRE(VirtFsDir::getEntries().size() == 2);
- REQUIRE(VirtFsDir::getEntries()[0]->root == "dir1/");
- REQUIRE(VirtFsDir::getEntries()[1]->root == "dir2/");
- REQUIRE(VirtFsDir::getEntries()[0]->userDir == "dir1/");
- REQUIRE(VirtFsDir::getEntries()[1]->userDir == "dir2");
- }
-
- SECTION("simple 5")
- {
- REQUIRE(VirtFsDir::addToSearchPathSilent("dir1",
- Append_true,
- SkipError_true));
- REQUIRE(VirtFsDir::addToSearchPathSilent("dir2",
- Append_true,
- SkipError_true));
- REQUIRE(VirtFsDir::addToSearchPathSilent("dir3/test",
- Append_true,
- SkipError_true));
- REQUIRE(VirtFsDir::searchEntryByRoot("dir1/") != nullptr);
- REQUIRE(VirtFsDir::searchEntryByRoot("dir2/") != nullptr);
- REQUIRE(VirtFsDir::searchEntryByRoot("dir3/test/") != nullptr);
- REQUIRE(VirtFsDir::searchEntryByRoot("test/") == nullptr);
- REQUIRE(VirtFsDir::getEntries().size() == 3);
- REQUIRE(VirtFsDir::getEntries()[0]->root == "dir1/");
- REQUIRE(VirtFsDir::getEntries()[0]->userDir == "dir1");
- REQUIRE(VirtFsDir::getEntries()[1]->root == "dir2/");
- REQUIRE(VirtFsDir::getEntries()[1]->userDir == "dir2");
- REQUIRE(VirtFsDir::getEntries()[2]->root == "dir3/test/");
- REQUIRE(VirtFsDir::getEntries()[2]->userDir == "dir3/test");
- }
-
- SECTION("simple 6")
- {
- REQUIRE(VirtFsDir::addToSearchPathSilent("dir1",
- Append_true,
- SkipError_true));
- REQUIRE(VirtFsDir::addToSearchPathSilent("dir2",
- Append_true,
- SkipError_true));
- REQUIRE(VirtFsDir::addToSearchPathSilent("dir3/test",
- Append_false,
- SkipError_true));
- REQUIRE(VirtFsDir::searchEntryByRoot("dir1/") != nullptr);
- REQUIRE(VirtFsDir::searchEntryByRoot("dir2/") != nullptr);
- REQUIRE(VirtFsDir::searchEntryByRoot("dir3/test/") != nullptr);
- REQUIRE(VirtFsDir::searchEntryByRoot("test/") == nullptr);
- REQUIRE(VirtFsDir::getEntries().size() == 3);
- REQUIRE(VirtFsDir::getEntries()[0]->root == "dir3/test/");
- REQUIRE(VirtFsDir::getEntries()[0]->userDir == "dir3/test");
- REQUIRE(VirtFsDir::getEntries()[1]->root == "dir1/");
- REQUIRE(VirtFsDir::getEntries()[1]->userDir == "dir1");
- REQUIRE(VirtFsDir::getEntries()[2]->root == "dir2/");
- REQUIRE(VirtFsDir::getEntries()[2]->userDir == "dir2");
- }
-
- VirtFsDir::deinit();
- delete2(logger);
-}
-
-TEST_CASE("VirtFsDir removeFromSearchPath")
-{
- VirtFsDir::init(".");
- logger = new Logger();
-
- SECTION("simple 1")
- {
- REQUIRE_THROWS(VirtFsDir::removeFromSearchPath("dir1"));
- REQUIRE_THROWS(VirtFsDir::removeFromSearchPath("dir1/"));
- }
-
- SECTION("simple 2")
- {
- REQUIRE(VirtFsDir::addToSearchPathSilent("dir1",
- Append_true,
- SkipError_true));
- REQUIRE_THROWS(VirtFsDir::removeFromSearchPath("dir2"));
- REQUIRE(VirtFsDir::removeFromSearchPath("dir1"));
- }
-
- SECTION("simple 3")
- {
- REQUIRE(VirtFsDir::addToSearchPathSilent("dir1",
- Append_true,
- SkipError_true));
- REQUIRE(VirtFsDir::addToSearchPathSilent("dir2//dir3",
- Append_true,
- SkipError_true));
- REQUIRE(VirtFsDir::addToSearchPathSilent("dir3",
- Append_false,
- SkipError_true));
- REQUIRE(VirtFsDir::getEntries().size() == 3);
- REQUIRE_THROWS(VirtFsDir::removeFromSearchPath("dir2"));
- REQUIRE(VirtFsDir::removeFromSearchPath("dir1"));
- REQUIRE(VirtFsDir::getEntries().size() == 2);
- REQUIRE(VirtFsDir::getEntries()[0]->root == "dir3/");
- REQUIRE(VirtFsDir::getEntries()[0]->userDir == "dir3");
- REQUIRE(VirtFsDir::getEntries()[1]->root == "dir2/dir3/");
- REQUIRE(VirtFsDir::getEntries()[1]->userDir == "dir2/dir3");
- REQUIRE_THROWS(VirtFsDir::removeFromSearchPath("dir1"));
- REQUIRE(VirtFsDir::getEntries().size() == 2);
- REQUIRE(VirtFsDir::getEntries()[0]->root == "dir3/");
- REQUIRE(VirtFsDir::getEntries()[0]->userDir == "dir3");
- REQUIRE(VirtFsDir::getEntries()[1]->root == "dir2/dir3/");
- REQUIRE(VirtFsDir::getEntries()[1]->userDir == "dir2/dir3");
- REQUIRE(VirtFsDir::removeFromSearchPath("dir2/dir3"));
- REQUIRE_THROWS(VirtFsDir::removeFromSearchPath("dir2/dir3/"));
- REQUIRE(VirtFsDir::getEntries().size() == 1);
- REQUIRE(VirtFsDir::getEntries()[0]->root == "dir3/");
- REQUIRE(VirtFsDir::getEntries()[0]->userDir == "dir3");
- }
-
- SECTION("simple 4")
- {
- REQUIRE(VirtFsDir::addToSearchPathSilent("dir1",
- Append_true,
- SkipError_true));
- REQUIRE(VirtFsDir::getEntries().size() == 1);
- REQUIRE(VirtFsDir::getEntries()[0]->root == "dir1/");
- REQUIRE(VirtFsDir::getEntries()[0]->userDir == "dir1");
- REQUIRE_THROWS(VirtFsDir::removeFromSearchPath("dir2"));
- REQUIRE(VirtFsDir::removeFromSearchPath("dir1"));
- REQUIRE(VirtFsDir::getEntries().size() == 0);
- REQUIRE(VirtFsDir::addToSearchPathSilent("dir1",
- Append_true,
- SkipError_true));
- REQUIRE(VirtFsDir::getEntries().size() == 1);
- REQUIRE(VirtFsDir::getEntries()[0]->root == "dir1/");
- REQUIRE(VirtFsDir::getEntries()[0]->userDir == "dir1");
- }
-
- VirtFsDir::deinit();
- delete2(logger);
-}
-
-TEST_CASE("VirtFsDir exists")
-{
- VirtFsDir::init(".");
- logger = new Logger();
- VirtFsDir::addToSearchPathSilent("data/",
- Append_false,
- SkipError_false);
- VirtFsDir::addToSearchPathSilent("..\\data",
- Append_false,
- SkipError_false);
-
- REQUIRE(VirtFsDir::exists("test") == true);
- REQUIRE(VirtFsDir::exists("test/dir1"));
- REQUIRE(VirtFsDir::exists("test/dir") == false);
- REQUIRE(VirtFsDir::exists("test//units.xml") == true);
- REQUIRE(VirtFsDir::exists("test/\\units123.xml") == false);
- REQUIRE(VirtFsDir::exists("tesQ/units.xml") == false);
- REQUIRE(VirtFsDir::exists("units.xml") == false);
-
- VirtFsDir::addToSearchPathSilent("data//test",
- Append_false,
- SkipError_false);
- VirtFsDir::addToSearchPathSilent("..//data\\test",
- Append_false,
- SkipError_false);
-
- REQUIRE(VirtFsDir::exists("test") == true);
- REQUIRE(VirtFsDir::exists("test/dir1"));
- REQUIRE(VirtFsDir::exists("test/dir") == false);
- REQUIRE(VirtFsDir::exists("test\\units.xml") == true);
- REQUIRE(VirtFsDir::exists("test/units123.xml") == false);
- REQUIRE(VirtFsDir::exists("tesQ/units.xml") == false);
- REQUIRE(VirtFsDir::exists("units.xml") == true);
-
- VirtFsDir::removeFromSearchPathSilent("data/test");
- VirtFsDir::removeFromSearchPathSilent("../data/test");
-
- REQUIRE(VirtFsDir::exists("test") == true);
- REQUIRE(VirtFsDir::exists("test/dir1"));
- REQUIRE(VirtFsDir::exists("test/dir") == false);
- REQUIRE(VirtFsDir::exists("test\\units.xml") == true);
- REQUIRE(VirtFsDir::exists("test/units123.xml") == false);
- REQUIRE(VirtFsDir::exists("tesQ/units.xml") == false);
- REQUIRE(VirtFsDir::exists("units.xml") == false);
-
- REQUIRE_THROWS(VirtFsDir::exists("test/../units.xml"));
-
- VirtFsDir::deinit();
- delete2(logger);
-}
-
-static void removeTemp(StringVect &restrict list)
-{
- int cnt = 0;
- std::sort(list.begin(), list.end());
-
- FOR_EACH (StringVectIter, it, list)
- {
- if (*it != "serverlistplus.xml.part")
- {
- logger->log("file: %d %s",
- cnt,
- (*it).c_str());
- cnt ++;
- }
- }
-
- FOR_EACH (StringVectIter, it, list)
- {
- if (*it == "serverlistplus.xml.part")
- {
- list.erase(it);
- return;
- }
- }
-}
-
-TEST_CASE("VirtFsDir getRealDir")
-{
- VirtFsDir::init(".");
- logger = new Logger();
- REQUIRE(VirtFsDir::getRealDir(".") == "");
- REQUIRE(VirtFsDir::getRealDir("..") == "");
- const bool dir1 = VirtFsDir::addToSearchPathSilent("data",
- Append_false,
- SkipError_false);
- REQUIRE((dir1 || VirtFsDir::addToSearchPathSilent("../data",
- Append_false,
- SkipError_false)) == true);
- if (dir1 == true)
- {
- REQUIRE(VirtFsDir::getRealDir("test") == "data");
- REQUIRE(VirtFsDir::getRealDir("test/test.txt") ==
- "data");
- REQUIRE(VirtFsDir::getRealDir("test\\test.txt") ==
- "data");
- REQUIRE(VirtFsDir::getRealDir("test//test.txt") ==
- "data");
- }
- else
- {
- REQUIRE(VirtFsDir::getRealDir("test") == "../data");
- REQUIRE(VirtFsDir::getRealDir("test/test.txt") ==
- "../data");
- REQUIRE(VirtFsDir::getRealDir("test\\test.txt") ==
- "../data");
- REQUIRE(VirtFsDir::getRealDir("test//test.txt") ==
- "../data");
- }
- REQUIRE(VirtFsDir::getRealDir("zzz") == "");
-
- VirtFsDir::addToSearchPathSilent("data/test",
- Append_false,
- SkipError_false);
- VirtFsDir::addToSearchPathSilent("../data/test",
- Append_false,
- SkipError_false);
- if (dir1 == true)
- {
- REQUIRE(VirtFsDir::getRealDir("test") == "data");
- REQUIRE(VirtFsDir::getRealDir("test/test.txt") ==
- "data");
- REQUIRE(VirtFsDir::getRealDir("test\\test.txt") ==
- "data");
- REQUIRE(VirtFsDir::getRealDir("test.txt") ==
- "data/test");
- }
- else
- {
- REQUIRE(VirtFsDir::getRealDir("test") == "../data");
- REQUIRE(VirtFsDir::getRealDir("test/test.txt") ==
- "../data");
- REQUIRE(VirtFsDir::getRealDir("test\\test.txt") ==
- "../data");
- REQUIRE(VirtFsDir::getRealDir("test.txt") ==
- "../data/test");
- }
- REQUIRE(VirtFsDir::getRealDir("zzz") == "");
-
- VirtFsDir::removeFromSearchPathSilent("data/test");
- VirtFsDir::removeFromSearchPathSilent("../data/test");
-
- if (dir1 == true)
- {
- REQUIRE(VirtFsDir::getRealDir("test") == "data");
- REQUIRE(VirtFsDir::getRealDir("test/test.txt") ==
- "data");
- }
- else
- {
- REQUIRE(VirtFsDir::getRealDir("test") == "../data");
- REQUIRE(VirtFsDir::getRealDir("test/test.txt") ==
- "../data");
- }
- REQUIRE(VirtFsDir::getRealDir("zzz") == "");
-
- VirtFsDir::removeFromSearchPathSilent("data");
- VirtFsDir::removeFromSearchPathSilent("../data");
- VirtFsDir::deinit();
- delete2(logger);
-}
-
-static bool inList(VirtList *list,
- const std::string &name)
-{
- FOR_EACH (StringVectCIter, it, list->names)
- {
- if (*it == name)
- return true;
- }
- return false;
-}
-
-TEST_CASE("VirtFsDir enumerateFiles1")
-{
- VirtFsDir::init(".");
- logger = new Logger;
-
- VirtFsDir::addToSearchPathSilent("data",
- Append_false,
- SkipError_false);
- VirtFsDir::addToSearchPathSilent("../data",
- Append_false,
- SkipError_false);
-
- VirtList *list = nullptr;
-
- const int cnt1 = VirtFsDir::exists("test/test2.txt") ? 28 : 27;
- const int cnt2 = 28;
-
- VirtFsDir::permitLinks(false);
- list = VirtFsDir::enumerateFiles("test");
- removeTemp(list->names);
- const size_t sz = list->names.size();
- REQUIRE(sz == cnt1);
- VirtFsDir::freeList(list);
-
- VirtFsDir::permitLinks(true);
- list = VirtFsDir::enumerateFiles("test/");
- removeTemp(list->names);
- REQUIRE(list->names.size() == cnt2);
- VirtFsDir::freeList(list);
-
- VirtFsDir::permitLinks(true);
- list = VirtFsDir::enumerateFiles("test/units.xml");
- REQUIRE(list->names.size() == 0);
- VirtFsDir::freeList(list);
-
- VirtFsDir::permitLinks(false);
- list = VirtFsDir::enumerateFiles("test\\");
- removeTemp(list->names);
- REQUIRE(list->names.size() == cnt1);
- VirtFsDir::freeList(list);
-
- VirtFsDir::removeFromSearchPathSilent("data");
- VirtFsDir::removeFromSearchPathSilent("../data");
- VirtFsDir::deinit();
- delete2(logger);
-}
-
-TEST_CASE("VirtFsDir enumerateFiles2")
-{
- VirtFsDir::init(".");
- logger = new Logger;
-
- VirtFsDir::addToSearchPathSilent("data/test/dir1",
- Append_false,
- SkipError_false);
- VirtFsDir::addToSearchPathSilent("../data/test/dir1",
- Append_false,
- SkipError_false);
-
- VirtList *list = nullptr;
-
- list = VirtFsDir::enumerateFiles("/");
- const size_t sz = list->names.size();
- REQUIRE(list->names.size() == 5);
- REQUIRE(inList(list, "file1.txt"));
- REQUIRE_FALSE(inList(list, "file2.txt"));
- VirtFsDir::freeList(list);
- VirtFsDir::deinit();
- delete2(logger);
-}
-
-TEST_CASE("VirtFsDir enumerateFiles3")
-{
- VirtFsDir::init(".");
- logger = new Logger;
-
- VirtFsDir::addToSearchPathSilent("data/test/dir1",
- Append_false,
- SkipError_false);
- VirtFsDir::addToSearchPathSilent("../data/test/dir1",
- Append_false,
- SkipError_false);
- VirtFsDir::addToSearchPathSilent("data/test/dir2",
- Append_false,
- SkipError_false);
- VirtFsDir::addToSearchPathSilent("../data/test/dir2",
- Append_false,
- SkipError_false);
-
- VirtList *list = nullptr;
-
- list = VirtFsDir::enumerateFiles("/");
- const size_t sz = list->names.size();
- REQUIRE(list->names.size() == 6);
- REQUIRE(inList(list, "file1.txt"));
- REQUIRE(inList(list, "file2.txt"));
- VirtFsDir::freeList(list);
- VirtFsDir::deinit();
- delete2(logger);
-}
-
-TEST_CASE("VirtFsDir isDirectory")
-{
- VirtFsDir::init(".");
- logger = new Logger();
- VirtFsDir::addToSearchPathSilent("data",
- Append_false,
- SkipError_false);
- VirtFsDir::addToSearchPathSilent("../data",
- Append_false,
- SkipError_false);
-
- REQUIRE(VirtFsDir::isDirectory("test/units.xml") == false);
- REQUIRE(VirtFsDir::isDirectory("test/units.xml/") == false);
- REQUIRE(VirtFsDir::isDirectory("test//units.xml") == false);
- REQUIRE(VirtFsDir::isDirectory("test/units123.xml") == false);
- REQUIRE(VirtFsDir::isDirectory("test//units123.xml") == false);
- REQUIRE(VirtFsDir::isDirectory("tesQ/units.xml") == false);
- REQUIRE(VirtFsDir::isDirectory("tesQ//units.xml") == false);
- REQUIRE(VirtFsDir::isDirectory("units.xml") == false);
- REQUIRE(VirtFsDir::isDirectory("test") == true);
- REQUIRE(VirtFsDir::isDirectory("test/") == true);
- REQUIRE(VirtFsDir::isDirectory("test//") == true);
- REQUIRE(VirtFsDir::isDirectory("test/dir1") == true);
- REQUIRE(VirtFsDir::isDirectory("test//dir1") == true);
- REQUIRE(VirtFsDir::isDirectory("test//dir1/") == true);
- REQUIRE(VirtFsDir::isDirectory("test//dir1//") == true);
- REQUIRE(VirtFsDir::isDirectory("test\\dir1/") == true);
- REQUIRE(VirtFsDir::isDirectory("test/dir1//") == true);
- REQUIRE(VirtFsDir::isDirectory("testQ") == false);
- REQUIRE(VirtFsDir::isDirectory("testQ/") == false);
- REQUIRE(VirtFsDir::isDirectory("testQ//") == false);
-
- VirtFsDir::addToSearchPathSilent("data/test",
- Append_false,
- SkipError_false);
- VirtFsDir::addToSearchPathSilent("../data/test",
- Append_false,
- SkipError_false);
-
- REQUIRE(VirtFsDir::isDirectory("test/units.xml") == false);
- REQUIRE(VirtFsDir::isDirectory("test/units.xml/") == false);
- REQUIRE(VirtFsDir::isDirectory("test//units.xml") == false);
- REQUIRE(VirtFsDir::isDirectory("test/units123.xml") == false);
- REQUIRE(VirtFsDir::isDirectory("tesQ/units.xml") == false);
- REQUIRE(VirtFsDir::isDirectory("units.xml") == false);
- REQUIRE(VirtFsDir::isDirectory("test") == true);
- REQUIRE(VirtFsDir::isDirectory("testQ") == false);
- REQUIRE(VirtFsDir::isDirectory("test/dir1") == true);
- REQUIRE(VirtFsDir::isDirectory("test\\dir1") == true);
-
- VirtFsDir::removeFromSearchPathSilent("data/test");
- VirtFsDir::removeFromSearchPathSilent("../data/test");
-
- REQUIRE(VirtFsDir::isDirectory("test/units.xml") == false);
- REQUIRE(VirtFsDir::isDirectory("test/units123.xml") == false);
- REQUIRE(VirtFsDir::isDirectory("tesQ/units.xml") == false);
- REQUIRE(VirtFsDir::isDirectory("units.xml") == false);
- REQUIRE(VirtFsDir::isDirectory("units.xml/") == false);
- REQUIRE(VirtFsDir::isDirectory("test") == true);
- REQUIRE(VirtFsDir::isDirectory("test/") == true);
- REQUIRE(VirtFsDir::isDirectory("testQ") == false);
- REQUIRE(VirtFsDir::isDirectory("test/dir1") == true);
-
- VirtFsDir::removeFromSearchPathSilent("data");
- VirtFsDir::removeFromSearchPathSilent("../data");
- VirtFsDir::deinit();
- delete2(logger);
-}
-
-TEST_CASE("VirtFsDir openRead")
-{
- VirtFsDir::init(".");
- logger = new Logger();
- VirtFsDir::addToSearchPathSilent("data",
- Append_false,
- SkipError_false);
- VirtFsDir::addToSearchPathSilent("../data",
- Append_false,
- SkipError_false);
-
- VirtFile *file = nullptr;
-
- file = VirtFsDir::openRead("test/units.xml");
- REQUIRE(file != nullptr);
- VirtFsDir::close(file);
- file = VirtFsDir::openRead("test\\units.xml");
- REQUIRE(file != nullptr);
- VirtFsDir::close(file);
- file = VirtFsDir::openRead("test/units123.xml");
- REQUIRE(file == nullptr);
- file = VirtFsDir::openRead("tesQ/units.xml");
- REQUIRE(file == nullptr);
- file = VirtFsDir::openRead("units.xml");
- REQUIRE(file == nullptr);
- file = VirtFsDir::openRead("testQ");
- REQUIRE(file == nullptr);
-
- VirtFsDir::addToSearchPathSilent("data/test",
- Append_false,
- SkipError_false);
- VirtFsDir::addToSearchPathSilent("../data/test",
- Append_false,
- SkipError_false);
-
- file = VirtFsDir::openRead("test/units.xml");
- REQUIRE(file != nullptr);
- VirtFsDir::close(file);
- file = VirtFsDir::openRead("test/units123.xml");
- REQUIRE(file == nullptr);
- file = VirtFsDir::openRead("tesQ/units.xml");
- REQUIRE(file == nullptr);
- file = VirtFsDir::openRead("units.xml");
- REQUIRE(file != nullptr);
- VirtFsDir::close(file);
- file = VirtFsDir::openRead("testQ");
- REQUIRE(file == nullptr);
-
- VirtFsDir::removeFromSearchPathSilent("data/test");
- VirtFsDir::removeFromSearchPathSilent("../data/test");
-
- file = VirtFsDir::openRead("test/units.xml");
- REQUIRE(file != nullptr);
- VirtFsDir::close(file);
- file = VirtFsDir::openRead("test/units123.xml");
- REQUIRE(file == nullptr);
- file = VirtFsDir::openRead("tesQ/units.xml");
- REQUIRE(file == nullptr);
- file = VirtFsDir::openRead("units.xml");
- REQUIRE(file == nullptr);
- file = VirtFsDir::openRead("testQ");
- REQUIRE(file == nullptr);
-
- VirtFsDir::removeFromSearchPathSilent("data");
- VirtFsDir::removeFromSearchPathSilent("../data");
- VirtFsDir::deinit();
- delete2(logger);
-}
-
-
-TEST_CASE("VirtFsDir permitLinks")
-{
- VirtFsDir::init(".");
- logger = new Logger();
- VirtFsDir::addToSearchPathSilent("data",
- Append_false,
- SkipError_false);
- VirtFsDir::addToSearchPathSilent("../data",
- Append_false,
- SkipError_false);
-
- const int cnt1 = VirtFsDir::exists("test/test2.txt") ? 26 : 25;
- const int cnt2 = 26;
-
- StringVect list;
- VirtFsDir::permitLinks(false);
- VirtFsDir::getFiles("test", list);
- removeTemp(list);
- const size_t sz = list.size();
- REQUIRE(sz == cnt1);
-
- list.clear();
- VirtFsDir::permitLinks(true);
- VirtFsDir::getFiles("test", list);
- removeTemp(list);
- REQUIRE(list.size() == cnt2);
-
- list.clear();
- VirtFsDir::permitLinks(false);
- VirtFsDir::getFiles("test", list);
- removeTemp(list);
- REQUIRE(list.size() == cnt1);
-
- VirtFsDir::removeFromSearchPathSilent("data");
- VirtFsDir::removeFromSearchPathSilent("../data");
- VirtFsDir::deinit();
- delete2(logger);
-}
-
-TEST_CASE("VirtFsDir read")
-{
- VirtFsDir::init(".");
- logger = new Logger();
- VirtFsDir::addToSearchPathSilent("data",
- Append_false,
- SkipError_false);
- VirtFsDir::addToSearchPathSilent("../data",
- Append_false,
- SkipError_false);
-
- VirtFile *file = VirtFsDir::openRead("test/test.txt");
- REQUIRE(file != nullptr);
- REQUIRE(VirtFsDir::fileLength(file) == 23);
- const int fileSize = VirtFsDir::fileLength(file);
-
- void *restrict buffer = calloc(fileSize + 1, 1);
- REQUIRE(VirtFsDir::read(file, buffer, 1, fileSize) == fileSize);
- REQUIRE(strcmp(static_cast<char*>(buffer),
- "test line 1\ntest line 2") == 0);
- REQUIRE(VirtFsDir::tell(file) == fileSize);
- REQUIRE(VirtFsDir::eof(file) == true);
-
- free(buffer);
- buffer = calloc(fileSize + 1, 1);
- REQUIRE(VirtFsDir::seek(file, 12) != 0);
- REQUIRE(VirtFsDir::eof(file) == false);
- REQUIRE(VirtFsDir::tell(file) == 12);
- REQUIRE(VirtFsDir::read(file, buffer, 1, 11) == 11);
- REQUIRE(strcmp(static_cast<char*>(buffer),
- "test line 2") == 0);
- REQUIRE(VirtFsDir::eof(file) == true);
-
- VirtFsDir::close(file);
- free(buffer);
-
- VirtFsDir::removeFromSearchPathSilent("data");
- VirtFsDir::removeFromSearchPathSilent("../data");
- VirtFsDir::deinit();
- delete2(logger);
-}
-*/
-#endif // USE_PHYSFS
diff --git a/src/fs/virtfs/virtfszip_unittest.cc b/src/fs/virtfs/virtfszip_unittest.cc
deleted file mode 100644
index 72dc16f64..000000000
--- a/src/fs/virtfs/virtfszip_unittest.cc
+++ /dev/null
@@ -1,753 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2016-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef USE_PHYSFS
-
-#include "catch.hpp"
-
-#include "fs/files.h"
-#include "fs/virtlist.h"
-
-#include "fs/virtfs/virtfszip.h"
-#include "fs/virtfs/virtzipentry.h"
-
-#include "utils/checkutils.h"
-#include "utils/delete2.h"
-
-#include "debug.h"
-/*
-TEST_CASE("VirtFsZip getEntries")
-{
- VirtFsZip::init();
- REQUIRE(VirtFsZip::getEntries().empty());
- REQUIRE(VirtFsZip::searchEntryByArchive("test.zip") == nullptr);
- VirtFsZip::deinit();
-}
-
-TEST_CASE("VirtFsZip addToSearchPath")
-{
- VirtFsZip::init();
- logger = new Logger();
- std::string name("data/test/test.zip");
- std::string prefix("data/test/");
- std::vector<ZipLocalHeader*> headers;
- if (Files::existsLocal(name) == false)
- prefix = "../" + prefix;
-
- SECTION("simple 1")
- {
- REQUIRE(VirtFsZip::addToSearchPathSilent(prefix + "/test.zip",
- Append_false));
- REQUIRE(VirtFsZip::searchEntryByArchive(
- prefix + "test.zip") != nullptr);
- REQUIRE(VirtFsZip::searchEntryByArchive(
- prefix + "file2.zip") == nullptr);
- REQUIRE(VirtFsZip::getEntries().size() == 1);
- REQUIRE(VirtFsZip::getEntries()[0]->root ==
- prefix + "test.zip");
- }
-
- SECTION("simple 2")
- {
- REQUIRE(VirtFsZip::addToSearchPathSilent(prefix + "\\test.zip",
- Append_true));
- REQUIRE(VirtFsZip::searchEntryByArchive(
- prefix + "test.zip") != nullptr);
- REQUIRE(VirtFsZip::searchEntryByArchive(
- prefix + "file2.zip") == nullptr);
- REQUIRE(VirtFsZip::getEntries().size() == 1);
- REQUIRE(VirtFsZip::getEntries()[0]->root ==
- prefix + "test.zip");
- }
-
- SECTION("simple 3")
- {
- REQUIRE(VirtFsZip::addToSearchPathSilent(prefix + "test.zip",
- Append_false));
- REQUIRE(VirtFsZip::addToSearchPathSilent(prefix + "test2.zip",
- Append_false));
- REQUIRE(VirtFsZip::searchEntryByArchive(
- prefix + "test.zip") != nullptr);
- REQUIRE(VirtFsZip::searchEntryByArchive(
- prefix + "test2.zip") != nullptr);
- REQUIRE(VirtFsZip::searchEntryByArchive(
- prefix + "test3.zip") == nullptr);
- REQUIRE(VirtFsZip::getEntries().size() == 2);
- REQUIRE(VirtFsZip::getEntries()[0]->root ==
- prefix + "test2.zip");
- REQUIRE(VirtFsZip::getEntries()[1]->root ==
- prefix + "test.zip");
- }
-
- SECTION("simple 4")
- {
- REQUIRE(VirtFsZip::addToSearchPathSilent(prefix + "test.zip",
- Append_true));
- REQUIRE(VirtFsZip::addToSearchPathSilent(prefix + "test2.zip",
- Append_true));
- REQUIRE(VirtFsZip::searchEntryByArchive(
- prefix + "test.zip") != nullptr);
- REQUIRE(VirtFsZip::searchEntryByArchive(
- prefix + "test2.zip") != nullptr);
- REQUIRE(VirtFsZip::searchEntryByArchive(
- prefix + "test3.zip") == nullptr);
- REQUIRE(VirtFsZip::getEntries().size() == 2);
- REQUIRE(VirtFsZip::getEntries()[0]->root ==
- prefix + "test.zip");
- REQUIRE(VirtFsZip::getEntries()[1]->root ==
- prefix + "test2.zip");
- }
-
- SECTION("simple 5")
- {
- REQUIRE(VirtFsZip::addToSearchPathSilent(prefix + "test.zip",
- Append_true));
- REQUIRE(VirtFsZip::addToSearchPathSilent(prefix + "test2.zip",
- Append_true));
- REQUIRE(VirtFsZip::addToSearchPathSilent(prefix + "test3.zip",
- Append_true));
- REQUIRE(VirtFsZip::searchEntryByArchive(
- prefix + "test.zip") != nullptr);
- REQUIRE(VirtFsZip::searchEntryByArchive(
- prefix + "test2.zip") != nullptr);
- REQUIRE(VirtFsZip::searchEntryByArchive(
- prefix + "test3.zip") != nullptr);
- REQUIRE(VirtFsZip::searchEntryByArchive(
- prefix + "test4.zip") == nullptr);
- REQUIRE(VirtFsZip::getEntries().size() == 3);
- REQUIRE(VirtFsZip::getEntries()[0]->root ==
- prefix + "test.zip");
- REQUIRE(VirtFsZip::getEntries()[1]->root ==
- prefix + "test2.zip");
- REQUIRE(VirtFsZip::getEntries()[2]->root ==
- prefix + "test3.zip");
- }
-
- SECTION("simple 6")
- {
- REQUIRE(VirtFsZip::addToSearchPathSilent(prefix + "test.zip",
- Append_true));
- REQUIRE(VirtFsZip::addToSearchPathSilent(prefix + "test2.zip",
- Append_true));
- REQUIRE(VirtFsZip::addToSearchPathSilent(prefix + "test3.zip",
- Append_false));
- REQUIRE(VirtFsZip::searchEntryByArchive(
- prefix + "test.zip") != nullptr);
- REQUIRE(VirtFsZip::searchEntryByArchive(
- prefix + "test2.zip") != nullptr);
- REQUIRE(VirtFsZip::searchEntryByArchive(
- prefix + "test3.zip") != nullptr);
- REQUIRE(VirtFsZip::searchEntryByArchive(
- prefix + "test4.zip") == nullptr);
- REQUIRE(VirtFsZip::getEntries().size() == 3);
- REQUIRE(VirtFsZip::getEntries()[0]->root ==
- prefix + "test3.zip");
- REQUIRE(VirtFsZip::getEntries()[1]->root ==
- prefix + "test.zip");
- REQUIRE(VirtFsZip::getEntries()[2]->root ==
- prefix + "test2.zip");
- }
-
- VirtFsZip::deinit();
- delete2(logger);
-}
-
-TEST_CASE("VirtFsZip removeFromSearchPath")
-{
- VirtFsZip::init();
- logger = new Logger();
- std::string name("data/test/test.zip");
- std::string prefix("data/test/");
- std::vector<ZipLocalHeader*> headers;
- if (Files::existsLocal(name) == false)
- prefix = "../" + prefix;
-
- SECTION("simple 1")
- {
- REQUIRE_THROWS(VirtFsZip::removeFromSearchPath(
- prefix + "test123.zip"));
- }
-
- SECTION("simple 2")
- {
- REQUIRE(VirtFsZip::addToSearchPathSilent(prefix + "test.zip",
- Append_true));
- REQUIRE_THROWS(VirtFsZip::removeFromSearchPath(prefix + "test2.zip"));
- REQUIRE(VirtFsZip::removeFromSearchPath(prefix + "test.zip"));
- }
-
- SECTION("simple 3")
- {
- REQUIRE(VirtFsZip::addToSearchPathSilent(prefix + "test.zip",
- Append_true));
- REQUIRE(VirtFsZip::addToSearchPathSilent(prefix + "test2.zip",
- Append_true));
- REQUIRE(VirtFsZip::addToSearchPathSilent(prefix + "test3.zip",
- Append_false));
- REQUIRE(VirtFsZip::getEntries().size() == 3);
- REQUIRE_THROWS(VirtFsZip::removeFromSearchPath(prefix + "test4.zip"));
- REQUIRE(VirtFsZip::removeFromSearchPath(prefix + "test.zip"));
- REQUIRE(VirtFsZip::getEntries().size() == 2);
- REQUIRE(VirtFsZip::getEntries()[0]->root ==
- prefix + "test3.zip");
- REQUIRE(VirtFsZip::getEntries()[1]->root ==
- prefix + "test2.zip");
- REQUIRE_THROWS(VirtFsZip::removeFromSearchPath(prefix + "test.zip"));
- REQUIRE(VirtFsZip::getEntries().size() == 2);
- REQUIRE(VirtFsZip::getEntries()[0]->root ==
- prefix + "test3.zip");
- REQUIRE(VirtFsZip::getEntries()[1]->root ==
- prefix + "test2.zip");
- REQUIRE(VirtFsZip::removeFromSearchPath(prefix + "//test2.zip"));
- REQUIRE_THROWS(VirtFsZip::removeFromSearchPath(prefix + "test2.zip"));
- REQUIRE(VirtFsZip::getEntries().size() == 1);
- REQUIRE(VirtFsZip::getEntries()[0]->root ==
- prefix + "test3.zip");
- }
-
- SECTION("simple 4")
- {
- REQUIRE(VirtFsZip::addToSearchPathSilent(prefix + "\\test.zip",
- Append_true));
- REQUIRE(VirtFsZip::getEntries().size() == 1);
- REQUIRE(VirtFsZip::getEntries()[0]->root ==
- prefix + "test.zip");
- REQUIRE_THROWS(VirtFsZip::removeFromSearchPath(prefix + "test2.zip"));
- REQUIRE(VirtFsZip::removeFromSearchPath(prefix + "\\test.zip"));
- REQUIRE(VirtFsZip::getEntries().size() == 0);
- REQUIRE(VirtFsZip::addToSearchPathSilent(prefix + "test.zip",
- Append_true));
- REQUIRE(VirtFsZip::getEntries().size() == 1);
- REQUIRE(VirtFsZip::getEntries()[0]->root ==
- prefix + "test.zip");
- }
-
- VirtFsZip::deinit();
- delete2(logger);
-}
-
-TEST_CASE("VirtFsZip exists")
-{
- VirtFsZip::init();
- logger = new Logger();
- VirtFsZip::addToSearchPathSilent("data\\test/test2.zip",
- Append_false);
- VirtFsZip::addToSearchPathSilent("../data\\test/test2.zip",
- Append_false);
-
- REQUIRE(VirtFsZip::exists("dir2//units.xml") == true);
- REQUIRE(VirtFsZip::exists("test/units123.xml") == false);
- REQUIRE(VirtFsZip::exists("tesQ/units.xml") == false);
- REQUIRE(VirtFsZip::exists("units1.xml") == false);
- REQUIRE(VirtFsZip::exists("dir/hide.png") == true);
- REQUIRE(VirtFsZip::exists("dir/brimmedhat.png") == false);
- REQUIRE(VirtFsZip::exists("dir\\1"));
-
- VirtFsZip::addToSearchPathSilent("data/test/test.zip",
- Append_false);
- VirtFsZip::addToSearchPathSilent("../data/test/test.zip",
- Append_false);
-
- REQUIRE(VirtFsZip::exists("dir2\\units.xml") == true);
- REQUIRE(VirtFsZip::exists("test/units123.xml") == false);
- REQUIRE(VirtFsZip::exists("tesQ/units.xml") == false);
- REQUIRE(VirtFsZip::exists("units1.xml") == false);
- REQUIRE(VirtFsZip::exists("dir/hide.png") == true);
- REQUIRE(VirtFsZip::exists("dir/brimmedhat.png") == true);
- REQUIRE(VirtFsZip::exists("dir\\1"));
-
- VirtFsZip::removeFromSearchPathSilent("data/test/test2.zip");
- VirtFsZip::removeFromSearchPathSilent("../data/test/test2.zip");
-
- REQUIRE(VirtFsZip::exists("dir2//units.xml") == false);
- REQUIRE(VirtFsZip::exists("test/units123.xml") == false);
- REQUIRE(VirtFsZip::exists("tesQ/units.xml") == false);
- REQUIRE(VirtFsZip::exists("units1.xml") == false);
- REQUIRE(VirtFsZip::exists("dir/\\/hide.png") == true);
- REQUIRE(VirtFsZip::exists("dir/brimmedhat.png") == true);
- REQUIRE(VirtFsZip::exists("dir\\1") == false);
-
- REQUIRE_THROWS(VirtFsZip::exists("test/../units.xml"));
-
- VirtFsZip::deinit();
- delete2(logger);
-}
-
-TEST_CASE("VirtFsZip getRealDir")
-{
- VirtFsZip::init();
- logger = new Logger();
- std::string name("data/test/test.zip");
- std::string prefix("data/test/");
- if (Files::existsLocal(name) == false)
- prefix = "../" + prefix;
- VirtFsZip::addToSearchPathSilent(prefix + "test2.zip",
- Append_false);
-
- REQUIRE(VirtFsZip::getRealDir(".") == "");
- REQUIRE(VirtFsZip::getRealDir("..") == "");
- REQUIRE(VirtFsZip::getRealDir("test.txt") == prefix + "test2.zip");
- REQUIRE(VirtFsZip::getRealDir("dir/1") == prefix + "test2.zip");
- REQUIRE(VirtFsZip::getRealDir("dir\\dye.png") ==
- prefix + "test2.zip");
- REQUIRE(VirtFsZip::getRealDir("zzz") == "");
-
- VirtFsZip::addToSearchPathSilent(prefix + "test.zip",
- Append_false);
- REQUIRE(VirtFsZip::getRealDir("dir//dye.png") ==
- prefix + "test2.zip");
- REQUIRE(VirtFsZip::getRealDir("dir///hide.png") ==
- prefix + "test.zip");
- REQUIRE(VirtFsZip::getRealDir("dir\\\\brimmedhat.png") ==
- prefix + "test.zip");
- REQUIRE(VirtFsZip::getRealDir("zzz") == "");
-
- VirtFsZip::removeFromSearchPathSilent(prefix + "test.zip");
-
- REQUIRE(VirtFsZip::getRealDir("dir/brimmedhat.png") == "");
- REQUIRE(VirtFsZip::getRealDir("test.txt") == prefix + "test2.zip");
- REQUIRE(VirtFsZip::getRealDir("dir//dye.png") ==
- prefix + "test2.zip");
- REQUIRE(VirtFsZip::getRealDir("zzz") == "");
-
- VirtFsZip::removeFromSearchPathSilent(prefix + "test2.zip");
- VirtFsZip::deinit();
- delete2(logger);
-}
-
-static bool inList(VirtList *list,
- const std::string &name)
-{
- FOR_EACH (StringVectCIter, it, list->names)
- {
- if (*it == name)
- return true;
- }
- return false;
-}
-
-TEST_CASE("VirtFsZip enumerateFiles1")
-{
- VirtFsZip::init();
- logger = new Logger;
- std::string name("data/test/test.zip");
- std::string prefix("data\\test/");
- if (Files::existsLocal(name) == false)
- prefix = "../" + prefix;
-
- VirtFsZip::addToSearchPathSilent(prefix + "test.zip",
- Append_false);
-
- VirtList *list = nullptr;
-
- list = VirtFsZip::enumerateFiles("dir");
- REQUIRE(list->names.size() == 2);
- REQUIRE(inList(list, "brimmedhat.png"));
- REQUIRE(inList(list, "hide.png"));
- VirtFsZip::freeList(list);
-
- VirtFsZip::removeFromSearchPathSilent(prefix + "test.zip");
- VirtFsZip::deinit();
- delete2(logger);
-}
-
-TEST_CASE("VirtFsZip enumerateFiles2")
-{
- VirtFsZip::init();
- logger = new Logger;
- std::string name("data/test/test.zip");
- std::string prefix("data//test/");
- if (Files::existsLocal(name) == false)
- prefix = "../" + prefix;
-
- VirtFsZip::addToSearchPathSilent(prefix + "test.zip",
- Append_true);
- VirtFsZip::addToSearchPathSilent(prefix + "test2.zip",
- Append_true);
-
- VirtList *list = nullptr;
-
- list = VirtFsZip::enumerateFiles("dir");
- FOR_EACH (StringVectCIter, it, list->names)
- {
- logger->log("filename: " + *it);
- }
-
- REQUIRE(list->names.size() == 5);
- REQUIRE(inList(list, "brimmedhat.png"));
- REQUIRE(inList(list, "hide.png"));
- REQUIRE(inList(list, "1"));
- REQUIRE(inList(list, "gpl"));
- REQUIRE(inList(list, "dye.png"));
- VirtFsZip::freeList(list);
-
- VirtFsZip::removeFromSearchPathSilent(prefix + "test.zip");
- VirtFsZip::removeFromSearchPathSilent(prefix + "test2.zip");
- VirtFsZip::deinit();
- delete2(logger);
-}
-
-TEST_CASE("VirtFsZip enumerateFiles3")
-{
- VirtFsZip::init();
- logger = new Logger;
- std::string name("data/test/test.zip");
- std::string prefix("data\\test/");
- if (Files::existsLocal(name) == false)
- prefix = "../" + prefix;
-
- VirtFsZip::addToSearchPathSilent(prefix + "test.zip",
- Append_false);
-
- VirtList *list = nullptr;
-
- list = VirtFsZip::enumerateFiles("/");
- REQUIRE(list->names.size() == 1);
- REQUIRE(inList(list, "dir"));
- VirtFsZip::freeList(list);
-
- VirtFsZip::removeFromSearchPathSilent(prefix + "test.zip");
- VirtFsZip::deinit();
- delete2(logger);
-}
-
-TEST_CASE("VirtFsZip enumerateFiles4")
-{
- VirtFsZip::init();
- logger = new Logger;
- std::string name("data/test/test.zip");
- std::string prefix("data\\test/");
- if (Files::existsLocal(name) == false)
- prefix = "../" + prefix;
-
- VirtFsZip::addToSearchPathSilent(prefix + "test2.zip",
- Append_false);
-
- VirtList *list = nullptr;
-
- list = VirtFsZip::enumerateFiles("/");
- REQUIRE(list->names.size() == 4);
- REQUIRE(inList(list, "dir"));
- REQUIRE(inList(list, "dir2"));
- REQUIRE(inList(list, "test.txt"));
- REQUIRE(inList(list, "units.xml"));
- VirtFsZip::freeList(list);
-
- VirtFsZip::removeFromSearchPathSilent(prefix + "test2.zip");
- VirtFsZip::deinit();
- delete2(logger);
-}
-
-TEST_CASE("VirtFsZip isDirectory")
-{
- VirtFsZip::init();
- logger = new Logger();
- std::string name("data/test/test.zip");
- std::string prefix("data/test/");
- if (Files::existsLocal(name) == false)
- prefix = "../" + prefix;
-
- VirtFsZip::addToSearchPathSilent(prefix + "test2.zip",
- Append_false);
-
- REQUIRE(VirtFsZip::isDirectory("dir2/units.xml") == false);
- REQUIRE(VirtFsZip::isDirectory("dir2/units.xml/") == false);
- REQUIRE(VirtFsZip::isDirectory("dir2//units.xml") == false);
- REQUIRE(VirtFsZip::isDirectory("dir2/units123.xml") == false);
- REQUIRE(VirtFsZip::isDirectory("dir2//units123.xml") == false);
- REQUIRE(VirtFsZip::isDirectory("tesQ/units.xml") == false);
- REQUIRE(VirtFsZip::isDirectory("tesQ//units.xml") == false);
- REQUIRE(VirtFsZip::isDirectory("units.xml") == false);
- REQUIRE(VirtFsZip::isDirectory("dir") == true);
- REQUIRE(VirtFsZip::isDirectory("dir2/") == true);
- REQUIRE(VirtFsZip::isDirectory("dir2//") == true);
- REQUIRE(VirtFsZip::isDirectory("dir/1") == true);
- REQUIRE(VirtFsZip::isDirectory("dir//1") == true);
- REQUIRE(VirtFsZip::isDirectory("dir\\1/") == true);
- REQUIRE(VirtFsZip::isDirectory("dir/1") == true);
- REQUIRE(VirtFsZip::isDirectory("dir/1/zzz") == false);
- REQUIRE(VirtFsZip::isDirectory("test/dir1\\") == false);
- REQUIRE(VirtFsZip::isDirectory("testQ") == false);
- REQUIRE(VirtFsZip::isDirectory("testQ/") == false);
- REQUIRE(VirtFsZip::isDirectory("testQ//") == false);
-
- VirtFsZip::addToSearchPathSilent(prefix + "test.zip",
- Append_false);
-
- REQUIRE(VirtFsZip::isDirectory("dir2/units.xml") == false);
- REQUIRE(VirtFsZip::isDirectory("dir2/units.xml/") == false);
- REQUIRE(VirtFsZip::isDirectory("dir2\\units.xml") == false);
- REQUIRE(VirtFsZip::isDirectory("dir2/units123.xml") == false);
- REQUIRE(VirtFsZip::isDirectory("dir2//units123.xml") == false);
- REQUIRE(VirtFsZip::isDirectory("tesQ/units.xml") == false);
- REQUIRE(VirtFsZip::isDirectory("tesQ//units.xml") == false);
- REQUIRE(VirtFsZip::isDirectory("units.xml") == false);
- REQUIRE(VirtFsZip::isDirectory("dir") == true);
- REQUIRE(VirtFsZip::isDirectory("dir2/") == true);
- REQUIRE(VirtFsZip::isDirectory("dir2\\") == true);
- REQUIRE(VirtFsZip::isDirectory("dir/1") == true);
- REQUIRE(VirtFsZip::isDirectory("dir//1") == true);
- REQUIRE(VirtFsZip::isDirectory("dir//1/") == true);
- REQUIRE(VirtFsZip::isDirectory("dir/1") == true);
- REQUIRE(VirtFsZip::isDirectory("dir/1/zzz") == false);
- REQUIRE(VirtFsZip::isDirectory("test/dir1//") == false);
- REQUIRE(VirtFsZip::isDirectory("testQ") == false);
- REQUIRE(VirtFsZip::isDirectory("testQ/") == false);
- REQUIRE(VirtFsZip::isDirectory("testQ//") == false);
-
- VirtFsZip::removeFromSearchPathSilent(prefix + "test2.zip");
-
- REQUIRE(VirtFsZip::isDirectory("dir2/units.xml") == false);
- REQUIRE(VirtFsZip::isDirectory("dir2/units.xml/") == false);
- REQUIRE(VirtFsZip::isDirectory("dir2//units.xml") == false);
- REQUIRE(VirtFsZip::isDirectory("dir2/units123.xml") == false);
- REQUIRE(VirtFsZip::isDirectory("dir2//units123.xml") == false);
- REQUIRE(VirtFsZip::isDirectory("tesQ/units.xml") == false);
- REQUIRE(VirtFsZip::isDirectory("tesQ//units.xml") == false);
- REQUIRE(VirtFsZip::isDirectory("units.xml") == false);
- REQUIRE(VirtFsZip::isDirectory("dir") == true);
- REQUIRE(VirtFsZip::isDirectory("dir2/") == false);
- REQUIRE(VirtFsZip::isDirectory("dir2//") == false);
- REQUIRE(VirtFsZip::isDirectory("dir/1") == false);
- REQUIRE(VirtFsZip::isDirectory("dir\\1") == false);
- REQUIRE(VirtFsZip::isDirectory("dir//1/") == false);
- REQUIRE(VirtFsZip::isDirectory("dir/1") == false);
- REQUIRE(VirtFsZip::isDirectory("dir/1/zzz") == false);
- REQUIRE(VirtFsZip::isDirectory("test/dir1//") == false);
- REQUIRE(VirtFsZip::isDirectory("testQ") == false);
- REQUIRE(VirtFsZip::isDirectory("testQ/") == false);
- REQUIRE(VirtFsZip::isDirectory("testQ//") == false);
-
- VirtFsZip::removeFromSearchPathSilent(prefix + "test.zip");
- VirtFsZip::deinit();
- delete2(logger);
-}
-
-TEST_CASE("VirtFsZip openRead")
-{
- VirtFsZip::init();
- logger = new Logger();
- std::string name("data/test/test.zip");
- std::string prefix("data/test/");
- if (Files::existsLocal(name) == false)
- prefix = "../" + prefix;
-
- VirtFsZip::addToSearchPathSilent(prefix + "test2.zip",
- Append_false);
-
- VirtFile *file = nullptr;
-
- file = VirtFsZip::openRead("dir2/units.xml");
- REQUIRE(file != nullptr);
- VirtFsZip::close(file);
- file = VirtFsZip::openRead("dir2\\units.xml");
- REQUIRE(file != nullptr);
- VirtFsZip::close(file);
- file = VirtFsZip::openRead("dir2/units123.xml");
- REQUIRE(file == nullptr);
- file = VirtFsZip::openRead("tesQ/units.xml");
- REQUIRE(file == nullptr);
- file = VirtFsZip::openRead("units.xml1");
- REQUIRE(file == nullptr);
- file = VirtFsZip::openRead("testQ");
- REQUIRE(file == nullptr);
- file = VirtFsZip::openRead("dir/brimmedhat.png");
- REQUIRE(file == nullptr);
- file = VirtFsZip::openRead("dir//brimmedhat.png");
- REQUIRE(file == nullptr);
-
- VirtFsZip::addToSearchPathSilent(prefix + "test.zip",
- Append_false);
-
- file = VirtFsZip::openRead("dir2/units.xml");
- REQUIRE(file != nullptr);
- VirtFsZip::close(file);
- file = VirtFsZip::openRead("dir2//units.xml");
- REQUIRE(file != nullptr);
- VirtFsZip::close(file);
- file = VirtFsZip::openRead("dir2/units123.xml");
- REQUIRE(file == nullptr);
- file = VirtFsZip::openRead("tesQ/units.xml");
- REQUIRE(file == nullptr);
- file = VirtFsZip::openRead("units.xml1");
- REQUIRE(file == nullptr);
- file = VirtFsZip::openRead("testQ");
- REQUIRE(file == nullptr);
- file = VirtFsZip::openRead("dir/brimmedhat.png");
- REQUIRE(file != nullptr);
- VirtFsZip::close(file);
-
- VirtFsZip::removeFromSearchPathSilent(prefix + "test.zip");
-
- file = VirtFsZip::openRead("dir2/units.xml");
- REQUIRE(file != nullptr);
- VirtFsZip::close(file);
- file = VirtFsZip::openRead("dir2\\/\\units.xml");
- REQUIRE(file != nullptr);
- VirtFsZip::close(file);
- file = VirtFsZip::openRead("dir2/units123.xml");
- REQUIRE(file == nullptr);
- file = VirtFsZip::openRead("tesQ/units.xml");
- REQUIRE(file == nullptr);
- file = VirtFsZip::openRead("units.xml1");
- REQUIRE(file == nullptr);
- file = VirtFsZip::openRead("testQ");
- REQUIRE(file == nullptr);
- file = VirtFsZip::openRead("dir/brimmedhat.png");
- REQUIRE(file == nullptr);
-
- VirtFsZip::removeFromSearchPathSilent(prefix + "test2.zip");
-
- VirtFsZip::deinit();
- delete2(logger);
-}
-
-TEST_CASE("VirtFsZip read")
-{
- VirtFsZip::init();
- logger = new Logger();
- std::string name("data/test/test.zip");
- std::string prefix("data/test/");
- if (Files::existsLocal(name) == false)
- prefix = "../" + prefix;
-
- VirtFsZip::addToSearchPathSilent(prefix + "test2.zip",
- Append_false);
- VirtFile *file = nullptr;
- void *restrict buffer = nullptr;
-
- SECTION("test 1")
- {
- file = VirtFsZip::openRead("dir2//test.txt");
- REQUIRE(file != nullptr);
- REQUIRE(VirtFsZip::fileLength(file) == 23);
- const int fileSize = VirtFsZip::fileLength(file);
-
- buffer = calloc(fileSize + 1, 1);
- REQUIRE(VirtFsZip::read(file, buffer, 1, fileSize) == fileSize);
- REQUIRE(strcmp(static_cast<char*>(buffer),
- "test line 1\ntest line 2") == 0);
- REQUIRE(VirtFsZip::tell(file) == fileSize);
- REQUIRE(VirtFsZip::eof(file) == true);
- }
-
- SECTION("test 2")
- {
- file = VirtFsZip::openRead("dir2\\/test.txt");
- REQUIRE(file != nullptr);
- REQUIRE(VirtFsZip::fileLength(file) == 23);
- const int fileSize = VirtFsZip::fileLength(file);
-
- buffer = calloc(fileSize + 1, 1);
- REQUIRE(VirtFsZip::seek(file, 12) != 0);
- REQUIRE(VirtFsZip::eof(file) == false);
- REQUIRE(VirtFsZip::tell(file) == 12);
- REQUIRE(VirtFsZip::read(file, buffer, 1, 11) == 11);
- REQUIRE(strcmp(static_cast<char*>(buffer),
- "test line 2") == 0);
- REQUIRE(VirtFsZip::eof(file) == true);
- }
-
- SECTION("test 3")
- {
- file = VirtFsZip::openRead("dir2//test.txt");
- REQUIRE(file != nullptr);
- const int fileSize = VirtFsZip::fileLength(file);
-
- buffer = calloc(fileSize + 1, 1);
- for (int f = 0; f < fileSize; f ++)
- {
- REQUIRE(VirtFsZip::seek(file, f) != 0);
- REQUIRE(VirtFsZip::eof(file) == false);
- REQUIRE(VirtFsZip::tell(file) == f);
- }
- }
-
- SECTION("test 4")
- {
- file = VirtFsZip::openRead("dir2/test.txt");
- REQUIRE(file != nullptr);
- const int fileSize = VirtFsZip::fileLength(file);
- const char *restrict const str = "test line 1\ntest line 2";
- buffer = calloc(fileSize + 1, 1);
- for (int f = 0; f < fileSize - 1; f ++)
- {
- REQUIRE(VirtFsZip::read(file, buffer, 1, 1) == 1);
- REQUIRE(static_cast<char*>(buffer)[0] == str[f]);
- REQUIRE(VirtFsZip::eof(file) == false);
- REQUIRE(VirtFsZip::tell(file) == f + 1);
- }
- REQUIRE(VirtFsZip::read(file, buffer, 1, 1) == 1);
- REQUIRE(static_cast<char*>(buffer)[0] == str[22]);
- REQUIRE(VirtFsZip::eof(file) == true);
- REQUIRE(VirtFsZip::tell(file) == fileSize);
- }
-
- SECTION("test 5")
- {
- file = VirtFsZip::openRead("dir2\\\\test.txt");
- REQUIRE(file != nullptr);
- const int fileSize = VirtFsZip::fileLength(file);
- const char *restrict const str = "test line 1\ntest line 2";
- buffer = calloc(fileSize + 1, 1);
- for (int f = 0; f < fileSize - 1; f += 2)
- {
- REQUIRE(VirtFsZip::read(file, buffer, 2, 1) == 1);
- REQUIRE(static_cast<char*>(buffer)[0] == str[f]);
- REQUIRE(static_cast<char*>(buffer)[1] == str[f + 1]);
- REQUIRE(VirtFsZip::eof(file) == false);
- REQUIRE(VirtFsZip::tell(file) == f + 2);
- }
- REQUIRE(VirtFsZip::eof(file) == false);
- REQUIRE(VirtFsZip::tell(file) == 22);
- REQUIRE(VirtFsZip::read(file, buffer, 2, 1) == 0);
- REQUIRE(VirtFsZip::eof(file) == false);
- }
-
- SECTION("test 6")
- {
- file = VirtFsZip::openRead("dir2//test.txt");
- REQUIRE(file != nullptr);
- const int fileSize = VirtFsZip::fileLength(file);
- const char *restrict const str = "test line 1\ntest line 2";
- buffer = calloc(fileSize + 1, 1);
- for (int f = 0; f < fileSize - 1; f += 2)
- {
- REQUIRE(VirtFsZip::read(file, buffer, 1, 2) == 2);
- REQUIRE(static_cast<char*>(buffer)[0] == str[f]);
- REQUIRE(static_cast<char*>(buffer)[1] == str[f + 1]);
- REQUIRE(VirtFsZip::eof(file) == false);
- REQUIRE(VirtFsZip::tell(file) == f + 2);
- }
- REQUIRE(VirtFsZip::eof(file) == false);
- REQUIRE(VirtFsZip::tell(file) == 22);
- REQUIRE(VirtFsZip::read(file, buffer, 1, 2) == 1);
- REQUIRE(static_cast<char*>(buffer)[0] == str[22]);
- REQUIRE(VirtFsZip::eof(file) == true);
- }
-
- VirtFsZip::close(file);
- free(buffer);
- VirtFsZip::removeFromSearchPathSilent(prefix + "test2.zip");
- VirtFsZip::deinit();
- delete2(logger);
-}
-*/
-#endif // USE_PHYSFS