From 1e8a0d6155b2edf1dc6cc1bdd749325e258933bb Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Tue, 23 May 2017 12:26:36 +0800 Subject: [PATCH 1/4] Add SDLTest lib support --- MiniEngine_Test.cpp | 37 +++++++++++++++++++++++++++++++++++++ MiniEngine_Test.h | 15 +++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 MiniEngine_Test.cpp create mode 100644 MiniEngine_Test.h diff --git a/MiniEngine_Test.cpp b/MiniEngine_Test.cpp new file mode 100644 index 0000000..8a36cb1 --- /dev/null +++ b/MiniEngine_Test.cpp @@ -0,0 +1,37 @@ +#include "MiniEngine_Test.h" +#include +#include + +namespace MiniEngine +{ + +namespace Test +{ + +void GetMD5Raw(unsigned char* buffer,unsigned int bufferLen,unsigned char* outbuff) +{ + SDLTest_Md5Context ct; + SDLTest_Md5Init(&ct); + SDLTest_Md5Update(&ct,buffer,bufferLen); + SDLTest_Md5Final(&ct); + memcpy(outbuff,ct.digest,16); +} + +std::string GetMD5(unsigned char* buffer,unsigned int bufferLen) +{ + unsigned char buff[16]; + char tmp[8]; + GetMD5Raw(buffer,bufferLen,buff); + std::string str; + for(int i=0;i<16;i++) + { + sprintf(tmp,"%02x",buff[i]); + str.append(tmp); + } + return str; +} + + +}/// End of namespace MiniEngine::Test + +}/// End of namespace MiniEngine diff --git a/MiniEngine_Test.h b/MiniEngine_Test.h new file mode 100644 index 0000000..879fa90 --- /dev/null +++ b/MiniEngine_Test.h @@ -0,0 +1,15 @@ +#pragma once +#include + +namespace MiniEngine +{ + +namespace Test +{ + +std::string GetMD5(unsigned char* buffer,unsigned int bufferLen); +void GetMD5Raw(unsigned char* buffer,unsigned int bufferLen,unsigned char* outbuff); + +}/// End of namespace MiniEngine::Test + +}/// End of namespace MiniEngine From d8e2bb9e2b01e75ed4a00473cc99fe1f20ea6a92 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Wed, 24 May 2017 18:17:29 +0800 Subject: [PATCH 2/4] Add Surface compare function. Build Notice!: I got a link error while compiling the full project. The link error is "undefined reference to SDL_GetRGBA" and "undefined reference to SDL_snprintf"... Currently there is one way to solve it : Link SDL2test.lib first (Before SDL2 and SDL2main) --- MiniEngine_Test.cpp | 4 ++++ MiniEngine_Test.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/MiniEngine_Test.cpp b/MiniEngine_Test.cpp index 8a36cb1..9e9db92 100644 --- a/MiniEngine_Test.cpp +++ b/MiniEngine_Test.cpp @@ -31,6 +31,10 @@ std::string GetMD5(unsigned char* buffer,unsigned int bufferLen) return str; } +int CompareSurface(const Surface& surface1, const Surface& surface2, int allowableError) +{ + return SDLTest_CompareSurfaces(surface1.getRawPointer(),surface2.getRawPointer(),allowableError); +} }/// End of namespace MiniEngine::Test diff --git a/MiniEngine_Test.h b/MiniEngine_Test.h index 879fa90..3d6389a 100644 --- a/MiniEngine_Test.h +++ b/MiniEngine_Test.h @@ -1,4 +1,5 @@ #pragma once +#include "MiniEngine.h" #include namespace MiniEngine @@ -9,6 +10,7 @@ namespace Test std::string GetMD5(unsigned char* buffer,unsigned int bufferLen); void GetMD5Raw(unsigned char* buffer,unsigned int bufferLen,unsigned char* outbuff); +int CompareSurface(const Surface& surface1,const Surface& surface2,int allowableError); }/// End of namespace MiniEngine::Test From e183a09f34d44a890b8b428b13c8d19b72938e30 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Tue, 6 Jun 2017 18:38:28 +0800 Subject: [PATCH 3/4] Add class UniRandom. (Random Number Generator) --- MiniEngine_Test.cpp | 27 ++++++++++++++++++++++++++- MiniEngine_Test.h | 12 ++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/MiniEngine_Test.cpp b/MiniEngine_Test.cpp index 9e9db92..f95f1a5 100644 --- a/MiniEngine_Test.cpp +++ b/MiniEngine_Test.cpp @@ -31,11 +31,36 @@ std::string GetMD5(unsigned char* buffer,unsigned int bufferLen) return str; } -int CompareSurface(const Surface& surface1, const Surface& surface2, int allowableError) +/// Compare two surfaces. Currently, Surface::getRawPointer() does not has constant attribute. +int CompareSurface(Surface& surface1, Surface& surface2, int allowableError) { return SDLTest_CompareSurfaces(surface1.getRawPointer(),surface2.getRawPointer(),allowableError); } +//private +struct UniRandom::_impl +{ + SDLTest_RandomContext context; +}; + +UniRandom::UniRandom() +{ + _sp.reset(new _impl); + SDLTest_RandomInitTime(&(_sp.get()->context)); +} + +UniRandom::UniRandom(unsigned int A, unsigned int B) +{ + _sp.reset(new _impl); + SDLTest_RandomInit(&(_sp.get()->context),A,B); +} + +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 3d6389a..2b71089 100644 --- a/MiniEngine_Test.h +++ b/MiniEngine_Test.h @@ -12,6 +12,18 @@ std::string GetMD5(unsigned char* buffer,unsigned int bufferLen); void GetMD5Raw(unsigned char* buffer,unsigned int bufferLen,unsigned char* outbuff); int CompareSurface(const Surface& surface1,const Surface& surface2,int allowableError); +class UniRandom +{ +public: + /// Default Constructor is based on system current time. + UniRandom(); + UniRandom(unsigned int A,unsigned int B); + uint32_t get(); +private: + struct _impl; + std::shared_ptr<_impl> _sp; +}; + }/// End of namespace MiniEngine::Test }/// End of namespace MiniEngine 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 4/4] 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