/*! * 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; }
/** * \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; }
/** * @brief Blits doing color tests. * * \sa * http://wiki.libsdl.org/moin.cgi/SDL_SetTextureColorMod * http://wiki.libsdl.org/moin.cgi/SDL_RenderCopy * http://wiki.libsdl.org/moin.cgi/SDL_DestroyTexture */ int render_testBlitColor (void *arg) { int ret; SDL_Rect rect; SDL_Texture *tface; SDL_Surface *referenceSurface = NULL; Uint32 tformat; int taccess, tw, th; int i, j, ni, nj; int checkFailCount1; int checkFailCount2; /* Create face surface. */ tface = _loadTestFace(); SDLTest_AssertCheck(tface != NULL, "Verify _loadTestFace() result"); if (tface == NULL) { return TEST_ABORTED; } /* Constant values. */ ret = SDL_QueryTexture(tface, &tformat, &taccess, &tw, &th); SDLTest_AssertCheck(ret == 0, "Verify result from SDL_QueryTexture, expected 0, got %i", ret); rect.w = tw; rect.h = th; ni = TESTRENDER_SCREEN_W - tw; nj = TESTRENDER_SCREEN_H - th; /* Test blitting with color mod. */ checkFailCount1 = 0; checkFailCount2 = 0; for (j=0; j <= nj; j+=4) { for (i=0; i <= ni; i+=4) { /* Set color mod. */ ret = SDL_SetTextureColorMod( tface, (255/nj)*j, (255/ni)*i, (255/nj)*j ); if (ret != 0) checkFailCount1++; /* Blitting. */ rect.x = i; rect.y = j; ret = SDL_RenderCopy(renderer, tface, NULL, &rect ); if (ret != 0) checkFailCount2++; } } SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i", checkFailCount1); SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount2); /* See if it's the same. */ referenceSurface = SDLTest_ImageBlitColor(); _compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE ); /* Clean up. */ SDL_DestroyTexture( tface ); SDL_FreeSurface(referenceSurface); referenceSurface = NULL; return TEST_COMPLETED; }
/** * \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; }
/** * \brief Locks and unlocks open audio device. * * \sa https://wiki.libsdl.org/SDL_LockAudioDevice * \sa https://wiki.libsdl.org/SDL_UnlockAudioDevice */ int audio_lockUnlockOpenAudioDevice() { 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) { /* Lock to protect callback */ SDL_LockAudioDevice(id); SDLTest_AssertPass("SDL_LockAudioDevice(%i)", id); /* Simulate callback processing */ SDL_Delay(10); SDLTest_Log("Simulate callback processing - delay"); /* Unlock again */ SDL_UnlockAudioDevice(id); SDLTest_AssertPass("SDL_UnlockAudioDevice(%i)", id); /* Close device again */ SDL_CloseAudioDevice(id); SDLTest_AssertPass("Call to SDL_CloseAudioDevice()"); } } } else { SDLTest_Log("No devices to test with"); } return TEST_COMPLETED; }
/** * \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; }
/** * @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; }
/** * \brief Checks current audio driver name with initialized audio. * * \sa https://wiki.libsdl.org/SDL_GetCurrentAudioDriver */ int audio_printCurrentAudioDriver() { /* Check current audio driver */ const char *name = SDL_GetCurrentAudioDriver(); SDLTest_AssertPass("Call to SDL_GetCurrentAudioDriver()"); 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; }
/** * @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; }
/** * \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; }
/* Test callback */ Uint32 _timerTestCallback(Uint32 interval, void *param) { _timerCallbackCalled = 1; if (_paramCheck != 0) { SDLTest_AssertCheck(param != NULL, "Check param pointer, expected: non-NULL, got: %s", (param != NULL) ? "non-NULL" : "NULL"); if (param != NULL) { SDLTest_AssertCheck(*(int *)param == _paramValue, "Check param value, expected: %i, got: %i", _paramValue, *(int *)param); } } return 0; }
/* Event filter that sets some flags and optionally checks userdata */ int _events_sampleNullEventFilter(void *userdata, SDL_Event *event) { _eventFilterCalled = 1; if (_userdataCheck != 0) { SDLTest_AssertCheck(userdata != NULL, "Check userdata pointer, expected: non-NULL, got: %s", (userdata != NULL) ? "non-NULL" : "NULL"); if (userdata != NULL) { SDLTest_AssertCheck(*(int *)userdata == _userdataValue, "Check userdata value, expected: %i, got: %i", _userdataValue, *(int *)userdata); } } return 0; }
void RWopsTearDown(void *arg) { int result; /* Remove the created files to clean up; ignore errors for write filename */ result = remove(RWopsReadTestFilename); SDLTest_AssertCheck(result == 0, "Verify result from remove(%s), expected 0, got %i", RWopsReadTestFilename, result); remove(RWopsWriteTestFilename); result = remove(RWopsAlphabetFilename); SDLTest_AssertCheck(result == 0, "Verify result from remove(%s), expected 0, got %i", RWopsAlphabetFilename, result); SDLTest_AssertPass("Cleanup of test files completed"); }
/** * @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; }
/* * 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()"); } }
/** * @brief Enable and disable screensaver while checking state */ int video_enableDisableScreensaver(void *arg) { SDL_bool initialResult; SDL_bool result; /* Get current state and proceed according to current state */ initialResult = SDL_IsScreenSaverEnabled(); SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()"); if (initialResult == SDL_TRUE) { /* Currently enabled: disable first, then enable again */ /* Disable screensaver and check */ SDL_DisableScreenSaver(); SDLTest_AssertPass("Call to SDL_DisableScreenSaver()"); result = SDL_IsScreenSaverEnabled(); SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()"); SDLTest_AssertCheck(result == SDL_FALSE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_FALSE, result); /* Enable screensaver and check */ SDL_EnableScreenSaver(); SDLTest_AssertPass("Call to SDL_EnableScreenSaver()"); result = SDL_IsScreenSaverEnabled(); SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()"); SDLTest_AssertCheck(result == SDL_TRUE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_TRUE, result); } else { /* Currently disabled: enable first, then disable again */ /* Enable screensaver and check */ SDL_EnableScreenSaver(); SDLTest_AssertPass("Call to SDL_EnableScreenSaver()"); result = SDL_IsScreenSaverEnabled(); SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()"); SDLTest_AssertCheck(result == SDL_TRUE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_TRUE, result); /* Disable screensaver and check */ SDL_DisableScreenSaver(); SDLTest_AssertPass("Call to SDL_DisableScreenSaver()"); result = SDL_IsScreenSaverEnabled(); SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()"); SDLTest_AssertCheck(result == SDL_FALSE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_FALSE, result); } return TEST_COMPLETED; }
/** * @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 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; }
/** * @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; }
/** * @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; }
/** * \brief Start and stop audio directly * * \sa https://wiki.libsdl.org/SDL_InitAudio * \sa https://wiki.libsdl.org/SDL_QuitAudio */ int audio_initQuitAudio() { int result; int i, iMax; const char* audioDriver; /* 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); /* 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); /* Call Quit */ SDL_AudioQuit(); SDLTest_AssertPass("Call to SDL_AudioQuit()"); } /* NULL driver specification */ audioDriver = NULL; /* Call Init */ result = SDL_AudioInit(audioDriver); SDLTest_AssertPass("Call to SDL_AudioInit(NULL)"); SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result); /* Call Quit */ SDL_AudioQuit(); SDLTest_AssertPass("Call to SDL_AudioQuit()"); /* Restart audio again */ _audioSetUp(NULL); return TEST_COMPLETED; }
/** * @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; }
/** * @brief Tests call to SDL_GetNumRenderDrivers * * \sa * http://wiki.libsdl.org/moin.cgi/SDL_GetNumRenderDrivers */ int render_testGetNumRenderDrivers(void *arg) { int n; n = SDL_GetNumRenderDrivers(); SDLTest_AssertCheck(n >= 1, "Number of renderers >= 1, reported as %i", n); return TEST_COMPLETED; }
/* Helper to check that a file exists */ void _AssertFileExist(const char *filename) { struct stat st; int ret = stat(filename, &st); SDLTest_AssertCheck(ret == 0, "Verify file '%s' exists", filename); }
/** * @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; }
/** * Creates a test window */ SDL_Window *_createMouseSuiteTestWindow() { int posX = 100, posY = 100, width = MOUSE_TESTWINDOW_WIDTH, height = MOUSE_TESTWINDOW_HEIGHT; SDL_Window *window; window = SDL_CreateWindow("mouse_createMouseSuiteTestWindow", posX, posY, width, height, 0); SDLTest_AssertPass("SDL_CreateWindow()"); SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result"); return window; }
/** * @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; }
/** * Create software renderer for tests */ void InitCreateRenderer(void *arg) { int posX = 100, posY = 100, width = 320, height = 240; renderer = NULL; window = SDL_CreateWindow("render_testCreateRenderer", posX, posY, width, height, 0); SDLTest_AssertPass("SDL_CreateWindow()"); SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result"); if (window == NULL) { return; } renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); SDLTest_AssertPass("SDL_CreateRenderer()"); SDLTest_AssertCheck(renderer != 0, "Check SDL_CreateRenderer result"); if (renderer == NULL) { SDL_DestroyWindow(window); return; } }
/* Helper that changes cursor visibility */ void _changeCursorVisibility(int state) { int oldState; int newState; int result; oldState = SDL_ShowCursor(SDL_QUERY); SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)"); result = SDL_ShowCursor(state); SDLTest_AssertPass("Call to SDL_ShowCursor(%s)", (state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE"); SDLTest_AssertCheck(result == oldState, "Validate result from SDL_ShowCursor(%s), expected: %i, got: %i", (state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE", oldState, result); newState = SDL_ShowCursor(SDL_QUERY); SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)"); SDLTest_AssertCheck(state == newState, "Validate new state, expected: %i, got: %i", state, newState); }
/** * @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; /* Check type */ SDLTest_AssertCheck( rw->type == SDL_RWOPS_UNKNOWN, "Verify RWops type is SDL_RWOPS_UNKNOWN; expected: %d, got: %d", SDL_RWOPS_UNKNOWN, rw->type); /* Free context again */ SDL_FreeRW(rw); SDLTest_AssertPass("Call to SDL_FreeRW() succeeded"); return TEST_COMPLETED; }