From c0677b055bf0159d1ac31644c6ac14618154b934 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Tue, 6 Jun 2017 19:05:52 +0800 Subject: [PATCH] Add CRC32 calculating support. --- MiniEngine_Test.cpp | 36 +++++++++++++++++++++++++++++++++++- MiniEngine_Test.h | 7 +++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/MiniEngine_Test.cpp b/MiniEngine_Test.cpp index f95f1a5..471fbe0 100644 --- a/MiniEngine_Test.cpp +++ b/MiniEngine_Test.cpp @@ -31,6 +31,41 @@ std::string GetMD5(unsigned char* buffer,unsigned int bufferLen) return str; } +/// Notice: SDLTest_crc32Calc is an undefined symbol. So we must use these 3 functions. +int GetCRC32(unsigned char* buffer,unsigned int bufferLen,uint32_t& out_CRCResult) +{ + uint32_t result; + SDLTest_Crc32Context ct; + SDLTest_Crc32Init(&ct); + + int ret=-2; + do + { + if (SDLTest_Crc32CalcStart(&ct,&result)) + { + ret=-1; + break; + } + if (SDLTest_Crc32CalcBuffer(&ct, buffer, bufferLen, &result)) + { + ret=-1; + break; + } + if (SDLTest_Crc32CalcEnd(&ct, &result)) + { + ret=-1; + break; + } + ret=0; + out_CRCResult=result; + break; + }while(0); + + SDLTest_Crc32Done(&ct); + + return ret; +} + /// Compare two surfaces. Currently, Surface::getRawPointer() does not has constant attribute. int CompareSurface(Surface& surface1, Surface& surface2, int allowableError) { @@ -60,7 +95,6 @@ uint32_t UniRandom::get() return SDLTest_Random(&(_sp.get()->context)); } - }/// End of namespace MiniEngine::Test }/// End of namespace MiniEngine diff --git a/MiniEngine_Test.h b/MiniEngine_Test.h index 2b71089..b05319b 100644 --- a/MiniEngine_Test.h +++ b/MiniEngine_Test.h @@ -10,6 +10,9 @@ namespace Test std::string GetMD5(unsigned char* buffer,unsigned int bufferLen); void GetMD5Raw(unsigned char* buffer,unsigned int bufferLen,unsigned char* outbuff); + +int GetCRC32(unsigned char* buffer,unsigned int bufferLen,uint32_t& out_CRCResult); + int CompareSurface(const Surface& surface1,const Surface& surface2,int allowableError); class UniRandom @@ -24,6 +27,10 @@ private: std::shared_ptr<_impl> _sp; }; +/// Not Implied : SDLTest_RandomAsciiString,SDLTest_RandomAsciiStringOfSize cause link error. +std::string GetRandomString(); +std::string GetRandomString(size_t length); + }/// End of namespace MiniEngine::Test }/// End of namespace MiniEngine