コード例 #1
0
ファイル: testautomation_video.c プロジェクト: Plombo/SDL
/**
 * @brief Tests the functionality of the SDL_GetWindowFlags function
 */
int
video_getWindowFlags(void *arg)
{
  SDL_Window* window;
  const char* title = "video_getWindowFlags Test Window";
  int x, y, w, h;
  SDL_WindowFlags flags;
  Uint32 actualFlags;
  
  /* Standard window */
  x = SDLTest_RandomIntegerInRange(1, 100);
  y = SDLTest_RandomIntegerInRange(1, 100);
  w = SDLTest_RandomIntegerInRange(320, 1024);
  h = SDLTest_RandomIntegerInRange(320, 768);
  
  /* Reliable flag */
  flags = SDL_WINDOW_SHOWN;
  
  window = SDL_CreateWindow(title, x, y, w, h, flags);
  SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags);
  SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
  if (window != NULL) {
      actualFlags = SDL_GetWindowFlags(window);
      SDLTest_AssertPass("Call to SDL_GetWindowFlags");
      SDLTest_AssertCheck((flags & actualFlags) == flags, "Verify returned value has flags %d set, got: %d", flags, actualFlags);
      SDL_DestroyWindow(window);
      SDLTest_AssertPass("Call to SDL_DestroyWindow");  
  }

  return TEST_COMPLETED;
}
コード例 #2
0
/**
 * @brief SDL_GetScancodeName negative cases
 * 
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeName
 */
int
keyboard_getScancodeNameNegative(void *arg)
{  
   SDL_Scancode scancode;
   char *result;
   char *expected = "";

   /* Clear error message */
   SDL_ClearError();
   SDLTest_AssertPass("Call to SDL_ClearError()");

   /* Negative scancode */
   scancode = (SDL_Scancode)SDLTest_RandomIntegerInRange(LONG_MIN, -1);
   result = (char *)SDL_GetScancodeName(scancode);
   SDLTest_AssertPass("Call to SDL_GetScancodeName(%d/negative)", scancode);
   SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
   SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result);
   _checkInvalidScancodeError();

   /* Large scancode */
   scancode = (SDL_Scancode)SDLTest_RandomIntegerInRange(SDL_NUM_SCANCODES, LONG_MAX);
   result = (char *)SDL_GetScancodeName(scancode);
   SDLTest_AssertPass("Call to SDL_GetScancodeName(%d/large)", scancode);
   SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
   SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result);
   _checkInvalidScancodeError();

   return TEST_COMPLETED;
}
コード例 #3
0
/**
 * \brief Builds various audio conversion structures
 *
 * \sa https://wiki.libsdl.org/SDL_BuildAudioCVT
 */
int audio_buildAudioCVT()
{
  int result;
  SDL_AudioCVT  cvt;
  SDL_AudioSpec spec1;
  SDL_AudioSpec spec2;
  int i, ii, j, jj, k, kk;

  /* No conversion needed */
  spec1.format = AUDIO_S16LSB;
  spec1.channels = 2;
  spec1.freq = 22050;
  result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
                                   spec1.format, spec1.channels, spec1.freq);
  SDLTest_AssertPass("Call to SDL_BuildAudioCVT(spec1 ==> spec1)");
  SDLTest_AssertCheck(result == 0, "Verify result value; expected: 0, got: %i", result);

  /* Typical conversion */
  spec1.format = AUDIO_S8;
  spec1.channels = 1;
  spec1.freq = 22050;
  spec2.format = AUDIO_S16LSB;
  spec2.channels = 2;
  spec2.freq = 44100;
  result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
                                   spec2.format, spec2.channels, spec2.freq);
  SDLTest_AssertPass("Call to SDL_BuildAudioCVT(spec1 ==> spec2)");
  SDLTest_AssertCheck(result == 1, "Verify result value; expected: 1, got: %i", result);

  /* All source conversions with random conversion targets, allow 'null' conversions */
  for (i = 0; i < _numAudioFormats; i++) {
    for (j = 0; j < _numAudioChannels; j++) {
      for (k = 0; k < _numAudioFrequencies; k++) {
        spec1.format = _audioFormats[i];
        spec1.channels = _audioChannels[j];
        spec1.freq = _audioFrequencies[k];
        ii = SDLTest_RandomIntegerInRange(0, _numAudioFormats - 1);
        jj = SDLTest_RandomIntegerInRange(0, _numAudioChannels - 1);
        kk = SDLTest_RandomIntegerInRange(0, _numAudioFrequencies - 1);
        spec2.format = _audioFormats[ii];
        spec2.channels = _audioChannels[jj];
        spec2.freq = _audioFrequencies[kk];
        result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
                                         spec2.format, spec2.channels, spec2.freq);
        SDLTest_AssertPass("Call to SDL_BuildAudioCVT(format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i ==> format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i)",
            i, _audioFormatsVerbose[i], spec1.format, j, spec1.channels, k, spec1.freq, ii, _audioFormatsVerbose[ii], spec2.format, jj, spec2.channels, kk, spec2.freq);
        SDLTest_AssertCheck(result == 0 || result == 1, "Verify result value; expected: 0 or 1, got: %i", result);
        if (result<0) {
          SDLTest_LogError("%s", SDL_GetError());
        } else {
          SDLTest_AssertCheck(cvt.len_mult > 0, "Verify that cvt.len_mult value; expected: >0, got: %i", cvt.len_mult);
        }
      }
    }
  }

   return TEST_COMPLETED;
}
コード例 #4
0
/**
 * @brief Check call to SDL_GetMouseFocus
 *
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetMouseFocus
 */
int
mouse_getMouseFocus(void *arg)
{
    const int w = MOUSE_TESTWINDOW_WIDTH, h = MOUSE_TESTWINDOW_HEIGHT;
    int x, y;
    SDL_Window *window;
    SDL_Window *focusWindow;

    /* Get focus - focus non-deterministic */
    focusWindow = SDL_GetMouseFocus();
    SDLTest_AssertPass("SDL_GetMouseFocus()");

        /* Create test window */
    window = _createMouseSuiteTestWindow();
    if (window == NULL) return TEST_ABORTED;

    /* Mouse to random position inside window */
    x = SDLTest_RandomIntegerInRange(1, w-1);
    y = SDLTest_RandomIntegerInRange(1, h-1);
    SDL_WarpMouseInWindow(window, x, y);
    SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);

    /* Pump events to update focus state */
    SDL_PumpEvents();
    SDLTest_AssertPass("SDL_PumpEvents()");

        /* Get focus with explicit window setup - focus deterministic */
    focusWindow = SDL_GetMouseFocus();
    SDLTest_AssertPass("SDL_GetMouseFocus()");
    SDLTest_AssertCheck (focusWindow != NULL, "Check returned window value is not NULL");
    SDLTest_AssertCheck (focusWindow == window, "Check returned window value is test window");

    /* Mouse to random position outside window */
    x = SDLTest_RandomIntegerInRange(-9, -1);
    y = SDLTest_RandomIntegerInRange(-9, -1);
    SDL_WarpMouseInWindow(window, x, y);
    SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);

        /* Clean up test window */
    _destroyMouseSuiteTestWindow(window);

    /* Pump events to update focus state */
    SDL_PumpEvents();
    SDLTest_AssertPass("SDL_PumpEvents()");

        /* Get focus for non-existing window */
    focusWindow = SDL_GetMouseFocus();
    SDLTest_AssertPass("SDL_GetMouseFocus()");
    SDLTest_AssertCheck (focusWindow == NULL, "Check returned window value is NULL");


    return TEST_COMPLETED;
}
コード例 #5
0
/**
 * \brief Enumerate and name available audio devices (output and capture).
 *
 * \sa https://wiki.libsdl.org/SDL_GetNumAudioDevices
 * \sa https://wiki.libsdl.org/SDL_GetAudioDeviceName
 */
