mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-01 19:44:40 +00:00
Cleanup add brace (#6545)
* Add braces after if conditions
* More add braces after if conditions
* Add braces after while() conditions
* Fix compilation because of macro being modified
* Add braces to for loop
* Add braces after if/goto
* Move comments up
* Remove extra () in the 'return ...;' statements
* More remove extra () in the 'return ...;' statements
* More remove extra () in the 'return ...;' statements after merge
* Fix inconsistent patterns are xxx == NULL vs !xxx
* More "{}" for "if() break;" and "if() continue;"
* More "{}" after if() short statement
* More "{}" after "if () return;" statement
* More fix inconsistent patterns are xxx == NULL vs !xxx
* Revert some modificaion on SDL_RLEaccel.c
* SDL_RLEaccel: no short statement
* Cleanup 'if' where the bracket is in a new line
* Cleanup 'while' where the bracket is in a new line
* Cleanup 'for' where the bracket is in a new line
* Cleanup 'else' where the bracket is in a new line
(cherry picked from commit 6a2200823c to reduce conflicts merging between SDL2 and SDL3)
This commit is contained in:
committed by
Sam Lantinga
parent
0739d237ad
commit
fb0ce375f0
@@ -68,30 +68,42 @@ print_modifiers(char **text, size_t *maxlen)
|
||||
print_string(text, maxlen, " (none)");
|
||||
return;
|
||||
}
|
||||
if (mod & KMOD_LSHIFT)
|
||||
if (mod & KMOD_LSHIFT) {
|
||||
print_string(text, maxlen, " LSHIFT");
|
||||
if (mod & KMOD_RSHIFT)
|
||||
}
|
||||
if (mod & KMOD_RSHIFT) {
|
||||
print_string(text, maxlen, " RSHIFT");
|
||||
if (mod & KMOD_LCTRL)
|
||||
}
|
||||
if (mod & KMOD_LCTRL) {
|
||||
print_string(text, maxlen, " LCTRL");
|
||||
if (mod & KMOD_RCTRL)
|
||||
}
|
||||
if (mod & KMOD_RCTRL) {
|
||||
print_string(text, maxlen, " RCTRL");
|
||||
if (mod & KMOD_LALT)
|
||||
}
|
||||
if (mod & KMOD_LALT) {
|
||||
print_string(text, maxlen, " LALT");
|
||||
if (mod & KMOD_RALT)
|
||||
}
|
||||
if (mod & KMOD_RALT) {
|
||||
print_string(text, maxlen, " RALT");
|
||||
if (mod & KMOD_LGUI)
|
||||
}
|
||||
if (mod & KMOD_LGUI) {
|
||||
print_string(text, maxlen, " LGUI");
|
||||
if (mod & KMOD_RGUI)
|
||||
}
|
||||
if (mod & KMOD_RGUI) {
|
||||
print_string(text, maxlen, " RGUI");
|
||||
if (mod & KMOD_NUM)
|
||||
}
|
||||
if (mod & KMOD_NUM) {
|
||||
print_string(text, maxlen, " NUM");
|
||||
if (mod & KMOD_CAPS)
|
||||
}
|
||||
if (mod & KMOD_CAPS) {
|
||||
print_string(text, maxlen, " CAPS");
|
||||
if (mod & KMOD_MODE)
|
||||
}
|
||||
if (mod & KMOD_MODE) {
|
||||
print_string(text, maxlen, " MODE");
|
||||
if (mod & KMOD_SCROLL)
|
||||
}
|
||||
if (mod & KMOD_SCROLL) {
|
||||
print_string(text, maxlen, " SCROLL");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -147,8 +159,7 @@ PrintText(const char *eventtype, const char *text)
|
||||
char expanded[1024];
|
||||
|
||||
expanded[0] = '\0';
|
||||
for ( spot = text; *spot; ++spot )
|
||||
{
|
||||
for ( spot = text; *spot; ++spot ) {
|
||||
size_t length = SDL_strlen(expanded);
|
||||
SDL_snprintf(expanded + length, sizeof(expanded) - length, "\\x%.2x", (unsigned char)*spot);
|
||||
}
|
||||
@@ -253,21 +264,21 @@ main(int argc, char *argv[])
|
||||
/* Initialize SDL */
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Set 640x480 video mode */
|
||||
window = SDL_CreateWindow("CheckKeys Test",
|
||||
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||
640, 480, 0);
|
||||
if (!window) {
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create 640x480 window: %s\n",
|
||||
SDL_GetError());
|
||||
quit(2);
|
||||
}
|
||||
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
if (!renderer) {
|
||||
if (renderer == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n",
|
||||
SDL_GetError());
|
||||
quit(2);
|
||||
@@ -298,7 +309,7 @@ main(int argc, char *argv[])
|
||||
#endif
|
||||
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -64,30 +64,42 @@ print_modifiers(char **text, size_t *maxlen)
|
||||
print_string(text, maxlen, " (none)");
|
||||
return;
|
||||
}
|
||||
if (mod & KMOD_LSHIFT)
|
||||
if (mod & KMOD_LSHIFT) {
|
||||
print_string(text, maxlen, " LSHIFT");
|
||||
if (mod & KMOD_RSHIFT)
|
||||
}
|
||||
if (mod & KMOD_RSHIFT) {
|
||||
print_string(text, maxlen, " RSHIFT");
|
||||
if (mod & KMOD_LCTRL)
|
||||
}
|
||||
if (mod & KMOD_LCTRL) {
|
||||
print_string(text, maxlen, " LCTRL");
|
||||
if (mod & KMOD_RCTRL)
|
||||
}
|
||||
if (mod & KMOD_RCTRL) {
|
||||
print_string(text, maxlen, " RCTRL");
|
||||
if (mod & KMOD_LALT)
|
||||
}
|
||||
if (mod & KMOD_LALT) {
|
||||
print_string(text, maxlen, " LALT");
|
||||
if (mod & KMOD_RALT)
|
||||
}
|
||||
if (mod & KMOD_RALT) {
|
||||
print_string(text, maxlen, " RALT");
|
||||
if (mod & KMOD_LGUI)
|
||||
}
|
||||
if (mod & KMOD_LGUI) {
|
||||
print_string(text, maxlen, " LGUI");
|
||||
if (mod & KMOD_RGUI)
|
||||
}
|
||||
if (mod & KMOD_RGUI) {
|
||||
print_string(text, maxlen, " RGUI");
|
||||
if (mod & KMOD_NUM)
|
||||
}
|
||||
if (mod & KMOD_NUM) {
|
||||
print_string(text, maxlen, " NUM");
|
||||
if (mod & KMOD_CAPS)
|
||||
}
|
||||
if (mod & KMOD_CAPS) {
|
||||
print_string(text, maxlen, " CAPS");
|
||||
if (mod & KMOD_MODE)
|
||||
}
|
||||
if (mod & KMOD_MODE) {
|
||||
print_string(text, maxlen, " MODE");
|
||||
if (mod & KMOD_SCROLL)
|
||||
}
|
||||
if (mod & KMOD_SCROLL) {
|
||||
print_string(text, maxlen, " SCROLL");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -144,8 +156,7 @@ PrintText(const char *eventtype, const char *text)
|
||||
char expanded[1024];
|
||||
|
||||
expanded[0] = '\0';
|
||||
for ( spot = text; *spot; ++spot )
|
||||
{
|
||||
for ( spot = text; *spot; ++spot ) {
|
||||
size_t length = SDL_strlen(expanded);
|
||||
SDL_snprintf(expanded + length, sizeof(expanded) - length, "\\x%.2x", (unsigned char)*spot);
|
||||
}
|
||||
@@ -235,14 +246,14 @@ main(int argc, char *argv[])
|
||||
/* Initialize SDL */
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Set 640x480 video mode */
|
||||
window = SDL_CreateWindow("CheckKeys Test",
|
||||
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||
640, 480, 0);
|
||||
if (!window) {
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create 640x480 window: %s\n",
|
||||
SDL_GetError());
|
||||
quit(2);
|
||||
@@ -280,7 +291,7 @@ main(int argc, char *argv[])
|
||||
|
||||
SDL_WaitThread(thread, NULL);
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -199,8 +199,7 @@ SetCurrentBinding(int iBinding)
|
||||
return;
|
||||
}
|
||||
|
||||
if (s_arrBindingOrder[iBinding] == -1)
|
||||
{
|
||||
if (s_arrBindingOrder[iBinding] == -1) {
|
||||
SetCurrentBinding(iBinding + 1);
|
||||
return;
|
||||
}
|
||||
@@ -227,8 +226,7 @@ SetCurrentBinding(int iBinding)
|
||||
static SDL_bool
|
||||
BBindingContainsBinding(const SDL_GameControllerExtendedBind *pBindingA, const SDL_GameControllerExtendedBind *pBindingB)
|
||||
{
|
||||
if (pBindingA->bindType != pBindingB->bindType)
|
||||
{
|
||||
if (pBindingA->bindType != pBindingB->bindType) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
switch (pBindingA->bindType)
|
||||
@@ -245,7 +243,7 @@ BBindingContainsBinding(const SDL_GameControllerExtendedBind *pBindingA, const S
|
||||
int maxA = SDL_max(pBindingA->value.axis.axis_min, pBindingA->value.axis.axis_max);
|
||||
int minB = SDL_min(pBindingB->value.axis.axis_min, pBindingB->value.axis.axis_max);
|
||||
int maxB = SDL_max(pBindingB->value.axis.axis_min, pBindingB->value.axis.axis_max);
|
||||
return (minA <= minB && maxA >= maxB);
|
||||
return minA <= minB && maxA >= maxB;
|
||||
}
|
||||
/* Not reached */
|
||||
default:
|
||||
|
||||
@@ -107,8 +107,9 @@ static int done = 0;
|
||||
void
|
||||
loop()
|
||||
{
|
||||
if(done || (SDL_GetAudioDeviceStatus(device) != SDL_AUDIO_PLAYING))
|
||||
if (done || (SDL_GetAudioDeviceStatus(device) != SDL_AUDIO_PLAYING)) {
|
||||
emscripten_cancel_main_loop();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -124,7 +125,7 @@ main(int argc, char *argv[])
|
||||
/* Load the SDL library */
|
||||
if (SDL_Init(SDL_INIT_AUDIO|SDL_INIT_EVENTS) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
filename = GetResourceFilename(argc > 1 ? argv[1] : NULL, "sample.wav");
|
||||
@@ -178,7 +179,7 @@ main(int argc, char *argv[])
|
||||
SDL_FreeWAV(wave.sound);
|
||||
SDL_free(filename);
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -56,8 +56,7 @@ loop()
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (done || (SDL_GetAudioStatus() != SDL_AUDIO_PLAYING)) {
|
||||
emscripten_cancel_main_loop();
|
||||
}
|
||||
else
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
/* The device from SDL_OpenAudio() is always device #1. */
|
||||
@@ -84,7 +83,7 @@ main(int argc, char *argv[])
|
||||
/* Load the SDL library */
|
||||
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
filename = GetResourceFilename(argc > 1 ? argv[1] : NULL, "sample.wav");
|
||||
@@ -135,8 +134,7 @@ main(int argc, char *argv[])
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING))
|
||||
{
|
||||
while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING)) {
|
||||
loop();
|
||||
|
||||
SDL_Delay(100); /* let it play for awhile. */
|
||||
|
||||
@@ -25,8 +25,7 @@ tf(SDL_bool _tf)
|
||||
static const char *t = "TRUE";
|
||||
static const char *f = "FALSE";
|
||||
|
||||
if (_tf)
|
||||
{
|
||||
if (_tf) {
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -142,11 +141,13 @@ void runAdder(void)
|
||||
|
||||
SDL_AtomicSet(&threadsRunning, NThreads);
|
||||
|
||||
while (T--)
|
||||
while (T--) {
|
||||
SDL_CreateThread(adder, "Adder", NULL);
|
||||
}
|
||||
|
||||
while (SDL_AtomicGet(&threadsRunning) > 0)
|
||||
while (SDL_AtomicGet(&threadsRunning) > 0) {
|
||||
SDL_SemWait(threadDone);
|
||||
}
|
||||
|
||||
SDL_DestroySemaphore(threadDone);
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ main(int argc, char **argv)
|
||||
/* Load the SDL library */
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
window = SDL_CreateWindow("testaudiocapture", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 320, 240, 0);
|
||||
|
||||
@@ -90,8 +90,9 @@ iteration()
|
||||
if (e.type == SDL_QUIT) {
|
||||
done = 1;
|
||||
} else if (e.type == SDL_KEYUP) {
|
||||
if (e.key.keysym.sym == SDLK_ESCAPE)
|
||||
if (e.key.keysym.sym == SDLK_ESCAPE) {
|
||||
done = 1;
|
||||
}
|
||||
} else if (e.type == SDL_AUDIODEVICEADDED) {
|
||||
int index = e.adevice.which;
|
||||
int iscapture = e.adevice.iscapture;
|
||||
@@ -127,7 +128,7 @@ iteration()
|
||||
void
|
||||
loop()
|
||||
{
|
||||
if(done)
|
||||
if (done)
|
||||
emscripten_cancel_main_loop();
|
||||
else
|
||||
iteration();
|
||||
@@ -146,7 +147,7 @@ main(int argc, char *argv[])
|
||||
/* Load the SDL library */
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Some targets (Mac CoreAudio) need an event queue for audio hotplug, so make and immediately hide a window. */
|
||||
@@ -201,7 +202,7 @@ main(int argc, char *argv[])
|
||||
SDL_FreeWAV(sound);
|
||||
SDL_free(filename);
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -57,7 +57,7 @@ main(int argc, char **argv)
|
||||
/* Load the SDL library */
|
||||
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Print available audio drivers */
|
||||
|
||||
@@ -42,7 +42,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -56,23 +56,22 @@ main(int argc, char *argv[])
|
||||
if (SDL_strcasecmp(argv[i], "--iterations") == 0) {
|
||||
if (argv[i + 1]) {
|
||||
testIterations = SDL_atoi(argv[i + 1]);
|
||||
if (testIterations < 1) testIterations = 1;
|
||||
if (testIterations < 1) {
|
||||
testIterations = 1;
|
||||
}
|
||||
consumed = 2;
|
||||
}
|
||||
}
|
||||
else if (SDL_strcasecmp(argv[i], "--execKey") == 0) {
|
||||
} else if (SDL_strcasecmp(argv[i], "--execKey") == 0) {
|
||||
if (argv[i + 1]) {
|
||||
SDL_sscanf(argv[i + 1], "%"SDL_PRIu64, &userExecKey);
|
||||
consumed = 2;
|
||||
}
|
||||
}
|
||||
else if (SDL_strcasecmp(argv[i], "--seed") == 0) {
|
||||
} else if (SDL_strcasecmp(argv[i], "--seed") == 0) {
|
||||
if (argv[i + 1]) {
|
||||
userRunSeed = SDL_strdup(argv[i + 1]);
|
||||
consumed = 2;
|
||||
}
|
||||
}
|
||||
else if (SDL_strcasecmp(argv[i], "--filter") == 0) {
|
||||
} else if (SDL_strcasecmp(argv[i], "--filter") == 0) {
|
||||
if (argv[i + 1]) {
|
||||
filter = SDL_strdup(argv[i + 1]);
|
||||
consumed = 2;
|
||||
@@ -105,7 +104,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Empty event queue */
|
||||
done = 0;
|
||||
for (i=0; i<100; i++) {
|
||||
for (i=0; i<100; i++) {
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
@@ -118,7 +117,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Shutdown everything */
|
||||
quit(result);
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -461,8 +461,7 @@ int audio_printAudioDrivers()
|
||||
SDLTest_AssertCheck(n>=0, "Verify number of audio drivers >= 0, got: %i", n);
|
||||
|
||||
/* List drivers. */
|
||||
if (n>0)
|
||||
{
|
||||
if (n>0) {
|
||||
for (i=0; i<n; i++) {
|
||||
name = SDL_GetAudioDriver(i);
|
||||
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%i)", i);
|
||||
@@ -712,7 +711,9 @@ int audio_openCloseAndGetAudioStatus()
|
||||
device = 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;
|
||||
if (device == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Set standard desired spec */
|
||||
desired.freq=22050;
|
||||
@@ -770,7 +771,9 @@ int audio_lockUnlockOpenAudioDevice()
|
||||
device = 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;
|
||||
if (device == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Set standard desired spec */
|
||||
desired.freq=22050;
|
||||
@@ -878,7 +881,9 @@ int audio_convertAudio()
|
||||
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;
|
||||
if (cvt.len_mult < 1) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Create some random data to convert */
|
||||
l = 64;
|
||||
@@ -887,7 +892,9 @@ int audio_convertAudio()
|
||||
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;
|
||||
if (cvt.buf == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Convert the data */
|
||||
result = SDL_ConvertAudio(&cvt);
|
||||
@@ -932,7 +939,9 @@ int audio_openCloseAudioDeviceConnected()
|
||||
device = 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;
|
||||
if (device == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Set standard desired spec */
|
||||
desired.freq=22050;
|
||||
|
||||
@@ -230,7 +230,9 @@ mouse_createFreeColorCursor(void *arg)
|
||||
/* Get sample surface */
|
||||
face = SDLTest_ImageFace();
|
||||
SDLTest_AssertCheck(face != NULL, "Validate sample input image is not NULL");
|
||||
if (face == NULL) return TEST_ABORTED;
|
||||
if (face == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Create a color cursor from surface */
|
||||
cursor = SDL_CreateColorCursor(face, 0, 0);
|
||||
@@ -466,7 +468,9 @@ mouse_warpMouseInWindow(void *arg)
|
||||
yPositions[5] = h+1;
|
||||
/* Create test window */
|
||||
window = _createMouseSuiteTestWindow();
|
||||
if (window == NULL) return TEST_ABORTED;
|
||||
if (window == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Mouse to random position inside window */
|
||||
x = SDLTest_RandomIntegerInRange(1, w-1);
|
||||
@@ -518,7 +522,9 @@ mouse_getMouseFocus(void *arg)
|
||||
|
||||
/* Create test window */
|
||||
window = _createMouseSuiteTestWindow();
|
||||
if (window == NULL) return TEST_ABORTED;
|
||||
if (window == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Mouse to random position inside window */
|
||||
x = SDLTest_RandomIntegerInRange(1, w-1);
|
||||
|
||||
@@ -352,7 +352,7 @@ pixels_allocFreePalette(void *arg)
|
||||
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++) {
|
||||
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);
|
||||
|
||||
@@ -305,8 +305,7 @@ int platform_testGetSetClearError(void *arg)
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError != NULL,
|
||||
"SDL_GetError() != NULL");
|
||||
if (lastError != NULL)
|
||||
{
|
||||
if (lastError != NULL) {
|
||||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == 0,
|
||||
"SDL_GetError(): no message expected, len: %i", (int) len);
|
||||
@@ -318,8 +317,7 @@ int platform_testGetSetClearError(void *arg)
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertCheck(lastError != NULL,
|
||||
"SDL_GetError() != NULL");
|
||||
if (lastError != NULL)
|
||||
{
|
||||
if (lastError != NULL) {
|
||||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == SDL_strlen(testError),
|
||||
"SDL_GetError(): expected message len %i, was len: %i",
|
||||
@@ -356,8 +354,7 @@ int platform_testSetErrorEmptyInput(void *arg)
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertCheck(lastError != NULL,
|
||||
"SDL_GetError() != NULL");
|
||||
if (lastError != NULL)
|
||||
{
|
||||
if (lastError != NULL) {
|
||||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == SDL_strlen(testError),
|
||||
"SDL_GetError(): expected message len %i, was len: %i",
|
||||
@@ -405,8 +402,7 @@ int platform_testSetErrorInvalidInput(void *arg)
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertCheck(lastError != NULL,
|
||||
"SDL_GetError() != NULL");
|
||||
if (lastError != NULL)
|
||||
{
|
||||
if (lastError != NULL) {
|
||||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == 0 || SDL_strcmp(lastError, "(null)") == 0,
|
||||
"SDL_GetError(): expected message len 0, was len: %i",
|
||||
@@ -425,8 +421,7 @@ int platform_testSetErrorInvalidInput(void *arg)
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertCheck(lastError != NULL,
|
||||
"SDL_GetError() != NULL");
|
||||
if (lastError != NULL)
|
||||
{
|
||||
if (lastError != NULL) {
|
||||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == 0 || SDL_strcmp( lastError, "(null)" ) == 0,
|
||||
"SDL_GetError(): expected message len 0, was len: %i",
|
||||
@@ -444,8 +439,7 @@ int platform_testSetErrorInvalidInput(void *arg)
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertCheck(lastError != NULL,
|
||||
"SDL_GetError() != NULL");
|
||||
if (lastError != NULL)
|
||||
{
|
||||
if (lastError != NULL) {
|
||||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == SDL_strlen(probeError),
|
||||
"SDL_GetError(): expected message len %i, was len: %i",
|
||||
@@ -493,8 +487,7 @@ int platform_testGetPowerInfo(void *arg)
|
||||
"SDL_GetPowerInfo(): state %i is one of the expected values",
|
||||
(int)state);
|
||||
|
||||
if (state==SDL_POWERSTATE_ON_BATTERY)
|
||||
{
|
||||
if (state==SDL_POWERSTATE_ON_BATTERY) {
|
||||
SDLTest_AssertCheck(
|
||||
secs >= 0,
|
||||
"SDL_GetPowerInfo(): on battery, secs >= 0, was: %i",
|
||||
|
||||
@@ -1009,10 +1009,18 @@ int rect_testEnclosePoints(void *arg)
|
||||
miny = newy;
|
||||
maxy = newy;
|
||||
} else {
|
||||
if (newx < minx) minx = newx;
|
||||
if (newx > maxx) maxx = newx;
|
||||
if (newy < miny) miny = newy;
|
||||
if (newy > maxy) maxy = newy;
|
||||
if (newx < minx) {
|
||||
minx = newx;
|
||||
}
|
||||
if (newx > maxx) {
|
||||
maxx = newx;
|
||||
}
|
||||
if (newy < miny) {
|
||||
miny = newy;
|
||||
}
|
||||
if (newy > maxy) {
|
||||
maxy = newy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1085,10 +1093,18 @@ int rect_testEnclosePointsRepeatedInput(void *arg)
|
||||
miny = newy;
|
||||
maxy = newy;
|
||||
} else {
|
||||
if (newx < minx) minx = newx;
|
||||
if (newx > maxx) maxx = newx;
|
||||
if (newy < miny) miny = newy;
|
||||
if (newy > maxy) maxy = newy;
|
||||
if (newx < minx) {
|
||||
minx = newx;
|
||||
}
|
||||
if (newx > maxx) {
|
||||
maxx = newx;
|
||||
}
|
||||
if (newy < miny) {
|
||||
miny = newy;
|
||||
}
|
||||
if (newy > maxy) {
|
||||
maxy = newy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1165,10 +1181,18 @@ int rect_testEnclosePointsWithClipping(void *arg)
|
||||
miny = newy;
|
||||
maxy = newy;
|
||||
} else {
|
||||
if (newx < minx) minx = newx;
|
||||
if (newx > maxx) maxx = newx;
|
||||
if (newy < miny) miny = newy;
|
||||
if (newy > maxy) maxy = newy;
|
||||
if (newx < minx) {
|
||||
minx = newx;
|
||||
}
|
||||
if (newx > maxx) {
|
||||
maxx = newx;
|
||||
}
|
||||
if (newy < miny) {
|
||||
miny = newy;
|
||||
}
|
||||
if (newy > maxy) {
|
||||
maxy = newy;
|
||||
}
|
||||
}
|
||||
expectedEnclosed = SDL_TRUE;
|
||||
}
|
||||
@@ -1305,10 +1329,18 @@ int rect_testUnionRectOutside(void *arg)
|
||||
refRectB.w=refRectA.w - 2;
|
||||
refRectB.h=refRectA.h - 2;
|
||||
expectedResult = refRectA;
|
||||
if (dx == -1) expectedResult.x--;
|
||||
if (dy == -1) expectedResult.y--;
|
||||
if ((dx == 1) || (dx == -1)) expectedResult.w++;
|
||||
if ((dy == 1) || (dy == -1)) expectedResult.h++;
|
||||
if (dx == -1) {
|
||||
expectedResult.x--;
|
||||
}
|
||||
if (dy == -1) {
|
||||
expectedResult.y--;
|
||||
}
|
||||
if ((dx == 1) || (dx == -1)) {
|
||||
expectedResult.w++;
|
||||
}
|
||||
if ((dy == 1) || (dy == -1)) {
|
||||
expectedResult.h++;
|
||||
}
|
||||
rectA = refRectA;
|
||||
rectB = refRectB;
|
||||
SDL_UnionRect(&rectA, &rectB, &result);
|
||||
@@ -1433,10 +1465,18 @@ int rect_testUnionRectInside(void *arg)
|
||||
refRectA.w=SDLTest_RandomIntegerInRange(256, 1024);
|
||||
refRectA.h=SDLTest_RandomIntegerInRange(256, 1024);
|
||||
refRectB = refRectA;
|
||||
if (dx == -1) refRectB.x++;
|
||||
if ((dx == 1) || (dx == -1)) refRectB.w--;
|
||||
if (dy == -1) refRectB.y++;
|
||||
if ((dy == 1) || (dy == -1)) refRectB.h--;
|
||||
if (dx == -1) {
|
||||
refRectB.x++;
|
||||
}
|
||||
if ((dx == 1) || (dx == -1)) {
|
||||
refRectB.w--;
|
||||
}
|
||||
if (dy == -1) {
|
||||
refRectB.y++;
|
||||
}
|
||||
if ((dy == 1) || (dy == -1)) {
|
||||
refRectB.h--;
|
||||
}
|
||||
expectedResult = refRectA;
|
||||
rectA = refRectA;
|
||||
rectB = refRectB;
|
||||
|
||||
@@ -151,10 +151,14 @@ int render_testPrimitives (void *arg)
|
||||
for (y=0; y<3; y++) {
|
||||
for (x = y % 2; x<TESTRENDER_SCREEN_W; x+=2) {
|
||||
ret = SDL_SetRenderDrawColor(renderer, x*y, x*y/2, x*y/3, SDL_ALPHA_OPAQUE );
|
||||
if (ret != 0) checkFailCount1++;
|
||||
if (ret != 0) {
|
||||
checkFailCount1++;
|
||||
}
|
||||
|
||||
ret = SDL_RenderDrawPoint(renderer, x, y );
|
||||
if (ret != 0) checkFailCount2++;
|
||||
if (ret != 0) {
|
||||
checkFailCount2++;
|
||||
}
|
||||
}
|
||||
}
|
||||
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetRenderDrawColor, expected: 0, got: %i", checkFailCount1);
|
||||
@@ -281,16 +285,22 @@ int render_testPrimitivesBlend (void *arg)
|
||||
checkFailCount1 = 0;
|
||||
checkFailCount2 = 0;
|
||||
checkFailCount3 = 0;
|
||||
for (i=0; i<TESTRENDER_SCREEN_W; i+=2) {
|
||||
for (i=0; i<TESTRENDER_SCREEN_W; i+=2) {
|
||||
ret = SDL_SetRenderDrawColor(renderer, 60+2*i, 240-2*i, 50, 3*i );
|
||||
if (ret != 0) checkFailCount1++;
|
||||
if (ret != 0) {
|
||||
checkFailCount1++;
|
||||
}
|
||||
|
||||
ret = SDL_SetRenderDrawBlendMode(renderer,(((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
|
||||
(((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_NONE );
|
||||
if (ret != 0) checkFailCount2++;
|
||||
if (ret != 0) {
|
||||
checkFailCount2++;
|
||||
}
|
||||
|
||||
ret = SDL_RenderDrawLine(renderer, 0, 0, i, 59 );
|
||||
if (ret != 0) checkFailCount3++;
|
||||
if (ret != 0) {
|
||||
checkFailCount3++;
|
||||
}
|
||||
}
|
||||
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetRenderDrawColor, expected: 0, got: %i", checkFailCount1);
|
||||
SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetRenderDrawBlendMode, expected: 0, got: %i", checkFailCount2);
|
||||
@@ -299,16 +309,22 @@ int render_testPrimitivesBlend (void *arg)
|
||||
checkFailCount1 = 0;
|
||||
checkFailCount2 = 0;
|
||||
checkFailCount3 = 0;
|
||||
for (i=0; i<TESTRENDER_SCREEN_H; i+=2) {
|
||||
for (i=0; i<TESTRENDER_SCREEN_H; i+=2) {
|
||||
ret = SDL_SetRenderDrawColor(renderer, 60+2*i, 240-2*i, 50, 3*i );
|
||||
if (ret != 0) checkFailCount1++;
|
||||
if (ret != 0) {
|
||||
checkFailCount1++;
|
||||
}
|
||||
|
||||
ret = SDL_SetRenderDrawBlendMode(renderer,(((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
|
||||
(((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_NONE );
|
||||
if (ret != 0) checkFailCount2++;
|
||||
if (ret != 0) {
|
||||
checkFailCount2++;
|
||||
}
|
||||
|
||||
ret = SDL_RenderDrawLine(renderer, 0, 0, 79, i );
|
||||
if (ret != 0) checkFailCount3++;
|
||||
if (ret != 0) {
|
||||
checkFailCount3++;
|
||||
}
|
||||
}
|
||||
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetRenderDrawColor, expected: 0, got: %i", checkFailCount1);
|
||||
SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetRenderDrawBlendMode, expected: 0, got: %i", checkFailCount2);
|
||||
@@ -321,14 +337,20 @@ int render_testPrimitivesBlend (void *arg)
|
||||
for (j=0; j<TESTRENDER_SCREEN_H; j+=3) {
|
||||
for (i=0; i<TESTRENDER_SCREEN_W; i+=3) {
|
||||
ret = SDL_SetRenderDrawColor(renderer, j*4, i*3, j*4, i*3 );
|
||||
if (ret != 0) checkFailCount1++;
|
||||
if (ret != 0) {
|
||||
checkFailCount1++;
|
||||
}
|
||||
|
||||
ret = SDL_SetRenderDrawBlendMode(renderer, ((((i+j)/3)%3)==0) ? SDL_BLENDMODE_BLEND :
|
||||
((((i+j)/3)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_NONE );
|
||||
if (ret != 0) checkFailCount2++;
|
||||
if (ret != 0) {
|
||||
checkFailCount2++;
|
||||
}
|
||||
|
||||
ret = SDL_RenderDrawPoint(renderer, i, j );
|
||||
if (ret != 0) checkFailCount3++;
|
||||
if (ret != 0) {
|
||||
checkFailCount3++;
|
||||
}
|
||||
}
|
||||
}
|
||||
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetRenderDrawColor, expected: 0, got: %i", checkFailCount1);
|
||||
@@ -399,7 +421,9 @@ render_testBlit(void *arg)
|
||||
rect.x = i;
|
||||
rect.y = j;
|
||||
ret = SDL_RenderCopy(renderer, tface, NULL, &rect );
|
||||
if (ret != 0) checkFailCount1++;
|
||||
if (ret != 0) {
|
||||
checkFailCount1++;
|
||||
}
|
||||
}
|
||||
}
|
||||
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount1);
|
||||
@@ -466,13 +490,17 @@ render_testBlitColor (void *arg)
|
||||
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++;
|
||||
if (ret != 0) {
|
||||
checkFailCount1++;
|
||||
}
|
||||
|
||||
/* Blitting. */
|
||||
rect.x = i;
|
||||
rect.y = j;
|
||||
ret = SDL_RenderCopy(renderer, tface, NULL, &rect );
|
||||
if (ret != 0) checkFailCount2++;
|
||||
if (ret != 0) {
|
||||
checkFailCount2++;
|
||||
}
|
||||
}
|
||||
}
|
||||
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i", checkFailCount1);
|
||||
@@ -543,13 +571,17 @@ render_testBlitAlpha (void *arg)
|
||||
for (i=0; i <= ni; i+=4) {
|
||||
/* Set alpha mod. */
|
||||
ret = SDL_SetTextureAlphaMod( tface, (255/ni)*i );
|
||||
if (ret != 0) checkFailCount1++;
|
||||
if (ret != 0) {
|
||||
checkFailCount1++;
|
||||
}
|
||||
|
||||
/* Blitting. */
|
||||
rect.x = i;
|
||||
rect.y = j;
|
||||
ret = SDL_RenderCopy(renderer, tface, NULL, &rect );
|
||||
if (ret != 0) checkFailCount2++;
|
||||
if (ret != 0) {
|
||||
checkFailCount2++;
|
||||
}
|
||||
}
|
||||
}
|
||||
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureAlphaMod, expected: 0, got: %i", checkFailCount1);
|
||||
@@ -608,13 +640,17 @@ _testBlitBlendMode( SDL_Texture * tface, int mode )
|
||||
for (i=0; i <= ni; i+=4) {
|
||||
/* Set blend mode. */
|
||||
ret = SDL_SetTextureBlendMode( tface, (SDL_BlendMode)mode );
|
||||
if (ret != 0) checkFailCount1++;
|
||||
if (ret != 0) {
|
||||
checkFailCount1++;
|
||||
}
|
||||
|
||||
/* Blitting. */
|
||||
rect.x = i;
|
||||
rect.y = j;
|
||||
ret = SDL_RenderCopy(renderer, tface, NULL, &rect );
|
||||
if (ret != 0) checkFailCount2++;
|
||||
if (ret != 0) {
|
||||
checkFailCount2++;
|
||||
}
|
||||
}
|
||||
}
|
||||
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureBlendMode, expected: 0, got: %i", checkFailCount1);
|
||||
@@ -727,26 +763,39 @@ render_testBlitBlend (void *arg)
|
||||
|
||||
/* Set color mod. */
|
||||
ret = SDL_SetTextureColorMod( tface, (255/nj)*j, (255/ni)*i, (255/nj)*j );
|
||||
if (ret != 0) checkFailCount1++;
|
||||
if (ret != 0) {
|
||||
checkFailCount1++;
|
||||
}
|
||||
|
||||
/* Set alpha mod. */
|
||||
ret = SDL_SetTextureAlphaMod( tface, (100/ni)*i );
|
||||
if (ret != 0) checkFailCount2++;
|
||||
if (ret != 0) {
|
||||
checkFailCount2++;
|
||||
}
|
||||
|
||||
/* Crazy blending mode magic. */
|
||||
mode = (i/4*j/4) % 4;
|
||||
if (mode==0) mode = SDL_BLENDMODE_NONE;
|
||||
else if (mode==1) mode = SDL_BLENDMODE_BLEND;
|
||||
else if (mode==2) mode = SDL_BLENDMODE_ADD;
|
||||
else if (mode==3) mode = SDL_BLENDMODE_MOD;
|
||||
if (mode==0) {
|
||||
mode = SDL_BLENDMODE_NONE;
|
||||
} else if (mode==1) {
|
||||
mode = SDL_BLENDMODE_BLEND;
|
||||
} else if (mode==2) {
|
||||
mode = SDL_BLENDMODE_ADD;
|
||||
} else if (mode == 3) {
|
||||
mode = SDL_BLENDMODE_MOD;
|
||||
}
|
||||
ret = SDL_SetTextureBlendMode( tface, (SDL_BlendMode)mode );
|
||||
if (ret != 0) checkFailCount3++;
|
||||
if (ret != 0) {
|
||||
checkFailCount3++;
|
||||
}
|
||||
|
||||
/* Blitting. */
|
||||
rect.x = i;
|
||||
rect.y = j;
|
||||
ret = SDL_RenderCopy(renderer, tface, NULL, &rect );
|
||||
if (ret != 0) checkFailCount4++;
|
||||
if (ret != 0) {
|
||||
checkFailCount4++;
|
||||
}
|
||||
}
|
||||
}
|
||||
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i", checkFailCount1);
|
||||
@@ -777,7 +826,7 @@ render_testBlitBlend (void *arg)
|
||||
static int
|
||||
_isSupported( int code )
|
||||
{
|
||||
return (code == 0);
|
||||
return code == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -797,24 +846,28 @@ _hasDrawColor (void)
|
||||
|
||||
/* Set color. */
|
||||
ret = SDL_SetRenderDrawColor(renderer, 100, 100, 100, 100 );
|
||||
if (!_isSupported(ret))
|
||||
if (!_isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
ret = SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a );
|
||||
if (!_isSupported(ret))
|
||||
if (!_isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
|
||||
/* Restore natural. */
|
||||
ret = SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE );
|
||||
if (!_isSupported(ret))
|
||||
if (!_isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
|
||||
/* Something failed, consider not available. */
|
||||
if (fail)
|
||||
if (fail) {
|
||||
return 0;
|
||||
|
||||
}
|
||||
/* Not set properly, consider failed. */
|
||||
else if ((r != 100) || (g != 100) || (b != 100) || (a != 100))
|
||||
else if ((r != 100) || (g != 100) || (b != 100) || (a != 100)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -835,41 +888,53 @@ _hasBlendModes (void)
|
||||
fail = 0;
|
||||
|
||||
ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND );
|
||||
if (!_isSupported(ret))
|
||||
if (!_isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
ret = SDL_GetRenderDrawBlendMode(renderer, &mode );
|
||||
if (!_isSupported(ret))
|
||||
if (!_isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
ret = (mode != SDL_BLENDMODE_BLEND);
|
||||
if (!_isSupported(ret))
|
||||
if (!_isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_ADD );
|
||||
if (!_isSupported(ret))
|
||||
if (!_isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
ret = SDL_GetRenderDrawBlendMode(renderer, &mode );
|
||||
if (!_isSupported(ret))
|
||||
if (!_isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
ret = (mode != SDL_BLENDMODE_ADD);
|
||||
if (!_isSupported(ret))
|
||||
if (!_isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_MOD );
|
||||
if (!_isSupported(ret))
|
||||
if (!_isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
ret = SDL_GetRenderDrawBlendMode(renderer, &mode );
|
||||
if (!_isSupported(ret))
|
||||
if (!_isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
ret = (mode != SDL_BLENDMODE_MOD);
|
||||
if (!_isSupported(ret))
|
||||
if (!_isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE );
|
||||
if (!_isSupported(ret))
|
||||
if (!_isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
ret = SDL_GetRenderDrawBlendMode(renderer, &mode );
|
||||
if (!_isSupported(ret))
|
||||
if (!_isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
ret = (mode != SDL_BLENDMODE_NONE);
|
||||
if (!_isSupported(ret))
|
||||
if (!_isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
|
||||
return !fail;
|
||||
}
|
||||
@@ -921,25 +986,29 @@ _hasTexColor (void)
|
||||
|
||||
/* Get test face. */
|
||||
tface = _loadTestFace();
|
||||
if (tface == NULL)
|
||||
if (tface == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* See if supported. */
|
||||
fail = 0;
|
||||
ret = SDL_SetTextureColorMod( tface, 100, 100, 100 );
|
||||
if (!_isSupported(ret))
|
||||
if (!_isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
ret = SDL_GetTextureColorMod( tface, &r, &g, &b );
|
||||
if (!_isSupported(ret))
|
||||
if (!_isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
|
||||
/* Clean up. */
|
||||
SDL_DestroyTexture( tface );
|
||||
|
||||
if (fail)
|
||||
if (fail) {
|
||||
return 0;
|
||||
else if ((r != 100) || (g != 100) || (b != 100))
|
||||
} else if ((r != 100) || (g != 100) || (b != 100)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -961,25 +1030,29 @@ _hasTexAlpha(void)
|
||||
|
||||
/* Get test face. */
|
||||
tface = _loadTestFace();
|
||||
if (tface == NULL)
|
||||
if (tface == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* See if supported. */
|
||||
fail = 0;
|
||||
ret = SDL_SetTextureAlphaMod( tface, 100 );
|
||||
if (!_isSupported(ret))
|
||||
if (!_isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
ret = SDL_GetTextureAlphaMod( tface, &a );
|
||||
if (!_isSupported(ret))
|
||||
if (!_isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
|
||||
/* Clean up. */
|
||||
SDL_DestroyTexture( tface );
|
||||
|
||||
if (fail)
|
||||
if (fail) {
|
||||
return 0;
|
||||
else if (a != 100)
|
||||
} else if (a != 100) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1004,7 +1077,9 @@ _compare(SDL_Surface *referenceSurface, int allowable_error)
|
||||
/* Read pixels. */
|
||||
pixels = (Uint8 *)SDL_malloc(4*TESTRENDER_SCREEN_W*TESTRENDER_SCREEN_H);
|
||||
SDLTest_AssertCheck(pixels != NULL, "Validate allocated temp pixel buffer");
|
||||
if (pixels == NULL) return;
|
||||
if (pixels == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Explicitly specify the rect in case the window isn't the expected size... */
|
||||
rect.x = 0;
|
||||
|
||||
@@ -47,7 +47,9 @@ RWopsSetUp(void *arg)
|
||||
/* 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;
|
||||
if (handle == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Write some known text into it */
|
||||
fileLen = SDL_strlen(RWopsHelloWorldTestString);
|
||||
@@ -59,7 +61,9 @@ RWopsSetUp(void *arg)
|
||||
/* Create a second test file */
|
||||
handle = fopen(RWopsAlphabetFilename, "w");
|
||||
SDLTest_AssertCheck(handle != NULL, "Verify creation of file '%s' returned non NULL handle", RWopsAlphabetFilename);
|
||||
if (handle == NULL) return;
|
||||
if (handle == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Write alphabet text into it */
|
||||
fileLen = SDL_strlen(RWopsAlphabetString);
|
||||
@@ -114,8 +118,7 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write)
|
||||
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", (int) s);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
SDLTest_AssertCheck(s == (size_t)0, "Verify result of writing with SDL_RWwrite, expected: 0, got %i", (int) s);
|
||||
}
|
||||
|
||||
@@ -236,7 +239,9 @@ rwops_testMem (void)
|
||||
SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromMem does not return NULL");
|
||||
|
||||
/* Bail out if NULL */
|
||||
if (rw == NULL) return TEST_ABORTED;
|
||||
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: %" SDL_PRIu32, SDL_RWOPS_MEMORY, rw->type);
|
||||
@@ -272,7 +277,9 @@ rwops_testConstMem (void)
|
||||
SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromConstMem does not return NULL");
|
||||
|
||||
/* Bail out if NULL */
|
||||
if (rw == NULL) return TEST_ABORTED;
|
||||
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: %" SDL_PRIu32, SDL_RWOPS_MEMORY_RO, rw->type);
|
||||
@@ -308,7 +315,9 @@ rwops_testFileRead(void)
|
||||
SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in read mode does not return NULL");
|
||||
|
||||
/* Bail out if NULL */
|
||||
if (rw == NULL) return TEST_ABORTED;
|
||||
if (rw == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Check type */
|
||||
#if defined(__ANDROID__)
|
||||
@@ -355,7 +364,9 @@ rwops_testFileWrite(void)
|
||||
SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in write mode does not return NULL");
|
||||
|
||||
/* Bail out if NULL */
|
||||
if (rw == NULL) return TEST_ABORTED;
|
||||
if (rw == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Check type */
|
||||
#if defined(__ANDROID__)
|
||||
@@ -502,7 +513,9 @@ rwops_testAllocFree (void)
|
||||
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;
|
||||
if (rw == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Check type */
|
||||
SDLTest_AssertCheck(
|
||||
@@ -538,8 +551,7 @@ rwops_testCompareRWFromMemWithRWFromFile(void)
|
||||
int result;
|
||||
|
||||
|
||||
for (size=5; size<10; size++)
|
||||
{
|
||||
for (size=5; size<10; size++) {
|
||||
/* Terminate buffer */
|
||||
buffer_file[slen] = 0;
|
||||
buffer_mem[slen] = 0;
|
||||
@@ -652,7 +664,9 @@ rwops_testFileWriteReadEndian(void)
|
||||
SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in write mode does not return NULL");
|
||||
|
||||
/* Bail out if NULL */
|
||||
if (rw == NULL) return TEST_ABORTED;
|
||||
if (rw == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Write test data */
|
||||
objectsWritten = SDL_WriteBE16(rw, BE16value);
|
||||
|
||||
@@ -191,7 +191,7 @@ stdlib_getsetenv(void *arg)
|
||||
/* 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++) {
|
||||
for (counter = 0; counter < nameLen; counter++) {
|
||||
name[counter] = (char)SDLTest_RandomIntegerInRange(65, 90);
|
||||
}
|
||||
name[nameLen] = '\0';
|
||||
|
||||
@@ -110,12 +110,16 @@ void _testBlitBlendMode(int mode)
|
||||
|
||||
/* Check test surface */
|
||||
SDLTest_AssertCheck(testSurface != NULL, "Verify testSurface is not NULL");
|
||||
if (testSurface == NULL) return;
|
||||
if (testSurface == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Create sample surface */
|
||||
face = SDLTest_ImageFace();
|
||||
SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
|
||||
if (face == NULL) return;
|
||||
if (face == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Reset alpha modulation */
|
||||
ret = SDL_SetSurfaceAlphaMod(face, 255);
|
||||
@@ -160,14 +164,16 @@ void _testBlitBlendMode(int mode)
|
||||
if (mode == -2) {
|
||||
/* Set color mod. */
|
||||
ret = SDL_SetSurfaceColorMod( face, (255/nj)*j, (255/ni)*i, (255/nj)*j );
|
||||
if (ret != 0) checkFailCount2++;
|
||||
}
|
||||
else if (mode == -3) {
|
||||
if (ret != 0) {
|
||||
checkFailCount2++;
|
||||
}
|
||||
} else if (mode == -3) {
|
||||
/* Set alpha mod. */
|
||||
ret = SDL_SetSurfaceAlphaMod( face, (255/ni)*i );
|
||||
if (ret != 0) checkFailCount3++;
|
||||
}
|
||||
else if (mode == -4) {
|
||||
if (ret != 0) {
|
||||
checkFailCount3++;
|
||||
}
|
||||
} else if (mode == -4) {
|
||||
/* Crazy blending mode magic. */
|
||||
nmode = (i/4*j/4) % 4;
|
||||
if (nmode==0) {
|
||||
@@ -184,14 +190,18 @@ void _testBlitBlendMode(int mode)
|
||||
return;
|
||||
}
|
||||
ret = SDL_SetSurfaceBlendMode( face, bmode );
|
||||
if (ret != 0) checkFailCount4++;
|
||||
if (ret != 0) {
|
||||
checkFailCount4++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Blitting. */
|
||||
rect.x = i;
|
||||
rect.y = j;
|
||||
ret = SDL_BlitSurface( face, NULL, testSurface, &rect );
|
||||
if (ret != 0) checkFailCount1++;
|
||||
if (ret != 0) {
|
||||
checkFailCount1++;
|
||||
}
|
||||
}
|
||||
}
|
||||
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_BlitSurface, expected: 0, got: %i", checkFailCount1);
|
||||
@@ -231,7 +241,9 @@ surface_testSaveLoadBitmap(void *arg)
|
||||
/* Create sample surface */
|
||||
face = SDLTest_ImageFace();
|
||||
SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
|
||||
if (face == NULL) return TEST_ABORTED;
|
||||
if (face == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Delete test file; ignore errors */
|
||||
unlink(sampleFilename);
|
||||
@@ -275,8 +287,9 @@ surface_testSurfaceConversion(void *arg)
|
||||
/* Create sample surface */
|
||||
face = SDLTest_ImageFace();
|
||||
SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
|
||||
if (face == NULL)
|
||||
if (face == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Set transparent pixel as the pixel at (0,0) */
|
||||
if (face->format->palette) {
|
||||
@@ -346,8 +359,9 @@ surface_testCompleteSurfaceConversion(void *arg)
|
||||
/* Create sample surface */
|
||||
face = SDLTest_ImageFace();
|
||||
SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
|
||||
if (face == NULL)
|
||||
if (face == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Set transparent pixel as the pixel at (0,0) */
|
||||
if (face->format->palette) {
|
||||
@@ -756,8 +770,7 @@ surface_testOverflow(void *arg)
|
||||
SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * height * bytes per pixel");
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
SDLTest_Log("Can't easily overflow size_t on this platform");
|
||||
}
|
||||
|
||||
|
||||
@@ -836,7 +836,9 @@ video_getSetWindowGrab(void *arg)
|
||||
|
||||
/* Call against new test window */
|
||||
window = _createVideoSuiteTestWindow(title);
|
||||
if (window == NULL) return TEST_ABORTED;
|
||||
if (window == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Get state */
|
||||
originalMouseState = SDL_GetWindowMouseGrab(window);
|
||||
@@ -980,7 +982,9 @@ video_getWindowId(void *arg)
|
||||
|
||||
/* Call against new test window */
|
||||
window = _createVideoSuiteTestWindow(title);
|
||||
if (window == NULL) return TEST_ABORTED;
|
||||
if (window == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Get ID */
|
||||
id = SDL_GetWindowID(window);
|
||||
@@ -1034,7 +1038,9 @@ video_getWindowPixelFormat(void *arg)
|
||||
|
||||
/* Call against new test window */
|
||||
window = _createVideoSuiteTestWindow(title);
|
||||
if (window == NULL) return TEST_ABORTED;
|
||||
if (window == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Get format */
|
||||
format = SDL_GetWindowPixelFormat(window);
|
||||
@@ -1072,7 +1078,9 @@ video_getSetWindowPosition(void *arg)
|
||||
|
||||
/* Call against new test window */
|
||||
window = _createVideoSuiteTestWindow(title);
|
||||
if (window == NULL) return TEST_ABORTED;
|
||||
if (window == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
for (xVariation = 0; xVariation < 4; xVariation++) {
|
||||
for (yVariation = 0; yVariation < 4; yVariation++) {
|
||||
@@ -1222,11 +1230,15 @@ video_getSetWindowSize(void *arg)
|
||||
result = SDL_GetDisplayBounds(0, &display);
|
||||
SDLTest_AssertPass("SDL_GetDisplayBounds()");
|
||||
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
|
||||
if (result != 0) return TEST_ABORTED;
|
||||
if (result != 0) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Call against new test window */
|
||||
window = _createVideoSuiteTestWindow(title);
|
||||
if (window == NULL) return TEST_ABORTED;
|
||||
if (window == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
#ifdef __WIN32__
|
||||
/* Platform clips window size to screen size */
|
||||
@@ -1386,11 +1398,15 @@ video_getSetWindowMinimumSize(void *arg)
|
||||
result = SDL_GetDisplayBounds(0, &display);
|
||||
SDLTest_AssertPass("SDL_GetDisplayBounds()");
|
||||
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
|
||||
if (result != 0) return TEST_ABORTED;
|
||||
if (result != 0) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Call against new test window */
|
||||
window = _createVideoSuiteTestWindow(title);
|
||||
if (window == NULL) return TEST_ABORTED;
|
||||
if (window == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
for (wVariation = 0; wVariation < 5; wVariation++) {
|
||||
for (hVariation = 0; hVariation < 5; hVariation++) {
|
||||
@@ -1525,11 +1541,15 @@ video_getSetWindowMaximumSize(void *arg)
|
||||
result = SDL_GetDisplayBounds(0, &display);
|
||||
SDLTest_AssertPass("SDL_GetDisplayBounds()");
|
||||
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
|
||||
if (result != 0) return TEST_ABORTED;
|
||||
if (result != 0) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Call against new test window */
|
||||
window = _createVideoSuiteTestWindow(title);
|
||||
if (window == NULL) return TEST_ABORTED;
|
||||
if (window == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
for (wVariation = 0; wVariation < 3; wVariation++) {
|
||||
for (hVariation = 0; hVariation < 3; hVariation++) {
|
||||
@@ -1667,7 +1687,9 @@ video_getSetWindowData(void *arg)
|
||||
|
||||
/* Call against new test window */
|
||||
window = _createVideoSuiteTestWindow(title);
|
||||
if (window == NULL) return TEST_ABORTED;
|
||||
if (window == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Create testdata */
|
||||
datasize = SDLTest_RandomIntegerInRange(1, 32);
|
||||
@@ -1879,14 +1901,16 @@ video_setWindowCenteredOnDisplay(void *arg)
|
||||
result = SDL_GetDisplayBounds(0 % displayNum, &display0);
|
||||
SDLTest_AssertPass("SDL_GetDisplayBounds()");
|
||||
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
|
||||
if (result != 0)
|
||||
if (result != 0) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
result = SDL_GetDisplayBounds(1 % displayNum, &display1);
|
||||
SDLTest_AssertPass("SDL_GetDisplayBounds()");
|
||||
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
|
||||
if (result != 0)
|
||||
if (result != 0) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
for (xVariation = 0; xVariation < 2; xVariation++) {
|
||||
for (yVariation = 0; yVariation < 2; yVariation++) {
|
||||
|
||||
@@ -216,7 +216,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
@@ -293,7 +293,7 @@ main(int argc, char *argv[])
|
||||
quit(0);
|
||||
|
||||
/* keep the compiler happy ... */
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -20,8 +20,9 @@
|
||||
static void
|
||||
print_mode(const char *prefix, const SDL_DisplayMode *mode)
|
||||
{
|
||||
if (!mode)
|
||||
if (mode == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_Log("%s: fmt=%s w=%d h=%d refresh=%d\n",
|
||||
prefix, SDL_GetPixelFormatName(mode->format),
|
||||
|
||||
@@ -190,8 +190,9 @@ loop()
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
@@ -232,7 +233,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
|
||||
@@ -37,11 +37,11 @@ DrawChessBoard()
|
||||
/* Get the Size of drawing surface */
|
||||
SDL_RenderGetViewport(renderer, &darea);
|
||||
|
||||
for( ; row < 8; row++)
|
||||
for ( ; row < 8; row++)
|
||||
{
|
||||
column = row%2;
|
||||
x = column;
|
||||
for( ; column < 4+(row%2); column++)
|
||||
for ( ; column < 4+(row%2); column++)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0xFF);
|
||||
|
||||
@@ -104,8 +104,7 @@ main(int argc, char *argv[])
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Initialize SDL */
|
||||
if(SDL_Init(SDL_INIT_VIDEO) != 0)
|
||||
{
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init fail : %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
@@ -113,15 +112,13 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Create window and renderer for given surface */
|
||||
window = SDL_CreateWindow("Chess Board", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_RESIZABLE);
|
||||
if(!window)
|
||||
{
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n",SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
surface = SDL_GetWindowSurface(window);
|
||||
renderer = SDL_CreateSoftwareRenderer(surface);
|
||||
if(!renderer)
|
||||
{
|
||||
if (renderer == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n",SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ main(int argc, char *argv[])
|
||||
|
||||
quit(0);
|
||||
/* keep the compiler happy ... */
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -38,7 +38,7 @@ ThreadFunc(void *data)
|
||||
SDL_Delay(1 * 1000);
|
||||
}
|
||||
SDL_Log("Child thread error string: %s\n", SDL_GetError());
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -52,7 +52,7 @@ main(int argc, char *argv[])
|
||||
/* Load the SDL library */
|
||||
if (SDL_Init(0) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Set the error value for the main thread */
|
||||
@@ -78,5 +78,5 @@ main(int argc, char *argv[])
|
||||
SDL_Log("Main thread error string: %s\n", SDL_GetError());
|
||||
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -998,8 +998,7 @@ run_test(void)
|
||||
|
||||
if (actual == t->expected) {
|
||||
printf("\tOK\n");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
printf("\tExpected 0x%08x\n", t->expected);
|
||||
|
||||
for (j = 0; device_classes[j].code != 0; j++) {
|
||||
|
||||
234
test/testfile.c
234
test/testfile.c
@@ -76,20 +76,25 @@ main(int argc, char *argv[])
|
||||
/* test 1 : basic argument test: all those calls to SDL_RWFromFile should fail */
|
||||
|
||||
rwops = SDL_RWFromFile(NULL, NULL);
|
||||
if (rwops)
|
||||
if (rwops) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops = SDL_RWFromFile(NULL, "ab+");
|
||||
if (rwops)
|
||||
if (rwops) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops = SDL_RWFromFile(NULL, "sldfkjsldkfj");
|
||||
if (rwops)
|
||||
if (rwops) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops = SDL_RWFromFile("something", "");
|
||||
if (rwops)
|
||||
if (rwops) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops = SDL_RWFromFile("something", NULL);
|
||||
if (rwops)
|
||||
if (rwops) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
SDL_Log("test1 OK\n");
|
||||
|
||||
/* test 2 : check that inexistent file is not successfully opened/created when required */
|
||||
@@ -98,29 +103,35 @@ main(int argc, char *argv[])
|
||||
|
||||
*/
|
||||
rwops = SDL_RWFromFile(FBASENAME2, "rb"); /* this file doesn't exist that call must fail */
|
||||
if (rwops)
|
||||
if (rwops) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops = SDL_RWFromFile(FBASENAME2, "rb+"); /* this file doesn't exist that call must fail */
|
||||
if (rwops)
|
||||
if (rwops) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops = SDL_RWFromFile(FBASENAME2, "wb");
|
||||
if (!rwops)
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops->close(rwops);
|
||||
unlink(FBASENAME2);
|
||||
rwops = SDL_RWFromFile(FBASENAME2, "wb+");
|
||||
if (!rwops)
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops->close(rwops);
|
||||
unlink(FBASENAME2);
|
||||
rwops = SDL_RWFromFile(FBASENAME2, "ab");
|
||||
if (!rwops)
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops->close(rwops);
|
||||
unlink(FBASENAME2);
|
||||
rwops = SDL_RWFromFile(FBASENAME2, "ab+");
|
||||
if (!rwops)
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops->close(rwops);
|
||||
unlink(FBASENAME2);
|
||||
SDL_Log("test2 OK\n");
|
||||
@@ -129,153 +140,220 @@ main(int argc, char *argv[])
|
||||
test : w mode, r mode, w+ mode
|
||||
*/
|
||||
rwops = SDL_RWFromFile(FBASENAME1, "wb"); /* write only */
|
||||
if (!rwops)
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (1 != rwops->write(rwops, "1234567890", 10, 1))
|
||||
}
|
||||
if (1 != rwops->write(rwops, "1234567890", 10, 1)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (10 != rwops->write(rwops, "1234567890", 1, 10))
|
||||
}
|
||||
if (10 != rwops->write(rwops, "1234567890", 1, 10)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->write(rwops, "1234567", 1, 7))
|
||||
}
|
||||
if (7 != rwops->write(rwops, "1234567", 1, 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
}
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1))
|
||||
RWOP_ERR_QUIT(rwops); /* we are in write only mode */
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1)) {
|
||||
RWOP_ERR_QUIT(rwops); /* we are in write only mode */
|
||||
}
|
||||
|
||||
rwops->close(rwops);
|
||||
|
||||
rwops = SDL_RWFromFile(FBASENAME1, "rb"); /* read mode, file must exists */
|
||||
if (!rwops)
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
}
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (20 != rwops->seek(rwops, -7, RW_SEEK_END))
|
||||
}
|
||||
if (20 != rwops->seek(rwops, -7, RW_SEEK_END)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->read(rwops, test_buf, 1, 7))
|
||||
}
|
||||
if (7 != rwops->read(rwops, test_buf, 1, 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "1234567", 7))
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "1234567", 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1))
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 10, 100))
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 10, 100)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR))
|
||||
}
|
||||
if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (2 != rwops->read(rwops, test_buf, 10, 3))
|
||||
}
|
||||
if (2 != rwops->read(rwops, test_buf, 10, 3)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "12345678901234567890", 20))
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "12345678901234567890", 20)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->write(rwops, test_buf, 1, 1))
|
||||
RWOP_ERR_QUIT(rwops); /* readonly mode */
|
||||
}
|
||||
if (0 != rwops->write(rwops, test_buf, 1, 1)) {
|
||||
RWOP_ERR_QUIT(rwops); /* readonly mode */
|
||||
}
|
||||
|
||||
rwops->close(rwops);
|
||||
|
||||
/* test 3: same with w+ mode */
|
||||
rwops = SDL_RWFromFile(FBASENAME1, "wb+"); /* write + read + truncation */
|
||||
if (!rwops)
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (1 != rwops->write(rwops, "1234567890", 10, 1))
|
||||
}
|
||||
if (1 != rwops->write(rwops, "1234567890", 10, 1)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (10 != rwops->write(rwops, "1234567890", 1, 10))
|
||||
}
|
||||
if (10 != rwops->write(rwops, "1234567890", 1, 10)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->write(rwops, "1234567", 1, 7))
|
||||
}
|
||||
if (7 != rwops->write(rwops, "1234567", 1, 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
}
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (1 != rwops->read(rwops, test_buf, 1, 1))
|
||||
RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
}
|
||||
if (1 != rwops->read(rwops, test_buf, 1, 1)) {
|
||||
RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
|
||||
}
|
||||
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (20 != rwops->seek(rwops, -7, RW_SEEK_END))
|
||||
}
|
||||
if (20 != rwops->seek(rwops, -7, RW_SEEK_END)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->read(rwops, test_buf, 1, 7))
|
||||
}
|
||||
if (7 != rwops->read(rwops, test_buf, 1, 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "1234567", 7))
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "1234567", 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1))
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 10, 100))
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 10, 100)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR))
|
||||
}
|
||||
if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (2 != rwops->read(rwops, test_buf, 10, 3))
|
||||
}
|
||||
if (2 != rwops->read(rwops, test_buf, 10, 3)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "12345678901234567890", 20))
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "12345678901234567890", 20)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops->close(rwops);
|
||||
SDL_Log("test3 OK\n");
|
||||
|
||||
/* test 4: same in r+ mode */
|
||||
rwops = SDL_RWFromFile(FBASENAME1, "rb+"); /* write + read + file must exists, no truncation */
|
||||
if (!rwops)
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (1 != rwops->write(rwops, "1234567890", 10, 1))
|
||||
}
|
||||
if (1 != rwops->write(rwops, "1234567890", 10, 1)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (10 != rwops->write(rwops, "1234567890", 1, 10))
|
||||
}
|
||||
if (10 != rwops->write(rwops, "1234567890", 1, 10)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->write(rwops, "1234567", 1, 7))
|
||||
}
|
||||
if (7 != rwops->write(rwops, "1234567", 1, 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
}
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (1 != rwops->read(rwops, test_buf, 1, 1))
|
||||
RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
}
|
||||
if (1 != rwops->read(rwops, test_buf, 1, 1)) {
|
||||
RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
|
||||
}
|
||||
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (20 != rwops->seek(rwops, -7, RW_SEEK_END))
|
||||
}
|
||||
if (20 != rwops->seek(rwops, -7, RW_SEEK_END)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->read(rwops, test_buf, 1, 7))
|
||||
}
|
||||
if (7 != rwops->read(rwops, test_buf, 1, 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "1234567", 7))
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "1234567", 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1))
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 10, 100))
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 10, 100)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR))
|
||||
}
|
||||
if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (2 != rwops->read(rwops, test_buf, 10, 3))
|
||||
}
|
||||
if (2 != rwops->read(rwops, test_buf, 10, 3)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "12345678901234567890", 20))
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "12345678901234567890", 20)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops->close(rwops);
|
||||
SDL_Log("test4 OK\n");
|
||||
|
||||
/* test5 : append mode */
|
||||
rwops = SDL_RWFromFile(FBASENAME1, "ab+"); /* write + read + append */
|
||||
if (!rwops)
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (1 != rwops->write(rwops, "1234567890", 10, 1))
|
||||
}
|
||||
if (1 != rwops->write(rwops, "1234567890", 10, 1)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (10 != rwops->write(rwops, "1234567890", 1, 10))
|
||||
}
|
||||
if (10 != rwops->write(rwops, "1234567890", 1, 10)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->write(rwops, "1234567", 1, 7))
|
||||
}
|
||||
if (7 != rwops->write(rwops, "1234567", 1, 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
}
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
|
||||
if (1 != rwops->read(rwops, test_buf, 1, 1))
|
||||
if (1 != rwops->read(rwops, test_buf, 1, 1)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
}
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
|
||||
if (20 + 27 != rwops->seek(rwops, -7, RW_SEEK_END))
|
||||
if (20 + 27 != rwops->seek(rwops, -7, RW_SEEK_END)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->read(rwops, test_buf, 1, 7))
|
||||
}
|
||||
if (7 != rwops->read(rwops, test_buf, 1, 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "1234567", 7))
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "1234567", 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1))
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 10, 100))
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 10, 100)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
|
||||
if (27 != rwops->seek(rwops, -27, RW_SEEK_CUR))
|
||||
if (27 != rwops->seek(rwops, -27, RW_SEEK_CUR)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (3 != rwops->read(rwops, test_buf, 10, 3))
|
||||
}
|
||||
if (3 != rwops->read(rwops, test_buf, 10, 3)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "123456789012345678901234567123", 30))
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "123456789012345678901234567123", 30)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops->close(rwops);
|
||||
SDL_Log("test5 OK\n");
|
||||
cleanup();
|
||||
|
||||
@@ -29,7 +29,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
base_path = SDL_GetBasePath();
|
||||
if(base_path == NULL){
|
||||
if (base_path == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find base path: %s\n",
|
||||
SDL_GetError());
|
||||
} else {
|
||||
@@ -38,7 +38,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
pref_path = SDL_GetPrefPath("libsdl", "test_filesystem");
|
||||
if(pref_path == NULL){
|
||||
if (pref_path == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find pref path: %s\n",
|
||||
SDL_GetError());
|
||||
} else {
|
||||
@@ -47,7 +47,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
pref_path = SDL_GetPrefPath(NULL, "test_filesystem");
|
||||
if(pref_path == NULL){
|
||||
if (pref_path == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find pref path without organization: %s\n",
|
||||
SDL_GetError());
|
||||
} else {
|
||||
|
||||
@@ -98,7 +98,7 @@ static SDL_GameControllerButton virtual_button_active = SDL_CONTROLLER_BUTTON_IN
|
||||
|
||||
static void UpdateWindowTitle()
|
||||
{
|
||||
if (!window) {
|
||||
if (window == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -190,13 +190,13 @@ static void AddController(int device_index, SDL_bool verbose)
|
||||
}
|
||||
|
||||
controller = SDL_GameControllerOpen(device_index);
|
||||
if (!controller) {
|
||||
if (controller == NULL) {
|
||||
SDL_Log("Couldn't open controller: %s\n", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
|
||||
controllers = (SDL_GameController **)SDL_realloc(gamecontrollers, (num_controllers + 1) * sizeof(*controllers));
|
||||
if (!controllers) {
|
||||
if (controllers == NULL) {
|
||||
SDL_GameControllerClose(controller);
|
||||
return;
|
||||
}
|
||||
@@ -403,7 +403,7 @@ static void OpenVirtualController()
|
||||
SDL_Log("Couldn't open virtual device: %s\n", SDL_GetError());
|
||||
} else {
|
||||
virtual_joystick = SDL_JoystickOpen(virtual_index);
|
||||
if (!virtual_joystick) {
|
||||
if (virtual_joystick == NULL) {
|
||||
SDL_Log("Couldn't open virtual device: %s\n", SDL_GetError());
|
||||
}
|
||||
}
|
||||
@@ -912,7 +912,7 @@ main(int argc, char *argv[])
|
||||
button_texture = LoadTexture(screen, "button.bmp", SDL_TRUE, NULL, NULL);
|
||||
axis_texture = LoadTexture(screen, "axis.bmp", SDL_TRUE, NULL, NULL);
|
||||
|
||||
if (!background_front || !background_back || !button_texture || !axis_texture) {
|
||||
if (background_front == NULL || background_back == NULL || button_texture == NULL || axis_texture == NULL) {
|
||||
SDL_DestroyRenderer(screen);
|
||||
SDL_DestroyWindow(window);
|
||||
return 2;
|
||||
|
||||
@@ -50,17 +50,17 @@ LoadSprite(const char *file)
|
||||
/* This does the SDL_LoadBMP step repeatedly, but that's OK for test code. */
|
||||
sprites[i] = LoadTexture(state->renderers[i], file, SDL_TRUE, &sprite_w, &sprite_h);
|
||||
if (!sprites[i]) {
|
||||
return (-1);
|
||||
return -1;
|
||||
}
|
||||
if (SDL_SetTextureBlendMode(sprites[i], blendMode) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s\n", SDL_GetError());
|
||||
SDL_DestroyTexture(sprites[i]);
|
||||
return (-1);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* We're ready to roll. :) */
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -99,8 +99,9 @@ loop()
|
||||
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
@@ -175,7 +176,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
@@ -219,7 +220,7 @@ main(int argc, char *argv[])
|
||||
/* Create the windows, initialize the renderers, and load the textures */
|
||||
sprites =
|
||||
(SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites));
|
||||
if (!sprites) {
|
||||
if (sprites == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
|
||||
quit(2);
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ drawCircle(SDL_Surface *screen, float x, float y, float r, unsigned int c)
|
||||
for (ty = (float) -SDL_fabs(r); ty <= (float) SDL_fabs((int) r); ty++) {
|
||||
xr = (float) SDL_sqrt(r * r - ty * ty);
|
||||
if (r > 0) { /* r > 0 ==> filled circle */
|
||||
for(tx = -xr + 0.5f; tx <= xr - 0.5f; tx++) {
|
||||
for (tx = -xr + 0.5f; tx <= xr - 0.5f; tx++) {
|
||||
setpix(screen, x + tx, y + ty, c);
|
||||
}
|
||||
} else {
|
||||
@@ -132,7 +132,7 @@ DrawScreen(SDL_Window *window)
|
||||
SDL_Surface *screen = SDL_GetWindowSurface(window);
|
||||
int i;
|
||||
|
||||
if (!screen) {
|
||||
if (screen == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ loop(void)
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -229,7 +229,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
@@ -405,8 +405,9 @@ main(int argc, char *argv[])
|
||||
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
int w, h;
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
SDL_GL_MakeCurrent(state->windows[i], context);
|
||||
if (update_swap_interval) {
|
||||
SDL_GL_SetSwapInterval(swap_interval);
|
||||
|
||||
@@ -119,7 +119,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
@@ -315,8 +315,9 @@ main(int argc, char *argv[])
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
|
||||
if (status) {
|
||||
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
|
||||
|
||||
@@ -114,7 +114,7 @@ quit(int rc)
|
||||
x; \
|
||||
{ \
|
||||
GLenum glError = ctx.glGetError(); \
|
||||
if(glError != GL_NO_ERROR) { \
|
||||
if (glError != GL_NO_ERROR) { \
|
||||
SDL_Log("glGetError() = %i (0x%.8x) at line %i\n", glError, glError, __LINE__); \
|
||||
quit(1); \
|
||||
} \
|
||||
@@ -239,7 +239,7 @@ process_shader(GLuint *shader, const char * source, GLint shader_type)
|
||||
GL_CHECK(ctx.glGetShaderiv(*shader, GL_COMPILE_STATUS, &status));
|
||||
|
||||
/* Dump debug info (source and log) if compilation failed. */
|
||||
if(status != GL_TRUE) {
|
||||
if (status != GL_TRUE) {
|
||||
ctx.glGetShaderInfoLog(*shader, sizeof(buffer), &length, &buffer[0]);
|
||||
buffer[length] = '\0';
|
||||
SDL_Log("Shader compilation failed: %s", buffer);
|
||||
@@ -260,7 +260,7 @@ link_program(struct shader_data *data)
|
||||
GL_CHECK(ctx.glLinkProgram(data->shader_program));
|
||||
GL_CHECK(ctx.glGetProgramiv(data->shader_program, GL_LINK_STATUS, &status));
|
||||
|
||||
if(status != GL_TRUE) {
|
||||
if (status != GL_TRUE) {
|
||||
ctx.glGetProgramInfoLog(data->shader_program, sizeof(buffer), &length, &buffer[0]);
|
||||
buffer[length] = '\0';
|
||||
SDL_Log("Program linking failed: %s", buffer);
|
||||
@@ -434,12 +434,24 @@ Render(unsigned int width, unsigned int height, shader_data* data)
|
||||
data->angle_y += 2;
|
||||
data->angle_z += 1;
|
||||
|
||||
if(data->angle_x >= 360) data->angle_x -= 360;
|
||||
if(data->angle_x < 0) data->angle_x += 360;
|
||||
if(data->angle_y >= 360) data->angle_y -= 360;
|
||||
if(data->angle_y < 0) data->angle_y += 360;
|
||||
if(data->angle_z >= 360) data->angle_z -= 360;
|
||||
if(data->angle_z < 0) data->angle_z += 360;
|
||||
if (data->angle_x >= 360) {
|
||||
data->angle_x -= 360;
|
||||
}
|
||||
if (data->angle_x < 0) {
|
||||
data->angle_x += 360;
|
||||
}
|
||||
if (data->angle_y >= 360) {
|
||||
data->angle_y -= 360;
|
||||
}
|
||||
if (data->angle_y < 0) {
|
||||
data->angle_y += 360;
|
||||
}
|
||||
if (data->angle_z >= 360) {
|
||||
data->angle_z -= 360;
|
||||
}
|
||||
if (data->angle_z < 0) {
|
||||
data->angle_z += 360;
|
||||
}
|
||||
|
||||
GL_CHECK(ctx.glViewport(0, 0, width, height));
|
||||
GL_CHECK(ctx.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
|
||||
@@ -555,7 +567,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
|
||||
@@ -117,7 +117,7 @@ quit(int rc)
|
||||
x; \
|
||||
{ \
|
||||
GLenum glError = ctx.glGetError(); \
|
||||
if(glError != GL_NO_ERROR) { \
|
||||
if (glError != GL_NO_ERROR) { \
|
||||
SDL_Log("glGetError() = %i (0x%.8x) at line %i\n", glError, glError, __LINE__); \
|
||||
quit(1); \
|
||||
} \
|
||||
@@ -154,7 +154,7 @@ process_shader(GLuint *shader, const char * source, GLint shader_type)
|
||||
GL_CHECK(ctx.glGetShaderiv(*shader, GL_COMPILE_STATUS, &status));
|
||||
|
||||
/* Dump debug info (source and log) if compilation failed. */
|
||||
if(status != GL_TRUE) {
|
||||
if (status != GL_TRUE) {
|
||||
ctx.glGetProgramInfoLog(*shader, sizeof(buffer), &length, &buffer[0]);
|
||||
buffer[length] = '\0';
|
||||
SDL_Log("Shader compilation failed: %s", buffer);fflush(stderr);
|
||||
@@ -357,10 +357,18 @@ void loop()
|
||||
}
|
||||
|
||||
|
||||
if (sym == SDLK_LEFT) g_val -= 0.05;
|
||||
if (sym == SDLK_RIGHT) g_val += 0.05;
|
||||
if (sym == SDLK_UP) g_angle -= 1;
|
||||
if (sym == SDLK_DOWN) g_angle += 1;
|
||||
if (sym == SDLK_LEFT) {
|
||||
g_val -= 0.05;
|
||||
}
|
||||
if (sym == SDLK_RIGHT) {
|
||||
g_val += 0.05;
|
||||
}
|
||||
if (sym == SDLK_UP) {
|
||||
g_angle -= 1;
|
||||
}
|
||||
if (sym == SDLK_DOWN) {
|
||||
g_angle += 1;
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
@@ -402,8 +410,7 @@ void loop()
|
||||
matrix_mvp[1][1] = -2.0f / 480.0;
|
||||
matrix_mvp[3][1] = 1.0f;
|
||||
|
||||
if (0)
|
||||
{
|
||||
if (0) {
|
||||
float *f = (float *) matrix_mvp;
|
||||
SDL_Log("-----------------------------------");
|
||||
SDL_Log("[ %f, %f, %f, %f ]", *f++, *f++, *f++, *f++);
|
||||
@@ -466,7 +473,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
@@ -564,8 +571,9 @@ main(int argc, char *argv[])
|
||||
#if 1
|
||||
path = GetNearbyFilename(f);
|
||||
|
||||
if (path == NULL)
|
||||
if (path == NULL) {
|
||||
path = SDL_strdup(f);
|
||||
}
|
||||
|
||||
if (path == NULL) {
|
||||
SDL_Log("out of memory\n");
|
||||
@@ -573,7 +581,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
tmp = SDL_LoadBMP(path);
|
||||
if (tmp == NULL) {
|
||||
if (tmp == NULL) {
|
||||
SDL_Log("missing image file: %s", path);
|
||||
exit(-1);
|
||||
} else {
|
||||
|
||||
@@ -78,8 +78,9 @@ main(int argc, char **argv)
|
||||
/* Try to find matching device */
|
||||
else {
|
||||
for (i = 0; i < SDL_NumHaptics(); i++) {
|
||||
if (SDL_strstr(SDL_HapticName(i), name) != NULL)
|
||||
if (SDL_strstr(SDL_HapticName(i), name) != NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= SDL_NumHaptics()) {
|
||||
@@ -283,8 +284,9 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* Quit */
|
||||
if (haptic != NULL)
|
||||
if (haptic != NULL) {
|
||||
SDL_HapticClose(haptic);
|
||||
}
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
@@ -317,40 +319,55 @@ HapticPrintSupported(SDL_Haptic * ptr)
|
||||
supported = SDL_HapticQuery(ptr);
|
||||
SDL_Log(" Supported effects [%d effects, %d playing]:\n",
|
||||
SDL_HapticNumEffects(ptr), SDL_HapticNumEffectsPlaying(ptr));
|
||||
if (supported & SDL_HAPTIC_CONSTANT)
|
||||
if (supported & SDL_HAPTIC_CONSTANT) {
|
||||
SDL_Log(" constant\n");
|
||||
if (supported & SDL_HAPTIC_SINE)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_SINE) {
|
||||
SDL_Log(" sine\n");
|
||||
}
|
||||
/* !!! FIXME: put this back when we have more bits in 2.1 */
|
||||
/* if (supported & SDL_HAPTIC_SQUARE)
|
||||
SDL_Log(" square\n"); */
|
||||
if (supported & SDL_HAPTIC_TRIANGLE)
|
||||
if (supported & SDL_HAPTIC_TRIANGLE) {
|
||||
SDL_Log(" triangle\n");
|
||||
if (supported & SDL_HAPTIC_SAWTOOTHUP)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_SAWTOOTHUP) {
|
||||
SDL_Log(" sawtoothup\n");
|
||||
if (supported & SDL_HAPTIC_SAWTOOTHDOWN)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_SAWTOOTHDOWN) {
|
||||
SDL_Log(" sawtoothdown\n");
|
||||
if (supported & SDL_HAPTIC_RAMP)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_RAMP) {
|
||||
SDL_Log(" ramp\n");
|
||||
if (supported & SDL_HAPTIC_FRICTION)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_FRICTION) {
|
||||
SDL_Log(" friction\n");
|
||||
if (supported & SDL_HAPTIC_SPRING)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_SPRING) {
|
||||
SDL_Log(" spring\n");
|
||||
if (supported & SDL_HAPTIC_DAMPER)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_DAMPER) {
|
||||
SDL_Log(" damper\n");
|
||||
if (supported & SDL_HAPTIC_INERTIA)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_INERTIA) {
|
||||
SDL_Log(" inertia\n");
|
||||
if (supported & SDL_HAPTIC_CUSTOM)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_CUSTOM) {
|
||||
SDL_Log(" custom\n");
|
||||
if (supported & SDL_HAPTIC_LEFTRIGHT)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_LEFTRIGHT) {
|
||||
SDL_Log(" left/right\n");
|
||||
}
|
||||
SDL_Log(" Supported capabilities:\n");
|
||||
if (supported & SDL_HAPTIC_GAIN)
|
||||
if (supported & SDL_HAPTIC_GAIN) {
|
||||
SDL_Log(" gain\n");
|
||||
if (supported & SDL_HAPTIC_AUTOCENTER)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_AUTOCENTER) {
|
||||
SDL_Log(" autocenter\n");
|
||||
if (supported & SDL_HAPTIC_STATUS)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_STATUS) {
|
||||
SDL_Log(" status\n");
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
@@ -74,8 +74,7 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (!done)
|
||||
{
|
||||
while (!done) {
|
||||
SDL_Event e;
|
||||
int nothing_to_do = 1;
|
||||
|
||||
@@ -108,7 +107,7 @@ int main(int argc, char **argv)
|
||||
if (e.key.keysym.sym == SDLK_ESCAPE) {
|
||||
done = 1;
|
||||
} else if (e.key.keysym.sym == SDLK_x) {
|
||||
if (!areas) {
|
||||
if (areas == NULL) {
|
||||
areas = drag_areas;
|
||||
numareas = SDL_arraysize(drag_areas);
|
||||
} else {
|
||||
|
||||
@@ -37,7 +37,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if(enable_haptic) {
|
||||
if (enable_haptic) {
|
||||
init_subsystems |= SDL_INIT_HAPTIC;
|
||||
}
|
||||
|
||||
@@ -57,39 +57,31 @@ main(int argc, char *argv[])
|
||||
*/
|
||||
|
||||
SDL_Log("There are %d joysticks at startup\n", SDL_NumJoysticks());
|
||||
if (enable_haptic)
|
||||
if (enable_haptic) {
|
||||
SDL_Log("There are %d haptic devices at startup\n", SDL_NumHaptics());
|
||||
}
|
||||
|
||||
while(keepGoing)
|
||||
{
|
||||
while (keepGoing) {
|
||||
SDL_Event event;
|
||||
while(SDL_PollEvent(&event))
|
||||
{
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch(event.type)
|
||||
{
|
||||
case SDL_QUIT:
|
||||
keepGoing = SDL_FALSE;
|
||||
break;
|
||||
case SDL_JOYDEVICEADDED:
|
||||
if (joystick != NULL)
|
||||
{
|
||||
if (joystick != NULL) {
|
||||
SDL_Log("Only one joystick supported by this test\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
joystick = SDL_JoystickOpen(event.jdevice.which);
|
||||
instance = SDL_JoystickInstanceID(joystick);
|
||||
SDL_Log("Joy Added : %" SDL_PRIs32 " : %s\n", event.jdevice.which, SDL_JoystickName(joystick));
|
||||
if (enable_haptic)
|
||||
{
|
||||
if (SDL_JoystickIsHaptic(joystick))
|
||||
{
|
||||
if (enable_haptic) {
|
||||
if (SDL_JoystickIsHaptic(joystick)) {
|
||||
haptic = SDL_HapticOpenFromJoystick(joystick);
|
||||
if (haptic)
|
||||
{
|
||||
if (haptic) {
|
||||
SDL_Log("Joy Haptic Opened\n");
|
||||
if (SDL_HapticRumbleInit( haptic ) != 0)
|
||||
{
|
||||
if (SDL_HapticRumbleInit( haptic ) != 0) {
|
||||
SDL_Log("Could not init Rumble!: %s\n", SDL_GetError());
|
||||
SDL_HapticClose(haptic);
|
||||
haptic = NULL;
|
||||
@@ -97,21 +89,17 @@ main(int argc, char *argv[])
|
||||
} else {
|
||||
SDL_Log("Joy haptic open FAILED!: %s\n", SDL_GetError());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SDL_Log("No haptic found\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_JOYDEVICEREMOVED:
|
||||
if (instance == event.jdevice.which)
|
||||
{
|
||||
if (instance == event.jdevice.which) {
|
||||
SDL_Log("Joy Removed: %" SDL_PRIs32 "\n", event.jdevice.which);
|
||||
instance = -1;
|
||||
if(enable_haptic && haptic)
|
||||
{
|
||||
if (enable_haptic && haptic) {
|
||||
SDL_HapticClose(haptic);
|
||||
haptic = NULL;
|
||||
}
|
||||
@@ -125,13 +113,13 @@ main(int argc, char *argv[])
|
||||
/*
|
||||
// SDL_Log("Axis Move: %d\n", event.jaxis.axis);
|
||||
*/
|
||||
if (enable_haptic)
|
||||
if (enable_haptic) {
|
||||
SDL_HapticRumblePlay(haptic, 0.25, 250);
|
||||
}
|
||||
break;
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
SDL_Log("Button Press: %d\n", event.jbutton.button);
|
||||
if(enable_haptic && haptic)
|
||||
{
|
||||
if (enable_haptic && haptic) {
|
||||
SDL_HapticRumblePlay(haptic, 0.25, 250);
|
||||
}
|
||||
if (event.jbutton.button == 0) {
|
||||
|
||||
@@ -62,9 +62,9 @@ main(int argc, char *argv[])
|
||||
|
||||
fname = GetResourceFilename(argc > 1 ? argv[1] : NULL, "utf8.txt");
|
||||
file = fopen(fname, "rb");
|
||||
if (!file) {
|
||||
if (file == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to open %s\n", fname);
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
SDL_free(fname);
|
||||
|
||||
@@ -93,5 +93,5 @@ main(int argc, char *argv[])
|
||||
fclose(file);
|
||||
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Total errors: %d\n", errors);
|
||||
return (errors ? errors + 1 : 0);
|
||||
return errors ? errors + 1 : 0;
|
||||
}
|
||||
|
||||
220
test/testime.c
220
test/testime.c
@@ -71,12 +71,13 @@ static Uint8 unifontTextureLoaded[UNIFONT_NUM_TEXTURES] = {0};
|
||||
|
||||
static Uint8 dehex(char c)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
if (c >= '0' && c <= '9') {
|
||||
return c - '0';
|
||||
else if (c >= 'a' && c <= 'f')
|
||||
} else if (c >= 'a' && c <= 'f') {
|
||||
return c - 'a' + 10;
|
||||
else if (c >= 'A' && c <= 'F')
|
||||
} else if (c >= 'A' && c <= 'F') {
|
||||
return c - 'A' + 10;
|
||||
}
|
||||
return 255;
|
||||
}
|
||||
|
||||
@@ -88,15 +89,16 @@ static Uint8 dehex2(char c1, char c2)
|
||||
static Uint8 validate_hex(const char *cp, size_t len, Uint32 *np)
|
||||
{
|
||||
Uint32 n = 0;
|
||||
for (; len > 0; cp++, len--)
|
||||
{
|
||||
for (; len > 0; cp++, len--) {
|
||||
Uint8 c = dehex(*cp);
|
||||
if (c == 255)
|
||||
if (c == 255) {
|
||||
return 0;
|
||||
}
|
||||
n = (n << 4) | c;
|
||||
}
|
||||
if (np != NULL)
|
||||
if (np != NULL) {
|
||||
*np = n;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -113,8 +115,7 @@ static int unifont_init(const char *fontname)
|
||||
|
||||
/* Allocate memory for the glyph data so the file can be closed after initialization. */
|
||||
unifontGlyph = (struct UnifontGlyph *)SDL_malloc(unifontGlyphSize);
|
||||
if (unifontGlyph == NULL)
|
||||
{
|
||||
if (unifontGlyph == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to allocate %d KiB for glyph data.\n", (int)(unifontGlyphSize + 1023) / 1024);
|
||||
return -1;
|
||||
}
|
||||
@@ -122,8 +123,7 @@ static int unifont_init(const char *fontname)
|
||||
|
||||
/* Allocate memory for texture pointers for all renderers. */
|
||||
unifontTexture = (SDL_Texture **)SDL_malloc(unifontTextureSize);
|
||||
if (unifontTexture == NULL)
|
||||
{
|
||||
if (unifontTexture == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to allocate %d KiB for texture pointer data.\n", (int)(unifontTextureSize + 1023) / 1024);
|
||||
return -1;
|
||||
}
|
||||
@@ -136,8 +136,7 @@ static int unifont_init(const char *fontname)
|
||||
}
|
||||
hexFile = SDL_RWFromFile(filename, "rb");
|
||||
SDL_free(filename);
|
||||
if (hexFile == NULL)
|
||||
{
|
||||
if (hexFile == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to open font file: %s\n", fontname);
|
||||
return -1;
|
||||
}
|
||||
@@ -150,10 +149,10 @@ static int unifont_init(const char *fontname)
|
||||
Uint32 codepoint;
|
||||
|
||||
bytesRead = SDL_RWread(hexFile, hexBuffer, 1, 9);
|
||||
if (numGlyphs > 0 && bytesRead == 0)
|
||||
if (numGlyphs > 0 && bytesRead == 0) {
|
||||
break; /* EOF */
|
||||
if ((numGlyphs == 0 && bytesRead == 0) || (numGlyphs > 0 && bytesRead < 9))
|
||||
{
|
||||
}
|
||||
if ((numGlyphs == 0 && bytesRead == 0) || (numGlyphs > 0 && bytesRead < 9)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Unexpected end of hex file.\n");
|
||||
return -1;
|
||||
}
|
||||
@@ -167,59 +166,54 @@ static int unifont_init(const char *fontname)
|
||||
codepointHexSize = 6;
|
||||
else if (hexBuffer[8] == ':')
|
||||
codepointHexSize = 8;
|
||||
else
|
||||
{
|
||||
else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Could not find codepoint and glyph data separator symbol in hex file on line %d.\n", lineNumber);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!validate_hex((const char *)hexBuffer, codepointHexSize, &codepoint))
|
||||
{
|
||||
if (!validate_hex((const char *)hexBuffer, codepointHexSize, &codepoint)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Malformed hexadecimal number in hex file on line %d.\n", lineNumber);
|
||||
return -1;
|
||||
}
|
||||
if (codepoint > UNIFONT_MAX_CODEPOINT)
|
||||
if (codepoint > UNIFONT_MAX_CODEPOINT) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "unifont: Codepoint on line %d exceeded limit of 0x%x.\n", lineNumber, UNIFONT_MAX_CODEPOINT);
|
||||
}
|
||||
|
||||
/* If there was glyph data read in the last file read, move it to the front of the buffer. */
|
||||
bytesOverread = 8 - codepointHexSize;
|
||||
if (codepointHexSize < 8)
|
||||
if (codepointHexSize < 8) {
|
||||
SDL_memmove(hexBuffer, hexBuffer + codepointHexSize + 1, bytesOverread);
|
||||
}
|
||||
bytesRead = SDL_RWread(hexFile, hexBuffer + bytesOverread, 1, 33 - bytesOverread);
|
||||
if (bytesRead < (33 - bytesOverread))
|
||||
{
|
||||
if (bytesRead < (33 - bytesOverread)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Unexpected end of hex file.\n");
|
||||
return -1;
|
||||
}
|
||||
if (hexBuffer[32] == '\n')
|
||||
glyphWidth = 8;
|
||||
else
|
||||
{
|
||||
else {
|
||||
glyphWidth = 16;
|
||||
bytesRead = SDL_RWread(hexFile, hexBuffer + 33, 1, 32);
|
||||
if (bytesRead < 32)
|
||||
{
|
||||
if (bytesRead < 32) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Unexpected end of hex file.\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!validate_hex((const char *)hexBuffer, glyphWidth * 4, NULL))
|
||||
{
|
||||
if (!validate_hex((const char *)hexBuffer, glyphWidth * 4, NULL)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Malformed hexadecimal glyph data in hex file on line %d.\n", lineNumber);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (codepoint <= UNIFONT_MAX_CODEPOINT)
|
||||
{
|
||||
if (codepoint <= UNIFONT_MAX_CODEPOINT) {
|
||||
if (unifontGlyph[codepoint].width > 0)
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "unifont: Ignoring duplicate codepoint 0x%08" SDL_PRIx32 " in hex file on line %d.\n", codepoint, lineNumber);
|
||||
else
|
||||
{
|
||||
else {
|
||||
unifontGlyph[codepoint].width = glyphWidth;
|
||||
/* Pack the hex data into a more compact form. */
|
||||
for (i = 0; i < glyphWidth * 2; i++)
|
||||
for (i = 0; i < glyphWidth * 2; i++) {
|
||||
unifontGlyph[codepoint].data[i] = dehex2(hexBuffer[i * 2], hexBuffer[i * 2 + 1]);
|
||||
}
|
||||
numGlyphs++;
|
||||
}
|
||||
}
|
||||
@@ -237,20 +231,15 @@ static void unifont_make_rgba(Uint8 *src, Uint8 *dst, Uint8 width)
|
||||
int i, j;
|
||||
Uint8 *row = dst;
|
||||
|
||||
for (i = 0; i < width * 2; i++)
|
||||
{
|
||||
for (i = 0; i < width * 2; i++) {
|
||||
Uint8 data = src[i];
|
||||
for (j = 0; j < 8; j++)
|
||||
{
|
||||
if (data & 0x80)
|
||||
{
|
||||
for (j = 0; j < 8; j++) {
|
||||
if (data & 0x80) {
|
||||
row[0] = textColor.r;
|
||||
row[1] = textColor.g;
|
||||
row[2] = textColor.b;
|
||||
row[3] = textColor.a;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
row[0] = 0;
|
||||
row[1] = 0;
|
||||
row[2] = 0;
|
||||
@@ -260,8 +249,7 @@ static void unifont_make_rgba(Uint8 *src, Uint8 *dst, Uint8 width)
|
||||
row += 4;
|
||||
}
|
||||
|
||||
if (width == 8 || (width == 16 && i % 2 == 1))
|
||||
{
|
||||
if (width == 8 || (width == 16 && i % 2 == 1)) {
|
||||
dst += UNIFONT_TEXTURE_PITCH;
|
||||
row = dst;
|
||||
}
|
||||
@@ -273,26 +261,22 @@ static int unifont_load_texture(Uint32 textureID)
|
||||
int i;
|
||||
Uint8 * textureRGBA;
|
||||
|
||||
if (textureID >= UNIFONT_NUM_TEXTURES)
|
||||
{
|
||||
if (textureID >= UNIFONT_NUM_TEXTURES) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Tried to load out of range texture %" SDL_PRIu32 "\n", textureID);
|
||||
return -1;
|
||||
}
|
||||
|
||||
textureRGBA = (Uint8 *)SDL_malloc(UNIFONT_TEXTURE_SIZE);
|
||||
if (textureRGBA == NULL)
|
||||
{
|
||||
if (textureRGBA == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to allocate %d MiB for a texture.\n", UNIFONT_TEXTURE_SIZE / 1024 / 1024);
|
||||
return -1;
|
||||
}
|
||||
SDL_memset(textureRGBA, 0, UNIFONT_TEXTURE_SIZE);
|
||||
|
||||
/* Copy the glyphs into memory in RGBA format. */
|
||||
for (i = 0; i < UNIFONT_GLYPHS_IN_TEXTURE; i++)
|
||||
{
|
||||
for (i = 0; i < UNIFONT_GLYPHS_IN_TEXTURE; i++) {
|
||||
Uint32 codepoint = UNIFONT_GLYPHS_IN_TEXTURE * textureID + i;
|
||||
if (unifontGlyph[codepoint].width > 0)
|
||||
{
|
||||
if (unifontGlyph[codepoint].width > 0) {
|
||||
const Uint32 cInTex = codepoint % UNIFONT_GLYPHS_IN_TEXTURE;
|
||||
const size_t offset = (cInTex / UNIFONT_GLYPHS_IN_ROW) * UNIFONT_TEXTURE_PITCH * 16 + (cInTex % UNIFONT_GLYPHS_IN_ROW) * 16 * 4;
|
||||
unifont_make_rgba(unifontGlyph[codepoint].data, textureRGBA + offset, unifontGlyph[codepoint].width);
|
||||
@@ -300,22 +284,20 @@ static int unifont_load_texture(Uint32 textureID)
|
||||
}
|
||||
|
||||
/* Create textures and upload the RGBA data from above. */
|
||||
for (i = 0; i < state->num_windows; ++i)
|
||||
{
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
SDL_Texture *tex = unifontTexture[UNIFONT_NUM_TEXTURES * i + textureID];
|
||||
if (state->windows[i] == NULL || renderer == NULL || tex != NULL)
|
||||
if (state->windows[i] == NULL || renderer == NULL || tex != NULL) {
|
||||
continue;
|
||||
}
|
||||
tex = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, UNIFONT_TEXTURE_WIDTH, UNIFONT_TEXTURE_WIDTH);
|
||||
if (tex == NULL)
|
||||
{
|
||||
if (tex == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to create texture %" SDL_PRIu32 " for renderer %d.\n", textureID, i);
|
||||
return -1;
|
||||
}
|
||||
unifontTexture[UNIFONT_NUM_TEXTURES * i + textureID] = tex;
|
||||
SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_BLEND);
|
||||
if (SDL_UpdateTexture(tex, NULL, textureRGBA, UNIFONT_TEXTURE_PITCH) != 0)
|
||||
{
|
||||
if (SDL_UpdateTexture(tex, NULL, textureRGBA, UNIFONT_TEXTURE_PITCH) != 0) {
|
||||
SDL_Log("unifont error: Failed to update texture %" SDL_PRIu32 " data for renderer %d.\n", textureID, i);
|
||||
}
|
||||
}
|
||||
@@ -340,8 +322,7 @@ static Sint32 unifont_draw_glyph(Uint32 codepoint, int rendererID, SDL_Rect *dst
|
||||
}
|
||||
}
|
||||
texture = unifontTexture[UNIFONT_NUM_TEXTURES * rendererID + textureID];
|
||||
if (texture != NULL)
|
||||
{
|
||||
if (texture != NULL) {
|
||||
const Uint32 cInTex = codepoint % UNIFONT_GLYPHS_IN_TEXTURE;
|
||||
srcrect.x = cInTex % UNIFONT_GLYPHS_IN_ROW * 16;
|
||||
srcrect.y = cInTex / UNIFONT_GLYPHS_IN_ROW * 16;
|
||||
@@ -353,21 +334,22 @@ static Sint32 unifont_draw_glyph(Uint32 codepoint, int rendererID, SDL_Rect *dst
|
||||
static void unifont_cleanup()
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < state->num_windows; ++i)
|
||||
{
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL || renderer == NULL)
|
||||
if (state->windows[i] == NULL || renderer == NULL) {
|
||||
continue;
|
||||
for (j = 0; j < UNIFONT_NUM_TEXTURES; j++)
|
||||
{
|
||||
}
|
||||
for (j = 0; j < UNIFONT_NUM_TEXTURES; j++) {
|
||||
SDL_Texture *tex = unifontTexture[UNIFONT_NUM_TEXTURES * i + j];
|
||||
if (tex != NULL)
|
||||
if (tex != NULL) {
|
||||
SDL_DestroyTexture(tex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < UNIFONT_NUM_TEXTURES; j++)
|
||||
unifontTextureLoaded[j] = 0;
|
||||
for (j = 0; j < UNIFONT_NUM_TEXTURES; j++) {
|
||||
unifontTextureLoaded[j] = 0;
|
||||
}
|
||||
|
||||
SDL_free(unifontTexture);
|
||||
SDL_free(unifontGlyph);
|
||||
@@ -395,14 +377,15 @@ char *utf8_next(char *p)
|
||||
{
|
||||
size_t len = utf8_length(*p);
|
||||
size_t i = 0;
|
||||
if (!len)
|
||||
if (!len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (; i < len; ++i)
|
||||
{
|
||||
for (; i < len; ++i) {
|
||||
++p;
|
||||
if (!*p)
|
||||
if (!*p) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
@@ -410,8 +393,7 @@ char *utf8_next(char *p)
|
||||
char *utf8_advance(char *p, size_t distance)
|
||||
{
|
||||
size_t i = 0;
|
||||
for (; i < distance && p; ++i)
|
||||
{
|
||||
for (; i < distance && p; ++i) {
|
||||
p = utf8_next(p);
|
||||
}
|
||||
return p;
|
||||
@@ -421,20 +403,20 @@ Uint32 utf8_decode(char *p, size_t len)
|
||||
{
|
||||
Uint32 codepoint = 0;
|
||||
size_t i = 0;
|
||||
if (!len)
|
||||
if (!len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (; i < len; ++i)
|
||||
{
|
||||
for (; i < len; ++i) {
|
||||
if (i == 0)
|
||||
codepoint = (0xff >> len) & *p;
|
||||
else
|
||||
{
|
||||
else {
|
||||
codepoint <<= 6;
|
||||
codepoint |= 0x3f & *p;
|
||||
}
|
||||
if (!*p)
|
||||
if (!*p) {
|
||||
return 0;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
@@ -481,8 +463,7 @@ void _Redraw(int rendererID)
|
||||
SDL_SetRenderDrawColor(renderer, backColor.r, backColor.g, backColor.b, backColor.a);
|
||||
SDL_RenderFillRect(renderer,&textRect);
|
||||
|
||||
if (*text)
|
||||
{
|
||||
if (*text) {
|
||||
#ifdef HAVE_SDL_TTF
|
||||
SDL_Surface *textSur = TTF_RenderUTF8_Blended(font, text, textColor);
|
||||
SDL_Texture *texture;
|
||||
@@ -510,8 +491,7 @@ void _Redraw(int rendererID)
|
||||
drawnTextRect.y = dstrect.y;
|
||||
drawnTextRect.h = dstrect.h;
|
||||
|
||||
while ((codepoint = utf8_decode(utext, len = utf8_length(*utext))))
|
||||
{
|
||||
while ((codepoint = utf8_decode(utext, len = utf8_length(*utext)))) {
|
||||
Sint32 advance = unifont_draw_glyph(codepoint, rendererID, &dstrect) * UNIFONT_DRAW_SCALE;
|
||||
dstrect.x += advance;
|
||||
drawnTextRect.w += advance;
|
||||
@@ -522,14 +502,11 @@ void _Redraw(int rendererID)
|
||||
|
||||
markedRect.x = textRect.x + drawnTextRect.w;
|
||||
markedRect.w = textRect.w - drawnTextRect.w;
|
||||
if (markedRect.w < 0)
|
||||
{
|
||||
if (markedRect.w < 0) {
|
||||
/* Stop text input because we cannot hold any more characters */
|
||||
SDL_StopTextInput();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SDL_StartTextInput();
|
||||
}
|
||||
|
||||
@@ -544,17 +521,16 @@ void _Redraw(int rendererID)
|
||||
SDL_SetRenderDrawColor(renderer, backColor.r, backColor.g, backColor.b, backColor.a);
|
||||
SDL_RenderFillRect(renderer,&markedRect);
|
||||
|
||||
if (markedText[0])
|
||||
{
|
||||
if (markedText[0]) {
|
||||
#ifdef HAVE_SDL_TTF
|
||||
SDL_Surface *textSur;
|
||||
SDL_Texture *texture;
|
||||
if (cursor)
|
||||
{
|
||||
if (cursor) {
|
||||
char *p = utf8_advance(markedText, cursor);
|
||||
char c = 0;
|
||||
if (!p)
|
||||
if (p == NULL) {
|
||||
p = &markedText[SDL_strlen(markedText)];
|
||||
}
|
||||
|
||||
c = *p;
|
||||
*p = 0;
|
||||
@@ -587,20 +563,19 @@ void _Redraw(int rendererID)
|
||||
drawnTextRect.y = dstrect.y;
|
||||
drawnTextRect.h = dstrect.h;
|
||||
|
||||
while ((codepoint = utf8_decode(utext, len = utf8_length(*utext))))
|
||||
{
|
||||
while ((codepoint = utf8_decode(utext, len = utf8_length(*utext)))) {
|
||||
Sint32 advance = unifont_draw_glyph(codepoint, rendererID, &dstrect) * UNIFONT_DRAW_SCALE;
|
||||
dstrect.x += advance;
|
||||
drawnTextRect.w += advance;
|
||||
if (i < cursor)
|
||||
if (i < cursor) {
|
||||
cursorRect.x += advance;
|
||||
}
|
||||
i++;
|
||||
utext += len;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (cursor > 0)
|
||||
{
|
||||
if (cursor > 0) {
|
||||
cursorRect.y = drawnTextRect.y;
|
||||
cursorRect.h = drawnTextRect.h;
|
||||
}
|
||||
@@ -625,8 +600,9 @@ void Redraw()
|
||||
int i;
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
@@ -648,21 +624,19 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;i++) {
|
||||
SDLTest_CommonArg(state, i);
|
||||
}
|
||||
for (argc--, argv++; argc > 0; argc--, argv++)
|
||||
{
|
||||
for (argc--, argv++; argc > 0; argc--, argv++) {
|
||||
if (SDL_strcmp(argv[0], "--help") == 0) {
|
||||
usage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
else if (SDL_strcmp(argv[0], "--font") == 0)
|
||||
{
|
||||
else if (SDL_strcmp(argv[0], "--font") == 0) {
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
@@ -685,8 +659,7 @@ int main(int argc, char *argv[])
|
||||
TTF_Init();
|
||||
|
||||
font = TTF_OpenFont(fontname, DEFAULT_PTSIZE);
|
||||
if (! font)
|
||||
{
|
||||
if (font == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to find font: %s\n", TTF_GetError());
|
||||
return -1;
|
||||
}
|
||||
@@ -723,42 +696,36 @@ int main(int argc, char *argv[])
|
||||
break;
|
||||
case SDLK_BACKSPACE:
|
||||
/* Only delete text if not in editing mode. */
|
||||
if (!markedText[0])
|
||||
{
|
||||
if (!markedText[0]) {
|
||||
size_t textlen = SDL_strlen(text);
|
||||
|
||||
do {
|
||||
if (textlen==0)
|
||||
{
|
||||
if (textlen==0) {
|
||||
break;
|
||||
}
|
||||
if ((text[textlen-1] & 0x80) == 0x00)
|
||||
{
|
||||
if ((text[textlen-1] & 0x80) == 0x00) {
|
||||
/* One byte */
|
||||
text[textlen-1]=0x00;
|
||||
break;
|
||||
}
|
||||
if ((text[textlen-1] & 0xC0) == 0x80)
|
||||
{
|
||||
if ((text[textlen-1] & 0xC0) == 0x80) {
|
||||
/* Byte from the multibyte sequence */
|
||||
text[textlen-1]=0x00;
|
||||
textlen--;
|
||||
}
|
||||
if ((text[textlen-1] & 0xC0) == 0xC0)
|
||||
{
|
||||
if ((text[textlen-1] & 0xC0) == 0xC0) {
|
||||
/* First byte of multibyte sequence */
|
||||
text[textlen-1]=0x00;
|
||||
break;
|
||||
}
|
||||
} while(1);
|
||||
} while (1);
|
||||
|
||||
Redraw();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (done)
|
||||
{
|
||||
if (done) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -770,14 +737,15 @@ int main(int argc, char *argv[])
|
||||
break;
|
||||
|
||||
case SDL_TEXTINPUT:
|
||||
if (event.text.text[0] == '\0' || event.text.text[0] == '\n' ||
|
||||
markedRect.w < 0)
|
||||
if (event.text.text[0] == '\0' || event.text.text[0] == '\n' || markedRect.w < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_Log("Keyboard: text input \"%s\"\n", event.text.text);
|
||||
|
||||
if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text))
|
||||
if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text)) {
|
||||
SDL_strlcat(text, event.text.text, sizeof(text));
|
||||
}
|
||||
|
||||
SDL_Log("text inputed: %s\n", text);
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include "SDL_test_common.h"
|
||||
|
||||
#define SWAP(typ,a,b) do{typ t=a;a=b;b=t;}while(0)
|
||||
#define SWAP(typ,a,b) do{typ t=a;a=b;b=t;}while (0)
|
||||
#define NUM_OBJECTS 100
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
@@ -86,10 +86,12 @@ SDL_Rect lines[MAX_LINES];
|
||||
static int
|
||||
add_line(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
if (num_lines >= MAX_LINES)
|
||||
if (num_lines >= MAX_LINES) {
|
||||
return 0;
|
||||
if ((x1 == x2) && (y1 == y2))
|
||||
}
|
||||
if ((x1 == x2) && (y1 == y2)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_Log("adding line (%d, %d), (%d, %d)\n", x1, y1, x2, y2);
|
||||
lines[num_lines].x = x1;
|
||||
@@ -130,15 +132,19 @@ SDL_Rect rects[MAX_RECTS];
|
||||
static int
|
||||
add_rect(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
if (num_rects >= MAX_RECTS)
|
||||
if (num_rects >= MAX_RECTS) {
|
||||
return 0;
|
||||
if ((x1 == x2) || (y1 == y2))
|
||||
}
|
||||
if ((x1 == x2) || (y1 == y2)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (x1 > x2)
|
||||
if (x1 > x2) {
|
||||
SWAP(int, x1, x2);
|
||||
if (y1 > y2)
|
||||
}
|
||||
if (y1 > y2) {
|
||||
SWAP(int, y1, y2);
|
||||
}
|
||||
|
||||
SDL_Log("adding rect (%d, %d), (%d, %d) [%dx%d]\n", x1, y1, x2, y2,
|
||||
x2 - x1, y2 - y1);
|
||||
@@ -213,12 +219,12 @@ loop()
|
||||
mouse_begin_y = event.button.y;
|
||||
break;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
if (event.button.button == 3)
|
||||
add_line(mouse_begin_x, mouse_begin_y, event.button.x,
|
||||
event.button.y);
|
||||
if (event.button.button == 1)
|
||||
add_rect(mouse_begin_x, mouse_begin_y, event.button.x,
|
||||
event.button.y);
|
||||
if (event.button.button == 3) {
|
||||
add_line(mouse_begin_x, mouse_begin_y, event.button.x, event.button.y);
|
||||
}
|
||||
if (event.button.button == 1) {
|
||||
add_rect(mouse_begin_x, mouse_begin_y, event.button.x, event.button.y);
|
||||
}
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
switch (event.key.keysym.sym) {
|
||||
@@ -244,8 +250,9 @@ loop()
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
@@ -278,7 +285,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
|
||||
@@ -118,7 +118,7 @@ loop(void *arg)
|
||||
|
||||
case SDL_JOYDEVICEADDED:
|
||||
SDL_Log("Joystick device %d added.\n", (int) event.jdevice.which);
|
||||
if (!joystick) {
|
||||
if (joystick == NULL) {
|
||||
joystick = SDL_JoystickOpen(event.jdevice.which);
|
||||
if (joystick) {
|
||||
PrintJoystick(joystick);
|
||||
@@ -144,16 +144,21 @@ loop(void *arg)
|
||||
case SDL_JOYHATMOTION:
|
||||
SDL_Log("Joystick %" SDL_PRIs32 " hat %d value:",
|
||||
event.jhat.which, event.jhat.hat);
|
||||
if (event.jhat.value == SDL_HAT_CENTERED)
|
||||
if (event.jhat.value == SDL_HAT_CENTERED) {
|
||||
SDL_Log(" centered");
|
||||
if (event.jhat.value & SDL_HAT_UP)
|
||||
}
|
||||
if (event.jhat.value & SDL_HAT_UP) {
|
||||
SDL_Log(" up");
|
||||
if (event.jhat.value & SDL_HAT_RIGHT)
|
||||
}
|
||||
if (event.jhat.value & SDL_HAT_RIGHT) {
|
||||
SDL_Log(" right");
|
||||
if (event.jhat.value & SDL_HAT_DOWN)
|
||||
}
|
||||
if (event.jhat.value & SDL_HAT_DOWN) {
|
||||
SDL_Log(" down");
|
||||
if (event.jhat.value & SDL_HAT_LEFT)
|
||||
}
|
||||
if (event.jhat.value & SDL_HAT_LEFT) {
|
||||
SDL_Log(" left");
|
||||
}
|
||||
SDL_Log("\n");
|
||||
break;
|
||||
case SDL_JOYBALLMOTION:
|
||||
|
||||
@@ -36,5 +36,5 @@ main(int argc, char *argv[])
|
||||
SDL_GetScancodeName(scancode));
|
||||
}
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -55,8 +55,9 @@ closemutex(int sig)
|
||||
int i;
|
||||
SDL_Log("Process %lu: Cleaning up...\n", id == mainthread ? 0 : id);
|
||||
SDL_AtomicSet(&doterminate, 1);
|
||||
for (i = 0; i < 6; ++i)
|
||||
for (i = 0; i < 6; ++i) {
|
||||
SDL_WaitThread(threads[i], NULL);
|
||||
}
|
||||
SDL_DestroyMutex(mutex);
|
||||
exit(sig);
|
||||
}
|
||||
@@ -64,8 +65,9 @@ closemutex(int sig)
|
||||
int SDLCALL
|
||||
Run(void *data)
|
||||
{
|
||||
if (SDL_ThreadID() == mainthread)
|
||||
if (SDL_ThreadID() == mainthread) {
|
||||
signal(SIGTERM, closemutex);
|
||||
}
|
||||
while (!SDL_AtomicGet(&doterminate)) {
|
||||
SDL_Log("Process %lu ready to work\n", SDL_ThreadID());
|
||||
if (SDL_LockMutex(mutex) < 0) {
|
||||
@@ -86,7 +88,7 @@ Run(void *data)
|
||||
SDL_Log("Process %lu: raising SIGTERM\n", SDL_ThreadID());
|
||||
raise(SIGTERM);
|
||||
}
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -118,11 +120,12 @@ main(int argc, char *argv[])
|
||||
for (i = 0; i < maxproc; ++i) {
|
||||
char name[64];
|
||||
SDL_snprintf(name, sizeof (name), "Worker%d", i);
|
||||
if ((threads[i] = SDL_CreateThread(Run, name, NULL)) == NULL)
|
||||
if ((threads[i] = SDL_CreateThread(Run, name, NULL)) == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread!\n");
|
||||
}
|
||||
}
|
||||
signal(SIGINT, terminate);
|
||||
Run(NULL);
|
||||
|
||||
return (0); /* Never reached */
|
||||
return 0; /* Never reached */
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ main(int argc, char *argv[])
|
||||
*/
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL video subsystem: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
{
|
||||
int status = 0;
|
||||
@@ -172,8 +172,7 @@ main(int argc, char *argv[])
|
||||
intptr_t eventNumber = SDL_RegisterEvents(1);
|
||||
SDL_Thread* thread = SDL_CreateThread(&button_messagebox, "MessageBox", (void*)eventNumber);
|
||||
|
||||
while (SDL_WaitEvent(&event))
|
||||
{
|
||||
while (SDL_WaitEvent(&event)) {
|
||||
if (event.type == eventNumber) {
|
||||
break;
|
||||
}
|
||||
@@ -204,8 +203,7 @@ main(int argc, char *argv[])
|
||||
quit(1);
|
||||
}
|
||||
|
||||
while (SDL_WaitEvent(&event))
|
||||
{
|
||||
while (SDL_WaitEvent(&event)) {
|
||||
if (event.type == SDL_QUIT || event.type == SDL_KEYUP) {
|
||||
break;
|
||||
}
|
||||
@@ -213,5 +211,5 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -133,15 +133,16 @@ loop(void *arg)
|
||||
break;
|
||||
|
||||
case SDL_MOUSEMOTION:
|
||||
if (!active)
|
||||
if (active == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
active->x2 = event.motion.x;
|
||||
active->y2 = event.motion.y;
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
if (!active) {
|
||||
if (active == NULL) {
|
||||
active = SDL_calloc(1, sizeof(*active));
|
||||
active->x1 = active->x2 = event.button.x;
|
||||
active->y1 = active->y2 = event.button.y;
|
||||
@@ -158,8 +159,9 @@ loop(void *arg)
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
if (!active)
|
||||
if (active == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (event.button.button) {
|
||||
case SDL_BUTTON_LEFT: buttons &= ~SDL_BUTTON_LMASK; break;
|
||||
@@ -210,8 +212,9 @@ loop(void *arg)
|
||||
|
||||
/* Objects from mouse clicks */
|
||||
DrawObjects(renderer);
|
||||
if (active)
|
||||
if (active) {
|
||||
DrawObject(renderer, active);
|
||||
}
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
|
||||
@@ -39,8 +39,9 @@ play_through_once(void *arg, Uint8 * stream, int len)
|
||||
Uint8 *waveptr = sound + cbdata->soundpos;
|
||||
int waveleft = soundlen - cbdata->soundpos;
|
||||
int cpy = len;
|
||||
if (cpy > waveleft)
|
||||
if (cpy > waveleft) {
|
||||
cpy = waveleft;
|
||||
}
|
||||
|
||||
SDL_memcpy(stream, waveptr, cpy);
|
||||
len -= cpy;
|
||||
@@ -105,7 +106,7 @@ test_multi_audio(int devcount)
|
||||
while (!SDL_AtomicGet(&cbd[0].done)) {
|
||||
#ifdef __ANDROID__
|
||||
/* Empty queue, some application events would prevent pause. */
|
||||
while (SDL_PollEvent(&event)){}
|
||||
while (SDL_PollEvent(&event)) {}
|
||||
#endif
|
||||
SDL_Delay(100);
|
||||
}
|
||||
@@ -143,7 +144,7 @@ test_multi_audio(int devcount)
|
||||
}
|
||||
#ifdef __ANDROID__
|
||||
/* Empty queue, some application events would prevent pause. */
|
||||
while (SDL_PollEvent(&event)){}
|
||||
while (SDL_PollEvent(&event)) {}
|
||||
#endif
|
||||
|
||||
SDL_Delay(100);
|
||||
@@ -173,7 +174,7 @@ main(int argc, char **argv)
|
||||
/* Load the SDL library */
|
||||
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
|
||||
|
||||
@@ -121,19 +121,19 @@ main(int argc, char *argv[])
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!factory) {
|
||||
if (factory == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find native window code for %s driver\n",
|
||||
driver);
|
||||
quit(2);
|
||||
}
|
||||
SDL_Log("Creating native window for %s driver\n", driver);
|
||||
native_window = factory->CreateNativeWindow(WINDOW_W, WINDOW_H);
|
||||
if (!native_window) {
|
||||
if (native_window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create native window\n");
|
||||
quit(3);
|
||||
}
|
||||
window = SDL_CreateWindowFrom(native_window);
|
||||
if (!window) {
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create SDL window: %s\n", SDL_GetError());
|
||||
quit(4);
|
||||
}
|
||||
@@ -141,7 +141,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Create the renderer */
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
if (!renderer) {
|
||||
if (renderer == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
|
||||
quit(5);
|
||||
}
|
||||
@@ -151,7 +151,7 @@ main(int argc, char *argv[])
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
sprite = LoadTexture(renderer, "icon.bmp", SDL_TRUE, NULL, NULL);
|
||||
if (!sprite) {
|
||||
if (sprite == NULL) {
|
||||
quit(6);
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ main(int argc, char *argv[])
|
||||
SDL_QueryTexture(sprite, NULL, NULL, &sprite_w, &sprite_h);
|
||||
positions = (SDL_Rect *) SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect));
|
||||
velocities = (SDL_Rect *) SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect));
|
||||
if (!positions || !velocities) {
|
||||
if (positions == NULL || velocities == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
|
||||
quit(2);
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ main(int argc, char *argv[])
|
||||
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||
width, height, 0);
|
||||
|
||||
if (!window) {
|
||||
if (window == NULL) {
|
||||
SDL_Log("Couldn't create window: %s\n",
|
||||
SDL_GetError());
|
||||
return SDL_FALSE;
|
||||
@@ -127,7 +127,7 @@ main(int argc, char *argv[])
|
||||
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
|
||||
if (!renderer) {
|
||||
if (renderer == NULL) {
|
||||
SDL_Log("Couldn't create renderer: %s\n",
|
||||
SDL_GetError());
|
||||
return SDL_FALSE;
|
||||
|
||||
@@ -342,21 +342,21 @@ main(int argc, char **argv)
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
window_w, window_h,
|
||||
SDL_WINDOW_RESIZABLE);
|
||||
if (!window) {
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create window: %s\n", SDL_GetError());
|
||||
SDL_free(RawMooseData);
|
||||
quit(4);
|
||||
}
|
||||
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
if (!renderer) {
|
||||
if (renderer == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create renderer: %s\n", SDL_GetError());
|
||||
SDL_free(RawMooseData);
|
||||
quit(4);
|
||||
}
|
||||
|
||||
MooseTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING, MOOSEPIC_W, MOOSEPIC_H);
|
||||
if (!MooseTexture) {
|
||||
if (MooseTexture == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError());
|
||||
SDL_free(RawMooseData);
|
||||
quit(5);
|
||||
|
||||
@@ -51,33 +51,34 @@ TestTypes(SDL_bool verbose)
|
||||
int error = 0;
|
||||
|
||||
if (badsize(sizeof(Uint8), 1)) {
|
||||
if (verbose)
|
||||
SDL_Log("sizeof(Uint8) != 1, instead = %u\n",
|
||||
(unsigned int)sizeof(Uint8));
|
||||
if (verbose) {
|
||||
SDL_Log("sizeof(Uint8) != 1, instead = %u\n", (unsigned int)sizeof(Uint8));
|
||||
}
|
||||
++error;
|
||||
}
|
||||
if (badsize(sizeof(Uint16), 2)) {
|
||||
if (verbose)
|
||||
SDL_Log("sizeof(Uint16) != 2, instead = %u\n",
|
||||
(unsigned int)sizeof(Uint16));
|
||||
if (verbose) {
|
||||
SDL_Log("sizeof(Uint16) != 2, instead = %u\n", (unsigned int)sizeof(Uint16));
|
||||
}
|
||||
++error;
|
||||
}
|
||||
if (badsize(sizeof(Uint32), 4)) {
|
||||
if (verbose)
|
||||
SDL_Log("sizeof(Uint32) != 4, instead = %u\n",
|
||||
(unsigned int)sizeof(Uint32));
|
||||
if (verbose) {
|
||||
SDL_Log("sizeof(Uint32) != 4, instead = %u\n", (unsigned int)sizeof(Uint32));
|
||||
}
|
||||
++error;
|
||||
}
|
||||
if (badsize(sizeof(Uint64), 8)) {
|
||||
if (verbose)
|
||||
SDL_Log("sizeof(Uint64) != 8, instead = %u\n",
|
||||
(unsigned int)sizeof(Uint64));
|
||||
if (verbose) {
|
||||
SDL_Log("sizeof(Uint64) != 8, instead = %u\n", (unsigned int)sizeof(Uint64));
|
||||
}
|
||||
++error;
|
||||
}
|
||||
if (verbose && !error)
|
||||
if (verbose && !error) {
|
||||
SDL_Log("All data types are the expected size.\n");
|
||||
}
|
||||
|
||||
return (error ? 1 : 0);
|
||||
return error ? 1 : 0;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -169,7 +170,7 @@ TestEndian(SDL_bool verbose)
|
||||
}
|
||||
++error;
|
||||
}
|
||||
return (error ? 1 : 0);
|
||||
return error ? 1 : 0;
|
||||
}
|
||||
|
||||
static int TST_allmul (void *a, void *b, int arg, void *result, void *expected)
|
||||
@@ -376,15 +377,17 @@ Test64Bit (SDL_bool verbose)
|
||||
unsigned int *rl = (unsigned int *)&result;
|
||||
|
||||
if (!t->routine(&t->a, &t->b, t->arg, &result, &t->expected_result)) {
|
||||
if (verbose)
|
||||
SDL_Log("%s(0x%08X%08X, 0x%08X%08X, %3d, produced: 0x%08X%08X, expected: 0x%08X%08X\n",
|
||||
t->operation, al[1], al[0], bl[1], bl[0], t->arg, rl[1], rl[0], el[1], el[0]);
|
||||
if (verbose) {
|
||||
SDL_Log("%s(0x%08X%08X, 0x%08X%08X, %3d, produced: 0x%08X%08X, expected: 0x%08X%08X\n", t->operation, al[1], al[0], bl[1], bl[0],
|
||||
t->arg, rl[1], rl[0], el[1], el[0]);
|
||||
}
|
||||
++failed;
|
||||
}
|
||||
}
|
||||
if (verbose && (failed == 0))
|
||||
if (verbose && (failed == 0)) {
|
||||
SDL_Log("All 64bit instrinsic tests passed\n");
|
||||
return (failed ? 1 : 0);
|
||||
}
|
||||
return failed ? 1 : 0;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -411,7 +414,7 @@ TestCPUInfo(SDL_bool verbose)
|
||||
SDL_Log("LASX %s\n", SDL_HasLASX()? "detected" : "not detected");
|
||||
SDL_Log("System RAM %d MB\n", SDL_GetSystemRAM());
|
||||
}
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -440,7 +443,7 @@ TestAssertions(SDL_bool verbose)
|
||||
item = item->next;
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
@@ -49,8 +49,7 @@ main(int argc, char *argv[])
|
||||
int iteration;
|
||||
SDLTest_RandomContext rndctx;
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
if (argc > 1) {
|
||||
int success;
|
||||
Uint64 seed = 0;
|
||||
if (argv[1][0] == '0' && argv[1][1] == 'x')
|
||||
@@ -66,9 +65,7 @@ main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
SDLTest_RandomInit(&rndctx, (unsigned int)(seed >> 32), (unsigned int)(seed & 0xffffffff));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SDLTest_RandomInitTime(&rndctx);
|
||||
}
|
||||
SDL_Log("Using random seed 0x%08x%08x\n", rndctx.x, rndctx.c);
|
||||
|
||||
@@ -35,7 +35,7 @@ DrawRects(SDL_Renderer * renderer)
|
||||
}
|
||||
|
||||
static void
|
||||
loop(){
|
||||
loop() {
|
||||
/* Check for events */
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
@@ -51,17 +51,26 @@ loop(){
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Rect viewport;
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
/* Wrap the cursor rectangle at the screen edges to keep it visible */
|
||||
SDL_RenderGetViewport(renderer, &viewport);
|
||||
if (rect.x < viewport.x) rect.x += viewport.w;
|
||||
if (rect.y < viewport.y) rect.y += viewport.h;
|
||||
if (rect.x > viewport.x + viewport.w) rect.x -= viewport.w;
|
||||
if (rect.y > viewport.y + viewport.h) rect.y -= viewport.h;
|
||||
if (rect.x < viewport.x) {
|
||||
rect.x += viewport.w;
|
||||
}
|
||||
if (rect.y < viewport.y) {
|
||||
rect.y += viewport.h;
|
||||
}
|
||||
if (rect.x > viewport.x + viewport.w) {
|
||||
rect.x -= viewport.w;
|
||||
}
|
||||
if (rect.y > viewport.y + viewport.h) {
|
||||
rect.y -= viewport.h;
|
||||
}
|
||||
|
||||
DrawRects(renderer);
|
||||
|
||||
@@ -83,7 +92,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc; ++i) {
|
||||
@@ -102,7 +111,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
srand((unsigned int)time(NULL));
|
||||
if(SDL_SetRelativeMouseMode(SDL_TRUE) < 0) {
|
||||
if (SDL_SetRelativeMouseMode(SDL_TRUE) < 0) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
|
||||
@@ -98,8 +98,9 @@ void loop()
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
Draw(&drawstates[i]);
|
||||
}
|
||||
#ifdef __EMSCRIPTEN__
|
||||
@@ -121,7 +122,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ Draw(DrawState *s)
|
||||
SDL_RenderGetViewport(s->renderer, &viewport);
|
||||
|
||||
target = SDL_CreateTexture(s->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, viewport.w, viewport.h);
|
||||
if (!target) {
|
||||
if (target == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create render target texture: %s\n", SDL_GetError());
|
||||
return SDL_FALSE;
|
||||
}
|
||||
@@ -183,12 +183,17 @@ loop()
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
if (test_composite) {
|
||||
if (!DrawComposite(&drawstates[i])) done = 1;
|
||||
if (!DrawComposite(&drawstates[i])) {
|
||||
done = 1;
|
||||
}
|
||||
} else {
|
||||
if (!Draw(&drawstates[i])) done = 1;
|
||||
if (!Draw(&drawstates[i])) {
|
||||
done = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef __EMSCRIPTEN__
|
||||
@@ -210,7 +215,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
|
||||
@@ -79,8 +79,9 @@ main(int argc, char **argv)
|
||||
/* Try to find matching device */
|
||||
else {
|
||||
for (i = 0; i < SDL_NumHaptics(); i++) {
|
||||
if (SDL_strstr(SDL_HapticName(i), name) != NULL)
|
||||
if (SDL_strstr(SDL_HapticName(i), name) != NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= SDL_NumHaptics()) {
|
||||
@@ -130,8 +131,9 @@ main(int argc, char **argv)
|
||||
SDL_Delay(2000);
|
||||
|
||||
/* Quit */
|
||||
if (haptic != NULL)
|
||||
if (haptic != NULL) {
|
||||
SDL_HapticClose(haptic);
|
||||
}
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -89,8 +89,9 @@ loop()
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
Draw(&drawstates[i]);
|
||||
}
|
||||
#ifdef __EMSCRIPTEN__
|
||||
@@ -112,7 +113,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -117,8 +117,9 @@ TestWaitTimeout(void)
|
||||
SDL_Log("Wait took %" SDL_PRIu32 " milliseconds\n\n", duration);
|
||||
|
||||
/* Check to make sure the return value indicates timed out */
|
||||
if (retval != SDL_MUTEX_TIMEDOUT)
|
||||
if (retval != SDL_MUTEX_TIMEDOUT) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_SemWaitTimeout returned: %d; expected: %d\n\n", retval, SDL_MUTEX_TIMEDOUT);
|
||||
}
|
||||
|
||||
SDL_DestroySemaphore(sem);
|
||||
}
|
||||
@@ -135,7 +136,7 @@ TestOverheadUncontended(void)
|
||||
SDL_Log("Doing %d uncontended Post/Wait operations on semaphore\n", NUM_OVERHEAD_OPS * NUM_OVERHEAD_OPS_MULT);
|
||||
|
||||
start_ticks = SDL_GetTicks();
|
||||
for (i = 0; i < NUM_OVERHEAD_OPS_MULT; i++){
|
||||
for (i = 0; i < NUM_OVERHEAD_OPS_MULT; i++) {
|
||||
for (j = 0; j < NUM_OVERHEAD_OPS; j++) {
|
||||
SDL_SemPost(sem);
|
||||
}
|
||||
@@ -157,14 +158,14 @@ ThreadFuncOverheadContended(void *data)
|
||||
Thread_State *state = (Thread_State *) data;
|
||||
|
||||
if (state->flag) {
|
||||
while(alive) {
|
||||
while (alive) {
|
||||
if (SDL_SemTryWait(sem) == SDL_MUTEX_TIMEDOUT) {
|
||||
++state->content_count;
|
||||
}
|
||||
++state->loop_count;
|
||||
}
|
||||
} else {
|
||||
while(alive) {
|
||||
while (alive) {
|
||||
/* Timeout needed to allow check on alive flag */
|
||||
if (SDL_SemWaitTimeout(sem, 50) == SDL_MUTEX_TIMEDOUT) {
|
||||
++state->content_count;
|
||||
@@ -251,13 +252,13 @@ main(int argc, char **argv)
|
||||
|
||||
if (argc < 2) {
|
||||
SDL_Log("Usage: %s init_value\n", argv[0]);
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Load the SDL library */
|
||||
if (SDL_Init(0) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
signal(SIGTERM, killed);
|
||||
signal(SIGINT, killed);
|
||||
@@ -276,5 +277,5 @@ main(int argc, char **argv)
|
||||
TestOverheadContended(SDL_TRUE);
|
||||
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ static const char *GetSensorTypeString(SDL_SensorType type)
|
||||
static void HandleSensorEvent(SDL_SensorEvent *event)
|
||||
{
|
||||
SDL_Sensor *sensor = SDL_SensorFromInstanceID(event->which);
|
||||
if (!sensor) {
|
||||
if (sensor == NULL) {
|
||||
SDL_Log("Couldn't get sensor for sensor event\n");
|
||||
return;
|
||||
}
|
||||
@@ -64,7 +64,7 @@ main(int argc, char **argv)
|
||||
/* Load the SDL library */
|
||||
if (SDL_Init(SDL_INIT_SENSOR) < 0) {
|
||||
SDL_Log("Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
num_sensors = SDL_NumSensors();
|
||||
@@ -117,5 +117,5 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ static SDL_bool CompileShader(GLhandleARB shader, const char *source)
|
||||
|
||||
glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
|
||||
info = (char *) SDL_malloc(length + 1);
|
||||
if (!info) {
|
||||
if (info == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
|
||||
} else {
|
||||
glGetInfoLogARB(shader, length, NULL, info);
|
||||
@@ -165,7 +165,7 @@ static SDL_bool LinkProgram(ShaderData *data)
|
||||
|
||||
glGetObjectParameterivARB(data->program, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
|
||||
info = (char *) SDL_malloc(length + 1);
|
||||
if (!info) {
|
||||
if (info == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
|
||||
} else {
|
||||
glGetInfoLogARB(data->program, length, NULL, info);
|
||||
@@ -463,7 +463,7 @@ int main(int argc, char **argv)
|
||||
|
||||
/* Create a 640x480 OpenGL screen */
|
||||
window = SDL_CreateWindow( "Shader Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL );
|
||||
if ( !window ) {
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create OpenGL window: %s\n", SDL_GetError());
|
||||
SDL_Quit();
|
||||
exit(2);
|
||||
@@ -476,7 +476,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
surface = SDL_LoadBMP("icon.bmp");
|
||||
if ( ! surface ) {
|
||||
if (surface == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to load icon.bmp: %s\n", SDL_GetError());
|
||||
SDL_Quit();
|
||||
exit(3);
|
||||
|
||||
@@ -58,30 +58,32 @@ int main(int argc,char** argv)
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
if(argc < 2) {
|
||||
if (argc < 2) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Shape requires at least one bitmap file as argument.");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if(SDL_VideoInit(NULL) == -1) {
|
||||
if (SDL_VideoInit(NULL) == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not initialize SDL video.");
|
||||
exit(-2);
|
||||
}
|
||||
|
||||
num_pictures = argc - 1;
|
||||
pictures = (LoadedPicture *)SDL_malloc(sizeof(LoadedPicture)*num_pictures);
|
||||
if (!pictures) {
|
||||
if (pictures == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not allocate memory.");
|
||||
exit(1);
|
||||
}
|
||||
for(i=0;i<num_pictures;i++)
|
||||
for (i = 0; i < num_pictures; i++) {
|
||||
pictures[i].surface = NULL;
|
||||
for(i=0;i<num_pictures;i++) {
|
||||
}
|
||||
for (i=0;i<num_pictures;i++) {
|
||||
pictures[i].surface = SDL_LoadBMP(argv[i+1]);
|
||||
pictures[i].name = argv[i+1];
|
||||
if(pictures[i].surface == NULL) {
|
||||
for(j=0;j<num_pictures;j++)
|
||||
if (pictures[i].surface == NULL) {
|
||||
for (j = 0; j < num_pictures; j++) {
|
||||
SDL_FreeSurface(pictures[j].surface);
|
||||
}
|
||||
SDL_free(pictures);
|
||||
SDL_VideoQuit();
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not load surface from named bitmap file: %s", argv[i+1]);
|
||||
@@ -89,11 +91,10 @@ int main(int argc,char** argv)
|
||||
}
|
||||
|
||||
format = pictures[i].surface->format;
|
||||
if(SDL_ISPIXELFORMAT_ALPHA(format->format)) {
|
||||
if (SDL_ISPIXELFORMAT_ALPHA(format->format)) {
|
||||
pictures[i].mode.mode = ShapeModeBinarizeAlpha;
|
||||
pictures[i].mode.parameters.binarizationCutoff = 255;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
pictures[i].mode.mode = ShapeModeColorKey;
|
||||
pictures[i].mode.parameters.colorKey = black;
|
||||
}
|
||||
@@ -104,35 +105,41 @@ int main(int argc,char** argv)
|
||||
SHAPED_WINDOW_DIMENSION,SHAPED_WINDOW_DIMENSION,
|
||||
0);
|
||||
SDL_SetWindowPosition(window, SHAPED_WINDOW_X, SHAPED_WINDOW_Y);
|
||||
if(window == NULL) {
|
||||
for(i=0;i<num_pictures;i++)
|
||||
if (window == NULL) {
|
||||
for (i = 0; i < num_pictures; i++) {
|
||||
SDL_FreeSurface(pictures[i].surface);
|
||||
}
|
||||
SDL_free(pictures);
|
||||
SDL_VideoQuit();
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create shaped window for SDL_Shape.");
|
||||
exit(-4);
|
||||
}
|
||||
renderer = SDL_CreateRenderer(window,-1,0);
|
||||
if (!renderer) {
|
||||
if (renderer == NULL) {
|
||||
SDL_DestroyWindow(window);
|
||||
for(i=0;i<num_pictures;i++)
|
||||
for (i = 0; i < num_pictures; i++) {
|
||||
SDL_FreeSurface(pictures[i].surface);
|
||||
}
|
||||
SDL_free(pictures);
|
||||
SDL_VideoQuit();
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create rendering context for SDL_Shape window.");
|
||||
exit(-5);
|
||||
}
|
||||
|
||||
for(i=0;i<num_pictures;i++)
|
||||
for (i = 0; i < num_pictures; i++) {
|
||||
pictures[i].texture = NULL;
|
||||
for(i=0;i<num_pictures;i++) {
|
||||
}
|
||||
for (i=0;i<num_pictures;i++) {
|
||||
pictures[i].texture = SDL_CreateTextureFromSurface(renderer,pictures[i].surface);
|
||||
if(pictures[i].texture == NULL) {
|
||||
for(i=0;i<num_pictures;i++)
|
||||
if(pictures[i].texture != NULL)
|
||||
if (pictures[i].texture == NULL) {
|
||||
for (i=0;i<num_pictures;i++) {
|
||||
if (pictures[i].texture != NULL) {
|
||||
SDL_DestroyTexture(pictures[i].texture);
|
||||
for(i=0;i<num_pictures;i++)
|
||||
}
|
||||
}
|
||||
for (i = 0; i < num_pictures; i++) {
|
||||
SDL_FreeSurface(pictures[i].surface);
|
||||
}
|
||||
SDL_free(pictures);
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
@@ -153,20 +160,21 @@ int main(int argc,char** argv)
|
||||
SDL_QueryTexture(pictures[current_picture].texture,(Uint32 *)&pixelFormat,(int *)&access,&texture_dimensions.w,&texture_dimensions.h);
|
||||
SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h);
|
||||
SDL_SetWindowShape(window,pictures[current_picture].surface,&pictures[current_picture].mode);
|
||||
while(should_exit == 0) {
|
||||
while (should_exit == 0) {
|
||||
while (SDL_PollEvent(&event)) {
|
||||
if(event.type == SDL_KEYDOWN) {
|
||||
if (event.type == SDL_KEYDOWN) {
|
||||
button_down = 1;
|
||||
if(event.key.keysym.sym == SDLK_ESCAPE) {
|
||||
if (event.key.keysym.sym == SDLK_ESCAPE) {
|
||||
should_exit = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(button_down && event.type == SDL_KEYUP) {
|
||||
if (button_down && event.type == SDL_KEYUP) {
|
||||
button_down = 0;
|
||||
current_picture += 1;
|
||||
if(current_picture >= num_pictures)
|
||||
if (current_picture >= num_pictures) {
|
||||
current_picture = 0;
|
||||
}
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Changing to shaped bmp: %s", pictures[current_picture].name);
|
||||
SDL_QueryTexture(pictures[current_picture].texture,(Uint32 *)&pixelFormat,(int *)&access,&texture_dimensions.w,&texture_dimensions.h);
|
||||
SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h);
|
||||
@@ -182,14 +190,16 @@ int main(int argc,char** argv)
|
||||
}
|
||||
|
||||
/* Free the textures. */
|
||||
for(i=0;i<num_pictures;i++)
|
||||
for (i = 0; i < num_pictures; i++) {
|
||||
SDL_DestroyTexture(pictures[i].texture);
|
||||
}
|
||||
SDL_DestroyRenderer(renderer);
|
||||
/* Destroy the window. */
|
||||
SDL_DestroyWindow(window);
|
||||
/* Free the original surfaces backing the textures. */
|
||||
for(i=0;i<num_pictures;i++)
|
||||
for (i = 0; i < num_pictures; i++) {
|
||||
SDL_FreeSurface(pictures[i].surface);
|
||||
}
|
||||
SDL_free(pictures);
|
||||
/* Call SDL_VideoQuit() before quitting. */
|
||||
SDL_VideoQuit();
|
||||
|
||||
@@ -73,17 +73,17 @@ LoadSprite(const char *file)
|
||||
/* This does the SDL_LoadBMP step repeatedly, but that's OK for test code. */
|
||||
sprites[i] = LoadTexture(state->renderers[i], file, SDL_TRUE, &sprite_w, &sprite_h);
|
||||
if (!sprites[i]) {
|
||||
return (-1);
|
||||
return -1;
|
||||
}
|
||||
if (SDL_SetTextureBlendMode(sprites[i], blendMode) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s\n", SDL_GetError());
|
||||
SDL_DestroyTexture(sprites[i]);
|
||||
return (-1);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* We're ready to roll. :) */
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -407,8 +407,9 @@ loop()
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
MoveSprites(state->renderers[i], sprites[i]);
|
||||
}
|
||||
#ifdef __EMSCRIPTEN__
|
||||
@@ -442,7 +443,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -474,7 +475,9 @@ main(int argc, char *argv[])
|
||||
} else if (SDL_strcasecmp(argv[i], "--iterations") == 0) {
|
||||
if (argv[i + 1]) {
|
||||
iterations = SDL_atoi(argv[i + 1]);
|
||||
if (iterations < -1) iterations = -1;
|
||||
if (iterations < -1) {
|
||||
iterations = -1;
|
||||
}
|
||||
consumed = 2;
|
||||
}
|
||||
} else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) {
|
||||
@@ -527,7 +530,7 @@ main(int argc, char *argv[])
|
||||
/* Create the windows, initialize the renderers, and load the textures */
|
||||
sprites =
|
||||
(SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites));
|
||||
if (!sprites) {
|
||||
if (sprites == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
|
||||
quit(2);
|
||||
}
|
||||
@@ -543,7 +546,7 @@ main(int argc, char *argv[])
|
||||
/* 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) {
|
||||
if (positions == NULL || velocities == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
|
||||
quit(2);
|
||||
}
|
||||
|
||||
@@ -161,19 +161,19 @@ main(int argc, char **argv)
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
MOOSEPIC_W*4, MOOSEPIC_H*4,
|
||||
SDL_WINDOW_RESIZABLE);
|
||||
if (!window) {
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create window: %s\n", SDL_GetError());
|
||||
quit(3);
|
||||
}
|
||||
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
if (!renderer) {
|
||||
if (renderer == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create renderer: %s\n", SDL_GetError());
|
||||
quit(4);
|
||||
}
|
||||
|
||||
MooseTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, MOOSEPIC_W, MOOSEPIC_H);
|
||||
if (!MooseTexture) {
|
||||
if (MooseTexture == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError());
|
||||
quit(5);
|
||||
}
|
||||
|
||||
@@ -57,14 +57,15 @@ ThreadFunc(void *data)
|
||||
|
||||
if (testprio) {
|
||||
SDL_Log("SDL_SetThreadPriority(%s):%d\n", getprioritystr(prio), SDL_SetThreadPriority(prio));
|
||||
if (++prio > SDL_THREAD_PRIORITY_TIME_CRITICAL)
|
||||
if (++prio > SDL_THREAD_PRIORITY_TIME_CRITICAL) {
|
||||
prio = SDL_THREAD_PRIORITY_LOW;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Delay(1 * 1000);
|
||||
}
|
||||
SDL_Log("Thread '%s' exiting!\n", (char *) data);
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -88,7 +89,7 @@ main(int argc, char *argv[])
|
||||
/* Load the SDL library */
|
||||
if (SDL_Init(0) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (SDL_getenv("SDL_TESTS_QUICK") != NULL) {
|
||||
@@ -132,5 +133,5 @@ main(int argc, char *argv[])
|
||||
raise(SIGTERM);
|
||||
|
||||
SDL_Quit(); /* Never reached */
|
||||
return (0); /* Never reached */
|
||||
return 0; /* Never reached */
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ static Uint32 SDLCALL
|
||||
ticktock(Uint32 interval, void *param)
|
||||
{
|
||||
++ticks;
|
||||
return (interval);
|
||||
return interval;
|
||||
}
|
||||
|
||||
static Uint32 SDLCALL
|
||||
@@ -51,7 +51,7 @@ main(int argc, char *argv[])
|
||||
|
||||
if (SDL_Init(SDL_INIT_TIMER) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (SDL_getenv("SDL_TESTS_QUICK") != NULL) {
|
||||
@@ -101,14 +101,17 @@ main(int argc, char *argv[])
|
||||
/* Test multiple timers */
|
||||
SDL_Log("Testing multiple timers...\n");
|
||||
t1 = SDL_AddTimer(100, callback, (void *) 1);
|
||||
if (!t1)
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Could not create timer 1: %s\n", SDL_GetError());
|
||||
if (!t1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create timer 1: %s\n", SDL_GetError());
|
||||
}
|
||||
t2 = SDL_AddTimer(50, callback, (void *) 2);
|
||||
if (!t2)
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Could not create timer 2: %s\n", SDL_GetError());
|
||||
if (!t2) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create timer 2: %s\n", SDL_GetError());
|
||||
}
|
||||
t3 = SDL_AddTimer(233, callback, (void *) 3);
|
||||
if (!t3)
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Could not create timer 3: %s\n", SDL_GetError());
|
||||
if (!t3) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create timer 3: %s\n", SDL_GetError());
|
||||
}
|
||||
|
||||
/* Wait 10 seconds */
|
||||
SDL_Log("Waiting 10 seconds\n");
|
||||
@@ -140,7 +143,7 @@ main(int argc, char *argv[])
|
||||
SDL_Log("Delay 1 second = %d ms in ticks, %d ms in ticks64, %f ms according to performance counter\n", (int) (now32-start32), (int) (now64-start64), (double)((now - start)*1000) / SDL_GetPerformanceFrequency());
|
||||
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -139,7 +139,7 @@ LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent,
|
||||
}
|
||||
|
||||
texture = SDL_CreateTextureFromSurface(renderer, temp);
|
||||
if (!texture) {
|
||||
if (texture == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,5 +43,5 @@ main(int argc, char *argv[])
|
||||
linked.major, linked.minor, linked.patch,
|
||||
SDL_GetRevision());
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -103,8 +103,9 @@ loop()
|
||||
int i;
|
||||
#ifdef __EMSCRIPTEN__
|
||||
/* Avoid using delays */
|
||||
if(SDL_GetTicks() - wait_start < 1000)
|
||||
if (SDL_GetTicks() - wait_start < 1000) {
|
||||
return;
|
||||
}
|
||||
wait_start = SDL_GetTicks();
|
||||
#endif
|
||||
/* Check for events */
|
||||
@@ -121,8 +122,9 @@ loop()
|
||||
SDL_Log("Current Viewport x=%i y=%i w=%i h=%i", viewport.x, viewport.y, viewport.w, viewport.h);
|
||||
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Draw using viewport */
|
||||
DrawOnViewport(state->renderers[i]);
|
||||
@@ -153,7 +155,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -233,7 +233,7 @@ static void createInstance(void)
|
||||
quit(2);
|
||||
}
|
||||
extensions = (const char **) SDL_malloc(sizeof(const char *) * extensionCount);
|
||||
if (!extensions) {
|
||||
if (extensions == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
quit(2);
|
||||
}
|
||||
@@ -309,7 +309,7 @@ static void findPhysicalDevice(void)
|
||||
quit(2);
|
||||
}
|
||||
physicalDevices = (VkPhysicalDevice *) SDL_malloc(sizeof(VkPhysicalDevice) * physicalDeviceCount);
|
||||
if (!physicalDevices) {
|
||||
if (physicalDevices == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
quit(2);
|
||||
}
|
||||
@@ -331,7 +331,7 @@ static void findPhysicalDevice(void)
|
||||
|
||||
VkPhysicalDevice physicalDevice = physicalDevices[physicalDeviceIndex];
|
||||
vkGetPhysicalDeviceProperties(physicalDevice, &vulkanContext->physicalDeviceProperties);
|
||||
if(VK_VERSION_MAJOR(vulkanContext->physicalDeviceProperties.apiVersion) < 1) {
|
||||
if (VK_VERSION_MAJOR(vulkanContext->physicalDeviceProperties.apiVersion) < 1) {
|
||||
continue;
|
||||
}
|
||||
vkGetPhysicalDeviceFeatures(physicalDevice, &vulkanContext->physicalDeviceFeatures);
|
||||
@@ -343,7 +343,7 @@ static void findPhysicalDevice(void)
|
||||
SDL_free(queueFamiliesProperties);
|
||||
queueFamiliesPropertiesAllocatedSize = queueFamiliesCount;
|
||||
queueFamiliesProperties = (VkQueueFamilyProperties *) SDL_malloc(sizeof(VkQueueFamilyProperties) * queueFamiliesPropertiesAllocatedSize);
|
||||
if (!queueFamiliesProperties) {
|
||||
if (queueFamiliesProperties == NULL) {
|
||||
SDL_free(physicalDevices);
|
||||
SDL_free(deviceExtensions);
|
||||
SDL_OutOfMemory();
|
||||
@@ -389,8 +389,7 @@ static void findPhysicalDevice(void)
|
||||
continue;
|
||||
}
|
||||
result = vkEnumerateDeviceExtensionProperties(physicalDevice, NULL, &deviceExtensionCount, NULL);
|
||||
if (result != VK_SUCCESS)
|
||||
{
|
||||
if (result != VK_SUCCESS) {
|
||||
SDL_free(physicalDevices);
|
||||
SDL_free(queueFamiliesProperties);
|
||||
SDL_free(deviceExtensions);
|
||||
@@ -406,7 +405,7 @@ static void findPhysicalDevice(void)
|
||||
SDL_free(deviceExtensions);
|
||||
deviceExtensionsAllocatedSize = deviceExtensionCount;
|
||||
deviceExtensions = SDL_malloc(sizeof(VkExtensionProperties) * deviceExtensionsAllocatedSize);
|
||||
if (!deviceExtensions) {
|
||||
if (deviceExtensions == NULL) {
|
||||
SDL_free(physicalDevices);
|
||||
SDL_free(queueFamiliesProperties);
|
||||
SDL_OutOfMemory();
|
||||
@@ -424,7 +423,7 @@ static void findPhysicalDevice(void)
|
||||
quit(2);
|
||||
}
|
||||
for (i = 0; i < deviceExtensionCount; i++) {
|
||||
if(SDL_strcmp(deviceExtensions[i].extensionName, VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
|
||||
if (SDL_strcmp(deviceExtensions[i].extensionName, VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
|
||||
hasSwapchainExtension = SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
@@ -641,7 +640,7 @@ static SDL_bool createSwapchain(void)
|
||||
} else {
|
||||
vulkanContext->surfaceFormat = vulkanContext->surfaceFormats[0];
|
||||
for (i = 0; i < vulkanContext->surfaceFormatsCount; i++) {
|
||||
if(vulkanContext->surfaceFormats[i].format == VK_FORMAT_R8G8B8A8_UNORM) {
|
||||
if (vulkanContext->surfaceFormats[i].format == VK_FORMAT_R8G8B8A8_UNORM) {
|
||||
vulkanContext->surfaceFormat = vulkanContext->surfaceFormats[i];
|
||||
break;
|
||||
}
|
||||
@@ -687,7 +686,7 @@ static SDL_bool createSwapchain(void)
|
||||
vkDestroySwapchainKHR(vulkanContext->device, createInfo.oldSwapchain, NULL);
|
||||
}
|
||||
|
||||
if(result != VK_SUCCESS) {
|
||||
if (result != VK_SUCCESS) {
|
||||
vulkanContext->swapchain = VK_NULL_HANDLE;
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"vkCreateSwapchainKHR(): %s\n",
|
||||
@@ -756,7 +755,7 @@ static void createCommandBuffers(void)
|
||||
allocateInfo.commandBufferCount = vulkanContext->swapchainImageCount;
|
||||
vulkanContext->commandBuffers = (VkCommandBuffer *) SDL_malloc(sizeof(VkCommandBuffer) * vulkanContext->swapchainImageCount);
|
||||
result = vkAllocateCommandBuffers(vulkanContext->device, &allocateInfo, vulkanContext->commandBuffers);
|
||||
if(result != VK_SUCCESS) {
|
||||
if (result != VK_SUCCESS) {
|
||||
SDL_free(vulkanContext->commandBuffers);
|
||||
vulkanContext->commandBuffers = NULL;
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
@@ -781,8 +780,8 @@ static void createFences(void)
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
||||
createInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
|
||||
result = vkCreateFence(vulkanContext->device, &createInfo, NULL, &vulkanContext->fences[i]);
|
||||
if(result != VK_SUCCESS) {
|
||||
for(; i > 0; i--) {
|
||||
if (result != VK_SUCCESS) {
|
||||
for (; i > 0; i--) {
|
||||
vkDestroyFence(vulkanContext->device, vulkanContext->fences[i - 1], NULL);
|
||||
}
|
||||
SDL_free(vulkanContext->fences);
|
||||
@@ -851,7 +850,7 @@ static void rerecordCommandBuffer(uint32_t frameIndex, const VkClearColorValue *
|
||||
VkImageSubresourceRange clearRange = {0};
|
||||
|
||||
VkResult result = vkResetCommandBuffer(commandBuffer, 0);
|
||||
if(result != VK_SUCCESS) {
|
||||
if (result != VK_SUCCESS) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"vkResetCommandBuffer(): %s\n",
|
||||
getVulkanResultString(result));
|
||||
@@ -909,7 +908,7 @@ static SDL_bool createNewSwapchainAndSwapchainSpecificStuff(void)
|
||||
destroySwapchainAndSwapchainSpecificStuff(SDL_FALSE);
|
||||
getSurfaceCaps();
|
||||
getSurfaceFormats();
|
||||
if(!createSwapchain()) {
|
||||
if (!createSwapchain()) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
createCommandPool();
|
||||
@@ -925,7 +924,7 @@ static void initVulkan(void)
|
||||
SDL_Vulkan_LoadLibrary(NULL);
|
||||
|
||||
vulkanContexts = (VulkanContext *) SDL_calloc(state->num_windows, sizeof (VulkanContext));
|
||||
if (!vulkanContexts) {
|
||||
if (vulkanContexts == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
|
||||
quit(2);
|
||||
}
|
||||
@@ -1000,8 +999,9 @@ static SDL_bool render(void)
|
||||
|
||||
if (!vulkanContext->swapchain) {
|
||||
SDL_bool retval = createNewSwapchainAndSwapchainSpecificStuff();
|
||||
if(!retval)
|
||||
if (!retval) {
|
||||
SDL_Delay(100);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
result = vkAcquireNextImageKHR(vulkanContext->device,
|
||||
@@ -1068,7 +1068,7 @@ static SDL_bool render(void)
|
||||
quit(2);
|
||||
}
|
||||
SDL_Vulkan_GetDrawableSize(vulkanContext->window, &w, &h);
|
||||
if(w != (int)vulkanContext->swapchainSize.width || h != (int)vulkanContext->swapchainSize.height) {
|
||||
if (w != (int)vulkanContext->swapchainSize.width || h != (int)vulkanContext->swapchainSize.height) {
|
||||
return createNewSwapchainAndSwapchainSpecificStuff();
|
||||
}
|
||||
return SDL_TRUE;
|
||||
@@ -1087,7 +1087,7 @@ int main(int argc, char **argv)
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if(!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1117,7 +1117,7 @@ int main(int argc, char **argv)
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
frames++;
|
||||
while(SDL_PollEvent(&event)) {
|
||||
while (SDL_PollEvent(&event)) {
|
||||
/* Need to destroy the swapchain before the window created
|
||||
* by SDL.
|
||||
*/
|
||||
|
||||
@@ -264,7 +264,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ main(int argc, char *argv[])
|
||||
|
||||
quit(0);
|
||||
/* keep the compiler happy ... */
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -25,9 +25,7 @@
|
||||
/* Return true if the YUV format is packed pixels */
|
||||
static SDL_bool is_packed_yuv_format(Uint32 format)
|
||||
{
|
||||
return (format == SDL_PIXELFORMAT_YUY2 ||
|
||||
format == SDL_PIXELFORMAT_UYVY ||
|
||||
format == SDL_PIXELFORMAT_YVYU);
|
||||
return format == SDL_PIXELFORMAT_YUY2 || format == SDL_PIXELFORMAT_UYVY || format == SDL_PIXELFORMAT_YVYU;
|
||||
}
|
||||
|
||||
/* Create a surface with a good pattern for verifying YUV conversion */
|
||||
@@ -79,7 +77,7 @@ static SDL_bool verify_yuv_data(Uint32 format, const Uint8 *yuv, int yuv_pitch,
|
||||
SDL_bool result = SDL_FALSE;
|
||||
|
||||
rgb = (Uint8 *)SDL_malloc(size);
|
||||
if (!rgb) {
|
||||
if (rgb == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory");
|
||||
return SDL_FALSE;
|
||||
}
|
||||
@@ -130,7 +128,7 @@ static int run_automated_tests(int pattern_size, int extra_pitch)
|
||||
int yuv1_pitch, yuv2_pitch;
|
||||
int result = -1;
|
||||
|
||||
if (!pattern || !yuv1 || !yuv2) {
|
||||
if (pattern == NULL || yuv1 == NULL || yuv2 == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't allocate test surfaces");
|
||||
goto done;
|
||||
}
|
||||
@@ -332,7 +330,7 @@ main(int argc, char **argv)
|
||||
filename = "testyuv.bmp";
|
||||
}
|
||||
original = SDL_ConvertSurfaceFormat(SDL_LoadBMP(filename), SDL_PIXELFORMAT_RGB24, 0);
|
||||
if (!original) {
|
||||
if (original == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError());
|
||||
return 3;
|
||||
}
|
||||
@@ -344,7 +342,7 @@ main(int argc, char **argv)
|
||||
pitch = CalculateYUVPitch(yuv_format, original->w);
|
||||
|
||||
converted = SDL_CreateRGBSurfaceWithFormat(0, original->w, original->h, 0, rgb_format);
|
||||
if (!converted) {
|
||||
if (converted == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create converted surface: %s\n", SDL_GetError());
|
||||
return 3;
|
||||
}
|
||||
@@ -361,13 +359,13 @@ main(int argc, char **argv)
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
original->w, original->h,
|
||||
0);
|
||||
if (!window) {
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
|
||||
return 4;
|
||||
}
|
||||
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
if (!renderer) {
|
||||
if (renderer == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
|
||||
return 4;
|
||||
}
|
||||
@@ -402,8 +400,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
{ int done = 0;
|
||||
while ( !done )
|
||||
{
|
||||
while ( !done ) {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event) > 0) {
|
||||
if (event.type == SDL_QUIT) {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
static float clip3(float x, float y, float z)
|
||||
{
|
||||
return ((z < x) ? x : ((z > y) ? y : z));
|
||||
return (z < x) ? x : ((z > y) ? y : z);
|
||||
}
|
||||
|
||||
static void RGBtoYUV(Uint8 * rgb, int *yuv, SDL_YUV_CONVERSION_MODE mode, int monochrome, int luminance)
|
||||
@@ -68,8 +68,9 @@ static void RGBtoYUV(Uint8 * rgb, int *yuv, SDL_YUV_CONVERSION_MODE mode, int mo
|
||||
|
||||
if (luminance != 100) {
|
||||
yuv[0] = yuv[0] * luminance / 100;
|
||||
if (yuv[0] > 255)
|
||||
if (yuv[0] > 255) {
|
||||
yuv[0] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,7 +292,7 @@ int CalculateYUVPitch(Uint32 format, int width)
|
||||
case SDL_PIXELFORMAT_YUY2:
|
||||
case SDL_PIXELFORMAT_UYVY:
|
||||
case SDL_PIXELFORMAT_YVYU:
|
||||
return 4*((width + 1)/2);
|
||||
return 4 * ((width + 1) / 2);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ main(int argc, char *argv[])
|
||||
/* Load the SDL library */
|
||||
if (SDL_Init(0) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
signal(SIGSEGV, SIG_DFL);
|
||||
@@ -109,5 +109,5 @@ main(int argc, char *argv[])
|
||||
SDL_WaitThread(threads[i], NULL);
|
||||
}
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user