Ejemplo n.º 1
0
/**
 * @brief Tests opening from memory.
 *
 * \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromMem
 * \sa http://wiki.libsdl.org/moin.cgi/SDL_RWClose
 */
int
rwops_testMem (void)
{
   char mem[sizeof(RWopsHelloWorldTestString)];
   SDL_RWops *rw;
   int result;

   /* Clear buffer */
   SDL_zero(mem);

   /* Open */
   rw = SDL_RWFromMem(mem, sizeof(RWopsHelloWorldTestString)-1);
   SDLTest_AssertPass("Call to SDL_RWFromMem() succeeded");
   SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromMem does not return NULL");

   /* Bail out if NULL */
   if (rw == NULL) return TEST_ABORTED;

   /* Check type */
   SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY, "Verify RWops type is SDL_RWOPS_MEMORY; expected: %d, got: %d", SDL_RWOPS_MEMORY, rw->type);

   /* Run generic tests */
   _testGenericRWopsValidations(rw, 1);

   /* Close */
   result = SDL_RWclose(rw);
   SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);

   return TEST_COMPLETED;
}
Ejemplo n.º 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;
}
Ejemplo n.º 3
0
/**
 * \brief Checks available audio driver names.
 *
 * \sa https://wiki.libsdl.org/SDL_GetNumAudioDrivers
 * \sa https://wiki.libsdl.org/SDL_GetAudioDriver
 */
int audio_printAudioDrivers()
{
   int i, n;
   const char *name;

   /* Get number of drivers */
   n = SDL_GetNumAudioDrivers();
   SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
   SDLTest_AssertCheck(n>=0, "Verify number of audio drivers >= 0, got: %i", n);

   /* List drivers. */
   if (n>0)
   {
      for (i=0; i<n; i++) {
         name = SDL_GetAudioDriver(i);
         SDLTest_AssertPass("Call to SDL_GetAudioDriver(%i)", i);
         SDLTest_AssertCheck(name != NULL, "Verify returned name is not NULL");
         if (name != NULL) {
            SDLTest_AssertCheck(name[0] != '\0', "Verify returned name is not empty, got: '%s'", name);
         }
      }
   }

   return TEST_COMPLETED;
}
Ejemplo n.º 4
0
/**
 * @brief Check call to SDL_SetTextInputRect with invalid data
 * 
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_SetTextInputRect
 */
int
keyboard_setTextInputRectNegative(void *arg)
{      
   /* Some platforms set also an error message; prepare for checking it */
#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_COCOA  
   const char *expectedError = "Parameter 'rect' is invalid";
   const char *error;
   
   SDL_ClearError();
   SDLTest_AssertPass("Call to SDL_ClearError()");
#endif
   
   /* NULL refRect */
   SDL_SetTextInputRect(NULL);
   SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");

   /* Some platforms set also an error message; so check it */
#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_COCOA  
   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, expectedError) == 0, 
          "Validate error message, expected: '%s', got: '%s'", expectedError, error);
   }

   SDL_ClearError();
   SDLTest_AssertPass("Call to SDL_ClearError()");
#endif
      
   return TEST_COMPLETED;
}
Ejemplo n.º 5
0
/**
 * @brief Call to SDL_GetWindowWMInfo
 */
int
syswm_getWindowWMInfo(void *arg)
{
  SDL_bool result;
  SDL_Window *window; 
  SDL_SysWMinfo info;
  
  window = SDL_CreateWindow("", 0, 0, 0, 0, SDL_WINDOW_HIDDEN);
  SDLTest_AssertPass("Call to SDL_CreateWindow()");
  SDLTest_AssertCheck(window != NULL, "Check that value returned from SDL_CreateWindow is not NULL");
  if (window == NULL) {
     return TEST_ABORTED;
  }
  
  /* Initialize info structure with SDL version info */
  SDL_VERSION(&info.version); 
  
  /* Make call */
  result = SDL_GetWindowWMInfo(window, &info);
  SDLTest_AssertPass("Call to SDL_GetWindowWMInfo");
  SDLTest_Log((result == SDL_TRUE) ? "Got window information" : "Couldn't get window information");
                                                                                                      		
  SDL_DestroyWindow(window);
  SDLTest_AssertPass("Call to SDL_DestroyWindow()");
  
  return TEST_COMPLETED;
}
Ejemplo n.º 6
0
/**
 * @brief Check call to SDL_SetCursor
 *
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_SetCursor
 */