int audio_enumerateAndNameAudioDevices()
{
   int t, tt;
   int i, n, nn;
   const char *name, *nameAgain;

   /* Iterate over types: t=0 output device, t=1 input/capture device */
   for (t=0; t<2; t++) {

      /* Get number of devices. */
      n = SDL_GetNumAudioDevices(t);
      SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(%i)", t);
      SDLTest_Log("Number of %s devices < 0, reported as %i", (t) ? "capture" : "output", n);
      SDLTest_AssertCheck(n >= 0, "Validate result is >= 0, got: %i", n);

      /* Variation of non-zero type */
      if (t==1) {
         tt = t + SDLTest_RandomIntegerInRange(1,10);
         nn = SDL_GetNumAudioDevices(tt);
         SDLTest_AssertCheck(n==nn, "Verify result from SDL_GetNumAudioDevices(%i), expected same number of audio devices %i, got %i", tt, n, nn);
         nn = SDL_GetNumAudioDevices(-tt);
         SDLTest_AssertCheck(n==nn, "Verify result from SDL_GetNumAudioDevices(%i), expected same number of audio devices %i, got %i", -tt, n, nn);
      }

      /* List devices. */
      if (n>0) {
         for (i=0; i<n; i++) {
            name = SDL_GetAudioDeviceName(i, t);
            SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
            SDLTest_AssertCheck(name != NULL, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not NULL", i, t);
            if (name != NULL) {
              SDLTest_AssertCheck(name[0] != '\0', "verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, t, name);
              if (t==1) {
                  /* Also try non-zero type */
                  tt = t + SDLTest_RandomIntegerInRange(1,10);
                  nameAgain = SDL_GetAudioDeviceName(i, tt);
                  SDLTest_AssertCheck(nameAgain != NULL, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not NULL", i, tt);
                  if (nameAgain != NULL) {
                    SDLTest_AssertCheck(nameAgain[0] != '\0', "Verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, tt, nameAgain);
                    SDLTest_AssertCheck(SDL_strcmp(name, nameAgain)==0,
                      "Verify SDL_GetAudioDeviceName(%i, %i) and SDL_GetAudioDeviceName(%i %i) return the same string",
                      i, t, i, tt);
                  }
               }
            }
         }
      }
   }

   return TEST_COMPLETED;
}
コード例 #6
0
/**
 * @brief SDL_GetKeyName negative cases
 * 
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyName
 */
int
keyboard_getKeyNameNegative(void *arg)
{  
   SDL_Keycode keycode;
   char *result;
   char *expected = "";

   /* Unknown keycode */
   keycode = SDLK_UNKNOWN;
   result = (char *)SDL_GetKeyName(keycode);
   SDLTest_AssertPass("Call to SDL_GetKeyName(%d/unknown)", keycode);
   SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
   SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result);

   /* Clear error message */
   SDL_ClearError();
   SDLTest_AssertPass("Call to SDL_ClearError()");

   /* Negative keycode */
   keycode = (SDL_Keycode)SDLTest_RandomIntegerInRange(-255, -1);
   result = (char *)SDL_GetKeyName(keycode);
   SDLTest_AssertPass("Call to SDL_GetKeyName(%d/negative)", keycode);
   SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
   SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result);
   _checkInvalidScancodeError();

   SDL_ClearError();
   SDLTest_AssertPass("Call to SDL_ClearError()");

   return TEST_COMPLETED;
}
コード例 #7
0
/**
 * @brief Check call to SDL_WarpMouseInWindow
 *
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_WarpMouseInWindow
 */
int
mouse_warpMouseInWindow(void *arg)
{
    const int w = MOUSE_TESTWINDOW_WIDTH, h = MOUSE_TESTWINDOW_HEIGHT;
    int numPositions = 6;
    int xPositions[] = {-1, 0, 1, w-1, w, w+1 };
    int yPositions[] = {-1, 0, 1, h-1, h, h+1 };
    int x, y, i, j;
    SDL_Window *window;

    /* Create test window */
    window = _createMouseSuiteTestWindow();
    if (window == NULL) return TEST_ABORTED;

    /* Mouse to random position inside window */
    x = SDLTest_RandomIntegerInRange(1, w-1);
    y = SDLTest_RandomIntegerInRange(1, h-1);
    SDL_WarpMouseInWindow(window, x, y);
    SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);

        /* Same position again */
    SDL_WarpMouseInWindow(window, x, y);
    SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);

    /* Mouse to various boundary positions */
    for (i=0; i<numPositions; i++) {
      for (j=0; j<numPositions; j++) {
        x = xPositions[i];
        y = yPositions[j];
        SDL_WarpMouseInWindow(window, x, y);
        SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);

        /* TODO: add tracking of events and check that each call generates a mouse motion event */
        SDL_PumpEvents();
        SDLTest_AssertPass("SDL_PumpEvents()");
      }
    }


        /* Clean up test window */
    _destroyMouseSuiteTestWindow(window);

    return TEST_COMPLETED;
}
コード例 #8
0
/**
 * @brief Check call to SDL_GetModState and SDL_SetModState
 * 
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetModState
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_SetModState
 */
int
keyboard_getSetModState(void *arg)
{   
   SDL_Keymod result;
   SDL_Keymod currentState;
   SDL_Keymod newState;
   SDL_Keymod allStates =     
    KMOD_NONE |
    KMOD_LSHIFT |
    KMOD_RSHIFT |
    KMOD_LCTRL |
    KMOD_RCTRL |
    KMOD_LALT |
    KMOD_RALT |
    KMOD_LGUI |
    KMOD_RGUI |
    KMOD_NUM |
    KMOD_CAPS |
    KMOD_MODE |
    KMOD_RESERVED;

   /* Get state, cache for later reset */                                                   
   result = SDL_GetModState();
   SDLTest_AssertPass("Call to SDL_GetModState()");
   SDLTest_AssertCheck(result >=0 && result <= allStates, "Verify result from call is valid, expected: 0 <= result <= %i, got: %i", allStates, result);   
   currentState = result;

   /* Set random state */   
   newState = SDLTest_RandomIntegerInRange(0, allStates);
   SDL_SetModState(newState);
   SDLTest_AssertPass("Call to SDL_SetModState(%i)", newState);
   result = SDL_GetModState();
   SDLTest_AssertPass("Call to SDL_GetModState()");
   SDLTest_AssertCheck(result == newState, "Verify result from call is valid, expected: %i, got: %i", newState, result);

   /* Set zero state */
   SDL_SetModState(0);
   SDLTest_AssertPass("Call to SDL_SetModState(0)");
   result = SDL_GetModState();
   SDLTest_AssertPass("Call to SDL_GetModState()");
   SDLTest_AssertCheck(result == 0, "Verify result from call is valid, expected: 0, got: %i", result);

   /* Revert back to cached current state if needed */
   if (currentState != 0) {
     SDL_SetModState(currentState);
     SDLTest_AssertPass("Call to SDL_SetModState(%i)", currentState);
     result = SDL_GetModState();
     SDLTest_AssertPass("Call to SDL_GetModState()");
     SDLTest_AssertCheck(result == currentState, "Verify result from call is valid, expected: %i, got: %i", currentState, result);
   }

   return TEST_COMPLETED;
}
コード例 #9
0
/**
 * @brief Call to SDL_AddTimer and SDL_RemoveTimer
 */
