diff options
Diffstat (limited to 'src/unittests')
-rw-r--r-- | src/unittests/fs/virtfs/throw.cc | 233 | ||||
-rw-r--r-- | src/unittests/fs/virtfs/virtfs1_exists.cc | 4 | ||||
-rw-r--r-- | src/unittests/fs/virtfs/virtfs1_unmount.cc | 25 | ||||
-rw-r--r-- | src/unittests/fs/virtfs/zip.cc | 10 | ||||
-rw-r--r-- | src/unittests/gui/windowmanager.cc | 2 | ||||
-rw-r--r-- | src/unittests/resources/map/maplayer/drawfringenormal.cc | 4 | ||||
-rw-r--r-- | src/unittests/resources/map/maplayer/drawfringesimple.cc | 4 | ||||
-rw-r--r-- | src/unittests/resources/map/maplayer/drawspeciallayer1.cc | 4 | ||||
-rw-r--r-- | src/unittests/resources/map/maplayer/drawspeciallayer2.cc | 4 |
9 files changed, 251 insertions, 39 deletions
diff --git a/src/unittests/fs/virtfs/throw.cc b/src/unittests/fs/virtfs/throw.cc new file mode 100644 index 000000000..377230686 --- /dev/null +++ b/src/unittests/fs/virtfs/throw.cc @@ -0,0 +1,233 @@ +/* + * 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/>. + */ + +#include "unittests/unittests.h" + +#include "fs/files.h" + +#include "fs/virtfs/fs.h" +#include "fs/virtfs/zipreader.h" + +#include "utils/checkutils.h" +#include "utils/delete2.h" + +#ifndef UNITTESTS_CATCH +#include <algorithm> +#endif // UNITTESTS_CATCH + +#include "debug.h" + +TEST_CASE("throw VirtFs1 exists1", "") +{ + VirtFs::init("."); + logger = new Logger(); + const bool dir1 = VirtFs::mountDirSilent("data/", + Append_false); + VirtFs::mountDirSilent("..\\data", + Append_false); + + if (dir1 == true) + { + VirtFs::mountDir("data//test", + Append_false); + } + else + { + VirtFs::mountDirSilent("..//data\\test", + Append_false); + } + + if (dir1 == true) + VirtFs::unmountDirSilent("data/test"); + else + VirtFs::unmountDirSilent("../data/test"); + + REQUIRE_THROWS(VirtFs::exists("test/../units.xml")); + + VirtFs::deinit(); + delete2(logger); +} + +TEST_CASE("throw VirtFs1 exists2", "") +{ + VirtFs::init("."); + logger = new Logger(); + const bool dir1 = VirtFs::mountDirSilent2("data/", + "test", + Append_false); + VirtFs::mountDirSilent2("..\\data", + "test", + Append_false); + + if (dir1 == true) + { + VirtFs::mountDir2("data//test", + "dir2", + Append_false); + } + else + { + VirtFs::mountDirSilent2("..//data\\test", + "dir2", + Append_false); + } + + if (dir1 == true) + VirtFs::unmountDirSilent2("data/test", "dir2"); + else + VirtFs::unmountDirSilent2("../data/test", "dir2"); + + REQUIRE_THROWS(VirtFs::exists("test/../units.xml")); + + VirtFs::deinit(); + delete2(logger); +} + +TEST_CASE("throw Zip readCompressedFile", "") +{ + logger = new Logger(); + std::string name("data/test/test.zip"); + std::string prefix; + if (Files::existsLocal(name) == false) + prefix = "../"; + + SECTION("empty") + { + REQUIRE_THROWS(VirtFs::ZipReader::readCompressedFile(nullptr)); + } + + delete2(logger); +} + +TEST_CASE("throw Zip readFile", "") +{ + logger = new Logger(); + std::string name("data/test/test.zip"); + std::string prefix; + if (Files::existsLocal(name) == false) + prefix = "../"; + + SECTION("empty") + { + REQUIRE_THROWS(VirtFs::ZipReader::readFile(nullptr)); + } + + delete2(logger); +} + +TEST_CASE("throw VirtFs1 unmount", "") +{ + VirtFs::init("."); + logger = new Logger(); + 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_THROWS(VirtFs::unmountDir("dir1")); + REQUIRE_THROWS(VirtFs::unmountDir("dir1/")); + } + + SECTION("simple 2") + { + REQUIRE(VirtFs::mountDirSilentTest("dir1", + Append_true)); + REQUIRE_THROWS(VirtFs::unmountDir("dir2")); + REQUIRE(VirtFs::unmountDir("dir1")); + } + + SECTION("simple 3") + { + REQUIRE(VirtFs::mountDirSilentTest("dir1", + Append_true)); + REQUIRE(VirtFs::mountDirSilentTest("dir2//dir3", + Append_true)); + REQUIRE(VirtFs::mountDirSilentTest("dir3", + Append_false)); + REQUIRE_THROWS(VirtFs::unmountDir("dir2")); + REQUIRE(VirtFs::unmountDir("dir1")); + REQUIRE_THROWS(VirtFs::unmountDir("dir1")); + REQUIRE(VirtFs::unmountDir("dir2/dir3")); + REQUIRE_THROWS(VirtFs::unmountDir("dir2/dir3" + sep)); + } + + SECTION("simple 4") + { + REQUIRE(VirtFs::mountDirSilentTest("dir1", + Append_true)); + REQUIRE_THROWS(VirtFs::unmountDir("dir2")); + REQUIRE(VirtFs::unmountDir("dir1")); + REQUIRE(VirtFs::mountDirSilentTest("dir1", + Append_true)); + } + + SECTION("subDir 1") + { + REQUIRE_THROWS(VirtFs::unmountDir2("dir1", "dir1")); + REQUIRE_THROWS(VirtFs::unmountDir2("dir1/", "dir1/")); + } + + SECTION("subDir 2") + { + REQUIRE(VirtFs::mountDirSilentTest2("dir1", + "dir2", + Append_true)); + REQUIRE_THROWS(VirtFs::unmountDir("dir1")); + REQUIRE_THROWS(VirtFs::unmountDir("dir2")); + REQUIRE(VirtFs::unmountDir2("dir1", "dir2")); + } + + SECTION("subDir 3") + { + REQUIRE(VirtFs::mountDirSilentTest2("dir1", + "dir2", + Append_true)); + REQUIRE(VirtFs::mountDirSilentTest("dir2//dir3", + Append_true)); + REQUIRE(VirtFs::mountDirSilentTest2("dir3", + "dir4", + Append_false)); + REQUIRE_THROWS(VirtFs::unmountDir("dir2")); + REQUIRE_THROWS(VirtFs::unmountDir2("dir1", "dir1")); + REQUIRE(VirtFs::unmountDir2("dir1", "dir2")); + REQUIRE_THROWS(VirtFs::unmountDir("dir1")); + REQUIRE(VirtFs::unmountDir("dir2/dir3")); + REQUIRE_THROWS(VirtFs::unmountDir("dir2/dir3" + sep)); + } + + SECTION("subDir 4") + { + REQUIRE(VirtFs::mountDirSilentTest2("dir1", + "dir2", + Append_true)); + REQUIRE_THROWS(VirtFs::unmountDir("dir2")); + REQUIRE_THROWS(VirtFs::unmountDir("dir1")); + REQUIRE(VirtFs::unmountDir2("dir1", "dir2")); + REQUIRE(VirtFs::mountDirSilentTest2("dir1", + "dir3", + Append_true)); + } + + VirtFs::deinit(); + delete2(logger); +} diff --git a/src/unittests/fs/virtfs/virtfs1_exists.cc b/src/unittests/fs/virtfs/virtfs1_exists.cc index 977572677..8f33d11d3 100644 --- a/src/unittests/fs/virtfs/virtfs1_exists.cc +++ b/src/unittests/fs/virtfs/virtfs1_exists.cc @@ -85,8 +85,6 @@ TEST_CASE("VirtFs1 exists1", "") REQUIRE(VirtFs::exists("units.xml") == false); REQUIRE(VirtFs::exists("units.xml/") == false); - REQUIRE_THROWS(VirtFs::exists("test/../units.xml")); - VirtFs::deinit(); delete2(logger); } @@ -156,8 +154,6 @@ TEST_CASE("VirtFs1 exists2", "") REQUIRE(VirtFs::exists("file1.txt") == false); REQUIRE(VirtFs::exists("file2.txt") == false); - REQUIRE_THROWS(VirtFs::exists("test/../units.xml")); - VirtFs::deinit(); delete2(logger); } diff --git a/src/unittests/fs/virtfs/virtfs1_unmount.cc b/src/unittests/fs/virtfs/virtfs1_unmount.cc index 5e6815d5c..61204ef27 100644 --- a/src/unittests/fs/virtfs/virtfs1_unmount.cc +++ b/src/unittests/fs/virtfs/virtfs1_unmount.cc @@ -44,17 +44,10 @@ TEST_CASE("VirtFs1 unmount", "") if (Files::existsLocal(name) == false) prefix = "../"; - SECTION("simple 1") - { - REQUIRE_THROWS(VirtFs::unmountDir("dir1")); - REQUIRE_THROWS(VirtFs::unmountDir("dir1/")); - } - SECTION("simple 2") { REQUIRE(VirtFs::mountDirSilentTest("dir1", Append_true)); - REQUIRE_THROWS(VirtFs::unmountDir("dir2")); REQUIRE(VirtFs::unmountDir("dir1")); } @@ -67,7 +60,6 @@ TEST_CASE("VirtFs1 unmount", "") REQUIRE(VirtFs::mountDirSilentTest("dir3", Append_false)); REQUIRE(VirtFs::getEntries().size() == 3); - REQUIRE_THROWS(VirtFs::unmountDir("dir2")); REQUIRE(VirtFs::unmountDir("dir1")); REQUIRE(VirtFs::getEntries().size() == 2); REQUIRE(VirtFs::getEntries()[0]->root == "dir3" + sep); @@ -80,7 +72,6 @@ TEST_CASE("VirtFs1 unmount", "") REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); REQUIRE(static_cast<VirtFs::DirEntry*>( VirtFs::getEntries()[1])->userDir == "dir2" + sep + "dir3"); - REQUIRE_THROWS(VirtFs::unmountDir("dir1")); REQUIRE(VirtFs::getEntries().size() == 2); REQUIRE(VirtFs::getEntries()[0]->root == "dir3" + sep); REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); @@ -93,7 +84,6 @@ TEST_CASE("VirtFs1 unmount", "") REQUIRE(static_cast<VirtFs::DirEntry*>( VirtFs::getEntries()[1])->userDir == "dir2" + sep + "dir3"); REQUIRE(VirtFs::unmountDir("dir2/dir3")); - REQUIRE_THROWS(VirtFs::unmountDir("dir2/dir3" + sep)); REQUIRE(VirtFs::getEntries().size() == 1); REQUIRE(VirtFs::getEntries()[0]->root == "dir3" + sep); REQUIRE(VirtFs::getEntries()[0]->subDir.empty()); @@ -112,7 +102,6 @@ TEST_CASE("VirtFs1 unmount", "") REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); REQUIRE(static_cast<VirtFs::DirEntry*>( VirtFs::getEntries()[0])->userDir == "dir1"); - REQUIRE_THROWS(VirtFs::unmountDir("dir2")); REQUIRE(VirtFs::unmountDir("dir1")); REQUIRE(VirtFs::getEntries().empty()); REQUIRE(VirtFs::mountDirSilentTest("dir1", @@ -214,19 +203,11 @@ TEST_CASE("VirtFs1 unmount", "") REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir); } - SECTION("subDir 1") - { - REQUIRE_THROWS(VirtFs::unmountDir2("dir1", "dir1")); - REQUIRE_THROWS(VirtFs::unmountDir2("dir1/", "dir1/")); - } - SECTION("subDir 2") { REQUIRE(VirtFs::mountDirSilentTest2("dir1", "dir2", Append_true)); - REQUIRE_THROWS(VirtFs::unmountDir("dir1")); - REQUIRE_THROWS(VirtFs::unmountDir("dir2")); REQUIRE(VirtFs::unmountDir2("dir1", "dir2")); } @@ -241,8 +222,6 @@ TEST_CASE("VirtFs1 unmount", "") "dir4", Append_false)); REQUIRE(VirtFs::getEntries().size() == 3); - REQUIRE_THROWS(VirtFs::unmountDir("dir2")); - REQUIRE_THROWS(VirtFs::unmountDir2("dir1", "dir1")); REQUIRE(VirtFs::unmountDir2("dir1", "dir2")); REQUIRE(VirtFs::getEntries().size() == 2); REQUIRE(VirtFs::getEntries()[0]->root == "dir3" + sep); @@ -255,7 +234,6 @@ TEST_CASE("VirtFs1 unmount", "") REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir); REQUIRE(static_cast<VirtFs::DirEntry*>( VirtFs::getEntries()[1])->userDir == "dir2" + sep + "dir3"); - REQUIRE_THROWS(VirtFs::unmountDir("dir1")); REQUIRE(VirtFs::getEntries().size() == 2); REQUIRE(VirtFs::getEntries()[0]->root == "dir3" + sep); REQUIRE(VirtFs::getEntries()[0]->subDir == "dir4" + sep); @@ -268,7 +246,6 @@ TEST_CASE("VirtFs1 unmount", "") REQUIRE(static_cast<VirtFs::DirEntry*>( VirtFs::getEntries()[1])->userDir == "dir2" + sep + "dir3"); REQUIRE(VirtFs::unmountDir("dir2/dir3")); - REQUIRE_THROWS(VirtFs::unmountDir("dir2/dir3" + sep)); REQUIRE(VirtFs::getEntries().size() == 1); REQUIRE(VirtFs::getEntries()[0]->root == "dir3" + sep); REQUIRE(VirtFs::getEntries()[0]->subDir == "dir4" + sep); @@ -288,8 +265,6 @@ TEST_CASE("VirtFs1 unmount", "") REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir); REQUIRE(static_cast<VirtFs::DirEntry*>( VirtFs::getEntries()[0])->userDir == "dir1"); - REQUIRE_THROWS(VirtFs::unmountDir("dir2")); - REQUIRE_THROWS(VirtFs::unmountDir("dir1")); REQUIRE(VirtFs::unmountDir2("dir1", "dir2")); REQUIRE(VirtFs::getEntries().empty()); REQUIRE(VirtFs::mountDirSilentTest2("dir1", diff --git a/src/unittests/fs/virtfs/zip.cc b/src/unittests/fs/virtfs/zip.cc index 6ea9063fe..50e0b2672 100644 --- a/src/unittests/fs/virtfs/zip.cc +++ b/src/unittests/fs/virtfs/zip.cc @@ -178,11 +178,6 @@ TEST_CASE("Zip readCompressedFile", "") if (Files::existsLocal(name) == false) prefix = "../"; - SECTION("empty") - { - REQUIRE_THROWS(VirtFs::ZipReader::readCompressedFile(nullptr)); - } - SECTION("test2.zip") { name = prefix + "data/test/test2.zip"; @@ -213,11 +208,6 @@ TEST_CASE("Zip readFile", "") if (Files::existsLocal(name) == false) prefix = "../"; - SECTION("empty") - { - REQUIRE_THROWS(VirtFs::ZipReader::readFile(nullptr)); - } - SECTION("test.zip") { name = prefix + "data/test/test.zip"; diff --git a/src/unittests/gui/windowmanager.cc b/src/unittests/gui/windowmanager.cc index 6090555ee..6a215d081 100644 --- a/src/unittests/gui/windowmanager.cc +++ b/src/unittests/gui/windowmanager.cc @@ -265,6 +265,7 @@ TEST_CASE("Windows tests", "windowmanager") mainGraphics->updateScreen(); delete2(dialog); delete2(being); + delete2(map); } SECTION("BuyingStoreSellDialog") { @@ -512,6 +513,7 @@ TEST_CASE("Windows tests", "windowmanager") gui->draw(); mainGraphics->updateScreen(); delete2(mailViewWindow); + delete(message); } SECTION("MailWindow") { diff --git a/src/unittests/resources/map/maplayer/drawfringenormal.cc b/src/unittests/resources/map/maplayer/drawfringenormal.cc index 84564ae64..6ab0a395c 100644 --- a/src/unittests/resources/map/maplayer/drawfringenormal.cc +++ b/src/unittests/resources/map/maplayer/drawfringenormal.cc @@ -35,6 +35,8 @@ #include "utils/delete2.h" #include "utils/env.h" +#include "resources/resourcemanager/resourcemanager.h" + #include "resources/sdlimagehelper.h" #include "resources/image/image.h" @@ -511,6 +513,8 @@ TEST_CASE("MapLayer drawFringe normal", "") delete mock; delete2(theme); GraphicsManager::deleteRenderers(); + ResourceManager::cleanOrphans(true); + ResourceManager::deleteInstance(); VirtFs::unmountDirSilent("data"); VirtFs::unmountDirSilent("../data"); delete2(logger); diff --git a/src/unittests/resources/map/maplayer/drawfringesimple.cc b/src/unittests/resources/map/maplayer/drawfringesimple.cc index fa24d3b94..6a362b8aa 100644 --- a/src/unittests/resources/map/maplayer/drawfringesimple.cc +++ b/src/unittests/resources/map/maplayer/drawfringesimple.cc @@ -33,6 +33,8 @@ #include "utils/delete2.h" #include "utils/env.h" +#include "resources/resourcemanager/resourcemanager.h" + #include "resources/sdlimagehelper.h" #include "resources/image/image.h" @@ -489,6 +491,8 @@ TEST_CASE("MapLayer drawFringe simple", "") delete mock; delete2(theme); GraphicsManager::deleteRenderers(); + ResourceManager::cleanOrphans(true); + ResourceManager::deleteInstance(); VirtFs::unmountDirSilent("data"); VirtFs::unmountDirSilent("../data"); delete2(logger); diff --git a/src/unittests/resources/map/maplayer/drawspeciallayer1.cc b/src/unittests/resources/map/maplayer/drawspeciallayer1.cc index 79cd056bb..3224eb5ef 100644 --- a/src/unittests/resources/map/maplayer/drawspeciallayer1.cc +++ b/src/unittests/resources/map/maplayer/drawspeciallayer1.cc @@ -31,6 +31,8 @@ #include "utils/delete2.h" #include "utils/env.h" +#include "resources/resourcemanager/resourcemanager.h" + #include "resources/sdlimagehelper.h" #include "resources/map/map.h" @@ -379,6 +381,8 @@ TEST_CASE("MapLayer drawSpecialLayer (specialLayer)", "") delete map; delete mock; GraphicsManager::deleteRenderers(); + ResourceManager::cleanOrphans(true); + ResourceManager::deleteInstance(); VirtFs::unmountDirSilent("data"); VirtFs::unmountDirSilent("../data"); delete2(logger); diff --git a/src/unittests/resources/map/maplayer/drawspeciallayer2.cc b/src/unittests/resources/map/maplayer/drawspeciallayer2.cc index e47ccdb97..0092b2019 100644 --- a/src/unittests/resources/map/maplayer/drawspeciallayer2.cc +++ b/src/unittests/resources/map/maplayer/drawspeciallayer2.cc @@ -31,6 +31,8 @@ #include "utils/delete2.h" #include "utils/env.h" +#include "resources/resourcemanager/resourcemanager.h" + #include "resources/sdlimagehelper.h" #include "resources/map/map.h" @@ -385,6 +387,8 @@ TEST_CASE("MapLayer drawSpecialLayer (tempLayer)", "") delete map; delete mock; GraphicsManager::deleteRenderers(); + ResourceManager::cleanOrphans(true); + ResourceManager::deleteInstance(); VirtFs::unmountDirSilent("data"); VirtFs::unmountDirSilent("../data"); delete2(logger); |