int
mouse_setCursor(void *arg)
{
    SDL_Cursor *cursor;

    /* Create a cursor */
    cursor = _initArrowCursor(_mouseArrowData);
        SDLTest_AssertPass("Call to SDL_CreateCursor()");
        SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL");
    if (cursor == NULL) {
        return TEST_ABORTED;
    }

    /* Set the arrow cursor */
    SDL_SetCursor(cursor);
    SDLTest_AssertPass("Call to SDL_SetCursor(cursor)");

    /* Force redraw */
    SDL_SetCursor(NULL);
    SDLTest_AssertPass("Call to SDL_SetCursor(NULL)");

    /* Free cursor again */
    SDL_FreeCursor(cursor);
    SDLTest_AssertPass("Call to SDL_FreeCursor()");

    return TEST_COMPLETED;
}
Ejemplo n.º 7
0
/**
 * @brief Check call to SDL_CreateColorCursor and SDL_FreeCursor
 *
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_CreateColorCursor
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_FreeCursor
 */
int
mouse_createFreeColorCursor(void *arg)
{
    SDL_Surface *face;
    SDL_Cursor *cursor;

    /* Get sample surface */
    face = SDLTest_ImageFace();
    SDLTest_AssertCheck(face != NULL, "Validate sample input image is not NULL");
    if (face == NULL) return TEST_ABORTED;

    /* Create a color cursor from surface */
    cursor = SDL_CreateColorCursor(face, 0, 0);
        SDLTest_AssertPass("Call to SDL_CreateColorCursor()");
        SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateColorCursor() is not NULL");
    if (cursor == NULL) {
        SDL_FreeSurface(face);
        return TEST_ABORTED;
    }

    /* Free cursor again */
    SDL_FreeCursor(cursor);
    SDLTest_AssertPass("Call to SDL_FreeCursor()");

    /* Clean up */
    SDL_FreeSurface(face);

    return TEST_COMPLETED;
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
0
/**
 * @brief Tests opening from memory.
 *
 * \sa
 * http://wiki.libsdl.org/moin.cgi/SDL_RWFromConstMem
 * http://wiki.libsdl.org/moin.cgi/SDL_RWClose
 */
int
rwops_testConstMem (void)
{
   SDL_RWops *rw;
   int result;

   /* Open handle */
   rw = SDL_RWFromConstMem( RWopsHelloWorldCompString, sizeof(RWopsHelloWorldCompString)-1 );
   SDLTest_AssertPass("Call to SDL_RWFromConstMem() succeeded");
   SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromConstMem does not return NULL");

   /* Bail out if NULL */
   if (rw == NULL) return TEST_ABORTED;

   /* Check type */
   SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY_RO, "Verify RWops type is SDL_RWOPS_MEMORY_RO; expected: %d, got: %d", SDL_RWOPS_MEMORY_RO, rw->type);

   /* Run generic tests */
   _testGenericRWopsValidations( rw, 0 );

   /* Close handle */
   result = SDL_RWclose(rw);
   SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);

  return TEST_COMPLETED;
}
Ejemplo n.º 10
0
/*!
 * Negative test for SDL_RWFromFile parameters
 *
 * \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
 *
 */
