summaryrefslogtreecommitdiff
path: root/src/fs/virtfs_unittest.cc
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-03-02 00:27:17 +0300
committerAndrei Karas <akaras@inbox.ru>2017-03-02 00:27:17 +0300
commit32061bfe63fce77accf1657a6631700c859fa541 (patch)
tree62ad40c3b71ab01295651fbfdfdd9547060bcc9f /src/fs/virtfs_unittest.cc
parent4998ec60e1f065a91fd45de2aea20c4d5a002a43 (diff)
downloadplus-32061bfe63fce77accf1657a6631700c859fa541.tar.gz
plus-32061bfe63fce77accf1657a6631700c859fa541.tar.bz2
plus-32061bfe63fce77accf1657a6631700c859fa541.tar.xz
plus-32061bfe63fce77accf1657a6631700c859fa541.zip
Fix some issues in virtfs and update tests.
Diffstat (limited to 'src/fs/virtfs_unittest.cc')
-rw-r--r--src/fs/virtfs_unittest.cc250
1 files changed, 249 insertions, 1 deletions
diff --git a/src/fs/virtfs_unittest.cc b/src/fs/virtfs_unittest.cc
index 5cbc9d237..2e9c1c31d 100644
--- a/src/fs/virtfs_unittest.cc
+++ b/src/fs/virtfs_unittest.cc
@@ -54,6 +54,9 @@ TEST_CASE("VirtFs exists1")
VirtFs::addDirToSearchPath("data", Append_false);
VirtFs::addDirToSearchPath("../data", Append_false);
+ REQUIRE(VirtFs::exists("test") == true);
+ REQUIRE(VirtFs::exists("test/dir1") == true);
+ REQUIRE(VirtFs::exists("test/dir") == false);
REQUIRE(VirtFs::exists("test/units.xml") == true);
REQUIRE(VirtFs::exists("test/units123.xml") == false);
REQUIRE(VirtFs::exists("tesQ/units.xml") == false);
@@ -62,6 +65,9 @@ TEST_CASE("VirtFs exists1")
VirtFs::addDirToSearchPath("data/test", Append_false);
VirtFs::addDirToSearchPath("../data/test", Append_false);
+ REQUIRE(VirtFs::exists("test") == true);
+ REQUIRE(VirtFs::exists("test/dir1") == true);
+ REQUIRE(VirtFs::exists("test/dir") == false);
REQUIRE(VirtFs::exists("test/units.xml") == true);
REQUIRE(VirtFs::exists("test/units123.xml") == false);
REQUIRE(VirtFs::exists("tesQ/units.xml") == false);
@@ -70,6 +76,9 @@ TEST_CASE("VirtFs exists1")
VirtFs::removeDirFromSearchPath("data/test");
VirtFs::removeDirFromSearchPath("../data/test");
+ REQUIRE(VirtFs::exists("test") == true);
+ REQUIRE(VirtFs::exists("test/dir1") == true);
+ REQUIRE(VirtFs::exists("test/dir") == false);
REQUIRE(VirtFs::exists("test/units.xml") == true);
REQUIRE(VirtFs::exists("test/units123.xml") == false);
REQUIRE(VirtFs::exists("tesQ/units.xml") == false);
@@ -86,9 +95,12 @@ TEST_CASE("VirtFs exists2")
VirtFs::addZipToSearchPath("data/test/test2.zip", Append_false);
VirtFs::addZipToSearchPath("../data/test/test2.zip", Append_false);
+ REQUIRE(VirtFs::exists("test") == false);
REQUIRE(VirtFs::exists("test/units.xml") == false);
REQUIRE(VirtFs::exists("test.txt") == true);
REQUIRE(VirtFs::exists("dir/hide.png") == true);
+ REQUIRE(VirtFs::exists("dir/gpl") == true);
+ REQUIRE(VirtFs::exists("dir/gpl/zzz") == false);
REQUIRE(VirtFs::exists("units.xml") == true);
REQUIRE(VirtFs::exists("units.xml.") == false);
REQUIRE(VirtFs::exists("units.xml2") == false);
@@ -98,6 +110,64 @@ TEST_CASE("VirtFs exists2")
delete2(logger);
}
+TEST_CASE("VirtFs exists3")
+{
+ logger = new Logger();
+ VirtFs::addZipToSearchPath("data/test/test.zip", Append_false);
+ VirtFs::addZipToSearchPath("../data/test/test.zip", Append_false);
+ VirtFs::addZipToSearchPath("data/test/test2.zip", Append_false);
+ VirtFs::addZipToSearchPath("../data/test/test2.zip", Append_false);
+
+ REQUIRE(VirtFs::exists("test") == false);
+ REQUIRE(VirtFs::exists("test/units.xml") == false);
+ REQUIRE(VirtFs::exists("dir/brimmedhat.png"));
+ REQUIRE(VirtFs::exists("dir//brimmedhat.png"));
+ REQUIRE(VirtFs::exists("dir//hide.png"));
+ REQUIRE(VirtFs::exists("dir/1"));
+ REQUIRE(VirtFs::exists("dir/gpl"));
+ REQUIRE(VirtFs::exists("dir/dye.png"));
+ REQUIRE(VirtFs::exists("dir/2") == false);
+ REQUIRE(VirtFs::exists("dir2/2") == false);
+ REQUIRE(VirtFs::exists("dir2/paths.xml"));
+
+ VirtFs::removeZipFromSearchPath("data/test/test.zip");
+ VirtFs::removeZipFromSearchPath("../data/test/test.zip");
+ VirtFs::removeZipFromSearchPath("data/test/test2.zip");
+ VirtFs::removeZipFromSearchPath("../data/test/test2.zip");
+ delete2(logger);
+}
+
+TEST_CASE("VirtFs exists4")
+{
+ logger = new Logger();
+ VirtFs::addZipToSearchPath("data/test/test.zip", Append_false);
+ VirtFs::addZipToSearchPath("../data/test/test.zip", Append_false);
+ VirtFs::addDirToSearchPath("data/test", Append_false);
+ VirtFs::addDirToSearchPath("../data/test", Append_false);
+
+ REQUIRE(VirtFs::exists("test") == false);
+ REQUIRE(VirtFs::exists("test/units.xml") == false);
+ REQUIRE(VirtFs::exists("dir/brimmedhat.png"));
+ REQUIRE(VirtFs::exists("dir//brimmedhat.png"));
+ REQUIRE(VirtFs::exists("dir//hide.png"));
+ REQUIRE(VirtFs::exists("dir/1") == false);
+ REQUIRE(VirtFs::exists("dir/gpl") == false);
+ REQUIRE(VirtFs::exists("dir/dye.png") == false);
+ REQUIRE(VirtFs::exists("dir/2") == false);
+ REQUIRE(VirtFs::exists("dir2/2") == false);
+ REQUIRE(VirtFs::exists("dir2/paths.xml") == false);
+ REQUIRE(VirtFs::exists("units.xml"));
+ REQUIRE(VirtFs::exists("dir1/file1.txt"));
+ REQUIRE(VirtFs::exists("dir2/file2.txt"));
+ REQUIRE(VirtFs::exists("dir2/file3.txt") == false);
+
+ VirtFs::removeZipFromSearchPath("data/test/test.zip");
+ VirtFs::removeZipFromSearchPath("../data/test/test.zip");
+ VirtFs::removeDirFromSearchPath("data/test");
+ VirtFs::removeDirFromSearchPath("../data/test");
+ delete2(logger);
+}
+
static void removeTemp(StringVect &restrict list)
{
int cnt = 0;
@@ -166,6 +236,11 @@ TEST_CASE("VirtFs enumerateFiles1")
REQUIRE(list->names.size() == cnt1);
VirtFs::freeList(list);
+ list = VirtFs::enumerateFiles("test/units.xml");
+ removeTemp(list->names);
+ REQUIRE(list->names.size() == 0);
+ VirtFs::freeList(list);
+
VirtFs::removeDirFromSearchPath("data");
VirtFs::removeDirFromSearchPath("../data");
delete2(logger);
@@ -237,6 +312,35 @@ TEST_CASE("VirtFs enumerateFiles4")
delete2(logger);
}
+TEST_CASE("VirtFs enumerateFiles5")
+{
+ logger = new Logger;
+
+ VirtFs::addZipToSearchPath("data/test/test2.zip",
+ Append_false);
+ VirtFs::addZipToSearchPath("../data/test/test2.zip",
+ Append_false);
+ VirtFs::addDirToSearchPath("data/test", Append_false);
+ VirtFs::addDirToSearchPath("../data/test", Append_false);
+
+ VirtList *list = nullptr;
+
+ list = VirtFs::enumerateFiles("dir2");
+ REQUIRE(inList(list, "file1.txt"));
+ REQUIRE(inList(list, "file2.txt"));
+ REQUIRE(inList(list, "hide.png"));
+ REQUIRE(inList(list, "paths.xml"));
+ REQUIRE(inList(list, "test.txt"));
+ REQUIRE(inList(list, "units.xml"));
+ VirtFs::freeList(list);
+
+ VirtFs::removeZipFromSearchPath("data/test/test2.zip");
+ VirtFs::removeZipFromSearchPath("../data/test/test2.zip");
+ VirtFs::removeDirFromSearchPath("data/test");
+ VirtFs::removeDirFromSearchPath("../data/test");
+ delete2(logger);
+}
+
TEST_CASE("VirtFs isDirectory1")
{
logger = new Logger();
@@ -311,6 +415,33 @@ TEST_CASE("VirtFs isDirectory2")
VirtFs::removeZipFromSearchPath("data/test/test2.zip");
VirtFs::removeZipFromSearchPath("../data/test/test2.zip");
+ delete2(logger);
+}
+
+TEST_CASE("VirtFs isDirectory3")
+{
+ logger = new Logger();
+ VirtFs::addDirToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("../data", Append_false);
+ 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("test"));
+ REQUIRE(VirtFs::isDirectory("test//dye.png") == false);
+ REQUIRE(VirtFs::isDirectory("dir"));
+ REQUIRE(VirtFs::isDirectory("dir/"));
+ REQUIRE(VirtFs::isDirectory("dir//"));
+ REQUIRE(VirtFs::isDirectory("dir2"));
+ REQUIRE(VirtFs::isDirectory("dir3") == false);
+ REQUIRE(VirtFs::isDirectory("test.txt") == false);
+ REQUIRE(VirtFs::isDirectory("dir/hide.png") == false);
+
+ VirtFs::removeZipFromSearchPath("data/test/test2.zip");
+ VirtFs::removeZipFromSearchPath("../data/test/test2.zip");
+ VirtFs::removeDirFromSearchPath("data");
+ VirtFs::removeDirFromSearchPath("../data");
+ delete2(logger);
}
TEST_CASE("VirtFs openRead1")
@@ -400,6 +531,40 @@ TEST_CASE("VirtFs openRead2")
delete2(logger);
}
+TEST_CASE("VirtFs openRead3")
+{
+ logger = new Logger();
+ VirtFs::addZipToSearchPath("data/test/test2.zip", Append_false);
+ VirtFs::addZipToSearchPath("../data/test/test2.zip", Append_false);
+ VirtFs::addDirToSearchPath("data/test", Append_false);
+ VirtFs::addDirToSearchPath("../data/test", 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);
+ file = VirtFs::openRead("dir/dye.png");
+ REQUIRE(file != nullptr);
+ VirtFs::close(file);
+ file = VirtFs::openRead("dir/dye.pn_");
+ REQUIRE(file == nullptr);
+
+ VirtFs::removeZipFromSearchPath("data/test/test2.zip");
+ VirtFs::removeZipFromSearchPath("../data/test/test2.zip");
+ VirtFs::removeDirFromSearchPath("data/test");
+ VirtFs::removeDirFromSearchPath("../data/test");
+ delete2(logger);
+}
+
TEST_CASE("VirtFs addZipToSearchPath")
{
// +++ need implement
@@ -410,7 +575,7 @@ TEST_CASE("VirtFs removeZipFromSearchPath")
// +++ need implement
}
-TEST_CASE("VirtFs getRealDir")
+TEST_CASE("VirtFs getRealDir1")
{
logger = new Logger();
REQUIRE(VirtFs::getRealDir(".") == "");
@@ -494,6 +659,49 @@ TEST_CASE("VirtFs getRealDir")
delete2(logger);
}
+TEST_CASE("VirtFs getrealDir2")
+{
+ logger = new Logger();
+ VirtFs::addZipToSearchPath("data/test/test2.zip", Append_false);
+ VirtFs::addZipToSearchPath("../data/test/test2.zip", Append_false);
+ VirtFs::addDirToSearchPath("data/test", Append_false);
+ VirtFs::addDirToSearchPath("../data/test", Append_false);
+ const bool dir1 = VirtFs::addDirToSearchPath("data", Append_false);
+ REQUIRE((dir1 || VirtFs::addDirToSearchPath("../data", Append_false)) ==
+ true);
+
+ REQUIRE(VirtFs::getRealDir("zzz") == "");
+
+ if (dir1 == true)
+ {
+ REQUIRE(VirtFs::getRealDir("dir1/file1.txt") ==
+ "data/test");
+ REQUIRE(VirtFs::getRealDir("hide.png") == "data/test");
+ REQUIRE(VirtFs::getRealDir("dir//hide.png") ==
+ "data/test/test2.zip");
+ REQUIRE(VirtFs::getRealDir("dir/1//test.txt") ==
+ "data/test/test2.zip");
+ }
+ else
+ {
+ REQUIRE(VirtFs::getRealDir("dir1/file1.txt") ==
+ "../data/test");
+ REQUIRE(VirtFs::getRealDir("hide.png") == "../data/test");
+ REQUIRE(VirtFs::getRealDir("dir//hide.png") ==
+ "../data/test/test2.zip");
+ REQUIRE(VirtFs::getRealDir("dir/1//test.txt") ==
+ "../data/test/test2.zip");
+ }
+
+ VirtFs::removeZipFromSearchPath("data/test/test2.zip");
+ VirtFs::removeZipFromSearchPath("../data/test/test2.zip");
+ VirtFs::removeDirFromSearchPath("data/test");
+ VirtFs::removeDirFromSearchPath("../data/test");
+ VirtFs::removeDirFromSearchPath("data");
+ VirtFs::removeDirFromSearchPath("../data");
+ delete2(logger);
+}
+
TEST_CASE("VirtFs permitLinks")
{
logger = new Logger();
@@ -598,3 +806,43 @@ TEST_CASE("VirtFs read2")
VirtFs::removeZipFromSearchPath("../data/test/test2.zip");
delete2(logger);
}
+
+TEST_CASE("VirtFs read3")
+{
+ logger = new Logger();
+ VirtFs::addZipToSearchPath("data/test/test2.zip", Append_false);
+ VirtFs::addZipToSearchPath("../data/test/test2.zip", Append_false);
+ VirtFs::addDirToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("../data", 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");
+ VirtFs::removeDirFromSearchPath("data");
+ VirtFs::removeDirFromSearchPath("../data");
+ delete2(logger);
+}