diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-07-08 01:11:01 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-07-08 01:30:47 +0300 |
commit | d684e1087bca633f81f32472acea724515b0e718 (patch) | |
tree | 0c47f0c0e695359d422228a008beac7424d68791 /src/unittests/fs/virtfs/virtfs1_getrealdir.cc | |
parent | c5a777d78b5eb4a829bb7aec76d7ce629f810bb8 (diff) | |
download | manaplus-d684e1087bca633f81f32472acea724515b0e718.tar.gz manaplus-d684e1087bca633f81f32472acea724515b0e718.tar.bz2 manaplus-d684e1087bca633f81f32472acea724515b0e718.tar.xz manaplus-d684e1087bca633f81f32472acea724515b0e718.zip |
Split virtfs1_unittests.cc into many files for reduce memory usage.
Diffstat (limited to 'src/unittests/fs/virtfs/virtfs1_getrealdir.cc')
-rw-r--r-- | src/unittests/fs/virtfs/virtfs1_getrealdir.cc | 219 |
1 files changed, 219 insertions, 0 deletions
diff --git a/src/unittests/fs/virtfs/virtfs1_getrealdir.cc b/src/unittests/fs/virtfs/virtfs1_getrealdir.cc new file mode 100644 index 000000000..7b2f7915c --- /dev/null +++ b/src/unittests/fs/virtfs/virtfs1_getrealdir.cc @@ -0,0 +1,219 @@ +/* + * 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/direntry.h" +#include "fs/virtfs/fs.h" +#include "fs/virtfs/rwops.h" +#include "fs/virtfs/list.h" + +#include "utils/checkutils.h" +#include "utils/delete2.h" +#include "utils/foreach.h" +#include "utils/stringutils.h" + +PRAGMA48(GCC diagnostic push) +PRAGMA48(GCC diagnostic ignored "-Wshadow") +#include <SDL_rwops.h> +PRAGMA48(GCC diagnostic pop) + +#ifndef UNITTESTS_CATCH +#include <algorithm> +#endif // UNITTESTS_CATCH + +#include "debug.h" + +TEST_CASE("VirtFs1 getRealDir1", "") +{ + VirtFs::init("."); + logger = new Logger(); + const std::string sep = dirSeparator; + REQUIRE(VirtFs::getRealDir(".").empty()); + REQUIRE(VirtFs::getRealDir("..").empty()); + const bool dir1 = VirtFs::mountDirSilent("data", + Append_false); + REQUIRE((dir1 || VirtFs::mountDirSilent("../data", + Append_false)) == true); + if (dir1 == true) + { + REQUIRE(VirtFs::getRealDir("test") == "data"); + REQUIRE(VirtFs::getRealDir("test/test.txt") == + "data"); + REQUIRE(VirtFs::getRealDir("test\\test.txt") == + "data"); + REQUIRE(VirtFs::getRealDir("test//test.txt") == + "data"); + } + else + { + REQUIRE(VirtFs::getRealDir("test") == "../data"); + REQUIRE(VirtFs::getRealDir("test/test.txt") == + "../data"); + REQUIRE(VirtFs::getRealDir("test\\test.txt") == + "../data"); + REQUIRE(VirtFs::getRealDir("test//test.txt") == + "../data"); + } + REQUIRE(VirtFs::getRealDir("zzz").empty()); + + VirtFs::mountDirSilent("data/test", + Append_false); + VirtFs::mountDirSilent("../data/test", + Append_false); + if (dir1 == true) + { + REQUIRE(VirtFs::getRealDir("test") == "data"); + REQUIRE(VirtFs::getRealDir("test/test.txt") == + "data"); + REQUIRE(VirtFs::getRealDir("test\\test.txt") == + "data"); + REQUIRE(VirtFs::getRealDir("test.txt") == + "data" + sep + "test"); + } + else + { + REQUIRE(VirtFs::getRealDir("test") == ".." + sep + "data"); + REQUIRE(VirtFs::getRealDir("test/test.txt") == + ".." + sep + "data"); + REQUIRE(VirtFs::getRealDir("test\\test.txt") == + ".." + sep + "data"); + REQUIRE(VirtFs::getRealDir("test.txt") == + ".." + sep + "data" + sep + "test"); + } + REQUIRE(VirtFs::getRealDir("zzz").empty()); + + VirtFs::unmountDirSilent("data/test"); + VirtFs::unmountDirSilent("../data/test"); + + if (dir1 == true) + { + REQUIRE(VirtFs::getRealDir("test") == "data"); + REQUIRE(VirtFs::getRealDir("test/test.txt") == + "data"); + } + else + { + REQUIRE(VirtFs::getRealDir("test") == ".." + sep + "data"); + REQUIRE(VirtFs::getRealDir("test/test.txt") == + ".." + sep + "data"); + } + REQUIRE(VirtFs::getRealDir("zzz").empty()); + + VirtFs::unmountDirSilent("data"); + VirtFs::unmountDirSilent("../data"); + VirtFs::deinit(); + delete2(logger); +} + +TEST_CASE("VirtFs1 getRealDir2", "") +{ + VirtFs::init("."); + logger = new Logger(); + const std::string sep = dirSeparator; + std::string name("data/test/test.zip"); + std::string prefix("data" + sep + "test" + sep); + if (Files::existsLocal(name) == false) + prefix = ".." + sep + prefix; + VirtFs::mountZip(prefix + "test2.zip", + Append_false); + + REQUIRE(VirtFs::getRealDir(".").empty()); + REQUIRE(VirtFs::getRealDir("..").empty()); + REQUIRE(VirtFs::getRealDir("test.txt") == prefix + "test2.zip"); + REQUIRE(VirtFs::getRealDir("dir/1") == prefix + "test2.zip"); + REQUIRE(VirtFs::getRealDir("dir\\dye.png") == + prefix + "test2.zip"); + REQUIRE(VirtFs::getRealDir("zzz").empty()); + + VirtFs::mountZip(prefix + "test.zip", + Append_false); + REQUIRE(VirtFs::getRealDir("dir//dye.png") == + prefix + "test2.zip"); + REQUIRE(VirtFs::getRealDir("dir///hide.png") == + prefix + "test.zip"); + REQUIRE(VirtFs::getRealDir("dir\\\\brimmedhat.png") == + prefix + "test.zip"); + REQUIRE(VirtFs::getRealDir("zzz").empty()); + + VirtFs::unmountZip(prefix + "test.zip"); + + REQUIRE(VirtFs::getRealDir("dir/brimmedhat.png").empty()); + REQUIRE(VirtFs::getRealDir("test.txt") == prefix + "test2.zip"); + REQUIRE(VirtFs::getRealDir("dir//dye.png") == + prefix + "test2.zip"); + REQUIRE(VirtFs::getRealDir("zzz").empty()); + + VirtFs::unmountZip(prefix + "test2.zip"); + VirtFs::deinit(); + delete2(logger); +} + +TEST_CASE("VirtFs1 getRealDir3", "") +{ + VirtFs::init("."); + logger = new Logger(); + const std::string sep = dirSeparator; + REQUIRE(VirtFs::getRealDir(".").empty()); + REQUIRE(VirtFs::getRealDir("..").empty()); + const bool dir1 = VirtFs::mountDirSilent2("data", + "test", + Append_false); + REQUIRE((dir1 || VirtFs::mountDirSilent2("../data", + "test", + Append_false)) == true); + REQUIRE(VirtFs::getRealDir("file1.txt").empty()); + if (dir1 == true) + { + REQUIRE(VirtFs::getRealDir("dir1") == "data"); + REQUIRE(VirtFs::getRealDir("simplefile.txt") == "data"); + } + else + { + REQUIRE(VirtFs::getRealDir("dir1") == ".." + sep + "data"); + REQUIRE(VirtFs::getRealDir("simplefile.txt") == ".." + sep + "data"); + } + REQUIRE(VirtFs::getRealDir("zzz").empty()); + + VirtFs::mountDirSilent2("data/test", + "dir2", + Append_false); + VirtFs::mountDirSilent2("../data/test", + "dir2", + Append_false); + REQUIRE(VirtFs::getRealDir("dir").empty()); + if (dir1 == true) + { + REQUIRE(VirtFs::getRealDir("file1.txt") == "data" + sep + "test"); + REQUIRE(VirtFs::getRealDir("simplefile.txt") == "data"); + } + else + { + REQUIRE(VirtFs::getRealDir("file1.txt") == + ".." + sep + "data" + sep + "test"); + REQUIRE(VirtFs::getRealDir("simplefile.txt") == ".." + sep + "data"); + } + REQUIRE(VirtFs::getRealDir("zzz").empty()); + + VirtFs::deinit(); + delete2(logger); +} |