int
rwops_testParamNegative (void)
{
   SDL_RWops *rwops;

   /* These should all fail. */
   rwops = SDL_RWFromFile(NULL, NULL);
   SDLTest_AssertPass("Call to SDL_RWFromFile(NULL, NULL) succeeded");
   SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(NULL, NULL) returns NULL");

   rwops = SDL_RWFromFile(NULL, "ab+");
   SDLTest_AssertPass("Call to SDL_RWFromFile(NULL, \"ab+\") succeeded");
   SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(NULL, \"ab+\") returns NULL");

   rwops = SDL_RWFromFile(NULL, "sldfkjsldkfj");
   SDLTest_AssertPass("Call to SDL_RWFromFile(NULL, \"sldfkjsldkfj\") succeeded");
   SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(NULL, \"sldfkjsldkfj\") returns NULL");

   rwops = SDL_RWFromFile("something", "");
   SDLTest_AssertPass("Call to SDL_RWFromFile(\"something\", \"\") succeeded");
   SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(\"something\", \"\") returns NULL");

   rwops = SDL_RWFromFile("something", NULL);
   SDLTest_AssertPass("Call to SDL_RWFromFile(\"something\", NULL) succeeded");
   SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(\"something\", NULL) returns NULL");

   return TEST_COMPLETED;
}
Ejemplo n.º 11
0
/**
 * @brief Tests opening from memory.
 *
 * \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromMem
 * http://wiki.libsdl.org/moin.cgi/SDL_RWClose
 */
int
rwops_testMem (void)
{
   char mem[sizeof(RWopsHelloWorldTestString)];
   SDL_RWops *rw;

   /* Clear buffer */
   SDL_zero(mem);

   /* Open */
   rw = SDL_RWFromMem(mem, sizeof(RWopsHelloWorldTestString)-1);
   SDLTest_AssertPass("Call to SDL_RWFromMem() succeeded");
   SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromMem does not return NULL");

   /* Bail out if NULL */
   if (rw == NULL) return TEST_ABORTED;

   /* Run generic tests */
   _testGenericRWopsValidations(rw, 1);

   /* Close */
   SDL_RWclose(rw);
   SDLTest_AssertPass("Call to SDL_RWclose() succeeded");

   return TEST_COMPLETED;
}
/**
 * @brief Test pumping and peeking events.
 *
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_PumpEvents
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_PollEvent
 */
int
events_pushPumpAndPollUserevent(void *arg)
{
   SDL_Event event1;
   SDL_Event event2;
   int result;

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

   /* Push a user event onto the queue and force queue update */
   SDL_PushEvent(&event1);
   SDLTest_AssertPass("Call to SDL_PushEvent()");
   SDL_PumpEvents();
   SDLTest_AssertPass("Call to SDL_PumpEvents()");

   /* Poll for user event */
   result = SDL_PollEvent(&event2);
   SDLTest_AssertPass("Call to SDL_PollEvent()");
   SDLTest_AssertCheck(result == 1, "Check result from SDL_PollEvent, expected: 1, got: %d", result);

   return TEST_COMPLETED;
}
Ejemplo n.º 13
0
int
stdlib_sscanf(void *arg)
{
  int output;
  int result;
  int expected_output;
  int expected_result;

  expected_output = output = 123;
  expected_result = -1;
  result = SDL_sscanf("", "%i", &output);
  SDLTest_AssertPass("Call to SDL_sscanf(\"\", \"%%i\", &output)");
  SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
  SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);

  expected_output = output = 123;
  expected_result = 0;
  result = SDL_sscanf("a", "%i", &output);
  SDLTest_AssertPass("Call to SDL_sscanf(\"a\", \"%%i\", &output)");
  SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
  SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);

  output = 123;
  expected_output = 2;
  expected_result = 1;
  result = SDL_sscanf("2", "%i", &output);
  SDLTest_AssertPass("Call to SDL_sscanf(\"2\", \"%%i\", &output)");
  SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
  SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);

  return TEST_COMPLETED;
}
Ejemplo n.º 14
0
/**
 * @brief Check call to SDL_GetKeyFromScancode
 * 
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyFromScancode
 */
