sdl 2.0.8 update

This commit is contained in:
Tim 2018-05-09 23:09:05 +10:00
parent 7f674a59c6
commit bfb08f9482
894 changed files with 66879 additions and 43299 deletions

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -148,3 +148,5 @@ int SDLTest_AssertSummaryToTestResult()
}
}
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -32,10 +32,33 @@
#define AUDIO_USAGE \
"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
static void SDL_snprintfcat(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ... )
{
size_t length = SDL_strlen(text);
va_list ap;
va_start(ap, fmt);
text += length;
maxlen -= length;
SDL_vsnprintf(text, maxlen, fmt, ap);
va_end(ap);
}
SDLTest_CommonState *
SDLTest_CommonCreateState(char **argv, Uint32 flags)
{
SDLTest_CommonState *state = (SDLTest_CommonState *)SDL_calloc(1, sizeof(*state));
int i;
SDLTest_CommonState *state;
/* Do this first so we catch all allocations */
for (i = 1; argv[i]; ++i) {
if (SDL_strcasecmp(argv[i], "--trackmem") == 0) {
SDLTest_TrackAllocations();
break;
}
}
state = (SDLTest_CommonState *)SDL_calloc(1, sizeof(*state));
if (!state) {
SDL_OutOfMemory();
return NULL;
@ -435,6 +458,10 @@ SDLTest_CommonArg(SDLTest_CommonState * state, int index)
state->audiospec.samples = (Uint16) SDL_atoi(argv[index]);
return 2;
}
if (SDL_strcasecmp(argv[index], "--trackmem") == 0) {
/* Already handled in SDLTest_CommonCreateState() */
return 1;
}
if ((SDL_strcasecmp(argv[index], "-h") == 0)
|| (SDL_strcasecmp(argv[index], "--help") == 0)) {
/* Print the usage message */
@ -452,134 +479,140 @@ SDLTest_CommonUsage(SDLTest_CommonState * state)
{
switch (state->flags & (SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
case SDL_INIT_VIDEO:
return VIDEO_USAGE;
return "[--trackmem] " VIDEO_USAGE;
case SDL_INIT_AUDIO:
return AUDIO_USAGE;
return "[--trackmem] " AUDIO_USAGE;
case (SDL_INIT_VIDEO | SDL_INIT_AUDIO):
return VIDEO_USAGE " " AUDIO_USAGE;
return "[--trackmem] " VIDEO_USAGE " " AUDIO_USAGE;
default:
return "";
return "[--trackmem]";
}
}
static void
SDLTest_PrintRendererFlag(Uint32 flag)
SDLTest_PrintRendererFlag(char *text, size_t maxlen, Uint32 flag)
{
switch (flag) {
case SDL_RENDERER_PRESENTVSYNC:
fprintf(stderr, "PresentVSync");
case SDL_RENDERER_SOFTWARE:
SDL_snprintfcat(text, maxlen, "Software");
break;
case SDL_RENDERER_ACCELERATED:
fprintf(stderr, "Accelerated");
SDL_snprintfcat(text, maxlen, "Accelerated");
break;
case SDL_RENDERER_PRESENTVSYNC:
SDL_snprintfcat(text, maxlen, "PresentVSync");
break;
case SDL_RENDERER_TARGETTEXTURE:
SDL_snprintfcat(text, maxlen, "TargetTexturesSupported");
break;
default:
fprintf(stderr, "0x%8.8x", flag);
SDL_snprintfcat(text, maxlen, "0x%8.8x", flag);
break;
}
}
static void
SDLTest_PrintPixelFormat(Uint32 format)
SDLTest_PrintPixelFormat(char *text, size_t maxlen, Uint32 format)
{
switch (format) {
case SDL_PIXELFORMAT_UNKNOWN:
fprintf(stderr, "Unknwon");
SDL_snprintfcat(text, maxlen, "Unknown");
break;
case SDL_PIXELFORMAT_INDEX1LSB:
fprintf(stderr, "Index1LSB");
SDL_snprintfcat(text, maxlen, "Index1LSB");
break;
case SDL_PIXELFORMAT_INDEX1MSB:
fprintf(stderr, "Index1MSB");
SDL_snprintfcat(text, maxlen, "Index1MSB");
break;
case SDL_PIXELFORMAT_INDEX4LSB:
fprintf(stderr, "Index4LSB");
SDL_snprintfcat(text, maxlen, "Index4LSB");
break;
case SDL_PIXELFORMAT_INDEX4MSB:
fprintf(stderr, "Index4MSB");
SDL_snprintfcat(text, maxlen, "Index4MSB");
break;
case SDL_PIXELFORMAT_INDEX8:
fprintf(stderr, "Index8");
SDL_snprintfcat(text, maxlen, "Index8");
break;
case SDL_PIXELFORMAT_RGB332:
fprintf(stderr, "RGB332");
SDL_snprintfcat(text, maxlen, "RGB332");
break;
case SDL_PIXELFORMAT_RGB444:
fprintf(stderr, "RGB444");
SDL_snprintfcat(text, maxlen, "RGB444");
break;
case SDL_PIXELFORMAT_RGB555:
fprintf(stderr, "RGB555");
SDL_snprintfcat(text, maxlen, "RGB555");
break;
case SDL_PIXELFORMAT_BGR555:
fprintf(stderr, "BGR555");
SDL_snprintfcat(text, maxlen, "BGR555");
break;
case SDL_PIXELFORMAT_ARGB4444:
fprintf(stderr, "ARGB4444");
SDL_snprintfcat(text, maxlen, "ARGB4444");
break;
case SDL_PIXELFORMAT_ABGR4444:
fprintf(stderr, "ABGR4444");
SDL_snprintfcat(text, maxlen, "ABGR4444");
break;
case SDL_PIXELFORMAT_ARGB1555:
fprintf(stderr, "ARGB1555");
SDL_snprintfcat(text, maxlen, "ARGB1555");
break;
case SDL_PIXELFORMAT_ABGR1555:
fprintf(stderr, "ABGR1555");
SDL_snprintfcat(text, maxlen, "ABGR1555");
break;
case SDL_PIXELFORMAT_RGB565:
fprintf(stderr, "RGB565");
SDL_snprintfcat(text, maxlen, "RGB565");
break;
case SDL_PIXELFORMAT_BGR565:
fprintf(stderr, "BGR565");
SDL_snprintfcat(text, maxlen, "BGR565");
break;
case SDL_PIXELFORMAT_RGB24:
fprintf(stderr, "RGB24");
SDL_snprintfcat(text, maxlen, "RGB24");
break;
case SDL_PIXELFORMAT_BGR24:
fprintf(stderr, "BGR24");
SDL_snprintfcat(text, maxlen, "BGR24");
break;
case SDL_PIXELFORMAT_RGB888:
fprintf(stderr, "RGB888");
SDL_snprintfcat(text, maxlen, "RGB888");
break;
case SDL_PIXELFORMAT_BGR888:
fprintf(stderr, "BGR888");
SDL_snprintfcat(text, maxlen, "BGR888");
break;
case SDL_PIXELFORMAT_ARGB8888:
fprintf(stderr, "ARGB8888");
SDL_snprintfcat(text, maxlen, "ARGB8888");
break;
case SDL_PIXELFORMAT_RGBA8888:
fprintf(stderr, "RGBA8888");
SDL_snprintfcat(text, maxlen, "RGBA8888");
break;
case SDL_PIXELFORMAT_ABGR8888:
fprintf(stderr, "ABGR8888");
SDL_snprintfcat(text, maxlen, "ABGR8888");
break;
case SDL_PIXELFORMAT_BGRA8888:
fprintf(stderr, "BGRA8888");
SDL_snprintfcat(text, maxlen, "BGRA8888");
break;
case SDL_PIXELFORMAT_ARGB2101010:
fprintf(stderr, "ARGB2101010");
SDL_snprintfcat(text, maxlen, "ARGB2101010");
break;
case SDL_PIXELFORMAT_YV12:
fprintf(stderr, "YV12");
SDL_snprintfcat(text, maxlen, "YV12");
break;
case SDL_PIXELFORMAT_IYUV:
fprintf(stderr, "IYUV");
SDL_snprintfcat(text, maxlen, "IYUV");
break;
case SDL_PIXELFORMAT_YUY2:
fprintf(stderr, "YUY2");
SDL_snprintfcat(text, maxlen, "YUY2");
break;
case SDL_PIXELFORMAT_UYVY:
fprintf(stderr, "UYVY");
SDL_snprintfcat(text, maxlen, "UYVY");
break;
case SDL_PIXELFORMAT_YVYU:
fprintf(stderr, "YVYU");
SDL_snprintfcat(text, maxlen, "YVYU");
break;
case SDL_PIXELFORMAT_NV12:
fprintf(stderr, "NV12");
SDL_snprintfcat(text, maxlen, "NV12");
break;
case SDL_PIXELFORMAT_NV21:
fprintf(stderr, "NV21");
SDL_snprintfcat(text, maxlen, "NV21");
break;
default:
fprintf(stderr, "0x%8.8x", format);
SDL_snprintfcat(text, maxlen, "0x%8.8x", format);
break;
}
}
@ -588,35 +621,37 @@ static void
SDLTest_PrintRenderer(SDL_RendererInfo * info)
{
int i, count;
char text[1024];
fprintf(stderr, " Renderer %s:\n", info->name);
SDL_Log(" Renderer %s:\n", info->name);
fprintf(stderr, " Flags: 0x%8.8X", info->flags);
fprintf(stderr, " (");
SDL_snprintf(text, sizeof(text), " Flags: 0x%8.8X", info->flags);
SDL_snprintfcat(text, sizeof(text), " (");
count = 0;
for (i = 0; i < sizeof(info->flags) * 8; ++i) {
Uint32 flag = (1 << i);
if (info->flags & flag) {
if (count > 0) {
fprintf(stderr, " | ");
SDL_snprintfcat(text, sizeof(text), " | ");
}
SDLTest_PrintRendererFlag(flag);
SDLTest_PrintRendererFlag(text, sizeof(text), flag);
++count;
}
}
fprintf(stderr, ")\n");
SDL_snprintfcat(text, sizeof(text), ")");
SDL_Log("%s\n", text);
fprintf(stderr, " Texture formats (%d): ", info->num_texture_formats);
SDL_snprintf(text, sizeof(text), " Texture formats (%d): ", info->num_texture_formats);
for (i = 0; i < (int) info->num_texture_formats; ++i) {
if (i > 0) {
fprintf(stderr, ", ");
SDL_snprintfcat(text, sizeof(text), ", ");
}
SDLTest_PrintPixelFormat(info->texture_formats[i]);
SDLTest_PrintPixelFormat(text, sizeof(text), info->texture_formats[i]);
}
fprintf(stderr, "\n");
SDL_Log("%s\n", text);
if (info->max_texture_width || info->max_texture_height) {
fprintf(stderr, " Max Texture Size: %dx%d\n",
SDL_Log(" Max Texture Size: %dx%d\n",
info->max_texture_width, info->max_texture_height);
}
}
@ -629,7 +664,7 @@ SDLTest_LoadIcon(const char *file)
/* Load the icon surface */
icon = SDL_LoadBMP(file);
if (icon == NULL) {
fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
SDL_Log("Couldn't load %s: %s\n", file, SDL_GetError());
return (NULL);
}
@ -641,35 +676,82 @@ SDLTest_LoadIcon(const char *file)
return (icon);
}
static SDL_HitTestResult SDLCALL
SDLTest_ExampleHitTestCallback(SDL_Window *win, const SDL_Point *area, void *data)
{
int w, h;
const int RESIZE_BORDER = 8;
const int DRAGGABLE_TITLE = 32;
/*SDL_Log("Hit test point %d,%d\n", area->x, area->y);*/
SDL_GetWindowSize(win, &w, &h);
if (area->x < RESIZE_BORDER) {
if (area->y < RESIZE_BORDER) {
SDL_Log("SDL_HITTEST_RESIZE_TOPLEFT\n");
return SDL_HITTEST_RESIZE_TOPLEFT;
} else if (area->y >= (h-RESIZE_BORDER)) {
SDL_Log("SDL_HITTEST_RESIZE_BOTTOMLEFT\n");
return SDL_HITTEST_RESIZE_BOTTOMLEFT;
} else {
SDL_Log("SDL_HITTEST_RESIZE_LEFT\n");
return SDL_HITTEST_RESIZE_LEFT;
}
} else if (area->x >= (w-RESIZE_BORDER)) {
if (area->y < RESIZE_BORDER) {
SDL_Log("SDL_HITTEST_RESIZE_TOPRIGHT\n");
return SDL_HITTEST_RESIZE_TOPRIGHT;
} else if (area->y >= (h-RESIZE_BORDER)) {
SDL_Log("SDL_HITTEST_RESIZE_BOTTOMRIGHT\n");
return SDL_HITTEST_RESIZE_BOTTOMRIGHT;
} else {
SDL_Log("SDL_HITTEST_RESIZE_RIGHT\n");
return SDL_HITTEST_RESIZE_RIGHT;
}
} else if (area->y >= (h-RESIZE_BORDER)) {
SDL_Log("SDL_HITTEST_RESIZE_BOTTOM\n");
return SDL_HITTEST_RESIZE_BOTTOM;
} else if (area->y < RESIZE_BORDER) {
SDL_Log("SDL_HITTEST_RESIZE_TOP\n");
return SDL_HITTEST_RESIZE_TOP;
} else if (area->y < DRAGGABLE_TITLE) {
SDL_Log("SDL_HITTEST_DRAGGABLE\n");
return SDL_HITTEST_DRAGGABLE;
}
return SDL_HITTEST_NORMAL;
}
SDL_bool
SDLTest_CommonInit(SDLTest_CommonState * state)
{
int i, j, m, n, w, h;
SDL_DisplayMode fullscreen_mode;
char text[1024];
if (state->flags & SDL_INIT_VIDEO) {
if (state->verbose & VERBOSE_VIDEO) {
n = SDL_GetNumVideoDrivers();
if (n == 0) {
fprintf(stderr, "No built-in video drivers\n");
SDL_Log("No built-in video drivers\n");
} else {
fprintf(stderr, "Built-in video drivers:");
SDL_snprintf(text, sizeof(text), "Built-in video drivers:");
for (i = 0; i < n; ++i) {
if (i > 0) {
fprintf(stderr, ",");
SDL_snprintfcat(text, sizeof(text), ",");
}
fprintf(stderr, " %s", SDL_GetVideoDriver(i));
SDL_snprintfcat(text, sizeof(text), " %s", SDL_GetVideoDriver(i));
}
fprintf(stderr, "\n");
SDL_Log("%s\n", text);
}
}
if (SDL_VideoInit(state->videodriver) < 0) {
fprintf(stderr, "Couldn't initialize video driver: %s\n",
SDL_Log("Couldn't initialize video driver: %s\n",
SDL_GetError());
return SDL_FALSE;
}
if (state->verbose & VERBOSE_VIDEO) {
fprintf(stderr, "Video driver: %s\n",
SDL_Log("Video driver: %s\n",
SDL_GetCurrentVideoDriver());
}
@ -706,75 +788,82 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
}
if (state->verbose & VERBOSE_MODES) {
SDL_Rect bounds;
SDL_Rect bounds, usablebounds;
float hdpi = 0;
float vdpi = 0;
SDL_DisplayMode mode;
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
#if SDL_VIDEO_DRIVER_WINDOWS
int adapterIndex = 0;
int outputIndex = 0;
int adapterIndex = 0;
int outputIndex = 0;
#endif
n = SDL_GetNumVideoDisplays();
fprintf(stderr, "Number of displays: %d\n", n);
SDL_Log("Number of displays: %d\n", n);
for (i = 0; i < n; ++i) {
fprintf(stderr, "Display %d: %s\n", i, SDL_GetDisplayName(i));
SDL_Log("Display %d: %s\n", i, SDL_GetDisplayName(i));
SDL_zero(bounds);
SDL_GetDisplayBounds(i, &bounds);
fprintf(stderr, "Bounds: %dx%d at %d,%d\n", bounds.w, bounds.h, bounds.x, bounds.y);
SDL_zero(usablebounds);
SDL_GetDisplayUsableBounds(i, &usablebounds);
SDL_GetDisplayDPI(i, NULL, &hdpi, &vdpi);
SDL_Log("Bounds: %dx%d at %d,%d\n", bounds.w, bounds.h, bounds.x, bounds.y);
SDL_Log("Usable bounds: %dx%d at %d,%d\n", usablebounds.w, usablebounds.h, usablebounds.x, usablebounds.y);
SDL_Log("DPI: %fx%f\n", hdpi, vdpi);
SDL_GetDesktopDisplayMode(i, &mode);
SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask,
&Bmask, &Amask);
fprintf(stderr,
" Current mode: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
SDL_Log(" Current mode: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
mode.w, mode.h, mode.refresh_rate, bpp,
SDL_GetPixelFormatName(mode.format));
if (Rmask || Gmask || Bmask) {
fprintf(stderr, " Red Mask = 0x%.8x\n", Rmask);
fprintf(stderr, " Green Mask = 0x%.8x\n", Gmask);
fprintf(stderr, " Blue Mask = 0x%.8x\n", Bmask);
SDL_Log(" Red Mask = 0x%.8x\n", Rmask);
SDL_Log(" Green Mask = 0x%.8x\n", Gmask);
SDL_Log(" Blue Mask = 0x%.8x\n", Bmask);
if (Amask)
fprintf(stderr, " Alpha Mask = 0x%.8x\n", Amask);
SDL_Log(" Alpha Mask = 0x%.8x\n", Amask);
}
/* Print available fullscreen video modes */
m = SDL_GetNumDisplayModes(i);
if (m == 0) {
fprintf(stderr, "No available fullscreen video modes\n");
SDL_Log("No available fullscreen video modes\n");
} else {
fprintf(stderr, " Fullscreen video modes:\n");
SDL_Log(" Fullscreen video modes:\n");
for (j = 0; j < m; ++j) {
SDL_GetDisplayMode(i, j, &mode);
SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask,
&Gmask, &Bmask, &Amask);
fprintf(stderr,
" Mode %d: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
SDL_Log(" Mode %d: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
j, mode.w, mode.h, mode.refresh_rate, bpp,
SDL_GetPixelFormatName(mode.format));
if (Rmask || Gmask || Bmask) {
fprintf(stderr, " Red Mask = 0x%.8x\n",
SDL_Log(" Red Mask = 0x%.8x\n",
Rmask);
fprintf(stderr, " Green Mask = 0x%.8x\n",
SDL_Log(" Green Mask = 0x%.8x\n",
Gmask);
fprintf(stderr, " Blue Mask = 0x%.8x\n",
SDL_Log(" Blue Mask = 0x%.8x\n",
Bmask);
if (Amask)
fprintf(stderr,
" Alpha Mask = 0x%.8x\n",
SDL_Log(" Alpha Mask = 0x%.8x\n",
Amask);
}
}
}
#if SDL_VIDEO_DRIVER_WINDOWS
/* Print the D3D9 adapter index */
adapterIndex = SDL_Direct3D9GetAdapterIndex( i );
fprintf( stderr, "D3D9 Adapter Index: %d", adapterIndex );
/* Print the D3D9 adapter index */
adapterIndex = SDL_Direct3D9GetAdapterIndex( i );
SDL_Log("D3D9 Adapter Index: %d", adapterIndex);
/* Print the DXGI adapter and output indices */
SDL_DXGIGetOutputInfo(i, &adapterIndex, &outputIndex);
fprintf( stderr, "DXGI Adapter Index: %d Output Index: %d", adapterIndex, outputIndex );
/* Print the DXGI adapter and output indices */
SDL_DXGIGetOutputInfo(i, &adapterIndex, &outputIndex);
SDL_Log("DXGI Adapter Index: %d Output Index: %d", adapterIndex, outputIndex);
#endif
}
}
@ -784,9 +873,9 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
n = SDL_GetNumRenderDrivers();
if (n == 0) {
fprintf(stderr, "No built-in render drivers\n");
SDL_Log("No built-in render drivers\n");
} else {
fprintf(stderr, "Built-in render drivers:\n");
SDL_Log("Built-in render drivers:\n");
for (i = 0; i < n; ++i) {
SDL_GetRenderDriverInfo(i, &info);
SDLTest_PrintRenderer(&info);
@ -815,16 +904,16 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
fullscreen_mode.refresh_rate = state->refresh_rate;
state->windows =
(SDL_Window **) SDL_malloc(state->num_windows *
(SDL_Window **) SDL_calloc(state->num_windows,
sizeof(*state->windows));
state->renderers =
(SDL_Renderer **) SDL_malloc(state->num_windows *
(SDL_Renderer **) SDL_calloc(state->num_windows,
sizeof(*state->renderers));
state->targets =
(SDL_Texture **) SDL_malloc(state->num_windows *
(SDL_Texture **) SDL_calloc(state->num_windows,
sizeof(*state->targets));
if (!state->windows || !state->renderers) {
fprintf(stderr, "Out of memory!\n");
SDL_Log("Out of memory!\n");
return SDL_FALSE;
}
for (i = 0; i < state->num_windows; ++i) {
@ -841,7 +930,7 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
state->window_w, state->window_h,
state->window_flags);
if (!state->windows[i]) {
fprintf(stderr, "Couldn't create window: %s\n",
SDL_Log("Couldn't create window: %s\n",
SDL_GetError());
return SDL_FALSE;
}
@ -859,11 +948,17 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
state->window_h = h;
}
if (SDL_SetWindowDisplayMode(state->windows[i], &fullscreen_mode) < 0) {
fprintf(stderr, "Can't set up fullscreen display mode: %s\n",
SDL_Log("Can't set up fullscreen display mode: %s\n",
SDL_GetError());
return SDL_FALSE;
}
/* Add resize/drag areas for windows that are borderless and resizable */
if ((state->window_flags & (SDL_WINDOW_RESIZABLE|SDL_WINDOW_BORDERLESS)) ==
(SDL_WINDOW_RESIZABLE|SDL_WINDOW_BORDERLESS)) {
SDL_SetWindowHitTest(state->windows[i], SDLTest_ExampleHitTestCallback, NULL);
}
if (state->window_icon) {
SDL_Surface *icon = SDLTest_LoadIcon(state->window_icon);
if (icon) {
@ -874,12 +969,9 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
SDL_ShowWindow(state->windows[i]);
state->renderers[i] = NULL;
state->targets[i] = NULL;
if (!state->skip_renderer
&& (state->renderdriver
|| !(state->window_flags & SDL_WINDOW_OPENGL))) {
|| !(state->window_flags & (SDL_WINDOW_OPENGL | SDL_WINDOW_VULKAN)))) {
m = -1;
if (state->renderdriver) {
SDL_RendererInfo info;
@ -893,8 +985,7 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
}
}
if (m == -1) {
fprintf(stderr,
"Couldn't find render driver named %s",
SDL_Log("Couldn't find render driver named %s",
state->renderdriver);
return SDL_FALSE;
}
@ -902,7 +993,7 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
state->renderers[i] = SDL_CreateRenderer(state->windows[i],
m, state->render_flags);
if (!state->renderers[i]) {
fprintf(stderr, "Couldn't create renderer: %s\n",
SDL_Log("Couldn't create renderer: %s\n",
SDL_GetError());
return SDL_FALSE;
}
@ -914,7 +1005,7 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
if (state->verbose & VERBOSE_RENDER) {
SDL_RendererInfo info;
fprintf(stderr, "Current renderer:\n");
SDL_Log("Current renderer:\n");
SDL_GetRendererInfo(state->renderers[i], &info);
SDLTest_PrintRenderer(&info);
}
@ -926,30 +1017,30 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
if (state->verbose & VERBOSE_AUDIO) {
n = SDL_GetNumAudioDrivers();
if (n == 0) {
fprintf(stderr, "No built-in audio drivers\n");
SDL_Log("No built-in audio drivers\n");
} else {
fprintf(stderr, "Built-in audio drivers:");
SDL_snprintf(text, sizeof(text), "Built-in audio drivers:");
for (i = 0; i < n; ++i) {
if (i > 0) {
fprintf(stderr, ",");
SDL_snprintfcat(text, sizeof(text), ",");
}
fprintf(stderr, " %s", SDL_GetAudioDriver(i));
SDL_snprintfcat(text, sizeof(text), " %s", SDL_GetAudioDriver(i));
}
fprintf(stderr, "\n");
SDL_Log("%s\n", text);
}
}
if (SDL_AudioInit(state->audiodriver) < 0) {
fprintf(stderr, "Couldn't initialize audio driver: %s\n",
SDL_Log("Couldn't initialize audio driver: %s\n",
SDL_GetError());
return SDL_FALSE;
}
if (state->verbose & VERBOSE_VIDEO) {
fprintf(stderr, "Audio driver: %s\n",
SDL_Log("Audio driver: %s\n",
SDL_GetCurrentAudioDriver());
}
if (SDL_OpenAudio(&state->audiospec, NULL) < 0) {
fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
SDL_Log("Couldn't open audio: %s\n", SDL_GetError());
return SDL_FALSE;
}
}
@ -1071,7 +1162,7 @@ SDLTest_PrintEvent(SDL_Event * event)
SDL_Log("SDL EVENT: Window %d hit test", event->window.windowID);
break;
default:
SDL_Log("SDL EVENT: Window %d got unknown event %d",
SDL_Log("SDL EVENT: Window %d got unknown event 0x%4.4x",
event->window.windowID, event->window.event);
break;
}
@ -1090,10 +1181,17 @@ SDLTest_PrintEvent(SDL_Event * event)
SDL_GetScancodeName(event->key.keysym.scancode),
event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
break;
case SDL_TEXTEDITING:
SDL_Log("SDL EVENT: Keyboard: text editing \"%s\" in window %d",
event->edit.text, event->edit.windowID);
break;
case SDL_TEXTINPUT:
SDL_Log("SDL EVENT: Keyboard: text input \"%s\" in window %d",
event->text.text, event->text.windowID);
break;
case SDL_KEYMAPCHANGED:
SDL_Log("SDL EVENT: Keymap changed");
break;
case SDL_MOUSEMOTION:
SDL_Log("SDL EVENT: Mouse: moved to %d,%d (%d,%d) in window %d",
event->motion.x, event->motion.y,
@ -1200,6 +1298,13 @@ SDLTest_PrintEvent(SDL_Event * event)
SDL_Log("SDL EVENT: Clipboard updated");
break;
case SDL_FINGERMOTION:
SDL_Log("SDL EVENT: Finger: motion touch=%ld, finger=%ld, x=%f, y=%f, dx=%f, dy=%f, pressure=%f",
(long) event->tfinger.touchId,
(long) event->tfinger.fingerId,
event->tfinger.x, event->tfinger.y,
event->tfinger.dx, event->tfinger.dy, event->tfinger.pressure);
break;
case SDL_FINGERDOWN:
case SDL_FINGERUP:
SDL_Log("SDL EVENT: Finger: %s touch=%ld, finger=%ld, x=%f, y=%f, dx=%f, dy=%f, pressure=%f",
@ -1210,10 +1315,10 @@ SDLTest_PrintEvent(SDL_Event * event)
event->tfinger.dx, event->tfinger.dy, event->tfinger.pressure);
break;
case SDL_DOLLARGESTURE:
SDL_Log("SDL_EVENT: Dollar gesture detect: %"SDL_PRIs64, (Sint64) event->dgesture.gestureId);
SDL_Log("SDL_EVENT: Dollar gesture detect: %ld", (long) event->dgesture.gestureId);
break;
case SDL_DOLLARRECORD:
SDL_Log("SDL_EVENT: Dollar gesture record: %"SDL_PRIs64, (Sint64) event->dgesture.gestureId);
SDL_Log("SDL_EVENT: Dollar gesture record: %ld", (long) event->dgesture.gestureId);
break;
case SDL_MULTIGESTURE:
SDL_Log("SDL_EVENT: Multi gesture fingers: %d", event->mgesture.numFingers);
@ -1226,6 +1331,25 @@ SDLTest_PrintEvent(SDL_Event * event)
SDL_Log("SDL EVENT: render targets reset");
break;
case SDL_APP_TERMINATING:
SDL_Log("SDL EVENT: App terminating");
break;
case SDL_APP_LOWMEMORY:
SDL_Log("SDL EVENT: App running low on memory");
break;
case SDL_APP_WILLENTERBACKGROUND:
SDL_Log("SDL EVENT: App will enter the background");
break;
case SDL_APP_DIDENTERBACKGROUND:
SDL_Log("SDL EVENT: App entered the background");
break;
case SDL_APP_WILLENTERFOREGROUND:
SDL_Log("SDL EVENT: App will enter the foreground");
break;
case SDL_APP_DIDENTERFOREGROUND:
SDL_Log("SDL EVENT: App entered the foreground");
break;
case SDL_QUIT:
SDL_Log("SDL EVENT: Quit requested");
break;
@ -1233,7 +1357,7 @@ SDLTest_PrintEvent(SDL_Event * event)
SDL_Log("SDL EVENT: User event %d", event->user.code);
break;
default:
SDL_Log("Unknown event %04x", event->type);
SDL_Log("Unknown event 0x%4.4x", event->type);
break;
}
}
@ -1257,19 +1381,19 @@ SDLTest_ScreenShot(SDL_Renderer *renderer)
#endif
0x00000000);
if (!surface) {
fprintf(stderr, "Couldn't create surface: %s\n", SDL_GetError());
SDL_Log("Couldn't create surface: %s\n", SDL_GetError());
return;
}
if (SDL_RenderReadPixels(renderer, NULL, surface->format->format,
surface->pixels, surface->pitch) < 0) {
fprintf(stderr, "Couldn't read screen: %s\n", SDL_GetError());
SDL_Log("Couldn't read screen: %s\n", SDL_GetError());
SDL_free(surface);
return;
}
if (SDL_SaveBMP(surface, "screenshot.bmp") < 0) {
fprintf(stderr, "Couldn't save screenshot.bmp: %s\n", SDL_GetError());
SDL_Log("Couldn't save screenshot.bmp: %s\n", SDL_GetError());
SDL_free(surface);
return;
}
@ -1374,6 +1498,49 @@ SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
}
}
break;
case SDLK_UP:
case SDLK_DOWN:
case SDLK_LEFT:
case SDLK_RIGHT:
if (withAlt) {
/* Alt-Up/Down/Left/Right switches between displays */
SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
if (window) {
int currentIndex = SDL_GetWindowDisplayIndex(window);
int numDisplays = SDL_GetNumVideoDisplays();
if (currentIndex >= 0 && numDisplays >= 1) {
int dest;
if (event->key.keysym.sym == SDLK_UP || event->key.keysym.sym == SDLK_LEFT) {
dest = (currentIndex + numDisplays - 1) % numDisplays;
} else {
dest = (currentIndex + numDisplays + 1) % numDisplays;
}
SDL_Log("Centering on display %d\n", dest);
SDL_SetWindowPosition(window,
SDL_WINDOWPOS_CENTERED_DISPLAY(dest),
SDL_WINDOWPOS_CENTERED_DISPLAY(dest));
}
}
}
if (withShift) {
/* Shift-Up/Down/Left/Right shift the window by 100px */
SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
if (window) {
const int delta = 100;
int x, y;
SDL_GetWindowPosition(window, &x, &y);
if (event->key.keysym.sym == SDLK_UP) y -= delta;
if (event->key.keysym.sym == SDLK_DOWN) y += delta;
if (event->key.keysym.sym == SDLK_LEFT) x -= delta;
if (event->key.keysym.sym == SDLK_RIGHT) x += delta;
SDL_Log("Setting position to (%d, %d)\n", x, y);
SDL_SetWindowPosition(window, x, y);
}
}
break;
case SDLK_o:
if (withControl) {
/* Ctrl-O (or Ctrl-Shift-O) changes window opacity. */
@ -1610,6 +1777,7 @@ SDLTest_CommonQuit(SDLTest_CommonState * state)
}
SDL_free(state);
SDL_Quit();
SDLTest_LogAllocations();
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -113,3 +113,5 @@ int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface,
return ret;
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -69,7 +69,6 @@ int SDLTest_Crc32Init(SDLTest_Crc32Context *crcContext)
}
/* Complete CRC32 calculation on a memory block */
int SDLTest_Crc32Calc(SDLTest_Crc32Context * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32)
{
if (SDLTest_Crc32CalcStart(crcContext,crc32)) {
@ -163,3 +162,5 @@ int SDLTest_Crc32Done(SDLTest_Crc32Context * crcContext)
return 0;
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -3116,9 +3116,9 @@ static SDL_Texture *SDLTest_CharTextureCache[256];
int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, char c)
{
const Uint32 charWidth = FONT_CHARACTER_SIZE;
const Uint32 charHeight = FONT_CHARACTER_SIZE;
const Uint32 charSize = FONT_CHARACTER_SIZE;
const Uint32 charWidth = FONT_CHARACTER_SIZE;
const Uint32 charHeight = FONT_CHARACTER_SIZE;
const Uint32 charSize = FONT_CHARACTER_SIZE;
SDL_Rect srect;
SDL_Rect drect;
int result;
@ -3133,16 +3133,16 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, char c)
Uint8 r, g, b, a;
/*
* Setup source rectangle
*/
* Setup source rectangle
*/
srect.x = 0;
srect.y = 0;
srect.w = charWidth;
srect.h = charHeight;
/*
* Setup destination rectangle
*/
* Setup destination rectangle
*/
drect.x = x;
drect.y = y;
drect.w = charWidth;
@ -3152,12 +3152,12 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, char c)
ci = (unsigned char)c;
/*
* Create new charWidth x charHeight bitmap surface if not already present.
*/
* Create new charWidth x charHeight bitmap surface if not already present.
*/
if (SDLTest_CharTextureCache[ci] == NULL) {
/*
* Redraw character into surface
*/
* Redraw character into surface
*/
character = SDL_CreateRGBSurface(SDL_SWSURFACE,
charWidth, charHeight, 32,
0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
@ -3170,8 +3170,8 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, char c)
pitch = character->pitch;
/*
* Drawing loop
*/
* Drawing loop
*/
patt = 0;
for (iy = 0; iy < charWidth; iy++) {
mask = 0x00;
@ -3196,24 +3196,24 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, char c)
SDL_FreeSurface(character);
/*
* Check pointer
*/
* Check pointer
*/
if (SDLTest_CharTextureCache[ci] == NULL) {
return (-1);
}
}
/*
* Set color
*/
* Set color
*/
result = 0;
result |= SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a);
result |= SDL_SetTextureColorMod(SDLTest_CharTextureCache[ci], r, g, b);
result |= SDL_SetTextureAlphaMod(SDLTest_CharTextureCache[ci], a);
/*
* Draw texture onto destination
*/
* Draw texture onto destination
*/
result |= SDL_RenderCopy(renderer, SDLTest_CharTextureCache[ci], &srect, &drect);
return (result);
@ -3221,7 +3221,7 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, char c)
int SDLTest_DrawString(SDL_Renderer * renderer, int x, int y, const char *s)
{
const Uint32 charWidth = FONT_CHARACTER_SIZE;
const Uint32 charWidth = FONT_CHARACTER_SIZE;
int result = 0;
int curx = x;
int cury = y;
@ -3236,3 +3236,15 @@ int SDLTest_DrawString(SDL_Renderer * renderer, int x, int y, const char *s)
return (result);
}
void SDLTest_CleanupTextDrawing(void)
{
unsigned int i;
for (i = 0; i < SDL_arraysize(SDLTest_CharTextureCache); ++i) {
if (SDLTest_CharTextureCache[i]) {
SDL_DestroyTexture(SDLTest_CharTextureCache[i]);
SDLTest_CharTextureCache[i] = NULL;
}
}
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -27,19 +27,20 @@
#include "SDL_config.h"
#include <limits.h>
/* Visual Studio 2008 doesn't have stdint.h */
#if defined(_MSC_VER) && _MSC_VER <= 1500
#define UINT8_MAX ~(Uint8)0
#define UINT16_MAX ~(Uint16)0
#define UINT32_MAX ~(Uint32)0
#define UINT64_MAX ~(Uint64)0
#define UINT8_MAX _UI8_MAX
#define UINT16_MAX _UI16_MAX
#define UINT32_MAX _UI32_MAX
#define INT64_MIN _I64_MIN
#define INT64_MAX _I64_MAX
#define UINT64_MAX _UI64_MAX
#else
#define _GNU_SOURCE
#include <stdint.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <float.h>
#include "SDL_test.h"
@ -125,29 +126,35 @@ SDLTest_RandomUint32()
Uint64
SDLTest_RandomUint64()
{
Uint64 value = 0;
Uint32 *vp = (void *)&value;
union {
Uint64 v64;
Uint32 v32[2];
} value;
value.v64 = 0;
fuzzerInvocationCounter++;
vp[0] = SDLTest_RandomSint32();
vp[1] = SDLTest_RandomSint32();
value.v32[0] = SDLTest_RandomSint32();
value.v32[1] = SDLTest_RandomSint32();
return value;
return value.v64;
}
Sint64
SDLTest_RandomSint64()
{
Uint64 value = 0;
Uint32 *vp = (void *)&value;
union {
Uint64 v64;
Uint32 v32[2];
} value;
value.v64 = 0;
fuzzerInvocationCounter++;
vp[0] = SDLTest_RandomSint32();
vp[1] = SDLTest_RandomSint32();
value.v32[0] = SDLTest_RandomSint32();
value.v32[1] = SDLTest_RandomSint32();
return value;
return (Sint64)value.v64;
}
@ -197,7 +204,7 @@ SDLTest_RandomIntegerInRange(Sint32 pMin, Sint32 pMax)
*
* \returns Returns a random boundary value for the domain or 0 in case of error
*/
Uint64
static Uint64
SDLTest_GenerateUnsignedBoundaryValues(const Uint64 maxValue, Uint64 boundary1, Uint64 boundary2, SDL_bool validDomain)
{
Uint64 b1, b2;
@ -298,7 +305,7 @@ Uint64
SDLTest_RandomUint64BoundaryValue(Uint64 boundary1, Uint64 boundary2, SDL_bool validDomain)
{
/* max value for Uint64 */
const Uint64 maxValue = ULLONG_MAX;
const Uint64 maxValue = UINT64_MAX;
return SDLTest_GenerateUnsignedBoundaryValues(maxValue,
(Uint64) boundary1, (Uint64) boundary2,
validDomain);
@ -329,7 +336,7 @@ SDLTest_RandomUint64BoundaryValue(Uint64 boundary1, Uint64 boundary2, SDL_bool v
*
* \returns Returns a random boundary value for the domain or 0 in case of error
*/
Sint64
static Sint64
SDLTest_GenerateSignedBoundaryValues(const Sint64 minValue, const Sint64 maxValue, Sint64 boundary1, Sint64 boundary2, SDL_bool validDomain)
{
Sint64 b1, b2;
@ -434,8 +441,8 @@ Sint64
SDLTest_RandomSint64BoundaryValue(Sint64 boundary1, Sint64 boundary2, SDL_bool validDomain)
{
/* min & max values for Sint64 */
const Sint64 maxValue = LLONG_MAX;
const Sint64 minValue = LLONG_MIN;
const Sint64 maxValue = INT64_MAX;
const Sint64 minValue = INT64_MIN;
return SDLTest_GenerateSignedBoundaryValues(minValue, maxValue,
boundary1, boundary2,
validDomain);
@ -444,7 +451,7 @@ SDLTest_RandomSint64BoundaryValue(Sint64 boundary1, Sint64 boundary2, SDL_bool v
float
SDLTest_RandomUnitFloat()
{
return (float) SDLTest_RandomUint32() / UINT_MAX;
return SDLTest_RandomUint32() / (float) UINT_MAX;
}
float
@ -523,3 +530,5 @@ SDLTest_RandomAsciiStringOfSize(int size)
return string;
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -97,17 +97,17 @@ SDLTest_GenerateRunSeed(const int length)
* \returns The generated execution key to initialize the fuzzer with.
*
*/
Uint64
SDLTest_GenerateExecKey(char *runSeed, char *suiteName, char *testName, int iteration)
static Uint64
SDLTest_GenerateExecKey(const char *runSeed, char *suiteName, char *testName, int iteration)
{
SDLTest_Md5Context md5Context;
Uint64 *keys;
char iterationString[16];
Uint32 runSeedLength;
Uint32 suiteNameLength;
Uint32 testNameLength;
Uint32 iterationStringLength;
Uint32 entireStringLength;
size_t runSeedLength;
size_t suiteNameLength;
size_t testNameLength;
size_t iterationStringLength;
size_t entireStringLength;
char *buffer;
if (runSeed == NULL || runSeed[0] == '\0') {
@ -150,7 +150,7 @@ SDLTest_GenerateExecKey(char *runSeed, char *suiteName, char *testName, int iter
/* Hash string and use half of the digest as 64bit exec key */
SDLTest_Md5Init(&md5Context);
SDLTest_Md5Update(&md5Context, (unsigned char *)buffer, entireStringLength);
SDLTest_Md5Update(&md5Context, (unsigned char *)buffer, (unsigned int) entireStringLength);
SDLTest_Md5Final(&md5Context);
SDL_free(buffer);
keys = (Uint64 *)md5Context.digest;
@ -168,7 +168,7 @@ SDLTest_GenerateExecKey(char *runSeed, char *suiteName, char *testName, int iter
*
* \return Timer id or -1 on failure.
*/
SDL_TimerID
static SDL_TimerID
SDLTest_SetTestTimeout(int timeout, void (*callback)())
{
Uint32 timeoutInMilliseconds;
@ -206,8 +206,8 @@ SDLTest_SetTestTimeout(int timeout, void (*callback)())
/**
* \brief Timeout handler. Aborts test run and exits harness process.
*/
void
SDLTest_BailOut()
static SDL_NORETURN void
SDLTest_BailOut()
{
SDLTest_LogError("TestCaseTimeout timer expired. Aborting test run.");
exit(TEST_ABORTED); /* bail out from the test */
@ -223,8 +223,8 @@ void
*
* \returns Test case result.
*/
int
SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, SDLTest_TestCaseReference *testCase, Uint64 execKey, SDL_bool forceTestRun)
static int
SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, const SDLTest_TestCaseReference *testCase, Uint64 execKey, SDL_bool forceTestRun)
{
SDL_TimerID timer = 0;
int testCaseResult = 0;
@ -313,7 +313,8 @@ SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, SDLTest_TestCaseReference
}
/* Prints summary of all suites/tests contained in the given reference */
void SDLTest_LogTestSuiteSummary(SDLTest_TestSuiteReference *testSuites)
#if 0
static void SDLTest_LogTestSuiteSummary(SDLTest_TestSuiteReference *testSuites)
{
int suiteCounter;
int testCounter;
@ -340,12 +341,13 @@ void SDLTest_LogTestSuiteSummary(SDLTest_TestSuiteReference *testSuites)
}
}
}
#endif
/* Gets a timer value in seconds */
float GetClock()
static float GetClock()
{
float currentClock = (float)clock();
return currentClock / (float)CLOCKS_PER_SEC;
float currentClock = clock() / (float) CLOCKS_PER_SEC;
return currentClock;
}
/**
@ -370,7 +372,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
int testCounter;
int iterationCounter;
SDLTest_TestSuiteReference *testSuite;
SDLTest_TestCaseReference *testCase;
const SDLTest_TestCaseReference *testCase;
const char *runSeed = NULL;
char *currentSuiteName;
char *currentTestName;
@ -396,7 +398,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
Uint32 testPassedCount = 0;
Uint32 testSkippedCount = 0;
Uint32 countSum = 0;
SDLTest_TestCaseReference **failedTests;
const SDLTest_TestCaseReference **failedTests;
/* Sanitize test iterations */
if (testIterations < 1) {
@ -440,7 +442,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
}
/* Pre-allocate an array for tracking failed tests (potentially all test cases) */
failedTests = (SDLTest_TestCaseReference **)SDL_malloc(totalNumberOfTests * sizeof(SDLTest_TestCaseReference *));
failedTests = (const SDLTest_TestCaseReference **)SDL_malloc(totalNumberOfTests * sizeof(SDLTest_TestCaseReference *));
if (failedTests == NULL) {
SDLTest_LogError("Unable to allocate cache for failed tests");
SDL_Error(SDL_ENOMEM);
@ -466,7 +468,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
testCounter = 0;
while (testSuite->testCases[testCounter] && testFilter == 0)
{
testCase=(SDLTest_TestCaseReference *)testSuite->testCases[testCounter];
testCase = testSuite->testCases[testCounter];
testCounter++;
if (testCase->name != NULL && SDL_strcmp(filter, testCase->name) == 0) {
/* Matched a test name */
@ -483,7 +485,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
if (suiteFilter == 0 && testFilter == 0) {
SDLTest_LogError("Filter '%s' did not match any test suite/case.", filter);
SDLTest_Log("Exit code: 2");
SDL_free(failedTests);
SDL_free((void *) failedTests);
return 2;
}
}
@ -521,7 +523,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
testCounter = 0;
while(testSuite->testCases[testCounter])
{
testCase=(SDLTest_TestCaseReference *)testSuite->testCases[testCounter];
testCase = testSuite->testCases[testCounter];
currentTestName = (char *)((testCase->name) ? testCase->name : SDLTEST_INVALID_NAME_FORMAT);
testCounter++;
@ -562,7 +564,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
if (userExecKey != 0) {
execKey = userExecKey;
} else {
execKey = SDLTest_GenerateExecKey((char *)runSeed, testSuite->name, testCase->name, iterationCounter);
execKey = SDLTest_GenerateExecKey(runSeed, testSuite->name, testCase->name, iterationCounter);
}
SDLTest_Log("Test Iteration %i: execKey %" SDL_PRIu64, iterationCounter, execKey);
@ -669,8 +671,10 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
SDLTest_Log(" --seed %s --filter %s", runSeed, failedTests[testCounter]->name);
}
}
SDL_free(failedTests);
SDL_free((void *) failedTests);
SDLTest_Log("Exit code: %d", runResult);
return runResult;
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -24,7 +24,7 @@
/* GIMP RGB C-Source image dump (blit.c) */
const SDLTest_SurfaceImage_t SDLTest_imageBlit = {
static const SDLTest_SurfaceImage_t SDLTest_imageBlit = {
80, 60, 3,
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
@ -561,7 +561,7 @@ SDL_Surface *SDLTest_ImageBlit()
return surface;
}
const SDLTest_SurfaceImage_t SDLTest_imageBlitColor = {
static const SDLTest_SurfaceImage_t SDLTest_imageBlitColor = {
80, 60, 3,
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
@ -1044,7 +1044,7 @@ SDL_Surface *SDLTest_ImageBlitColor()
return surface;
}
const SDLTest_SurfaceImage_t SDLTest_imageBlitAlpha = {
static const SDLTest_SurfaceImage_t SDLTest_imageBlitAlpha = {
80, 60, 3,
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
@ -1555,3 +1555,5 @@ SDL_Surface *SDLTest_ImageBlitAlpha()
);
return surface;
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -24,7 +24,7 @@
/* GIMP RGB C-Source image dump (alpha.c) */
const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendAdd = {
static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendAdd = {
80, 60, 3,
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
@ -601,7 +601,7 @@ SDL_Surface *SDLTest_ImageBlitBlendAdd()
return surface;
}
const SDLTest_SurfaceImage_t SDLTest_imageBlitBlend = {
static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlend = {
80, 60, 3,
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
@ -1131,7 +1131,7 @@ SDL_Surface *SDLTest_ImageBlitBlend()
return surface;
}
const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendMod = {
static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendMod = {
80, 60, 3,
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
@ -1561,7 +1561,7 @@ SDL_Surface *SDLTest_ImageBlitBlendMod()
return surface;
}
const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendNone = {
static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendNone = {
80, 60, 3,
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
@ -2374,7 +2374,7 @@ SDL_Surface *SDLTest_ImageBlitBlendNone()
return surface;
}
const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendAll = {
static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendAll = {
80, 60, 3,
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
@ -2841,3 +2841,5 @@ SDL_Surface *SDLTest_ImageBlitBlendAll()
);
return surface;
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -24,7 +24,7 @@
/* GIMP RGBA C-Source image dump (face.c) */
const SDLTest_SurfaceImage_t SDLTest_imageFace = {
static const SDLTest_SurfaceImage_t SDLTest_imageFace = {
32, 32, 4,
"\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
"\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
@ -244,3 +244,4 @@ SDL_Surface *SDLTest_ImageFace()
return surface;
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -24,7 +24,7 @@
/* GIMP RGB C-Source image dump (primitives.c) */
const SDLTest_SurfaceImage_t SDLTest_imagePrimitives = {
static const SDLTest_SurfaceImage_t SDLTest_imagePrimitives = {
80, 60, 3,
"\5ii\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
@ -510,3 +510,5 @@ SDL_Surface *SDLTest_ImagePrimitives()
);
return surface;
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -24,7 +24,7 @@
/* GIMP RGB C-Source image dump (alpha.c) */
const SDLTest_SurfaceImage_t SDLTest_imagePrimitivesBlend = {
static const SDLTest_SurfaceImage_t SDLTest_imagePrimitivesBlend = {
80, 60, 3,
"\260e\15\222\356/\37\313\15\36\330\17K\3745D\3471\0\20\0D\3502D\3502<\321"
",\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\0-\0\377\377"
@ -692,3 +692,5 @@ SDL_Surface *SDLTest_ImagePrimitivesBlend()
);
return surface;
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -26,7 +26,9 @@
*/
/* quiet windows compiler warnings */
#define _CRT_SECURE_NO_WARNINGS
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
# define _CRT_SECURE_NO_WARNINGS
#endif
#include "SDL_config.h"
@ -39,6 +41,19 @@
#include "SDL_test.h"
/* work around compiler warning on older GCCs. */
#if (defined(__GNUC__) && (__GNUC__ <= 2))
static size_t
strftime_gcc2_workaround(char *s, size_t max, const char *fmt, const struct tm *tm)
{
return strftime(s, max, fmt, tm);
}
#ifdef strftime
#undef strftime
#endif
#define strftime strftime_gcc2_workaround
#endif
/* !
* Converts unix timestamp to its ascii representation in localtime
*
@ -50,7 +65,7 @@
*
* \return Ascii representation of the timestamp in localtime in the format '08/23/01 14:55:02'
*/
char *SDLTest_TimestampToString(const time_t timestamp)
static char *SDLTest_TimestampToString(const time_t timestamp)
{
time_t copy;
static char buffer[64];
@ -99,3 +114,5 @@ void SDLTest_LogError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
/* Log with timestamp and newline */
SDL_LogMessage(SDL_LOG_CATEGORY_TEST, SDL_LOG_PRIORITY_ERROR, "%s: %s", SDLTest_TimestampToString(time(0)), logMessage);
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -334,3 +334,5 @@ static void SDLTest_Md5Transform(MD5UINT4 * buf, MD5UINT4 * in)
buf[2] += c;
buf[3] += d;
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -0,0 +1,274 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_config.h"
#include "SDL_assert.h"
#include "SDL_stdinc.h"
#include "SDL_log.h"
#include "SDL_test_crc32.h"
#include "SDL_test_memory.h"
#ifdef HAVE_LIBUNWIND_H
#include <libunwind.h>
#endif
/* This is a simple tracking allocator to demonstrate the use of SDL's
memory allocation replacement functionality.
It gets slow with large numbers of allocations and shouldn't be used
for production code.
*/
typedef struct SDL_tracked_allocation
{
void *mem;
size_t size;
Uint64 stack[10];
char stack_names[10][256];
struct SDL_tracked_allocation *next;
} SDL_tracked_allocation;
static SDLTest_Crc32Context s_crc32_context;
static SDL_malloc_func SDL_malloc_orig = NULL;
static SDL_calloc_func SDL_calloc_orig = NULL;
static SDL_realloc_func SDL_realloc_orig = NULL;
static SDL_free_func SDL_free_orig = NULL;
static int s_previous_allocations = 0;
static SDL_tracked_allocation *s_tracked_allocations[256];
static unsigned int get_allocation_bucket(void *mem)
{
CrcUint32 crc_value;
unsigned int index;
SDLTest_Crc32Calc(&s_crc32_context, (CrcUint8 *)&mem, sizeof(mem), &crc_value);
index = (crc_value & (SDL_arraysize(s_tracked_allocations) - 1));
return index;
}
static SDL_bool SDL_IsAllocationTracked(void *mem)
{
SDL_tracked_allocation *entry;
int index = get_allocation_bucket(mem);
for (entry = s_tracked_allocations[index]; entry; entry = entry->next) {
if (mem == entry->mem) {
return SDL_TRUE;
}
}
return SDL_FALSE;
}
static void SDL_TrackAllocation(void *mem, size_t size)
{
SDL_tracked_allocation *entry;
int index = get_allocation_bucket(mem);
if (SDL_IsAllocationTracked(mem)) {
return;
}
entry = (SDL_tracked_allocation *)SDL_malloc_orig(sizeof(*entry));
if (!entry) {
return;
}
entry->mem = mem;
entry->size = size;
/* Generate the stack trace for the allocation */
SDL_zero(entry->stack);
#ifdef HAVE_LIBUNWIND_H
{
int stack_index;
unw_cursor_t cursor;
unw_context_t context;
unw_getcontext(&context);
unw_init_local(&cursor, &context);
stack_index = 0;
while (unw_step(&cursor) > 0) {
unw_word_t offset, pc;
char sym[256];
unw_get_reg(&cursor, UNW_REG_IP, &pc);
entry->stack[stack_index] = pc;
if (unw_get_proc_name(&cursor, sym, sizeof(sym), &offset) == 0) {
snprintf(entry->stack_names[stack_index], sizeof(entry->stack_names[stack_index]), "%s+0x%llx", sym, offset);
}
++stack_index;
if (stack_index == SDL_arraysize(entry->stack)) {
break;
}
}
}
#endif /* HAVE_LIBUNWIND_H */
entry->next = s_tracked_allocations[index];
s_tracked_allocations[index] = entry;
}
static void SDL_UntrackAllocation(void *mem)
{
SDL_tracked_allocation *entry, *prev;
int index = get_allocation_bucket(mem);
prev = NULL;
for (entry = s_tracked_allocations[index]; entry; entry = entry->next) {
if (mem == entry->mem) {
if (prev) {
prev->next = entry->next;
} else {
s_tracked_allocations[index] = entry->next;
}
SDL_free_orig(entry);
return;
}
prev = entry;
}
}
static void * SDLCALL SDLTest_TrackedMalloc(size_t size)
{
void *mem;
mem = SDL_malloc_orig(size);
if (mem) {
SDL_TrackAllocation(mem, size);
}
return mem;
}
static void * SDLCALL SDLTest_TrackedCalloc(size_t nmemb, size_t size)
{
void *mem;
mem = SDL_calloc_orig(nmemb, size);
if (mem) {
SDL_TrackAllocation(mem, nmemb * size);
}
return mem;
}
static void * SDLCALL SDLTest_TrackedRealloc(void *ptr, size_t size)
{
void *mem;
SDL_assert(!ptr || SDL_IsAllocationTracked(ptr));
mem = SDL_realloc_orig(ptr, size);
if (mem && mem != ptr) {
if (ptr) {
SDL_UntrackAllocation(ptr);
}
SDL_TrackAllocation(mem, size);
}
return mem;
}
static void SDLCALL SDLTest_TrackedFree(void *ptr)
{
if (!ptr) {
return;
}
if (!s_previous_allocations) {
SDL_assert(SDL_IsAllocationTracked(ptr));
}
SDL_UntrackAllocation(ptr);
SDL_free_orig(ptr);
}
int SDLTest_TrackAllocations()
{
if (SDL_malloc_orig) {
return 0;
}
SDLTest_Crc32Init(&s_crc32_context);
s_previous_allocations = SDL_GetNumAllocations();
if (s_previous_allocations != 0) {
SDL_Log("SDLTest_TrackAllocations(): There are %d previous allocations, disabling free() validation", s_previous_allocations);
}
SDL_GetMemoryFunctions(&SDL_malloc_orig,
&SDL_calloc_orig,
&SDL_realloc_orig,
&SDL_free_orig);
SDL_SetMemoryFunctions(SDLTest_TrackedMalloc,
SDLTest_TrackedCalloc,
SDLTest_TrackedRealloc,
SDLTest_TrackedFree);
return 0;
}
void SDLTest_LogAllocations()
{
char *message = NULL;
size_t message_size = 0;
char line[128], *tmp;
SDL_tracked_allocation *entry;
int index, count, stack_index;
Uint64 total_allocated;
if (!SDL_malloc_orig) {
return;
}
#define ADD_LINE() \
message_size += (SDL_strlen(line) + 1); \
tmp = (char *)SDL_realloc_orig(message, message_size); \
if (!tmp) { \
return; \
} \
message = tmp; \
SDL_strlcat(message, line, message_size)
SDL_strlcpy(line, "Memory allocations:\n", sizeof(line));
ADD_LINE();
SDL_strlcpy(line, "Expect 2 allocations from within SDL_GetErrBuf()\n", sizeof(line));
ADD_LINE();
count = 0;
total_allocated = 0;
for (index = 0; index < SDL_arraysize(s_tracked_allocations); ++index) {
for (entry = s_tracked_allocations[index]; entry; entry = entry->next) {
SDL_snprintf(line, sizeof(line), "Allocation %d: %d bytes\n", count, (int)entry->size);
ADD_LINE();
/* Start at stack index 1 to skip our tracking functions */
for (stack_index = 1; stack_index < SDL_arraysize(entry->stack); ++stack_index) {
if (!entry->stack[stack_index]) {
break;
}
SDL_snprintf(line, sizeof(line), "\t0x%"SDL_PRIx64": %s\n", entry->stack[stack_index], entry->stack_names[stack_index]);
ADD_LINE();
}
total_allocated += entry->size;
++count;
}
}
SDL_snprintf(line, sizeof(line), "Total: %.2f Kb in %d allocations\n", (float)total_allocated / 1024, count);
ADD_LINE();
#undef ADD_LINE
SDL_Log("%s", message);
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -70,7 +70,7 @@ void SDLTest_RandomInitTime(SDLTest_RandomContext * rndContext)
srand((unsigned int)time(NULL));
a=rand();
srand(clock());
srand((unsigned int)clock());
b=rand();
SDLTest_RandomInit(rndContext, a, b);
}
@ -92,3 +92,5 @@ unsigned int SDLTest_Random(SDLTest_RandomContext * rndContext)
rndContext->c++;
return (rndContext->x);
}
/* vi: set ts=4 sw=4 expandtab: */