int
timer_addRemoveTimer(void *arg)
{
  SDL_TimerID id;
  SDL_bool result;
  int param;

  /* Reset state */
  _paramCheck = 0;
  _timerCallbackCalled = 0;

  /* Set timer with a long delay */
  id = SDL_AddTimer(10000, _timerTestCallback, NULL);
  SDLTest_AssertPass("Call to SDL_AddTimer(10000,...)");
  SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %d", id);

  /* Remove timer again and check that callback was not called */
  result = SDL_RemoveTimer(id);
  SDLTest_AssertPass("Call to SDL_RemoveTimer()");
  SDLTest_AssertCheck(result == SDL_TRUE, "Check result value, expected: %i, got: %i", SDL_TRUE, result);
  SDLTest_AssertCheck(_timerCallbackCalled == 0, "Check callback WAS NOT called, expected: 0, got: %i", _timerCallbackCalled);

  /* Try to remove timer again (should be a NOOP) */
  result = SDL_RemoveTimer(id);
  SDLTest_AssertPass("Call to SDL_RemoveTimer()");
  SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected: %i, got: %i", SDL_FALSE, result);

  /* Reset state */
  param = SDLTest_RandomIntegerInRange(-1024, 1024);
  _paramCheck = 1;
  _paramValue = param;
  _timerCallbackCalled = 0;

  /* Set timer with a short delay */
  id = SDL_AddTimer(10, _timerTestCallback, (void *)&param);
  SDLTest_AssertPass("Call to SDL_AddTimer(10, param)");
  SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %d", id);

  /* Wait to let timer trigger callback */
  SDL_Delay(100);
  SDLTest_AssertPass("Call to SDL_Delay(100)");

  /* Remove timer again and check that callback was called */
  result = SDL_RemoveTimer(id);
  SDLTest_AssertPass("Call to SDL_RemoveTimer()");
  SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected: %i, got: %i", SDL_FALSE, result);
  SDLTest_AssertCheck(_timerCallbackCalled == 1, "Check callback WAS called, expected: 1, got: %i", _timerCallbackCalled);

  return TEST_COMPLETED;
}
コード例 #10
0
ファイル: testautomation_video.c プロジェクト: Plombo/SDL
/**
 * @brief Tests the functionality of the SDL_CreateWindow function using different sizes
 */
int
video_createWindowVariousSizes(void *arg)
{
  SDL_Window* window;
  const char* title = "video_createWindowVariousSizes Test Window";
  int x, y, w, h;
  int wVariation, hVariation;
  
  x = SDLTest_RandomIntegerInRange(1, 100);
  y = SDLTest_RandomIntegerInRange(1, 100);
  for (wVariation = 0; wVariation < 3; wVariation++) {
   for (hVariation = 0; hVariation < 3; hVariation++) {
    switch(wVariation) {
     case 0:
      /* Width of 1 */  
      w = 1;
      break;
     case 1:
      /* Random "normal" width */  
      w = SDLTest_RandomIntegerInRange(320, 1920);
      break;
     case 2:
      /* Random "large" width */  
      w = SDLTest_RandomIntegerInRange(2048, 4095);
      break;
    }

    switch(hVariation) {
     case 0:
      /* Height of 1 */  
      h = 1;
      break;
     case 1:
      /* Random "normal" height */  
      h = SDLTest_RandomIntegerInRange(320, 1080);
      break;
     case 2:
      /* Random "large" height */  
      h = SDLTest_RandomIntegerInRange(2048, 4095);
      break;
     }
     
    window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN);
    SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
    SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
    if (window != NULL) {
      SDL_DestroyWindow(window);
      SDLTest_AssertPass("Call to SDL_DestroyWindow");
    }
   }
  }  

  return TEST_COMPLETED;
}
コード例 #11
0
/**
 * @brief Adds and deletes an event watch function with userdata
 *
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_AddEventWatch
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_DelEventWatch
 *
 */
int
events_addDelEventWatchWithUserdata(void *arg)
{
   SDL_Event event;

   /* Create user event */
   event.type = SDL_USEREVENT;
   event.user.code = SDLTest_RandomSint32();
   event.user.data1 = (void *)&_userdataValue1;
   event.user.data2 = (void *)&_userdataValue2;

   /* Enable userdata check and set a value to check */
   _userdataCheck = 1;
   _userdataValue = SDLTest_RandomIntegerInRange(-1024, 1024);

   /* Reset event filter call tracker */
   _eventFilterCalled = 0;

   /* Add watch */
   SDL_AddEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
   SDLTest_AssertPass("Call to SDL_AddEventWatch()");

   /* Push a user event onto the queue and force queue update */
   SDL_PushEvent(&event);
   SDLTest_AssertPass("Call to SDL_PushEvent()");
   SDL_PumpEvents();
   SDLTest_AssertPass("Call to SDL_PumpEvents()");
   SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");

   /* Delete watch */
   SDL_DelEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
   SDLTest_AssertPass("Call to SDL_DelEventWatch()");

   /* Push a user event onto the queue and force queue update */
   _eventFilterCalled = 0;
   SDL_PushEvent(&event);
   SDLTest_AssertPass("Call to SDL_PushEvent()");
   SDL_PumpEvents();
   SDLTest_AssertPass("Call to SDL_PumpEvents()");
   SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");

   return TEST_COMPLETED;
}
コード例 #12
0
/**
 * \brief Negative tests around enumeration and naming of audio devices.
 *
 * \sa https://wiki.libsdl.org/SDL_GetNumAudioDevices
 * \sa https://wiki.libsdl.org/SDL_GetAudioDeviceName
 */
int audio_enumerateAndNameAudioDevicesNegativeTests()
{
   int t;
   int i, j, no, nc;
   const char *name;

   /* Get number of devices. */
   no = SDL_GetNumAudioDevices(0);
   SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
   nc = SDL_GetNumAudioDevices(1);
   SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(1)");

   /* Invalid device index when getting name */
   for (t=0; t<2; t++) {
      /* Negative device index */
      i = SDLTest_RandomIntegerInRange(-10,-1);
      name = SDL_GetAudioDeviceName(i, t);
      SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
      SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result NULL, expected NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);

      /* Device index past range */
      for (j=0; j<3; j++) {
         i = (t) ? nc+j : no+j;
         name = SDL_GetAudioDeviceName(i, t);
         SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
         SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result, expected: NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
      }

      /* Capture index past capture range but within output range */
      if ((no>0) && (no>nc) && (t==1)) {
         i = no-1;
         name = SDL_GetAudioDeviceName(i, t);
         SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
         SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result, expected: NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
      }
   }

   return TEST_COMPLETED;
}
コード例 #13
0
/**
 * @brief Call to SDL_Delay and SDL_GetTicks
 */