int
keyboard_getKeyFromScancode(void *arg)
{
   SDL_Keycode result;

   /* Case where input is valid */
   result = SDL_GetKeyFromScancode(SDL_SCANCODE_A);
   SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(valid)");
   SDLTest_AssertCheck(result == SDLK_a, "Verify result from call, expected: %i, got: %i", SDLK_a, result);

   /* Case where input is zero */
   result = SDL_GetKeyFromScancode(0);
   SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(0)");
   SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);

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

   /* Case where input is invalid (too small) */
   result = SDL_GetKeyFromScancode(-999);
   SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(-999)");
   SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
   _checkInvalidScancodeError();

   /* Case where input is invalid (too big) */
   result = SDL_GetKeyFromScancode(999);
   SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(999)");
   SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
   _checkInvalidScancodeError();

   return TEST_COMPLETED;
}
Ejemplo n.º 15
0
/**
 * @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;
}
Ejemplo n.º 16
0
/**
 * @brief Tests writing to file handle
 *
 * \sa
 * http://wiki.libsdl.org/moin.cgi/SDL_RWFromFP
 * http://wiki.libsdl.org/moin.cgi/SDL_RWClose
 *
 */
int
rwops_testFPWrite(void)
{
   FILE *fp;
   SDL_RWops *rw;

   /* Run write tests. */
   fp = fopen(RWopsWriteTestFilename, "w+");
   SDLTest_AssertCheck(fp != NULL, "Verify handle from opening file '%s' in write mode is not NULL", RWopsWriteTestFilename);

   /* Bail out if NULL */
   if (fp == NULL) return TEST_ABORTED;

   /* Open */
   rw = SDL_RWFromFP( fp, SDL_TRUE );
   SDLTest_AssertPass("Call to SDL_RWFromFP() succeeded");
   SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFP in write mode does not return NULL");

   /* Bail out if NULL */
   if (rw == NULL) {
     fclose(fp);
     return TEST_ABORTED;
   }

   /* Run generic tests */
   _testGenericRWopsValidations( rw, 1 );

   /* Close handle - does fclose() */
   SDL_RWclose(rw);
   SDLTest_AssertPass("Call to SDL_RWclose() succeeded");

   return TEST_COMPLETED;
}
Ejemplo n.º 17
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;
}
Ejemplo n.º 18
0
/**
 * @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;
}
Ejemplo n.º 19
0
/**
 * \brief Opens, checks current connected status, and closes a device.
 *
 * \sa https://wiki.libsdl.org/SDL_AudioDeviceConnected
 */
