Hash :
b72938c8
Author :
Date :
2015-04-20T12:22:44
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
/* See COPYING.txt for the full license governing this code. */
/**
* \file screenshot.c
*
* Source file for the screenshot API.
*/
#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; /* path to the bmp file used for verification */
char* test_path; /* path to the bmp file to be verified */
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;
}
/* generate the MD5 hash */
SDLVisualTest_HashString(args, hash);
/* find the verification image */
/* path_len + hash_len + some number of extra characters */
verify_len = SDL_strlen(verify_dir) + 32 + 10;
verify_path = (char*)SDL_malloc(verify_len * sizeof(char));
if(!verify_path)
{
SDLTest_LogError("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;
}
/* load the verification image */
verifybmp = SDL_LoadBMP_RW(rw, 1);
if(!verifybmp)
{
SDLTest_LogError("SDL_LoadBMP_RW() failed");
return_code = -1;
goto verifyscreenshots_cleanup_verifypath;
}
/* load the test images and compare with the verification image */
/* path_len + hash_len + some number of extra characters */
test_len = SDL_strlen(test_dir) + 32 + 10;
test_path = (char*)SDL_malloc(test_len * sizeof(char));
if(!test_path)
{
SDLTest_LogError("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");
/* we keep going until we've iterated through the screenshots each
SUT window */
if(!testrw)
break;
/* load the test screenshot */
testbmp = SDL_LoadBMP_RW(testrw, 1);
if(!testbmp)
{
SDLTest_LogError("SDL_LoadBMP_RW() failed");
return_code = -1;
goto verifyscreenshots_cleanup_verifybmp;
}
/* compare with the verification image */
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;
}