int
timer_delayAndGetTicks(void *arg)
{
  const Uint32 testDelay = 100;
  const Uint32 marginOfError = 25;
  Uint32 result;
  Uint32 result2;
  Uint32 difference;

  /* Zero delay */
  SDL_Delay(0);
  SDLTest_AssertPass("Call to SDL_Delay(0)");

  /* Non-zero delay */
  SDL_Delay(1);
  SDLTest_AssertPass("Call to SDL_Delay(1)");

  SDL_Delay(SDLTest_RandomIntegerInRange(5, 15));
  SDLTest_AssertPass("Call to SDL_Delay()");

  /* Get ticks count - should be non-zero by now */
  result = SDL_GetTicks();
  SDLTest_AssertPass("Call to SDL_GetTicks()");
  SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %d", result);

  /* Delay a bit longer and measure ticks and verify difference */
  SDL_Delay(testDelay);
  SDLTest_AssertPass("Call to SDL_Delay(%d)", testDelay);
  result2 = SDL_GetTicks();
  SDLTest_AssertPass("Call to SDL_GetTicks()");
  SDLTest_AssertCheck(result2 > 0, "Check result value, expected: >0, got: %d", result2);
  difference = result2 - result;
  SDLTest_AssertCheck(difference > (testDelay - marginOfError), "Check difference, expected: >%d, got: %d", testDelay - marginOfError, difference);
  SDLTest_AssertCheck(difference < (testDelay + marginOfError), "Check difference, expected: <%d, got: %d", testDelay + marginOfError, difference);

  return TEST_COMPLETED;
}
コード例 #14
0
ファイル: testsprite2.c プロジェクト: Super-Man/seal2d
int
main(int argc, char *argv[])
{
    int i;
    Uint32 then, now, frames;
    Uint64 seed;
    const char *icon = "icon.bmp";

    /* Initialize parameters */
    num_sprites = NUM_SPRITES;

    /* Initialize test framework */
    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
    if (!state) {
        return 1;
    }

    for (i = 1; i < argc;) {
        int consumed;

        consumed = SDLTest_CommonArg(state, i);
        if (consumed == 0) {
            consumed = -1;
            if (SDL_strcasecmp(argv[i], "--blend") == 0) {
                if (argv[i + 1]) {
                    if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
                        blendMode = SDL_BLENDMODE_NONE;
                        consumed = 2;
                    } else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) {
                        blendMode = SDL_BLENDMODE_BLEND;
                        consumed = 2;
                    } else if (SDL_strcasecmp(argv[i + 1], "add") == 0) {
                        blendMode = SDL_BLENDMODE_ADD;
                        consumed = 2;
                    } else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) {
                        blendMode = SDL_BLENDMODE_MOD;
                        consumed = 2;
                    }
                }
            } else if (SDL_strcasecmp(argv[i], "--iterations") == 0) {
                if (argv[i + 1]) {
                    iterations = SDL_atoi(argv[i + 1]);
                    if (iterations < -1) iterations = -1;
                    consumed = 2;
                }
            } else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) {
                cycle_color = SDL_TRUE;
                consumed = 1;
            } else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) {
                cycle_alpha = SDL_TRUE;
                consumed = 1;
            } else if (SDL_isdigit(*argv[i])) {
                num_sprites = SDL_atoi(argv[i]);
                consumed = 1;
            } else if (argv[i][0] != '-') {
                icon = argv[i];
                consumed = 1;
            }
        }
        if (consumed < 0) {
            SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha] [--iterations N] [num_sprites] [icon.bmp]\n",
                    argv[0], SDLTest_CommonUsage(state));
            quit(1);
        }
        i += consumed;
    }
    if (!SDLTest_CommonInit(state)) {
        quit(2);
    }

    /* Create the windows, initialize the renderers, and load the textures */
    sprites =
        (SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites));
    if (!sprites) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
        quit(2);
    }
    for (i = 0; i < state->num_windows; ++i) {
        SDL_Renderer *renderer = state->renderers[i];
        SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
        SDL_RenderClear(renderer);
    }
    if (LoadSprite(icon) < 0) {
        quit(2);
    }

    /* Allocate memory for the sprite info */
    positions = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect));
    velocities = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect));
    if (!positions || !velocities) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
        quit(2);
    }

    /* Position sprites and set their velocities using the fuzzer */ 
    if (iterations >= 0) {
        /* Deterministic seed - used for visual tests */
        seed = (Uint64)iterations;
    } else {
        /* Pseudo-random seed generated from the time */
        seed = (Uint64)time(NULL);
    }
    SDLTest_FuzzerInit(seed);
    for (i = 0; i < num_sprites; ++i) {
        positions[i].x = SDLTest_RandomIntegerInRange(0, state->window_w - sprite_w);
        positions[i].y = SDLTest_RandomIntegerInRange(0, state->window_h - sprite_h);
        positions[i].w = sprite_w;
        positions[i].h = sprite_h;
        velocities[i].x = 0;
        velocities[i].y = 0;
        while (!velocities[i].x && !velocities[i].y) {
            velocities[i].x = SDLTest_RandomIntegerInRange(-MAX_SPEED, MAX_SPEED);
            velocities[i].y = SDLTest_RandomIntegerInRange(-MAX_SPEED, MAX_SPEED);
        }
    }

    /* Main render loop */
    frames = 0;
    then = SDL_GetTicks();
    done = 0;

#ifdef __EMSCRIPTEN__
    emscripten_set_main_loop(loop, 0, 1);
#else
    while (!done) {
        ++frames;
        loop();
    }
#endif

    /* Print out some timing information */
    now = SDL_GetTicks();
    if (now > then) {
        double fps = ((double) frames * 1000) / (now - then);
        SDL_Log("%2.2f frames per second\n", fps);
    }
    quit(0);
    return 0;
}
コード例 #15
0
/**
 * @brief Check call to SDL_SetTextInputRect
 * 
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_SetTextInputRect
 */
int
keyboard_setTextInputRect(void *arg)
{   
   SDL_Rect refRect;
   
   /* Normal visible refRect, origin inside */
   refRect.x = SDLTest_RandomIntegerInRange(1, 50);;
   refRect.y = SDLTest_RandomIntegerInRange(1, 50);;
   refRect.w = SDLTest_RandomIntegerInRange(10, 50);
   refRect.h = SDLTest_RandomIntegerInRange(10, 50);
   _testSetTextInputRect(refRect);
   
   /* Normal visible refRect, origin 0,0 */
   refRect.x = 0;
   refRect.y = 0;
   refRect.w = SDLTest_RandomIntegerInRange(10, 50);
   refRect.h = SDLTest_RandomIntegerInRange(10, 50);
   _testSetTextInputRect(refRect);

   /* 1Pixel refRect */
   refRect.x = SDLTest_RandomIntegerInRange(10, 50);;
   refRect.y = SDLTest_RandomIntegerInRange(10, 50);;
   refRect.w = 1;
   refRect.h = 1;
   _testSetTextInputRect(refRect);

   /* 0pixel refRect */
   refRect.x = 1;
   refRect.y = 1;
   refRect.w = 1;
   refRect.h = 0;
   _testSetTextInputRect(refRect);

   /* 0pixel refRect */
   refRect.x = 1;
   refRect.y = 1;
   refRect.w = 0;
   refRect.h = 1;
   _testSetTextInputRect(refRect);

   /* 0pixel refRect */
   refRect.x = 1;
   refRect.y = 1;
   refRect.w = 0;
   refRect.h = 0;
   _testSetTextInputRect(refRect);

   /* 0pixel refRect */
   refRect.x = 0;
   refRect.y = 0;
   refRect.w = 0;
   refRect.h = 0;
   _testSetTextInputRect(refRect);

   /* negative refRect */
   refRect.x = SDLTest_RandomIntegerInRange(-200, -100);;
   refRect.y = SDLTest_RandomIntegerInRange(-200, -100);;
   refRect.w = 50;
   refRect.h = 50;
   _testSetTextInputRect(refRect);

   /* oversized refRect */
   refRect.x = SDLTest_RandomIntegerInRange(1, 50);;
   refRect.y = SDLTest_RandomIntegerInRange(1, 50);;
   refRect.w = 5000;
   refRect.h = 5000;
   _testSetTextInputRect(refRect);

   /* NULL refRect */
   SDL_SetTextInputRect(NULL);
   SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");

   return TEST_COMPLETED;
}
コード例 #16
0
/**
 * \brief Pause and unpause audio
 *
 * \sa https://wiki.libsdl.org/SDL_PauseAudio
 */
