test/testautomation_hints.c
changeset 8645 d69fdbefeecf
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/testautomation_hints.c	Wed Mar 19 21:39:55 2014 -0700
     1.3 @@ -0,0 +1,168 @@
     1.4 +/**
     1.5 + * Hints test suite
     1.6 + */
     1.7 +
     1.8 +#include <stdio.h>
     1.9 +
    1.10 +#include "SDL.h"
    1.11 +#include "SDL_test.h"
    1.12 +
    1.13 +
    1.14 +const int _numHintsEnum = 25;
    1.15 +char* _HintsEnum[] =
    1.16 +  {
    1.17 +    SDL_HINT_ACCELEROMETER_AS_JOYSTICK,
    1.18 +    SDL_HINT_FRAMEBUFFER_ACCELERATION,
    1.19 +    SDL_HINT_GAMECONTROLLERCONFIG,
    1.20 +    SDL_HINT_GRAB_KEYBOARD,
    1.21 +    SDL_HINT_IDLE_TIMER_DISABLED,
    1.22 +    SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,
    1.23 +    SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK,
    1.24 +    SDL_HINT_MOUSE_RELATIVE_MODE_WARP,
    1.25 +    SDL_HINT_ORIENTATIONS,
    1.26 +    SDL_HINT_RENDER_DIRECT3D_THREADSAFE,
    1.27 +    SDL_HINT_RENDER_DRIVER,
    1.28 +    SDL_HINT_RENDER_OPENGL_SHADERS,
    1.29 +    SDL_HINT_RENDER_SCALE_QUALITY,
    1.30 +    SDL_HINT_RENDER_VSYNC,
    1.31 +    SDL_HINT_TIMER_RESOLUTION,
    1.32 +    SDL_HINT_VIDEO_ALLOW_SCREENSAVER,
    1.33 +    SDL_HINT_VIDEO_HIGHDPI_DISABLED,
    1.34 +    SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES,
    1.35 +    SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
    1.36 +    SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT,
    1.37 +    SDL_HINT_VIDEO_WIN_D3DCOMPILER,
    1.38 +    SDL_HINT_VIDEO_X11_XINERAMA,
    1.39 +    SDL_HINT_VIDEO_X11_XRANDR,
    1.40 +    SDL_HINT_VIDEO_X11_XVIDMODE,
    1.41 +    SDL_HINT_XINPUT_ENABLED,
    1.42 +  };
    1.43 +char* _HintsVerbose[] =
    1.44 +  {
    1.45 +    "SDL_HINT_ACCELEROMETER_AS_JOYSTICK",
    1.46 +    "SDL_HINT_FRAMEBUFFER_ACCELERATION",
    1.47 +    "SDL_HINT_GAMECONTROLLERCONFIG",
    1.48 +    "SDL_HINT_GRAB_KEYBOARD",
    1.49 +    "SDL_HINT_IDLE_TIMER_DISABLED",
    1.50 +    "SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS",
    1.51 +    "SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK",
    1.52 +    "SDL_HINT_MOUSE_RELATIVE_MODE_WARP",
    1.53 +    "SDL_HINT_ORIENTATIONS",
    1.54 +    "SDL_HINT_RENDER_DIRECT3D_THREADSAFE",
    1.55 +    "SDL_HINT_RENDER_DRIVER",
    1.56 +    "SDL_HINT_RENDER_OPENGL_SHADERS",
    1.57 +    "SDL_HINT_RENDER_SCALE_QUALITY",
    1.58 +    "SDL_HINT_RENDER_VSYNC",
    1.59 +    "SDL_HINT_TIMER_RESOLUTION",
    1.60 +    "SDL_HINT_VIDEO_ALLOW_SCREENSAVER",
    1.61 +    "SDL_HINT_VIDEO_HIGHDPI_DISABLED",
    1.62 +    "SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES",
    1.63 +    "SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS",
    1.64 +    "SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT",
    1.65 +    "SDL_HINT_VIDEO_WIN_D3DCOMPILER",
    1.66 +    "SDL_HINT_VIDEO_X11_XINERAMA",
    1.67 +    "SDL_HINT_VIDEO_X11_XRANDR",
    1.68 +    "SDL_HINT_VIDEO_X11_XVIDMODE",
    1.69 +    "SDL_HINT_XINPUT_ENABLED"
    1.70 +  };
    1.71 +
    1.72 +
    1.73 +/* Test case functions */
    1.74 +
    1.75 +/**
    1.76 + * @brief Call to SDL_GetHint
    1.77 + */
    1.78 +int
    1.79 +hints_getHint(void *arg)
    1.80 +{
    1.81 +  char *result1;
    1.82 +  char *result2;
    1.83 +  int i;
    1.84 +    
    1.85 +  for (i=0; i<_numHintsEnum; i++) {
    1.86 +    result1 = (char *)SDL_GetHint((char*)_HintsEnum[i]);
    1.87 +    SDLTest_AssertPass("Call to SDL_GetHint(%s) - using define definition", (char*)_HintsEnum[i]);
    1.88 +    result2 = (char *)SDL_GetHint((char *)_HintsVerbose[i]);
    1.89 +    SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char*)_HintsVerbose[i]);
    1.90 +    SDLTest_AssertCheck(
    1.91 +      (result1 == NULL && result2 == NULL) || (SDL_strcmp(result1, result2) == 0),
    1.92 +      "Verify returned values are equal; got: result1='%s' result2='%s",
    1.93 +      (result1 == NULL) ? "null" : result1,
    1.94 +      (result2 == NULL) ? "null" : result2);
    1.95 +  }
    1.96 +  
    1.97 +  return TEST_COMPLETED;
    1.98 +}
    1.99 +
   1.100 +/**
   1.101 + * @brief Call to SDL_SetHint
   1.102 + */
   1.103 +int
   1.104 +hints_setHint(void *arg)
   1.105 +{
   1.106 +  char *originalValue;
   1.107 +  char *value;
   1.108 +  char *testValue;
   1.109 +  SDL_bool result;
   1.110 +  int i, j;
   1.111 +
   1.112 +  /* Create random values to set */                    
   1.113 +  value = SDLTest_RandomAsciiStringOfSize(10);
   1.114 +    
   1.115 +  for (i=0; i<_numHintsEnum; i++) {
   1.116 +    /* Capture current value */
   1.117 +    originalValue = (char *)SDL_GetHint((char*)_HintsEnum[i]);
   1.118 +    SDLTest_AssertPass("Call to SDL_GetHint(%s)", (char*)_HintsEnum[i]);
   1.119 +    
   1.120 +    /* Set value (twice) */
   1.121 +    for (j=1; j<=2; j++) {
   1.122 +      result = SDL_SetHint((char*)_HintsEnum[i], value);
   1.123 +      SDLTest_AssertPass("Call to SDL_SetHint(%s, %s) (iteration %i)", (char*)_HintsEnum[i], value, j);
   1.124 +      SDLTest_AssertCheck(
   1.125 +        result == SDL_TRUE || result == SDL_FALSE, 
   1.126 +        "Verify valid result was returned, got: %i",
   1.127 +        (int)result);
   1.128 +      testValue = (char *)SDL_GetHint((char*)_HintsEnum[i]);
   1.129 +      SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char*)_HintsVerbose[i]);
   1.130 +      SDLTest_AssertCheck(
   1.131 +        (SDL_strcmp(value, testValue) == 0),
   1.132 +        "Verify returned value equals set value; got: testValue='%s' value='%s",
   1.133 +        (testValue == NULL) ? "null" : testValue,
   1.134 +        value);
   1.135 +    }
   1.136 +      
   1.137 +    /* Reset original value */
   1.138 +    result = SDL_SetHint((char*)_HintsEnum[i], originalValue);
   1.139 +    SDLTest_AssertPass("Call to SDL_SetHint(%s, originalValue)", (char*)_HintsEnum[i]);
   1.140 +    SDLTest_AssertCheck(
   1.141 +      result == SDL_TRUE || result == SDL_FALSE, 
   1.142 +      "Verify valid result was returned, got: %i",
   1.143 +      (int)result);
   1.144 +  }
   1.145 +  
   1.146 +  SDL_free(value);
   1.147 +  
   1.148 +  return TEST_COMPLETED;
   1.149 +}
   1.150 +
   1.151 +/* ================= Test References ================== */
   1.152 +
   1.153 +/* Hints test cases */
   1.154 +static const SDLTest_TestCaseReference hintsTest1 =
   1.155 +        { (SDLTest_TestCaseFp)hints_getHint, "hints_getHint", "Call to SDL_GetHint", TEST_ENABLED };
   1.156 +
   1.157 +static const SDLTest_TestCaseReference hintsTest2 =
   1.158 +        { (SDLTest_TestCaseFp)hints_setHint, "hints_setHint", "Call to SDL_SetHint", TEST_ENABLED };
   1.159 +
   1.160 +/* Sequence of Hints test cases */
   1.161 +static const SDLTest_TestCaseReference *hintsTests[] =  {
   1.162 +    &hintsTest1, &hintsTest2, NULL
   1.163 +};
   1.164 +
   1.165 +/* Hints test suite (global) */
   1.166 +SDLTest_TestSuiteReference hintsTestSuite = {
   1.167 +    "Hints",
   1.168 +    NULL,
   1.169 +    hintsTests,
   1.170 +    NULL
   1.171 +};