diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-03-02 20:29:42 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-03-02 20:29:42 +0300 |
commit | 6dd76d756ab20b474bd29d76be1899ae6c561e2a (patch) | |
tree | b9b54392ac75b3c13cd04ad730ad10cd8321c6fb /src | |
parent | 0665da9d5fe353069c418158fd9b6ecad75f0889 (diff) | |
download | plus-6dd76d756ab20b474bd29d76be1899ae6c561e2a.tar.gz plus-6dd76d756ab20b474bd29d76be1899ae6c561e2a.tar.bz2 plus-6dd76d756ab20b474bd29d76be1899ae6c561e2a.tar.xz plus-6dd76d756ab20b474bd29d76be1899ae6c561e2a.zip |
Add VirtFs for mounted zips and dirs order.
On this test VirtFs without physfs for now failing.
Diffstat (limited to 'src')
-rw-r--r-- | src/fs/virtfs_unittest.cc | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/fs/virtfs_unittest.cc b/src/fs/virtfs_unittest.cc index 057f641d5..228d0576a 100644 --- a/src/fs/virtfs_unittest.cc +++ b/src/fs/virtfs_unittest.cc @@ -846,3 +846,83 @@ TEST_CASE("VirtFs read3") VirtFs::removeDirFromSearchPath("../data"); delete2(logger); } + +TEST_CASE("VirtFs read4") +{ + logger = new Logger(); + VirtFs::addDirToSearchPath("data/test", Append_true); + VirtFs::addDirToSearchPath("../data/test", Append_true); + VirtFs::addZipToSearchPath("data/test/test5.zip", Append_true); + VirtFs::addZipToSearchPath("../data/test/test5.zip", Append_true); + + VirtFile *file = VirtFs::openRead("dir1/file1.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/test5.zip"); + VirtFs::removeZipFromSearchPath("../data/test/test5.zip"); + VirtFs::removeDirFromSearchPath("data/test"); + VirtFs::removeDirFromSearchPath("../data/test"); + delete2(logger); +} + +TEST_CASE("VirtFs read5") +{ + logger = new Logger(); + VirtFs::addZipToSearchPath("data/test/test5.zip", Append_true); + VirtFs::addZipToSearchPath("../data/test/test5.zip", Append_true); + VirtFs::addDirToSearchPath("data/test", Append_true); + VirtFs::addDirToSearchPath("../data/test", Append_true); + + VirtFile *file = VirtFs::openRead("dir1/file1.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 3\ntest line 4") == 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 4") == 0); + REQUIRE(VirtFs::eof(file) == true); + + VirtFs::close(file); + free(buffer); + + VirtFs::removeZipFromSearchPath("data/test/test5.zip"); + VirtFs::removeZipFromSearchPath("../data/test/test5.zip"); + VirtFs::removeDirFromSearchPath("data/test"); + VirtFs::removeDirFromSearchPath("../data/test"); + delete2(logger); +} |