added HashTest.cpp

This commit is contained in:
HuYingzhuo(hugo/hyzboy) 2023-07-21 19:44:43 +08:00
parent 7ca8c39354
commit 4d40490d43
2 changed files with 73 additions and 1 deletions

View File

@ -108,4 +108,7 @@ add_executable(PAttribTest utils/PAttribTest.cpp)
cm_example_project("utils" PAttribTest) cm_example_project("utils" PAttribTest)
add_executable(Base64Test utils/base64test.cpp) add_executable(Base64Test utils/base64test.cpp)
cm_example_project("utils" Base64Test) cm_example_project("utils" Base64Test)
add_executable(HashTest utils/HashTest.cpp)
cm_example_project("utils" HashTest)

69
utils/HashTest.cpp Normal file
View File

@ -0,0 +1,69 @@
#include<hgl/util/hash/Hash.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/Time.h>
#include<iostream>
#include<iomanip>
using namespace std;
using namespace hgl;
using namespace hgl::util;
#if HGL_OS == HGL_OS_Windows
int wmain(int argc,wchar_t **argv)
#else
int main(int argc,char **argv)
#endif//HGL_OS == HGL_OS_Windows
{
if(argc<2)
{
cout<<"CountHash [filename]"<<endl;
return(0);
}
#if HGL_OS == HGL_OS_Windows
wcout<<L"CountHash \""<<argv[1]<<L'"'<<endl;
#else
cout<<"CountHash \""<<argv[1]<<'"'<<endl;
#endif//HGL_OS == HGL_OS_Windows
void *file_data;
int64 file_length;
file_length=filesystem::LoadFileToMemory(argv[1],&file_data);
cout<<"file length: "<<file_length<<endl;
UTF8String hash_name;
int hash_length;
char *hash_code;
char hash_str[256];
double start_time,end_time;
ENUM_CLASS_FOR(HASH,int,i)
{
Hash *h=CreateHash(HASH(i));
hash_length=h->GetHashBytes();
hash_code=new char[hash_length];
start_time=GetDoubleTime();
h->Init();
h->Update(file_data,file_length);
h->Final(hash_code);
end_time=GetDoubleTime();
ToLowerHexStr(hash_str,hash_code,hash_length);
hash_str[hash_length*2]=0;
h->GetName(hash_name);
cout<<setw(8)<<hash_name.c_str()<<":"<<hash_str<<",use time: "<<(end_time-start_time)<<endl;
delete[] hash_code;
delete h;
}
}