#include "SDL_visualtest_mischelper.h"
#include <SDL_test.h>
int
SDLVisualTest_VerifyScreenshots(char* args, char* test_dir, char* verify_dir)
{
int i, verify_len, return_code, test_len;
char hash[33];
char* verify_path;
char* test_path;
SDL_RWops* rw;
SDL_Surface* verifybmp;
return_code = 1;
if(!args)
{
SDLTest_LogError("args argument cannot be NULL");
return_code = -1;
goto verifyscreenshots_cleanup_generic;
}
if(!test_dir)
{
SDLTest_LogError("test_dir argument cannot be NULL");
return_code = -1;
goto verifyscreenshots_cleanup_generic;
}
if(!verify_dir)
{
SDLTest_LogError("verify_dir argument cannot be NULL");
return_code = -1;
goto verifyscreenshots_cleanup_generic;
}
SDLVisualTest_HashString(args, hash);
verify_len = SDL_strlen(verify_dir) + 32 + 10;
verify_path = (char*)SDL_malloc(verify_len * sizeof(char));
if(!verify_path)
{
SDLTest_LogError("SDL_malloc() failed");
return_code = -1;
goto verifyscreenshots_cleanup_generic;
}
SDL_snprintf(verify_path, verify_len - 1,
"%s/%s.bmp", verify_dir, hash);
rw = SDL_RWFromFile(verify_path, "rb");
if(!rw)
{
SDLTest_Log("Verification image does not exist."
" Please manually verify that the SUT is working correctly.");
return_code = 2;
goto verifyscreenshots_cleanup_verifypath;
}
verifybmp = SDL_LoadBMP_RW(rw, 1);
if(!verifybmp)
{
SDLTest_LogError("SDL_LoadBMP_RW() failed");
return_code = -1;
goto verifyscreenshots_cleanup_verifypath;
}
test_len = SDL_strlen(test_dir) + 32 + 10;
test_path = (char*)SDL_malloc(test_len * sizeof(char));
if(!test_path)
{
SDLTest_LogError("SDL_malloc() failed");
return_code = -1;
goto verifyscreenshots_cleanup_verifybmp;
}
for(i = 1; ; i++)
{
SDL_RWops* testrw;
SDL_Surface* testbmp;
if(i == 1)
SDL_snprintf(test_path, test_len - 1, "%s/%s.bmp", test_dir, hash);
else
SDL_snprintf(test_path, test_len - 1, "%s/%s_%d.bmp", test_dir, hash, i);
testrw = SDL_RWFromFile(test_path, "rb");
if(!testrw)
break;
testbmp = SDL_LoadBMP_RW(testrw, 1);
if(!testbmp)
{
SDLTest_LogError("SDL_LoadBMP_RW() failed");
return_code = -1;
goto verifyscreenshots_cleanup_verifybmp;
}
if(SDLTest_CompareSurfaces(testbmp, verifybmp, 0) != 0)
{
return_code = 0;
SDL_FreeSurface(testbmp);
goto verifyscreenshots_cleanup_verifybmp;
}
SDL_FreeSurface(testbmp);
}
if(i == 1)
{
SDLTest_LogError("No verification images found");
return_code = -1;
}
verifyscreenshots_cleanup_verifybmp:
SDL_FreeSurface(verifybmp);
verifyscreenshots_cleanup_verifypath:
SDL_free(verify_path);
verifyscreenshots_cleanup_generic:
return return_code;
}