summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-02-28 21:29:33 +0300
committerAndrei Karas <akaras@inbox.ru>2017-02-28 21:29:33 +0300
commit6583c1a039a28a41a865b02598e6da9521046325 (patch)
tree6f1f51085f5b8f8e513dbf39ce24529e6de0474a
parent993e6f9b9606a71ad35302f0767017fd426c1d0e (diff)
downloadmanaplus-6583c1a039a28a41a865b02598e6da9521046325.tar.gz
manaplus-6583c1a039a28a41a865b02598e6da9521046325.tar.bz2
manaplus-6583c1a039a28a41a865b02598e6da9521046325.tar.xz
manaplus-6583c1a039a28a41a865b02598e6da9521046325.zip
Add test with zip archives into VirtFs.
-rw-r--r--src/fs/virtfs_unittest.cc105
-rw-r--r--src/fs/virtfsphys_unittest.cc18
2 files changed, 119 insertions, 4 deletions
diff --git a/src/fs/virtfs_unittest.cc b/src/fs/virtfs_unittest.cc
index 7e079e212..5cbc9d237 100644
--- a/src/fs/virtfs_unittest.cc
+++ b/src/fs/virtfs_unittest.cc
@@ -48,7 +48,7 @@ TEST_CASE("VirtFs getUserDir")
REQUIRE(VirtFs::getUserDir() != nullptr);
}
-TEST_CASE("VirtFs exists")
+TEST_CASE("VirtFs exists1")
{
logger = new Logger();
VirtFs::addDirToSearchPath("data", Append_false);
@@ -80,6 +80,24 @@ TEST_CASE("VirtFs exists")
delete2(logger);
}
+TEST_CASE("VirtFs exists2")
+{
+ logger = new Logger();
+ VirtFs::addZipToSearchPath("data/test/test2.zip", Append_false);
+ VirtFs::addZipToSearchPath("../data/test/test2.zip", Append_false);
+
+ REQUIRE(VirtFs::exists("test/units.xml") == false);
+ REQUIRE(VirtFs::exists("test.txt") == true);
+ REQUIRE(VirtFs::exists("dir/hide.png") == true);
+ REQUIRE(VirtFs::exists("units.xml") == true);
+ REQUIRE(VirtFs::exists("units.xml.") == false);
+ REQUIRE(VirtFs::exists("units.xml2") == false);
+
+ VirtFs::removeZipFromSearchPath("data/test/test2.zip");
+ VirtFs::removeZipFromSearchPath("../data/test/test2.zip");
+ delete2(logger);
+}
+
static void removeTemp(StringVect &restrict list)
{
int cnt = 0;
@@ -219,7 +237,7 @@ TEST_CASE("VirtFs enumerateFiles4")
delete2(logger);
}
-TEST_CASE("VirtFs isDirectory")
+TEST_CASE("VirtFs isDirectory1")
{
logger = new Logger();
VirtFs::addDirToSearchPath("data", Append_false);
@@ -277,7 +295,25 @@ TEST_CASE("VirtFs isDirectory")
delete2(logger);
}
-TEST_CASE("VirtFs openRead")
+TEST_CASE("VirtFs isDirectory2")
+{
+ logger = new Logger();
+ VirtFs::addZipToSearchPath("data/test/test2.zip", Append_false);
+ VirtFs::addZipToSearchPath("../data/test/test2.zip", Append_false);
+
+ REQUIRE(VirtFs::isDirectory("test/units.xml") == false);
+ REQUIRE(VirtFs::isDirectory("dir") == true);
+ REQUIRE(VirtFs::isDirectory("dir/") == true);
+ REQUIRE(VirtFs::isDirectory("dir//") == true);
+ REQUIRE(VirtFs::isDirectory("dir2") == true);
+ REQUIRE(VirtFs::isDirectory("dir3") == false);
+ REQUIRE(VirtFs::isDirectory("test.txt") == false);
+
+ VirtFs::removeZipFromSearchPath("data/test/test2.zip");
+ VirtFs::removeZipFromSearchPath("../data/test/test2.zip");
+}
+
+TEST_CASE("VirtFs openRead1")
{
logger = new Logger();
VirtFs::addDirToSearchPath("data", Append_false);
@@ -339,6 +375,31 @@ TEST_CASE("VirtFs openRead")
delete2(logger);
}
+TEST_CASE("VirtFs openRead2")
+{
+ logger = new Logger();
+ VirtFs::addZipToSearchPath("data/test/test2.zip", Append_false);
+ VirtFs::addZipToSearchPath("../data/test/test2.zip", Append_false);
+
+ VirtFile *file = nullptr;
+
+ file = VirtFs::openRead("test/units.xml");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("units.xml");
+ REQUIRE(file != nullptr);
+ VirtFs::close(file);
+ file = VirtFs::openRead("dir/hide.png");
+ REQUIRE(file != nullptr);
+ VirtFs::close(file);
+ file = VirtFs::openRead("dir//hide.png");
+ REQUIRE(file != nullptr);
+ VirtFs::close(file);
+
+ VirtFs::removeZipFromSearchPath("data/test/test2.zip");
+ VirtFs::removeZipFromSearchPath("../data/test/test2.zip");
+ delete2(logger);
+}
+
TEST_CASE("VirtFs addZipToSearchPath")
{
// +++ need implement
@@ -466,7 +527,7 @@ TEST_CASE("VirtFs permitLinks")
delete2(logger);
}
-TEST_CASE("VirtFs read")
+TEST_CASE("VirtFs read1")
{
logger = new Logger();
VirtFs::addDirToSearchPath("data", Append_false);
@@ -501,3 +562,39 @@ TEST_CASE("VirtFs read")
VirtFs::removeDirFromSearchPath("../data");
delete2(logger);
}
+
+TEST_CASE("VirtFs read2")
+{
+ logger = new Logger();
+ VirtFs::addZipToSearchPath("data/test/test2.zip", Append_false);
+ VirtFs::addZipToSearchPath("../data/test/test2.zip", Append_false);
+
+ VirtFile *file = VirtFs::openRead("dir2/test.txt");
+ REQUIRE(file != nullptr);
+ REQUIRE(VirtFs::fileLength(file) == 23);
+ const int fileSize = VirtFs::fileLength(file);
+
+ void *restrict buffer = calloc(fileSize + 1, 1);
+ REQUIRE(VirtFs::read(file, buffer, 1, fileSize) == fileSize);
+ REQUIRE(strcmp(static_cast<char*>(buffer),
+ "test line 1\ntest line 2") == 0);
+ REQUIRE(VirtFs::tell(file) == fileSize);
+ REQUIRE(VirtFs::eof(file) == true);
+
+ free(buffer);
+ buffer = calloc(fileSize + 1, 1);
+ REQUIRE(VirtFs::seek(file, 12) != 0);
+ REQUIRE(VirtFs::eof(file) == false);
+ REQUIRE(VirtFs::tell(file) == 12);
+ REQUIRE(VirtFs::read(file, buffer, 1, 11) == 11);
+ REQUIRE(strcmp(static_cast<char*>(buffer),
+ "test line 2") == 0);
+ REQUIRE(VirtFs::eof(file) == true);
+
+ VirtFs::close(file);
+ free(buffer);
+
+ VirtFs::removeZipFromSearchPath("data/test/test2.zip");
+ VirtFs::removeZipFromSearchPath("../data/test/test2.zip");
+ delete2(logger);
+}
diff --git a/src/fs/virtfsphys_unittest.cc b/src/fs/virtfsphys_unittest.cc
index d9821d350..cb7013248 100644
--- a/src/fs/virtfsphys_unittest.cc
+++ b/src/fs/virtfsphys_unittest.cc
@@ -89,6 +89,24 @@ TEST_CASE("VirtFsPhys exists")
delete2(logger);
}
+TEST_CASE("VirtFsPhys exists2")
+{
+ VirtFsPhys::initFuncs();
+ logger = new Logger();
+ VirtFsPhys::addZipToSearchPath("data/test/test2.zip", Append_false);
+ VirtFsPhys::addZipToSearchPath("../data/test/test2.zip", Append_false);
+
+ REQUIRE(VirtFsPhys::exists("test/units.xml") == false);
+ REQUIRE(VirtFsPhys::exists("test.txt") == true);
+ REQUIRE(VirtFsPhys::exists("units123.xml") == false);
+ REQUIRE(VirtFsPhys::exists("tesQ/units.xml") == false);
+ REQUIRE(VirtFsPhys::exists("units.xml") == true);
+
+ VirtFsPhys::removeZipFromSearchPath("data/test/test2.zip");
+ VirtFsPhys::removeZipFromSearchPath("../data/test/test2.zip");
+ delete2(logger);
+}
+
static void removeTemp(StringVect &restrict list)
{
int cnt = 0;