int audio_openCloseAudioDeviceConnected()
{
   int result = -1;
   int i;
   int count;
   char *device;
   SDL_AudioDeviceID id;
   SDL_AudioSpec desired, obtained;

   /* Get number of devices. */
   count = SDL_GetNumAudioDevices(0);
   SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
   if (count > 0) {
     for (i = 0; i < count; i++) {
       /* Get device name */
       device = (char *)SDL_GetAudioDeviceName(i, 0);
       SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
       SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
       if (device == NULL) return TEST_ABORTED;

       /* Set standard desired spec */
       desired.freq=22050;
       desired.format=AUDIO_S16SYS;
       desired.channels=2;
       desired.samples=4096;
       desired.callback=_audio_testCallback;
       desired.userdata=NULL;

       /* Open device */
       id = SDL_OpenAudioDevice((const char *)device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
       SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
       SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >1, got: %i", id);
       if (id > 1) {

/* TODO: enable test code when function is available in SDL2 */

#ifdef AUDIODEVICECONNECTED_DEFINED
         /* Get connected status */
         result = SDL_AudioDeviceConnected(id);
         SDLTest_AssertPass("Call to SDL_AudioDeviceConnected()");
#endif
         SDLTest_AssertCheck(result == 1, "Verify returned value; expected: 1; got: %i", result);

         /* Close device again */
         SDL_CloseAudioDevice(id);
         SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
       }
     }
   } else {
     SDLTest_Log("No devices to test with");
   }

   return TEST_COMPLETED;
}
Ejemplo n.º 20
0
/**
 * Helper that clears the test surface
 */
void _clearTestSurface()
{
    int ret;
    Uint32 color;

    /* Clear surface. */
    color = SDL_MapRGBA( testSurface->format, 0, 0, 0, 0);
    SDLTest_AssertPass("Call to SDL_MapRGBA()");
    ret = SDL_FillRect( testSurface, NULL, color);
    SDLTest_AssertPass("Call to SDL_FillRect()");
    SDLTest_AssertCheck(ret == 0, "Verify result from SDL_FillRect, expected: 0, got: %i", ret);
}
Ejemplo n.º 21
0
/**
 * \brief Opens, checks current audio status, and closes a device.
 *
 * \sa https://wiki.libsdl.org/SDL_GetAudioStatus
 */
int audio_openCloseAndGetAudioStatus()
{
   SDL_AudioStatus result;
   int i;
   int count;
   char *device;
   SDL_AudioDeviceID id;
   SDL_AudioSpec desired, obtained;

   /* Get number of devices. */
   count = SDL_GetNumAudioDevices(0);
   SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
   if (count > 0) {
     for (i = 0; i < count; i++) {
       /* Get device name */
       device = (char *)SDL_GetAudioDeviceName(i, 0);
       SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
       SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
       if (device == NULL) return TEST_ABORTED;

       /* Set standard desired spec */
       desired.freq=22050;
       desired.format=AUDIO_S16SYS;
       desired.channels=2;
       desired.samples=4096;
       desired.callback=_audio_testCallback;
       desired.userdata=NULL;

       /* Open device */
       id = SDL_OpenAudioDevice((const char *)device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
       SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
       SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >=2, got: %i", id);
       if (id > 1) {

         /* Check device audio status */
         result = SDL_GetAudioDeviceStatus(id);
         SDLTest_AssertPass("Call to SDL_GetAudioDeviceStatus()");
         SDLTest_AssertCheck(result == SDL_AUDIO_STOPPED || result == SDL_AUDIO_PLAYING || result == SDL_AUDIO_PAUSED,
            "Verify returned value; expected: STOPPED (%i) | PLAYING (%i) | PAUSED (%i), got: %i",
            SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED, result);

         /* Close device again */
         SDL_CloseAudioDevice(id);
         SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
       }
     }
   } else {
     SDLTest_Log("No devices to test with");
   }

   return TEST_COMPLETED;
}
Ejemplo n.º 22
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;
}
Ejemplo n.º 23
0
/*
 * Destroy renderer for tests
 */
void CleanupDestroyRenderer(void *arg)
{
  if (renderer != NULL) {
     SDL_DestroyRenderer(renderer);
     renderer = NULL;
     SDLTest_AssertPass("SDL_DestroyRenderer()");
  }

  if (window != NULL) {
     SDL_DestroyWindow(window);
     window = NULL;
     SDLTest_AssertPass("SDL_DestroyWindow");
  }
}
Ejemplo n.º 24
0
/**
 * @brief Compare memory and file reads
 *
 * \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromMem
 * \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
 */
int
rwops_testCompareRWFromMemWithRWFromFile(void)
{
   int slen = 26;
   char buffer_file[27];
   char buffer_mem[27];
   size_t rv_file;
   size_t rv_mem;
   Uint64 sv_file;
   Uint64 sv_mem;
   SDL_RWops* rwops_file;
   SDL_RWops* rwops_mem;
   int size;
   int result;


   for (size=5; size<10; size++)
   {
     /* Terminate buffer */
     buffer_file[slen] = 0;
     buffer_mem[slen] = 0;

     /* Read/seek from memory */
     rwops_mem = SDL_RWFromMem((void *)RWopsAlphabetString, slen);
     SDLTest_AssertPass("Call to SDL_RWFromMem()");
     rv_mem = SDL_RWread(rwops_mem, buffer_mem, size, 6);
     SDLTest_AssertPass("Call to SDL_RWread(mem, size=%d)", size);
     sv_mem = SDL_RWseek(rwops_mem, 0, SEEK_END);
     SDLTest_AssertPass("Call to SDL_RWseek(mem,SEEK_END)");
     result = SDL_RWclose(rwops_mem);
     SDLTest_AssertPass("Call to SDL_RWclose(mem)");
     SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);

     /* Read/see from file */
     rwops_file = SDL_RWFromFile(RWopsAlphabetFilename, "r");
     SDLTest_AssertPass("Call to SDL_RWFromFile()");
     rv_file = SDL_RWread(rwops_file, buffer_file, size, 6);
     SDLTest_AssertPass("Call to SDL_RWread(file, size=%d)", size);
     sv_file = SDL_RWseek(rwops_file, 0, SEEK_END);
     SDLTest_AssertPass("Call to SDL_RWseek(file,SEEK_END)");
     result = SDL_RWclose(rwops_file);
     SDLTest_AssertPass("Call to SDL_RWclose(file)");
     SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);

     /* Compare */
     SDLTest_AssertCheck(rv_mem == rv_file, "Verify returned read blocks matches for mem and file reads; got: rv_mem=%d rv_file=%d", rv_mem, rv_file);
     SDLTest_AssertCheck(sv_mem == sv_file, "Verify SEEK_END position matches for mem and file seeks; got: sv_mem=%llu sv_file=%llu", sv_mem, sv_file);
     SDLTest_AssertCheck(buffer_mem[slen] == 0, "Verify mem buffer termination; expected: 0, got: %d", buffer_mem[slen]);
     SDLTest_AssertCheck(buffer_file[slen] == 0, "Verify file buffer termination; expected: 0, got: %d", buffer_file[slen]);
     SDLTest_AssertCheck(
       SDL_strncmp(buffer_mem, RWopsAlphabetString, slen) == 0,
       "Verify mem buffer contain alphabet string; expected: %s, got: %s", RWopsAlphabetString, buffer_mem);
     SDLTest_AssertCheck(
       SDL_strncmp(buffer_file, RWopsAlphabetString, slen) == 0,
       "Verify file buffer contain alphabet string; expected: %s, got: %s", RWopsAlphabetString, buffer_file);
   }

   return TEST_COMPLETED;
}
Ejemplo n.º 25
0
/**
 * @brief Tests alloc and free RW context.
 *
 * \sa http://wiki.libsdl.org/moin.cgi/SDL_AllocRW
 * \sa http://wiki.libsdl.org/moin.cgi/SDL_FreeRW
 */
