cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

testautomation_hints.c (5125B)


      1/**
      2 * Hints test suite
      3 */
      4
      5#include <stdio.h>
      6
      7#include "SDL.h"
      8#include "SDL_test.h"
      9
     10
     11const int _numHintsEnum = 25;
     12char* _HintsEnum[] =
     13  {
     14    SDL_HINT_ACCELEROMETER_AS_JOYSTICK,
     15    SDL_HINT_FRAMEBUFFER_ACCELERATION,
     16    SDL_HINT_GAMECONTROLLERCONFIG,
     17    SDL_HINT_GRAB_KEYBOARD,
     18    SDL_HINT_IDLE_TIMER_DISABLED,
     19    SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,
     20    SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK,
     21    SDL_HINT_MOUSE_RELATIVE_MODE_WARP,
     22    SDL_HINT_ORIENTATIONS,
     23    SDL_HINT_RENDER_DIRECT3D_THREADSAFE,
     24    SDL_HINT_RENDER_DRIVER,
     25    SDL_HINT_RENDER_OPENGL_SHADERS,
     26    SDL_HINT_RENDER_SCALE_QUALITY,
     27    SDL_HINT_RENDER_VSYNC,
     28    SDL_HINT_TIMER_RESOLUTION,
     29    SDL_HINT_VIDEO_ALLOW_SCREENSAVER,
     30    SDL_HINT_VIDEO_HIGHDPI_DISABLED,
     31    SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES,
     32    SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
     33    SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT,
     34    SDL_HINT_VIDEO_WIN_D3DCOMPILER,
     35    SDL_HINT_VIDEO_X11_XINERAMA,
     36    SDL_HINT_VIDEO_X11_XRANDR,
     37    SDL_HINT_VIDEO_X11_XVIDMODE,
     38    SDL_HINT_XINPUT_ENABLED,
     39  };
     40char* _HintsVerbose[] =
     41  {
     42    "SDL_HINT_ACCELEROMETER_AS_JOYSTICK",
     43    "SDL_HINT_FRAMEBUFFER_ACCELERATION",
     44    "SDL_HINT_GAMECONTROLLERCONFIG",
     45    "SDL_HINT_GRAB_KEYBOARD",
     46    "SDL_HINT_IDLE_TIMER_DISABLED",
     47    "SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS",
     48    "SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK",
     49    "SDL_HINT_MOUSE_RELATIVE_MODE_WARP",
     50    "SDL_HINT_ORIENTATIONS",
     51    "SDL_HINT_RENDER_DIRECT3D_THREADSAFE",
     52    "SDL_HINT_RENDER_DRIVER",
     53    "SDL_HINT_RENDER_OPENGL_SHADERS",
     54    "SDL_HINT_RENDER_SCALE_QUALITY",
     55    "SDL_HINT_RENDER_VSYNC",
     56    "SDL_HINT_TIMER_RESOLUTION",
     57    "SDL_HINT_VIDEO_ALLOW_SCREENSAVER",
     58    "SDL_HINT_VIDEO_HIGHDPI_DISABLED",
     59    "SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES",
     60    "SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS",
     61    "SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT",
     62    "SDL_HINT_VIDEO_WIN_D3DCOMPILER",
     63    "SDL_HINT_VIDEO_X11_XINERAMA",
     64    "SDL_HINT_VIDEO_X11_XRANDR",
     65    "SDL_HINT_VIDEO_X11_XVIDMODE",
     66    "SDL_HINT_XINPUT_ENABLED"
     67  };
     68
     69
     70/* Test case functions */
     71
     72/**
     73 * @brief Call to SDL_GetHint
     74 */
     75int
     76hints_getHint(void *arg)
     77{
     78  char *result1;
     79  char *result2;
     80  int i;
     81    
     82  for (i=0; i<_numHintsEnum; i++) {
     83    result1 = (char *)SDL_GetHint((char*)_HintsEnum[i]);
     84    SDLTest_AssertPass("Call to SDL_GetHint(%s) - using define definition", (char*)_HintsEnum[i]);
     85    result2 = (char *)SDL_GetHint((char *)_HintsVerbose[i]);
     86    SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char*)_HintsVerbose[i]);
     87    SDLTest_AssertCheck(
     88      (result1 == NULL && result2 == NULL) || (SDL_strcmp(result1, result2) == 0),
     89      "Verify returned values are equal; got: result1='%s' result2='%s",
     90      (result1 == NULL) ? "null" : result1,
     91      (result2 == NULL) ? "null" : result2);
     92  }
     93  
     94  return TEST_COMPLETED;
     95}
     96
     97/**
     98 * @brief Call to SDL_SetHint
     99 */
    100int
    101hints_setHint(void *arg)
    102{
    103  char *originalValue;
    104  char *value;
    105  char *testValue;
    106  SDL_bool result;
    107  int i, j;
    108
    109  /* Create random values to set */                    
    110  value = SDLTest_RandomAsciiStringOfSize(10);
    111    
    112  for (i=0; i<_numHintsEnum; i++) {
    113    /* Capture current value */
    114    originalValue = (char *)SDL_GetHint((char*)_HintsEnum[i]);
    115    SDLTest_AssertPass("Call to SDL_GetHint(%s)", (char*)_HintsEnum[i]);
    116    
    117    /* Set value (twice) */
    118    for (j=1; j<=2; j++) {
    119      result = SDL_SetHint((char*)_HintsEnum[i], value);
    120      SDLTest_AssertPass("Call to SDL_SetHint(%s, %s) (iteration %i)", (char*)_HintsEnum[i], value, j);
    121      SDLTest_AssertCheck(
    122        result == SDL_TRUE || result == SDL_FALSE, 
    123        "Verify valid result was returned, got: %i",
    124        (int)result);
    125      testValue = (char *)SDL_GetHint((char*)_HintsEnum[i]);
    126      SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char*)_HintsVerbose[i]);
    127      SDLTest_AssertCheck(
    128        (SDL_strcmp(value, testValue) == 0),
    129        "Verify returned value equals set value; got: testValue='%s' value='%s",
    130        (testValue == NULL) ? "null" : testValue,
    131        value);
    132    }
    133      
    134    /* Reset original value */
    135    result = SDL_SetHint((char*)_HintsEnum[i], originalValue);
    136    SDLTest_AssertPass("Call to SDL_SetHint(%s, originalValue)", (char*)_HintsEnum[i]);
    137    SDLTest_AssertCheck(
    138      result == SDL_TRUE || result == SDL_FALSE, 
    139      "Verify valid result was returned, got: %i",
    140      (int)result);
    141  }
    142  
    143  SDL_free(value);
    144  
    145  return TEST_COMPLETED;
    146}
    147
    148/* ================= Test References ================== */
    149
    150/* Hints test cases */
    151static const SDLTest_TestCaseReference hintsTest1 =
    152        { (SDLTest_TestCaseFp)hints_getHint, "hints_getHint", "Call to SDL_GetHint", TEST_ENABLED };
    153
    154static const SDLTest_TestCaseReference hintsTest2 =
    155        { (SDLTest_TestCaseFp)hints_setHint, "hints_setHint", "Call to SDL_SetHint", TEST_ENABLED };
    156
    157/* Sequence of Hints test cases */
    158static const SDLTest_TestCaseReference *hintsTests[] =  {
    159    &hintsTest1, &hintsTest2, NULL
    160};
    161
    162/* Hints test suite (global) */
    163SDLTest_TestSuiteReference hintsTestSuite = {
    164    "Hints",
    165    NULL,
    166    hintsTests,
    167    NULL
    168};