diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-07-26 15:21:18 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-07-26 15:21:18 -0700 |
commit | 0914aca645370e8ff46324d304b8a2acb64567ec (patch) | |
tree | 2933178476562cc662e29daf15b3dbd38bd2fc9a /tests/sdl_surface_refcount.c | |
parent | 9987b9a039052cb84f33127e5b2c3df58f349d7c (diff) | |
parent | 36aa6eb6c7fd6acfb04a9f7467b8ca1974a07dcd (diff) |
Merge pull request #1393 from fhd/sdl-surface-refcount
Implement SDL_Surface refcounting
Diffstat (limited to 'tests/sdl_surface_refcount.c')
-rw-r--r-- | tests/sdl_surface_refcount.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/sdl_surface_refcount.c b/tests/sdl_surface_refcount.c new file mode 100644 index 00000000..5e0f30a9 --- /dev/null +++ b/tests/sdl_surface_refcount.c @@ -0,0 +1,28 @@ +#include <emscripten.h> +#include <SDL.h> +#include <stdio.h> +#include <stdlib.h> + +int is_surface_freed(SDL_Surface *surface) +{ + const char *template = "!SDL.surfaces[%d]"; + int length = snprintf(NULL, 0, template, surface) + 1; + char *script = malloc(length * sizeof(char)); + snprintf(script, length, template, surface); + int is_freed = emscripten_run_script_int(script); + free(script); + return is_freed; +} + +int main(int argc, char *argv[]) +{ + SDL_Surface *surface = SDL_CreateRGBSurface(SDL_SWSURFACE, 10, 10, 32, + 0, 0, 0, 0); + SDL_Surface *reference = surface; + reference->refcount++; + SDL_FreeSurface(surface); + SDL_FreeSurface(reference); + int result = is_surface_freed(surface); + REPORT_RESULT(); + return 0; +} |