int audio_pauseUnpauseAudio()
{
    int result;
    int i, iMax, j, k, l;
    int totalDelay;
    int pause_on;
    int originalCounter;
    const char* audioDriver;
    SDL_AudioSpec desired;

    /* Stop SDL audio subsystem */
    SDL_QuitSubSystem( SDL_INIT_AUDIO );
        SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");

        /* Loop over all available audio drivers */
        iMax = SDL_GetNumAudioDrivers();
        SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
        SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
        for (i = 0; i < iMax; i++) {
            audioDriver = SDL_GetAudioDriver(i);
            SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
            SDLTest_AssertCheck(audioDriver != NULL, "Audio driver name is not NULL");
            SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver);

            /* Change specs */
            for (j = 0; j < 2; j++) {

                /* Call Init */
                result = SDL_AudioInit(audioDriver);
                SDLTest_AssertPass("Call to SDL_AudioInit('%s')", audioDriver);
                SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);

                /* Set spec */
                SDL_memset(&desired, 0, sizeof(desired));
                switch (j) {
                    case 0:
                    /* Set standard desired spec */
                    desired.freq = 22050;
                    desired.format = AUDIO_S16SYS;
                    desired.channels = 2;
                    desired.samples = 4096;
                    desired.callback = _audio_testCallback;
                    desired.userdata = NULL;

                    case 1:
                    /* Set custom desired spec */
                    desired.freq = 48000;
                    desired.format = AUDIO_F32SYS;
                    desired.channels = 2;
                    desired.samples = 2048;
                    desired.callback = _audio_testCallback;
                    desired.userdata = NULL;
                    break;
            }

            /* Call Open */
            result = SDL_OpenAudio(&desired, NULL);
            SDLTest_AssertPass("Call to SDL_OpenAudio(desired_spec_%d, NULL)", j);
            SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0 got: %d", result);

            /* Start and stop audio multiple times */
            for (l=0; l<3; l++) {
                SDLTest_Log("Pause/Unpause iteration: %d", l+1);
            
                /* Reset callback counters */
                _audio_testCallbackCounter = 0;
                _audio_testCallbackLength = 0;

                /* Un-pause audio to start playing (maybe multiple times) */
                pause_on = 0;
                for (k=0; k <= j; k++) {
                    SDL_PauseAudio(pause_on);
                    SDLTest_AssertPass("Call to SDL_PauseAudio(%d), call %d", pause_on, k+1);
                }
            
                /* Wait for callback */
                totalDelay = 0;
                do {
                    SDL_Delay(10);
                    totalDelay += 10;
                } 
                while (_audio_testCallbackCounter == 0 && totalDelay < 1000);
                SDLTest_AssertCheck(_audio_testCallbackCounter > 0, "Verify callback counter; expected: >0 got: %d", _audio_testCallbackCounter);
                SDLTest_AssertCheck(_audio_testCallbackLength > 0, "Verify callback length; expected: >0 got: %d", _audio_testCallbackLength);

                /* Pause audio to stop playing (maybe multiple times) */
                for (k=0; k <= j; k++) {
                    pause_on = (k==0) ? 1 : SDLTest_RandomIntegerInRange(99, 9999);
                    SDL_PauseAudio(pause_on);
                    SDLTest_AssertPass("Call to SDL_PauseAudio(%d), call %d", pause_on, k+1);
                }
            
                /* Ensure callback is not called again */
                originalCounter = _audio_testCallbackCounter;
                SDL_Delay(totalDelay + 10);
                SDLTest_AssertCheck(originalCounter == _audio_testCallbackCounter, "Verify callback counter; expected: %d, got: %d", originalCounter, _audio_testCallbackCounter);
            }

            /* Call Close */
            SDL_CloseAudio();
            SDLTest_AssertPass("Call to SDL_CloseAudio()");

            /* Call Quit */
            SDL_AudioQuit();
            SDLTest_AssertPass("Call to SDL_AudioQuit()");

        } /* spec loop */
    } /* driver loop */

    /* Restart audio again */
    _audioSetUp(NULL);

    return TEST_COMPLETED;
}
コード例 #17
0
/**
 * \brief Convert audio using various conversion structures
 *
 * \sa https://wiki.libsdl.org/SDL_BuildAudioCVT
 * \sa https://wiki.libsdl.org/SDL_ConvertAudio
 */
