mirror of
https://github.com/Kiritow/MiniEngine.git
synced 2024-03-22 13:11:22 +08:00
Merge test branch.
We are about to support some functions from SDL2 Test Library.
This commit is contained in:
commit
c4b8e3e34e
100
MiniEngine_Test.cpp
Normal file
100
MiniEngine_Test.cpp
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
#include "MiniEngine_Test.h"
|
||||||
|
#include <SDL2/SDL_test.h>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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)
|
||||||
|
{
|
||||||
|
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
|
36
MiniEngine_Test.h
Normal file
36
MiniEngine_Test.h
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
#pragma once
|
||||||
|
#include "MiniEngine.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace MiniEngine
|
||||||
|
{
|
||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// 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
|
Loading…
Reference in New Issue
Block a user