int
rwops_testAllocFree (void)
{
   /* Allocate context */
   SDL_RWops *rw = SDL_AllocRW();
   SDLTest_AssertPass("Call to SDL_AllocRW() succeeded");
   SDLTest_AssertCheck(rw != NULL, "Validate result from SDL_AllocRW() is not NULL");
   if (rw==NULL) return TEST_ABORTED;
          
   /* Free context again */
   SDL_FreeRW(rw);
   SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");

   return TEST_COMPLETED;
}
Ejemplo n.º 26
0
/* 
 * Local helper to check for the invalid scancode error message
 */
void
_checkInvalidNameError()
{
   const char *expectedError = "Parameter 'name' is invalid";
   const char *error;   
   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, expectedError) == 0, 
          "Validate error message, expected: '%s', got: '%s'", expectedError, error);
      SDL_ClearError();
      SDLTest_AssertPass("Call to SDL_ClearError()");
   }
}
Ejemplo n.º 27
0
void
RWopsSetUp(void *arg)
{
	int fileLen = SDL_strlen(RWopsHelloWorldTestString);
	FILE *handle;
	int writtenLen;
	int result;

	/* Clean up from previous runs (if any); ignore errors */
	remove(RWopsReadTestFilename);
	remove(RWopsWriteTestFilename);

	/* Create a test file */
	handle = fopen(RWopsReadTestFilename, "w");
	SDLTest_AssertCheck(handle != NULL, "Verify creation of file '%s' returned non NULL handle", RWopsReadTestFilename);
        if (handle == NULL) return;

	/* Write some known test into it */
	writtenLen = (int)fwrite(RWopsHelloWorldTestString, 1, fileLen, handle);
	SDLTest_AssertCheck(fileLen == writtenLen, "Verify number of written bytes, expected %i, got %i", fileLen, writtenLen);
	result = fclose(handle);
	SDLTest_AssertCheck(result == 0, "Verify result from fclose, expected 0, got %i", result);

	SDLTest_AssertPass("Creation of test file completed");
}
Ejemplo n.º 28
0
/*
 * Destroy test window
 */