int audio_convertAudio()
{
  int result;
  SDL_AudioCVT  cvt;
  SDL_AudioSpec spec1;
  SDL_AudioSpec spec2;
  int c;
  char message[128];
  int i, ii, j, jj, k, kk, l, ll;

  /* Iterate over bitmask that determines which parameters are modified in the conversion */
  for (c = 1; c < 8; c++) {
    SDL_strlcpy(message, "Changing:", 128);
    if (c & 1) {
      SDL_strlcat(message, " Format", 128);
    }
    if (c & 2) {
      SDL_strlcat(message, " Channels", 128);
    }
    if (c & 4) {
      SDL_strlcat(message, " Frequencies", 128);
    }
    SDLTest_Log("%s", message);
    /* All source conversions with random conversion targets */
    for (i = 0; i < _numAudioFormats; i++) {
      for (j = 0; j < _numAudioChannels; j++) {
        for (k = 0; k < _numAudioFrequencies; k++) {
          spec1.format = _audioFormats[i];
          spec1.channels = _audioChannels[j];
          spec1.freq = _audioFrequencies[k];

          /* Ensure we have a different target format */
          do {
            if (c & 1) {
              ii = SDLTest_RandomIntegerInRange(0, _numAudioFormats - 1);
            } else {
              ii = 1;
            }
            if (c & 2) {
              jj = SDLTest_RandomIntegerInRange(0, _numAudioChannels - 1);
            } else {
              jj= j;
            }
            if (c & 4) {
              kk = SDLTest_RandomIntegerInRange(0, _numAudioFrequencies - 1);
            } else {
              kk = k;
            }
          } while ((i == ii) && (j == jj) && (k == kk));
          spec2.format = _audioFormats[ii];
          spec2.channels = _audioChannels[jj];
          spec2.freq = _audioFrequencies[kk];

          result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
                                           spec2.format, spec2.channels, spec2.freq);
          SDLTest_AssertPass("Call to SDL_BuildAudioCVT(format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i ==> format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i)",
            i, _audioFormatsVerbose[i], spec1.format, j, spec1.channels, k, spec1.freq, ii, _audioFormatsVerbose[ii], spec2.format, jj, spec2.channels, kk, spec2.freq);
          SDLTest_AssertCheck(result == 1, "Verify result value; expected: 1, got: %i", result);
          if (result != 1) {
            SDLTest_LogError("%s", SDL_GetError());
          } else {
            SDLTest_AssertCheck(cvt.len_mult > 0, "Verify that cvt.len_mult value; expected: >0, got: %i", cvt.len_mult);
            if (cvt.len_mult < 1) return TEST_ABORTED;

            /* Create some random data to convert */
            l = 64;
            ll = l * cvt.len_mult;
            SDLTest_Log("Creating dummy sample buffer of %i length (%i bytes)", l, ll);
            cvt.len = l;
            cvt.buf = (Uint8 *)SDL_malloc(ll);
            SDLTest_AssertCheck(cvt.buf != NULL, "Check data buffer to convert is not NULL");
            if (cvt.buf == NULL) return TEST_ABORTED;

            /* Convert the data */
            result = SDL_ConvertAudio(&cvt);
            SDLTest_AssertPass("Call to SDL_ConvertAudio()");
            SDLTest_AssertCheck(result == 0, "Verify result value; expected: 0; got: %i", result);
            SDLTest_AssertCheck(cvt.buf != NULL, "Verify conversion buffer is not NULL");
            SDLTest_AssertCheck(cvt.len_ratio > 0.0, "Verify conversion length ratio; expected: >0; got: %f", cvt.len_ratio);

            /* Free converted buffer */
            SDL_free(cvt.buf);
            cvt.buf = NULL;
          }
        }
      }
    }
  }

   return TEST_COMPLETED;
}
コード例 #18
0
ファイル: testautomation_video.c プロジェクト: Plombo/SDL
/**
 * @brief Tests the functionality of the SDL_CreateWindow function using different positions
 */
int
video_createWindowVariousPositions(void *arg)
{
  SDL_Window* window;
  const char* title = "video_createWindowVariousPositions Test Window";
  int x, y, w, h;
  int xVariation, yVariation;
  
  for (xVariation = 0; xVariation < 6; xVariation++) {
   for (yVariation = 0; yVariation < 6; yVariation++) {
    switch(xVariation) {
     case 0:
      /* Zero X Position */  
      x = 0;
      break;
     case 1:
      /* Random X position inside screen */  
      x = SDLTest_RandomIntegerInRange(1, 100);
      break;
     case 2:
      /* Random X position outside screen (positive) */  
      x = SDLTest_RandomIntegerInRange(10000, 11000);
      break;
     case 3:
      /* Random X position outside screen (negative) */  
      x = SDLTest_RandomIntegerInRange(-1000, -100);
      break;
     case 4:
      /* Centered X position */  
      x = SDL_WINDOWPOS_CENTERED;
      break;
     case 5:
      /* Undefined X position */  
      x = SDL_WINDOWPOS_UNDEFINED;
      break;
    }

    switch(yVariation) {
     case 0:
      /* Zero X Position */  
      y = 0;
      break;
     case 1:
      /* Random X position inside screen */  
      y = SDLTest_RandomIntegerInRange(1, 100);
      break;
     case 2:
      /* Random X position outside screen (positive) */  
      y = SDLTest_RandomIntegerInRange(10000, 11000);
      break;
     case 3:
      /* Random Y position outside screen (negative) */  
      y = SDLTest_RandomIntegerInRange(-1000, -100);
      break;
     case 4:
      /* Centered Y position */  
      y = SDL_WINDOWPOS_CENTERED;
      break;
     case 5:
      /* Undefined Y position */  
      y = SDL_WINDOWPOS_UNDEFINED;
      break;
    }
     
    w = SDLTest_RandomIntegerInRange(32, 96);
    h = SDLTest_RandomIntegerInRange(32, 96);
    window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN);
    SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
    SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
    if (window != NULL) {
      SDL_DestroyWindow(window);
      SDLTest_AssertPass("Call to SDL_DestroyWindow");
    }
   }
  } 

  return TEST_COMPLETED;
}
コード例 #19
0
/**
 * @brief Call to SDL_getenv and SDL_setenv
 */
int
stdlib_getsetenv(void *arg)
{
  const int nameLen = 16;
  char name[17];
  int counter;
  int result;
  char * value1;
  char * value2;
  char * expected;
  int overwrite;
  char * text;

  /* Create a random name. This tests SDL_getenv, since we need to */
  /* make sure the variable is not set yet (it shouldn't). */
  do {
    for(counter = 0; counter < nameLen; counter++) {
      name[counter] = (char)SDLTest_RandomIntegerInRange(65, 90);
    }
    name[nameLen] = '\0';
    
    text = SDL_getenv(name);
    SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
    if (text != NULL) {
      SDLTest_Log("Expected: NULL, Got: '%s' (%i)", text, (int) SDL_strlen(text));
    }
  } while (text != NULL);
   
  /* Create random values to set */                    
  value1 = SDLTest_RandomAsciiStringOfSize(10);
  value2 = SDLTest_RandomAsciiStringOfSize(10);

  /* Set value 1 without overwrite */
  overwrite = 0;
  expected = value1;
  result = SDL_setenv(name, value1, overwrite);
  SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value1, overwrite);
  SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);

  /* Check value */
  text = SDL_getenv(name);
  SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
  SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
  if (text != NULL) {
    SDLTest_AssertCheck(
      SDL_strcmp(text, expected) == 0, 
      "Verify returned text, expected: %s, got: %s",
      expected,
      text);
  }
  
  /* Set value 2 with overwrite */
  overwrite = 1;
  expected = value2;    
  result = SDL_setenv(name, value2, overwrite);
  SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value2, overwrite);
  SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);

  /* Check value */
  text = SDL_getenv(name);
  SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
  SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
  if (text != NULL) {
    SDLTest_AssertCheck(
      SDL_strcmp(text, expected) == 0, 
      "Verify returned text, expected: %s, got: %s",
      expected,
      text);
  }

  /* Set value 1 without overwrite */
  overwrite = 0;
  expected = value2;    
  result = SDL_setenv(name, value1, overwrite);
  SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value1, overwrite);
  SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);

  /* Check value */
  text = SDL_getenv(name);
  SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
  SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
  if (text != NULL) {
    SDLTest_AssertCheck(
      SDL_strcmp(text, expected) == 0, 
      "Verify returned text, expected: %s, got: %s",
      expected,
      text);
  }
  
  /* Set value 1 without overwrite */
  overwrite = 1;
  expected = value1;
  result = SDL_setenv(name, value1, overwrite);
  SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value1, overwrite);
  SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);

  /* Check value */
  text = SDL_getenv(name);
  SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
  SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
  if (text != NULL) {
    SDLTest_AssertCheck(
      SDL_strcmp(text, expected) == 0, 
      "Verify returned text, expected: %s, got: %s",
      expected,
      text);
  }

  /* Negative cases */
  for (overwrite=0; overwrite <= 1; overwrite++) { 
    result = SDL_setenv(NULL, value1, overwrite);
    SDLTest_AssertPass("Call to SDL_setenv(NULL,'%s', %i)", value1, overwrite);
    SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
    result = SDL_setenv("", value1, overwrite);
    SDLTest_AssertPass("Call to SDL_setenv('','%s', %i)", value1, overwrite);
    SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
    result = SDL_setenv("=", value1, overwrite);
    SDLTest_AssertPass("Call to SDL_setenv('=','%s', %i)", value1, overwrite);
    SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
    result = SDL_setenv(name, NULL, overwrite);
    SDLTest_AssertPass("Call to SDL_setenv('%s', NULL, %i)", name, overwrite);
    SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
  }

  /* Clean up */
  SDL_free(value1);
  SDL_free(value2);
    
  return TEST_COMPLETED;
}
コード例 #20
0
ファイル: testautomation_video.c プロジェクト: Plombo/SDL
/**
 * @brief Tests the functionality of the SDL_CreateWindow function using different flags
 */
int
video_createWindowVariousFlags(void *arg)
{
  SDL_Window* window;
  const char* title = "video_createWindowVariousFlags Test Window";
  int x, y, w, h;
  int fVariation;
  SDL_WindowFlags flags;
  
  /* Standard window */
  x = SDLTest_RandomIntegerInRange(1, 100);
  y = SDLTest_RandomIntegerInRange(1, 100);
  w = SDLTest_RandomIntegerInRange(320, 1024);
  h = SDLTest_RandomIntegerInRange(320, 768);

  for (fVariation = 0; fVariation < 13; fVariation++) {
    switch(fVariation) {
     case 0:
      flags = SDL_WINDOW_FULLSCREEN;
      /* Skip - blanks screen; comment out next line to run test */
      continue;   
      break;
     case 1:
      flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
      /* Skip - blanks screen; comment out next line to run test */
      continue;  
      break;
     case 2:
      flags = SDL_WINDOW_OPENGL;
      break;  
     case 3:
      flags = SDL_WINDOW_SHOWN;
      break;   
     case 4:    
      flags = SDL_WINDOW_HIDDEN;
      break;     
     case 5:
      flags = SDL_WINDOW_BORDERLESS;
      break;       
     case 6:
      flags = SDL_WINDOW_RESIZABLE;
      break;         
     case 7:
      flags = SDL_WINDOW_MINIMIZED;
      break;           
     case 8:
      flags = SDL_WINDOW_MAXIMIZED;
      break;
     case 9: 
      flags = SDL_WINDOW_INPUT_GRABBED;
      break;
     case 10:              
      flags = SDL_WINDOW_INPUT_FOCUS;
      break;                 
     case 11:                      
      flags = SDL_WINDOW_MOUSE_FOCUS;
      break;
     case 12: 
      flags = SDL_WINDOW_FOREIGN;
      break;
    }
       
    window = SDL_CreateWindow(title, x, y, w, h, flags);
    SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags);
    SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
    if (window != NULL) {
      SDL_DestroyWindow(window);
      SDLTest_AssertPass("Call to SDL_DestroyWindow");
    }   
  }

  return TEST_COMPLETED;
}
コード例 #21
0
/**
 * @brief Call to SDL_CalculateGammaRamp
 *
 * @sa http://wiki.libsdl.org/moin.fcg/SDL_CalculateGammaRamp
 */
int
pixels_calcGammaRamp(void *arg)
{
  const char *expectedError1 = "Parameter 'gamma' is invalid";
  const char *expectedError2 = "Parameter 'ramp' is invalid";
  const char *error;
  float gamma;
  Uint16 *ramp;
  int variation;
  int i;
  int changed;
  Uint16 magic = 0xbeef;

  /* Allocate temp ramp array and fill with some value */
  ramp = (Uint16 *)SDL_malloc(256 * sizeof(Uint16));
  SDLTest_AssertCheck(ramp != NULL, "Validate temp ramp array could be allocated");
  if (ramp == NULL) return TEST_ABORTED;

  /* Make call with different gamma values */
  for (variation = 0; variation < 4; variation++) {
    switch (variation) {
      /* gamma = 0 all black */
      case 0:
        gamma = 0.0f;
        break;
      /* gamma = 1 identity */
      case 1:
        gamma = 1.0f;
        break;
      /* gamma = [0.2,0.8] normal range */
      case 2:
        gamma = 0.2f + 0.8f * SDLTest_RandomUnitFloat();
        break;
      /* gamma = >1.1 non-standard range */
      case 3:
        gamma = 1.1f + SDLTest_RandomUnitFloat();
        break;
    }

    /* Make call and check that values were updated */
    for (i = 0; i < 256; i++) ramp[i] = magic;
    SDL_CalculateGammaRamp(gamma, ramp);
    SDLTest_AssertPass("Call to SDL_CalculateGammaRamp(%f)", gamma);
    changed = 0;
    for (i = 0; i < 256; i++) if (ramp[i] != magic) changed++;
    SDLTest_AssertCheck(changed > 250, "Validate that ramp was calculated; expected: >250 values changed, got: %d values changed", changed);

    /* Additional value checks for some cases */
    i = SDLTest_RandomIntegerInRange(64,192);
    switch (variation) {
      case 0:
        SDLTest_AssertCheck(ramp[i] == 0, "Validate value at position %d; expected: 0, got: %d", i, ramp[i]);
        break;
      case 1:
        SDLTest_AssertCheck(ramp[i] == ((i << 8) | i), "Validate value at position %d; expected: %d, got: %d", i, (i << 8) | i, ramp[i]);
        break;
      case 2:
      case 3:
        SDLTest_AssertCheck(ramp[i] > 0, "Validate value at position %d; expected: >0, got: %d", i, ramp[i]);
        break;
    }
  }

  /* Negative cases */
  SDL_ClearError();
  SDLTest_AssertPass("Call to SDL_ClearError()");
  gamma = -1;
  for (i=0; i<256; i++) ramp[i] = magic;
  SDL_CalculateGammaRamp(gamma, ramp);
  SDLTest_AssertPass("Call to SDL_CalculateGammaRamp(%f)", gamma);
  error = SDL_GetError();
  SDLTest_AssertPass("Call to SDL_GetError()");
  SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
  if (error != NULL) {
      SDLTest_AssertCheck(SDL_strcmp(error, expectedError1) == 0,
          "Validate error message, expected: '%s', got: '%s'", expectedError1, error);
  }
  changed = 0;
  for (i = 0; i < 256; i++) if (ramp[i] != magic) changed++;
  SDLTest_AssertCheck(changed ==0, "Validate that ramp unchanged; expected: 0 values changed got: %d values changed", changed);

  SDL_CalculateGammaRamp(0.5f, NULL);
  SDLTest_AssertPass("Call to SDL_CalculateGammaRamp(0.5,NULL)");
  error = SDL_GetError();
  SDLTest_AssertPass("Call to SDL_GetError()");
  SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
  if (error != NULL) {
      SDLTest_AssertCheck(SDL_strcmp(error, expectedError2) == 0,
          "Validate error message, expected: '%s', got: '%s'", expectedError2, error);
  }

  /* Cleanup */
  SDL_free(ramp);


  return TEST_COMPLETED;
}
コード例 #22
0
/**
 * @brief Makes sure parameters work properly. Local helper function.
 *
 * \sa
 * http://wiki.libsdl.org/moin.cgi/SDL_RWseek
 * http://wiki.libsdl.org/moin.cgi/SDL_RWread
 */
