Skip to content

Commit

Permalink
Moved a test from integration tests to unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekazakov committed Feb 17, 2024
1 parent 259b560 commit d4e94ee
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
17 changes: 0 additions & 17 deletions Source/VFS/tests/VFSArchive_IT.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
[[clang::no_destroy]] static const auto g_Preffix = std::string(NCE(nc::env::test::ext_data_prefix)) + "archives/";
[[clang::no_destroy]] static const auto g_Angular = g_Preffix + "angular-1.4.0-beta.4.zip";
[[clang::no_destroy]] static const auto g_WarningArchive = g_Preffix + "maverix-master.zip";
[[clang::no_destroy]] static const auto g_ChineseArchive = g_Preffix + "GB18030.zip";

static int VFSCompareEntries(const std::filesystem::path &_file1_full_path,
const VFSHostPtr &_file1_host,
Expand Down Expand Up @@ -158,19 +157,3 @@ static int VFSCompareEntries(const std::filesystem::path &_file1_full_path,
auto ref = "'use strict';";
REQUIRE(std::memcmp(d->data(), ref, std::strlen(ref)) == 0);
}

TEST_CASE(PREFIX "chinese archive")
{
std::shared_ptr<ArchiveHost> host;
REQUIRE_NOTHROW(host = std::make_shared<ArchiveHost>(g_ChineseArchive.c_str(), TestEnv().vfs_native));

VFSFilePtr file;

REQUIRE(host->CreateFile(@"/操作系统原理/学生讲座/1.c".UTF8String, file, 0) == 0);
REQUIRE(file->Open(VFSFlags::OF_Read) == 0);

auto d = file->ReadFile();
REQUIRE(d->size() == 627);
auto ref = "#include <stdio.h>";
REQUIRE(std::memcmp(d->data(), ref, std::strlen(ref)) == 0);
}
33 changes: 33 additions & 0 deletions Source/VFS/tests/VFSArchive_UT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1842,3 +1842,36 @@ TEST_CASE(PREFIX "lzma support")
auto ref = "World";
REQUIRE(memcmp(d->data(), ref, strlen(ref)) == 0);
}

TEST_CASE(PREFIX "zip with GB18030-2020 support")
{
// This archive was made by Windows7 with a "Chinese (Simplified, PRC)" language.
const unsigned char arc_zip[] = {
0x50, 0x4b, 0x03, 0x04, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x83, 0x51, 0x58, 0x56, 0xcc, 0x2a,
0x9d, 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0xce, 0xac, 0xbb, 0xf9,
0xb0, 0xd9, 0xbf, 0xc6, 0xca, 0xc7, 0xca, 0xb2, 0xc3, 0xb4, 0x2f, 0xd2, 0xd4, 0xbc, 0xb0, 0xbe, 0xdf,
0xd3, 0xd0, 0xb0, 0xd9, 0xbf, 0xc6, 0xc8, 0xab, 0xca, 0xe9, 0xd6, 0xae, 0xd2, 0xe2, 0xb5, 0xc4, 0x2e,
0x74, 0x78, 0x74, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x21, 0x50, 0x4b, 0x01, 0x02, 0x14, 0x00, 0x14, 0x00,
0x00, 0x00, 0x00, 0x00, 0x78, 0x83, 0x51, 0x58, 0x56, 0xcc, 0x2a, 0x9d, 0x06, 0x00, 0x00, 0x00, 0x06,
0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xce, 0xac, 0xbb, 0xf9, 0xb0, 0xd9, 0xbf, 0xc6, 0xca, 0xc7, 0xca, 0xb2, 0xc3,
0xb4, 0x2f, 0xd2, 0xd4, 0xbc, 0xb0, 0xbe, 0xdf, 0xd3, 0xd0, 0xb0, 0xd9, 0xbf, 0xc6, 0xc8, 0xab, 0xca,
0xe9, 0xd6, 0xae, 0xd2, 0xe2, 0xb5, 0xc4, 0x2e, 0x74, 0x78, 0x74, 0x50, 0x4b, 0x05, 0x06, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x57, 0x00, 0x00, 0x00, 0x4d, 0x00, 0x00, 0x00, 0x00, 0x00};
TestDir dir;
const auto path = std::filesystem::path(dir.directory) / "arc_zip";
REQUIRE(nc::base::WriteAtomically(path, {reinterpret_cast<const std::byte *>(arc_zip), std::size(arc_zip)}));
std::shared_ptr<ArchiveHost> host;
REQUIRE_NOTHROW(host = std::make_shared<ArchiveHost>(path.c_str(), TestEnv().vfs_native));

VFSListingPtr listing;
REQUIRE(host->FetchDirectoryListing("/", listing, 0, nullptr) == VFSError::Ok);
REQUIRE(host->FetchDirectoryListing("/维基百科是什么", listing, 0, nullptr) == VFSError::Ok);

VFSFilePtr file;
auto fn = "/维基百科是什么/以及具有百科全书之意的.txt";
REQUIRE(host->CreateFile(fn, file, nullptr) == 0);
REQUIRE(file->Open(VFSFlags::OF_Read) == 0);
auto d = file->ReadFile();
CHECK(std::string_view{reinterpret_cast<const char *>(d.value().data()), d.value().size()} == "Hello!");
}

0 comments on commit d4e94ee

Please sign in to comment.