void _destroyMouseSuiteTestWindow(SDL_Window *window)
{
  if (window != NULL) {
     SDL_DestroyWindow(window);
     window = NULL;
     SDLTest_AssertPass("SDL_DestroyWindow()");
  }
}
Ejemplo n.º 29
0
/**
 * @brief Check call to SDL_GetScancodeFromKey
 * 
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromKey
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
 */
int
keyboard_getScancodeFromKey(void *arg)
{      
   SDL_Scancode scancode;
   
   /* Regular key */
   scancode = SDL_GetScancodeFromKey(SDLK_4);
   SDLTest_AssertPass("Call to SDL_GetScancodeFromKey(SDLK_4)");
   SDLTest_AssertCheck(scancode == SDL_SCANCODE_4, "Validate return value from SDL_GetScancodeFromKey, expected: %i, got: %i", SDL_SCANCODE_4, scancode); 

   /* Virtual key */
   scancode = SDL_GetScancodeFromKey(SDLK_PLUS);
   SDLTest_AssertPass("Call to SDL_GetScancodeFromKey(SDLK_PLUS)");
   SDLTest_AssertCheck(scancode == 0, "Validate return value from SDL_GetScancodeFromKey, expected: 0, got: %i", scancode); 
        
   return TEST_COMPLETED;
}
Ejemplo n.º 30
0
/**
 * @brief Tests sprite saving and loading
 */
int
surface_testSaveLoadBitmap(void *arg)
{
    int ret;
    const char *sampleFilename = "testSaveLoadBitmap.bmp";
    SDL_Surface *face;
    SDL_Surface *rface;

    /* Create sample surface */
    face = SDLTest_ImageFace();
    SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
    if (face == NULL) return TEST_ABORTED;

    /* Delete test file; ignore errors */
    unlink(sampleFilename);

    /* Save a surface */
    ret = SDL_SaveBMP(face, sampleFilename);
    SDLTest_AssertPass("Call to SDL_SaveBMP()");
    SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SaveBMP, expected: 0, got: %i", ret);
    _AssertFileExist(sampleFilename);

    /* Load a surface */
    rface = SDL_LoadBMP(sampleFilename);
    SDLTest_AssertPass("Call to SDL_LoadBMP()");
    SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_LoadBMP is not NULL");
    if (rface != NULL) {
        SDLTest_AssertCheck(face->w == rface->w, "Verify width of loaded surface, expected: %i, got: %i", face->w, rface->w);
        SDLTest_AssertCheck(face->h == rface->h, "Verify height of loaded surface, expected: %i, got: %i", face->h, rface->h);
    }

    /* Delete test file; ignore errors */
    unlink(sampleFilename);

    /* Clean up */
    if (face != NULL) {
    SDL_FreeSurface(face);
    face = NULL;
    }
    if (rface != NULL) {
    SDL_FreeSurface(rface);
    rface = NULL;
    }

    return TEST_COMPLETED;
}