📄 test.cpp
字号:
if (p_abort) return;
// unzip a nonround multiple into a bigger buffer
{ hz=OpenZip(_T("\\z\\unztomem.zip"),0); if (hz==0) msg(_T("* Failed to open unztomem.zip"));
char buf[16384];
zr=UnzipItem(hz,0,buf,16384); if (zr!=ZR_OK) msg(_T("* Failed to unzip the buffer of unztomem-10k00"));
zr=CloseZip(hz); if (zr!=ZR_OK) msg(_T("* Failed to close unztomem.zip"));
}
if (p_abort) return;
// fixed bug: doesn't work on ARM, change lutime_t mtime = *(lutime_t*)(extra+epos); epos+=4; to lutime_t mtime; memcpy(&mtime,&extra[epos],4); epos+=4;. Also in TUnzip::Get, such atime and ctime
// fixed bug: (extrapos+epos) has size 4 while sizeof(lutime_t) is currently 8
msg(_T("time - testing whether timestamps are preserved on CE"));
{ TCHAR *c=_T("Time waits for no man\r\n");
hf=CreateFile(_T("\\z\\time.txt"),GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0); WriteFile(hf,c,(DWORD)(_tcslen(c)*sizeof(TCHAR)),&writ,0); CloseHandle(hf);
hf=CreateFile(_T("\\z\\time.txt"),GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0);
BY_HANDLE_FILE_INFORMATION fi; GetFileInformationByHandle(hf,&fi); CloseHandle(hf);
hz=CreateZip(_T("\\z\\time.zip"),0); if (hz==0) msg(_T("* Failed to create hello.zip"));
zr=ZipAdd(hz,_T("time.txt"),_T("\\z\\time.txt")); if (zr!=ZR_OK) msg(_T("* Failed to add time.txt"));
zr=CloseZip(hz); if (zr!=ZR_OK) msg(_T("* Failed to close time.zip"));
if (p_abort) return;
hz=OpenZip(_T("\\z\\time.zip"),0); if (hz==0) msg(_T("* Failed to open time.zip"));
zr=GetZipItem(hz,0,&ze); if (zr!=ZR_OK) msg(_T("* Failed to GetZipItem(time.txt)"));
zr=CloseZip(hz); if (zr!=ZR_OK) msg(_T("* Failed to close time.zip"));
if (!tsame(fi.ftCreationTime,ze.ctime)) msg(_T("* Failed to preserve creation time of hello.txt"));
if (!tsame(fi.ftLastWriteTime,ze.mtime)) msg(_T("* Failed to preserve modify time of hello.txt"));
if (!tsame(fi.ftLastAccessTime,ze.atime)) msg(_T("* Failed to preserve access time of hello.txt"));
if (p_abort) return;
}
// fixed bug: Some problem occurs in the library when reading the "extra field" removing the "extra field" the GetZipItem function functions. Some solution?
// fixed bug: unzipping a password-zipfile. Seems to miss 12chars from the original file. Line 3530: pfile_in_zip_read_info->rest_read_uncompressed-=uDoEncHead. Is this right?
msg(_T("extra - testing whether the extra headers cause problems, with passwords"));
if (GetFileAttributes(_T("\\z\\extra.zip"))!=0xFFFFFFFF)
{ hz=OpenZip(_T("\\z\\extra.zip"),0); if (hz==0) msg(_T("extra.zip is absent; can't do this test"));
zr=GetZipItem(hz,0,&ze); if (zr!=ZR_OK) msg(_T("* Failed to GetItem(extra.txt)"));
zr=UnzipItem(hz,0,_T("\\z\\extra.txt")); if (zr!=ZR_OK) msg(_T("* Failed to UnzipItem(extra.txt)"));
zr=CloseZip(hz); if (zr!=ZR_OK) msg(_T("* Failed to close extra.zip"));
if (p_abort) return;
hf=CreateFile(_T("\\z\\extra.txt"),GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0);
writ=GetFileSize(hf,0);
CloseHandle(hf);
if ((long)writ!=ze.unc_size) msg(_T("* Failed to unzip all of extra.txt"));
if (p_abort) return;
}
{ TCHAR *c=_T("Hello there this will have to be a very long file if I want to see what I want to see the quick brown fox jumped over the lazy dog and a merry time was had by all at the party few things are more distressing to a well-regulated mind than to see a boy who ought to know better disporting himself at improper moments\r\n");
hf=CreateFile(_T("\\z\\extrapp.txt"),GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0); WriteFile(hf,c,(DWORD)(_tcslen(c)*sizeof(TCHAR)),&writ,0); CloseHandle(hf);
hz=CreateZip(_T("\\z\\extrapp.zip"),"password"); if (hz==0) msg(_T("* Failed to create extrapp.zip"));
zr=ZipAdd(hz,_T("extrapp.txt"),_T("\\z\\extrapp.txt")); if (zr!=ZR_OK) msg(_T("* Failed to add extrapp.txt"));
zr=CloseZip(hz); if (zr!=ZR_OK) msg(_T("* Failed to close extrapp.zip"));
if (p_abort) return;
hz=OpenZip(_T("\\z\\extrapp.zip"),"password"); if (hz==0) msg(_T("* Failed to open extrapp.zip"));
zr=GetZipItem(hz,0,&ze); if (zr!=ZR_OK) msg(_T("* Failed to GetItem(extrapp.txt)"));
zr=UnzipItem(hz,0,_T("\\z\\extrapp.out.txt")); if (zr!=ZR_OK) msg(_T("* Failed to unzip extrapp.txt"));
zr=CloseZip(hz); if (zr!=ZR_OK) msg(_T("* Failed to close extrapp.zip"));
if (!fsame(_T("\\z\\extrapp.txt"),_T("\\z\\extrapp.out.txt"))) msg(_T("* Failed to unzip all of extrapp.txt"));
if (p_abort) return;
}
// fixed bug: XP(zip)->CE(unzip) works, and Winzip->CE(unzip) works, but CE(zip)->CE(unzip) doesn't.
msg(_T("ce2ce - testing whether ce zipping and unzipping work"));
if (GetFileAttributes(_T("\\z\\ce2ce.jpg"))!=0xFFFFFFFF && GetFileAttributes(_T("\\z\\ce2ce.txt"))!=0xFFFFFFFF)
{ hz=CreateZip(_T("\\z\\ce2ce.zip"),0); if (hz==0) msg(_T("* Failed to create ce2ce.zip"));
zr=ZipAdd(hz,_T("ce2ce.out.jpg"),_T("\\z\\ce2ce.jpg")); if (zr!=ZR_OK) msg(_T("* Failed to zip ce2ce.jpg"));
zr=ZipAdd(hz,_T("ce2ce.out.txt"),_T("\\z\\ce2ce.txt")); if (zr!=ZR_OK) msg(_T("* Failed to zip ce2ce.txt"));
zr=CloseZip(hz); if (zr!=ZR_OK) msg(_T("* Failed to close ce2ce.zip"));
if (p_abort) return;
hz=OpenZip(_T("\\z\\ce2ce.zip"),0); if (hz==0) msg(_T("* Failed to open ce2ce.zip"));
zr=SetUnzipBaseDir(hz,_T("\\z")); if (zr!=ZR_OK) msg(_T("* Failed to set base dir for ce2ce.zip"));
zr=GetZipItem(hz,-1,&ze); if (zr!=ZR_OK) msg(_T("* Failed to get index of ce2ce.zip"));
zr=GetZipItem(hz,0,&ze); if (zr!=ZR_OK) msg(_T("* Failed to GetItem(ce2ce.jpg)"));
zr=UnzipItem(hz,0,ze.name); if (zr!=ZR_OK) msg(_T("* Failed to unzip ce2ce.out.jpg"));
zr=GetZipItem(hz,1,&ze); if (zr!=ZR_OK) msg(_T("* Failed to GetItem(ce2ce.txt)"));
zr=UnzipItem(hz,1,ze.name); if (zr!=ZR_OK) msg(_T("* Failed to unzip ce2ce.out.txt"));
zr=CloseZip(hz); if (zr!=ZR_OK) msg(_T("* Failed to close ce2ce.zip"));
if (!fsame(_T("\\z\\ce2ce.jpg"),_T("\\z\\ce2ce.out.jpg"))) msg(_T("* Failed to unzip all of ce2ce.jpg"));
if (!fsame(_T("\\z\\ce2ce.txt"),_T("\\z\\ce2ce.out.txt"))) msg(_T("* Failed to unzip all of ce2ce.txt"));
if (p_abort) return;
}
// fixed bug: doesn't work with multiple levels of subfolder
// fixed bug: EnsureDirectory, bug: line 3940 of unzip, replace _tcscat(cd,name); with _tcscat(cd,dir); otherwise root directories are never created!
msg(_T("folders - testing whether unzip to subfolders works"));
{ TCHAR *c=_T("Hello just a dummy file\r\n");
hf=CreateFile(_T("\\z\\folders.txt"),GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0); WriteFile(hf,c,(DWORD)(_tcslen(c)*sizeof(TCHAR)),&writ,0); CloseHandle(hf);
hz=CreateZip(_T("\\z\\folders.zip"),0); if (hz==0) msg(_T("* Failed to create folders.zip"));
zr=ZipAdd(hz,_T("folders.out.txt"),_T("\\z\\folders.txt")); if (zr!=ZR_OK) msg(_T("* Failed to add folders.txt"));
zr=ZipAdd(hz,_T("sub1\\folders.out.txt"),_T("\\z\\folders.txt")); if (zr!=ZR_OK) msg(_T("* Failed to add sub1\\folders.txt"));
zr=ZipAdd(hz,_T("sub1\\sub2\\folders.out.txt"),_T("\\z\\folders.txt")); if (zr!=ZR_OK) msg(_T("* Failed to add sub1\\sub2\\folders.txt"));
zr=ZipAdd(hz,_T("sub1\\sub2\\sub3\\sub4\\folders.out.txt"),_T("\\z\\folders.txt")); if (zr!=ZR_OK) msg(_T("* Failed to add sub1\\sub2\\sub3\\sub4\\folders.txt"));
zr=ZipAddFolder(hz,_T("sub1\\sub5\\sub6")); if (zr!=ZR_OK) msg(_T("* Failed to add sub1\\sub5\\sub6"));
zr=CloseZip(hz); if (zr!=ZR_OK) msg(_T("* Failed to close folders.zip"));
if (p_abort) return;
hz=OpenZip(_T("\\z\\folders.zip"),0); if (hz==0) msg(_T("* Failed to open folders.zip"));
zr=SetUnzipBaseDir(hz,_T("\\z")); if (zr!=ZR_OK) msg(_T("* Failed to set base dir for folders.zip"));
zr=GetZipItem(hz,-1,&ze); if (zr!=ZR_OK) msg(_T("* Failed to get index of folders.zip"));
int numitems=ze.index; for (int i=0; i<numitems; i++)
{ zr=GetZipItem(hz,i,&ze); if (zr!=ZR_OK) {wsprintf(m,_T("* Failed to get index %i of folders.zip"),i); msg(m);}
zr=UnzipItem(hz,i,ze.name); if (zr!=ZR_OK) {wsprintf(m,_T("* Failed to unzip item %i of folders.zip"),i); msg(m);}
TCHAR absfn[MAX_PATH]; wsprintf(absfn,_T("\\z\\%s"),ze.name);
if ((ze.attr&FILE_ATTRIBUTE_DIRECTORY)==0 && !fsame(_T("\\z\\folders.txt"),absfn)) {wsprintf(m,_T("* Failed to unzip all of item %i of folders.zip"),i); msg(m);}
}
zr=CloseZip(hz); if (zr!=ZR_OK) msg(_T("* Failed to close folders.zip"));
if (p_abort) return;
}
// fixed bug: it skips first few (8/12) bytes when extracting a big file (27760609; 17838044 is okay)
msg(_T("skip - testing whether it skips bytes when extracting big files... (will take a while)"));
{ DWORD size= (fast) ? 277606 : 27760609;
char *c=new char[size]; for (DWORD i=0; i<size; i++) c[i]=(char)(rand()%255);
HANDLE hf = CreateFile(_T("\\z\\skip.dat"),GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
DWORD writ; WriteFile(hf,c,size,&writ,0);
CloseHandle(hf);
delete[] c;
if (p_abort) return;
//
hz=CreateZip(_T("\\z\\skip.zip"),0); if (hz==0) msg(_T("* Failed to create skip.zip"));
zr=ZipAdd(hz,_T("skip.dat"),_T("\\z\\skip.dat")); if (zr!=ZR_OK) msg(_T("* Failed to add skip.dat"));
zr=CloseZip(hz); if (zr!=ZR_OK) msg(_T("* Failed to close skip.zip"));
if (p_abort) return;
hz=OpenZip(_T("\\z\\skip.zip"),0); if (hz==0) msg(_T("* Failed to open skip.zip"));
zr=UnzipItem(hz,0,_T("\\z\\skip.out.dat")); if (zr!=ZR_OK) msg(_T("* Failed to unzip skip.out.zip"));
zr=CloseZip(hz); if (zr!=ZR_OK) msg(_T("* Failed to close skip.zip"));
if (!fsame(_T("\\z\\skip.dat"),_T("\\z\\skip.out.dat"))) msg(_T("* Failed to unzip all of skip.zip"));
if (p_abort) return;
}
// fixed bug: had problems with big files
msg(_T("win - testing with zipping up the whole windows directory... (will take a while)"));
hz=CreateZip(_T("\\z\\win.big"),0); if (hz==0) msg(_T("* Failed to create win.big"));
DWORD tot=0, max=fast?1*1024*1024:30*1024*1024; WIN32_FIND_DATA fdat; HANDLE hfind=FindFirstFile(_T("\\windows\\*"),&fdat);
for (BOOL gotmore=(hfind!=INVALID_HANDLE_VALUE); gotmore; gotmore=FindNextFile(hfind,&fdat))
{ if (fdat.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) continue;
if (fdat.cFileName[0]=='$') continue;
TCHAR src[MAX_PATH]; wsprintf(src,_T("\\windows\\%s"),fdat.cFileName);
TCHAR dst[MAX_PATH]; wsprintf(dst,_T("out_%s"),fdat.cFileName);
wsprintf(m,_T(".%s (%i%%)"),src,(tot*100/max)); msg(m);
HANDLE hf=CreateFile(src,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0);
if (hf==INVALID_HANDLE_VALUE) continue; tot+=GetFileSize(hf,0);
CloseHandle(hf);
zr=ZipAdd(hz,dst,src); if (zr!=ZR_OK) {wsprintf(m,_T("* Failed to add %s to win.big"),src); msg(m);}
if (tot>max) break;
if (p_abort) break;
}
if (hfind!=INVALID_HANDLE_VALUE) FindClose(hfind);
zr=CloseZip(hz); if (zr!=ZR_OK) msg(_T("* Failed to close win.big"));
if (p_abort) return;
//
hz=CreateZip(_T("\\z\\big.zip"),0); if (hz==0) msg(_T("* Failed to create big.zip"));
zr=ZipAdd(hz,_T("win.out.big"),_T("\\z\\win.big")); if (zr!=ZR_OK) msg(_T("* Failed to add win.big to big.zip"));
zr=CloseZip(hz); if (zr!=ZR_OK) msg(_T("* Failed to close big.zip"));
if (p_abort) return;
hz=OpenZip(_T("\\z\\big.zip"),0); if (hz==0) msg(_T("* Failed to open big.zip"));
zr=UnzipItem(hz,0,_T("\\z\\win.out.big")); if (zr!=ZR_OK) msg(_T("* Failed to unzip win.big"));
zr=CloseZip(hz); if (zr!=ZR_OK) msg(_T("* Failed to close big.zip"));
if (!fsame(_T("\\z\\win.big"),_T("\\z\\win.out.big"))) msg(_T("* Failed to unzip all of win.big"));
if (p_abort) return;
if (any_errors) msg(_T("Finished"));
else msg(_T("Finished. No errors."));
}
// and when compiling for windows-ce we need winmain...
#ifdef UNDER_CE
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPWSTR,int) {main(); return 0;}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -