From 495110a8cb407548e227b062f6446b8eaa9605d0 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 10 Oct 2017 18:21:02 +0300 Subject: Split unit tests for mount dir and mount zip into separate files. --- src/Makefile.am | 6 +- src/unittests/fs/virtfs/virtfs1_mountdir.cc | 471 --------------------------- src/unittests/fs/virtfs/virtfs1_mountdir1.cc | 195 +++++++++++ src/unittests/fs/virtfs/virtfs1_mountdir2.cc | 315 ++++++++++++++++++ src/unittests/fs/virtfs/virtfs1_mountzip.cc | 329 ------------------- src/unittests/fs/virtfs/virtfs1_mountzip1.cc | 173 ++++++++++ src/unittests/fs/virtfs/virtfs1_mountzip2.cc | 202 ++++++++++++ 7 files changed, 889 insertions(+), 802 deletions(-) delete mode 100644 src/unittests/fs/virtfs/virtfs1_mountdir.cc create mode 100644 src/unittests/fs/virtfs/virtfs1_mountdir1.cc create mode 100644 src/unittests/fs/virtfs/virtfs1_mountdir2.cc delete mode 100644 src/unittests/fs/virtfs/virtfs1_mountzip.cc create mode 100644 src/unittests/fs/virtfs/virtfs1_mountzip1.cc create mode 100644 src/unittests/fs/virtfs/virtfs1_mountzip2.cc diff --git a/src/Makefile.am b/src/Makefile.am index d46a76cad..7f22f0507 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2091,8 +2091,10 @@ manaplustests_SOURCES += \ unittests/fs/virtfs/virtfs1_enumerate.cc \ unittests/fs/virtfs/virtfs1_exists.cc \ unittests/fs/virtfs/virtfs1_getrealdir.cc \ - unittests/fs/virtfs/virtfs1_mountdir.cc \ - unittests/fs/virtfs/virtfs1_mountzip.cc \ + unittests/fs/virtfs/virtfs1_mountdir1.cc \ + unittests/fs/virtfs/virtfs1_mountdir2.cc \ + unittests/fs/virtfs/virtfs1_mountzip1.cc \ + unittests/fs/virtfs/virtfs1_mountzip2.cc \ unittests/fs/virtfs/virtfs1_unmount.cc \ unittests/fs/virtfs/virtfs2.cc \ unittests/fs/virtfs/zip.cc \ diff --git a/src/unittests/fs/virtfs/virtfs1_mountdir.cc b/src/unittests/fs/virtfs/virtfs1_mountdir.cc deleted file mode 100644 index a4a9dd648..000000000 --- a/src/unittests/fs/virtfs/virtfs1_mountdir.cc +++ /dev/null @@ -1,471 +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 . - */ - -#include "unittests/unittests.h" - -#include "fs/virtfs/direntry.h" -#include "fs/virtfs/fs.h" - -#include "utils/checkutils.h" - -#ifndef UNITTESTS_CATCH -#include -#endif // UNITTESTS_CATCH - -#include "debug.h" - -TEST_CASE("VirtFs1 mountDir", "") -{ - VirtFs::init("."); - const std::string sep = dirSeparator; - SECTION("simple 1") - { - REQUIRE(VirtFs::mountDirSilentTest("dir1", - Append_false)); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1") == - nullptr); - REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) == - nullptr); - REQUIRE(VirtFs::getEntries().size() == 1); - REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep); - REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); - REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); - REQUIRE(static_cast( - VirtFs::getEntries()[0])->userDir == "dir1"); - } - - SECTION("simple 2") - { - REQUIRE(VirtFs::mountDirSilentTest("dir1/", - Append_true)); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1") == - nullptr); - REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) == - nullptr); - REQUIRE(VirtFs::getEntries().size() == 1); - REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep); - REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); - REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); - REQUIRE(static_cast( - VirtFs::getEntries()[0])->userDir == "dir1" + sep); - } - - SECTION("simple 3") - { - REQUIRE(VirtFs::mountDirSilentTest("dir1", - Append_false)); - REQUIRE(VirtFs::mountDirSilentTest("dir2", - Append_false)); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1") == - nullptr); - REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, std::string()) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) == - nullptr); - REQUIRE(VirtFs::getEntries().size() == 2); - 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(VirtFs::getEntries()[0]->subDir.empty()); - REQUIRE(VirtFs::getEntries()[1]->subDir.empty()); - REQUIRE(static_cast( - VirtFs::getEntries()[0])->userDir == "dir2"); - REQUIRE(static_cast( - VirtFs::getEntries()[1])->userDir == "dir1"); - } - - SECTION("simple 4") - { - REQUIRE(VirtFs::mountDirSilentTest("dir1\\", - Append_true)); - REQUIRE(VirtFs::mountDirSilentTest("dir2", - Append_true)); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, std::string()) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) == - nullptr); - REQUIRE(VirtFs::getEntries().size() == 2); - 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(VirtFs::getEntries()[0]->subDir.empty()); - REQUIRE(VirtFs::getEntries()[1]->subDir.empty()); - REQUIRE(static_cast( - VirtFs::getEntries()[0])->userDir == "dir1" + sep); - REQUIRE(static_cast( - VirtFs::getEntries()[1])->userDir == "dir2"); - } - - SECTION("simple 5") - { - REQUIRE(VirtFs::mountDirSilentTest("dir1", - Append_true)); - REQUIRE(VirtFs::mountDirSilentTest("dir2", - Append_true)); - REQUIRE(VirtFs::mountDirSilentTest("dir3/test", - Append_true)); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, std::string()) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal( - "dir3" + sep + "test" + sep, std::string()) != nullptr); - REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) == - nullptr); - REQUIRE(VirtFs::getEntries().size() == 3); - 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); - REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); - REQUIRE(VirtFs::getEntries()[1]->subDir.empty()); - REQUIRE(VirtFs::getEntries()[2]->subDir.empty()); - REQUIRE(static_cast( - VirtFs::getEntries()[0])->userDir == "dir1"); - REQUIRE(static_cast( - VirtFs::getEntries()[1])->userDir == "dir2"); - REQUIRE(static_cast( - VirtFs::getEntries()[2])->userDir == "dir3" + sep + "test"); - } - - SECTION("simple 6") - { - REQUIRE(VirtFs::mountDirSilentTest("dir1", - Append_true)); - REQUIRE(VirtFs::mountDirSilentTest("dir2", - Append_true)); - REQUIRE(VirtFs::mountDirSilentTest("dir3\\test", - Append_false)); - REQUIRE(VirtFs::searchByRootInternal( - "dir1" + sep + "", std::string()) != nullptr); - REQUIRE(VirtFs::searchByRootInternal( - "dir2" + sep + "", std::string()) != nullptr); - REQUIRE(VirtFs::searchByRootInternal( - "dir3" + sep + "test" + sep, std::string()) != nullptr); - REQUIRE(VirtFs::searchByRootInternal( - "test" + sep + "", std::string()) == nullptr); - REQUIRE(VirtFs::getEntries().size() == 3); - 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(VirtFs::getEntries()[0]->subDir.empty()); - REQUIRE(VirtFs::getEntries()[1]->subDir.empty()); - REQUIRE(VirtFs::getEntries()[2]->subDir.empty()); - REQUIRE(static_cast( - VirtFs::getEntries()[0])->userDir == "dir3" + sep + "test"); - REQUIRE(static_cast( - VirtFs::getEntries()[1])->userDir == "dir1"); - REQUIRE(static_cast( - VirtFs::getEntries()[2])->userDir == "dir2"); - } - - SECTION("subDir 1") - { - REQUIRE(VirtFs::mountDirSilentTest2("dir1", - dirSeparator, - Append_false)); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) == - nullptr); - REQUIRE(VirtFs::getEntries().size() == 1); - REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep); - REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); - REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); - REQUIRE(static_cast( - VirtFs::getEntries()[0])->userDir == "dir1"); - } - - SECTION("subDir 1.2") - { - REQUIRE(VirtFs::mountDirSilentTest2("dir1", - "dir2", - Append_false)); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir2" + sep) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1" + sep) == - nullptr); - REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir2" + sep) == - nullptr); - REQUIRE(VirtFs::getEntries().size() == 1); - REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep); - REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2" + sep); - REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); - REQUIRE(static_cast( - VirtFs::getEntries()[0])->userDir == "dir1"); - } - - SECTION("subDir 2") - { - REQUIRE(VirtFs::mountDirSilentTest2("dir1/", - "dir2", - Append_true)); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir2" + sep) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir2" + sep) == - nullptr); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1" + sep) == - nullptr); - REQUIRE(VirtFs::getEntries().size() == 1); - REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep); - REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2" + sep); - REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); - REQUIRE(static_cast( - VirtFs::getEntries()[0])->userDir == "dir1" + sep); - } - - SECTION("subDir 3") - { - REQUIRE(VirtFs::mountDirSilentTest2("dir1", - "dir3", - Append_false)); - REQUIRE(VirtFs::mountDirSilentTest2("dir2", - "dir4", - Append_false)); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir3" + sep) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1" + sep) == - nullptr); - REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, "dir4" + sep) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir3" + sep) == - nullptr); - REQUIRE(VirtFs::getEntries().size() == 2); - 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(VirtFs::getEntries()[0]->subDir == "dir4" + sep); - REQUIRE(VirtFs::getEntries()[1]->subDir == "dir3" + sep); - REQUIRE(static_cast( - VirtFs::getEntries()[0])->userDir == "dir2"); - REQUIRE(static_cast( - VirtFs::getEntries()[1])->userDir == "dir1"); - } - - SECTION("subDir 4") - { - REQUIRE(VirtFs::mountDirSilentTest2("dir1\\", - "dir3", - Append_true)); - REQUIRE(VirtFs::mountDirSilentTest2("dir2", - "dir4", - Append_true)); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir3" + sep) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1" + sep) == - nullptr); - REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, "dir4" + sep) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir3" + sep) == - nullptr); - REQUIRE(VirtFs::getEntries().size() == 2); - 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(VirtFs::getEntries()[0]->subDir == "dir3" + sep); - REQUIRE(VirtFs::getEntries()[1]->subDir == "dir4" + sep); - REQUIRE(static_cast( - VirtFs::getEntries()[0])->userDir == "dir1" + sep); - REQUIRE(static_cast( - VirtFs::getEntries()[1])->userDir == "dir2"); - } - - SECTION("subDir 5") - { - REQUIRE(VirtFs::mountDirSilentTest2("dir1", - "dir3", - Append_true)); - REQUIRE(VirtFs::mountDirSilentTest2("dir2", - "dir4", - Append_true)); - REQUIRE(VirtFs::mountDirSilentTest2("dir3/test", - "dir5", - Append_true)); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir3" + sep) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, "dir4" + sep) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal( - "dir3" + sep + "test" + sep, "dir5" + sep) != nullptr); - REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir3" + sep) == - nullptr); - REQUIRE(VirtFs::getEntries().size() == 3); - 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); - REQUIRE(VirtFs::getEntries()[0]->subDir == "dir3" + sep); - REQUIRE(VirtFs::getEntries()[1]->subDir == "dir4" + sep); - REQUIRE(VirtFs::getEntries()[2]->subDir == "dir5" + sep); - REQUIRE(static_cast( - VirtFs::getEntries()[0])->userDir == "dir1"); - REQUIRE(static_cast( - VirtFs::getEntries()[1])->userDir == "dir2"); - REQUIRE(static_cast( - VirtFs::getEntries()[2])->userDir == "dir3" + sep + "test"); - } - - SECTION("subDir 6") - { - REQUIRE(VirtFs::mountDirSilentTest2("dir1", - "dir1", - Append_true)); - REQUIRE(VirtFs::mountDirSilentTest2("dir2", - "dir2", - Append_true)); - REQUIRE(VirtFs::mountDirSilentTest2("dir3\\test", - "dir3\\test", - Append_false)); - REQUIRE(VirtFs::searchByRootInternal( - "dir1" + sep + "", "dir1" + sep) != nullptr); - REQUIRE(VirtFs::searchByRootInternal( - "dir2" + sep + "", "dir2" + sep) != nullptr); - REQUIRE(VirtFs::searchByRootInternal( - "dir3" + sep + "test" + sep, - "dir3" + sep + "test" + sep) != nullptr); - REQUIRE(VirtFs::searchByRootInternal( - "test" + sep + "", "dir1" + sep) == nullptr); - REQUIRE(VirtFs::getEntries().size() == 3); - 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(VirtFs::getEntries()[0]->subDir == - "dir3" + sep + "test" + sep); - REQUIRE(VirtFs::getEntries()[1]->subDir == "dir1" + sep); - REQUIRE(VirtFs::getEntries()[2]->subDir == "dir2" + sep); - REQUIRE(static_cast( - VirtFs::getEntries()[0])->userDir == "dir3" + sep + "test"); - REQUIRE(static_cast( - VirtFs::getEntries()[1])->userDir == "dir1"); - REQUIRE(static_cast( - VirtFs::getEntries()[2])->userDir == "dir2"); - } - - SECTION("subDir 7") - { - REQUIRE(VirtFs::mountDirSilentTest("dir1", - Append_true)); - REQUIRE(VirtFs::mountDirSilentTest2("dir1", - "dir2", - Append_true)); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir2" + sep) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir2" + sep) == - nullptr); - REQUIRE(VirtFs::getEntries().size() == 2); - REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep); - REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); - REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); - REQUIRE(VirtFs::getEntries()[1]->root == "dir1" + sep); - REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2" + sep); - REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir); - REQUIRE(static_cast( - VirtFs::getEntries()[0])->userDir == "dir1"); - REQUIRE(static_cast( - VirtFs::getEntries()[1])->userDir == "dir1"); - - REQUIRE(VirtFs::unmountDirSilent("dir1")); - REQUIRE(VirtFs::getEntries().size() == 1); - REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep); - REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2" + sep); - REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); - REQUIRE(static_cast( - VirtFs::getEntries()[0])->userDir == "dir1"); - } - - SECTION("subDir 8") - { - REQUIRE(VirtFs::mountDirSilentTest("dir1", - Append_true)); - REQUIRE(VirtFs::mountDirSilentTest2("dir1", - "dir2", - Append_true)); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir2" + sep) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir2" + sep) == - nullptr); - REQUIRE(VirtFs::getEntries().size() == 2); - REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep); - REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); - REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); - REQUIRE(VirtFs::getEntries()[1]->root == "dir1" + sep); - REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2" + sep); - REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir); - REQUIRE(static_cast( - VirtFs::getEntries()[0])->userDir == "dir1"); - REQUIRE(static_cast( - VirtFs::getEntries()[1])->userDir == "dir1"); - - REQUIRE(VirtFs::unmountDirSilent2("dir1", "dir2")); - REQUIRE(VirtFs::getEntries().size() == 1); - REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep); - REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); - REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); - REQUIRE(static_cast( - VirtFs::getEntries()[0])->userDir == "dir1"); - } - - SECTION("subDir 9") - { - REQUIRE(VirtFs::mountDirSilentTest2("dir1", - dirSeparator, - Append_false)); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1") == - nullptr); - REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) == - nullptr); - REQUIRE(VirtFs::getEntries().size() == 1); - REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep); - REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); - REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); - REQUIRE(static_cast( - VirtFs::getEntries()[0])->userDir == "dir1"); - } - - VirtFs::deinit(); -} diff --git a/src/unittests/fs/virtfs/virtfs1_mountdir1.cc b/src/unittests/fs/virtfs/virtfs1_mountdir1.cc new file mode 100644 index 000000000..92d6d037d --- /dev/null +++ b/src/unittests/fs/virtfs/virtfs1_mountdir1.cc @@ -0,0 +1,195 @@ +/* + * 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 . + */ + +#include "unittests/unittests.h" + +#include "fs/virtfs/direntry.h" +#include "fs/virtfs/fs.h" + +#include "utils/checkutils.h" + +#ifndef UNITTESTS_CATCH +#include +#endif // UNITTESTS_CATCH + +#include "debug.h" + +TEST_CASE("VirtFs1 mountDir1", "") +{ + VirtFs::init("."); + const std::string sep = dirSeparator; + SECTION("simple 1") + { + REQUIRE(VirtFs::mountDirSilentTest("dir1", + Append_false)); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1") == + nullptr); + REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) == + nullptr); + REQUIRE(VirtFs::getEntries().size() == 1); + REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep); + REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); + REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); + REQUIRE(static_cast( + VirtFs::getEntries()[0])->userDir == "dir1"); + } + + SECTION("simple 2") + { + REQUIRE(VirtFs::mountDirSilentTest("dir1/", + Append_true)); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1") == + nullptr); + REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) == + nullptr); + REQUIRE(VirtFs::getEntries().size() == 1); + REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep); + REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); + REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); + REQUIRE(static_cast( + VirtFs::getEntries()[0])->userDir == "dir1" + sep); + } + + SECTION("simple 3") + { + REQUIRE(VirtFs::mountDirSilentTest("dir1", + Append_false)); + REQUIRE(VirtFs::mountDirSilentTest("dir2", + Append_false)); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1") == + nullptr); + REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, std::string()) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) == + nullptr); + REQUIRE(VirtFs::getEntries().size() == 2); + 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(VirtFs::getEntries()[0]->subDir.empty()); + REQUIRE(VirtFs::getEntries()[1]->subDir.empty()); + REQUIRE(static_cast( + VirtFs::getEntries()[0])->userDir == "dir2"); + REQUIRE(static_cast( + VirtFs::getEntries()[1])->userDir == "dir1"); + } + + SECTION("simple 4") + { + REQUIRE(VirtFs::mountDirSilentTest("dir1\\", + Append_true)); + REQUIRE(VirtFs::mountDirSilentTest("dir2", + Append_true)); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, std::string()) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) == + nullptr); + REQUIRE(VirtFs::getEntries().size() == 2); + 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(VirtFs::getEntries()[0]->subDir.empty()); + REQUIRE(VirtFs::getEntries()[1]->subDir.empty()); + REQUIRE(static_cast( + VirtFs::getEntries()[0])->userDir == "dir1" + sep); + REQUIRE(static_cast( + VirtFs::getEntries()[1])->userDir == "dir2"); + } + + SECTION("simple 5") + { + REQUIRE(VirtFs::mountDirSilentTest("dir1", + Append_true)); + REQUIRE(VirtFs::mountDirSilentTest("dir2", + Append_true)); + REQUIRE(VirtFs::mountDirSilentTest("dir3/test", + Append_true)); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, std::string()) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal( + "dir3" + sep + "test" + sep, std::string()) != nullptr); + REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) == + nullptr); + REQUIRE(VirtFs::getEntries().size() == 3); + 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); + REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); + REQUIRE(VirtFs::getEntries()[1]->subDir.empty()); + REQUIRE(VirtFs::getEntries()[2]->subDir.empty()); + REQUIRE(static_cast( + VirtFs::getEntries()[0])->userDir == "dir1"); + REQUIRE(static_cast( + VirtFs::getEntries()[1])->userDir == "dir2"); + REQUIRE(static_cast( + VirtFs::getEntries()[2])->userDir == "dir3" + sep + "test"); + } + + SECTION("simple 6") + { + REQUIRE(VirtFs::mountDirSilentTest("dir1", + Append_true)); + REQUIRE(VirtFs::mountDirSilentTest("dir2", + Append_true)); + REQUIRE(VirtFs::mountDirSilentTest("dir3\\test", + Append_false)); + REQUIRE(VirtFs::searchByRootInternal( + "dir1" + sep + "", std::string()) != nullptr); + REQUIRE(VirtFs::searchByRootInternal( + "dir2" + sep + "", std::string()) != nullptr); + REQUIRE(VirtFs::searchByRootInternal( + "dir3" + sep + "test" + sep, std::string()) != nullptr); + REQUIRE(VirtFs::searchByRootInternal( + "test" + sep + "", std::string()) == nullptr); + REQUIRE(VirtFs::getEntries().size() == 3); + 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(VirtFs::getEntries()[0]->subDir.empty()); + REQUIRE(VirtFs::getEntries()[1]->subDir.empty()); + REQUIRE(VirtFs::getEntries()[2]->subDir.empty()); + REQUIRE(static_cast( + VirtFs::getEntries()[0])->userDir == "dir3" + sep + "test"); + REQUIRE(static_cast( + VirtFs::getEntries()[1])->userDir == "dir1"); + REQUIRE(static_cast( + VirtFs::getEntries()[2])->userDir == "dir2"); + } + + VirtFs::deinit(); +} diff --git a/src/unittests/fs/virtfs/virtfs1_mountdir2.cc b/src/unittests/fs/virtfs/virtfs1_mountdir2.cc new file mode 100644 index 000000000..35900389f --- /dev/null +++ b/src/unittests/fs/virtfs/virtfs1_mountdir2.cc @@ -0,0 +1,315 @@ +/* + * 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 . + */ + +#include "unittests/unittests.h" + +#include "fs/virtfs/direntry.h" +#include "fs/virtfs/fs.h" + +#include "utils/checkutils.h" + +#ifndef UNITTESTS_CATCH +#include +#endif // UNITTESTS_CATCH + +#include "debug.h" + +TEST_CASE("VirtFs1 mountDir2", "") +{ + VirtFs::init("."); + const std::string sep = dirSeparator; + SECTION("subDir 1") + { + REQUIRE(VirtFs::mountDirSilentTest2("dir1", + dirSeparator, + Append_false)); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) == + nullptr); + REQUIRE(VirtFs::getEntries().size() == 1); + REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep); + REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); + REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); + REQUIRE(static_cast( + VirtFs::getEntries()[0])->userDir == "dir1"); + } + + SECTION("subDir 1.2") + { + REQUIRE(VirtFs::mountDirSilentTest2("dir1", + "dir2", + Append_false)); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir2" + sep) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1" + sep) == + nullptr); + REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir2" + sep) == + nullptr); + REQUIRE(VirtFs::getEntries().size() == 1); + REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep); + REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2" + sep); + REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); + REQUIRE(static_cast( + VirtFs::getEntries()[0])->userDir == "dir1"); + } + + SECTION("subDir 2") + { + REQUIRE(VirtFs::mountDirSilentTest2("dir1/", + "dir2", + Append_true)); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir2" + sep) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir2" + sep) == + nullptr); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1" + sep) == + nullptr); + REQUIRE(VirtFs::getEntries().size() == 1); + REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep); + REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2" + sep); + REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); + REQUIRE(static_cast( + VirtFs::getEntries()[0])->userDir == "dir1" + sep); + } + + SECTION("subDir 3") + { + REQUIRE(VirtFs::mountDirSilentTest2("dir1", + "dir3", + Append_false)); + REQUIRE(VirtFs::mountDirSilentTest2("dir2", + "dir4", + Append_false)); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir3" + sep) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1" + sep) == + nullptr); + REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, "dir4" + sep) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir3" + sep) == + nullptr); + REQUIRE(VirtFs::getEntries().size() == 2); + 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(VirtFs::getEntries()[0]->subDir == "dir4" + sep); + REQUIRE(VirtFs::getEntries()[1]->subDir == "dir3" + sep); + REQUIRE(static_cast( + VirtFs::getEntries()[0])->userDir == "dir2"); + REQUIRE(static_cast( + VirtFs::getEntries()[1])->userDir == "dir1"); + } + + SECTION("subDir 4") + { + REQUIRE(VirtFs::mountDirSilentTest2("dir1\\", + "dir3", + Append_true)); + REQUIRE(VirtFs::mountDirSilentTest2("dir2", + "dir4", + Append_true)); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir3" + sep) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1" + sep) == + nullptr); + REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, "dir4" + sep) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir3" + sep) == + nullptr); + REQUIRE(VirtFs::getEntries().size() == 2); + 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(VirtFs::getEntries()[0]->subDir == "dir3" + sep); + REQUIRE(VirtFs::getEntries()[1]->subDir == "dir4" + sep); + REQUIRE(static_cast( + VirtFs::getEntries()[0])->userDir == "dir1" + sep); + REQUIRE(static_cast( + VirtFs::getEntries()[1])->userDir == "dir2"); + } + + SECTION("subDir 5") + { + REQUIRE(VirtFs::mountDirSilentTest2("dir1", + "dir3", + Append_true)); + REQUIRE(VirtFs::mountDirSilentTest2("dir2", + "dir4", + Append_true)); + REQUIRE(VirtFs::mountDirSilentTest2("dir3/test", + "dir5", + Append_true)); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir3" + sep) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, "dir4" + sep) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal( + "dir3" + sep + "test" + sep, "dir5" + sep) != nullptr); + REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir3" + sep) == + nullptr); + REQUIRE(VirtFs::getEntries().size() == 3); + 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); + REQUIRE(VirtFs::getEntries()[0]->subDir == "dir3" + sep); + REQUIRE(VirtFs::getEntries()[1]->subDir == "dir4" + sep); + REQUIRE(VirtFs::getEntries()[2]->subDir == "dir5" + sep); + REQUIRE(static_cast( + VirtFs::getEntries()[0])->userDir == "dir1"); + REQUIRE(static_cast( + VirtFs::getEntries()[1])->userDir == "dir2"); + REQUIRE(static_cast( + VirtFs::getEntries()[2])->userDir == "dir3" + sep + "test"); + } + + SECTION("subDir 6") + { + REQUIRE(VirtFs::mountDirSilentTest2("dir1", + "dir1", + Append_true)); + REQUIRE(VirtFs::mountDirSilentTest2("dir2", + "dir2", + Append_true)); + REQUIRE(VirtFs::mountDirSilentTest2("dir3\\test", + "dir3\\test", + Append_false)); + REQUIRE(VirtFs::searchByRootInternal( + "dir1" + sep + "", "dir1" + sep) != nullptr); + REQUIRE(VirtFs::searchByRootInternal( + "dir2" + sep + "", "dir2" + sep) != nullptr); + REQUIRE(VirtFs::searchByRootInternal( + "dir3" + sep + "test" + sep, + "dir3" + sep + "test" + sep) != nullptr); + REQUIRE(VirtFs::searchByRootInternal( + "test" + sep + "", "dir1" + sep) == nullptr); + REQUIRE(VirtFs::getEntries().size() == 3); + 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(VirtFs::getEntries()[0]->subDir == + "dir3" + sep + "test" + sep); + REQUIRE(VirtFs::getEntries()[1]->subDir == "dir1" + sep); + REQUIRE(VirtFs::getEntries()[2]->subDir == "dir2" + sep); + REQUIRE(static_cast( + VirtFs::getEntries()[0])->userDir == "dir3" + sep + "test"); + REQUIRE(static_cast( + VirtFs::getEntries()[1])->userDir == "dir1"); + REQUIRE(static_cast( + VirtFs::getEntries()[2])->userDir == "dir2"); + } + + SECTION("subDir 7") + { + REQUIRE(VirtFs::mountDirSilentTest("dir1", + Append_true)); + REQUIRE(VirtFs::mountDirSilentTest2("dir1", + "dir2", + Append_true)); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir2" + sep) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir2" + sep) == + nullptr); + REQUIRE(VirtFs::getEntries().size() == 2); + REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep); + REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); + REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); + REQUIRE(VirtFs::getEntries()[1]->root == "dir1" + sep); + REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2" + sep); + REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir); + REQUIRE(static_cast( + VirtFs::getEntries()[0])->userDir == "dir1"); + REQUIRE(static_cast( + VirtFs::getEntries()[1])->userDir == "dir1"); + + REQUIRE(VirtFs::unmountDirSilent("dir1")); + REQUIRE(VirtFs::getEntries().size() == 1); + REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep); + REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2" + sep); + REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); + REQUIRE(static_cast( + VirtFs::getEntries()[0])->userDir == "dir1"); + } + + SECTION("subDir 8") + { + REQUIRE(VirtFs::mountDirSilentTest("dir1", + Append_true)); + REQUIRE(VirtFs::mountDirSilentTest2("dir1", + "dir2", + Append_true)); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir2" + sep) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir2" + sep) == + nullptr); + REQUIRE(VirtFs::getEntries().size() == 2); + REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep); + REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); + REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); + REQUIRE(VirtFs::getEntries()[1]->root == "dir1" + sep); + REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2" + sep); + REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir); + REQUIRE(static_cast( + VirtFs::getEntries()[0])->userDir == "dir1"); + REQUIRE(static_cast( + VirtFs::getEntries()[1])->userDir == "dir1"); + + REQUIRE(VirtFs::unmountDirSilent2("dir1", "dir2")); + REQUIRE(VirtFs::getEntries().size() == 1); + REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep); + REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); + REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); + REQUIRE(static_cast( + VirtFs::getEntries()[0])->userDir == "dir1"); + } + + SECTION("subDir 9") + { + REQUIRE(VirtFs::mountDirSilentTest2("dir1", + dirSeparator, + Append_false)); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, std::string()) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1") == + nullptr); + REQUIRE(VirtFs::searchByRootInternal("test" + sep, std::string()) == + nullptr); + REQUIRE(VirtFs::getEntries().size() == 1); + REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep); + REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); + REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); + REQUIRE(static_cast( + VirtFs::getEntries()[0])->userDir == "dir1"); + } + + VirtFs::deinit(); +} diff --git a/src/unittests/fs/virtfs/virtfs1_mountzip.cc b/src/unittests/fs/virtfs/virtfs1_mountzip.cc deleted file mode 100644 index 5cd0cda17..000000000 --- a/src/unittests/fs/virtfs/virtfs1_mountzip.cc +++ /dev/null @@ -1,329 +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 . - */ - -#include "unittests/unittests.h" - -#include "fs/files.h" - -#include "fs/virtfs/direntry.h" -#include "fs/virtfs/fs.h" - -#include "utils/checkutils.h" - -#ifndef UNITTESTS_CATCH -#include -#endif // UNITTESTS_CATCH - -#include "debug.h" - -TEST_CASE("VirtFs1 mountZip", "") -{ - VirtFs::init("."); - std::string name("data/test/test.zip"); - std::string prefix; - const std::string sep = dirSeparator; - if (Files::existsLocal(name) == false) - prefix = "../"; - - SECTION("simple 1") - { - REQUIRE(VirtFs::mountZip(prefix + "data/test/test.zip", - Append_false)); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "test.zip", std::string()) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "test2.zip", - std::string()) == nullptr); - REQUIRE(VirtFs::getEntries().size() == 1); - REQUIRE(VirtFs::getEntries()[0]->root == - prefix + "data" + sep + "test" + sep + "test.zip"); - REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); - REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip); - } - - SECTION("simple 2") - { - REQUIRE(VirtFs::mountZip(prefix + "data/test/test.zip", - Append_false)); - REQUIRE(VirtFs::mountZip(prefix + "data/test/test2.zip", - Append_false)); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "test.zip", - std::string()) != nullptr); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "test2.zip", - std::string()) != nullptr); - REQUIRE(VirtFs::getEntries().size() == 2); - REQUIRE(VirtFs::getEntries()[0]->root == - prefix + "data" + sep + "test" + sep + "test2.zip"); - REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip); - REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); - REQUIRE(VirtFs::getEntries()[1]->root == - prefix + "data" + sep + "test" + sep + "test.zip"); - REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Zip); - REQUIRE(VirtFs::getEntries()[1]->subDir.empty()); - } - - SECTION("simple 3") - { - REQUIRE(VirtFs::mountZip(prefix + "data/test/test.zip", - Append_true)); - REQUIRE(VirtFs::mountZip(prefix + "data/test/test2.zip", - Append_true)); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "test.zip", - std::string()) != nullptr); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "test2.zip", - std::string()) != nullptr); - REQUIRE(VirtFs::getEntries().size() == 2); - REQUIRE(VirtFs::getEntries()[0]->root == - prefix + "data" + sep + "test" + sep + "test.zip"); - REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip); - REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); - REQUIRE(VirtFs::getEntries()[1]->root == - prefix + "data" + sep + "test" + sep + "test2.zip"); - REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Zip); - REQUIRE(VirtFs::getEntries()[1]->subDir.empty()); - } - - SECTION("simple 4") - { - REQUIRE(VirtFs::mountZip(prefix + "data/test/test.zip", - Append_false)); - REQUIRE(VirtFs::mountDir(prefix + "data/test", - Append_false)); - REQUIRE(VirtFs::mountZip(prefix + "data/test/test2.zip", - Append_false)); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "test.zip", - std::string()) != nullptr); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "test2.zip", - std::string()) != nullptr); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "", - std::string()) != nullptr); - REQUIRE(VirtFs::getEntries().size() == 3); - REQUIRE(VirtFs::getEntries()[0]->root == - prefix + "data" + sep + "test" + sep + "test2.zip"); - REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip); - REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); - REQUIRE(VirtFs::getEntries()[1]->root == - prefix + "data" + sep + "test" + sep + ""); - REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir); - REQUIRE(VirtFs::getEntries()[1]->subDir.empty()); - REQUIRE(VirtFs::getEntries()[2]->root == - prefix + "data" + sep + "test" + sep + "test.zip"); - REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Zip); - REQUIRE(VirtFs::getEntries()[2]->subDir.empty()); - } - - SECTION("simple 5") - { - REQUIRE(VirtFs::mountZip(prefix + "data/test/test.zip", - Append_false)); - REQUIRE(VirtFs::mountDir(prefix + "data/test", - Append_false)); - REQUIRE(VirtFs::mountZip(prefix + "data/test/test2.zip", - Append_true)); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "test.zip", - std::string()) != nullptr); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "test2.zip", - std::string()) != nullptr); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "", - std::string()) != nullptr); - REQUIRE(VirtFs::getEntries().size() == 3); - REQUIRE(VirtFs::getEntries()[0]->root == - prefix + "data" + sep + "test" + sep + ""); - REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); - REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); - REQUIRE(VirtFs::getEntries()[1]->root == - prefix + "data" + sep + "test" + sep + "test.zip"); - REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Zip); - REQUIRE(VirtFs::getEntries()[1]->subDir.empty()); - REQUIRE(VirtFs::getEntries()[2]->root == - prefix + "data" + sep + "test" + sep + "test2.zip"); - REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Zip); - REQUIRE(VirtFs::getEntries()[2]->subDir.empty()); - } - - SECTION("subDir 1") - { - REQUIRE(VirtFs::mountZip2(prefix + "data/test/test.zip", - "dir1", - Append_false)); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "test.zip", "dir1" + sep) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "test2.zip", - std::string()) == nullptr); - REQUIRE(VirtFs::getEntries().size() == 1); - REQUIRE(VirtFs::getEntries()[0]->root == - prefix + "data" + sep + "test" + sep + "test.zip"); - REQUIRE(VirtFs::getEntries()[0]->subDir == "dir1" + sep); - REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip); - } - - SECTION("subDir 2") - { - REQUIRE(VirtFs::mountZip2(prefix + "data/test/test.zip", - "dir1", - Append_false)); - REQUIRE(VirtFs::mountZip2(prefix + "data/test/test2.zip", - "dir2", - Append_false)); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "test.zip", "dir1" + sep) != - nullptr); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "test2.zip", - "dir2" + sep) != nullptr); - REQUIRE(VirtFs::getEntries().size() == 2); - REQUIRE(VirtFs::getEntries()[0]->root == - prefix + "data" + sep + "test" + sep + "test2.zip"); - REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip); - REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2" + sep); - REQUIRE(VirtFs::getEntries()[1]->root == - prefix + "data" + sep + "test" + sep + "test.zip"); - REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Zip); - REQUIRE(VirtFs::getEntries()[1]->subDir == "dir1" + sep); - } - - SECTION("subDir 3") - { - REQUIRE(VirtFs::mountZip2(prefix + "data/test/test.zip", - "dir1", - Append_true)); - REQUIRE(VirtFs::mountZip2(prefix + "data/test/test2.zip", - "dir2", - Append_true)); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "test.zip", - "dir1" + sep) != nullptr); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "test2.zip", - "dir2" + sep) != nullptr); - REQUIRE(VirtFs::getEntries().size() == 2); - REQUIRE(VirtFs::getEntries()[0]->root == - prefix + "data" + sep + "test" + sep + "test.zip"); - REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip); - REQUIRE(VirtFs::getEntries()[0]->subDir == "dir1" + sep); - REQUIRE(VirtFs::getEntries()[1]->root == - prefix + "data" + sep + "test" + sep + "test2.zip"); - REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Zip); - REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2" + sep); - } - - SECTION("subDir 4") - { - REQUIRE(VirtFs::mountZip2(prefix + "data/test/test.zip", - "dir1", - Append_false)); - REQUIRE(VirtFs::mountDir2(prefix + "data/test", - "dir2", - Append_false)); - REQUIRE(VirtFs::mountZip2(prefix + "data/test/test2.zip", - "dir3", - Append_false)); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "test.zip", - "dir1" + sep) != nullptr); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "test2.zip", - "dir3" + sep) != nullptr); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "", - "dir2" + sep) != nullptr); - REQUIRE(VirtFs::getEntries().size() == 3); - REQUIRE(VirtFs::getEntries()[0]->root == - prefix + "data" + sep + "test" + sep + "test2.zip"); - REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip); - REQUIRE(VirtFs::getEntries()[0]->subDir == "dir3" + sep); - REQUIRE(VirtFs::getEntries()[1]->root == - prefix + "data" + sep + "test" + sep + ""); - REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir); - REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2" + sep); - REQUIRE(VirtFs::getEntries()[2]->root == - prefix + "data" + sep + "test" + sep + "test.zip"); - REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Zip); - REQUIRE(VirtFs::getEntries()[2]->subDir == "dir1" + sep); - } - - SECTION("subDir 5") - { - REQUIRE(VirtFs::mountZip2(prefix + "data/test/test.zip", - "dir1", - Append_false)); - REQUIRE(VirtFs::mountDir2(prefix + "data/test", - "dir2", - Append_false)); - REQUIRE(VirtFs::mountZip2(prefix + "data/test/test2.zip", - "dir3", - Append_true)); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "test.zip", - "dir1" + sep) != nullptr); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "test2.zip", - "dir3" + sep) != nullptr); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "", - "dir2" + sep) != nullptr); - REQUIRE(VirtFs::getEntries().size() == 3); - REQUIRE(VirtFs::getEntries()[0]->root == - prefix + "data" + sep + "test" + sep + ""); - REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); - REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2" + sep); - REQUIRE(VirtFs::getEntries()[1]->root == - prefix + "data" + sep + "test" + sep + "test.zip"); - REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Zip); - REQUIRE(VirtFs::getEntries()[1]->subDir == "dir1" + sep); - REQUIRE(VirtFs::getEntries()[2]->root == - prefix + "data" + sep + "test" + sep + "test2.zip"); - REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Zip); - REQUIRE(VirtFs::getEntries()[2]->subDir == "dir3" + sep); - } - - SECTION("subDir 6") - { - REQUIRE(VirtFs::mountZip2(prefix + "data/test/test.zip", - dirSeparator, - Append_false)); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "test.zip", - std::string()) != nullptr); - REQUIRE(VirtFs::searchByRootInternal( - prefix + "data" + sep + "test" + sep + "test2.zip", - std::string()) == nullptr); - REQUIRE(VirtFs::getEntries().size() == 1); - REQUIRE(VirtFs::getEntries()[0]->root == - prefix + "data" + sep + "test" + sep + "test.zip"); - REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); - REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip); - } - - VirtFs::deinit(); -} diff --git a/src/unittests/fs/virtfs/virtfs1_mountzip1.cc b/src/unittests/fs/virtfs/virtfs1_mountzip1.cc new file mode 100644 index 000000000..09932f0a6 --- /dev/null +++ b/src/unittests/fs/virtfs/virtfs1_mountzip1.cc @@ -0,0 +1,173 @@ +/* + * 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 . + */ + +#include "unittests/unittests.h" + +#include "fs/files.h" + +#include "fs/virtfs/direntry.h" +#include "fs/virtfs/fs.h" + +#include "utils/checkutils.h" + +#ifndef UNITTESTS_CATCH +#include +#endif // UNITTESTS_CATCH + +#include "debug.h" + +TEST_CASE("VirtFs1 mountZip1", "") +{ + VirtFs::init("."); + std::string name("data/test/test.zip"); + std::string prefix; + const std::string sep = dirSeparator; + if (Files::existsLocal(name) == false) + prefix = "../"; + + SECTION("simple 1") + { + REQUIRE(VirtFs::mountZip(prefix + "data/test/test.zip", + Append_false)); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "test.zip", std::string()) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "test2.zip", + std::string()) == nullptr); + REQUIRE(VirtFs::getEntries().size() == 1); + REQUIRE(VirtFs::getEntries()[0]->root == + prefix + "data" + sep + "test" + sep + "test.zip"); + REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); + REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip); + } + + SECTION("simple 2") + { + REQUIRE(VirtFs::mountZip(prefix + "data/test/test.zip", + Append_false)); + REQUIRE(VirtFs::mountZip(prefix + "data/test/test2.zip", + Append_false)); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "test.zip", + std::string()) != nullptr); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "test2.zip", + std::string()) != nullptr); + REQUIRE(VirtFs::getEntries().size() == 2); + REQUIRE(VirtFs::getEntries()[0]->root == + prefix + "data" + sep + "test" + sep + "test2.zip"); + REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip); + REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); + REQUIRE(VirtFs::getEntries()[1]->root == + prefix + "data" + sep + "test" + sep + "test.zip"); + REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Zip); + REQUIRE(VirtFs::getEntries()[1]->subDir.empty()); + } + + SECTION("simple 3") + { + REQUIRE(VirtFs::mountZip(prefix + "data/test/test.zip", + Append_true)); + REQUIRE(VirtFs::mountZip(prefix + "data/test/test2.zip", + Append_true)); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "test.zip", + std::string()) != nullptr); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "test2.zip", + std::string()) != nullptr); + REQUIRE(VirtFs::getEntries().size() == 2); + REQUIRE(VirtFs::getEntries()[0]->root == + prefix + "data" + sep + "test" + sep + "test.zip"); + REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip); + REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); + REQUIRE(VirtFs::getEntries()[1]->root == + prefix + "data" + sep + "test" + sep + "test2.zip"); + REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Zip); + REQUIRE(VirtFs::getEntries()[1]->subDir.empty()); + } + + SECTION("simple 4") + { + REQUIRE(VirtFs::mountZip(prefix + "data/test/test.zip", + Append_false)); + REQUIRE(VirtFs::mountDir(prefix + "data/test", + Append_false)); + REQUIRE(VirtFs::mountZip(prefix + "data/test/test2.zip", + Append_false)); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "test.zip", + std::string()) != nullptr); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "test2.zip", + std::string()) != nullptr); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "", + std::string()) != nullptr); + REQUIRE(VirtFs::getEntries().size() == 3); + REQUIRE(VirtFs::getEntries()[0]->root == + prefix + "data" + sep + "test" + sep + "test2.zip"); + REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip); + REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); + REQUIRE(VirtFs::getEntries()[1]->root == + prefix + "data" + sep + "test" + sep + ""); + REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir); + REQUIRE(VirtFs::getEntries()[1]->subDir.empty()); + REQUIRE(VirtFs::getEntries()[2]->root == + prefix + "data" + sep + "test" + sep + "test.zip"); + REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Zip); + REQUIRE(VirtFs::getEntries()[2]->subDir.empty()); + } + + SECTION("simple 5") + { + REQUIRE(VirtFs::mountZip(prefix + "data/test/test.zip", + Append_false)); + REQUIRE(VirtFs::mountDir(prefix + "data/test", + Append_false)); + REQUIRE(VirtFs::mountZip(prefix + "data/test/test2.zip", + Append_true)); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "test.zip", + std::string()) != nullptr); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "test2.zip", + std::string()) != nullptr); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "", + std::string()) != nullptr); + REQUIRE(VirtFs::getEntries().size() == 3); + REQUIRE(VirtFs::getEntries()[0]->root == + prefix + "data" + sep + "test" + sep + ""); + REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); + REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); + REQUIRE(VirtFs::getEntries()[1]->root == + prefix + "data" + sep + "test" + sep + "test.zip"); + REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Zip); + REQUIRE(VirtFs::getEntries()[1]->subDir.empty()); + REQUIRE(VirtFs::getEntries()[2]->root == + prefix + "data" + sep + "test" + sep + "test2.zip"); + REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Zip); + REQUIRE(VirtFs::getEntries()[2]->subDir.empty()); + } + + VirtFs::deinit(); +} diff --git a/src/unittests/fs/virtfs/virtfs1_mountzip2.cc b/src/unittests/fs/virtfs/virtfs1_mountzip2.cc new file mode 100644 index 000000000..c9415e007 --- /dev/null +++ b/src/unittests/fs/virtfs/virtfs1_mountzip2.cc @@ -0,0 +1,202 @@ +/* + * 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 . + */ + +#include "unittests/unittests.h" + +#include "fs/files.h" + +#include "fs/virtfs/direntry.h" +#include "fs/virtfs/fs.h" + +#include "utils/checkutils.h" + +#ifndef UNITTESTS_CATCH +#include +#endif // UNITTESTS_CATCH + +#include "debug.h" + +TEST_CASE("VirtFs1 mountZip2", "") +{ + VirtFs::init("."); + std::string name("data/test/test.zip"); + std::string prefix; + const std::string sep = dirSeparator; + if (Files::existsLocal(name) == false) + prefix = "../"; + + SECTION("subDir 1") + { + REQUIRE(VirtFs::mountZip2(prefix + "data/test/test.zip", + "dir1", + Append_false)); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "test.zip", "dir1" + sep) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "test2.zip", + std::string()) == nullptr); + REQUIRE(VirtFs::getEntries().size() == 1); + REQUIRE(VirtFs::getEntries()[0]->root == + prefix + "data" + sep + "test" + sep + "test.zip"); + REQUIRE(VirtFs::getEntries()[0]->subDir == "dir1" + sep); + REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip); + } + + SECTION("subDir 2") + { + REQUIRE(VirtFs::mountZip2(prefix + "data/test/test.zip", + "dir1", + Append_false)); + REQUIRE(VirtFs::mountZip2(prefix + "data/test/test2.zip", + "dir2", + Append_false)); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "test.zip", "dir1" + sep) != + nullptr); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "test2.zip", + "dir2" + sep) != nullptr); + REQUIRE(VirtFs::getEntries().size() == 2); + REQUIRE(VirtFs::getEntries()[0]->root == + prefix + "data" + sep + "test" + sep + "test2.zip"); + REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip); + REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2" + sep); + REQUIRE(VirtFs::getEntries()[1]->root == + prefix + "data" + sep + "test" + sep + "test.zip"); + REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Zip); + REQUIRE(VirtFs::getEntries()[1]->subDir == "dir1" + sep); + } + + SECTION("subDir 3") + { + REQUIRE(VirtFs::mountZip2(prefix + "data/test/test.zip", + "dir1", + Append_true)); + REQUIRE(VirtFs::mountZip2(prefix + "data/test/test2.zip", + "dir2", + Append_true)); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "test.zip", + "dir1" + sep) != nullptr); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "test2.zip", + "dir2" + sep) != nullptr); + REQUIRE(VirtFs::getEntries().size() == 2); + REQUIRE(VirtFs::getEntries()[0]->root == + prefix + "data" + sep + "test" + sep + "test.zip"); + REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip); + REQUIRE(VirtFs::getEntries()[0]->subDir == "dir1" + sep); + REQUIRE(VirtFs::getEntries()[1]->root == + prefix + "data" + sep + "test" + sep + "test2.zip"); + REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Zip); + REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2" + sep); + } + + SECTION("subDir 4") + { + REQUIRE(VirtFs::mountZip2(prefix + "data/test/test.zip", + "dir1", + Append_false)); + REQUIRE(VirtFs::mountDir2(prefix + "data/test", + "dir2", + Append_false)); + REQUIRE(VirtFs::mountZip2(prefix + "data/test/test2.zip", + "dir3", + Append_false)); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "test.zip", + "dir1" + sep) != nullptr); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "test2.zip", + "dir3" + sep) != nullptr); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "", + "dir2" + sep) != nullptr); + REQUIRE(VirtFs::getEntries().size() == 3); + REQUIRE(VirtFs::getEntries()[0]->root == + prefix + "data" + sep + "test" + sep + "test2.zip"); + REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip); + REQUIRE(VirtFs::getEntries()[0]->subDir == "dir3" + sep); + REQUIRE(VirtFs::getEntries()[1]->root == + prefix + "data" + sep + "test" + sep + ""); + REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir); + REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2" + sep); + REQUIRE(VirtFs::getEntries()[2]->root == + prefix + "data" + sep + "test" + sep + "test.zip"); + REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Zip); + REQUIRE(VirtFs::getEntries()[2]->subDir == "dir1" + sep); + } + + SECTION("subDir 5") + { + REQUIRE(VirtFs::mountZip2(prefix + "data/test/test.zip", + "dir1", + Append_false)); + REQUIRE(VirtFs::mountDir2(prefix + "data/test", + "dir2", + Append_false)); + REQUIRE(VirtFs::mountZip2(prefix + "data/test/test2.zip", + "dir3", + Append_true)); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "test.zip", + "dir1" + sep) != nullptr); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "test2.zip", + "dir3" + sep) != nullptr); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "", + "dir2" + sep) != nullptr); + REQUIRE(VirtFs::getEntries().size() == 3); + REQUIRE(VirtFs::getEntries()[0]->root == + prefix + "data" + sep + "test" + sep + ""); + REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); + REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2" + sep); + REQUIRE(VirtFs::getEntries()[1]->root == + prefix + "data" + sep + "test" + sep + "test.zip"); + REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Zip); + REQUIRE(VirtFs::getEntries()[1]->subDir == "dir1" + sep); + REQUIRE(VirtFs::getEntries()[2]->root == + prefix + "data" + sep + "test" + sep + "test2.zip"); + REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Zip); + REQUIRE(VirtFs::getEntries()[2]->subDir == "dir3" + sep); + } + + SECTION("subDir 6") + { + REQUIRE(VirtFs::mountZip2(prefix + "data/test/test.zip", + dirSeparator, + Append_false)); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "test.zip", + std::string()) != nullptr); + REQUIRE(VirtFs::searchByRootInternal( + prefix + "data" + sep + "test" + sep + "test2.zip", + std::string()) == nullptr); + REQUIRE(VirtFs::getEntries().size() == 1); + REQUIRE(VirtFs::getEntries()[0]->root == + prefix + "data" + sep + "test" + sep + "test.zip"); + REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); + REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip); + } + + VirtFs::deinit(); +} -- cgit v1.2.3-60-g2f50