MCPcopy Create free account
hub / github.com/axmolengine/axmol / unzipTest

Function unzipTest

tests/cpp-tests/Source/ZipTest/ZipTests.cpp:44–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44static void unzipTest(Label* label,
45 std::string_view originFile,
46 std::string_view tmpName,
47 std::string_view zipFile,
48 std::string_view password = "")
49{
50
51 auto fu = FileUtils::getInstance();
52 ax::Data origContent;
53 const int BUFF_SIZE = 1024;
54 char* buff = nullptr;
55 std::vector<char> fileData;
56 bool hasError = false;
57 unz_file_info fileInfo = {0};
58 char fileName[40] = {0};
59
60 std::string newLocal{fu->getWritablePath()};
61 newLocal += tmpName;
62 // copy file to support android
63
64 if (fu->isFileExist(newLocal))
65 {
66 AXLOGD("Remove file {}", newLocal);
67 fu->removeFile(newLocal);
68 }
69
70 AXLOGD("Copy {} to {}", zipFile.data(), newLocal);
71 auto writeSuccess = fu->writeDataToFile(fu->getDataFromFile(zipFile), newLocal);
72 if (!writeSuccess)
73 {
74 label->setString("Failed to copy zip file to writable path");
75 return;
76 }
77
78 unzFile fp = unzOpen(newLocal.c_str());
79 if (!fp)
80 {
81 AXLOGD("Failed to open zip file {}", newLocal);
82 label->setString("Failed to open zip file");
83 return;
84 }
85
86 int err = unzGoToFirstFile(fp);
87 if (err != UNZ_OK)
88 {
89 label->setString("Failed to local first file");
90 goto close_and_return;
91 }
92
93 unzGetCurrentFileInfo(fp, &fileInfo, fileName, sizeof(fileName) - 1, nullptr, 0, nullptr, 0);
94
95 AXASSERT(strncmp("10k.txt", fileName, 7) == 0, "file name should be 10k.txt");
96
97 if (password.empty())
98 {
99 err = unzOpenCurrentFile(fp);
100 }
101 else

Callers 1

onEnterMethod · 0.85

Calls 15

getInstanceFunction · 0.85
unzOpenFunction · 0.85
unzGoToFirstFileFunction · 0.85
unzGetCurrentFileInfoFunction · 0.85
unzOpenCurrentFileFunction · 0.85
unzReadCurrentFileFunction · 0.85
unzCloseFunction · 0.85
writeDataToFileMethod · 0.80
getDataFromFileMethod · 0.80
getBytesMethod · 0.80
getWritablePathMethod · 0.45

Tested by

no test coverage detected