void
_testGenericRWopsValidations(SDL_RWops *rw, int write)
{
   char buf[sizeof(RWopsHelloWorldTestString)];
   Sint64 i;
   size_t s;
   int seekPos = SDLTest_RandomIntegerInRange(4, 8);

   /* Clear buffer */
   SDL_zero(buf);

   /* Set to start. */
   i = SDL_RWseek(rw, 0, RW_SEEK_SET );
   SDLTest_AssertPass("Call to SDL_RWseek succeeded");
   SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %i", i);

   /* Test write. */
   s = SDL_RWwrite(rw, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1, 1);
   SDLTest_AssertPass("Call to SDL_RWwrite succeeded");
   if (write) {
        SDLTest_AssertCheck(s == (size_t)1, "Verify result of writing one byte with SDL_RWwrite, expected 1, got %i", s);
   }
   else {
        SDLTest_AssertCheck(s == (size_t)0, "Verify result of writing with SDL_RWwrite, expected: 0, got %i", s);
   }

   /* Test seek to random position */
   i = SDL_RWseek( rw, seekPos, RW_SEEK_SET );
   SDLTest_AssertPass("Call to SDL_RWseek succeeded");
   SDLTest_AssertCheck(i == (Sint64)seekPos, "Verify seek to %i with SDL_RWseek (RW_SEEK_SET), expected %i, got %i", seekPos, seekPos, i);

   /* Test seek back to start */
   i = SDL_RWseek(rw, 0, RW_SEEK_SET );
   SDLTest_AssertPass("Call to SDL_RWseek succeeded");
   SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %i", i);

   /* Test read */
   s = SDL_RWread( rw, buf, 1, sizeof(RWopsHelloWorldTestString)-1 );
   SDLTest_AssertPass("Call to SDL_RWread succeeded");
   SDLTest_AssertCheck(
       s == (size_t)(sizeof(RWopsHelloWorldTestString)-1),
       "Verify result from SDL_RWread, expected %i, got %i",
       sizeof(RWopsHelloWorldTestString)-1,
       s);
   SDLTest_AssertCheck(
       SDL_memcmp(buf, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1 ) == 0,
       "Verify read bytes match expected string, expected '%s', got '%s'", RWopsHelloWorldTestString, buf);

   /* More seek tests. */
   i = SDL_RWseek( rw, -4, RW_SEEK_CUR );
   SDLTest_AssertPass("Call to SDL_RWseek(...,-4,RW_SEEK_CUR) succeeded");
   SDLTest_AssertCheck(
       i == (Sint64)(sizeof(RWopsHelloWorldTestString)-5),
       "Verify seek to -4 with SDL_RWseek (RW_SEEK_CUR), expected %i, got %i",
       sizeof(RWopsHelloWorldTestString)-5,
       i);

   i = SDL_RWseek( rw, -1, RW_SEEK_END );
   SDLTest_AssertPass("Call to SDL_RWseek(...,-1,RW_SEEK_END) succeeded");
   SDLTest_AssertCheck(
       i == (Sint64)(sizeof(RWopsHelloWorldTestString)-2),
       "Verify seek to -1 with SDL_RWseek (RW_SEEK_END), expected %i, got %i",
       sizeof(RWopsHelloWorldTestString)-2,
       i);

   /* Invalid whence seek */
   i = SDL_RWseek( rw, 0, 999 );
   SDLTest_AssertPass("Call to SDL_RWseek(...,0,invalid_whence) succeeded");
   SDLTest_AssertCheck(
       i == (Sint64)(-1),
       "Verify seek with SDL_RWseek (invalid_whence); expected: -1, got %i",
       i);
}
コード例 #23
0
/**
 * @brief Call to SDL_AllocPalette and SDL_FreePalette
 *
 * @sa http://wiki.libsdl.org/moin.fcg/SDL_AllocPalette
 * @sa http://wiki.libsdl.org/moin.fcg/SDL_FreePalette
 */
int
pixels_allocFreePalette(void *arg)
{
  const char *expectedError1 = "Parameter 'ncolors' is invalid";
  const char *expectedError2 = "Parameter 'palette' is invalid";
  const char *error;
  int variation;
  int i;
  int ncolors;
  SDL_Palette* result;

  /* Allocate palette */
  for (variation = 1; variation <= 3; variation++) {
    switch (variation) {
      /* Just one color */
      case 1:
        ncolors = 1;
        break;
      /* Two colors */
      case 2:
        ncolors = 2;
        break;
      /* More than two colors */
      case 3:
        ncolors = SDLTest_RandomIntegerInRange(8, 16);
        break;
    }

    result = SDL_AllocPalette(ncolors);
    SDLTest_AssertPass("Call to SDL_AllocPalette(%d)", ncolors);
    SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
    if (result != NULL) {
      SDLTest_AssertCheck(result->ncolors == ncolors, "Verify value of result.ncolors; expected: %u, got %u", ncolors, result->ncolors);
      if (result->ncolors > 0) {
        SDLTest_AssertCheck(result->colors != NULL, "Verify value of result.colors is not NULL");
        if (result->colors != NULL) {
          for(i = 0; i < result->ncolors; i++) {
            SDLTest_AssertCheck(result->colors[i].r == 255, "Verify value of result.colors[%d].r; expected: 255, got %u", i, result->colors[i].r);
            SDLTest_AssertCheck(result->colors[i].g == 255, "Verify value of result.colors[%d].g; expected: 255, got %u", i, result->colors[i].g);
            SDLTest_AssertCheck(result->colors[i].b == 255, "Verify value of result.colors[%d].b; expected: 255, got %u", i, result->colors[i].b);
           }
         }
      }

      /* Deallocate again */
      SDL_FreePalette(result);
      SDLTest_AssertPass("Call to SDL_FreePalette()");
    }
  }

  /* Negative cases */

  /* Invalid number of colors */
  for (ncolors = 0; ncolors > -3; ncolors--) {
    SDL_ClearError();
    SDLTest_AssertPass("Call to SDL_ClearError()");
    result = SDL_AllocPalette(ncolors);
    SDLTest_AssertPass("Call to SDL_AllocPalette(%d)", ncolors);
    SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
    error = SDL_GetError();
    SDLTest_AssertPass("Call to SDL_GetError()");
    SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
    if (error != NULL) {
      SDLTest_AssertCheck(SDL_strcmp(error, expectedError1) == 0,
          "Validate error message, expected: '%s', got: '%s'", expectedError1, error);
    }
  }

  /* Invalid free pointer */
  SDL_ClearError();
  SDLTest_AssertPass("Call to SDL_ClearError()");
  SDL_FreePalette(NULL);
  SDLTest_AssertPass("Call to SDL_FreePalette(NULL)");
  error = SDL_GetError();
  SDLTest_AssertPass("Call to SDL_GetError()");
  SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
  if (error != NULL) {
      SDLTest_AssertCheck(SDL_strcmp(error, expectedError2) == 0,
          "Validate error message, expected: '%s', got: '%s'", expectedError2, error);
  }

  return TEST_COMPLETED;
}