Added existing common.c/.h functions to test lib; minor assert refactoring
authorAndreas Schiffler <aschiffler@ferzkopp.net>
Sun, 09 Dec 2012 17:56:19 -0800
changeset 67271b5280cd5885
parent 6726 f2898757eaae
child 6728 0f8336c1f6d9
Added existing common.c/.h functions to test lib; minor assert refactoring
VisualC/SDLtest/SDLtest_VS2010.vcxproj
VisualC/SDLtest/SDLtest_VS2012.vcxproj
include/SDL_test.h
include/SDL_test_assert.h
include/SDL_test_common.h
src/test/SDL_test_assert.c
src/test/SDL_test_common.c
src/test/SDL_test_harness.c
     1.1 --- a/VisualC/SDLtest/SDLtest_VS2010.vcxproj	Sat Dec 08 15:33:14 2012 -0500
     1.2 +++ b/VisualC/SDLtest/SDLtest_VS2010.vcxproj	Sun Dec 09 17:56:19 2012 -0800
     1.3 @@ -153,6 +153,7 @@
     1.4    <ItemGroup>
     1.5      <ClInclude Include="..\..\include\SDL_test.h" />
     1.6      <ClInclude Include="..\..\include\SDL_test_assert.h" />
     1.7 +    <ClInclude Include="..\..\include\SDL_test_common.h" />
     1.8      <ClInclude Include="..\..\include\SDL_test_crc32.h" />
     1.9      <ClInclude Include="..\..\include\SDL_test_font.h" />
    1.10      <ClInclude Include="..\..\include\SDL_test_fuzzer.h" />
    1.11 @@ -163,6 +164,7 @@
    1.12    </ItemGroup>
    1.13    <ItemGroup>
    1.14      <ClCompile Include="..\..\src\test\SDL_test_assert.c" />
    1.15 +    <ClCompile Include="..\..\src\test\SDL_test_common.c" />
    1.16      <ClCompile Include="..\..\src\test\SDL_test_crc32.c" />
    1.17      <ClCompile Include="..\..\src\test\SDL_test_font.c" />
    1.18      <ClCompile Include="..\..\src\test\SDL_test_fuzzer.c" />
     2.1 --- a/VisualC/SDLtest/SDLtest_VS2012.vcxproj	Sat Dec 08 15:33:14 2012 -0500
     2.2 +++ b/VisualC/SDLtest/SDLtest_VS2012.vcxproj	Sun Dec 09 17:56:19 2012 -0800
     2.3 @@ -157,6 +157,7 @@
     2.4    <ItemGroup>
     2.5      <ClInclude Include="..\..\include\SDL_test.h" />
     2.6      <ClInclude Include="..\..\include\SDL_test_assert.h" />
     2.7 +    <ClInclude Include="..\..\include\SDL_test_common.h" />
     2.8      <ClInclude Include="..\..\include\SDL_test_crc32.h" />
     2.9      <ClInclude Include="..\..\include\SDL_test_font.h" />
    2.10      <ClInclude Include="..\..\include\SDL_test_fuzzer.h" />
    2.11 @@ -167,6 +168,7 @@
    2.12    </ItemGroup>
    2.13    <ItemGroup>
    2.14      <ClCompile Include="..\..\src\test\SDL_test_assert.c" />
    2.15 +    <ClCompile Include="..\..\src\test\SDL_test_common.c" />
    2.16      <ClCompile Include="..\..\src\test\SDL_test_crc32.c" />
    2.17      <ClCompile Include="..\..\src\test\SDL_test_font.c" />
    2.18      <ClCompile Include="..\..\src\test\SDL_test_fuzzer.c" />
     3.1 --- a/include/SDL_test.h	Sat Dec 08 15:33:14 2012 -0500
     3.2 +++ b/include/SDL_test.h	Sun Dec 09 17:56:19 2012 -0800
     3.3 @@ -31,6 +31,7 @@
     3.4  #define _SDL_test_h
     3.5  
     3.6  #include "SDL.h"
     3.7 +#include "SDL_test_common.h"
     3.8  #include "SDL_test_font.h"
     3.9  #include "SDL_test_random.h"
    3.10  #include "SDL_test_fuzzer.h"
     4.1 --- a/include/SDL_test_assert.h	Sat Dec 08 15:33:14 2012 -0500
     4.2 +++ b/include/SDL_test_assert.h	Sun Dec 09 17:56:19 2012 -0800
     4.3 @@ -54,12 +54,6 @@
     4.4   */
     4.5  #define ASSERT_PASS		1
     4.6  
     4.7 -/*! \brief counts the failed asserts */
     4.8 -static Uint32 SDLTest_AssertsFailed = 0;
     4.9 -
    4.10 -/*! \brief counts the passed asserts */
    4.11 -static Uint32 SDLTest_AssertsPassed = 0;
    4.12 -
    4.13  /**
    4.14   * \brief Assert that logs and break execution flow on failures.
    4.15   *
    4.16 @@ -85,10 +79,17 @@
    4.17  
    4.18  /**
    4.19   * \brief Logs summary of all assertions (total, pass, fail) since last reset as INFO or ERROR.
    4.20 - *
    4.21   */
    4.22  void SDLTest_LogAssertSummary();
    4.23  
    4.24 +
    4.25 +/**
    4.26 + * \brief Converts the current assert summary state to a test result.
    4.27 + *
    4.28 + * \returns TEST_RESULT_PASSED, TEST_RESULT_FAILED, or TEST_RESULT_NO_ASSERT
    4.29 + */
    4.30 +int SDLTest_AssertSummaryToTestResult();
    4.31 +
    4.32  #ifdef __cplusplus
    4.33  /* *INDENT-OFF* */
    4.34  }
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/include/SDL_test_common.h	Sun Dec 09 17:56:19 2012 -0800
     5.3 @@ -0,0 +1,182 @@
     5.4 +/*
     5.5 +  Simple DirectMedia Layer
     5.6 +  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     5.7 +
     5.8 +  This software is provided 'as-is', without any express or implied
     5.9 +  warranty.  In no event will the authors be held liable for any damages
    5.10 +  arising from the use of this software.
    5.11 +
    5.12 +  Permission is granted to anyone to use this software for any purpose,
    5.13 +  including commercial applications, and to alter it and redistribute it
    5.14 +  freely, subject to the following restrictions:
    5.15 +
    5.16 +  1. The origin of this software must not be misrepresented; you must not
    5.17 +     claim that you wrote the original software. If you use this software
    5.18 +     in a product, an acknowledgment in the product documentation would be
    5.19 +     appreciated but is not required.
    5.20 +  2. Altered source versions must be plainly marked as such, and must not be
    5.21 +     misrepresented as being the original software.
    5.22 +  3. This notice may not be removed or altered from any source distribution.
    5.23 +*/
    5.24 +
    5.25 +/**
    5.26 + *  \file SDL_test_common.h
    5.27 + *  
    5.28 + *  Include file for SDL test framework.
    5.29 + *
    5.30 + *  This code is a part of the SDL2_test library, not the main SDL library.
    5.31 + */
    5.32 +
    5.33 +/* Ported from original test\common.h file. */
    5.34 +
    5.35 +#ifndef _SDL_test_common_h
    5.36 +#define _SDL_test_common_h
    5.37 +
    5.38 +#include "SDL.h"
    5.39 +
    5.40 +#ifdef __NDS__
    5.41 +#define DEFAULT_WINDOW_WIDTH  256
    5.42 +#define DEFAULT_WINDOW_HEIGHT (2*192)
    5.43 +#else
    5.44 +#define DEFAULT_WINDOW_WIDTH  640
    5.45 +#define DEFAULT_WINDOW_HEIGHT 480
    5.46 +#endif
    5.47 +
    5.48 +#define VERBOSE_VIDEO   0x00000001
    5.49 +#define VERBOSE_MODES   0x00000002
    5.50 +#define VERBOSE_RENDER  0x00000004
    5.51 +#define VERBOSE_EVENT   0x00000008
    5.52 +#define VERBOSE_AUDIO   0x00000010
    5.53 +
    5.54 +typedef struct
    5.55 +{
    5.56 +    /* SDL init flags */
    5.57 +    char **argv;
    5.58 +    Uint32 flags;
    5.59 +    Uint32 verbose;
    5.60 +
    5.61 +    /* Video info */
    5.62 +    const char *videodriver;
    5.63 +    int display;
    5.64 +    const char *window_title;
    5.65 +    const char *window_icon;
    5.66 +    Uint32 window_flags;
    5.67 +    int window_x;
    5.68 +    int window_y;
    5.69 +    int window_w;
    5.70 +    int window_h;
    5.71 +    int depth;
    5.72 +    int refresh_rate;
    5.73 +    int num_windows;
    5.74 +    SDL_Window **windows;
    5.75 +
    5.76 +    /* Renderer info */
    5.77 +    const char *renderdriver;
    5.78 +    Uint32 render_flags;
    5.79 +    SDL_bool skip_renderer;
    5.80 +    SDL_Renderer **renderers;
    5.81 +
    5.82 +    /* Audio info */
    5.83 +    const char *audiodriver;
    5.84 +    SDL_AudioSpec audiospec;
    5.85 +
    5.86 +    /* GL settings */
    5.87 +    int gl_red_size;
    5.88 +    int gl_green_size;
    5.89 +    int gl_blue_size;
    5.90 +    int gl_alpha_size;
    5.91 +    int gl_buffer_size;
    5.92 +    int gl_depth_size;
    5.93 +    int gl_stencil_size;
    5.94 +    int gl_double_buffer;
    5.95 +    int gl_accum_red_size;
    5.96 +    int gl_accum_green_size;
    5.97 +    int gl_accum_blue_size;
    5.98 +    int gl_accum_alpha_size;
    5.99 +    int gl_stereo;
   5.100 +    int gl_multisamplebuffers;
   5.101 +    int gl_multisamplesamples;
   5.102 +    int gl_retained_backing;
   5.103 +    int gl_accelerated;
   5.104 +    int gl_major_version;
   5.105 +    int gl_minor_version;
   5.106 +} SDLTest_CommonState;
   5.107 +
   5.108 +#include "begin_code.h"
   5.109 +/* Set up for C function definitions, even when using C++ */
   5.110 +#ifdef __cplusplus
   5.111 +/* *INDENT-OFF* */
   5.112 +extern "C" {
   5.113 +/* *INDENT-ON* */
   5.114 +#endif
   5.115 +
   5.116 +/* Function prototypes */
   5.117 +
   5.118 +/**
   5.119 + * \brief Parse command line parameters and create common state.
   5.120 + *
   5.121 + * \param argv Array of command line parameters
   5.122 + * \param flags Flags indicating which subsystem to initialize (i.e. SDL_INIT_VIDEO | SDL_INIT_AUDIO)
   5.123 + *
   5.124 + * \returns Returns a newly allocated common state object.
   5.125 + */
   5.126 +SDLTest_CommonState *SDLTest_CommonCreateState(char **argv, Uint32 flags);
   5.127 +
   5.128 +/**
   5.129 + * \brief Process one common argument.
   5.130 + *
   5.131 + * \param state The common state describing the test window to create.
   5.132 + * \param index The index of the argument to process in argv[].
   5.133 + *
   5.134 + * \returns The number of arguments processed (i.e. 1 for --fullscreen, 2 for --video [videodriver], or -1 on error.
   5.135 + */
   5.136 +int SDLTest_CommonArg(SDLTest_CommonState * state, int index);
   5.137 +
   5.138 +/**
   5.139 + * \brief Returns common usage information
   5.140 + *
   5.141 + * \param state The common state describing the test window to create.
   5.142 + *
   5.143 + * \returns String with usage information
   5.144 + */
   5.145 +const char *SDLTest_CommonUsage(SDLTest_CommonState * state);
   5.146 +
   5.147 +/**
   5.148 + * \brief Open test window.
   5.149 + *
   5.150 + * \param state The common state describing the test window to create.
   5.151 + *
   5.152 + * \returns True if initialization succeeded, false otherwise
   5.153 + */
   5.154 +SDL_bool SDLTest_CommonInit(SDLTest_CommonState * state);
   5.155 +
   5.156 +/**
   5.157 + * \brief Common event handler for test windows.
   5.158 + *
   5.159 + * \param state The common state used to create test window.
   5.160 + * \param event The event to handle.
   5.161 + * \param done Flag indicating we are done.
   5.162 + *
   5.163 + */
   5.164 +void SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done);
   5.165 +
   5.166 +/**
   5.167 + * \brief Close test window.
   5.168 + *
   5.169 + * \param state The common state used to create test window.
   5.170 + *
   5.171 + */
   5.172 +void SDLTest_CommonQuit(SDLTest_CommonState * state);
   5.173 +
   5.174 +
   5.175 +/* Ends C function definitions when using C++ */
   5.176 +#ifdef __cplusplus
   5.177 +/* *INDENT-OFF* */
   5.178 +}
   5.179 +/* *INDENT-ON* */
   5.180 +#endif
   5.181 +#include "close_code.h"
   5.182 +
   5.183 +#endif /* _SDL_test_common_h */
   5.184 +
   5.185 +/* vi: set ts=4 sw=4 expandtab: */
     6.1 --- a/src/test/SDL_test_assert.c	Sat Dec 08 15:33:14 2012 -0500
     6.2 +++ b/src/test/SDL_test_assert.c	Sun Dec 09 17:56:19 2012 -0800
     6.3 @@ -35,6 +35,12 @@
     6.4  /* Assert summary message format */
     6.5  const char *SDLTest_AssertSummaryFmt = "Assert Summary: Total=%d Passed=%d Failed=%d";
     6.6  
     6.7 +/*! \brief counts the failed asserts */
     6.8 +static Uint32 SDLTest_AssertsFailed = 0;
     6.9 +
    6.10 +/*! \brief counts the passed asserts */
    6.11 +static Uint32 SDLTest_AssertsPassed = 0;
    6.12 +
    6.13  /*
    6.14   *  Assert that logs and break execution flow on failures (i.e. for harness errors).
    6.15   */
    6.16 @@ -89,3 +95,19 @@
    6.17  		SDLTest_LogError(fmt, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
    6.18  	}
    6.19  }
    6.20 +
    6.21 +/*
    6.22 + * Converts the current assert state into a test result
    6.23 + */
    6.24 +int SDLTest_AssertSummaryToTestResult()
    6.25 +{
    6.26 +	if (SDLTest_AssertsFailed > 0) {
    6.27 +		return TEST_RESULT_FAILED;
    6.28 +	} else {
    6.29 +		if (SDLTest_AssertsPassed > 0) {
    6.30 +			return TEST_RESULT_PASSED;
    6.31 +		} else {
    6.32 +			return TEST_RESULT_NO_ASSERT;
    6.33 +		}
    6.34 +	}
    6.35 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/test/SDL_test_common.c	Sun Dec 09 17:56:19 2012 -0800
     7.3 @@ -0,0 +1,1261 @@
     7.4 +/*
     7.5 +  Simple DirectMedia Layer
     7.6 +  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     7.7 +
     7.8 +  This software is provided 'as-is', without any express or implied
     7.9 +  warranty.  In no event will the authors be held liable for any damages
    7.10 +  arising from the use of this software.
    7.11 +
    7.12 +  Permission is granted to anyone to use this software for any purpose,
    7.13 +  including commercial applications, and to alter it and redistribute it
    7.14 +  freely, subject to the following restrictions:
    7.15 +
    7.16 +  1. The origin of this software must not be misrepresented; you must not
    7.17 +     claim that you wrote the original software. If you use this software
    7.18 +     in a product, an acknowledgment in the product documentation would be
    7.19 +     appreciated but is not required.
    7.20 +  2. Altered source versions must be plainly marked as such, and must not be
    7.21 +     misrepresented as being the original software.
    7.22 +  3. This notice may not be removed or altered from any source distribution.
    7.23 +*/
    7.24 +
    7.25 +/* Ported from original test\common.c file. */
    7.26 +
    7.27 +#include "SDL_config.h"
    7.28 +#include "SDL_test.h"
    7.29 +
    7.30 +#include <stdio.h>
    7.31 +
    7.32 +#define VIDEO_USAGE \
    7.33 +"[--video driver] [--renderer driver] [--info all|video|modes|render|event] [--log all|error|system|audio|video|render|input] [--display N] [--fullscreen | --windows N] [--title title] [--icon icon.bmp] [--center | --position X,Y] [--geometry WxH] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab]"
    7.34 +
    7.35 +#define AUDIO_USAGE \
    7.36 +"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
    7.37 +
    7.38 +SDLTest_CommonState *
    7.39 +SDLTest_CommonCreateState(char **argv, Uint32 flags)
    7.40 +{
    7.41 +    SDLTest_CommonState *state = (SDLTest_CommonState *)SDL_calloc(1, sizeof(*state));
    7.42 +    if (!state) {
    7.43 +        SDL_OutOfMemory();
    7.44 +        return NULL;
    7.45 +    }
    7.46 +
    7.47 +    /* Initialize some defaults */
    7.48 +    state->argv = argv;
    7.49 +    state->flags = flags;
    7.50 +#ifdef __NDS__
    7.51 +    state->window_title = "";
    7.52 +#else
    7.53 +    state->window_title = argv[0];
    7.54 +#endif
    7.55 +    state->window_flags = 0;
    7.56 +    state->window_x = SDL_WINDOWPOS_UNDEFINED;
    7.57 +    state->window_y = SDL_WINDOWPOS_UNDEFINED;
    7.58 +    state->window_w = DEFAULT_WINDOW_WIDTH;
    7.59 +    state->window_h = DEFAULT_WINDOW_HEIGHT;
    7.60 +    state->num_windows = 1;
    7.61 +    state->audiospec.freq = 22050;
    7.62 +    state->audiospec.format = AUDIO_S16;
    7.63 +    state->audiospec.channels = 2;
    7.64 +    state->audiospec.samples = 2048;
    7.65 +
    7.66 +    /* Set some very sane GL defaults */
    7.67 +    state->gl_red_size = 3;
    7.68 +    state->gl_green_size = 3;
    7.69 +    state->gl_blue_size = 2;
    7.70 +    state->gl_alpha_size = 0;
    7.71 +    state->gl_buffer_size = 0;
    7.72 +    state->gl_depth_size = 16;
    7.73 +    state->gl_stencil_size = 0;
    7.74 +    state->gl_double_buffer = 1;
    7.75 +    state->gl_accum_red_size = 0;
    7.76 +    state->gl_accum_green_size = 0;
    7.77 +    state->gl_accum_blue_size = 0;
    7.78 +    state->gl_accum_alpha_size = 0;
    7.79 +    state->gl_stereo = 0;
    7.80 +    state->gl_multisamplebuffers = 0;
    7.81 +    state->gl_multisamplesamples = 0;
    7.82 +    state->gl_retained_backing = 1;
    7.83 +    state->gl_accelerated = -1;
    7.84 +
    7.85 +    return state;
    7.86 +}
    7.87 +
    7.88 +int
    7.89 +SDLTest_CommonArg(SDLTest_CommonState * state, int index)
    7.90 +{
    7.91 +    char **argv = state->argv;
    7.92 +
    7.93 +#ifdef __NDS__
    7.94 +    return 0;
    7.95 +#endif
    7.96 +
    7.97 +    if (SDL_strcasecmp(argv[index], "--video") == 0) {
    7.98 +        ++index;
    7.99 +        if (!argv[index]) {
   7.100 +            return -1;
   7.101 +        }
   7.102 +        state->videodriver = argv[index];
   7.103 +        return 2;
   7.104 +    }
   7.105 +    if (SDL_strcasecmp(argv[index], "--renderer") == 0) {
   7.106 +        ++index;
   7.107 +        if (!argv[index]) {
   7.108 +            return -1;
   7.109 +        }
   7.110 +        state->renderdriver = argv[index];
   7.111 +        return 2;
   7.112 +    }
   7.113 +    if (SDL_strcasecmp(argv[index], "--info") == 0) {
   7.114 +        ++index;
   7.115 +        if (!argv[index]) {
   7.116 +            return -1;
   7.117 +        }
   7.118 +        if (SDL_strcasecmp(argv[index], "all") == 0) {
   7.119 +            state->verbose |=
   7.120 +                (VERBOSE_VIDEO | VERBOSE_MODES | VERBOSE_RENDER |
   7.121 +                 VERBOSE_EVENT);
   7.122 +            return 2;
   7.123 +        }
   7.124 +        if (SDL_strcasecmp(argv[index], "video") == 0) {
   7.125 +            state->verbose |= VERBOSE_VIDEO;
   7.126 +            return 2;
   7.127 +        }
   7.128 +        if (SDL_strcasecmp(argv[index], "modes") == 0) {
   7.129 +            state->verbose |= VERBOSE_MODES;
   7.130 +            return 2;
   7.131 +        }
   7.132 +        if (SDL_strcasecmp(argv[index], "render") == 0) {
   7.133 +            state->verbose |= VERBOSE_RENDER;
   7.134 +            return 2;
   7.135 +        }
   7.136 +        if (SDL_strcasecmp(argv[index], "event") == 0) {
   7.137 +            state->verbose |= VERBOSE_EVENT;
   7.138 +            return 2;
   7.139 +        }
   7.140 +        return -1;
   7.141 +    }
   7.142 +    if (SDL_strcasecmp(argv[index], "--log") == 0) {
   7.143 +        ++index;
   7.144 +        if (!argv[index]) {
   7.145 +            return -1;
   7.146 +        }
   7.147 +        if (SDL_strcasecmp(argv[index], "all") == 0) {
   7.148 +            SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE);
   7.149 +            return 2;
   7.150 +        }
   7.151 +        if (SDL_strcasecmp(argv[index], "error") == 0) {
   7.152 +            SDL_LogSetPriority(SDL_LOG_CATEGORY_ERROR, SDL_LOG_PRIORITY_VERBOSE);
   7.153 +            return 2;
   7.154 +        }
   7.155 +        if (SDL_strcasecmp(argv[index], "system") == 0) {
   7.156 +            SDL_LogSetPriority(SDL_LOG_CATEGORY_SYSTEM, SDL_LOG_PRIORITY_VERBOSE);
   7.157 +            return 2;
   7.158 +        }
   7.159 +        if (SDL_strcasecmp(argv[index], "audio") == 0) {
   7.160 +            SDL_LogSetPriority(SDL_LOG_CATEGORY_AUDIO, SDL_LOG_PRIORITY_VERBOSE);
   7.161 +            return 2;
   7.162 +        }
   7.163 +        if (SDL_strcasecmp(argv[index], "video") == 0) {
   7.164 +            SDL_LogSetPriority(SDL_LOG_CATEGORY_VIDEO, SDL_LOG_PRIORITY_VERBOSE);
   7.165 +            return 2;
   7.166 +        }
   7.167 +        if (SDL_strcasecmp(argv[index], "render") == 0) {
   7.168 +            SDL_LogSetPriority(SDL_LOG_CATEGORY_RENDER, SDL_LOG_PRIORITY_VERBOSE);
   7.169 +            return 2;
   7.170 +        }
   7.171 +        if (SDL_strcasecmp(argv[index], "input") == 0) {
   7.172 +            SDL_LogSetPriority(SDL_LOG_CATEGORY_INPUT, SDL_LOG_PRIORITY_VERBOSE);
   7.173 +            return 2;
   7.174 +        }
   7.175 +        return -1;
   7.176 +    }
   7.177 +    if (SDL_strcasecmp(argv[index], "--display") == 0) {
   7.178 +        ++index;
   7.179 +        if (!argv[index]) {
   7.180 +            return -1;
   7.181 +        }
   7.182 +        state->display = SDL_atoi(argv[index]);
   7.183 +        if (SDL_WINDOWPOS_ISUNDEFINED(state->window_x)) {
   7.184 +            state->window_x = SDL_WINDOWPOS_UNDEFINED_DISPLAY(state->display);
   7.185 +            state->window_y = SDL_WINDOWPOS_UNDEFINED_DISPLAY(state->display);
   7.186 +        }
   7.187 +        if (SDL_WINDOWPOS_ISCENTERED(state->window_x)) {
   7.188 +            state->window_x = SDL_WINDOWPOS_CENTERED_DISPLAY(state->display);
   7.189 +            state->window_y = SDL_WINDOWPOS_CENTERED_DISPLAY(state->display);
   7.190 +        }
   7.191 +        return 2;
   7.192 +    }
   7.193 +    if (SDL_strcasecmp(argv[index], "--fullscreen") == 0) {
   7.194 +        state->window_flags |= SDL_WINDOW_FULLSCREEN;
   7.195 +        state->num_windows = 1;
   7.196 +        return 1;
   7.197 +    }
   7.198 +    if (SDL_strcasecmp(argv[index], "--windows") == 0) {
   7.199 +        ++index;
   7.200 +        if (!argv[index] || !SDL_isdigit(*argv[index])) {
   7.201 +            return -1;
   7.202 +        }
   7.203 +        if (!(state->window_flags & SDL_WINDOW_FULLSCREEN)) {
   7.204 +            state->num_windows = SDL_atoi(argv[index]);
   7.205 +        }
   7.206 +        return 2;
   7.207 +    }
   7.208 +    if (SDL_strcasecmp(argv[index], "--title") == 0) {
   7.209 +        ++index;
   7.210 +        if (!argv[index]) {
   7.211 +            return -1;
   7.212 +        }
   7.213 +        state->window_title = argv[index];
   7.214 +        return 2;
   7.215 +    }
   7.216 +    if (SDL_strcasecmp(argv[index], "--icon") == 0) {
   7.217 +        ++index;
   7.218 +        if (!argv[index]) {
   7.219 +            return -1;
   7.220 +        }
   7.221 +        state->window_icon = argv[index];
   7.222 +        return 2;
   7.223 +    }
   7.224 +    if (SDL_strcasecmp(argv[index], "--center") == 0) {
   7.225 +        state->window_x = SDL_WINDOWPOS_CENTERED;
   7.226 +        state->window_y = SDL_WINDOWPOS_CENTERED;
   7.227 +        return 1;
   7.228 +    }
   7.229 +    if (SDL_strcasecmp(argv[index], "--position") == 0) {
   7.230 +        char *x, *y;
   7.231 +        ++index;
   7.232 +        if (!argv[index]) {
   7.233 +            return -1;
   7.234 +        }
   7.235 +        x = argv[index];
   7.236 +        y = argv[index];
   7.237 +        while (*y && *y != ',') {
   7.238 +            ++y;
   7.239 +        }
   7.240 +        if (!*y) {
   7.241 +            return -1;
   7.242 +        }
   7.243 +        *y++ = '\0';
   7.244 +        state->window_x = SDL_atoi(x);
   7.245 +        state->window_y = SDL_atoi(y);
   7.246 +        return 2;
   7.247 +    }
   7.248 +    if (SDL_strcasecmp(argv[index], "--geometry") == 0) {
   7.249 +        char *w, *h;
   7.250 +        ++index;
   7.251 +        if (!argv[index]) {
   7.252 +            return -1;
   7.253 +        }
   7.254 +        w = argv[index];
   7.255 +        h = argv[index];
   7.256 +        while (*h && *h != 'x') {
   7.257 +            ++h;
   7.258 +        }
   7.259 +        if (!*h) {
   7.260 +            return -1;
   7.261 +        }
   7.262 +        *h++ = '\0';
   7.263 +        state->window_w = SDL_atoi(w);
   7.264 +        state->window_h = SDL_atoi(h);
   7.265 +        return 2;
   7.266 +    }
   7.267 +    if (SDL_strcasecmp(argv[index], "--depth") == 0) {
   7.268 +        ++index;
   7.269 +        if (!argv[index]) {
   7.270 +            return -1;
   7.271 +        }
   7.272 +        state->depth = SDL_atoi(argv[index]);
   7.273 +        return 2;
   7.274 +    }
   7.275 +    if (SDL_strcasecmp(argv[index], "--refresh") == 0) {
   7.276 +        ++index;
   7.277 +        if (!argv[index]) {
   7.278 +            return -1;
   7.279 +        }
   7.280 +        state->refresh_rate = SDL_atoi(argv[index]);
   7.281 +        return 2;
   7.282 +    }
   7.283 +    if (SDL_strcasecmp(argv[index], "--vsync") == 0) {
   7.284 +        state->render_flags |= SDL_RENDERER_PRESENTVSYNC;
   7.285 +        return 1;
   7.286 +    }
   7.287 +    if (SDL_strcasecmp(argv[index], "--noframe") == 0) {
   7.288 +        state->window_flags |= SDL_WINDOW_BORDERLESS;
   7.289 +        return 1;
   7.290 +    }
   7.291 +    if (SDL_strcasecmp(argv[index], "--resize") == 0) {
   7.292 +        state->window_flags |= SDL_WINDOW_RESIZABLE;
   7.293 +        return 1;
   7.294 +    }
   7.295 +    if (SDL_strcasecmp(argv[index], "--minimize") == 0) {
   7.296 +        state->window_flags |= SDL_WINDOW_MINIMIZED;
   7.297 +        return 1;
   7.298 +    }
   7.299 +    if (SDL_strcasecmp(argv[index], "--maximize") == 0) {
   7.300 +        state->window_flags |= SDL_WINDOW_MAXIMIZED;
   7.301 +        return 1;
   7.302 +    }
   7.303 +    if (SDL_strcasecmp(argv[index], "--grab") == 0) {
   7.304 +        state->window_flags |= SDL_WINDOW_INPUT_GRABBED;
   7.305 +        return 1;
   7.306 +    }
   7.307 +    if (SDL_strcasecmp(argv[index], "--rate") == 0) {
   7.308 +        ++index;
   7.309 +        if (!argv[index]) {
   7.310 +            return -1;
   7.311 +        }
   7.312 +        state->audiospec.freq = SDL_atoi(argv[index]);
   7.313 +        return 2;
   7.314 +    }
   7.315 +    if (SDL_strcasecmp(argv[index], "--format") == 0) {
   7.316 +        ++index;
   7.317 +        if (!argv[index]) {
   7.318 +            return -1;
   7.319 +        }
   7.320 +        if (SDL_strcasecmp(argv[index], "U8") == 0) {
   7.321 +            state->audiospec.format = AUDIO_U8;
   7.322 +            return 2;
   7.323 +        }
   7.324 +        if (SDL_strcasecmp(argv[index], "S8") == 0) {
   7.325 +            state->audiospec.format = AUDIO_S8;
   7.326 +            return 2;
   7.327 +        }
   7.328 +        if (SDL_strcasecmp(argv[index], "U16") == 0) {
   7.329 +            state->audiospec.format = AUDIO_U16;
   7.330 +            return 2;
   7.331 +        }
   7.332 +        if (SDL_strcasecmp(argv[index], "U16LE") == 0) {
   7.333 +            state->audiospec.format = AUDIO_U16LSB;
   7.334 +            return 2;
   7.335 +        }
   7.336 +        if (SDL_strcasecmp(argv[index], "U16BE") == 0) {
   7.337 +            state->audiospec.format = AUDIO_U16MSB;
   7.338 +            return 2;
   7.339 +        }
   7.340 +        if (SDL_strcasecmp(argv[index], "S16") == 0) {
   7.341 +            state->audiospec.format = AUDIO_S16;
   7.342 +            return 2;
   7.343 +        }
   7.344 +        if (SDL_strcasecmp(argv[index], "S16LE") == 0) {
   7.345 +            state->audiospec.format = AUDIO_S16LSB;
   7.346 +            return 2;
   7.347 +        }
   7.348 +        if (SDL_strcasecmp(argv[index], "S16BE") == 0) {
   7.349 +            state->audiospec.format = AUDIO_S16MSB;
   7.350 +            return 2;
   7.351 +        }
   7.352 +        return -1;
   7.353 +    }
   7.354 +    if (SDL_strcasecmp(argv[index], "--channels") == 0) {
   7.355 +        ++index;
   7.356 +        if (!argv[index]) {
   7.357 +            return -1;
   7.358 +        }
   7.359 +        state->audiospec.channels = (Uint8) SDL_atoi(argv[index]);
   7.360 +        return 2;
   7.361 +    }
   7.362 +    if (SDL_strcasecmp(argv[index], "--samples") == 0) {
   7.363 +        ++index;
   7.364 +        if (!argv[index]) {
   7.365 +            return -1;
   7.366 +        }
   7.367 +        state->audiospec.samples = (Uint16) SDL_atoi(argv[index]);
   7.368 +        return 2;
   7.369 +    }
   7.370 +    if ((SDL_strcasecmp(argv[index], "-h") == 0)
   7.371 +        || (SDL_strcasecmp(argv[index], "--help") == 0)) {
   7.372 +        /* Print the usage message */
   7.373 +        return -1;
   7.374 +    }
   7.375 +    if (SDL_strcmp(argv[index], "-NSDocumentRevisionsDebugMode") == 0) {
   7.376 +	/* Debug flag sent by Xcode */
   7.377 +        return 2;
   7.378 +    }
   7.379 +    return 0;
   7.380 +}
   7.381 +
   7.382 +const char *
   7.383 +SDLTest_CommonUsage(SDLTest_CommonState * state)
   7.384 +{
   7.385 +    switch (state->flags & (SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
   7.386 +    case SDL_INIT_VIDEO:
   7.387 +        return VIDEO_USAGE;
   7.388 +    case SDL_INIT_AUDIO:
   7.389 +        return AUDIO_USAGE;
   7.390 +    case (SDL_INIT_VIDEO | SDL_INIT_AUDIO):
   7.391 +        return VIDEO_USAGE " " AUDIO_USAGE;
   7.392 +    default:
   7.393 +        return "";
   7.394 +    }
   7.395 +}
   7.396 +
   7.397 +static void
   7.398 +SDLTest_PrintRendererFlag(Uint32 flag)
   7.399 +{
   7.400 +    switch (flag) {
   7.401 +    case SDL_RENDERER_PRESENTVSYNC:
   7.402 +        fprintf(stderr, "PresentVSync");
   7.403 +        break;
   7.404 +    case SDL_RENDERER_ACCELERATED:
   7.405 +        fprintf(stderr, "Accelerated");
   7.406 +        break;
   7.407 +    default:
   7.408 +        fprintf(stderr, "0x%8.8x", flag);
   7.409 +        break;
   7.410 +    }
   7.411 +}
   7.412 +
   7.413 +static void
   7.414 +SDLTest_PrintPixelFormat(Uint32 format)
   7.415 +{
   7.416 +    switch (format) {
   7.417 +    case SDL_PIXELFORMAT_UNKNOWN:
   7.418 +        fprintf(stderr, "Unknwon");
   7.419 +        break;
   7.420 +    case SDL_PIXELFORMAT_INDEX1LSB:
   7.421 +        fprintf(stderr, "Index1LSB");
   7.422 +        break;
   7.423 +    case SDL_PIXELFORMAT_INDEX1MSB:
   7.424 +        fprintf(stderr, "Index1MSB");
   7.425 +        break;
   7.426 +    case SDL_PIXELFORMAT_INDEX4LSB:
   7.427 +        fprintf(stderr, "Index4LSB");
   7.428 +        break;
   7.429 +    case SDL_PIXELFORMAT_INDEX4MSB:
   7.430 +        fprintf(stderr, "Index4MSB");
   7.431 +        break;
   7.432 +    case SDL_PIXELFORMAT_INDEX8:
   7.433 +        fprintf(stderr, "Index8");
   7.434 +        break;
   7.435 +    case SDL_PIXELFORMAT_RGB332:
   7.436 +        fprintf(stderr, "RGB332");
   7.437 +        break;
   7.438 +    case SDL_PIXELFORMAT_RGB444:
   7.439 +        fprintf(stderr, "RGB444");
   7.440 +        break;
   7.441 +    case SDL_PIXELFORMAT_RGB555:
   7.442 +        fprintf(stderr, "RGB555");
   7.443 +        break;
   7.444 +    case SDL_PIXELFORMAT_BGR555:
   7.445 +        fprintf(stderr, "BGR555");
   7.446 +        break;
   7.447 +    case SDL_PIXELFORMAT_ARGB4444:
   7.448 +        fprintf(stderr, "ARGB4444");
   7.449 +        break;
   7.450 +    case SDL_PIXELFORMAT_ABGR4444:
   7.451 +        fprintf(stderr, "ABGR4444");
   7.452 +        break;
   7.453 +    case SDL_PIXELFORMAT_ARGB1555:
   7.454 +        fprintf(stderr, "ARGB1555");
   7.455 +        break;
   7.456 +    case SDL_PIXELFORMAT_ABGR1555:
   7.457 +        fprintf(stderr, "ABGR1555");
   7.458 +        break;
   7.459 +    case SDL_PIXELFORMAT_RGB565:
   7.460 +        fprintf(stderr, "RGB565");
   7.461 +        break;
   7.462 +    case SDL_PIXELFORMAT_BGR565:
   7.463 +        fprintf(stderr, "BGR565");
   7.464 +        break;
   7.465 +    case SDL_PIXELFORMAT_RGB24:
   7.466 +        fprintf(stderr, "RGB24");
   7.467 +        break;
   7.468 +    case SDL_PIXELFORMAT_BGR24:
   7.469 +        fprintf(stderr, "BGR24");
   7.470 +        break;
   7.471 +    case SDL_PIXELFORMAT_RGB888:
   7.472 +        fprintf(stderr, "RGB888");
   7.473 +        break;
   7.474 +    case SDL_PIXELFORMAT_BGR888:
   7.475 +        fprintf(stderr, "BGR888");
   7.476 +        break;
   7.477 +    case SDL_PIXELFORMAT_ARGB8888:
   7.478 +        fprintf(stderr, "ARGB8888");
   7.479 +        break;
   7.480 +    case SDL_PIXELFORMAT_RGBA8888:
   7.481 +        fprintf(stderr, "RGBA8888");
   7.482 +        break;
   7.483 +    case SDL_PIXELFORMAT_ABGR8888:
   7.484 +        fprintf(stderr, "ABGR8888");
   7.485 +        break;
   7.486 +    case SDL_PIXELFORMAT_BGRA8888:
   7.487 +        fprintf(stderr, "BGRA8888");
   7.488 +        break;
   7.489 +    case SDL_PIXELFORMAT_ARGB2101010:
   7.490 +        fprintf(stderr, "ARGB2101010");
   7.491 +        break;
   7.492 +    case SDL_PIXELFORMAT_YV12:
   7.493 +        fprintf(stderr, "YV12");
   7.494 +        break;
   7.495 +    case SDL_PIXELFORMAT_IYUV:
   7.496 +        fprintf(stderr, "IYUV");
   7.497 +        break;
   7.498 +    case SDL_PIXELFORMAT_YUY2:
   7.499 +        fprintf(stderr, "YUY2");
   7.500 +        break;
   7.501 +    case SDL_PIXELFORMAT_UYVY:
   7.502 +        fprintf(stderr, "UYVY");
   7.503 +        break;
   7.504 +    case SDL_PIXELFORMAT_YVYU:
   7.505 +        fprintf(stderr, "YVYU");
   7.506 +        break;
   7.507 +    default:
   7.508 +        fprintf(stderr, "0x%8.8x", format);
   7.509 +        break;
   7.510 +    }
   7.511 +}
   7.512 +
   7.513 +static void
   7.514 +SDLTest_PrintRenderer(SDL_RendererInfo * info)
   7.515 +{
   7.516 +    int i, count;
   7.517 +
   7.518 +    fprintf(stderr, "  Renderer %s:\n", info->name);
   7.519 +
   7.520 +    fprintf(stderr, "    Flags: 0x%8.8X", info->flags);
   7.521 +    fprintf(stderr, " (");
   7.522 +    count = 0;
   7.523 +    for (i = 0; i < sizeof(info->flags) * 8; ++i) {
   7.524 +        Uint32 flag = (1 << i);
   7.525 +        if (info->flags & flag) {
   7.526 +            if (count > 0) {
   7.527 +                fprintf(stderr, " | ");
   7.528 +            }
   7.529 +            SDLTest_PrintRendererFlag(flag);
   7.530 +            ++count;
   7.531 +        }
   7.532 +    }
   7.533 +    fprintf(stderr, ")\n");
   7.534 +
   7.535 +    fprintf(stderr, "    Texture formats (%d): ", info->num_texture_formats);
   7.536 +    for (i = 0; i < (int) info->num_texture_formats; ++i) {
   7.537 +        if (i > 0) {
   7.538 +            fprintf(stderr, ", ");
   7.539 +        }
   7.540 +        SDLTest_PrintPixelFormat(info->texture_formats[i]);
   7.541 +    }
   7.542 +    fprintf(stderr, "\n");
   7.543 +
   7.544 +    if (info->max_texture_width || info->max_texture_height) {
   7.545 +        fprintf(stderr, "    Max Texture Size: %dx%d\n",
   7.546 +                info->max_texture_width, info->max_texture_height);
   7.547 +    }
   7.548 +}
   7.549 +
   7.550 +static SDL_Surface *
   7.551 +SDLTest_LoadIcon(const char *file)
   7.552 +{
   7.553 +    SDL_Surface *icon;
   7.554 +
   7.555 +    /* Load the icon surface */
   7.556 +    icon = SDL_LoadBMP(file);
   7.557 +    if (icon == NULL) {
   7.558 +        fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
   7.559 +        return (NULL);
   7.560 +    }
   7.561 +
   7.562 +    if (icon->format->palette) {
   7.563 +        /* Set the colorkey */
   7.564 +        SDL_SetColorKey(icon, 1, *((Uint8 *) icon->pixels));
   7.565 +    }
   7.566 +
   7.567 +    return (icon);
   7.568 +}
   7.569 +
   7.570 +SDL_bool
   7.571 +SDLTest_CommonInit(SDLTest_CommonState * state)
   7.572 +{
   7.573 +    int i, j, m, n, w, h;
   7.574 +    SDL_DisplayMode fullscreen_mode;
   7.575 +
   7.576 +    if (state->flags & SDL_INIT_VIDEO) {
   7.577 +        if (state->verbose & VERBOSE_VIDEO) {
   7.578 +            n = SDL_GetNumVideoDrivers();
   7.579 +            if (n == 0) {
   7.580 +                fprintf(stderr, "No built-in video drivers\n");
   7.581 +            } else {
   7.582 +                fprintf(stderr, "Built-in video drivers:");
   7.583 +                for (i = 0; i < n; ++i) {
   7.584 +                    if (i > 0) {
   7.585 +                        fprintf(stderr, ",");
   7.586 +                    }
   7.587 +                    fprintf(stderr, " %s", SDL_GetVideoDriver(i));
   7.588 +                }
   7.589 +                fprintf(stderr, "\n");
   7.590 +            }
   7.591 +        }
   7.592 +        if (SDL_VideoInit(state->videodriver) < 0) {
   7.593 +            fprintf(stderr, "Couldn't initialize video driver: %s\n",
   7.594 +                    SDL_GetError());
   7.595 +            return SDL_FALSE;
   7.596 +        }
   7.597 +        if (state->verbose & VERBOSE_VIDEO) {
   7.598 +            fprintf(stderr, "Video driver: %s\n",
   7.599 +                    SDL_GetCurrentVideoDriver());
   7.600 +        }
   7.601 +
   7.602 +        /* Upload GL settings */
   7.603 +        SDL_GL_SetAttribute(SDL_GL_RED_SIZE, state->gl_red_size);
   7.604 +        SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, state->gl_green_size);
   7.605 +        SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, state->gl_blue_size);
   7.606 +        SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, state->gl_alpha_size);
   7.607 +        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, state->gl_double_buffer);
   7.608 +        SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, state->gl_buffer_size);
   7.609 +        SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, state->gl_depth_size);
   7.610 +        SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, state->gl_stencil_size);
   7.611 +        SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, state->gl_accum_red_size);
   7.612 +        SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, state->gl_accum_green_size);
   7.613 +        SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, state->gl_accum_blue_size);
   7.614 +        SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, state->gl_accum_alpha_size);
   7.615 +        SDL_GL_SetAttribute(SDL_GL_STEREO, state->gl_stereo);
   7.616 +        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, state->gl_multisamplebuffers);
   7.617 +        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, state->gl_multisamplesamples);
   7.618 +        if (state->gl_accelerated >= 0) {
   7.619 +            SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL,
   7.620 +                                state->gl_accelerated);
   7.621 +        }
   7.622 +        SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, state->gl_retained_backing);
   7.623 +        if (state->gl_major_version) {
   7.624 +            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, state->gl_major_version);
   7.625 +            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, state->gl_minor_version);
   7.626 +        }
   7.627 +
   7.628 +        if (state->verbose & VERBOSE_MODES) {
   7.629 +            SDL_Rect bounds;
   7.630 +            SDL_DisplayMode mode;
   7.631 +            int bpp;
   7.632 +            Uint32 Rmask, Gmask, Bmask, Amask;
   7.633 +
   7.634 +            n = SDL_GetNumVideoDisplays();
   7.635 +            fprintf(stderr, "Number of displays: %d\n", n);
   7.636 +            for (i = 0; i < n; ++i) {
   7.637 +                fprintf(stderr, "Display %d:\n", i);
   7.638 +
   7.639 +                SDL_zero(bounds);
   7.640 +                SDL_GetDisplayBounds(i, &bounds);
   7.641 +                fprintf(stderr, "Bounds: %dx%d at %d,%d\n", bounds.w, bounds.h, bounds.x, bounds.y);
   7.642 +
   7.643 +                SDL_GetDesktopDisplayMode(i, &mode);
   7.644 +                SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask,
   7.645 +                                           &Bmask, &Amask);
   7.646 +                fprintf(stderr,
   7.647 +                        "  Current mode: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
   7.648 +                        mode.w, mode.h, mode.refresh_rate, bpp,
   7.649 +                        SDL_GetPixelFormatName(mode.format));
   7.650 +                if (Rmask || Gmask || Bmask) {
   7.651 +                    fprintf(stderr, "      Red Mask   = 0x%.8x\n", Rmask);
   7.652 +                    fprintf(stderr, "      Green Mask = 0x%.8x\n", Gmask);
   7.653 +                    fprintf(stderr, "      Blue Mask  = 0x%.8x\n", Bmask);
   7.654 +                    if (Amask)
   7.655 +                        fprintf(stderr, "      Alpha Mask = 0x%.8x\n", Amask);
   7.656 +                }
   7.657 +
   7.658 +                /* Print available fullscreen video modes */
   7.659 +                m = SDL_GetNumDisplayModes(i);
   7.660 +                if (m == 0) {
   7.661 +                    fprintf(stderr, "No available fullscreen video modes\n");
   7.662 +                } else {
   7.663 +                    fprintf(stderr, "  Fullscreen video modes:\n");
   7.664 +                    for (j = 0; j < m; ++j) {
   7.665 +                        SDL_GetDisplayMode(i, j, &mode);
   7.666 +                        SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask,
   7.667 +                                                   &Gmask, &Bmask, &Amask);
   7.668 +                        fprintf(stderr,
   7.669 +                                "    Mode %d: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
   7.670 +                                j, mode.w, mode.h, mode.refresh_rate, bpp,
   7.671 +                                SDL_GetPixelFormatName(mode.format));
   7.672 +                        if (Rmask || Gmask || Bmask) {
   7.673 +                            fprintf(stderr, "        Red Mask   = 0x%.8x\n",
   7.674 +                                    Rmask);
   7.675 +                            fprintf(stderr, "        Green Mask = 0x%.8x\n",
   7.676 +                                    Gmask);
   7.677 +                            fprintf(stderr, "        Blue Mask  = 0x%.8x\n",
   7.678 +                                    Bmask);
   7.679 +                            if (Amask)
   7.680 +                                fprintf(stderr,
   7.681 +                                        "        Alpha Mask = 0x%.8x\n",
   7.682 +                                        Amask);
   7.683 +                        }
   7.684 +                    }
   7.685 +                }
   7.686 +            }
   7.687 +        }
   7.688 +
   7.689 +        if (state->verbose & VERBOSE_RENDER) {
   7.690 +            SDL_RendererInfo info;
   7.691 +
   7.692 +            n = SDL_GetNumRenderDrivers();
   7.693 +            if (n == 0) {
   7.694 +                fprintf(stderr, "No built-in render drivers\n");
   7.695 +            } else {
   7.696 +                fprintf(stderr, "Built-in render drivers:\n");
   7.697 +                for (i = 0; i < n; ++i) {
   7.698 +                    SDL_GetRenderDriverInfo(i, &info);
   7.699 +                    SDLTest_PrintRenderer(&info);
   7.700 +                }
   7.701 +            }
   7.702 +        }
   7.703 +
   7.704 +        SDL_zero(fullscreen_mode);
   7.705 +        switch (state->depth) {
   7.706 +        case 8:
   7.707 +            fullscreen_mode.format = SDL_PIXELFORMAT_INDEX8;
   7.708 +            break;
   7.709 +        case 15:
   7.710 +            fullscreen_mode.format = SDL_PIXELFORMAT_RGB555;
   7.711 +            break;
   7.712 +        case 16:
   7.713 +            fullscreen_mode.format = SDL_PIXELFORMAT_RGB565;
   7.714 +            break;
   7.715 +        case 24:
   7.716 +            fullscreen_mode.format = SDL_PIXELFORMAT_RGB24;
   7.717 +            break;
   7.718 +        default:
   7.719 +            fullscreen_mode.format = SDL_PIXELFORMAT_RGB888;
   7.720 +            break;
   7.721 +        }
   7.722 +        fullscreen_mode.refresh_rate = state->refresh_rate;
   7.723 +
   7.724 +        state->windows =
   7.725 +            (SDL_Window **) SDL_malloc(state->num_windows *
   7.726 +                                        sizeof(*state->windows));
   7.727 +        state->renderers =
   7.728 +            (SDL_Renderer **) SDL_malloc(state->num_windows *
   7.729 +                                        sizeof(*state->renderers));
   7.730 +        if (!state->windows || !state->renderers) {
   7.731 +            fprintf(stderr, "Out of memory!\n");
   7.732 +            return SDL_FALSE;
   7.733 +        }
   7.734 +        for (i = 0; i < state->num_windows; ++i) {
   7.735 +            char title[1024];
   7.736 +
   7.737 +            if (state->num_windows > 1) {
   7.738 +                SDL_snprintf(title, SDL_arraysize(title), "%s %d",
   7.739 +                             state->window_title, i + 1);
   7.740 +            } else {
   7.741 +                SDL_strlcpy(title, state->window_title, SDL_arraysize(title));
   7.742 +            }
   7.743 +            state->windows[i] =
   7.744 +                SDL_CreateWindow(title, state->window_x, state->window_y,
   7.745 +                                 state->window_w, state->window_h,
   7.746 +                                 state->window_flags);
   7.747 +            if (!state->windows[i]) {
   7.748 +                fprintf(stderr, "Couldn't create window: %s\n",
   7.749 +                        SDL_GetError());
   7.750 +                return SDL_FALSE;
   7.751 +            }
   7.752 +            SDL_GetWindowSize(state->windows[i], &w, &h);
   7.753 +            if (!(state->window_flags & SDL_WINDOW_RESIZABLE) &&
   7.754 +                (w != state->window_w || h != state->window_h)) {
   7.755 +                printf("Window requested size %dx%d, got %dx%d\n", state->window_w, state->window_h, w, h);
   7.756 +                state->window_w = w;
   7.757 +                state->window_h = h;
   7.758 +            }
   7.759 +            if (SDL_SetWindowDisplayMode(state->windows[i], &fullscreen_mode) < 0) {
   7.760 +                fprintf(stderr, "Can't set up fullscreen display mode: %s\n",
   7.761 +                        SDL_GetError());
   7.762 +                return SDL_FALSE;
   7.763 +            }
   7.764 +
   7.765 +            if (state->window_icon) {
   7.766 +                SDL_Surface *icon = SDLTest_LoadIcon(state->window_icon);
   7.767 +                if (icon) {
   7.768 +                    SDL_SetWindowIcon(state->windows[i], icon);
   7.769 +                    SDL_FreeSurface(icon);
   7.770 +                }
   7.771 +            }
   7.772 +
   7.773 +            SDL_ShowWindow(state->windows[i]);
   7.774 +
   7.775 +            state->renderers[i] = NULL;
   7.776 +
   7.777 +            if (!state->skip_renderer
   7.778 +                && (state->renderdriver
   7.779 +                    || !(state->window_flags & SDL_WINDOW_OPENGL))) {
   7.780 +                m = -1;
   7.781 +                if (state->renderdriver) {
   7.782 +                    SDL_RendererInfo info;
   7.783 +                    n = SDL_GetNumRenderDrivers();
   7.784 +                    for (j = 0; j < n; ++j) {
   7.785 +                        SDL_GetRenderDriverInfo(j, &info);
   7.786 +                        if (SDL_strcasecmp(info.name, state->renderdriver) ==
   7.787 +                            0) {
   7.788 +                            m = j;
   7.789 +                            break;
   7.790 +                        }
   7.791 +                    }
   7.792 +                    if (m == n) {
   7.793 +                        fprintf(stderr,
   7.794 +                                "Couldn't find render driver named %s",
   7.795 +                                state->renderdriver);
   7.796 +                        return SDL_FALSE;
   7.797 +                    }
   7.798 +                }
   7.799 +                state->renderers[i] = SDL_CreateRenderer(state->windows[i],
   7.800 +                                            m, state->render_flags);
   7.801 +                if (!state->renderers[i]) {
   7.802 +                    fprintf(stderr, "Couldn't create renderer: %s\n",
   7.803 +                            SDL_GetError());
   7.804 +                    return SDL_FALSE;
   7.805 +                }
   7.806 +                if (state->verbose & VERBOSE_RENDER) {
   7.807 +                    SDL_RendererInfo info;
   7.808 +
   7.809 +                    fprintf(stderr, "Current renderer:\n");
   7.810 +                    SDL_GetRendererInfo(state->renderers[i], &info);
   7.811 +                    SDLTest_PrintRenderer(&info);
   7.812 +                }
   7.813 +            }
   7.814 +        }
   7.815 +    }
   7.816 +
   7.817 +    if (state->flags & SDL_INIT_AUDIO) {
   7.818 +        if (state->verbose & VERBOSE_AUDIO) {
   7.819 +            n = SDL_GetNumAudioDrivers();
   7.820 +            if (n == 0) {
   7.821 +                fprintf(stderr, "No built-in audio drivers\n");
   7.822 +            } else {
   7.823 +                fprintf(stderr, "Built-in audio drivers:");
   7.824 +                for (i = 0; i < n; ++i) {
   7.825 +                    if (i > 0) {
   7.826 +                        fprintf(stderr, ",");
   7.827 +                    }
   7.828 +                    fprintf(stderr, " %s", SDL_GetAudioDriver(i));
   7.829 +                }
   7.830 +                fprintf(stderr, "\n");
   7.831 +            }
   7.832 +        }
   7.833 +        if (SDL_AudioInit(state->audiodriver) < 0) {
   7.834 +            fprintf(stderr, "Couldn't initialize audio driver: %s\n",
   7.835 +                    SDL_GetError());
   7.836 +            return SDL_FALSE;
   7.837 +        }
   7.838 +        if (state->verbose & VERBOSE_VIDEO) {
   7.839 +            fprintf(stderr, "Audio driver: %s\n",
   7.840 +                    SDL_GetCurrentAudioDriver());
   7.841 +        }
   7.842 +
   7.843 +        if (SDL_OpenAudio(&state->audiospec, NULL) < 0) {
   7.844 +            fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
   7.845 +            return SDL_FALSE;
   7.846 +        }
   7.847 +    }
   7.848 +
   7.849 +    return SDL_TRUE;
   7.850 +}
   7.851 +
   7.852 +static void
   7.853 +SDLTest_PrintEvent(SDL_Event * event)
   7.854 +{
   7.855 +    if (event->type == SDL_MOUSEMOTION) {
   7.856 +        /* Mouse motion is really spammy */
   7.857 +        //return;
   7.858 +    }
   7.859 +
   7.860 +    fprintf(stderr, "SDL EVENT: ");
   7.861 +    switch (event->type) {
   7.862 +    case SDL_WINDOWEVENT:
   7.863 +        switch (event->window.event) {
   7.864 +        case SDL_WINDOWEVENT_SHOWN:
   7.865 +            fprintf(stderr, "Window %d shown", event->window.windowID);
   7.866 +            break;
   7.867 +        case SDL_WINDOWEVENT_HIDDEN:
   7.868 +            fprintf(stderr, "Window %d hidden", event->window.windowID);
   7.869 +            break;
   7.870 +        case SDL_WINDOWEVENT_EXPOSED:
   7.871 +            fprintf(stderr, "Window %d exposed", event->window.windowID);
   7.872 +            break;
   7.873 +        case SDL_WINDOWEVENT_MOVED:
   7.874 +            fprintf(stderr, "Window %d moved to %d,%d",
   7.875 +                    event->window.windowID, event->window.data1,
   7.876 +                    event->window.data2);
   7.877 +            break;
   7.878 +        case SDL_WINDOWEVENT_RESIZED:
   7.879 +            fprintf(stderr, "Window %d resized to %dx%d",
   7.880 +                    event->window.windowID, event->window.data1,
   7.881 +                    event->window.data2);
   7.882 +            break;
   7.883 +        case SDL_WINDOWEVENT_SIZE_CHANGED:
   7.884 +            fprintf(stderr, "Window %d changed size to %dx%d",
   7.885 +                    event->window.windowID, event->window.data1,
   7.886 +                    event->window.data2);
   7.887 +            break;
   7.888 +        case SDL_WINDOWEVENT_MINIMIZED:
   7.889 +            fprintf(stderr, "Window %d minimized", event->window.windowID);
   7.890 +            break;
   7.891 +        case SDL_WINDOWEVENT_MAXIMIZED:
   7.892 +            fprintf(stderr, "Window %d maximized", event->window.windowID);
   7.893 +            break;
   7.894 +        case SDL_WINDOWEVENT_RESTORED:
   7.895 +            fprintf(stderr, "Window %d restored", event->window.windowID);
   7.896 +            break;
   7.897 +        case SDL_WINDOWEVENT_ENTER:
   7.898 +            fprintf(stderr, "Mouse entered window %d",
   7.899 +                    event->window.windowID);
   7.900 +            break;
   7.901 +        case SDL_WINDOWEVENT_LEAVE:
   7.902 +            fprintf(stderr, "Mouse left window %d", event->window.windowID);
   7.903 +            break;
   7.904 +        case SDL_WINDOWEVENT_FOCUS_GAINED:
   7.905 +            fprintf(stderr, "Window %d gained keyboard focus",
   7.906 +                    event->window.windowID);
   7.907 +            break;
   7.908 +        case SDL_WINDOWEVENT_FOCUS_LOST:
   7.909 +            fprintf(stderr, "Window %d lost keyboard focus",
   7.910 +                    event->window.windowID);
   7.911 +            break;
   7.912 +        case SDL_WINDOWEVENT_CLOSE:
   7.913 +            fprintf(stderr, "Window %d closed", event->window.windowID);
   7.914 +            break;
   7.915 +        default:
   7.916 +            fprintf(stderr, "Window %d got unknown event %d",
   7.917 +                    event->window.windowID, event->window.event);
   7.918 +            break;
   7.919 +        }
   7.920 +        break;
   7.921 +    case SDL_KEYDOWN:
   7.922 +        fprintf(stderr,
   7.923 +                "Keyboard: key pressed  in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
   7.924 +                event->key.windowID,
   7.925 +                event->key.keysym.scancode,
   7.926 +                SDL_GetScancodeName(event->key.keysym.scancode),
   7.927 +                event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
   7.928 +        break;
   7.929 +    case SDL_KEYUP:
   7.930 +        fprintf(stderr,
   7.931 +                "Keyboard: key released in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
   7.932 +                event->key.windowID,
   7.933 +                event->key.keysym.scancode,
   7.934 +                SDL_GetScancodeName(event->key.keysym.scancode),
   7.935 +                event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
   7.936 +        break;
   7.937 +    case SDL_TEXTINPUT:
   7.938 +        fprintf(stderr, "Keyboard: text input \"%s\" in window %d",
   7.939 +                event->text.text, event->text.windowID);
   7.940 +        break;
   7.941 +    case SDL_MOUSEMOTION:
   7.942 +        fprintf(stderr, "Mouse: moved to %d,%d (%d,%d) in window %d",
   7.943 +                event->motion.x, event->motion.y,
   7.944 +                event->motion.xrel, event->motion.yrel,
   7.945 +                event->motion.windowID);
   7.946 +        break;
   7.947 +    case SDL_MOUSEBUTTONDOWN:
   7.948 +        fprintf(stderr, "Mouse: button %d pressed at %d,%d in window %d",
   7.949 +                event->button.button, event->button.x, event->button.y,
   7.950 +                event->button.windowID);
   7.951 +        break;
   7.952 +    case SDL_MOUSEBUTTONUP:
   7.953 +        fprintf(stderr, "Mouse: button %d released at %d,%d in window %d",
   7.954 +                event->button.button, event->button.x, event->button.y,
   7.955 +                event->button.windowID);
   7.956 +        break;
   7.957 +    case SDL_MOUSEWHEEL:
   7.958 +        fprintf(stderr,
   7.959 +                "Mouse: wheel scrolled %d in x and %d in y in window %d",
   7.960 +                event->wheel.x, event->wheel.y, event->wheel.windowID);
   7.961 +        break;
   7.962 +    case SDL_JOYBALLMOTION:
   7.963 +        fprintf(stderr, "Joystick %d: ball %d moved by %d,%d",
   7.964 +                event->jball.which, event->jball.ball, event->jball.xrel,
   7.965 +                event->jball.yrel);
   7.966 +        break;
   7.967 +    case SDL_JOYHATMOTION:
   7.968 +        fprintf(stderr, "Joystick %d: hat %d moved to ", event->jhat.which,
   7.969 +                event->jhat.hat);
   7.970 +        switch (event->jhat.value) {
   7.971 +        case SDL_HAT_CENTERED:
   7.972 +            fprintf(stderr, "CENTER");
   7.973 +            break;
   7.974 +        case SDL_HAT_UP:
   7.975 +            fprintf(stderr, "UP");
   7.976 +            break;
   7.977 +        case SDL_HAT_RIGHTUP:
   7.978 +            fprintf(stderr, "RIGHTUP");
   7.979 +            break;
   7.980 +        case SDL_HAT_RIGHT:
   7.981 +            fprintf(stderr, "RIGHT");
   7.982 +            break;
   7.983 +        case SDL_HAT_RIGHTDOWN:
   7.984 +            fprintf(stderr, "RIGHTDOWN");
   7.985 +            break;
   7.986 +        case SDL_HAT_DOWN:
   7.987 +            fprintf(stderr, "DOWN");
   7.988 +            break;
   7.989 +        case SDL_HAT_LEFTDOWN:
   7.990 +            fprintf(stderr, "LEFTDOWN");
   7.991 +            break;
   7.992 +        case SDL_HAT_LEFT:
   7.993 +            fprintf(stderr, "LEFT");
   7.994 +            break;
   7.995 +        case SDL_HAT_LEFTUP:
   7.996 +            fprintf(stderr, "LEFTUP");
   7.997 +            break;
   7.998 +        default:
   7.999 +            fprintf(stderr, "UNKNOWN");
  7.1000 +            break;
  7.1001 +        }
  7.1002 +        break;
  7.1003 +    case SDL_JOYBUTTONDOWN:
  7.1004 +        fprintf(stderr, "Joystick %d: button %d pressed",
  7.1005 +                event->jbutton.which, event->jbutton.button);
  7.1006 +        break;
  7.1007 +    case SDL_JOYBUTTONUP:
  7.1008 +        fprintf(stderr, "Joystick %d: button %d released",
  7.1009 +                event->jbutton.which, event->jbutton.button);
  7.1010 +        break;
  7.1011 +    case SDL_CLIPBOARDUPDATE:
  7.1012 +        fprintf(stderr, "Clipboard updated");
  7.1013 +        break;
  7.1014 +    case SDL_QUIT:
  7.1015 +        fprintf(stderr, "Quit requested");
  7.1016 +        break;
  7.1017 +    case SDL_USEREVENT:
  7.1018 +        fprintf(stderr, "User event %d", event->user.code);
  7.1019 +        break;
  7.1020 +    default:
  7.1021 +        fprintf(stderr, "Unknown event %d", event->type);
  7.1022 +        break;
  7.1023 +    }
  7.1024 +    fprintf(stderr, "\n");
  7.1025 +}
  7.1026 +
  7.1027 +static void
  7.1028 +SDLTest_ScreenShot(SDL_Renderer *renderer)
  7.1029 +{
  7.1030 +    SDL_Rect viewport;
  7.1031 +    SDL_Surface *surface;
  7.1032 +
  7.1033 +    if (!renderer) {
  7.1034 +        return;
  7.1035 +    }
  7.1036 +
  7.1037 +    SDL_RenderGetViewport(renderer, &viewport);
  7.1038 +    surface = SDL_CreateRGBSurface(0, viewport.w, viewport.h, 24,
  7.1039 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN
  7.1040 +                    0x00FF0000, 0x0000FF00, 0x000000FF,
  7.1041 +#else
  7.1042 +                    0x000000FF, 0x0000FF00, 0x00FF0000,
  7.1043 +#endif
  7.1044 +                    0x00000000);
  7.1045 +    if (!surface) {
  7.1046 +        fprintf(stderr, "Couldn't create surface: %s\n", SDL_GetError());
  7.1047 +        return;
  7.1048 +    }
  7.1049 +
  7.1050 +    if (SDL_RenderReadPixels(renderer, NULL, surface->format->format,
  7.1051 +                             surface->pixels, surface->pitch) < 0) {
  7.1052 +        fprintf(stderr, "Couldn't read screen: %s\n", SDL_GetError());
  7.1053 +        return;
  7.1054 +    }
  7.1055 +
  7.1056 +    if (SDL_SaveBMP(surface, "screenshot.bmp") < 0) {
  7.1057 +        fprintf(stderr, "Couldn't save screenshot.bmp: %s\n", SDL_GetError());
  7.1058 +        return;
  7.1059 +    }
  7.1060 +}
  7.1061 +
  7.1062 +void
  7.1063 +SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
  7.1064 +{
  7.1065 +    int i;
  7.1066 +
  7.1067 +    if (state->verbose & VERBOSE_EVENT) {
  7.1068 +        SDLTest_PrintEvent(event);
  7.1069 +    }
  7.1070 +
  7.1071 +    switch (event->type) {
  7.1072 +    case SDL_WINDOWEVENT:
  7.1073 +        switch (event->window.event) {
  7.1074 +        case SDL_WINDOWEVENT_SIZE_CHANGED:
  7.1075 +            {
  7.1076 +                SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
  7.1077 +                if (window) {
  7.1078 +                    for (i = 0; i < state->num_windows; ++i) {
  7.1079 +                        if (window == state->windows[i] &&
  7.1080 +                            (state->window_flags & SDL_WINDOW_RESIZABLE)) {
  7.1081 +                            SDL_Rect viewport;
  7.1082 +
  7.1083 +                            viewport.x = 0;
  7.1084 +                            viewport.y = 0;
  7.1085 +                            SDL_GetWindowSize(window, &viewport.w, &viewport.h);
  7.1086 +                            SDL_RenderSetViewport(state->renderers[i], &viewport);
  7.1087 +                        }
  7.1088 +                    }
  7.1089 +                }
  7.1090 +            }
  7.1091 +            break;
  7.1092 +        case SDL_WINDOWEVENT_CLOSE:
  7.1093 +			{
  7.1094 +                SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
  7.1095 +                if (window) {
  7.1096 +					SDL_DestroyWindow(window);
  7.1097 +				}
  7.1098 +			}
  7.1099 +            break;
  7.1100 +        }
  7.1101 +        break;
  7.1102 +    case SDL_KEYDOWN:
  7.1103 +        switch (event->key.keysym.sym) {
  7.1104 +            /* Add hotkeys here */
  7.1105 +        case SDLK_PRINTSCREEN: {
  7.1106 +                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
  7.1107 +                if (window) {
  7.1108 +                    for (i = 0; i < state->num_windows; ++i) {
  7.1109 +                        if (window == state->windows[i]) {
  7.1110 +                            SDLTest_ScreenShot(state->renderers[i]);
  7.1111 +                        }
  7.1112 +                    }
  7.1113 +                }
  7.1114 +            }
  7.1115 +            break;
  7.1116 +        case SDLK_EQUALS:
  7.1117 +            if (event->key.keysym.mod & KMOD_CTRL) {
  7.1118 +                /* Ctrt-+ double the size of the window */
  7.1119 +                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
  7.1120 +                if (window) {
  7.1121 +                    int w, h;
  7.1122 +                    SDL_GetWindowSize(window, &w, &h);
  7.1123 +                    SDL_SetWindowSize(window, w*2, h*2);
  7.1124 +                }
  7.1125 +            }
  7.1126 +            break;
  7.1127 +        case SDLK_MINUS:
  7.1128 +            if (event->key.keysym.mod & KMOD_CTRL) {
  7.1129 +                /* Ctrt-- double the size of the window */
  7.1130 +                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
  7.1131 +                if (window) {
  7.1132 +                    int w, h;
  7.1133 +                    SDL_GetWindowSize(window, &w, &h);
  7.1134 +                    SDL_SetWindowSize(window, w/2, h/2);
  7.1135 +                }
  7.1136 +            }
  7.1137 +            break;
  7.1138 +        case SDLK_c:
  7.1139 +            if (event->key.keysym.mod & KMOD_CTRL) {
  7.1140 +                /* Ctrl-C copy awesome text! */
  7.1141 +                SDL_SetClipboardText("SDL rocks!\nYou know it!");
  7.1142 +                printf("Copied text to clipboard\n");
  7.1143 +            }
  7.1144 +            break;
  7.1145 +        case SDLK_v:
  7.1146 +            if (event->key.keysym.mod & KMOD_CTRL) {
  7.1147 +                /* Ctrl-V paste awesome text! */
  7.1148 +                char *text = SDL_GetClipboardText();
  7.1149 +                if (*text) {
  7.1150 +                    printf("Clipboard: %s\n", text);
  7.1151 +                } else {
  7.1152 +                    printf("Clipboard is empty\n");
  7.1153 +                }
  7.1154 +                SDL_free(text);
  7.1155 +            }
  7.1156 +            break;
  7.1157 +        case SDLK_g:
  7.1158 +            if (event->key.keysym.mod & KMOD_CTRL) {
  7.1159 +                /* Ctrl-G toggle grab */
  7.1160 +                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
  7.1161 +                if (window) {
  7.1162 +                    SDL_SetWindowGrab(window, !SDL_GetWindowGrab(window));
  7.1163 +                }
  7.1164 +            }
  7.1165 +            break;
  7.1166 +        case SDLK_m:
  7.1167 +            if (event->key.keysym.mod & KMOD_CTRL) {
  7.1168 +                /* Ctrl-M maximize */
  7.1169 +                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
  7.1170 +                if (window) {
  7.1171 +                    Uint32 flags = SDL_GetWindowFlags(window);
  7.1172 +                    if (flags & SDL_WINDOW_MAXIMIZED) {
  7.1173 +                        SDL_RestoreWindow(window);
  7.1174 +                    } else {
  7.1175 +                        SDL_MaximizeWindow(window);
  7.1176 +                    }
  7.1177 +                }
  7.1178 +            }
  7.1179 +            break;
  7.1180 +        case SDLK_r:
  7.1181 +            if (event->key.keysym.mod & KMOD_CTRL) {
  7.1182 +                /* Ctrl-R toggle mouse relative mode */
  7.1183 +                SDL_SetRelativeMouseMode(!SDL_GetRelativeMouseMode());
  7.1184 +            }
  7.1185 +            break;
  7.1186 +        case SDLK_z:
  7.1187 +            if (event->key.keysym.mod & KMOD_CTRL) {
  7.1188 +                /* Ctrl-Z minimize */
  7.1189 +                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
  7.1190 +                if (window) {
  7.1191 +                    SDL_MinimizeWindow(window);
  7.1192 +                }
  7.1193 +            }
  7.1194 +            break;
  7.1195 +        case SDLK_RETURN:
  7.1196 +            if (event->key.keysym.mod & KMOD_CTRL) {
  7.1197 +                /* Ctrl-Enter toggle fullscreen */
  7.1198 +                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
  7.1199 +                if (window) {
  7.1200 +                    Uint32 flags = SDL_GetWindowFlags(window);
  7.1201 +                    if (flags & SDL_WINDOW_FULLSCREEN) {
  7.1202 +                        SDL_SetWindowFullscreen(window, SDL_FALSE);
  7.1203 +                    } else {
  7.1204 +                        SDL_SetWindowFullscreen(window, SDL_TRUE);
  7.1205 +                    }
  7.1206 +                }
  7.1207 +            }
  7.1208 +            break;
  7.1209 +        case SDLK_b:
  7.1210 +            if (event->key.keysym.mod & KMOD_CTRL) {
  7.1211 +                /* Ctrl-B toggle window border */
  7.1212 +                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
  7.1213 +                if (window) {
  7.1214 +                    const Uint32 flags = SDL_GetWindowFlags(window);
  7.1215 +                    const SDL_bool b = ((flags & SDL_WINDOW_BORDERLESS) != 0);
  7.1216 +                    SDL_SetWindowBordered(window, b);
  7.1217 +                }
  7.1218 +            }
  7.1219 +            break;
  7.1220 +        case SDLK_1:
  7.1221 +            if (event->key.keysym.mod & KMOD_CTRL) {
  7.1222 +                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
  7.1223 +                SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Test Message", "You're awesome!", window);
  7.1224 +            }
  7.1225 +            break;
  7.1226 +        case SDLK_ESCAPE:
  7.1227 +            *done = 1;
  7.1228 +            break;
  7.1229 +        default:
  7.1230 +            break;
  7.1231 +        }
  7.1232 +        break;
  7.1233 +    case SDL_QUIT:
  7.1234 +        *done = 1;
  7.1235 +        break;
  7.1236 +    }
  7.1237 +}
  7.1238 +
  7.1239 +void
  7.1240 +SDLTest_CommonQuit(SDLTest_CommonState * state)
  7.1241 +{
  7.1242 +    int i;
  7.1243 +
  7.1244 +    if (state->windows) {
  7.1245 +        SDL_free(state->windows);
  7.1246 +    }
  7.1247 +    if (state->renderers) {
  7.1248 +        for (i = 0; i < state->num_windows; ++i) {
  7.1249 +            if (state->renderers[i]) {
  7.1250 +                SDL_DestroyRenderer(state->renderers[i]);
  7.1251 +            }
  7.1252 +        }
  7.1253 +        SDL_free(state->renderers);
  7.1254 +    }
  7.1255 +    if (state->flags & SDL_INIT_VIDEO) {
  7.1256 +        SDL_VideoQuit();
  7.1257 +    }
  7.1258 +    if (state->flags & SDL_INIT_AUDIO) {
  7.1259 +        SDL_AudioQuit();
  7.1260 +    }
  7.1261 +    SDL_free(state);
  7.1262 +}
  7.1263 +
  7.1264 +/* vi: set ts=4 sw=4 expandtab: */
     8.1 --- a/src/test/SDL_test_harness.c	Sat Dec 08 15:33:14 2012 -0500
     8.2 +++ b/src/test/SDL_test_harness.c	Sun Dec 09 17:56:19 2012 -0800
     8.3 @@ -218,6 +218,7 @@
     8.4  SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, SDLTest_TestCaseReference *testCase, Uint64 execKey)
     8.5  {
     8.6  	SDL_TimerID timer = 0;
     8.7 +	int testResult = 0;
     8.8  
     8.9  	if (testSuite==NULL || testCase==NULL || testSuite->name==NULL || testCase->name==NULL)
    8.10  	{
    8.11 @@ -243,7 +244,7 @@
    8.12  	// Maybe run suite initalizer function
    8.13  	if (testSuite->testSetUp) {
    8.14  		testSuite->testSetUp(0x0);
    8.15 -		if (SDLTest_AssertsFailed > 0) {
    8.16 +		if (SDLTest_AssertSummaryToTestResult() == TEST_RESULT_FAILED) {
    8.17  			SDLTest_LogError((char *)SDLTest_TestCheckFmt, testSuite->name, "Failed");
    8.18  			return TEST_RESULT_SETUP_FAILURE;
    8.19  		}
    8.20 @@ -251,8 +252,9 @@
    8.21  
    8.22  	// Run test case function
    8.23  	testCase->testCase(0x0);
    8.24 +	testResult = SDLTest_AssertSummaryToTestResult();
    8.25  
    8.26 -	// Maybe run suite cleanup function
    8.27 +	// Maybe run suite cleanup function (ignore failed asserts)
    8.28  	if (testSuite->testTearDown) {
    8.29  		testSuite->testTearDown(0x0);
    8.30  	}
    8.31 @@ -266,19 +268,17 @@
    8.32  	SDLTest_Log("Fuzzer invocations: %d", SDLTest_GetFuzzerInvocationCount());
    8.33  	SDLTest_LogAssertSummary();
    8.34  
    8.35 -	// Analyze assert count to determine test case result
    8.36 -	if (SDLTest_AssertsFailed > 0) {
    8.37 -		SDLTest_LogError((char *)SDLTest_TestCheckFmt, testCase->name, "Failed");
    8.38 -		return TEST_RESULT_FAILED;
    8.39 -	} else {
    8.40 -		if (SDLTest_AssertsPassed > 0) {
    8.41 +	// Analyze assert count to determine final test case result
    8.42 +	switch (testResult) {
    8.43 +		case TEST_RESULT_PASSED:
    8.44 +			SDLTest_LogError((char *)SDLTest_TestCheckFmt, testCase->name, "Failed");
    8.45 +		case TEST_RESULT_FAILED:
    8.46  			SDLTest_Log((char *)SDLTest_TestCheckFmt, testCase->name, "Passed");
    8.47 -			return TEST_RESULT_PASSED;
    8.48 -		} else {
    8.49 +		case TEST_RESULT_NO_ASSERT:
    8.50  			SDLTest_LogError((char *)SDLTest_TestCheckFmt, testCase->name, "No Asserts");
    8.51 -			return TEST_RESULT_NO_ASSERT;
    8.52 -		}
    8.53  	}
    8.54 +
    8.55 +	return testResult;
    8.56  }
    8.57  
    8.58  /* Prints summary of all suites/tests contained in the given reference */
    8.59 @@ -329,7 +329,7 @@
    8.60  	int iterationCounter;
    8.61  	SDLTest_TestSuiteReference *testSuite;
    8.62  	SDLTest_TestCaseReference *testCase;
    8.63 -	char *runSeed;
    8.64 +	char *runSeed = NULL;
    8.65  	Uint64 execKey;
    8.66  	Uint32 runStartTicks;
    8.67  	time_t runStartTimestamp;