diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-03-28 23:24:41 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-03-28 23:25:13 +0300 |
commit | a85c68d09497c1242064998dbc19ffab4a485ab6 (patch) | |
tree | 892d42f143c009be898a648e28b9e61b9f8a4cb5 /src/fs | |
parent | 30df2c7248c2b58469aeb635a87a0ed978829c47 (diff) | |
download | manaplus-a85c68d09497c1242064998dbc19ffab4a485ab6.tar.gz manaplus-a85c68d09497c1242064998dbc19ffab4a485ab6.tar.bz2 manaplus-a85c68d09497c1242064998dbc19ffab4a485ab6.tar.xz manaplus-a85c68d09497c1242064998dbc19ffab4a485ab6.zip |
Add tests for VirtFs::loadFile.
Diffstat (limited to 'src/fs')
-rw-r--r-- | src/fs/virtfs/virtfs1_unittest.cc | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/fs/virtfs/virtfs1_unittest.cc b/src/fs/virtfs/virtfs1_unittest.cc index 902620303..ee8e97e3e 100644 --- a/src/fs/virtfs/virtfs1_unittest.cc +++ b/src/fs/virtfs/virtfs1_unittest.cc @@ -1419,3 +1419,63 @@ TEST_CASE("VirtFs1 read2") VirtFs::deinit(); delete2(logger); } + +TEST_CASE("VirtFs1 loadFile1") +{ + VirtFs::init("."); + int fileSize = 0; + logger = new Logger(); + std::string name("data/test/test.zip"); + std::string prefix; + if (Files::existsLocal(name) == false) + prefix = "../" + prefix; + + VirtFs::mountDir(prefix + "data", + Append_false); + + char *const buffer = VirtFs::loadFile("test/test.txt", fileSize); + REQUIRE(static_cast<void*>(buffer) != nullptr); + REQUIRE(fileSize == 23); + REQUIRE(strncmp(buffer, "test line 1\ntest line 2", 23) == 0); + delete [] buffer; + + VirtFs::unmountDir(prefix + "data"); + VirtFs::deinit(); + delete2(logger); +} + +TEST_CASE("VirtFs1 loadFile2") +{ + VirtFs::init("."); + int fileSize = 0; + logger = new Logger(); + std::string name("data/test/test.zip"); + std::string prefix; + if (Files::existsLocal(name) == false) + prefix = "../" + prefix; + + VirtFs::mountZip(prefix + "data/test/test2.zip", + Append_false); + + SECTION("test 1") + { + char *restrict buffer = VirtFs::loadFile("dir2//test.txt", fileSize); + REQUIRE(static_cast<void*>(buffer) != nullptr); + REQUIRE(fileSize == 23); + REQUIRE(strncmp(buffer, "test line 1\ntest line 2", 23) == 0); + delete [] buffer; + } + + SECTION("test 2") + { + char *restrict buffer = VirtFs::loadFile("dir2\\/test.txt", fileSize); + REQUIRE(static_cast<void*>(buffer) != nullptr); + REQUIRE(fileSize == 23); + REQUIRE(strncmp(buffer, "test line 1\ntest line 2", 23) == 0); + delete [] buffer; + } + + VirtFs::unmountZip(prefix + "data/test/test2.zip"); + VirtFs::deinit(); + delete2(logger); +} |