From a85c68d09497c1242064998dbc19ffab4a485ab6 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 28 Mar 2017 23:24:41 +0300 Subject: Add tests for VirtFs::loadFile. --- src/fs/virtfs/virtfs1_unittest.cc | 60 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'src/fs') 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(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(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(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); +} -- cgit v1.2.3-70-g09d2