Update for SDL3 coding style (#6717)

I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base.

In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted.

The script I ran for the src directory is added as build-scripts/clang-format-src.sh

This fixes:
#6592
#6593
#6594

(cherry picked from commit 5750bcb174)
This commit is contained in:
Sam Lantinga
2022-11-30 12:51:59 -08:00
parent 5c4bc807f7
commit b8d85c6939
764 changed files with 50598 additions and 54407 deletions

View File

@@ -49,8 +49,8 @@ print_string(char **text, size_t *maxlen, const char *fmt, ...)
len = SDL_vsnprintf(*text, *maxlen, fmt, ap);
if (len > 0) {
*text += len;
if ( ((size_t) len) < *maxlen ) {
*maxlen -= (size_t) len;
if (((size_t)len) < *maxlen) {
*maxlen -= (size_t)len;
} else {
*maxlen = 0;
}
@@ -121,7 +121,7 @@ PrintModifierState()
}
static void
PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat)
PrintKey(SDL_Keysym *sym, SDL_bool pressed, SDL_bool repeat)
{
char message[512];
char *spot;
@@ -133,17 +133,17 @@ PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat)
/* Print the keycode, name and state */
if (sym->sym) {
print_string(&spot, &left,
"Key %s: scancode %d = %s, keycode 0x%08X = %s ",
pressed ? "pressed " : "released",
sym->scancode,
SDL_GetScancodeName(sym->scancode),
sym->sym, SDL_GetKeyName(sym->sym));
"Key %s: scancode %d = %s, keycode 0x%08X = %s ",
pressed ? "pressed " : "released",
sym->scancode,
SDL_GetScancodeName(sym->scancode),
sym->sym, SDL_GetKeyName(sym->sym));
} else {
print_string(&spot, &left,
"Unknown Key (scancode %d = %s) %s ",
sym->scancode,
SDL_GetScancodeName(sym->scancode),
pressed ? "pressed " : "released");
"Unknown Key (scancode %d = %s) %s ",
sym->scancode,
SDL_GetScancodeName(sym->scancode),
pressed ? "pressed " : "released");
}
print_modifiers(&spot, &left);
if (repeat) {
@@ -159,15 +159,14 @@ 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);
}
SDL_Log("%s Text (%s): \"%s%s\"\n", eventtype, expanded, *text == '"' ? "\\" : "", text);
}
void
loop()
void loop()
{
SDL_Event event;
/* Check for events */
@@ -249,8 +248,7 @@ loop()
#endif
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
@@ -273,14 +271,14 @@ main(int argc, char *argv[])
640, 480, 0);
if (window == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create 640x480 window: %s\n",
SDL_GetError());
SDL_GetError());
quit(2);
}
renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n",
SDL_GetError());
SDL_GetError());
quit(2);
}

View File

@@ -45,8 +45,8 @@ print_string(char **text, size_t *maxlen, const char *fmt, ...)
len = SDL_vsnprintf(*text, *maxlen, fmt, ap);
if (len > 0) {
*text += len;
if ( ((size_t) len) < *maxlen ) {
*maxlen -= (size_t) len;
if (((size_t)len) < *maxlen) {
*maxlen -= (size_t)len;
} else {
*maxlen = 0;
}
@@ -117,7 +117,7 @@ PrintModifierState()
}
static void
PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat)
PrintKey(SDL_Keysym *sym, SDL_bool pressed, SDL_bool repeat)
{
char message[512];
char *spot;
@@ -129,17 +129,17 @@ PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat)
/* Print the keycode, name and state */
if (sym->sym) {
print_string(&spot, &left,
"Key %s: scancode %d = %s, keycode 0x%08X = %s ",
pressed ? "pressed " : "released",
sym->scancode,
SDL_GetScancodeName(sym->scancode),
sym->sym, SDL_GetKeyName(sym->sym));
"Key %s: scancode %d = %s, keycode 0x%08X = %s ",
pressed ? "pressed " : "released",
sym->scancode,
SDL_GetScancodeName(sym->scancode),
sym->sym, SDL_GetKeyName(sym->sym));
} else {
print_string(&spot, &left,
"Unknown Key (scancode %d = %s) %s ",
sym->scancode,
SDL_GetScancodeName(sym->scancode),
pressed ? "pressed " : "released");
"Unknown Key (scancode %d = %s) %s ",
sym->scancode,
SDL_GetScancodeName(sym->scancode),
pressed ? "pressed " : "released");
}
print_modifiers(&spot, &left);
if (repeat) {
@@ -156,21 +156,21 @@ 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);
}
SDL_Log("%s Text (%s): \"%s%s\"\n", eventtype, expanded, *text == '"' ? "\\" : "", text);
}
void
loop()
void loop()
{
SDL_Event event;
/* Check for events */
/*SDL_WaitEvent(&event); emscripten does not like waiting*/
fprintf(stderr, "starting loop\n"); fflush(stderr);
fprintf(stderr, "starting loop\n");
fflush(stderr);
// while (SDL_PollEvent(&event)) {
while (!done && SDL_WaitEvent(&event)) {
fprintf(stderr, "got event type: %" SDL_PRIu32 "\n", event.type);
@@ -188,7 +188,8 @@ loop()
break;
case SDL_MOUSEBUTTONDOWN:
/* Left button quits the app, other buttons toggles text input */
fprintf(stderr, "mouse button down button: %d (LEFT=%d)\n", event.button.button, SDL_BUTTON_LEFT); fflush(stderr);
fprintf(stderr, "mouse button down button: %d (LEFT=%d)\n", event.button.button, SDL_BUTTON_LEFT);
fflush(stderr);
if (event.button.button == SDL_BUTTON_LEFT) {
done = 1;
} else {
@@ -207,9 +208,11 @@ loop()
default:
break;
}
fprintf(stderr, "waiting new event\n"); fflush(stderr);
fprintf(stderr, "waiting new event\n");
fflush(stderr);
}
fprintf(stderr, "exiting event loop\n"); fflush(stderr);
fprintf(stderr, "exiting event loop\n");
fflush(stderr);
#ifdef __EMSCRIPTEN__
if (done) {
emscripten_cancel_main_loop();
@@ -222,9 +225,10 @@ static int SDLCALL ping_thread(void *ptr)
{
int cnt;
SDL_Event sdlevent;
SDL_memset(&sdlevent, 0 , sizeof(SDL_Event));
SDL_memset(&sdlevent, 0, sizeof(SDL_Event));
for (cnt = 0; cnt < 10; ++cnt) {
fprintf(stderr, "sending event (%d/%d) from thread.\n", cnt + 1, 10); fflush(stderr);
fprintf(stderr, "sending event (%d/%d) from thread.\n", cnt + 1, 10);
fflush(stderr);
sdlevent.type = SDL_KEYDOWN;
sdlevent.key.keysym.sym = SDLK_1;
SDL_PushEvent(&sdlevent);
@@ -233,8 +237,7 @@ static int SDLCALL ping_thread(void *ptr)
return cnt;
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
SDL_Window *window;
SDL_Renderer *renderer;
@@ -255,7 +258,7 @@ main(int argc, char *argv[])
640, 480, 0);
if (window == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create 640x480 window: %s\n",
SDL_GetError());
SDL_GetError());
quit(2);
}

View File

@@ -25,10 +25,11 @@
/* Define this for verbose output while mapping controllers */
#define DEBUG_CONTROLLERMAP
#define SCREEN_WIDTH 512
#define SCREEN_HEIGHT 320
#define SCREEN_WIDTH 512
#define SCREEN_HEIGHT 320
enum marker_type {
enum marker_type
{
MARKER_BUTTON,
MARKER_AXIS,
};
@@ -64,10 +65,10 @@ static struct
{ 174, 132, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_BACK */
{ 232, 128, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_GUIDE */
{ 289, 132, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_START */
{ 75, 154, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_LEFTSTICK */
{ 75, 154, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_LEFTSTICK */
{ 305, 230, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_RIGHTSTICK */
{ 77, 40, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_LEFTSHOULDER */
{ 396, 36, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_RIGHTSHOULDER */
{ 77, 40, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_LEFTSHOULDER */
{ 396, 36, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_RIGHTSHOULDER */
{ 154, 188, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_DPAD_UP */
{ 154, 249, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_DPAD_DOWN */
{ 116, 217, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_DPAD_LEFT */
@@ -77,16 +78,16 @@ static struct
{ 330, 135, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_PADDLE2 */
{ 132, 175, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_PADDLE3 */
{ 330, 175, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_PADDLE4 */
{ 0, 0, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_TOUCHPAD */
{ 74, 153, 270.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTX_NEGATIVE */
{ 74, 153, 90.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTX_POSITIVE */
{ 74, 153, 0.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTY_NEGATIVE */
{ 74, 153, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTY_POSITIVE */
{ 0, 0, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_TOUCHPAD */
{ 74, 153, 270.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTX_NEGATIVE */
{ 74, 153, 90.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTX_POSITIVE */
{ 74, 153, 0.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTY_NEGATIVE */
{ 74, 153, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTY_POSITIVE */
{ 306, 231, 270.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTX_NEGATIVE */
{ 306, 231, 90.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTX_POSITIVE */
{ 306, 231, 0.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTY_NEGATIVE */
{ 306, 231, 90.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTX_POSITIVE */
{ 306, 231, 0.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTY_NEGATIVE */
{ 306, 231, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTY_POSITIVE */
{ 91, -20, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_TRIGGERLEFT */
{ 91, -20, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_TRIGGERLEFT */
{ 375, -20, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_TRIGGERRIGHT */
};
SDL_COMPILE_TIME_ASSERT(s_arrBindingDisplay, SDL_arraysize(s_arrBindingDisplay) == BINDING_COUNT);
@@ -133,13 +134,15 @@ typedef struct
{
int button;
struct {
struct
{
int axis;
int axis_min;
int axis_max;
} axis;
struct {
struct
{
int hat;
int hat_mask;
} hat;
@@ -162,7 +165,7 @@ typedef struct
static int s_nNumAxes;
static AxisState *s_arrAxisState;
static int s_iCurrentBinding;
static Uint32 s_unPendingAdvanceTime;
static SDL_bool s_bBindingComplete;
@@ -175,9 +178,9 @@ static SDL_bool bind_touchpad = SDL_FALSE;
static int
StandardizeAxisValue(int nValue)
{
if (nValue > SDL_JOYSTICK_AXIS_MAX/2) {
if (nValue > SDL_JOYSTICK_AXIS_MAX / 2) {
return SDL_JOYSTICK_AXIS_MAX;
} else if (nValue < SDL_JOYSTICK_AXIS_MIN/2) {
} else if (nValue < SDL_JOYSTICK_AXIS_MIN / 2) {
return SDL_JOYSTICK_AXIS_MIN;
} else {
return 0;
@@ -205,8 +208,7 @@ SetCurrentBinding(int iBinding)
}
if (s_arrBindingOrder[iBinding] == SDL_CONTROLLER_BUTTON_TOUCHPAD &&
!bind_touchpad)
{
!bind_touchpad) {
SetCurrentBinding(iBinding + 1);
return;
}
@@ -229,8 +231,7 @@ BBindingContainsBinding(const SDL_GameControllerExtendedBind *pBindingA, const S
if (pBindingA->bindType != pBindingB->bindType) {
return SDL_FALSE;
}
switch (pBindingA->bindType)
{
switch (pBindingA->bindType) {
case SDL_CONTROLLER_BINDTYPE_AXIS:
if (pBindingA->value.axis.axis != pBindingB->value.axis.axis) {
return SDL_FALSE;
@@ -280,19 +281,18 @@ ConfigureBinding(const SDL_GameControllerExtendedBind *pBinding)
}
#ifdef DEBUG_CONTROLLERMAP
switch ( pBinding->bindType )
{
switch (pBinding->bindType) {
case SDL_CONTROLLER_BINDTYPE_NONE:
break;
break;
case SDL_CONTROLLER_BINDTYPE_BUTTON:
SDL_Log("Configuring button binding for button %d\n", pBinding->value.button);
break;
SDL_Log("Configuring button binding for button %d\n", pBinding->value.button);
break;
case SDL_CONTROLLER_BINDTYPE_AXIS:
SDL_Log("Configuring axis binding for axis %d %d/%d committed = %s\n", pBinding->value.axis.axis, pBinding->value.axis.axis_min, pBinding->value.axis.axis_max, pBinding->committed ? "true" : "false");
break;
SDL_Log("Configuring axis binding for axis %d %d/%d committed = %s\n", pBinding->value.axis.axis, pBinding->value.axis.axis_min, pBinding->value.axis.axis_max, pBinding->committed ? "true" : "false");
break;
case SDL_CONTROLLER_BINDTYPE_HAT:
SDL_Log("Configuring hat binding for hat %d %d\n", pBinding->value.hat.hat, pBinding->value.hat.hat_mask);
break;
SDL_Log("Configuring hat binding for hat %d %d\n", pBinding->value.hat.hat, pBinding->value.hat.hat_mask);
break;
}
#endif /* DEBUG_CONTROLLERMAP */
@@ -301,7 +301,7 @@ ConfigureBinding(const SDL_GameControllerExtendedBind *pBinding)
if (pCurrent->bindType != SDL_CONTROLLER_BINDTYPE_NONE) {
SDL_bool bNativeDPad, bCurrentDPad;
SDL_bool bNativeAxis, bCurrentAxis;
bNativeDPad = (iCurrentElement == SDL_CONTROLLER_BUTTON_DPAD_UP ||
iCurrentElement == SDL_CONTROLLER_BUTTON_DPAD_DOWN ||
iCurrentElement == SDL_CONTROLLER_BUTTON_DPAD_LEFT ||
@@ -335,7 +335,7 @@ static SDL_bool
BMergeAxisBindings(int iIndex)
{
SDL_GameControllerExtendedBind *pBindingA = &s_arrBindings[iIndex];
SDL_GameControllerExtendedBind *pBindingB = &s_arrBindings[iIndex+1];
SDL_GameControllerExtendedBind *pBindingB = &s_arrBindings[iIndex + 1];
if (pBindingA->bindType == SDL_CONTROLLER_BINDTYPE_AXIS &&
pBindingB->bindType == SDL_CONTROLLER_BINDTYPE_AXIS &&
pBindingA->value.axis.axis == pBindingB->value.axis.axis) {
@@ -350,13 +350,13 @@ BMergeAxisBindings(int iIndex)
}
static void
WatchJoystick(SDL_Joystick * joystick)
WatchJoystick(SDL_Joystick *joystick)
{
SDL_Texture *background_front, *background_back, *button, *axis, *marker=NULL;
SDL_Texture *background_front, *background_back, *button, *axis, *marker = NULL;
const char *name = NULL;
SDL_Event event;
SDL_Rect dst;
Uint8 alpha=200, alpha_step = -1;
Uint8 alpha = 200, alpha_step = -1;
Uint32 alpha_ticks = 0;
SDL_JoystickID nJoystickID;
@@ -374,9 +374,9 @@ WatchJoystick(SDL_Joystick * joystick)
SDL_Log("Watching joystick %" SDL_PRIs32 ": (%s)\n", SDL_JoystickInstanceID(joystick),
name ? name : "Unknown Joystick");
SDL_Log("Joystick has %d axes, %d hats, %d balls, and %d buttons\n",
SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
SDL_Log("\n\n\
====================================================================================\n\
Press the buttons on your controller when indicated\n\
@@ -401,14 +401,14 @@ WatchJoystick(SDL_Joystick * joystick)
int iElement = s_arrBindingOrder[s_iCurrentBinding];
switch (s_arrBindingDisplay[iElement].marker) {
case MARKER_AXIS:
marker = axis;
break;
case MARKER_BUTTON:
marker = button;
break;
case MARKER_AXIS:
marker = axis;
break;
case MARKER_BUTTON:
marker = button;
break;
}
dst.x = s_arrBindingDisplay[iElement].x;
dst.y = s_arrBindingDisplay[iElement].y;
SDL_QueryTexture(marker, NULL, NULL, &dst.w, &dst.h);
@@ -436,7 +436,7 @@ WatchJoystick(SDL_Joystick * joystick)
SDL_SetTextureColorMod(marker, 10, 255, 21);
SDL_RenderCopyEx(screen, marker, NULL, &dst, s_arrBindingDisplay[iElement].angle, NULL, SDL_FLIP_NONE);
SDL_RenderPresent(screen);
while (SDL_PollEvent(&event) > 0) {
switch (event.type) {
case SDL_JOYDEVICEREMOVED:
@@ -446,7 +446,7 @@ WatchJoystick(SDL_Joystick * joystick)
break;
case SDL_JOYAXISMOTION:
if (event.jaxis.which == nJoystickID) {
const int MAX_ALLOWED_JITTER = SDL_JOYSTICK_AXIS_MAX / 80; /* ShanWan PS3 controller needed 96 */
const int MAX_ALLOWED_JITTER = SDL_JOYSTICK_AXIS_MAX / 80; /* ShanWan PS3 controller needed 96 */
AxisState *pAxisState = &s_arrAxisState[event.jaxis.axis];
int nValue = event.jaxis.value;
int nCurrentDistance, nFarthestDistance;
@@ -702,12 +702,11 @@ WatchJoystick(SDL_Joystick * joystick)
SDL_free(s_arrAxisState);
s_arrAxisState = NULL;
SDL_DestroyRenderer(screen);
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
const char *name;
int i;
@@ -772,11 +771,11 @@ main(int argc, char *argv[])
joystick = SDL_JoystickOpen(i);
if (joystick == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_JoystickOpen(%d) failed: %s\n", i,
SDL_GetError());
SDL_GetError());
} else {
char guid[64];
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick),
guid, sizeof (guid));
guid, sizeof(guid));
SDL_Log(" axes: %d\n", SDL_JoystickNumAxes(joystick));
SDL_Log(" balls: %d\n", SDL_JoystickNumBalls(joystick));
SDL_Log(" hats: %d\n", SDL_JoystickNumHats(joystick));

View File

@@ -30,9 +30,9 @@
static struct
{
SDL_AudioSpec spec;
Uint8 *sound; /* Pointer to wave data */
Uint32 soundlen; /* Length of wave data */
int soundpos; /* Current play position */
Uint8 *sound; /* Pointer to wave data */
Uint32 soundlen; /* Length of wave data */
int soundpos; /* Current play position */
} wave;
static SDL_AudioDeviceID device;
@@ -65,7 +65,6 @@ open_audio()
quit(2);
}
/* Let the audio run */
SDL_PauseAudioDevice(device, SDL_FALSE);
}
@@ -79,7 +78,7 @@ static void reopen_audio()
#endif
void SDLCALL
fillerup(void *unused, Uint8 * stream, int len)
fillerup(void *unused, Uint8 *stream, int len)
{
Uint8 *waveptr;
int waveleft;
@@ -104,8 +103,7 @@ fillerup(void *unused, Uint8 * stream, int len)
static int done = 0;
#ifdef __EMSCRIPTEN__
void
loop()
void loop()
{
if (done || (SDL_GetAudioDeviceStatus(device) != SDL_AUDIO_PLAYING)) {
emscripten_cancel_main_loop();
@@ -113,8 +111,7 @@ loop()
}
#endif
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int i;
char *filename = NULL;
@@ -123,7 +120,7 @@ main(int argc, char *argv[])
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Load the SDL library */
if (SDL_Init(SDL_INIT_AUDIO|SDL_INIT_EVENTS) < 0) {
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;
}

View File

@@ -30,11 +30,10 @@
static struct
{
SDL_AudioSpec spec;
Uint8 *sound; /* Pointer to wave data */
Uint32 soundlen; /* Length of wave data */
Uint8 *sound; /* Pointer to wave data */
Uint32 soundlen; /* Length of wave data */
} wave;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
quit(int rc)
@@ -44,14 +43,12 @@ quit(int rc)
}
static int done = 0;
void
poked(int sig)
void poked(int sig)
{
done = 1;
}
void
loop()
void loop()
{
#ifdef __EMSCRIPTEN__
if (done || (SDL_GetAudioStatus() != SDL_AUDIO_PLAYING)) {
@@ -61,19 +58,18 @@ loop()
{
/* The device from SDL_OpenAudio() is always device #1. */
const Uint32 queued = SDL_GetQueuedAudioSize(1);
SDL_Log("Device has %u bytes queued.\n", (unsigned int) queued);
if (queued <= 8192) { /* time to requeue the whole thing? */
SDL_Log("Device has %u bytes queued.\n", (unsigned int)queued);
if (queued <= 8192) { /* time to requeue the whole thing? */
if (SDL_QueueAudio(1, wave.sound, wave.soundlen) == 0) {
SDL_Log("Device queued %u more bytes.\n", (unsigned int) wave.soundlen);
SDL_Log("Device queued %u more bytes.\n", (unsigned int)wave.soundlen);
} else {
SDL_Log("Device FAILED to queue %u more bytes: %s\n", (unsigned int) wave.soundlen, SDL_GetError());
SDL_Log("Device FAILED to queue %u more bytes: %s\n", (unsigned int)wave.soundlen, SDL_GetError());
}
}
}
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
char *filename = NULL;
@@ -99,7 +95,7 @@ main(int argc, char *argv[])
quit(1);
}
wave.spec.callback = NULL; /* we'll push audio. */
wave.spec.callback = NULL; /* we'll push audio. */
#if HAVE_SIGNAL_H
/* Set the signals */
@@ -130,14 +126,14 @@ main(int argc, char *argv[])
/* Note that we stuff the entire audio buffer into the queue in one
shot. Most apps would want to feed it a little at a time, as it
plays, but we're going for simplicity here. */
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(loop, 0, 1);
#else
while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING)) {
loop();
SDL_Delay(100); /* let it play for awhile. */
SDL_Delay(100); /* let it play for awhile. */
}
#endif

View File

@@ -18,22 +18,20 @@
after calling each function.
*/
static
const char *
static const char *
tf(SDL_bool _tf)
{
static const char *t = "TRUE";
static const char *f = "FALSE";
if (_tf) {
return t;
return t;
}
return f;
}
static
void RunBasicTest()
static void RunBasicTest()
{
int value;
SDL_SpinLock lock = 0;
@@ -95,15 +93,16 @@ void RunBasicTest()
/* Number of concurrent incrementers */
#define NThreads 2
#define CountInc 100
#define VALBITS (sizeof(atomicValue)*8)
#define VALBITS (sizeof(atomicValue) * 8)
#define atomicValue int
#define CountTo ((atomicValue)((unsigned int)(1<<(VALBITS-1))-1))
#define NInter (CountTo/CountInc/NThreads)
#define Expect (CountTo-NInter*CountInc*NThreads)
#define CountTo ((atomicValue)((unsigned int)(1 << (VALBITS - 1)) - 1))
#define NInter (CountTo / CountInc / NThreads)
#define Expect (CountTo - NInter * CountInc * NThreads)
enum {
CountTo_GreaterThanZero = CountTo > 0,
enum
{
CountTo_GreaterThanZero = CountTo > 0,
};
SDL_COMPILE_TIME_ASSERT(size, CountTo_GreaterThanZero); /* check for rollover */
@@ -115,25 +114,23 @@ static SDL_atomic_t threadsRunning;
static SDL_sem *threadDone;
static
int SDLCALL adder(void* junk)
static int SDLCALL adder(void *junk)
{
unsigned long N=NInter;
SDL_Log("Thread subtracting %d %lu times\n",CountInc,N);
unsigned long N = NInter;
SDL_Log("Thread subtracting %d %lu times\n", CountInc, N);
while (N--) {
SDL_AtomicAdd(&good, -CountInc);
bad-=CountInc;
bad -= CountInc;
}
SDL_AtomicAdd(&threadsRunning, -1);
SDL_SemPost(threadDone);
return 0;
}
static
void runAdder(void)
static void runAdder(void)
{
Uint32 start, end;
int T=NThreads;
int T = NThreads;
start = SDL_GetTicks();
@@ -156,8 +153,7 @@ void runAdder(void)
SDL_Log("Finished in %f sec\n", (end - start) / 1000.f);
}
static
void RunEpicTest()
static void RunEpicTest()
{
int b;
atomicValue v;
@@ -165,80 +161,80 @@ void RunEpicTest()
SDL_Log("\nepic test---------------------------------------\n\n");
SDL_Log("Size asserted to be >= 32-bit\n");
SDL_assert(sizeof(atomicValue)>=4);
SDL_assert(sizeof(atomicValue) >= 4);
SDL_Log("Check static initializer\n");
v=SDL_AtomicGet(&good);
SDL_assert(v==42);
v = SDL_AtomicGet(&good);
SDL_assert(v == 42);
SDL_assert(bad==42);
SDL_assert(bad == 42);
SDL_Log("Test negative values\n");
SDL_AtomicSet(&good, -5);
v=SDL_AtomicGet(&good);
SDL_assert(v==-5);
v = SDL_AtomicGet(&good);
SDL_assert(v == -5);
SDL_Log("Verify maximum value\n");
SDL_AtomicSet(&good, CountTo);
v=SDL_AtomicGet(&good);
SDL_assert(v==CountTo);
v = SDL_AtomicGet(&good);
SDL_assert(v == CountTo);
SDL_Log("Test compare and exchange\n");
b=SDL_AtomicCAS(&good, 500, 43);
b = SDL_AtomicCAS(&good, 500, 43);
SDL_assert(!b); /* no swap since CountTo!=500 */
v=SDL_AtomicGet(&good);
SDL_assert(v==CountTo); /* ensure no swap */
v = SDL_AtomicGet(&good);
SDL_assert(v == CountTo); /* ensure no swap */
b=SDL_AtomicCAS(&good, CountTo, 44);
b = SDL_AtomicCAS(&good, CountTo, 44);
SDL_assert(!!b); /* will swap */
v=SDL_AtomicGet(&good);
SDL_assert(v==44);
v = SDL_AtomicGet(&good);
SDL_assert(v == 44);
SDL_Log("Test Add\n");
v=SDL_AtomicAdd(&good, 1);
SDL_assert(v==44);
v=SDL_AtomicGet(&good);
SDL_assert(v==45);
v = SDL_AtomicAdd(&good, 1);
SDL_assert(v == 44);
v = SDL_AtomicGet(&good);
SDL_assert(v == 45);
v=SDL_AtomicAdd(&good, 10);
SDL_assert(v==45);
v=SDL_AtomicGet(&good);
SDL_assert(v==55);
v = SDL_AtomicAdd(&good, 10);
SDL_assert(v == 45);
v = SDL_AtomicGet(&good);
SDL_assert(v == 55);
SDL_Log("Test Add (Negative values)\n");
v=SDL_AtomicAdd(&good, -20);
SDL_assert(v==55);
v=SDL_AtomicGet(&good);
SDL_assert(v==35);
v = SDL_AtomicAdd(&good, -20);
SDL_assert(v == 55);
v = SDL_AtomicGet(&good);
SDL_assert(v == 35);
v=SDL_AtomicAdd(&good, -50); /* crossing zero down */
SDL_assert(v==35);
v=SDL_AtomicGet(&good);
SDL_assert(v==-15);
v = SDL_AtomicAdd(&good, -50); /* crossing zero down */
SDL_assert(v == 35);
v = SDL_AtomicGet(&good);
SDL_assert(v == -15);
v=SDL_AtomicAdd(&good, 30); /* crossing zero up */
SDL_assert(v==-15);
v=SDL_AtomicGet(&good);
SDL_assert(v==15);
v = SDL_AtomicAdd(&good, 30); /* crossing zero up */
SDL_assert(v == -15);
v = SDL_AtomicGet(&good);
SDL_assert(v == 15);
SDL_Log("Reset before count down test\n");
SDL_AtomicSet(&good, CountTo);
v=SDL_AtomicGet(&good);
SDL_assert(v==CountTo);
v = SDL_AtomicGet(&good);
SDL_assert(v == CountTo);
bad=CountTo;
SDL_assert(bad==CountTo);
bad = CountTo;
SDL_assert(bad == CountTo);
SDL_Log("Counting down from %d, Expect %d remaining\n",CountTo,Expect);
SDL_Log("Counting down from %d, Expect %d remaining\n", CountTo, Expect);
runAdder();
v=SDL_AtomicGet(&good);
SDL_Log("Atomic %d Non-Atomic %d\n",v,bad);
SDL_assert(v==Expect);
SDL_assert(bad!=Expect);
v = SDL_AtomicGet(&good);
SDL_Log("Atomic %d Non-Atomic %d\n", v, bad);
SDL_assert(v == Expect);
SDL_assert(bad != Expect);
}
/* End atomic operation test */
@@ -252,13 +248,13 @@ void RunEpicTest()
*/
#define TEST_SPINLOCK_FIFO
#define NUM_READERS 4
#define NUM_WRITERS 4
#define EVENTS_PER_WRITER 1000000
#define NUM_READERS 4
#define NUM_WRITERS 4
#define EVENTS_PER_WRITER 1000000
/* The number of entries must be a power of 2 */
#define MAX_ENTRIES 256
#define WRAP_MASK (MAX_ENTRIES-1)
#define WRAP_MASK (MAX_ENTRIES - 1)
typedef struct
{
@@ -270,22 +266,22 @@ typedef struct
{
SDL_EventQueueEntry entries[MAX_ENTRIES];
char cache_pad1[SDL_CACHELINE_SIZE-((sizeof(SDL_EventQueueEntry)*MAX_ENTRIES)%SDL_CACHELINE_SIZE)];
char cache_pad1[SDL_CACHELINE_SIZE - ((sizeof(SDL_EventQueueEntry) * MAX_ENTRIES) % SDL_CACHELINE_SIZE)];
SDL_atomic_t enqueue_pos;
char cache_pad2[SDL_CACHELINE_SIZE-sizeof(SDL_atomic_t)];
char cache_pad2[SDL_CACHELINE_SIZE - sizeof(SDL_atomic_t)];
SDL_atomic_t dequeue_pos;
char cache_pad3[SDL_CACHELINE_SIZE-sizeof(SDL_atomic_t)];
char cache_pad3[SDL_CACHELINE_SIZE - sizeof(SDL_atomic_t)];
#ifdef TEST_SPINLOCK_FIFO
SDL_SpinLock lock;
SDL_atomic_t rwcount;
SDL_atomic_t watcher;
char cache_pad4[SDL_CACHELINE_SIZE-sizeof(SDL_SpinLock)-2*sizeof(SDL_atomic_t)];
char cache_pad4[SDL_CACHELINE_SIZE - sizeof(SDL_SpinLock) - 2 * sizeof(SDL_atomic_t)];
#endif
SDL_atomic_t active;
@@ -329,14 +325,14 @@ static SDL_bool EnqueueEvent_LockFree(SDL_EventQueue *queue, const SDL_Event *ev
#endif
queue_pos = (unsigned)SDL_AtomicGet(&queue->enqueue_pos);
for ( ; ; ) {
for (;;) {
entry = &queue->entries[queue_pos & WRAP_MASK];
entry_seq = (unsigned)SDL_AtomicGet(&entry->sequence);
delta = (int)(entry_seq - queue_pos);
if (delta == 0) {
/* The entry and the queue position match, try to increment the queue position */
if (SDL_AtomicCAS(&queue->enqueue_pos, (int)queue_pos, (int)(queue_pos+1))) {
if (SDL_AtomicCAS(&queue->enqueue_pos, (int)queue_pos, (int)(queue_pos + 1))) {
/* We own the object, fill it! */
entry->event = *event;
SDL_AtomicSet(&entry->sequence, (int)(queue_pos + 1));
@@ -354,7 +350,7 @@ static SDL_bool EnqueueEvent_LockFree(SDL_EventQueue *queue, const SDL_Event *ev
}
#ifdef TEST_SPINLOCK_FIFO
(void) SDL_AtomicDecRef(&queue->rwcount);
(void)SDL_AtomicDecRef(&queue->rwcount);
#endif
return status;
}
@@ -376,17 +372,17 @@ static SDL_bool DequeueEvent_LockFree(SDL_EventQueue *queue, SDL_Event *event)
#endif
queue_pos = (unsigned)SDL_AtomicGet(&queue->dequeue_pos);
for ( ; ; ) {
for (;;) {
entry = &queue->entries[queue_pos & WRAP_MASK];
entry_seq = (unsigned)SDL_AtomicGet(&entry->sequence);
delta = (int)(entry_seq - (queue_pos + 1));
if (delta == 0) {
/* The entry and the queue position match, try to increment the queue position */
if (SDL_AtomicCAS(&queue->dequeue_pos, (int)queue_pos, (int)(queue_pos+1))) {
if (SDL_AtomicCAS(&queue->dequeue_pos, (int)queue_pos, (int)(queue_pos + 1))) {
/* We own the object, fill it! */
*event = entry->event;
SDL_AtomicSet(&entry->sequence, (int)(queue_pos+MAX_ENTRIES));
SDL_AtomicSet(&entry->sequence, (int)(queue_pos + MAX_ENTRIES));
status = SDL_TRUE;
break;
}
@@ -401,7 +397,7 @@ static SDL_bool DequeueEvent_LockFree(SDL_EventQueue *queue, SDL_Event *event)
}
#ifdef TEST_SPINLOCK_FIFO
(void) SDL_AtomicDecRef(&queue->rwcount);
(void)SDL_AtomicDecRef(&queue->rwcount);
#endif
return status;
}
@@ -476,10 +472,10 @@ typedef struct
{
SDL_EventQueue *queue;
int index;
char padding1[SDL_CACHELINE_SIZE-(sizeof(SDL_EventQueue*)+sizeof(int))%SDL_CACHELINE_SIZE];
char padding1[SDL_CACHELINE_SIZE - (sizeof(SDL_EventQueue *) + sizeof(int)) % SDL_CACHELINE_SIZE];
int waits;
SDL_bool lock_free;
char padding2[SDL_CACHELINE_SIZE-sizeof(int)-sizeof(SDL_bool)];
char padding2[SDL_CACHELINE_SIZE - sizeof(int) - sizeof(SDL_bool)];
SDL_Thread *thread;
} WriterData;
@@ -489,11 +485,11 @@ typedef struct
int counters[NUM_WRITERS];
int waits;
SDL_bool lock_free;
char padding[SDL_CACHELINE_SIZE-(sizeof(SDL_EventQueue*)+sizeof(int)*NUM_WRITERS+sizeof(int)+sizeof(SDL_bool))%SDL_CACHELINE_SIZE];
char padding[SDL_CACHELINE_SIZE - (sizeof(SDL_EventQueue *) + sizeof(int) * NUM_WRITERS + sizeof(int) + sizeof(SDL_bool)) % SDL_CACHELINE_SIZE];
SDL_Thread *thread;
} ReaderData;
static int SDLCALL FIFO_Writer(void* _data)
static int SDLCALL FIFO_Writer(void *_data)
{
WriterData *data = (WriterData *)_data;
SDL_EventQueue *queue = data->queue;
@@ -526,16 +522,16 @@ static int SDLCALL FIFO_Writer(void* _data)
return 0;
}
static int SDLCALL FIFO_Reader(void* _data)
static int SDLCALL FIFO_Reader(void *_data)
{
ReaderData *data = (ReaderData *)_data;
SDL_EventQueue *queue = data->queue;
SDL_Event event;
if (data->lock_free) {
for ( ; ; ) {
for (;;) {
if (DequeueEvent_LockFree(queue, &event)) {
WriterData *writer = (WriterData*)event.user.data1;
WriterData *writer = (WriterData *)event.user.data1;
++data->counters[writer->index];
} else if (SDL_AtomicGet(&queue->active)) {
++data->waits;
@@ -546,9 +542,9 @@ static int SDLCALL FIFO_Reader(void* _data)
}
}
} else {
for ( ; ; ) {
for (;;) {
if (DequeueEvent_Mutex(queue, &event)) {
WriterData *writer = (WriterData*)event.user.data1;
WriterData *writer = (WriterData *)event.user.data1;
++data->counters[writer->index];
} else if (SDL_AtomicGet(&queue->active)) {
++data->waits;
@@ -564,7 +560,7 @@ static int SDLCALL FIFO_Reader(void* _data)
#ifdef TEST_SPINLOCK_FIFO
/* This thread periodically locks the queue for no particular reason */
static int SDLCALL FIFO_Watcher(void* _data)
static int SDLCALL FIFO_Watcher(void *_data)
{
SDL_EventQueue *queue = (SDL_EventQueue *)_data;
@@ -575,7 +571,7 @@ static int SDLCALL FIFO_Watcher(void* _data)
SDL_Delay(0);
}
/* Do queue manipulation here... */
(void) SDL_AtomicDecRef(&queue->watcher);
(void)SDL_AtomicDecRef(&queue->watcher);
SDL_AtomicUnlock(&queue->lock);
/* Wait a bit... */
@@ -621,7 +617,7 @@ static void RunFIFOTest(SDL_bool lock_free)
SDL_zeroa(readerData);
for (i = 0; i < NUM_READERS; ++i) {
char name[64];
SDL_snprintf(name, sizeof (name), "FIFOReader%d", i);
SDL_snprintf(name, sizeof(name), "FIFOReader%d", i);
readerData[i].queue = &queue;
readerData[i].lock_free = lock_free;
readerData[i].thread = SDL_CreateThread(FIFO_Reader, name, &readerData[i]);
@@ -632,7 +628,7 @@ static void RunFIFOTest(SDL_bool lock_free)
SDL_zeroa(writerData);
for (i = 0; i < NUM_WRITERS; ++i) {
char name[64];
SDL_snprintf(name, sizeof (name), "FIFOWriter%d", i);
SDL_snprintf(name, sizeof(name), "FIFOWriter%d", i);
writerData[i].queue = &queue;
writerData[i].index = i;
writerData[i].lock_free = lock_free;
@@ -669,7 +665,7 @@ static void RunFIFOTest(SDL_bool lock_free)
for (i = 0; i < NUM_WRITERS; ++i) {
SDL_Log("Writer %d wrote %d events, had %d waits\n", i, EVENTS_PER_WRITER, writerData[i].waits);
}
SDL_Log("Writers wrote %d total events\n", NUM_WRITERS*EVENTS_PER_WRITER);
SDL_Log("Writers wrote %d total events\n", NUM_WRITERS * EVENTS_PER_WRITER);
/* Print a breakdown of which readers read messages from which writer */
SDL_Log("\n");
@@ -700,8 +696,7 @@ static void RunFIFOTest(SDL_bool lock_free)
/* End FIFO test */
/**************************************************************************/
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);

View File

@@ -67,9 +67,9 @@ loop()
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
#ifdef __EMSCRIPTEN__
#ifdef __EMSCRIPTEN__
emscripten_cancel_main_loop();
#endif
#endif
exit(0);
}
@@ -78,16 +78,15 @@ loop()
trying to test the API, so we use SDL_DequeueAudio() here. */
while (SDL_TRUE) {
Uint8 buf[1024];
const Uint32 br = SDL_DequeueAudio(devid_in, buf, sizeof (buf));
const Uint32 br = SDL_DequeueAudio(devid_in, buf, sizeof(buf));
SDL_QueueAudio(devid_out, buf, br);
if (br < sizeof (buf)) {
if (br < sizeof(buf)) {
break;
}
}
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
/* (argv[1] == NULL means "open default device.") */
const char *devname = argv[1];
@@ -157,7 +156,10 @@ main(int argc, char **argv)
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(loop, 0, 1);
#else
while (1) { loop(); SDL_Delay(16); }
while (1) {
loop();
SDL_Delay(16);
}
#endif
return 0;

View File

@@ -29,8 +29,8 @@
#include "testutils.h"
static SDL_AudioSpec spec;
static Uint8 *sound = NULL; /* Pointer to wave data */
static Uint32 soundlen = 0; /* Length of wave data */
static Uint8 *sound = NULL; /* Pointer to wave data */
static Uint32 soundlen = 0; /* Length of wave data */
static int posindex = 0;
static Uint32 positions[64];
@@ -44,9 +44,9 @@ quit(int rc)
}
void SDLCALL
fillerup(void *_pos, Uint8 * stream, int len)
fillerup(void *_pos, Uint8 *stream, int len)
{
Uint32 pos = *((Uint32 *) _pos);
Uint32 pos = *((Uint32 *)_pos);
Uint8 *waveptr;
int waveleft;
@@ -65,17 +65,16 @@ fillerup(void *_pos, Uint8 * stream, int len)
}
SDL_memcpy(stream, waveptr, len);
pos += len;
*((Uint32 *) _pos) = pos;
*((Uint32 *)_pos) = pos;
}
static int done = 0;
void
poked(int sig)
void poked(int sig)
{
done = 1;
}
static const char*
static const char *
devtypestr(int iscapture)
{
return iscapture ? "capture" : "output";
@@ -98,10 +97,10 @@ iteration()
int iscapture = e.adevice.iscapture;
const char *name = SDL_GetAudioDeviceName(index, iscapture);
if (name != NULL)
SDL_Log("New %s audio device at index %u: %s\n", devtypestr(iscapture), (unsigned int) index, name);
SDL_Log("New %s audio device at index %u: %s\n", devtypestr(iscapture), (unsigned int)index, name);
else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Got new %s device at index %u, but failed to get the name: %s\n",
devtypestr(iscapture), (unsigned int) index, SDL_GetError());
devtypestr(iscapture), (unsigned int)index, SDL_GetError());
continue;
}
if (!iscapture) {
@@ -112,21 +111,20 @@ iteration()
if (!dev) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open '%s': %s\n", name, SDL_GetError());
} else {
SDL_Log("Opened '%s' as %u\n", name, (unsigned int) dev);
SDL_Log("Opened '%s' as %u\n", name, (unsigned int)dev);
SDL_PauseAudioDevice(dev, 0);
}
}
} else if (e.type == SDL_AUDIODEVICEREMOVED) {
dev = (SDL_AudioDeviceID) e.adevice.which;
SDL_Log("%s device %u removed.\n", devtypestr(e.adevice.iscapture), (unsigned int) dev);
dev = (SDL_AudioDeviceID)e.adevice.which;
SDL_Log("%s device %u removed.\n", devtypestr(e.adevice.iscapture), (unsigned int)dev);
SDL_CloseAudioDevice(dev);
}
}
}
#ifdef __EMSCRIPTEN__
void
loop()
void loop()
{
if (done)
emscripten_cancel_main_loop();
@@ -135,8 +133,7 @@ loop()
}
#endif
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int i;
char *filename = NULL;

View File

@@ -44,8 +44,7 @@ print_devices(int iscapture)
}
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
char *deviceName = NULL;
SDL_AudioSpec spec;
@@ -98,7 +97,6 @@ main(int argc, char **argv)
SDL_Log("SDL_AudioFormat: %X\n", spec.format);
}
SDL_Quit();
return 0;
}

View File

@@ -29,8 +29,7 @@ quit(int rc)
exit(rc);
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int result;
int testIterations = 1;
@@ -63,7 +62,7 @@ main(int argc, char *argv[])
}
} else if (SDL_strcasecmp(argv[i], "--execKey") == 0) {
if (argv[i + 1]) {
SDL_sscanf(argv[i + 1], "%"SDL_PRIu64, &userExecKey);
SDL_sscanf(argv[i + 1], "%" SDL_PRIu64, &userExecKey);
consumed = 2;
}
} else if (SDL_strcasecmp(argv[i], "--seed") == 0) {
@@ -104,11 +103,11 @@ main(int argc, char *argv[])
/* Empty event queue */
done = 0;
for (i=0; i<100; i++) {
while (SDL_PollEvent(&event)) {
SDLTest_CommonEvent(state, &event, &done);
}
SDL_Delay(10);
for (i = 0; i < 100; i++) {
while (SDL_PollEvent(&event)) {
SDLTest_CommonEvent(state, &event, &done);
}
SDL_Delay(10);
}
/* Clean up */

File diff suppressed because it is too large Load Diff

View File

@@ -18,8 +18,7 @@
* \sa
* http://wiki.libsdl.org/SDL_HasClipboardText
*/
int
clipboard_testHasClipboardText(void *arg)
int clipboard_testHasClipboardText(void *arg)
{
SDL_HasClipboardText();
SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
@@ -33,8 +32,7 @@ clipboard_testHasClipboardText(void *arg)
* \sa
* http://wiki.libsdl.org/SDL_HasPrimarySelectionText
*/
int
clipboard_testHasPrimarySelectionText(void *arg)
int clipboard_testHasPrimarySelectionText(void *arg)
{
SDL_HasPrimarySelectionText();
SDLTest_AssertPass("Call to SDL_HasPrimarySelectionText succeeded");
@@ -48,8 +46,7 @@ clipboard_testHasPrimarySelectionText(void *arg)
* \sa
* http://wiki.libsdl.org/SDL_GetClipboardText
*/
int
clipboard_testGetClipboardText(void *arg)
int clipboard_testGetClipboardText(void *arg)
{
char *charResult;
charResult = SDL_GetClipboardText();
@@ -66,8 +63,7 @@ clipboard_testGetClipboardText(void *arg)
* \sa
* http://wiki.libsdl.org/SDL_GetPrimarySelectionText
*/
int
clipboard_testGetPrimarySelectionText(void *arg)
int clipboard_testGetPrimarySelectionText(void *arg)
{
char *charResult;
charResult = SDL_GetPrimarySelectionText();
@@ -83,8 +79,7 @@ clipboard_testGetPrimarySelectionText(void *arg)
* \sa
* http://wiki.libsdl.org/SDL_SetClipboardText
*/
int
clipboard_testSetClipboardText(void *arg)
int clipboard_testSetClipboardText(void *arg)
{
char *textRef = SDLTest_RandomAsciiString();
char *text = SDL_strdup(textRef);
@@ -112,8 +107,7 @@ clipboard_testSetClipboardText(void *arg)
* \sa
* http://wiki.libsdl.org/SDL_SetPrimarySelectionText
*/
int
clipboard_testSetPrimarySelectionText(void *arg)
int clipboard_testSetPrimarySelectionText(void *arg)
{
char *textRef = SDLTest_RandomAsciiString();
char *text = SDL_strdup(textRef);
@@ -143,8 +137,7 @@ clipboard_testSetPrimarySelectionText(void *arg)
* http://wiki.libsdl.org/SDL_GetClipboardText
* http://wiki.libsdl.org/SDL_SetClipboardText
*/
int
clipboard_testClipboardTextFunctions(void *arg)
int clipboard_testClipboardTextFunctions(void *arg)
{
char *textRef = SDLTest_RandomAsciiString();
char *text = SDL_strdup(textRef);
@@ -182,7 +175,7 @@ clipboard_testClipboardTextFunctions(void *arg)
SDLTest_AssertCheck(
charResult[0] == '\0',
"Verify SDL_GetClipboardText returned string with length 0, got length %i",
(int) SDL_strlen(charResult));
(int)SDL_strlen(charResult));
intResult = SDL_SetClipboardText((const char *)text);
SDLTest_AssertPass("Call to SDL_SetClipboardText succeeded");
SDLTest_AssertCheck(
@@ -222,8 +215,7 @@ clipboard_testClipboardTextFunctions(void *arg)
* http://wiki.libsdl.org/SDL_GetPrimarySelectionText
* http://wiki.libsdl.org/SDL_SetPrimarySelectionText
*/
int
clipboard_testPrimarySelectionTextFunctions(void *arg)
int clipboard_testPrimarySelectionTextFunctions(void *arg)
{
char *textRef = SDLTest_RandomAsciiString();
char *text = SDL_strdup(textRef);
@@ -261,7 +253,7 @@ clipboard_testPrimarySelectionTextFunctions(void *arg)
SDLTest_AssertCheck(
charResult[0] == '\0',
"Verify SDL_GetPrimarySelectionText returned string with length 0, got length %i",
(int) SDL_strlen(charResult));
(int)SDL_strlen(charResult));
intResult = SDL_SetPrimarySelectionText((const char *)text);
SDLTest_AssertPass("Call to SDL_SetPrimarySelectionText succeeded");
SDLTest_AssertCheck(
@@ -294,36 +286,43 @@ clipboard_testPrimarySelectionTextFunctions(void *arg)
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Clipboard test cases */
static const SDLTest_TestCaseReference clipboardTest1 =
{ (SDLTest_TestCaseFp)clipboard_testHasClipboardText, "clipboard_testHasClipboardText", "Check call to SDL_HasClipboardText", TEST_ENABLED };
static const SDLTest_TestCaseReference clipboardTest1 = {
(SDLTest_TestCaseFp)clipboard_testHasClipboardText, "clipboard_testHasClipboardText", "Check call to SDL_HasClipboardText", TEST_ENABLED
};
static const SDLTest_TestCaseReference clipboardTest2 =
{ (SDLTest_TestCaseFp)clipboard_testHasPrimarySelectionText, "clipboard_testHasPrimarySelectionText", "Check call to SDL_HasPrimarySelectionText", TEST_ENABLED };
static const SDLTest_TestCaseReference clipboardTest2 = {
(SDLTest_TestCaseFp)clipboard_testHasPrimarySelectionText, "clipboard_testHasPrimarySelectionText", "Check call to SDL_HasPrimarySelectionText", TEST_ENABLED
};
static const SDLTest_TestCaseReference clipboardTest3 =
{ (SDLTest_TestCaseFp)clipboard_testGetClipboardText, "clipboard_testGetClipboardText", "Check call to SDL_GetClipboardText", TEST_ENABLED };
static const SDLTest_TestCaseReference clipboardTest3 = {
(SDLTest_TestCaseFp)clipboard_testGetClipboardText, "clipboard_testGetClipboardText", "Check call to SDL_GetClipboardText", TEST_ENABLED
};
static const SDLTest_TestCaseReference clipboardTest4 =
{ (SDLTest_TestCaseFp)clipboard_testGetPrimarySelectionText, "clipboard_testGetPrimarySelectionText", "Check call to SDL_GetPrimarySelectionText", TEST_ENABLED };
static const SDLTest_TestCaseReference clipboardTest4 = {
(SDLTest_TestCaseFp)clipboard_testGetPrimarySelectionText, "clipboard_testGetPrimarySelectionText", "Check call to SDL_GetPrimarySelectionText", TEST_ENABLED
};
static const SDLTest_TestCaseReference clipboardTest5 =
{ (SDLTest_TestCaseFp)clipboard_testSetClipboardText, "clipboard_testSetClipboardText", "Check call to SDL_SetClipboardText", TEST_ENABLED };
static const SDLTest_TestCaseReference clipboardTest5 = {
(SDLTest_TestCaseFp)clipboard_testSetClipboardText, "clipboard_testSetClipboardText", "Check call to SDL_SetClipboardText", TEST_ENABLED
};
static const SDLTest_TestCaseReference clipboardTest6 =
{ (SDLTest_TestCaseFp)clipboard_testSetPrimarySelectionText, "clipboard_testSetPrimarySelectionText", "Check call to SDL_SetPrimarySelectionText", TEST_ENABLED };
static const SDLTest_TestCaseReference clipboardTest6 = {
(SDLTest_TestCaseFp)clipboard_testSetPrimarySelectionText, "clipboard_testSetPrimarySelectionText", "Check call to SDL_SetPrimarySelectionText", TEST_ENABLED
};
static const SDLTest_TestCaseReference clipboardTest7 =
{ (SDLTest_TestCaseFp)clipboard_testClipboardTextFunctions, "clipboard_testClipboardTextFunctions", "End-to-end test of SDL_xyzClipboardText functions", TEST_ENABLED };
static const SDLTest_TestCaseReference clipboardTest7 = {
(SDLTest_TestCaseFp)clipboard_testClipboardTextFunctions, "clipboard_testClipboardTextFunctions", "End-to-end test of SDL_xyzClipboardText functions", TEST_ENABLED
};
static const SDLTest_TestCaseReference clipboardTest8 =
{ (SDLTest_TestCaseFp)clipboard_testPrimarySelectionTextFunctions, "clipboard_testPrimarySelectionTextFunctions", "End-to-end test of SDL_xyzPrimarySelectionText functions", TEST_ENABLED };
static const SDLTest_TestCaseReference clipboardTest8 = {
(SDLTest_TestCaseFp)clipboard_testPrimarySelectionTextFunctions, "clipboard_testPrimarySelectionTextFunctions", "End-to-end test of SDL_xyzPrimarySelectionText functions", TEST_ENABLED
};
/* Sequence of Clipboard test cases */
static const SDLTest_TestCaseReference *clipboardTests[] = {
static const SDLTest_TestCaseReference *clipboardTests[] = {
&clipboardTest1, &clipboardTest2, &clipboardTest3, &clipboardTest4, &clipboardTest5, &clipboardTest6, &clipboardTest7, &clipboardTest8, NULL
};

View File

@@ -27,16 +27,16 @@ int _userdataValue2 = 2;
/* Event filter that sets some flags and optionally checks userdata */
int SDLCALL _events_sampleNullEventFilter(void *userdata, SDL_Event *event)
{
_eventFilterCalled = 1;
_eventFilterCalled = 1;
if (_userdataCheck != 0) {
SDLTest_AssertCheck(userdata != NULL, "Check userdata pointer, expected: non-NULL, got: %s", (userdata != NULL) ? "non-NULL" : "NULL");
if (userdata != NULL) {
SDLTest_AssertCheck(*(int *)userdata == _userdataValue, "Check userdata value, expected: %i, got: %i", _userdataValue, *(int *)userdata);
}
}
if (_userdataCheck != 0) {
SDLTest_AssertCheck(userdata != NULL, "Check userdata pointer, expected: non-NULL, got: %s", (userdata != NULL) ? "non-NULL" : "NULL");
if (userdata != NULL) {
SDLTest_AssertCheck(*(int *)userdata == _userdataValue, "Check userdata value, expected: %i, got: %i", _userdataValue, *(int *)userdata);
}
}
return 0;
return 0;
}
/**
@@ -45,34 +45,32 @@ int SDLCALL _events_sampleNullEventFilter(void *userdata, SDL_Event *event)
* @sa http://wiki.libsdl.org/SDL_PumpEvents
* @sa http://wiki.libsdl.org/SDL_PollEvent
*/
int
events_pushPumpAndPollUserevent(void *arg)
int events_pushPumpAndPollUserevent(void *arg)
{
SDL_Event event1;
SDL_Event event2;
int result;
SDL_Event event1;
SDL_Event event2;
int result;
/* Create user event */
event1.type = SDL_USEREVENT;
event1.user.code = SDLTest_RandomSint32();
event1.user.data1 = (void *)&_userdataValue1;
event1.user.data2 = (void *)&_userdataValue2;
/* Create user event */
event1.type = SDL_USEREVENT;
event1.user.code = SDLTest_RandomSint32();
event1.user.data1 = (void *)&_userdataValue1;
event1.user.data2 = (void *)&_userdataValue2;
/* Push a user event onto the queue and force queue update */
SDL_PushEvent(&event1);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
/* Push a user event onto the queue and force queue update */
SDL_PushEvent(&event1);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
/* Poll for user event */
result = SDL_PollEvent(&event2);
SDLTest_AssertPass("Call to SDL_PollEvent()");
SDLTest_AssertCheck(result == 1, "Check result from SDL_PollEvent, expected: 1, got: %d", result);
/* Poll for user event */
result = SDL_PollEvent(&event2);
SDLTest_AssertPass("Call to SDL_PollEvent()");
SDLTest_AssertCheck(result == 1, "Check result from SDL_PollEvent, expected: 1, got: %d", result);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
* @brief Adds and deletes an event watch function with NULL userdata
*
@@ -80,47 +78,46 @@ events_pushPumpAndPollUserevent(void *arg)
* @sa http://wiki.libsdl.org/SDL_DelEventWatch
*
*/
int
events_addDelEventWatch(void *arg)
int events_addDelEventWatch(void *arg)
{
SDL_Event event;
SDL_Event event;
/* Create user event */
event.type = SDL_USEREVENT;
event.user.code = SDLTest_RandomSint32();
event.user.data1 = (void *)&_userdataValue1;
event.user.data2 = (void *)&_userdataValue2;
/* Create user event */
event.type = SDL_USEREVENT;
event.user.code = SDLTest_RandomSint32();
event.user.data1 = (void *)&_userdataValue1;
event.user.data2 = (void *)&_userdataValue2;
/* Disable userdata check */
_userdataCheck = 0;
/* Disable userdata check */
_userdataCheck = 0;
/* Reset event filter call tracker */
_eventFilterCalled = 0;
/* Reset event filter call tracker */
_eventFilterCalled = 0;
/* Add watch */
SDL_AddEventWatch(_events_sampleNullEventFilter, NULL);
SDLTest_AssertPass("Call to SDL_AddEventWatch()");
/* Add watch */
SDL_AddEventWatch(_events_sampleNullEventFilter, NULL);
SDLTest_AssertPass("Call to SDL_AddEventWatch()");
/* Push a user event onto the queue and force queue update */
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
/* Push a user event onto the queue and force queue update */
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
/* Delete watch */
SDL_DelEventWatch(_events_sampleNullEventFilter, NULL);
SDLTest_AssertPass("Call to SDL_DelEventWatch()");
/* Delete watch */
SDL_DelEventWatch(_events_sampleNullEventFilter, NULL);
SDLTest_AssertPass("Call to SDL_DelEventWatch()");
/* Push a user event onto the queue and force queue update */
_eventFilterCalled = 0;
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
/* Push a user event onto the queue and force queue update */
_eventFilterCalled = 0;
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
@@ -130,65 +127,66 @@ events_addDelEventWatch(void *arg)
* @sa http://wiki.libsdl.org/SDL_DelEventWatch
*
*/
int
events_addDelEventWatchWithUserdata(void *arg)
int events_addDelEventWatchWithUserdata(void *arg)
{
SDL_Event event;
SDL_Event event;
/* Create user event */
event.type = SDL_USEREVENT;
event.user.code = SDLTest_RandomSint32();
event.user.data1 = (void *)&_userdataValue1;
event.user.data2 = (void *)&_userdataValue2;
/* Create user event */
event.type = SDL_USEREVENT;
event.user.code = SDLTest_RandomSint32();
event.user.data1 = (void *)&_userdataValue1;
event.user.data2 = (void *)&_userdataValue2;
/* Enable userdata check and set a value to check */
_userdataCheck = 1;
_userdataValue = SDLTest_RandomIntegerInRange(-1024, 1024);
/* Enable userdata check and set a value to check */
_userdataCheck = 1;
_userdataValue = SDLTest_RandomIntegerInRange(-1024, 1024);
/* Reset event filter call tracker */
_eventFilterCalled = 0;
/* Reset event filter call tracker */
_eventFilterCalled = 0;
/* Add watch */
SDL_AddEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
SDLTest_AssertPass("Call to SDL_AddEventWatch()");
/* Add watch */
SDL_AddEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
SDLTest_AssertPass("Call to SDL_AddEventWatch()");
/* Push a user event onto the queue and force queue update */
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
/* Push a user event onto the queue and force queue update */
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
/* Delete watch */
SDL_DelEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
SDLTest_AssertPass("Call to SDL_DelEventWatch()");
/* Delete watch */
SDL_DelEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
SDLTest_AssertPass("Call to SDL_DelEventWatch()");
/* Push a user event onto the queue and force queue update */
_eventFilterCalled = 0;
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
/* Push a user event onto the queue and force queue update */
_eventFilterCalled = 0;
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Events test cases */
static const SDLTest_TestCaseReference eventsTest1 =
{ (SDLTest_TestCaseFp)events_pushPumpAndPollUserevent, "events_pushPumpAndPollUserevent", "Pushes, pumps and polls a user event", TEST_ENABLED };
static const SDLTest_TestCaseReference eventsTest1 = {
(SDLTest_TestCaseFp)events_pushPumpAndPollUserevent, "events_pushPumpAndPollUserevent", "Pushes, pumps and polls a user event", TEST_ENABLED
};
static const SDLTest_TestCaseReference eventsTest2 =
{ (SDLTest_TestCaseFp)events_addDelEventWatch, "events_addDelEventWatch", "Adds and deletes an event watch function with NULL userdata", TEST_ENABLED };
static const SDLTest_TestCaseReference eventsTest2 = {
(SDLTest_TestCaseFp)events_addDelEventWatch, "events_addDelEventWatch", "Adds and deletes an event watch function with NULL userdata", TEST_ENABLED
};
static const SDLTest_TestCaseReference eventsTest3 =
{ (SDLTest_TestCaseFp)events_addDelEventWatchWithUserdata, "events_addDelEventWatchWithUserdata", "Adds and deletes an event watch function with userdata", TEST_ENABLED };
static const SDLTest_TestCaseReference eventsTest3 = {
(SDLTest_TestCaseFp)events_addDelEventWatchWithUserdata, "events_addDelEventWatchWithUserdata", "Adds and deletes an event watch function with userdata", TEST_ENABLED
};
/* Sequence of Events test cases */
static const SDLTest_TestCaseReference *eventsTests[] = {
static const SDLTest_TestCaseReference *eventsTests[] = {
&eventsTest1, &eventsTest2, &eventsTest3, NULL
};

View File

@@ -11,30 +11,36 @@
#define NUM_TEST_GUIDS 5
static struct {
static struct
{
char *str;
Uint64 upper, lower;
} test_guids[NUM_TEST_GUIDS] = {
{ "0000000000000000" "ffffffffffffffff",
0x0000000000000000, 0xfffffffffffffffflu },
{ "0011223344556677" "8091a2b3c4d5e6f0",
0x0011223344556677lu, 0x8091a2b3c4d5e6f0lu },
{ "a011223344556677" "8091a2b3c4d5e6f0",
0xa011223344556677lu, 0x8091a2b3c4d5e6f0lu },
{ "a011223344556677" "8091a2b3c4d5e6f1",
0xa011223344556677lu, 0x8091a2b3c4d5e6f1lu },
{ "a011223344556677" "8191a2b3c4d5e6f0",
0xa011223344556677lu, 0x8191a2b3c4d5e6f0lu },
{ "0000000000000000"
"ffffffffffffffff",
0x0000000000000000, 0xfffffffffffffffflu },
{ "0011223344556677"
"8091a2b3c4d5e6f0",
0x0011223344556677lu, 0x8091a2b3c4d5e6f0lu },
{ "a011223344556677"
"8091a2b3c4d5e6f0",
0xa011223344556677lu, 0x8091a2b3c4d5e6f0lu },
{ "a011223344556677"
"8091a2b3c4d5e6f1",
0xa011223344556677lu, 0x8091a2b3c4d5e6f1lu },
{ "a011223344556677"
"8191a2b3c4d5e6f0",
0xa011223344556677lu, 0x8191a2b3c4d5e6f0lu },
};
static void
upper_lower_to_bytestring(Uint8* out, Uint64 upper, Uint64 lower)
upper_lower_to_bytestring(Uint8 *out, Uint64 upper, Uint64 lower)
{
Uint64 values[2];
int i, k;
values[0] = upper;
values [1] = lower;
values[1] = lower;
for (i = 0; i < 2; ++i) {
Uint64 v = values[i];
@@ -46,7 +52,6 @@ upper_lower_to_bytestring(Uint8* out, Uint64 upper, Uint64 lower)
}
}
/* Test case functions */
/**
@@ -128,14 +133,16 @@ TestGuidToString(void *arg)
/* ================= Test References ================== */
/* GUID routine test cases */
static const SDLTest_TestCaseReference guidTest1 =
{ (SDLTest_TestCaseFp)TestGuidFromString, "TestGuidFromString", "Call to SDL_GUIDFromString", TEST_ENABLED };
static const SDLTest_TestCaseReference guidTest1 = {
(SDLTest_TestCaseFp)TestGuidFromString, "TestGuidFromString", "Call to SDL_GUIDFromString", TEST_ENABLED
};
static const SDLTest_TestCaseReference guidTest2 =
{ (SDLTest_TestCaseFp)TestGuidToString, "TestGuidToString", "Call to SDL_GUIDToString", TEST_ENABLED };
static const SDLTest_TestCaseReference guidTest2 = {
(SDLTest_TestCaseFp)TestGuidToString, "TestGuidToString", "Call to SDL_GUIDToString", TEST_ENABLED
};
/* Sequence of GUID routine test cases */
static const SDLTest_TestCaseReference *guidTests[] = {
static const SDLTest_TestCaseReference *guidTests[] = {
&guidTest1,
&guidTest2,
NULL

View File

@@ -7,9 +7,7 @@
#include "SDL.h"
#include "SDL_test.h"
const char* _HintsEnum[] =
{
const char *_HintsEnum[] = {
SDL_HINT_ACCELEROMETER_AS_JOYSTICK,
SDL_HINT_FRAMEBUFFER_ACCELERATION,
SDL_HINT_GAMECONTROLLERCONFIG,
@@ -33,9 +31,8 @@ const char* _HintsEnum[] =
SDL_HINT_VIDEO_WIN_D3DCOMPILER,
SDL_HINT_VIDEO_X11_XRANDR,
SDL_HINT_XINPUT_ENABLED,
};
const char* _HintsVerbose[] =
{
};
const char *_HintsVerbose[] = {
"SDL_ACCELEROMETER_AS_JOYSTICK",
"SDL_FRAMEBUFFER_ACCELERATION",
"SDL_GAMECONTROLLERCONFIG",
@@ -59,7 +56,7 @@ const char* _HintsVerbose[] =
"SDL_VIDEO_WIN_D3DCOMPILER",
"SDL_VIDEO_X11_XRANDR",
"SDL_XINPUT_ENABLED"
};
};
SDL_COMPILE_TIME_ASSERT(HintsEnum, SDL_arraysize(_HintsEnum) == SDL_arraysize(_HintsVerbose));
@@ -70,193 +67,193 @@ const int _numHintsEnum = SDL_arraysize(_HintsEnum);
/**
* @brief Call to SDL_GetHint
*/
int
hints_getHint(void *arg)
int hints_getHint(void *arg)
{
const char *result1;
const char *result2;
int i;
const char *result1;
const char *result2;
int i;
for (i=0; i<_numHintsEnum; i++) {
result1 = SDL_GetHint(_HintsEnum[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using define definition", (char*)_HintsEnum[i]);
result2 = SDL_GetHint(_HintsVerbose[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char*)_HintsVerbose[i]);
SDLTest_AssertCheck(
(result1 == NULL && result2 == NULL) || (SDL_strcmp(result1, result2) == 0),
"Verify returned values are equal; got: result1='%s' result2='%s",
(result1 == NULL) ? "null" : result1,
(result2 == NULL) ? "null" : result2);
}
for (i = 0; i < _numHintsEnum; i++) {
result1 = SDL_GetHint(_HintsEnum[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using define definition", (char *)_HintsEnum[i]);
result2 = SDL_GetHint(_HintsVerbose[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char *)_HintsVerbose[i]);
SDLTest_AssertCheck(
(result1 == NULL && result2 == NULL) || (SDL_strcmp(result1, result2) == 0),
"Verify returned values are equal; got: result1='%s' result2='%s",
(result1 == NULL) ? "null" : result1,
(result2 == NULL) ? "null" : result2);
}
return TEST_COMPLETED;
return TEST_COMPLETED;
}
static void SDLCALL hints_testHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
*(char **)userdata = hint ? SDL_strdup(hint) : NULL;
*(char **)userdata = hint ? SDL_strdup(hint) : NULL;
}
/**
* @brief Call to SDL_SetHint
*/
int
hints_setHint(void *arg)
int hints_setHint(void *arg)
{
const char *testHint = "SDL_AUTOMATED_TEST_HINT";
const char *originalValue;
char *value;
const char *testValue;
char *callbackValue;
SDL_bool result;
int i, j;
const char *testHint = "SDL_AUTOMATED_TEST_HINT";
const char *originalValue;
char *value;
const char *testValue;
char *callbackValue;
SDL_bool result;
int i, j;
/* Create random values to set */
value = SDLTest_RandomAsciiStringOfSize(10);
/* Create random values to set */
value = SDLTest_RandomAsciiStringOfSize(10);
for (i=0; i<_numHintsEnum; i++) {
/* Capture current value */
originalValue = SDL_GetHint(_HintsEnum[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s)", _HintsEnum[i]);
for (i = 0; i < _numHintsEnum; i++) {
/* Capture current value */
originalValue = SDL_GetHint(_HintsEnum[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s)", _HintsEnum[i]);
/* Copy the original value, since it will be freed when we set it again */
originalValue = originalValue ? SDL_strdup(originalValue) : NULL;
/* Copy the original value, since it will be freed when we set it again */
originalValue = originalValue ? SDL_strdup(originalValue) : NULL;
/* Set value (twice) */
for (j=1; j<=2; j++) {
result = SDL_SetHint(_HintsEnum[i], value);
SDLTest_AssertPass("Call to SDL_SetHint(%s, %s) (iteration %i)", _HintsEnum[i], value, j);
SDLTest_AssertCheck(
result == SDL_TRUE || result == SDL_FALSE,
"Verify valid result was returned, got: %i",
(int)result);
testValue = SDL_GetHint(_HintsEnum[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", _HintsVerbose[i]);
SDLTest_AssertCheck(
(SDL_strcmp(value, testValue) == 0),
"Verify returned value equals set value; got: testValue='%s' value='%s",
(testValue == NULL) ? "null" : testValue,
value);
/* Set value (twice) */
for (j = 1; j <= 2; j++) {
result = SDL_SetHint(_HintsEnum[i], value);
SDLTest_AssertPass("Call to SDL_SetHint(%s, %s) (iteration %i)", _HintsEnum[i], value, j);
SDLTest_AssertCheck(
result == SDL_TRUE || result == SDL_FALSE,
"Verify valid result was returned, got: %i",
(int)result);
testValue = SDL_GetHint(_HintsEnum[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", _HintsVerbose[i]);
SDLTest_AssertCheck(
(SDL_strcmp(value, testValue) == 0),
"Verify returned value equals set value; got: testValue='%s' value='%s",
(testValue == NULL) ? "null" : testValue,
value);
}
/* Reset original value */
result = SDL_SetHint(_HintsEnum[i], originalValue);
SDLTest_AssertPass("Call to SDL_SetHint(%s, originalValue)", _HintsEnum[i]);
SDLTest_AssertCheck(
result == SDL_TRUE || result == SDL_FALSE,
"Verify valid result was returned, got: %i",
(int)result);
SDL_free((void *)originalValue);
}
/* Reset original value */
result = SDL_SetHint(_HintsEnum[i], originalValue);
SDLTest_AssertPass("Call to SDL_SetHint(%s, originalValue)", _HintsEnum[i]);
SDL_free(value);
/* Set default value in environment */
SDL_setenv(testHint, "original", 1);
SDLTest_AssertPass("Call to SDL_GetHint() after saving and restoring hint");
originalValue = SDL_GetHint(testHint);
value = (originalValue == NULL) ? NULL : SDL_strdup(originalValue);
SDL_SetHint(testHint, "temp");
SDL_SetHint(testHint, value);
SDL_free(value);
testValue = SDL_GetHint(testHint);
SDLTest_AssertCheck(
result == SDL_TRUE || result == SDL_FALSE,
"Verify valid result was returned, got: %i",
(int)result);
SDL_free((void *)originalValue);
}
testValue && SDL_strcmp(testValue, "original") == 0,
"testValue = %s, expected \"original\"",
testValue);
SDL_free(value);
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(NULL, SDL_HINT_DEFAULT)");
SDL_SetHintWithPriority(testHint, NULL, SDL_HINT_DEFAULT);
testValue = SDL_GetHint(testHint);
SDLTest_AssertCheck(
testValue && SDL_strcmp(testValue, "original") == 0,
"testValue = %s, expected \"original\"",
testValue);
/* Set default value in environment */
SDL_setenv(testHint, "original", 1);
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE)");
SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE);
testValue = SDL_GetHint(testHint);
SDLTest_AssertCheck(
testValue && SDL_strcmp(testValue, "temp") == 0,
"testValue = %s, expected \"temp\"",
testValue);
SDLTest_AssertPass("Call to SDL_GetHint() after saving and restoring hint");
originalValue = SDL_GetHint(testHint);
value = (originalValue == NULL) ? NULL : SDL_strdup(originalValue);
SDL_SetHint(testHint, "temp");
SDL_SetHint(testHint, value);
SDL_free(value);
testValue = SDL_GetHint(testHint);
SDLTest_AssertCheck(
testValue && SDL_strcmp(testValue, "original") == 0,
"testValue = %s, expected \"original\"",
testValue);
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(NULL, SDL_HINT_OVERRIDE)");
SDL_SetHintWithPriority(testHint, NULL, SDL_HINT_OVERRIDE);
testValue = SDL_GetHint(testHint);
SDLTest_AssertCheck(
testValue == NULL,
"testValue = %s, expected NULL",
testValue);
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(NULL, SDL_HINT_DEFAULT)");
SDL_SetHintWithPriority(testHint, NULL, SDL_HINT_DEFAULT);
testValue = SDL_GetHint(testHint);
SDLTest_AssertCheck(
testValue && SDL_strcmp(testValue, "original") == 0,
"testValue = %s, expected \"original\"",
testValue);
SDLTest_AssertPass("Call to SDL_ResetHint()");
SDL_ResetHint(testHint);
testValue = SDL_GetHint(testHint);
SDLTest_AssertCheck(
testValue && SDL_strcmp(testValue, "original") == 0,
"testValue = %s, expected \"original\"",
testValue);
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE)");
SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE);
testValue = SDL_GetHint(testHint);
SDLTest_AssertCheck(
testValue && SDL_strcmp(testValue, "temp") == 0,
"testValue = %s, expected \"temp\"",
testValue);
/* Make sure callback functionality works past a reset */
SDLTest_AssertPass("Call to SDL_AddHintCallback()");
callbackValue = NULL;
SDL_AddHintCallback(testHint, hints_testHintChanged, &callbackValue);
SDLTest_AssertCheck(
callbackValue && SDL_strcmp(callbackValue, "original") == 0,
"callbackValue = %s, expected \"original\"",
callbackValue);
SDL_free(callbackValue);
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(NULL, SDL_HINT_OVERRIDE)");
SDL_SetHintWithPriority(testHint, NULL, SDL_HINT_OVERRIDE);
testValue = SDL_GetHint(testHint);
SDLTest_AssertCheck(
testValue == NULL,
"testValue = %s, expected NULL",
testValue);
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE), using callback");
callbackValue = NULL;
SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE);
SDLTest_AssertCheck(
callbackValue && SDL_strcmp(callbackValue, "temp") == 0,
"callbackValue = %s, expected \"temp\"",
callbackValue);
SDL_free(callbackValue);
SDLTest_AssertPass("Call to SDL_ResetHint()");
SDL_ResetHint(testHint);
testValue = SDL_GetHint(testHint);
SDLTest_AssertCheck(
testValue && SDL_strcmp(testValue, "original") == 0,
"testValue = %s, expected \"original\"",
testValue);
SDLTest_AssertPass("Call to SDL_ResetHint(), using callback");
callbackValue = NULL;
SDL_ResetHint(testHint);
SDLTest_AssertCheck(
callbackValue && SDL_strcmp(callbackValue, "original") == 0,
"callbackValue = %s, expected \"original\"",
callbackValue);
/* Make sure callback functionality works past a reset */
SDLTest_AssertPass("Call to SDL_AddHintCallback()");
callbackValue = NULL;
SDL_AddHintCallback(testHint, hints_testHintChanged, &callbackValue);
SDLTest_AssertCheck(
callbackValue && SDL_strcmp(callbackValue, "original") == 0,
"callbackValue = %s, expected \"original\"",
callbackValue);
SDL_free(callbackValue);
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE), using callback after reset");
callbackValue = NULL;
SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE);
SDLTest_AssertCheck(
callbackValue && SDL_strcmp(callbackValue, "temp") == 0,
"callbackValue = %s, expected \"temp\"",
callbackValue);
SDL_free(callbackValue);
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE), using callback");
callbackValue = NULL;
SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE);
SDLTest_AssertCheck(
callbackValue && SDL_strcmp(callbackValue, "temp") == 0,
"callbackValue = %s, expected \"temp\"",
callbackValue);
SDL_free(callbackValue);
SDLTest_AssertPass("Call to SDL_ResetHint(), after clearing callback");
callbackValue = NULL;
SDL_DelHintCallback(testHint, hints_testHintChanged, &callbackValue);
SDL_ResetHint(testHint);
SDLTest_AssertCheck(
callbackValue == NULL,
"callbackValue = %s, expected \"(null)\"",
callbackValue);
SDLTest_AssertPass("Call to SDL_ResetHint(), using callback");
callbackValue = NULL;
SDL_ResetHint(testHint);
SDLTest_AssertCheck(
callbackValue && SDL_strcmp(callbackValue, "original") == 0,
"callbackValue = %s, expected \"original\"",
callbackValue);
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE), using callback after reset");
callbackValue = NULL;
SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE);
SDLTest_AssertCheck(
callbackValue && SDL_strcmp(callbackValue, "temp") == 0,
"callbackValue = %s, expected \"temp\"",
callbackValue);
SDL_free(callbackValue);
SDLTest_AssertPass("Call to SDL_ResetHint(), after clearing callback");
callbackValue = NULL;
SDL_DelHintCallback(testHint, hints_testHintChanged, &callbackValue);
SDL_ResetHint(testHint);
SDLTest_AssertCheck(
callbackValue == NULL,
"callbackValue = %s, expected \"(null)\"",
callbackValue);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Hints test cases */
static const SDLTest_TestCaseReference hintsTest1 =
{ (SDLTest_TestCaseFp)hints_getHint, "hints_getHint", "Call to SDL_GetHint", TEST_ENABLED };
static const SDLTest_TestCaseReference hintsTest1 = {
(SDLTest_TestCaseFp)hints_getHint, "hints_getHint", "Call to SDL_GetHint", TEST_ENABLED
};
static const SDLTest_TestCaseReference hintsTest2 =
{ (SDLTest_TestCaseFp)hints_setHint, "hints_setHint", "Call to SDL_SetHint", TEST_ENABLED };
static const SDLTest_TestCaseReference hintsTest2 = {
(SDLTest_TestCaseFp)hints_setHint, "hints_setHint", "Call to SDL_SetHint", TEST_ENABLED
};
/* Sequence of Hints test cases */
static const SDLTest_TestCaseReference *hintsTests[] = {
static const SDLTest_TestCaseReference *hintsTests[] = {
&hintsTest1, &hintsTest2, NULL
};

View File

@@ -72,11 +72,12 @@ TestVirtualJoystick(void *arg)
/* ================= Test References ================== */
/* Joystick routine test cases */
static const SDLTest_TestCaseReference joystickTest1 =
{ (SDLTest_TestCaseFp)TestVirtualJoystick, "TestVirtualJoystick", "Test virtual joystick functionality", TEST_ENABLED };
static const SDLTest_TestCaseReference joystickTest1 = {
(SDLTest_TestCaseFp)TestVirtualJoystick, "TestVirtualJoystick", "Test virtual joystick functionality", TEST_ENABLED
};
/* Sequence of Joystick routine test cases */
static const SDLTest_TestCaseReference *joystickTests[] = {
static const SDLTest_TestCaseReference *joystickTests[] = {
&joystickTest1,
NULL
};

File diff suppressed because it is too large Load Diff

View File

@@ -9,14 +9,13 @@
#include "SDL.h"
#include "SDL_test.h"
/* !
* \brief Tests SDL_Init() and SDL_Quit() of Joystick and Haptic subsystems
* \sa
* http://wiki.libsdl.org/SDL_Init
* http://wiki.libsdl.org/SDL_Quit
*/
static int main_testInitQuitJoystickHaptic (void *arg)
static int main_testInitQuitJoystickHaptic(void *arg)
{
#if defined SDL_JOYSTICK_DISABLED || defined SDL_HAPTIC_DISABLED
return TEST_SKIPPED;
@@ -24,15 +23,15 @@ static int main_testInitQuitJoystickHaptic (void *arg)
int enabled_subsystems;
int initialized_subsystems = SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC;
SDLTest_AssertCheck( SDL_Init(initialized_subsystems) == 0, "SDL_Init multiple systems." );
SDLTest_AssertCheck(SDL_Init(initialized_subsystems) == 0, "SDL_Init multiple systems.");
enabled_subsystems = SDL_WasInit(initialized_subsystems);
SDLTest_AssertCheck( enabled_subsystems == initialized_subsystems, "SDL_WasInit(SDL_INIT_EVERYTHING) contains all systems (%i)", enabled_subsystems );
SDLTest_AssertCheck(enabled_subsystems == initialized_subsystems, "SDL_WasInit(SDL_INIT_EVERYTHING) contains all systems (%i)", enabled_subsystems);
SDL_Quit();
enabled_subsystems = SDL_WasInit(initialized_subsystems);
SDLTest_AssertCheck( enabled_subsystems == 0, "SDL_Quit should shut down everything (%i)", enabled_subsystems );
SDLTest_AssertCheck(enabled_subsystems == 0, "SDL_Quit should shut down everything (%i)", enabled_subsystems);
return TEST_COMPLETED;
#endif
@@ -44,7 +43,7 @@ static int main_testInitQuitJoystickHaptic (void *arg)
* http://wiki.libsdl.org/SDL_Init
* http://wiki.libsdl.org/SDL_Quit
*/
static int main_testInitQuitSubSystem (void *arg)
static int main_testInitQuitSubSystem(void *arg)
{
#if defined SDL_JOYSTICK_DISABLED || defined SDL_HAPTIC_DISABLED || defined SDL_GAMECONTROLLER_DISABLED
return TEST_SKIPPED;
@@ -56,15 +55,15 @@ static int main_testInitQuitSubSystem (void *arg)
int initialized_system;
int subsystem = subsystems[i];
SDLTest_AssertCheck( (SDL_WasInit(subsystem) & subsystem) == 0, "SDL_WasInit(%x) before init should be false", subsystem );
SDLTest_AssertCheck( SDL_InitSubSystem(subsystem) == 0, "SDL_InitSubSystem(%x)", subsystem );
SDLTest_AssertCheck((SDL_WasInit(subsystem) & subsystem) == 0, "SDL_WasInit(%x) before init should be false", subsystem);
SDLTest_AssertCheck(SDL_InitSubSystem(subsystem) == 0, "SDL_InitSubSystem(%x)", subsystem);
initialized_system = SDL_WasInit(subsystem);
SDLTest_AssertCheck( (initialized_system & subsystem) != 0, "SDL_WasInit(%x) should be true (%x)", subsystem, initialized_system );
SDLTest_AssertCheck((initialized_system & subsystem) != 0, "SDL_WasInit(%x) should be true (%x)", subsystem, initialized_system);
SDL_QuitSubSystem(subsystem);
SDLTest_AssertCheck( (SDL_WasInit(subsystem) & subsystem) == 0, "SDL_WasInit(%x) after shutdown should be false", subsystem );
SDLTest_AssertCheck((SDL_WasInit(subsystem) & subsystem) == 0, "SDL_WasInit(%x) after shutdown should be false", subsystem);
}
return TEST_COMPLETED;
@@ -72,7 +71,7 @@ static int main_testInitQuitSubSystem (void *arg)
}
const int joy_and_controller = SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER;
static int main_testImpliedJoystickInit (void *arg)
static int main_testImpliedJoystickInit(void *arg)
{
#if defined SDL_JOYSTICK_DISABLED || defined SDL_GAMECONTROLLER_DISABLED
return TEST_SKIPPED;
@@ -80,24 +79,24 @@ static int main_testImpliedJoystickInit (void *arg)
int initialized_system;
/* First initialize the controller */
SDLTest_AssertCheck( (SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller" );
SDLTest_AssertCheck( SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)" );
SDLTest_AssertCheck((SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller");
SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)");
/* Then make sure this implicitly initialized the joystick subsystem */
initialized_system = SDL_WasInit(joy_and_controller);
SDLTest_AssertCheck( (initialized_system & joy_and_controller) == joy_and_controller, "SDL_WasInit() should be true for joystick & controller (%x)", initialized_system );
SDLTest_AssertCheck((initialized_system & joy_and_controller) == joy_and_controller, "SDL_WasInit() should be true for joystick & controller (%x)", initialized_system);
/* Then quit the controller, and make sure that implicitly also quits the */
/* joystick subsystem */
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
initialized_system = SDL_WasInit(joy_and_controller);
SDLTest_AssertCheck( (initialized_system & joy_and_controller) == 0, "SDL_WasInit() should be false for joystick & controller (%x)", initialized_system );
SDLTest_AssertCheck((initialized_system & joy_and_controller) == 0, "SDL_WasInit() should be false for joystick & controller (%x)", initialized_system);
return TEST_COMPLETED;
#endif
}
static int main_testImpliedJoystickQuit (void *arg)
static int main_testImpliedJoystickQuit(void *arg)
{
#if defined SDL_JOYSTICK_DISABLED || defined SDL_GAMECONTROLLER_DISABLED
return TEST_SKIPPED;
@@ -105,19 +104,19 @@ static int main_testImpliedJoystickQuit (void *arg)
int initialized_system;
/* First initialize the controller and the joystick (explicitly) */
SDLTest_AssertCheck( (SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller" );
SDLTest_AssertCheck( SDL_InitSubSystem(SDL_INIT_JOYSTICK) == 0, "SDL_InitSubSystem(SDL_INIT_JOYSTICK)" );
SDLTest_AssertCheck( SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)" );
SDLTest_AssertCheck((SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller");
SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_JOYSTICK) == 0, "SDL_InitSubSystem(SDL_INIT_JOYSTICK)");
SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)");
/* Then make sure they're both initialized properly */
initialized_system = SDL_WasInit(joy_and_controller);
SDLTest_AssertCheck( (initialized_system & joy_and_controller) == joy_and_controller, "SDL_WasInit() should be true for joystick & controller (%x)", initialized_system );
SDLTest_AssertCheck((initialized_system & joy_and_controller) == joy_and_controller, "SDL_WasInit() should be true for joystick & controller (%x)", initialized_system);
/* Then quit the controller, and make sure that it does NOT quit the */
/* explicitly initialized joystick subsystem. */
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
initialized_system = SDL_WasInit(joy_and_controller);
SDLTest_AssertCheck( (initialized_system & joy_and_controller) == SDL_INIT_JOYSTICK, "SDL_WasInit() should be false for joystick & controller (%x)", initialized_system );
SDLTest_AssertCheck((initialized_system & joy_and_controller) == SDL_INIT_JOYSTICK, "SDL_WasInit() should be false for joystick & controller (%x)", initialized_system);
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
@@ -140,7 +139,7 @@ main_testSetError(void *arg)
SDL_SetError("");
SDLTest_AssertCheck(SDL_strcmp(error, SDL_GetError()) == 0, "SDL_SetError(\"\")");
for (i = 0; i < (sizeof(error)-1); ++i) {
for (i = 0; i < (sizeof(error) - 1); ++i) {
error[i] = 'a' + (i % 26);
}
error[i] = '\0';
@@ -154,23 +153,28 @@ main_testSetError(void *arg)
#pragma GCC diagnostic pop
#endif
static const SDLTest_TestCaseReference mainTest1 =
{ (SDLTest_TestCaseFp)main_testInitQuitJoystickHaptic, "main_testInitQuitJoystickHaptic", "Tests SDL_Init/Quit of Joystick and Haptic subsystem", TEST_ENABLED};
static const SDLTest_TestCaseReference mainTest1 = {
(SDLTest_TestCaseFp)main_testInitQuitJoystickHaptic, "main_testInitQuitJoystickHaptic", "Tests SDL_Init/Quit of Joystick and Haptic subsystem", TEST_ENABLED
};
static const SDLTest_TestCaseReference mainTest2 =
{ (SDLTest_TestCaseFp)main_testInitQuitSubSystem, "main_testInitQuitSubSystem", "Tests SDL_InitSubSystem/QuitSubSystem", TEST_ENABLED};
static const SDLTest_TestCaseReference mainTest2 = {
(SDLTest_TestCaseFp)main_testInitQuitSubSystem, "main_testInitQuitSubSystem", "Tests SDL_InitSubSystem/QuitSubSystem", TEST_ENABLED
};
static const SDLTest_TestCaseReference mainTest3 =
{ (SDLTest_TestCaseFp)main_testImpliedJoystickInit, "main_testImpliedJoystickInit", "Tests that init for gamecontroller properly implies joystick", TEST_ENABLED};
static const SDLTest_TestCaseReference mainTest3 = {
(SDLTest_TestCaseFp)main_testImpliedJoystickInit, "main_testImpliedJoystickInit", "Tests that init for gamecontroller properly implies joystick", TEST_ENABLED
};
static const SDLTest_TestCaseReference mainTest4 =
{ (SDLTest_TestCaseFp)main_testImpliedJoystickQuit, "main_testImpliedJoystickQuit", "Tests that quit for gamecontroller doesn't quit joystick if you inited it explicitly", TEST_ENABLED};
static const SDLTest_TestCaseReference mainTest4 = {
(SDLTest_TestCaseFp)main_testImpliedJoystickQuit, "main_testImpliedJoystickQuit", "Tests that quit for gamecontroller doesn't quit joystick if you inited it explicitly", TEST_ENABLED
};
static const SDLTest_TestCaseReference mainTest5 =
{ (SDLTest_TestCaseFp)main_testSetError, "main_testSetError", "Tests that SDL_SetError() handles arbitrarily large strings", TEST_ENABLED};
static const SDLTest_TestCaseReference mainTest5 = {
(SDLTest_TestCaseFp)main_testSetError, "main_testSetError", "Tests that SDL_SetError() handles arbitrarily large strings", TEST_ENABLED
};
/* Sequence of Main test cases */
static const SDLTest_TestCaseReference *mainTests[] = {
static const SDLTest_TestCaseReference *mainTests[] = {
&mainTest1,
&mainTest2,
&mainTest3,

View File

@@ -2769,520 +2769,520 @@ atan2_bottomLeftQuadrantTest(void *args)
/* SDL_floor test cases */
static const SDLTest_TestCaseReference floorTestInf = {
(SDLTest_TestCaseFp) floor_infCases, "floor_infCases",
(SDLTest_TestCaseFp)floor_infCases, "floor_infCases",
"Checks positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference floorTestZero = {
(SDLTest_TestCaseFp) floor_zeroCases, "floor_zeroCases",
(SDLTest_TestCaseFp)floor_zeroCases, "floor_zeroCases",
"Checks positive and negative zero", TEST_ENABLED
};
static const SDLTest_TestCaseReference floorTestNan = {
(SDLTest_TestCaseFp) floor_nanCase, "floor_nanCase",
(SDLTest_TestCaseFp)floor_nanCase, "floor_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference floorTestRound = {
(SDLTest_TestCaseFp) floor_roundNumbersCases, "floor_roundNumberCases",
(SDLTest_TestCaseFp)floor_roundNumbersCases, "floor_roundNumberCases",
"Checks a set of integral values", TEST_ENABLED
};
static const SDLTest_TestCaseReference floorTestFraction = {
(SDLTest_TestCaseFp) floor_fractionCases, "floor_fractionCases",
(SDLTest_TestCaseFp)floor_fractionCases, "floor_fractionCases",
"Checks a set of fractions", TEST_ENABLED
};
static const SDLTest_TestCaseReference floorTestRange = {
(SDLTest_TestCaseFp) floor_rangeTest, "floor_rangeTest",
(SDLTest_TestCaseFp)floor_rangeTest, "floor_rangeTest",
"Checks a range of positive integer", TEST_ENABLED
};
/* SDL_ceil test cases */
static const SDLTest_TestCaseReference ceilTestInf = {
(SDLTest_TestCaseFp) ceil_infCases, "ceil_infCases",
(SDLTest_TestCaseFp)ceil_infCases, "ceil_infCases",
"Checks positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference ceilTestZero = {
(SDLTest_TestCaseFp) ceil_zeroCases, "ceil_zeroCases",
(SDLTest_TestCaseFp)ceil_zeroCases, "ceil_zeroCases",
"Checks positive and negative zero", TEST_ENABLED
};
static const SDLTest_TestCaseReference ceilTestNan = {
(SDLTest_TestCaseFp) ceil_nanCase, "ceil_nanCase",
(SDLTest_TestCaseFp)ceil_nanCase, "ceil_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference ceilTestRound = {
(SDLTest_TestCaseFp) ceil_roundNumbersCases, "ceil_roundNumberCases",
(SDLTest_TestCaseFp)ceil_roundNumbersCases, "ceil_roundNumberCases",
"Checks a set of integral values", TEST_ENABLED
};
static const SDLTest_TestCaseReference ceilTestFraction = {
(SDLTest_TestCaseFp) ceil_fractionCases, "ceil_fractionCases",
(SDLTest_TestCaseFp)ceil_fractionCases, "ceil_fractionCases",
"Checks a set of fractions", TEST_ENABLED
};
static const SDLTest_TestCaseReference ceilTestRange = {
(SDLTest_TestCaseFp) ceil_rangeTest, "ceil_rangeTest",
(SDLTest_TestCaseFp)ceil_rangeTest, "ceil_rangeTest",
"Checks a range of positive integer", TEST_ENABLED
};
/* SDL_trunc test cases */
static const SDLTest_TestCaseReference truncTestInf = {
(SDLTest_TestCaseFp) trunc_infCases, "trunc_infCases",
(SDLTest_TestCaseFp)trunc_infCases, "trunc_infCases",
"Checks positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference truncTestZero = {
(SDLTest_TestCaseFp) trunc_zeroCases, "trunc_zeroCases",
(SDLTest_TestCaseFp)trunc_zeroCases, "trunc_zeroCases",
"Checks positive and negative zero", TEST_ENABLED
};
static const SDLTest_TestCaseReference truncTestNan = {
(SDLTest_TestCaseFp) trunc_nanCase, "trunc_nanCase",
(SDLTest_TestCaseFp)trunc_nanCase, "trunc_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference truncTestRound = {
(SDLTest_TestCaseFp) trunc_roundNumbersCases, "trunc_roundNumberCases",
(SDLTest_TestCaseFp)trunc_roundNumbersCases, "trunc_roundNumberCases",
"Checks a set of integral values", TEST_ENABLED
};
static const SDLTest_TestCaseReference truncTestFraction = {
(SDLTest_TestCaseFp) trunc_fractionCases, "trunc_fractionCases",
(SDLTest_TestCaseFp)trunc_fractionCases, "trunc_fractionCases",
"Checks a set of fractions", TEST_ENABLED
};
static const SDLTest_TestCaseReference truncTestRange = {
(SDLTest_TestCaseFp) trunc_rangeTest, "trunc_rangeTest",
(SDLTest_TestCaseFp)trunc_rangeTest, "trunc_rangeTest",
"Checks a range of positive integer", TEST_ENABLED
};
/* SDL_round test cases */
static const SDLTest_TestCaseReference roundTestInf = {
(SDLTest_TestCaseFp) round_infCases, "round_infCases",
(SDLTest_TestCaseFp)round_infCases, "round_infCases",
"Checks positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference roundTestZero = {
(SDLTest_TestCaseFp) round_zeroCases, "round_zeroCases",
(SDLTest_TestCaseFp)round_zeroCases, "round_zeroCases",
"Checks positive and negative zero", TEST_ENABLED
};
static const SDLTest_TestCaseReference roundTestNan = {
(SDLTest_TestCaseFp) round_nanCase, "round_nanCase",
(SDLTest_TestCaseFp)round_nanCase, "round_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference roundTestRound = {
(SDLTest_TestCaseFp) round_roundNumbersCases, "round_roundNumberCases",
(SDLTest_TestCaseFp)round_roundNumbersCases, "round_roundNumberCases",
"Checks a set of integral values", TEST_ENABLED
};
static const SDLTest_TestCaseReference roundTestFraction = {
(SDLTest_TestCaseFp) round_fractionCases, "round_fractionCases",
(SDLTest_TestCaseFp)round_fractionCases, "round_fractionCases",
"Checks a set of fractions", TEST_ENABLED
};
static const SDLTest_TestCaseReference roundTestRange = {
(SDLTest_TestCaseFp) round_rangeTest, "round_rangeTest",
(SDLTest_TestCaseFp)round_rangeTest, "round_rangeTest",
"Checks a range of positive integer", TEST_ENABLED
};
/* SDL_fabs test cases */
static const SDLTest_TestCaseReference fabsTestInf = {
(SDLTest_TestCaseFp) fabs_infCases, "fabs_infCases",
(SDLTest_TestCaseFp)fabs_infCases, "fabs_infCases",
"Checks positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference fabsTestZero = {
(SDLTest_TestCaseFp) fabs_zeroCases, "fabs_zeroCases",
(SDLTest_TestCaseFp)fabs_zeroCases, "fabs_zeroCases",
"Checks positive and negative zero", TEST_ENABLED
};
static const SDLTest_TestCaseReference fabsTestNan = {
(SDLTest_TestCaseFp) fabs_nanCase, "fabs_nanCase",
(SDLTest_TestCaseFp)fabs_nanCase, "fabs_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference fabsTestRange = {
(SDLTest_TestCaseFp) fabs_rangeTest, "fabs_rangeTest",
(SDLTest_TestCaseFp)fabs_rangeTest, "fabs_rangeTest",
"Checks a range of positive integer", TEST_ENABLED
};
/* SDL_copysign test cases */
static const SDLTest_TestCaseReference copysignTestInf = {
(SDLTest_TestCaseFp) copysign_infCases, "copysign_infCases",
(SDLTest_TestCaseFp)copysign_infCases, "copysign_infCases",
"Checks positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference copysignTestZero = {
(SDLTest_TestCaseFp) copysign_zeroCases, "copysign_zeroCases",
(SDLTest_TestCaseFp)copysign_zeroCases, "copysign_zeroCases",
"Checks positive and negative zero", TEST_ENABLED
};
static const SDLTest_TestCaseReference copysignTestNan = {
(SDLTest_TestCaseFp) copysign_nanCases, "copysign_nanCases",
(SDLTest_TestCaseFp)copysign_nanCases, "copysign_nanCases",
"Checks NANs", TEST_ENABLED
};
static const SDLTest_TestCaseReference copysignTestRange = {
(SDLTest_TestCaseFp) copysign_rangeTest, "copysign_rangeTest",
(SDLTest_TestCaseFp)copysign_rangeTest, "copysign_rangeTest",
"Checks a range of positive integer", TEST_ENABLED
};
/* SDL_fmod test cases */
static const SDLTest_TestCaseReference fmodTestDivOfInf = {
(SDLTest_TestCaseFp) fmod_divOfInfCases, "fmod_divOfInfCases",
(SDLTest_TestCaseFp)fmod_divOfInfCases, "fmod_divOfInfCases",
"Checks division of positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference fmodTestDivByInf = {
(SDLTest_TestCaseFp) fmod_divByInfCases, "fmod_divByInfCases",
(SDLTest_TestCaseFp)fmod_divByInfCases, "fmod_divByInfCases",
"Checks division by positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference fmodTestDivOfZero = {
(SDLTest_TestCaseFp) fmod_divOfZeroCases, "fmod_divOfZeroCases",
(SDLTest_TestCaseFp)fmod_divOfZeroCases, "fmod_divOfZeroCases",
"Checks division of positive and negative zero", TEST_ENABLED
};
static const SDLTest_TestCaseReference fmodTestDivByZero = {
(SDLTest_TestCaseFp) fmod_divByZeroCases, "fmod_divByZeroCases",
(SDLTest_TestCaseFp)fmod_divByZeroCases, "fmod_divByZeroCases",
"Checks division by positive and negative zero", TEST_ENABLED
};
static const SDLTest_TestCaseReference fmodTestNan = {
(SDLTest_TestCaseFp) fmod_nanCases, "fmod_nanCases",
(SDLTest_TestCaseFp)fmod_nanCases, "fmod_nanCases",
"Checks NANs", TEST_ENABLED
};
static const SDLTest_TestCaseReference fmodTestRegular = {
(SDLTest_TestCaseFp) fmod_regularCases, "fmod_regularCases",
(SDLTest_TestCaseFp)fmod_regularCases, "fmod_regularCases",
"Checks a set of regular values", TEST_ENABLED
};
static const SDLTest_TestCaseReference fmodTestRange = {
(SDLTest_TestCaseFp) fmod_rangeTest, "fmod_rangeTest",
(SDLTest_TestCaseFp)fmod_rangeTest, "fmod_rangeTest",
"Checks a range of positive integer", TEST_ENABLED
};
/* SDL_exp test cases */
static const SDLTest_TestCaseReference expTestInf = {
(SDLTest_TestCaseFp) exp_infCases, "exp_infCases",
(SDLTest_TestCaseFp)exp_infCases, "exp_infCases",
"Checks positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference expTestZero = {
(SDLTest_TestCaseFp) exp_zeroCases, "exp_zeroCases",
(SDLTest_TestCaseFp)exp_zeroCases, "exp_zeroCases",
"Checks for positive and negative zero", TEST_ENABLED
};
static const SDLTest_TestCaseReference expTestOverflow = {
(SDLTest_TestCaseFp) exp_overflowCase, "exp_overflowCase",
(SDLTest_TestCaseFp)exp_overflowCase, "exp_overflowCase",
"Checks for overflow", TEST_ENABLED
};
static const SDLTest_TestCaseReference expTestBase = {
(SDLTest_TestCaseFp) exp_baseCase, "exp_baseCase",
(SDLTest_TestCaseFp)exp_baseCase, "exp_baseCase",
"Checks the base case", TEST_ENABLED
};
static const SDLTest_TestCaseReference expTestRegular = {
(SDLTest_TestCaseFp) exp_regularCases, "exp_regularCases",
(SDLTest_TestCaseFp)exp_regularCases, "exp_regularCases",
"Checks a set of regular values", TEST_ENABLED
};
/* SDL_log test cases */
static const SDLTest_TestCaseReference logTestLimit = {
(SDLTest_TestCaseFp) log_limitCases, "log_limitCases",
(SDLTest_TestCaseFp)log_limitCases, "log_limitCases",
"Checks the domain limits", TEST_ENABLED
};
static const SDLTest_TestCaseReference logTestNan = {
(SDLTest_TestCaseFp) log_nanCases, "log_nanCases",
(SDLTest_TestCaseFp)log_nanCases, "log_nanCases",
"Checks NAN and negative values", TEST_ENABLED
};
static const SDLTest_TestCaseReference logTestBase = {
(SDLTest_TestCaseFp) log_baseCases, "log_baseCases",
(SDLTest_TestCaseFp)log_baseCases, "log_baseCases",
"Checks the base cases", TEST_ENABLED
};
static const SDLTest_TestCaseReference logTestRegular = {
(SDLTest_TestCaseFp) log_regularCases, "log_regularCases",
(SDLTest_TestCaseFp)log_regularCases, "log_regularCases",
"Checks a set of regular values", TEST_ENABLED
};
/* SDL_log10 test cases */
static const SDLTest_TestCaseReference log10TestLimit = {
(SDLTest_TestCaseFp) log10_limitCases, "log10_limitCases",
(SDLTest_TestCaseFp)log10_limitCases, "log10_limitCases",
"Checks the domain limits", TEST_ENABLED
};
static const SDLTest_TestCaseReference log10TestNan = {
(SDLTest_TestCaseFp) log10_nanCases, "log10_nanCases",
(SDLTest_TestCaseFp)log10_nanCases, "log10_nanCases",
"Checks NAN and negative values", TEST_ENABLED
};
static const SDLTest_TestCaseReference log10TestBase = {
(SDLTest_TestCaseFp) log10_baseCases, "log10_baseCases",
(SDLTest_TestCaseFp)log10_baseCases, "log10_baseCases",
"Checks the base cases", TEST_ENABLED
};
static const SDLTest_TestCaseReference log10TestRegular = {
(SDLTest_TestCaseFp) log10_regularCases, "log10_regularCases",
(SDLTest_TestCaseFp)log10_regularCases, "log10_regularCases",
"Checks a set of regular values", TEST_ENABLED
};
/* SDL_pow test cases */
static const SDLTest_TestCaseReference powTestExpInf1 = {
(SDLTest_TestCaseFp) pow_baseNOneExpInfCases, "pow_baseNOneExpInfCases",
(SDLTest_TestCaseFp)pow_baseNOneExpInfCases, "pow_baseNOneExpInfCases",
"Checks for pow(-1, +/-inf)", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestExpInf2 = {
(SDLTest_TestCaseFp) pow_baseZeroExpNInfCases, "pow_baseZeroExpNInfCases",
(SDLTest_TestCaseFp)pow_baseZeroExpNInfCases, "pow_baseZeroExpNInfCases",
"Checks for pow(+/-0, -inf)", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestExpInf3 = {
(SDLTest_TestCaseFp) pow_expInfCases, "pow_expInfCases",
(SDLTest_TestCaseFp)pow_expInfCases, "pow_expInfCases",
"Checks for pow(x, +/-inf)", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestBaseInf1 = {
(SDLTest_TestCaseFp) pow_basePInfCases, "pow_basePInfCases",
(SDLTest_TestCaseFp)pow_basePInfCases, "pow_basePInfCases",
"Checks for pow(inf, x)", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestBaseInf2 = {
(SDLTest_TestCaseFp) pow_baseNInfCases, "pow_baseNInfCases",
(SDLTest_TestCaseFp)pow_baseNInfCases, "pow_baseNInfCases",
"Checks for pow(-inf, x)", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestNan1 = {
(SDLTest_TestCaseFp) pow_badOperationCase, "pow_badOperationCase",
(SDLTest_TestCaseFp)pow_badOperationCase, "pow_badOperationCase",
"Checks for negative finite base and non-integer finite exponent", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestNan2 = {
(SDLTest_TestCaseFp) pow_base1ExpNanCase, "pow_base1ExpNanCase",
(SDLTest_TestCaseFp)pow_base1ExpNanCase, "pow_base1ExpNanCase",
"Checks for pow(1.0, NAN)", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestNan3 = {
(SDLTest_TestCaseFp) pow_baseNanExp0Cases, "pow_baseNanExp0Cases",
(SDLTest_TestCaseFp)pow_baseNanExp0Cases, "pow_baseNanExp0Cases",
"Checks for pow(NAN, +/-0)", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestNan4 = {
(SDLTest_TestCaseFp) pow_nanArgsCases, "pow_nanArgsCases",
(SDLTest_TestCaseFp)pow_nanArgsCases, "pow_nanArgsCases",
"Checks for pow(x, y) with either x or y being NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestZero1 = {
(SDLTest_TestCaseFp) pow_baseNZeroExpOddCases, "pow_baseNZeroExpOddCases",
(SDLTest_TestCaseFp)pow_baseNZeroExpOddCases, "pow_baseNZeroExpOddCases",
"Checks for pow(-0.0, y), with y an odd integer.", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestZero2 = {
(SDLTest_TestCaseFp) pow_basePZeroExpOddCases, "pow_basePZeroExpOddCases",
(SDLTest_TestCaseFp)pow_basePZeroExpOddCases, "pow_basePZeroExpOddCases",
"Checks for pow(0.0, y), with y an odd integer.", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestZero3 = {
(SDLTest_TestCaseFp) pow_baseNZeroCases, "pow_baseNZeroCases",
(SDLTest_TestCaseFp)pow_baseNZeroCases, "pow_baseNZeroCases",
"Checks for pow(-0.0, y), with y finite and even or non-integer number", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestZero4 = {
(SDLTest_TestCaseFp) pow_basePZeroCases, "pow_basePZeroCases",
(SDLTest_TestCaseFp)pow_basePZeroCases, "pow_basePZeroCases",
"Checks for pow(0.0, y), with y finite and even or non-integer number", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestRegular = {
(SDLTest_TestCaseFp) pow_regularCases, "pow_regularCases",
(SDLTest_TestCaseFp)pow_regularCases, "pow_regularCases",
"Checks a set of regular values", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestPowOf2 = {
(SDLTest_TestCaseFp) pow_powerOfTwo, "pow_powerOfTwo",
(SDLTest_TestCaseFp)pow_powerOfTwo, "pow_powerOfTwo",
"Checks the powers of two from 1 to 8", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestRange = {
(SDLTest_TestCaseFp) pow_rangeTest, "pow_rangeTest",
(SDLTest_TestCaseFp)pow_rangeTest, "pow_rangeTest",
"Checks a range of positive integer to the power of 0", TEST_ENABLED
};
/* SDL_sqrt test cases */
static const SDLTest_TestCaseReference sqrtTestInf = {
(SDLTest_TestCaseFp) sqrt_infCase, "sqrt_infCase",
(SDLTest_TestCaseFp)sqrt_infCase, "sqrt_infCase",
"Checks positive infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference sqrtTestNan = {
(SDLTest_TestCaseFp) sqrt_nanCase, "sqrt_nanCase",
(SDLTest_TestCaseFp)sqrt_nanCase, "sqrt_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference sqrtTestDomain = {
(SDLTest_TestCaseFp) sqrt_outOfDomainCases, "sqrt_outOfDomainCases",
(SDLTest_TestCaseFp)sqrt_outOfDomainCases, "sqrt_outOfDomainCases",
"Checks for values out of the domain", TEST_ENABLED
};
static const SDLTest_TestCaseReference sqrtTestBase = {
(SDLTest_TestCaseFp) sqrt_baseCases, "sqrt_baseCases",
(SDLTest_TestCaseFp)sqrt_baseCases, "sqrt_baseCases",
"Checks the base cases", TEST_ENABLED
};
static const SDLTest_TestCaseReference sqrtTestRegular = {
(SDLTest_TestCaseFp) sqrt_regularCases, "sqrt_regularCases",
(SDLTest_TestCaseFp)sqrt_regularCases, "sqrt_regularCases",
"Checks a set of regular values", TEST_ENABLED
};
/* SDL_scalbn test cases */
static const SDLTest_TestCaseReference scalbnTestInf = {
(SDLTest_TestCaseFp) scalbn_infCases, "scalbn_infCases",
(SDLTest_TestCaseFp)scalbn_infCases, "scalbn_infCases",
"Checks positive and negative infinity arg", TEST_ENABLED
};
static const SDLTest_TestCaseReference scalbnTestBaseZero = {
(SDLTest_TestCaseFp) scalbn_baseZeroCases, "scalbn_baseZeroCases",
(SDLTest_TestCaseFp)scalbn_baseZeroCases, "scalbn_baseZeroCases",
"Checks for positive and negative zero arg", TEST_ENABLED
};
static const SDLTest_TestCaseReference scalbnTestExpZero = {
(SDLTest_TestCaseFp) scalbn_expZeroCase, "scalbn_expZeroCase",
(SDLTest_TestCaseFp)scalbn_expZeroCase, "scalbn_expZeroCase",
"Checks for zero exp", TEST_ENABLED
};
static const SDLTest_TestCaseReference scalbnTestNan = {
(SDLTest_TestCaseFp) scalbn_nanCase, "scalbn_nanCase",
(SDLTest_TestCaseFp)scalbn_nanCase, "scalbn_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference scalbnTestRegular = {
(SDLTest_TestCaseFp) scalbn_regularCases, "scalbn_regularCases",
(SDLTest_TestCaseFp)scalbn_regularCases, "scalbn_regularCases",
"Checks a set of regular cases", TEST_ENABLED
};
/* SDL_cos test cases */
static const SDLTest_TestCaseReference cosTestInf = {
(SDLTest_TestCaseFp) cos_infCases, "cos_infCases",
(SDLTest_TestCaseFp)cos_infCases, "cos_infCases",
"Checks for positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference cosTestNan = {
(SDLTest_TestCaseFp) cos_nanCase, "cos_nanCase",
(SDLTest_TestCaseFp)cos_nanCase, "cos_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference cosTestRegular = {
(SDLTest_TestCaseFp) cos_regularCases, "cos_regularCases",
(SDLTest_TestCaseFp)cos_regularCases, "cos_regularCases",
"Checks a set of regular cases", TEST_ENABLED
};
static const SDLTest_TestCaseReference cosTestPrecision = {
(SDLTest_TestCaseFp) cos_precisionTest, "cos_precisionTest",
(SDLTest_TestCaseFp)cos_precisionTest, "cos_precisionTest",
"Checks cosine precision", TEST_ENABLED
};
static const SDLTest_TestCaseReference cosTestRange = {
(SDLTest_TestCaseFp) cos_rangeTest, "cos_rangeTest",
(SDLTest_TestCaseFp)cos_rangeTest, "cos_rangeTest",
"Checks a range of positive integer", TEST_ENABLED
};
/* SDL_sin test cases */
static const SDLTest_TestCaseReference sinTestInf = {
(SDLTest_TestCaseFp) sin_infCases, "sin_infCases",
(SDLTest_TestCaseFp)sin_infCases, "sin_infCases",
"Checks for positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference sinTestNan = {
(SDLTest_TestCaseFp) sin_nanCase, "sin_nanCase",
(SDLTest_TestCaseFp)sin_nanCase, "sin_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference sinTestRegular = {
(SDLTest_TestCaseFp) sin_regularCases, "sin_regularCases",
(SDLTest_TestCaseFp)sin_regularCases, "sin_regularCases",
"Checks a set of regular cases", TEST_ENABLED
};
static const SDLTest_TestCaseReference sinTestPrecision = {
(SDLTest_TestCaseFp) sin_precisionTest, "sin_precisionTest",
(SDLTest_TestCaseFp)sin_precisionTest, "sin_precisionTest",
"Checks sine precision", TEST_ENABLED
};
static const SDLTest_TestCaseReference sinTestRange = {
(SDLTest_TestCaseFp) sin_rangeTest, "sin_rangeTest",
(SDLTest_TestCaseFp)sin_rangeTest, "sin_rangeTest",
"Checks a range of positive integer", TEST_ENABLED
};
/* SDL_tan test cases */
static const SDLTest_TestCaseReference tanTestInf = {
(SDLTest_TestCaseFp) tan_infCases, "tan_infCases",
(SDLTest_TestCaseFp)tan_infCases, "tan_infCases",
"Checks for positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference tanTestNan = {
(SDLTest_TestCaseFp) tan_nanCase, "tan_nanCase",
(SDLTest_TestCaseFp)tan_nanCase, "tan_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference tanTestZero = {
(SDLTest_TestCaseFp) tan_zeroCases, "tan_zeroCases",
(SDLTest_TestCaseFp)tan_zeroCases, "tan_zeroCases",
"Checks a set of regular cases", TEST_ENABLED
};
static const SDLTest_TestCaseReference tanTestPrecision = {
(SDLTest_TestCaseFp) tan_precisionTest, "tan_precisionTest",
(SDLTest_TestCaseFp)tan_precisionTest, "tan_precisionTest",
"Checks tangent precision", TEST_ENABLED
};
/* SDL_acos test cases */
static const SDLTest_TestCaseReference acosTestLimit = {
(SDLTest_TestCaseFp) acos_limitCases, "acos_limitCases",
(SDLTest_TestCaseFp)acos_limitCases, "acos_limitCases",
"Checks the edge of the domain (+/-1)", TEST_ENABLED
};
static const SDLTest_TestCaseReference acosTestOutOfDomain = {
(SDLTest_TestCaseFp) acos_outOfDomainCases, "acos_outOfDomainCases",
(SDLTest_TestCaseFp)acos_outOfDomainCases, "acos_outOfDomainCases",
"Checks values outside the domain", TEST_ENABLED
};
static const SDLTest_TestCaseReference acosTestNan = {
(SDLTest_TestCaseFp) acos_nanCase, "acos_nanCase",
(SDLTest_TestCaseFp)acos_nanCase, "acos_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference acosTestPrecision = {
(SDLTest_TestCaseFp) acos_precisionTest, "acos_precisionTest",
(SDLTest_TestCaseFp)acos_precisionTest, "acos_precisionTest",
"Checks acos precision", TEST_ENABLED
};
/* SDL_asin test cases */
static const SDLTest_TestCaseReference asinTestLimit = {
(SDLTest_TestCaseFp) asin_limitCases, "asin_limitCases",
(SDLTest_TestCaseFp)asin_limitCases, "asin_limitCases",
"Checks the edge of the domain (+/-1)", TEST_ENABLED
};
static const SDLTest_TestCaseReference asinTestOutOfDomain = {
(SDLTest_TestCaseFp) asin_outOfDomainCases, "asin_outOfDomainCases",
(SDLTest_TestCaseFp)asin_outOfDomainCases, "asin_outOfDomainCases",
"Checks values outside the domain", TEST_ENABLED
};
static const SDLTest_TestCaseReference asinTestNan = {
(SDLTest_TestCaseFp) asin_nanCase, "asin_nanCase",
(SDLTest_TestCaseFp)asin_nanCase, "asin_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference asinTestPrecision = {
(SDLTest_TestCaseFp) asin_precisionTest, "asin_precisionTest",
(SDLTest_TestCaseFp)asin_precisionTest, "asin_precisionTest",
"Checks asin precision", TEST_ENABLED
};
/* SDL_atan test cases */
static const SDLTest_TestCaseReference atanTestLimit = {
(SDLTest_TestCaseFp) atan_limitCases, "atan_limitCases",
(SDLTest_TestCaseFp)atan_limitCases, "atan_limitCases",
"Checks the edge of the domain (+/-Infinity)", TEST_ENABLED
};
static const SDLTest_TestCaseReference atanTestZero = {
(SDLTest_TestCaseFp) atan_zeroCases, "atan_zeroCases",
(SDLTest_TestCaseFp)atan_zeroCases, "atan_zeroCases",
"Checks for positive and negative zero", TEST_ENABLED
};
static const SDLTest_TestCaseReference atanTestNan = {
(SDLTest_TestCaseFp) atan_nanCase, "atan_nanCase",
(SDLTest_TestCaseFp)atan_nanCase, "atan_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference atanTestPrecision = {
(SDLTest_TestCaseFp) atan_precisionTest, "atan_precisionTest",
(SDLTest_TestCaseFp)atan_precisionTest, "atan_precisionTest",
"Checks atan precision", TEST_ENABLED
};
/* SDL_atan2 test cases */
static const SDLTest_TestCaseReference atan2TestZero1 = {
(SDLTest_TestCaseFp) atan2_bothZeroCases, "atan2_bothZeroCases",
(SDLTest_TestCaseFp)atan2_bothZeroCases, "atan2_bothZeroCases",
"Checks for both arguments being zero", TEST_ENABLED
};
static const SDLTest_TestCaseReference atan2TestZero2 = {
(SDLTest_TestCaseFp) atan2_yZeroCases, "atan2_yZeroCases",
(SDLTest_TestCaseFp)atan2_yZeroCases, "atan2_yZeroCases",
"Checks for y=0", TEST_ENABLED
};
static const SDLTest_TestCaseReference atan2TestZero3 = {
(SDLTest_TestCaseFp) atan2_xZeroCases, "atan2_xZeroCases",
(SDLTest_TestCaseFp)atan2_xZeroCases, "atan2_xZeroCases",
"Checks for x=0", TEST_ENABLED
};
static const SDLTest_TestCaseReference atan2TestInf1 = {
(SDLTest_TestCaseFp) atan2_bothInfCases, "atan2_bothInfCases",
(SDLTest_TestCaseFp)atan2_bothInfCases, "atan2_bothInfCases",
"Checks for both arguments being infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference atan2TestInf2 = {
(SDLTest_TestCaseFp) atan2_yInfCases, "atan2_yInfCases",
(SDLTest_TestCaseFp)atan2_yInfCases, "atan2_yInfCases",
"Checks for y=0", TEST_ENABLED
};
static const SDLTest_TestCaseReference atan2TestInf3 = {
(SDLTest_TestCaseFp) atan2_xInfCases, "atan2_xInfCases",
(SDLTest_TestCaseFp)atan2_xInfCases, "atan2_xInfCases",
"Checks for x=0", TEST_ENABLED
};
static const SDLTest_TestCaseReference atan2TestNan = {
(SDLTest_TestCaseFp) atan2_nanCases, "atan2_nanCases",
(SDLTest_TestCaseFp)atan2_nanCases, "atan2_nanCases",
"Checks NANs", TEST_ENABLED
};
static const SDLTest_TestCaseReference atan2TestQuadrantTopRight = {
(SDLTest_TestCaseFp) atan2_topRightQuadrantTest, "atan2_topRightQuadrantTest",
(SDLTest_TestCaseFp)atan2_topRightQuadrantTest, "atan2_topRightQuadrantTest",
"Checks values in the top right quadrant", TEST_ENABLED
};
static const SDLTest_TestCaseReference atan2TestQuadrantTopLeft = {
(SDLTest_TestCaseFp) atan2_topLeftQuadrantTest, "atan2_topLeftQuadrantTest",
(SDLTest_TestCaseFp)atan2_topLeftQuadrantTest, "atan2_topLeftQuadrantTest",
"Checks values in the top left quadrant", TEST_ENABLED
};
static const SDLTest_TestCaseReference atan2TestQuadrantBottomRight = {
(SDLTest_TestCaseFp) atan2_bottomRightQuadrantTest, "atan2_bottomRightQuadrantTest",
(SDLTest_TestCaseFp)atan2_bottomRightQuadrantTest, "atan2_bottomRightQuadrantTest",
"Checks values in the bottom right quadrant", TEST_ENABLED
};
static const SDLTest_TestCaseReference atan2TestQuadrantBottomLeft = {
(SDLTest_TestCaseFp) atan2_bottomLeftQuadrantTest, "atan2_bottomLeftQuadrantTest",
(SDLTest_TestCaseFp)atan2_bottomLeftQuadrantTest, "atan2_bottomLeftQuadrantTest",
"Checks values in the bottom left quadrant", TEST_ENABLED
};

View File

@@ -15,178 +15,175 @@
/* Helper to evaluate state returned from SDL_GetMouseState */
int _mouseStateCheck(Uint32 state)
{
return (state == 0) ||
(state == SDL_BUTTON(SDL_BUTTON_LEFT)) ||
(state == SDL_BUTTON(SDL_BUTTON_MIDDLE)) ||
(state == SDL_BUTTON(SDL_BUTTON_RIGHT)) ||
(state == SDL_BUTTON(SDL_BUTTON_X1)) ||
(state == SDL_BUTTON(SDL_BUTTON_X2));
return (state == 0) ||
(state == SDL_BUTTON(SDL_BUTTON_LEFT)) ||
(state == SDL_BUTTON(SDL_BUTTON_MIDDLE)) ||
(state == SDL_BUTTON(SDL_BUTTON_RIGHT)) ||
(state == SDL_BUTTON(SDL_BUTTON_X1)) ||
(state == SDL_BUTTON(SDL_BUTTON_X2));
}
/**
* @brief Check call to SDL_GetMouseState
*
*/
int
mouse_getMouseState(void *arg)
int mouse_getMouseState(void *arg)
{
int x;
int y;
Uint32 state;
int x;
int y;
Uint32 state;
/* Pump some events to update mouse state */
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
/* Pump some events to update mouse state */
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
/* Case where x, y pointer is NULL */
state = SDL_GetMouseState(NULL, NULL);
SDLTest_AssertPass("Call to SDL_GetMouseState(NULL, NULL)");
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
/* Case where x, y pointer is NULL */
state = SDL_GetMouseState(NULL, NULL);
SDLTest_AssertPass("Call to SDL_GetMouseState(NULL, NULL)");
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
/* Case where x pointer is not NULL */
x = INT_MIN;
state = SDL_GetMouseState(&x, NULL);
SDLTest_AssertPass("Call to SDL_GetMouseState(&x, NULL)");
SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
/* Case where x pointer is not NULL */
x = INT_MIN;
state = SDL_GetMouseState(&x, NULL);
SDLTest_AssertPass("Call to SDL_GetMouseState(&x, NULL)");
SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
/* Case where y pointer is not NULL */
y = INT_MIN;
state = SDL_GetMouseState(NULL, &y);
SDLTest_AssertPass("Call to SDL_GetMouseState(NULL, &y)");
SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
/* Case where y pointer is not NULL */
y = INT_MIN;
state = SDL_GetMouseState(NULL, &y);
SDLTest_AssertPass("Call to SDL_GetMouseState(NULL, &y)");
SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
/* Case where x and y pointer is not NULL */
x = INT_MIN;
y = INT_MIN;
state = SDL_GetMouseState(&x, &y);
SDLTest_AssertPass("Call to SDL_GetMouseState(&x, &y)");
SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
/* Case where x and y pointer is not NULL */
x = INT_MIN;
y = INT_MIN;
state = SDL_GetMouseState(&x, &y);
SDLTest_AssertPass("Call to SDL_GetMouseState(&x, &y)");
SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
* @brief Check call to SDL_GetRelativeMouseState
*
*/
int
mouse_getRelativeMouseState(void *arg)
int mouse_getRelativeMouseState(void *arg)
{
int x;
int y;
Uint32 state;
int x;
int y;
Uint32 state;
/* Pump some events to update mouse state */
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
/* Pump some events to update mouse state */
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
/* Case where x, y pointer is NULL */
state = SDL_GetRelativeMouseState(NULL, NULL);
SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(NULL, NULL)");
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
/* Case where x, y pointer is NULL */
state = SDL_GetRelativeMouseState(NULL, NULL);
SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(NULL, NULL)");
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
/* Case where x pointer is not NULL */
x = INT_MIN;
state = SDL_GetRelativeMouseState(&x, NULL);
SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(&x, NULL)");
SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
/* Case where x pointer is not NULL */
x = INT_MIN;
state = SDL_GetRelativeMouseState(&x, NULL);
SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(&x, NULL)");
SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
/* Case where y pointer is not NULL */
y = INT_MIN;
state = SDL_GetRelativeMouseState(NULL, &y);
SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(NULL, &y)");
SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
/* Case where y pointer is not NULL */
y = INT_MIN;
state = SDL_GetRelativeMouseState(NULL, &y);
SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(NULL, &y)");
SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
/* Case where x and y pointer is not NULL */
x = INT_MIN;
y = INT_MIN;
state = SDL_GetRelativeMouseState(&x, &y);
SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(&x, &y)");
SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
/* Case where x and y pointer is not NULL */
x = INT_MIN;
y = INT_MIN;
state = SDL_GetRelativeMouseState(&x, &y);
SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(&x, &y)");
SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/* XPM definition of mouse Cursor */
static const char *_mouseArrowData[] = {
/* pixels */
"X ",
"XX ",
"X.X ",
"X..X ",
"X...X ",
"X....X ",
"X.....X ",
"X......X ",
"X.......X ",
"X........X ",
"X.....XXXXX ",
"X..X..X ",
"X.X X..X ",
"XX X..X ",
"X X..X ",
" X..X ",
" X..X ",
" X..X ",
" XX ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "
/* pixels */
"X ",
"XX ",
"X.X ",
"X..X ",
"X...X ",
"X....X ",
"X.....X ",
"X......X ",
"X.......X ",
"X........X ",
"X.....XXXXX ",
"X..X..X ",
"X.X X..X ",
"XX X..X ",
"X X..X ",
" X..X ",
" X..X ",
" X..X ",
" XX ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "
};
/* Helper that creates a new mouse cursor from an XPM */
static SDL_Cursor *_initArrowCursor(const char *image[])
{
SDL_Cursor *cursor;
int i, row, col;
Uint8 data[4*32];
Uint8 mask[4*32];
SDL_Cursor *cursor;
int i, row, col;
Uint8 data[4 * 32];
Uint8 mask[4 * 32];
i = -1;
for ( row=0; row<32; ++row ) {
for ( col=0; col<32; ++col ) {
if ( col % 8 ) {
data[i] <<= 1;
mask[i] <<= 1;
} else {
++i;
data[i] = mask[i] = 0;
}
switch (image[row][col]) {
case 'X':
data[i] |= 0x01;
mask[i] |= 0x01;
break;
case '.':
mask[i] |= 0x01;
break;
case ' ':
break;
}
i = -1;
for (row = 0; row < 32; ++row) {
for (col = 0; col < 32; ++col) {
if (col % 8) {
data[i] <<= 1;
mask[i] <<= 1;
} else {
++i;
data[i] = mask[i] = 0;
}
switch (image[row][col]) {
case 'X':
data[i] |= 0x01;
mask[i] |= 0x01;
break;
case '.':
mask[i] |= 0x01;
break;
case ' ':
break;
}
}
}
}
cursor = SDL_CreateCursor(data, mask, 32, 32, 0, 0);
return cursor;
cursor = SDL_CreateCursor(data, mask, 32, 32, 0, 0);
return cursor;
}
/**
@@ -195,15 +192,14 @@ static SDL_Cursor *_initArrowCursor(const char *image[])
* @sa http://wiki.libsdl.org/SDL_CreateCursor
* @sa http://wiki.libsdl.org/SDL_FreeCursor
*/
int
mouse_createFreeCursor(void *arg)
int mouse_createFreeCursor(void *arg)
{
SDL_Cursor *cursor;
/* Create a cursor */
cursor = _initArrowCursor(_mouseArrowData);
SDLTest_AssertPass("Call to SDL_CreateCursor()");
SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL");
SDLTest_AssertPass("Call to SDL_CreateCursor()");
SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL");
if (cursor == NULL) {
return TEST_ABORTED;
}
@@ -221,8 +217,7 @@ mouse_createFreeCursor(void *arg)
* @sa http://wiki.libsdl.org/SDL_CreateColorCursor
* @sa http://wiki.libsdl.org/SDL_FreeCursor
*/
int
mouse_createFreeColorCursor(void *arg)
int mouse_createFreeColorCursor(void *arg)
{
SDL_Surface *face;
SDL_Cursor *cursor;
@@ -236,8 +231,8 @@ mouse_createFreeColorCursor(void *arg)
/* Create a color cursor from surface */
cursor = SDL_CreateColorCursor(face, 0, 0);
SDLTest_AssertPass("Call to SDL_CreateColorCursor()");
SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateColorCursor() is not NULL");
SDLTest_AssertPass("Call to SDL_CreateColorCursor()");
SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateColorCursor() is not NULL");
if (cursor == NULL) {
SDL_FreeSurface(face);
return TEST_ABORTED;
@@ -260,18 +255,18 @@ void _changeCursorVisibility(int state)
int newState;
int result;
oldState = SDL_ShowCursor(SDL_QUERY);
oldState = SDL_ShowCursor(SDL_QUERY);
SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)");
result = SDL_ShowCursor(state);
result = SDL_ShowCursor(state);
SDLTest_AssertPass("Call to SDL_ShowCursor(%s)", (state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE");
SDLTest_AssertCheck(result == oldState, "Validate result from SDL_ShowCursor(%s), expected: %i, got: %i",
(state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE", oldState, result);
(state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE", oldState, result);
newState = SDL_ShowCursor(SDL_QUERY);
SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)");
SDLTest_AssertCheck(state == newState, "Validate new state, expected: %i, got: %i",
state, newState);
state, newState);
}
/**
@@ -279,8 +274,7 @@ void _changeCursorVisibility(int state)
*
* @sa http://wiki.libsdl.org/SDL_ShowCursor
*/
int
mouse_showCursor(void *arg)
int mouse_showCursor(void *arg)
{
int currentState;
@@ -288,7 +282,7 @@ mouse_showCursor(void *arg)
currentState = SDL_ShowCursor(SDL_QUERY);
SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)");
SDLTest_AssertCheck(currentState == SDL_DISABLE || currentState == SDL_ENABLE,
"Validate result is %i or %i, got: %i", SDL_DISABLE, SDL_ENABLE, currentState);
"Validate result is %i or %i, got: %i", SDL_DISABLE, SDL_ENABLE, currentState);
if (currentState == SDL_DISABLE) {
/* Show the cursor, then hide it again */
_changeCursorVisibility(SDL_ENABLE);
@@ -309,15 +303,14 @@ mouse_showCursor(void *arg)
*
* @sa http://wiki.libsdl.org/SDL_SetCursor
*/
int
mouse_setCursor(void *arg)
int mouse_setCursor(void *arg)
{
SDL_Cursor *cursor;
/* Create a cursor */
cursor = _initArrowCursor(_mouseArrowData);
SDLTest_AssertPass("Call to SDL_CreateCursor()");
SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL");
SDLTest_AssertPass("Call to SDL_CreateCursor()");
SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL");
if (cursor == NULL) {
return TEST_ABORTED;
}
@@ -342,15 +335,14 @@ mouse_setCursor(void *arg)
*
* @sa http://wiki.libsdl.org/SDL_GetCursor
*/
int
mouse_getCursor(void *arg)
int mouse_getCursor(void *arg)
{
SDL_Cursor *cursor;
/* Get current cursor */
cursor = SDL_GetCursor();
SDLTest_AssertPass("Call to SDL_GetCursor()");
SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_GetCursor() is not NULL");
SDLTest_AssertPass("Call to SDL_GetCursor()");
SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_GetCursor() is not NULL");
return TEST_COMPLETED;
}
@@ -361,52 +353,51 @@ mouse_getCursor(void *arg)
* @sa http://wiki.libsdl.org/SDL_GetRelativeMouseMode
* @sa http://wiki.libsdl.org/SDL_SetRelativeMouseMode
*/
int
mouse_getSetRelativeMouseMode(void *arg)
int mouse_getSetRelativeMouseMode(void *arg)
{
int result;
int i;
int i;
SDL_bool initialState;
SDL_bool currentState;
/* Capture original state so we can revert back to it later */
initialState = SDL_GetRelativeMouseMode();
SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
/* Repeat twice to check D->D transition */
for (i=0; i<2; i++) {
/* Disable - should always be supported */
result = SDL_SetRelativeMouseMode(SDL_FALSE);
SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(FALSE)");
SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result);
currentState = SDL_GetRelativeMouseMode();
SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
SDLTest_AssertCheck(currentState == SDL_FALSE, "Validate current state is FALSE, got: %i", currentState);
}
/* Repeat twice to check D->E->E transition */
for (i=0; i<2; i++) {
/* Enable - may not be supported */
result = SDL_SetRelativeMouseMode(SDL_TRUE);
SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(TRUE)");
if (result != -1) {
SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result);
currentState = SDL_GetRelativeMouseMode();
SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
SDLTest_AssertCheck(currentState == SDL_TRUE, "Validate current state is TRUE, got: %i", currentState);
}
}
/* Disable to check E->D transition */
/* Repeat twice to check D->D transition */
for (i = 0; i < 2; i++) {
/* Disable - should always be supported */
result = SDL_SetRelativeMouseMode(SDL_FALSE);
SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(FALSE)");
SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result);
currentState = SDL_GetRelativeMouseMode();
currentState = SDL_GetRelativeMouseMode();
SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
SDLTest_AssertCheck(currentState == SDL_FALSE, "Validate current state is FALSE, got: %i", currentState);
}
/* Revert to original state - ignore result */
result = SDL_SetRelativeMouseMode(initialState);
/* Repeat twice to check D->E->E transition */
for (i = 0; i < 2; i++) {
/* Enable - may not be supported */
result = SDL_SetRelativeMouseMode(SDL_TRUE);
SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(TRUE)");
if (result != -1) {
SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result);
currentState = SDL_GetRelativeMouseMode();
SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
SDLTest_AssertCheck(currentState == SDL_TRUE, "Validate current state is TRUE, got: %i", currentState);
}
}
/* Disable to check E->D transition */
result = SDL_SetRelativeMouseMode(SDL_FALSE);
SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(FALSE)");
SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result);
currentState = SDL_GetRelativeMouseMode();
SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
SDLTest_AssertCheck(currentState == SDL_FALSE, "Validate current state is FALSE, got: %i", currentState);
/* Revert to original state - ignore result */
result = SDL_SetRelativeMouseMode(initialState);
return TEST_COMPLETED;
}
@@ -419,12 +410,12 @@ mouse_getSetRelativeMouseMode(void *arg)
*/
SDL_Window *_createMouseSuiteTestWindow()
{
int posX = 100, posY = 100, width = MOUSE_TESTWINDOW_WIDTH, height = MOUSE_TESTWINDOW_HEIGHT;
SDL_Window *window;
window = SDL_CreateWindow("mouse_createMouseSuiteTestWindow", posX, posY, width, height, 0);
SDLTest_AssertPass("SDL_CreateWindow()");
SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result");
return window;
int posX = 100, posY = 100, width = MOUSE_TESTWINDOW_WIDTH, height = MOUSE_TESTWINDOW_HEIGHT;
SDL_Window *window;
window = SDL_CreateWindow("mouse_createMouseSuiteTestWindow", posX, posY, width, height, 0);
SDLTest_AssertPass("SDL_CreateWindow()");
SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result");
return window;
}
/*
@@ -432,11 +423,11 @@ SDL_Window *_createMouseSuiteTestWindow()
*/
void _destroyMouseSuiteTestWindow(SDL_Window *window)
{
if (window != NULL) {
SDL_DestroyWindow(window);
window = NULL;
SDLTest_AssertPass("SDL_DestroyWindow()");
}
if (window != NULL) {
SDL_DestroyWindow(window);
window = NULL;
SDLTest_AssertPass("SDL_DestroyWindow()");
}
}
/**
@@ -444,8 +435,7 @@ void _destroyMouseSuiteTestWindow(SDL_Window *window)
*
* @sa http://wiki.libsdl.org/SDL_WarpMouseInWindow
*/
int
mouse_warpMouseInWindow(void *arg)
int mouse_warpMouseInWindow(void *arg)
{
const int w = MOUSE_TESTWINDOW_WIDTH, h = MOUSE_TESTWINDOW_HEIGHT;
int numPositions = 6;
@@ -457,47 +447,46 @@ mouse_warpMouseInWindow(void *arg)
xPositions[0] = -1;
xPositions[1] = 0;
xPositions[2] = 1;
xPositions[3] = w-1;
xPositions[3] = w - 1;
xPositions[4] = w;
xPositions[5] = w+1;
xPositions[5] = w + 1;
yPositions[0] = -1;
yPositions[1] = 0;
yPositions[2] = 1;
yPositions[3] = h-1;
yPositions[3] = h - 1;
yPositions[4] = h;
yPositions[5] = h+1;
yPositions[5] = h + 1;
/* Create test window */
window = _createMouseSuiteTestWindow();
if (window == NULL) {
return TEST_ABORTED;
return TEST_ABORTED;
}
/* Mouse to random position inside window */
x = SDLTest_RandomIntegerInRange(1, w-1);
y = SDLTest_RandomIntegerInRange(1, h-1);
x = SDLTest_RandomIntegerInRange(1, w - 1);
y = SDLTest_RandomIntegerInRange(1, h - 1);
SDL_WarpMouseInWindow(window, x, y);
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
/* Same position again */
/* Same position again */
SDL_WarpMouseInWindow(window, x, y);
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
/* Mouse to various boundary positions */
for (i=0; i<numPositions; i++) {
for (j=0; j<numPositions; j++) {
x = xPositions[i];
y = yPositions[j];
SDL_WarpMouseInWindow(window, x, y);
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
for (i = 0; i < numPositions; i++) {
for (j = 0; j < numPositions; j++) {
x = xPositions[i];
y = yPositions[j];
SDL_WarpMouseInWindow(window, x, y);
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
/* TODO: add tracking of events and check that each call generates a mouse motion event */
SDL_PumpEvents();
SDLTest_AssertPass("SDL_PumpEvents()");
}
/* TODO: add tracking of events and check that each call generates a mouse motion event */
SDL_PumpEvents();
SDLTest_AssertPass("SDL_PumpEvents()");
}
}
/* Clean up test window */
/* Clean up test window */
_destroyMouseSuiteTestWindow(window);
return TEST_COMPLETED;
@@ -508,8 +497,7 @@ mouse_warpMouseInWindow(void *arg)
*
* @sa http://wiki.libsdl.org/SDL_GetMouseFocus
*/
int
mouse_getMouseFocus(void *arg)
int mouse_getMouseFocus(void *arg)
{
const int w = MOUSE_TESTWINDOW_WIDTH, h = MOUSE_TESTWINDOW_HEIGHT;
int x, y;
@@ -520,15 +508,15 @@ mouse_getMouseFocus(void *arg)
focusWindow = SDL_GetMouseFocus();
SDLTest_AssertPass("SDL_GetMouseFocus()");
/* Create test window */
/* Create test window */
window = _createMouseSuiteTestWindow();
if (window == NULL) {
return TEST_ABORTED;
}
/* Mouse to random position inside window */
x = SDLTest_RandomIntegerInRange(1, w-1);
y = SDLTest_RandomIntegerInRange(1, h-1);
x = SDLTest_RandomIntegerInRange(1, w - 1);
y = SDLTest_RandomIntegerInRange(1, h - 1);
SDL_WarpMouseInWindow(window, x, y);
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
@@ -537,11 +525,11 @@ mouse_getMouseFocus(void *arg)
SDL_PumpEvents();
SDLTest_AssertPass("SDL_PumpEvents()");
/* Get focus with explicit window setup - focus deterministic */
/* Get focus with explicit window setup - focus deterministic */
focusWindow = SDL_GetMouseFocus();
SDLTest_AssertPass("SDL_GetMouseFocus()");
SDLTest_AssertCheck (focusWindow != NULL, "Check returned window value is not NULL");
SDLTest_AssertCheck (focusWindow == window, "Check returned window value is test window");
SDLTest_AssertCheck(focusWindow != NULL, "Check returned window value is not NULL");
SDLTest_AssertCheck(focusWindow == window, "Check returned window value is test window");
/* Mouse to random position outside window */
x = SDLTest_RandomIntegerInRange(-9, -1);
@@ -549,18 +537,17 @@ mouse_getMouseFocus(void *arg)
SDL_WarpMouseInWindow(window, x, y);
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
/* Clean up test window */
/* Clean up test window */
_destroyMouseSuiteTestWindow(window);
/* Pump events to update focus state */
SDL_PumpEvents();
SDLTest_AssertPass("SDL_PumpEvents()");
/* Get focus for non-existing window */
/* Get focus for non-existing window */
focusWindow = SDL_GetMouseFocus();
SDLTest_AssertPass("SDL_GetMouseFocus()");
SDLTest_AssertCheck (focusWindow == NULL, "Check returned window value is NULL");
SDLTest_AssertCheck(focusWindow == NULL, "Check returned window value is NULL");
return TEST_COMPLETED;
}
@@ -568,35 +555,45 @@ mouse_getMouseFocus(void *arg)
/* ================= Test References ================== */
/* Mouse test cases */
static const SDLTest_TestCaseReference mouseTest1 =
{ (SDLTest_TestCaseFp)mouse_getMouseState, "mouse_getMouseState", "Check call to SDL_GetMouseState", TEST_ENABLED };
static const SDLTest_TestCaseReference mouseTest1 = {
(SDLTest_TestCaseFp)mouse_getMouseState, "mouse_getMouseState", "Check call to SDL_GetMouseState", TEST_ENABLED
};
static const SDLTest_TestCaseReference mouseTest2 =
{ (SDLTest_TestCaseFp)mouse_getRelativeMouseState, "mouse_getRelativeMouseState", "Check call to SDL_GetRelativeMouseState", TEST_ENABLED };
static const SDLTest_TestCaseReference mouseTest2 = {
(SDLTest_TestCaseFp)mouse_getRelativeMouseState, "mouse_getRelativeMouseState", "Check call to SDL_GetRelativeMouseState", TEST_ENABLED
};
static const SDLTest_TestCaseReference mouseTest3 =
{ (SDLTest_TestCaseFp)mouse_createFreeCursor, "mouse_createFreeCursor", "Check call to SDL_CreateCursor and SDL_FreeCursor", TEST_ENABLED };
static const SDLTest_TestCaseReference mouseTest3 = {
(SDLTest_TestCaseFp)mouse_createFreeCursor, "mouse_createFreeCursor", "Check call to SDL_CreateCursor and SDL_FreeCursor", TEST_ENABLED
};
static const SDLTest_TestCaseReference mouseTest4 =
{ (SDLTest_TestCaseFp)mouse_showCursor, "mouse_showCursor", "Check call to SDL_ShowCursor", TEST_ENABLED };
static const SDLTest_TestCaseReference mouseTest4 = {
(SDLTest_TestCaseFp)mouse_showCursor, "mouse_showCursor", "Check call to SDL_ShowCursor", TEST_ENABLED
};
static const SDLTest_TestCaseReference mouseTest5 =
{ (SDLTest_TestCaseFp)mouse_setCursor, "mouse_setCursor", "Check call to SDL_SetCursor", TEST_ENABLED };
static const SDLTest_TestCaseReference mouseTest5 = {
(SDLTest_TestCaseFp)mouse_setCursor, "mouse_setCursor", "Check call to SDL_SetCursor", TEST_ENABLED
};
static const SDLTest_TestCaseReference mouseTest6 =
{ (SDLTest_TestCaseFp)mouse_getCursor, "mouse_getCursor", "Check call to SDL_GetCursor", TEST_ENABLED };
static const SDLTest_TestCaseReference mouseTest6 = {
(SDLTest_TestCaseFp)mouse_getCursor, "mouse_getCursor", "Check call to SDL_GetCursor", TEST_ENABLED
};
static const SDLTest_TestCaseReference mouseTest7 =
{ (SDLTest_TestCaseFp)mouse_warpMouseInWindow, "mouse_warpMouseInWindow", "Check call to SDL_WarpMouseInWindow", TEST_ENABLED };
static const SDLTest_TestCaseReference mouseTest7 = {
(SDLTest_TestCaseFp)mouse_warpMouseInWindow, "mouse_warpMouseInWindow", "Check call to SDL_WarpMouseInWindow", TEST_ENABLED
};
static const SDLTest_TestCaseReference mouseTest8 =
{ (SDLTest_TestCaseFp)mouse_getMouseFocus, "mouse_getMouseFocus", "Check call to SDL_getMouseFocus", TEST_ENABLED };
static const SDLTest_TestCaseReference mouseTest8 = {
(SDLTest_TestCaseFp)mouse_getMouseFocus, "mouse_getMouseFocus", "Check call to SDL_getMouseFocus", TEST_ENABLED
};
static const SDLTest_TestCaseReference mouseTest9 =
{ (SDLTest_TestCaseFp)mouse_createFreeColorCursor, "mouse_createFreeColorCursor", "Check call to SDL_CreateColorCursor and SDL_FreeCursor", TEST_ENABLED };
static const SDLTest_TestCaseReference mouseTest9 = {
(SDLTest_TestCaseFp)mouse_createFreeColorCursor, "mouse_createFreeColorCursor", "Check call to SDL_CreateColorCursor and SDL_FreeCursor", TEST_ENABLED
};
static const SDLTest_TestCaseReference mouseTest10 =
{ (SDLTest_TestCaseFp)mouse_getSetRelativeMouseMode, "mouse_getSetRelativeMouseMode", "Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode", TEST_ENABLED };
static const SDLTest_TestCaseReference mouseTest10 = {
(SDLTest_TestCaseFp)mouse_getSetRelativeMouseMode, "mouse_getSetRelativeMouseMode", "Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode", TEST_ENABLED
};
/* Sequence of Mouse test cases */
static const SDLTest_TestCaseReference *mouseTests[] = {

View File

@@ -11,8 +11,7 @@
/* Definition of all RGB formats used to test pixel conversions */
const int _numRGBPixelFormats = 31;
Uint32 _RGBPixelFormats[] =
{
Uint32 _RGBPixelFormats[] = {
SDL_PIXELFORMAT_INDEX1LSB,
SDL_PIXELFORMAT_INDEX1MSB,
SDL_PIXELFORMAT_INDEX4LSB,
@@ -44,9 +43,8 @@ Uint32 _RGBPixelFormats[] =
SDL_PIXELFORMAT_ABGR8888,
SDL_PIXELFORMAT_BGRA8888,
SDL_PIXELFORMAT_ARGB2101010
};
const char* _RGBPixelFormatsVerbose[] =
{
};
const char *_RGBPixelFormatsVerbose[] = {
"SDL_PIXELFORMAT_INDEX1LSB",
"SDL_PIXELFORMAT_INDEX1MSB",
"SDL_PIXELFORMAT_INDEX4LSB",
@@ -78,12 +76,11 @@ const char* _RGBPixelFormatsVerbose[] =
"SDL_PIXELFORMAT_ABGR8888",
"SDL_PIXELFORMAT_BGRA8888",
"SDL_PIXELFORMAT_ARGB2101010"
};
};
/* Definition of all Non-RGB formats used to test pixel conversions */
const int _numNonRGBPixelFormats = 7;
Uint32 _nonRGBPixelFormats[] =
{
Uint32 _nonRGBPixelFormats[] = {
SDL_PIXELFORMAT_YV12,
SDL_PIXELFORMAT_IYUV,
SDL_PIXELFORMAT_YUY2,
@@ -91,9 +88,8 @@ Uint32 _nonRGBPixelFormats[] =
SDL_PIXELFORMAT_YVYU,
SDL_PIXELFORMAT_NV12,
SDL_PIXELFORMAT_NV21
};
const char* _nonRGBPixelFormatsVerbose[] =
{
};
const char *_nonRGBPixelFormatsVerbose[] = {
"SDL_PIXELFORMAT_YV12",
"SDL_PIXELFORMAT_IYUV",
"SDL_PIXELFORMAT_YUY2",
@@ -101,20 +97,18 @@ const char* _nonRGBPixelFormatsVerbose[] =
"SDL_PIXELFORMAT_YVYU",
"SDL_PIXELFORMAT_NV12",
"SDL_PIXELFORMAT_NV21"
};
};
/* Definition of some invalid formats for negative tests */
const int _numInvalidPixelFormats = 2;
Uint32 _invalidPixelFormats[] =
{
Uint32 _invalidPixelFormats[] = {
0xfffffffe,
0xffffffff
};
const char* _invalidPixelFormatsVerbose[] =
{
};
const char *_invalidPixelFormatsVerbose[] = {
"SDL_PIXELFORMAT_UNKNOWN",
"SDL_PIXELFORMAT_UNKNOWN"
};
};
/* Test case functions */
@@ -124,105 +118,104 @@ const char* _invalidPixelFormatsVerbose[] =
* @sa http://wiki.libsdl.org/SDL_AllocFormat
* @sa http://wiki.libsdl.org/SDL_FreeFormat
*/
int
pixels_allocFreeFormat(void *arg)
int pixels_allocFreeFormat(void *arg)
{
const char *unknownFormat = "SDL_PIXELFORMAT_UNKNOWN";
const char *expectedError = "Parameter 'format' is invalid";
const char *error;
int i;
Uint32 format;
Uint32 masks;
SDL_PixelFormat* result;
const char *unknownFormat = "SDL_PIXELFORMAT_UNKNOWN";
const char *expectedError = "Parameter 'format' is invalid";
const char *error;
int i;
Uint32 format;
Uint32 masks;
SDL_PixelFormat *result;
/* Blank/unknown format */
format = 0;
SDLTest_Log("RGB Format: %s (%" SDL_PRIu32 ")", unknownFormat, format);
/* Allocate format */
result = SDL_AllocFormat(format);
SDLTest_AssertPass("Call to SDL_AllocFormat()");
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(result->format == format, "Verify value of result.format; expected: %" SDL_PRIu32 ", got %" SDL_PRIu32, format, result->format);
SDLTest_AssertCheck(result->BitsPerPixel == 0, "Verify value of result.BitsPerPixel; expected: 0, got %u", result->BitsPerPixel);
SDLTest_AssertCheck(result->BytesPerPixel == 0, "Verify value of result.BytesPerPixel; expected: 0, got %u", result->BytesPerPixel);
masks = result->Rmask | result->Gmask | result->Bmask | result->Amask;
SDLTest_AssertCheck(masks == 0, "Verify value of result.[RGBA]mask combined; expected: 0, got %" SDL_PRIu32, masks);
/* Deallocate again */
SDL_FreeFormat(result);
SDLTest_AssertPass("Call to SDL_FreeFormat()");
}
/* RGB formats */
for (i = 0; i < _numRGBPixelFormats; i++) {
format = _RGBPixelFormats[i];
SDLTest_Log("RGB Format: %s (%" SDL_PRIu32 ")", _RGBPixelFormatsVerbose[i], format);
/* Blank/unknown format */
format = 0;
SDLTest_Log("RGB Format: %s (%" SDL_PRIu32 ")", unknownFormat, format);
/* Allocate format */
result = SDL_AllocFormat(format);
SDLTest_AssertPass("Call to SDL_AllocFormat()");
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(result->format == format, "Verify value of result.format; expected: %" SDL_PRIu32 ", got %" SDL_PRIu32, format, result->format);
SDLTest_AssertCheck(result->BitsPerPixel > 0, "Verify value of result.BitsPerPixel; expected: >0, got %u", result->BitsPerPixel);
SDLTest_AssertCheck(result->BytesPerPixel > 0, "Verify value of result.BytesPerPixel; expected: >0, got %u", result->BytesPerPixel);
if (result->palette != NULL) {
masks = result->Rmask | result->Gmask | result->Bmask | result->Amask;
SDLTest_AssertCheck(masks > 0, "Verify value of result.[RGBA]mask combined; expected: >0, got %" SDL_PRIu32, masks);
}
SDLTest_AssertCheck(result->format == format, "Verify value of result.format; expected: %" SDL_PRIu32 ", got %" SDL_PRIu32, format, result->format);
SDLTest_AssertCheck(result->BitsPerPixel == 0, "Verify value of result.BitsPerPixel; expected: 0, got %u", result->BitsPerPixel);
SDLTest_AssertCheck(result->BytesPerPixel == 0, "Verify value of result.BytesPerPixel; expected: 0, got %u", result->BytesPerPixel);
masks = result->Rmask | result->Gmask | result->Bmask | result->Amask;
SDLTest_AssertCheck(masks == 0, "Verify value of result.[RGBA]mask combined; expected: 0, got %" SDL_PRIu32, masks);
/* Deallocate again */
SDL_FreeFormat(result);
SDLTest_AssertPass("Call to SDL_FreeFormat()");
/* Deallocate again */
SDL_FreeFormat(result);
SDLTest_AssertPass("Call to SDL_FreeFormat()");
}
}
/* Non-RGB formats */
for (i = 0; i < _numNonRGBPixelFormats; i++) {
format = _nonRGBPixelFormats[i];
SDLTest_Log("non-RGB Format: %s (%" SDL_PRIu32 ")", _nonRGBPixelFormatsVerbose[i], format);
/* RGB formats */
for (i = 0; i < _numRGBPixelFormats; i++) {
format = _RGBPixelFormats[i];
SDLTest_Log("RGB Format: %s (%" SDL_PRIu32 ")", _RGBPixelFormatsVerbose[i], format);
/* Try to allocate format */
result = SDL_AllocFormat(format);
SDLTest_AssertPass("Call to SDL_AllocFormat()");
SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
}
/* Allocate format */
result = SDL_AllocFormat(format);
SDLTest_AssertPass("Call to SDL_AllocFormat()");
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(result->format == format, "Verify value of result.format; expected: %" SDL_PRIu32 ", got %" SDL_PRIu32, format, result->format);
SDLTest_AssertCheck(result->BitsPerPixel > 0, "Verify value of result.BitsPerPixel; expected: >0, got %u", result->BitsPerPixel);
SDLTest_AssertCheck(result->BytesPerPixel > 0, "Verify value of result.BytesPerPixel; expected: >0, got %u", result->BytesPerPixel);
if (result->palette != NULL) {
masks = result->Rmask | result->Gmask | result->Bmask | result->Amask;
SDLTest_AssertCheck(masks > 0, "Verify value of result.[RGBA]mask combined; expected: >0, got %" SDL_PRIu32, masks);
}
/* Negative cases */
/* Deallocate again */
SDL_FreeFormat(result);
SDLTest_AssertPass("Call to SDL_FreeFormat()");
}
}
/* Invalid Formats */
for (i = 0; i < _numInvalidPixelFormats; i++) {
/* Non-RGB formats */
for (i = 0; i < _numNonRGBPixelFormats; i++) {
format = _nonRGBPixelFormats[i];
SDLTest_Log("non-RGB Format: %s (%" SDL_PRIu32 ")", _nonRGBPixelFormatsVerbose[i], format);
/* Try to allocate format */
result = SDL_AllocFormat(format);
SDLTest_AssertPass("Call to SDL_AllocFormat()");
SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
}
/* Negative cases */
/* Invalid Formats */
for (i = 0; i < _numInvalidPixelFormats; i++) {
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
format = _invalidPixelFormats[i];
result = SDL_AllocFormat(format);
SDLTest_AssertPass("Call to SDL_AllocFormat(%" SDL_PRIu32 ")", format);
SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
}
}
/* Invalid free pointer */
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
format = _invalidPixelFormats[i];
result = SDL_AllocFormat(format);
SDLTest_AssertPass("Call to SDL_AllocFormat(%" SDL_PRIu32 ")", format);
SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
SDL_FreeFormat(NULL);
SDLTest_AssertPass("Call to SDL_FreeFormat(NULL)");
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
}
}
/* Invalid free pointer */
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
SDL_FreeFormat(NULL);
SDLTest_AssertPass("Call to SDL_FreeFormat(NULL)");
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
}
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
@@ -230,83 +223,82 @@ pixels_allocFreeFormat(void *arg)
*
* @sa http://wiki.libsdl.org/SDL_GetPixelFormatName
*/
int
pixels_getPixelFormatName(void *arg)
int pixels_getPixelFormatName(void *arg)
{
const char *unknownFormat = "SDL_PIXELFORMAT_UNKNOWN";
const char *error;
int i;
Uint32 format;
const char *result;
const char *unknownFormat = "SDL_PIXELFORMAT_UNKNOWN";
const char *error;
int i;
Uint32 format;
const char *result;
/* Blank/undefined format */
format = 0;
SDLTest_Log("RGB Format: %s (%" SDL_PRIu32 ")", unknownFormat, format);
/* Get name of format */
result = SDL_GetPixelFormatName(format);
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(result[0] != '\0', "Verify result is non-empty");
SDLTest_AssertCheck(SDL_strcmp(result, unknownFormat) == 0,
"Verify result text; expected: %s, got %s", unknownFormat, result);
}
/* RGB formats */
for (i = 0; i < _numRGBPixelFormats; i++) {
format = _RGBPixelFormats[i];
SDLTest_Log("RGB Format: %s (%" SDL_PRIu32 ")", _RGBPixelFormatsVerbose[i], format);
/* Blank/undefined format */
format = 0;
SDLTest_Log("RGB Format: %s (%" SDL_PRIu32 ")", unknownFormat, format);
/* Get name of format */
result = SDL_GetPixelFormatName(format);
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(result[0] != '\0', "Verify result is non-empty");
SDLTest_AssertCheck(SDL_strcmp(result, _RGBPixelFormatsVerbose[i]) == 0,
"Verify result text; expected: %s, got %s", _RGBPixelFormatsVerbose[i], result);
SDLTest_AssertCheck(result[0] != '\0', "Verify result is non-empty");
SDLTest_AssertCheck(SDL_strcmp(result, unknownFormat) == 0,
"Verify result text; expected: %s, got %s", unknownFormat, result);
}
}
/* Non-RGB formats */
for (i = 0; i < _numNonRGBPixelFormats; i++) {
format = _nonRGBPixelFormats[i];
SDLTest_Log("non-RGB Format: %s (%" SDL_PRIu32 ")", _nonRGBPixelFormatsVerbose[i], format);
/* RGB formats */
for (i = 0; i < _numRGBPixelFormats; i++) {
format = _RGBPixelFormats[i];
SDLTest_Log("RGB Format: %s (%" SDL_PRIu32 ")", _RGBPixelFormatsVerbose[i], format);
/* Get name of format */
result = SDL_GetPixelFormatName(format);
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(result[0] != '\0', "Verify result is non-empty");
SDLTest_AssertCheck(SDL_strcmp(result, _nonRGBPixelFormatsVerbose[i]) == 0,
"Verify result text; expected: %s, got %s", _nonRGBPixelFormatsVerbose[i], result);
/* Get name of format */
result = SDL_GetPixelFormatName(format);
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(result[0] != '\0', "Verify result is non-empty");
SDLTest_AssertCheck(SDL_strcmp(result, _RGBPixelFormatsVerbose[i]) == 0,
"Verify result text; expected: %s, got %s", _RGBPixelFormatsVerbose[i], result);
}
}
}
/* Negative cases */
/* Non-RGB formats */
for (i = 0; i < _numNonRGBPixelFormats; i++) {
format = _nonRGBPixelFormats[i];
SDLTest_Log("non-RGB Format: %s (%" SDL_PRIu32 ")", _nonRGBPixelFormatsVerbose[i], format);
/* Invalid Formats */
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
for (i = 0; i < _numInvalidPixelFormats; i++) {
format = _invalidPixelFormats[i];
result = SDL_GetPixelFormatName(format);
SDLTest_AssertPass("Call to SDL_GetPixelFormatName(%" SDL_PRIu32 ")", format);
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(result[0] != '\0',
"Verify result is non-empty; got: %s", result);
SDLTest_AssertCheck(SDL_strcmp(result, _invalidPixelFormatsVerbose[i]) == 0,
"Validate name is UNKNOWN, expected: '%s', got: '%s'", _invalidPixelFormatsVerbose[i], result);
/* Get name of format */
result = SDL_GetPixelFormatName(format);
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(result[0] != '\0', "Verify result is non-empty");
SDLTest_AssertCheck(SDL_strcmp(result, _nonRGBPixelFormatsVerbose[i]) == 0,
"Verify result text; expected: %s, got %s", _nonRGBPixelFormatsVerbose[i], result);
}
}
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error == NULL || error[0] == '\0', "Validate that error message is empty");
}
return TEST_COMPLETED;
/* Negative cases */
/* Invalid Formats */
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
for (i = 0; i < _numInvalidPixelFormats; i++) {
format = _invalidPixelFormats[i];
result = SDL_GetPixelFormatName(format);
SDLTest_AssertPass("Call to SDL_GetPixelFormatName(%" SDL_PRIu32 ")", format);
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(result[0] != '\0',
"Verify result is non-empty; got: %s", result);
SDLTest_AssertCheck(SDL_strcmp(result, _invalidPixelFormatsVerbose[i]) == 0,
"Validate name is UNKNOWN, expected: '%s', got: '%s'", _invalidPixelFormatsVerbose[i], result);
}
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error == NULL || error[0] == '\0', "Validate that error message is empty");
}
return TEST_COMPLETED;
}
/**
@@ -315,89 +307,88 @@ pixels_getPixelFormatName(void *arg)
* @sa http://wiki.libsdl.org/SDL_AllocPalette
* @sa http://wiki.libsdl.org/SDL_FreePalette
*/
int
pixels_allocFreePalette(void *arg)
int pixels_allocFreePalette(void *arg)
{
const char *expectedError1 = "Parameter 'ncolors' is invalid";
const char *expectedError2 = "Parameter 'palette' is invalid";
const char *error;
int variation;
int i;
int ncolors;
SDL_Palette* result;
const char *expectedError1 = "Parameter 'ncolors' is invalid";
const char *expectedError2 = "Parameter 'palette' is invalid";
const char *error;
int variation;
int i;
int ncolors;
SDL_Palette *result;
/* Allocate palette */
for (variation = 1; variation <= 3; variation++) {
switch (variation) {
/* Just one color */
default:
case 1:
ncolors = 1;
break;
/* Two colors */
case 2:
ncolors = 2;
break;
/* More than two colors */
case 3:
ncolors = SDLTest_RandomIntegerInRange(8, 16);
break;
/* Allocate palette */
for (variation = 1; variation <= 3; variation++) {
switch (variation) {
/* Just one color */
default:
case 1:
ncolors = 1;
break;
/* Two colors */
case 2:
ncolors = 2;
break;
/* More than two colors */
case 3:
ncolors = SDLTest_RandomIntegerInRange(8, 16);
break;
}
result = SDL_AllocPalette(ncolors);
SDLTest_AssertPass("Call to SDL_AllocPalette(%d)", ncolors);
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(result->ncolors == ncolors, "Verify value of result.ncolors; expected: %u, got %u", ncolors, result->ncolors);
if (result->ncolors > 0) {
SDLTest_AssertCheck(result->colors != NULL, "Verify value of result.colors is not NULL");
if (result->colors != NULL) {
for (i = 0; i < result->ncolors; i++) {
SDLTest_AssertCheck(result->colors[i].r == 255, "Verify value of result.colors[%d].r; expected: 255, got %u", i, result->colors[i].r);
SDLTest_AssertCheck(result->colors[i].g == 255, "Verify value of result.colors[%d].g; expected: 255, got %u", i, result->colors[i].g);
SDLTest_AssertCheck(result->colors[i].b == 255, "Verify value of result.colors[%d].b; expected: 255, got %u", i, result->colors[i].b);
}
}
}
/* Deallocate again */
SDL_FreePalette(result);
SDLTest_AssertPass("Call to SDL_FreePalette()");
}
}
result = SDL_AllocPalette(ncolors);
SDLTest_AssertPass("Call to SDL_AllocPalette(%d)", ncolors);
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(result->ncolors == ncolors, "Verify value of result.ncolors; expected: %u, got %u", ncolors, result->ncolors);
if (result->ncolors > 0) {
SDLTest_AssertCheck(result->colors != NULL, "Verify value of result.colors is not NULL");
if (result->colors != NULL) {
for (i = 0; i < result->ncolors; i++) {
SDLTest_AssertCheck(result->colors[i].r == 255, "Verify value of result.colors[%d].r; expected: 255, got %u", i, result->colors[i].r);
SDLTest_AssertCheck(result->colors[i].g == 255, "Verify value of result.colors[%d].g; expected: 255, got %u", i, result->colors[i].g);
SDLTest_AssertCheck(result->colors[i].b == 255, "Verify value of result.colors[%d].b; expected: 255, got %u", i, result->colors[i].b);
}
}
}
/* Negative cases */
/* Deallocate again */
SDL_FreePalette(result);
SDLTest_AssertPass("Call to SDL_FreePalette()");
/* Invalid number of colors */
for (ncolors = 0; ncolors > -3; ncolors--) {
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
result = SDL_AllocPalette(ncolors);
SDLTest_AssertPass("Call to SDL_AllocPalette(%d)", ncolors);
SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
SDLTest_AssertCheck(SDL_strcmp(error, expectedError1) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError1, error);
}
}
}
/* Negative cases */
/* Invalid number of colors */
for (ncolors = 0; ncolors > -3; ncolors--) {
/* Invalid free pointer */
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
result = SDL_AllocPalette(ncolors);
SDLTest_AssertPass("Call to SDL_AllocPalette(%d)", ncolors);
SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
SDL_FreePalette(NULL);
SDLTest_AssertPass("Call to SDL_FreePalette(NULL)");
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
SDLTest_AssertCheck(SDL_strcmp(error, expectedError1) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError1, error);
SDLTest_AssertCheck(SDL_strcmp(error, expectedError2) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError2, error);
}
}
/* Invalid free pointer */
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
SDL_FreePalette(NULL);
SDLTest_AssertPass("Call to SDL_FreePalette(NULL)");
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
SDLTest_AssertCheck(SDL_strcmp(error, expectedError2) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError2, error);
}
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
@@ -507,11 +498,13 @@ pixels_calcGammaRamp(void *arg)
/* ================= Test References ================== */
/* Pixels test cases */
static const SDLTest_TestCaseReference pixelsTest1 =
{ (SDLTest_TestCaseFp)pixels_allocFreeFormat, "pixels_allocFreeFormat", "Call to SDL_AllocFormat and SDL_FreeFormat", TEST_ENABLED };
static const SDLTest_TestCaseReference pixelsTest1 = {
(SDLTest_TestCaseFp)pixels_allocFreeFormat, "pixels_allocFreeFormat", "Call to SDL_AllocFormat and SDL_FreeFormat", TEST_ENABLED
};
static const SDLTest_TestCaseReference pixelsTest2 =
{ (SDLTest_TestCaseFp)pixels_allocFreePalette, "pixels_allocFreePalette", "Call to SDL_AllocPalette and SDL_FreePalette", TEST_ENABLED };
static const SDLTest_TestCaseReference pixelsTest2 = {
(SDLTest_TestCaseFp)pixels_allocFreePalette, "pixels_allocFreePalette", "Call to SDL_AllocPalette and SDL_FreePalette", TEST_ENABLED
};
static const SDLTest_TestCaseReference pixelsTest3 =
{ (SDLTest_TestCaseFp)pixels_calcGammaRamp, "pixels_calcGammaRamp", "Call to SDL_CalculateGammaRamp", TEST_ENABLED };

View File

@@ -19,7 +19,7 @@
* compare them directly, so we push it through a function to keep the
* compiler quiet. --ryan.
*/
static int _compareSizeOfType( size_t sizeoftype, size_t hardcodetype )
static int _compareSizeOfType(size_t sizeoftype, size_t hardcodetype)
{
return sizeoftype != hardcodetype;
}
@@ -31,21 +31,21 @@ static int _compareSizeOfType( size_t sizeoftype, size_t hardcodetype )
*/
int platform_testTypes(void *arg)
{
int ret;
int ret;
ret = _compareSizeOfType( sizeof(Uint8), 1 );
SDLTest_AssertCheck( ret == 0, "sizeof(Uint8) = %lu, expected 1", (unsigned long)sizeof(Uint8) );
ret = _compareSizeOfType(sizeof(Uint8), 1);
SDLTest_AssertCheck(ret == 0, "sizeof(Uint8) = %lu, expected 1", (unsigned long)sizeof(Uint8));
ret = _compareSizeOfType( sizeof(Uint16), 2 );
SDLTest_AssertCheck( ret == 0, "sizeof(Uint16) = %lu, expected 2", (unsigned long)sizeof(Uint16) );
ret = _compareSizeOfType(sizeof(Uint16), 2);
SDLTest_AssertCheck(ret == 0, "sizeof(Uint16) = %lu, expected 2", (unsigned long)sizeof(Uint16));
ret = _compareSizeOfType( sizeof(Uint32), 4 );
SDLTest_AssertCheck( ret == 0, "sizeof(Uint32) = %lu, expected 4", (unsigned long)sizeof(Uint32) );
ret = _compareSizeOfType(sizeof(Uint32), 4);
SDLTest_AssertCheck(ret == 0, "sizeof(Uint32) = %lu, expected 4", (unsigned long)sizeof(Uint32));
ret = _compareSizeOfType( sizeof(Uint64), 8 );
SDLTest_AssertCheck( ret == 0, "sizeof(Uint64) = %lu, expected 8", (unsigned long)sizeof(Uint64) );
ret = _compareSizeOfType(sizeof(Uint64), 8);
SDLTest_AssertCheck(ret == 0, "sizeof(Uint64) = %lu, expected 8", (unsigned long)sizeof(Uint64));
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
@@ -61,9 +61,10 @@ int platform_testEndianessAndSwap(void *arg)
Uint32 value32 = 0xEFBEADDE;
Uint32 swapped32 = 0xDEADBEEF;
union {
double d;
Uint32 ui32[2];
union
{
double d;
Uint32 ui32[2];
} value_double;
Uint64 value64, swapped64;
@@ -75,17 +76,17 @@ int platform_testEndianessAndSwap(void *arg)
swapped64 |= 0xDEADBEEF;
value_double.d = 3.141593;
if ((*((char *) &value) >> 4) == 0x1) {
if ((*((char *)&value) >> 4) == 0x1) {
real_byteorder = SDL_BIG_ENDIAN;
} else {
real_byteorder = SDL_LIL_ENDIAN;
}
/* Test endianness. */
SDLTest_AssertCheck( real_byteorder == SDL_BYTEORDER,
"Machine detected as %s endian, appears to be %s endian.",
(SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big",
(real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big" );
SDLTest_AssertCheck(real_byteorder == SDL_BYTEORDER,
"Machine detected as %s endian, appears to be %s endian.",
(SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big",
(real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big");
if (value_double.ui32[0] == 0x82c2bd7f && value_double.ui32[1] == 0x400921fb) {
real_floatwordorder = SDL_LIL_ENDIAN;
@@ -94,27 +95,28 @@ int platform_testEndianessAndSwap(void *arg)
}
/* Test endianness. */
SDLTest_AssertCheck( real_floatwordorder == SDL_FLOATWORDORDER,
"Machine detected as having %s endian float word order, appears to be %s endian.",
(SDL_FLOATWORDORDER == SDL_LIL_ENDIAN) ? "little" : "big",
(real_floatwordorder == SDL_LIL_ENDIAN) ? "little" : (real_floatwordorder == SDL_BIG_ENDIAN) ? "big" : "unknown" );
SDLTest_AssertCheck(real_floatwordorder == SDL_FLOATWORDORDER,
"Machine detected as having %s endian float word order, appears to be %s endian.",
(SDL_FLOATWORDORDER == SDL_LIL_ENDIAN) ? "little" : "big",
(real_floatwordorder == SDL_LIL_ENDIAN) ? "little" : (real_floatwordorder == SDL_BIG_ENDIAN) ? "big"
: "unknown");
/* Test 16 swap. */
SDLTest_AssertCheck( SDL_Swap16(value16) == swapped16,
"SDL_Swap16(): 16 bit swapped: 0x%X => 0x%X",
value16, SDL_Swap16(value16) );
SDLTest_AssertCheck(SDL_Swap16(value16) == swapped16,
"SDL_Swap16(): 16 bit swapped: 0x%X => 0x%X",
value16, SDL_Swap16(value16));
/* Test 32 swap. */
SDLTest_AssertCheck( SDL_Swap32(value32) == swapped32,
"SDL_Swap32(): 32 bit swapped: 0x%" SDL_PRIX32 " => 0x%" SDL_PRIX32,
value32, SDL_Swap32(value32) );
SDLTest_AssertCheck(SDL_Swap32(value32) == swapped32,
"SDL_Swap32(): 32 bit swapped: 0x%" SDL_PRIX32 " => 0x%" SDL_PRIX32,
value32, SDL_Swap32(value32));
/* Test 64 swap. */
SDLTest_AssertCheck( SDL_Swap64(value64) == swapped64,
"SDL_Swap64(): 64 bit swapped: 0x%"SDL_PRIX64" => 0x%"SDL_PRIX64,
value64, SDL_Swap64(value64) );
SDLTest_AssertCheck(SDL_Swap64(value64) == swapped64,
"SDL_Swap64(): 64 bit swapped: 0x%" SDL_PRIX64 " => 0x%" SDL_PRIX64,
value64, SDL_Swap64(value64));
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/* !
@@ -126,41 +128,41 @@ int platform_testEndianessAndSwap(void *arg)
* http://wiki.libsdl.org/SDL_GetRevision
* http://wiki.libsdl.org/SDL_GetRevisionNumber
*/
int platform_testGetFunctions (void *arg)
int platform_testGetFunctions(void *arg)
{
char *platform;
char *revision;
int ret;
size_t len;
char *platform;
char *revision;
int ret;
size_t len;
platform = (char *)SDL_GetPlatform();
SDLTest_AssertPass("SDL_GetPlatform()");
SDLTest_AssertCheck(platform != NULL, "SDL_GetPlatform() != NULL");
if (platform != NULL) {
len = SDL_strlen(platform);
SDLTest_AssertCheck(len > 0,
"SDL_GetPlatform(): expected non-empty platform, was platform: '%s', len: %i",
platform,
(int) len);
}
platform = (char *)SDL_GetPlatform();
SDLTest_AssertPass("SDL_GetPlatform()");
SDLTest_AssertCheck(platform != NULL, "SDL_GetPlatform() != NULL");
if (platform != NULL) {
len = SDL_strlen(platform);
SDLTest_AssertCheck(len > 0,
"SDL_GetPlatform(): expected non-empty platform, was platform: '%s', len: %i",
platform,
(int)len);
}
ret = SDL_GetCPUCount();
SDLTest_AssertPass("SDL_GetCPUCount()");
SDLTest_AssertCheck(ret > 0,
"SDL_GetCPUCount(): expected count > 0, was: %i",
ret);
ret = SDL_GetCPUCount();
SDLTest_AssertPass("SDL_GetCPUCount()");
SDLTest_AssertCheck(ret > 0,
"SDL_GetCPUCount(): expected count > 0, was: %i",
ret);
ret = SDL_GetCPUCacheLineSize();
SDLTest_AssertPass("SDL_GetCPUCacheLineSize()");
SDLTest_AssertCheck(ret >= 0,
"SDL_GetCPUCacheLineSize(): expected size >= 0, was: %i",
ret);
ret = SDL_GetCPUCacheLineSize();
SDLTest_AssertPass("SDL_GetCPUCacheLineSize()");
SDLTest_AssertCheck(ret >= 0,
"SDL_GetCPUCacheLineSize(): expected size >= 0, was: %i",
ret);
revision = (char *)SDL_GetRevision();
SDLTest_AssertPass("SDL_GetRevision()");
SDLTest_AssertCheck(revision != NULL, "SDL_GetRevision() != NULL");
revision = (char *)SDL_GetRevision();
SDLTest_AssertPass("SDL_GetRevision()");
SDLTest_AssertCheck(revision != NULL, "SDL_GetRevision() != NULL");
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/* !
@@ -177,41 +179,41 @@ int platform_testGetFunctions (void *arg)
* http://wiki.libsdl.org/SDL_HasSSE42
* http://wiki.libsdl.org/SDL_HasAVX
*/
int platform_testHasFunctions (void *arg)
int platform_testHasFunctions(void *arg)
{
/* TODO: independently determine and compare values as well */
/* TODO: independently determine and compare values as well */
SDL_HasRDTSC();
SDLTest_AssertPass("SDL_HasRDTSC()");
SDL_HasRDTSC();
SDLTest_AssertPass("SDL_HasRDTSC()");
SDL_HasAltiVec();
SDLTest_AssertPass("SDL_HasAltiVec()");
SDL_HasAltiVec();
SDLTest_AssertPass("SDL_HasAltiVec()");
SDL_HasMMX();
SDLTest_AssertPass("SDL_HasMMX()");
SDL_HasMMX();
SDLTest_AssertPass("SDL_HasMMX()");
SDL_Has3DNow();
SDLTest_AssertPass("SDL_Has3DNow()");
SDL_Has3DNow();
SDLTest_AssertPass("SDL_Has3DNow()");
SDL_HasSSE();
SDLTest_AssertPass("SDL_HasSSE()");
SDL_HasSSE();
SDLTest_AssertPass("SDL_HasSSE()");
SDL_HasSSE2();
SDLTest_AssertPass("SDL_HasSSE2()");
SDL_HasSSE2();
SDLTest_AssertPass("SDL_HasSSE2()");
SDL_HasSSE3();
SDLTest_AssertPass("SDL_HasSSE3()");
SDL_HasSSE3();
SDLTest_AssertPass("SDL_HasSSE3()");
SDL_HasSSE41();
SDLTest_AssertPass("SDL_HasSSE41()");
SDL_HasSSE41();
SDLTest_AssertPass("SDL_HasSSE41()");
SDL_HasSSE42();
SDLTest_AssertPass("SDL_HasSSE42()");
SDL_HasSSE42();
SDLTest_AssertPass("SDL_HasSSE42()");
SDL_HasAVX();
SDLTest_AssertPass("SDL_HasAVX()");
SDL_HasAVX();
SDLTest_AssertPass("SDL_HasAVX()");
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/* !
@@ -221,67 +223,65 @@ int platform_testHasFunctions (void *arg)
*/
int platform_testGetVersion(void *arg)
{
SDL_version linked;
int major = SDL_MAJOR_VERSION;
int minor = SDL_MINOR_VERSION;
SDL_version linked;
int major = SDL_MAJOR_VERSION;
int minor = SDL_MINOR_VERSION;
SDL_GetVersion(&linked);
SDLTest_AssertCheck( linked.major >= major,
"SDL_GetVersion(): returned major %i (>= %i)",
linked.major,
major);
SDLTest_AssertCheck( linked.minor >= minor,
"SDL_GetVersion(): returned minor %i (>= %i)",
linked.minor,
minor);
SDL_GetVersion(&linked);
SDLTest_AssertCheck(linked.major >= major,
"SDL_GetVersion(): returned major %i (>= %i)",
linked.major,
major);
SDLTest_AssertCheck(linked.minor >= minor,
"SDL_GetVersion(): returned minor %i (>= %i)",
linked.minor,
minor);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/* !
* \brief Tests SDL_VERSION macro
*/
int platform_testSDLVersion(void *arg)
{
SDL_version compiled;
int major = SDL_MAJOR_VERSION;
int minor = SDL_MINOR_VERSION;
SDL_version compiled;
int major = SDL_MAJOR_VERSION;
int minor = SDL_MINOR_VERSION;
SDL_VERSION(&compiled);
SDLTest_AssertCheck( compiled.major >= major,
"SDL_VERSION() returned major %i (>= %i)",
compiled.major,
major);
SDLTest_AssertCheck( compiled.minor >= minor,
"SDL_VERSION() returned minor %i (>= %i)",
compiled.minor,
minor);
SDL_VERSION(&compiled);
SDLTest_AssertCheck(compiled.major >= major,
"SDL_VERSION() returned major %i (>= %i)",
compiled.major,
major);
SDLTest_AssertCheck(compiled.minor >= minor,
"SDL_VERSION() returned minor %i (>= %i)",
compiled.minor,
minor);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/* !
* \brief Tests default SDL_Init
*/
int platform_testDefaultInit(void *arg)
{
int ret;
int subsystem;
int ret;
int subsystem;
subsystem = SDL_WasInit(SDL_INIT_EVERYTHING);
SDLTest_AssertCheck( subsystem != 0,
"SDL_WasInit(0): returned %i, expected != 0",
subsystem);
subsystem = SDL_WasInit(SDL_INIT_EVERYTHING);
SDLTest_AssertCheck(subsystem != 0,
"SDL_WasInit(0): returned %i, expected != 0",
subsystem);
ret = SDL_Init(SDL_WasInit(SDL_INIT_EVERYTHING));
SDLTest_AssertCheck( ret == 0,
"SDL_Init(0): returned %i, expected 0, error: %s",
ret,
SDL_GetError());
ret = SDL_Init(SDL_WasInit(SDL_INIT_EVERYTHING));
SDLTest_AssertCheck(ret == 0,
"SDL_Init(0): returned %i, expected 0, error: %s",
ret,
SDL_GetError());
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/* !
@@ -293,47 +293,47 @@ int platform_testDefaultInit(void *arg)
*/
int platform_testGetSetClearError(void *arg)
{
int result;
const char *testError = "Testing";
char *lastError;
size_t len;
int result;
const char *testError = "Testing";
char *lastError;
size_t len;
SDL_ClearError();
SDLTest_AssertPass("SDL_ClearError()");
SDL_ClearError();
SDLTest_AssertPass("SDL_ClearError()");
lastError = (char *)SDL_GetError();
SDLTest_AssertPass("SDL_GetError()");
SDLTest_AssertCheck(lastError != NULL,
"SDL_GetError() != NULL");
if (lastError != NULL) {
len = SDL_strlen(lastError);
SDLTest_AssertCheck(len == 0,
"SDL_GetError(): no message expected, len: %i", (int) len);
}
lastError = (char *)SDL_GetError();
SDLTest_AssertPass("SDL_GetError()");
SDLTest_AssertCheck(lastError != NULL,
"SDL_GetError() != NULL");
if (lastError != NULL) {
len = SDL_strlen(lastError);
SDLTest_AssertCheck(len == 0,
"SDL_GetError(): no message expected, len: %i", (int)len);
}
result = SDL_SetError("%s", testError);
SDLTest_AssertPass("SDL_SetError()");
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
lastError = (char *)SDL_GetError();
SDLTest_AssertCheck(lastError != NULL,
"SDL_GetError() != NULL");
if (lastError != NULL) {
len = SDL_strlen(lastError);
SDLTest_AssertCheck(len == SDL_strlen(testError),
"SDL_GetError(): expected message len %i, was len: %i",
(int) SDL_strlen(testError),
(int) len);
SDLTest_AssertCheck(SDL_strcmp(lastError, testError) == 0,
"SDL_GetError(): expected message %s, was message: %s",
testError,
lastError);
}
result = SDL_SetError("%s", testError);
SDLTest_AssertPass("SDL_SetError()");
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
lastError = (char *)SDL_GetError();
SDLTest_AssertCheck(lastError != NULL,
"SDL_GetError() != NULL");
if (lastError != NULL) {
len = SDL_strlen(lastError);
SDLTest_AssertCheck(len == SDL_strlen(testError),
"SDL_GetError(): expected message len %i, was len: %i",
(int)SDL_strlen(testError),
(int)len);
SDLTest_AssertCheck(SDL_strcmp(lastError, testError) == 0,
"SDL_GetError(): expected message %s, was message: %s",
testError,
lastError);
}
/* Clean up */
SDL_ClearError();
SDLTest_AssertPass("SDL_ClearError()");
/* Clean up */
SDL_ClearError();
SDLTest_AssertPass("SDL_ClearError()");
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/* !
@@ -343,34 +343,34 @@ int platform_testGetSetClearError(void *arg)
*/
int platform_testSetErrorEmptyInput(void *arg)
{
int result;
const char *testError = "";
char *lastError;
size_t len;
int result;
const char *testError = "";
char *lastError;
size_t len;
result = SDL_SetError("%s", testError);
SDLTest_AssertPass("SDL_SetError()");
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
lastError = (char *)SDL_GetError();
SDLTest_AssertCheck(lastError != NULL,
"SDL_GetError() != NULL");
if (lastError != NULL) {
len = SDL_strlen(lastError);
SDLTest_AssertCheck(len == SDL_strlen(testError),
"SDL_GetError(): expected message len %i, was len: %i",
(int) SDL_strlen(testError),
(int) len);
SDLTest_AssertCheck(SDL_strcmp(lastError, testError) == 0,
"SDL_GetError(): expected message '%s', was message: '%s'",
testError,
lastError);
}
result = SDL_SetError("%s", testError);
SDLTest_AssertPass("SDL_SetError()");
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
lastError = (char *)SDL_GetError();
SDLTest_AssertCheck(lastError != NULL,
"SDL_GetError() != NULL");
if (lastError != NULL) {
len = SDL_strlen(lastError);
SDLTest_AssertCheck(len == SDL_strlen(testError),
"SDL_GetError(): expected message len %i, was len: %i",
(int)SDL_strlen(testError),
(int)len);
SDLTest_AssertCheck(SDL_strcmp(lastError, testError) == 0,
"SDL_GetError(): expected message '%s', was message: '%s'",
testError,
lastError);
}
/* Clean up */
SDL_ClearError();
SDLTest_AssertPass("SDL_ClearError()");
/* Clean up */
SDL_ClearError();
SDLTest_AssertPass("SDL_ClearError()");
return TEST_COMPLETED;
return TEST_COMPLETED;
}
#if defined(HAVE_WFORMAT_OVERFLOW)
@@ -385,77 +385,77 @@ int platform_testSetErrorEmptyInput(void *arg)
*/
int platform_testSetErrorInvalidInput(void *arg)
{
int result;
const char *invalidError = NULL;
const char *probeError = "Testing";
char *lastError;
size_t len;
int result;
const char *invalidError = NULL;
const char *probeError = "Testing";
char *lastError;
size_t len;
/* Reset */
SDL_ClearError();
SDLTest_AssertPass("SDL_ClearError()");
/* Reset */
SDL_ClearError();
SDLTest_AssertPass("SDL_ClearError()");
/* Check for no-op */
result = SDL_SetError("%s", invalidError);
SDLTest_AssertPass("SDL_SetError()");
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
lastError = (char *)SDL_GetError();
SDLTest_AssertCheck(lastError != NULL,
"SDL_GetError() != 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",
(int) len);
}
/* Check for no-op */
result = SDL_SetError("%s", invalidError);
SDLTest_AssertPass("SDL_SetError()");
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
lastError = (char *)SDL_GetError();
SDLTest_AssertCheck(lastError != NULL,
"SDL_GetError() != 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",
(int)len);
}
/* Set */
result = SDL_SetError("%s", probeError);
SDLTest_AssertPass("SDL_SetError('%s')", probeError);
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
/* Set */
result = SDL_SetError("%s", probeError);
SDLTest_AssertPass("SDL_SetError('%s')", probeError);
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
/* Check for no-op */
result = SDL_SetError("%s", invalidError);
SDLTest_AssertPass("SDL_SetError(NULL)");
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
lastError = (char *)SDL_GetError();
SDLTest_AssertCheck(lastError != NULL,
"SDL_GetError() != 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",
(int) len);
}
/* Check for no-op */
result = SDL_SetError("%s", invalidError);
SDLTest_AssertPass("SDL_SetError(NULL)");
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
lastError = (char *)SDL_GetError();
SDLTest_AssertCheck(lastError != NULL,
"SDL_GetError() != 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",
(int)len);
}
/* Reset */
SDL_ClearError();
SDLTest_AssertPass("SDL_ClearError()");
/* Reset */
SDL_ClearError();
SDLTest_AssertPass("SDL_ClearError()");
/* Set and check */
result = SDL_SetError("%s", probeError);
SDLTest_AssertPass("SDL_SetError()");
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
lastError = (char *)SDL_GetError();
SDLTest_AssertCheck(lastError != NULL,
"SDL_GetError() != NULL");
if (lastError != NULL) {
len = SDL_strlen(lastError);
SDLTest_AssertCheck(len == SDL_strlen(probeError),
"SDL_GetError(): expected message len %i, was len: %i",
(int) SDL_strlen(probeError),
(int) len);
SDLTest_AssertCheck(SDL_strcmp(lastError, probeError) == 0,
"SDL_GetError(): expected message '%s', was message: '%s'",
probeError,
lastError);
}
/* Set and check */
result = SDL_SetError("%s", probeError);
SDLTest_AssertPass("SDL_SetError()");
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
lastError = (char *)SDL_GetError();
SDLTest_AssertCheck(lastError != NULL,
"SDL_GetError() != NULL");
if (lastError != NULL) {
len = SDL_strlen(lastError);
SDLTest_AssertCheck(len == SDL_strlen(probeError),
"SDL_GetError(): expected message len %i, was len: %i",
(int)SDL_strlen(probeError),
(int)len);
SDLTest_AssertCheck(SDL_strcmp(lastError, probeError) == 0,
"SDL_GetError(): expected message '%s', was message: '%s'",
probeError,
lastError);
}
/* Clean up */
SDL_ClearError();
SDLTest_AssertPass("SDL_ClearError()");
/* Clean up */
SDL_ClearError();
SDLTest_AssertPass("SDL_ClearError()");
return TEST_COMPLETED;
return TEST_COMPLETED;
}
#if defined(HAVE_WFORMAT_OVERFLOW)
@@ -469,114 +469,124 @@ int platform_testSetErrorInvalidInput(void *arg)
*/
int platform_testGetPowerInfo(void *arg)
{
SDL_PowerState state;
SDL_PowerState stateAgain;
int secs;
int secsAgain;
int pct;
int pctAgain;
SDL_PowerState state;
SDL_PowerState stateAgain;
int secs;
int secsAgain;
int pct;
int pctAgain;
state = SDL_GetPowerInfo(&secs, &pct);
SDLTest_AssertPass("SDL_GetPowerInfo()");
SDLTest_AssertCheck(
state==SDL_POWERSTATE_UNKNOWN ||
state==SDL_POWERSTATE_ON_BATTERY ||
state==SDL_POWERSTATE_NO_BATTERY ||
state==SDL_POWERSTATE_CHARGING ||
state==SDL_POWERSTATE_CHARGED,
"SDL_GetPowerInfo(): state %i is one of the expected values",
(int)state);
state = SDL_GetPowerInfo(&secs, &pct);
SDLTest_AssertPass("SDL_GetPowerInfo()");
SDLTest_AssertCheck(
state == SDL_POWERSTATE_UNKNOWN ||
state == SDL_POWERSTATE_ON_BATTERY ||
state == SDL_POWERSTATE_NO_BATTERY ||
state == SDL_POWERSTATE_CHARGING ||
state == SDL_POWERSTATE_CHARGED,
"SDL_GetPowerInfo(): state %i is one of the expected values",
(int)state);
if (state==SDL_POWERSTATE_ON_BATTERY) {
SDLTest_AssertCheck(
secs >= 0,
"SDL_GetPowerInfo(): on battery, secs >= 0, was: %i",
secs);
SDLTest_AssertCheck(
(pct >= 0) && (pct <= 100),
"SDL_GetPowerInfo(): on battery, pct=[0,100], was: %i",
pct);
}
if (state == SDL_POWERSTATE_ON_BATTERY) {
SDLTest_AssertCheck(
secs >= 0,
"SDL_GetPowerInfo(): on battery, secs >= 0, was: %i",
secs);
SDLTest_AssertCheck(
(pct >= 0) && (pct <= 100),
"SDL_GetPowerInfo(): on battery, pct=[0,100], was: %i",
pct);
}
if (state==SDL_POWERSTATE_UNKNOWN ||
state==SDL_POWERSTATE_NO_BATTERY)
{
SDLTest_AssertCheck(
secs == -1,
"SDL_GetPowerInfo(): no battery, secs == -1, was: %i",
secs);
SDLTest_AssertCheck(
pct == -1,
"SDL_GetPowerInfo(): no battery, pct == -1, was: %i",
pct);
}
if (state == SDL_POWERSTATE_UNKNOWN ||
state == SDL_POWERSTATE_NO_BATTERY) {
SDLTest_AssertCheck(
secs == -1,
"SDL_GetPowerInfo(): no battery, secs == -1, was: %i",
secs);
SDLTest_AssertCheck(
pct == -1,
"SDL_GetPowerInfo(): no battery, pct == -1, was: %i",
pct);
}
/* Partial return value variations */
stateAgain = SDL_GetPowerInfo(&secsAgain, NULL);
SDLTest_AssertCheck(
state==stateAgain,
/* Partial return value variations */
stateAgain = SDL_GetPowerInfo(&secsAgain, NULL);
SDLTest_AssertCheck(
state == stateAgain,
"State %i returned when only 'secs' requested",
stateAgain);
SDLTest_AssertCheck(
secs==secsAgain,
SDLTest_AssertCheck(
secs == secsAgain,
"Value %i matches when only 'secs' requested",
secsAgain);
stateAgain = SDL_GetPowerInfo(NULL, &pctAgain);
SDLTest_AssertCheck(
state==stateAgain,
stateAgain = SDL_GetPowerInfo(NULL, &pctAgain);
SDLTest_AssertCheck(
state == stateAgain,
"State %i returned when only 'pct' requested",
stateAgain);
SDLTest_AssertCheck(
pct==pctAgain,
SDLTest_AssertCheck(
pct == pctAgain,
"Value %i matches when only 'pct' requested",
pctAgain);
stateAgain = SDL_GetPowerInfo(NULL, NULL);
SDLTest_AssertCheck(
state==stateAgain,
stateAgain = SDL_GetPowerInfo(NULL, NULL);
SDLTest_AssertCheck(
state == stateAgain,
"State %i returned when no value requested",
stateAgain);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Platform test cases */
static const SDLTest_TestCaseReference platformTest1 =
{ (SDLTest_TestCaseFp)platform_testTypes, "platform_testTypes", "Tests predefined types", TEST_ENABLED};
static const SDLTest_TestCaseReference platformTest1 = {
(SDLTest_TestCaseFp)platform_testTypes, "platform_testTypes", "Tests predefined types", TEST_ENABLED
};
static const SDLTest_TestCaseReference platformTest2 =
{ (SDLTest_TestCaseFp)platform_testEndianessAndSwap, "platform_testEndianessAndSwap", "Tests endianness and swap functions", TEST_ENABLED};
static const SDLTest_TestCaseReference platformTest2 = {
(SDLTest_TestCaseFp)platform_testEndianessAndSwap, "platform_testEndianessAndSwap", "Tests endianness and swap functions", TEST_ENABLED
};
static const SDLTest_TestCaseReference platformTest3 =
{ (SDLTest_TestCaseFp)platform_testGetFunctions, "platform_testGetFunctions", "Tests various SDL_GetXYZ functions", TEST_ENABLED};
static const SDLTest_TestCaseReference platformTest3 = {
(SDLTest_TestCaseFp)platform_testGetFunctions, "platform_testGetFunctions", "Tests various SDL_GetXYZ functions", TEST_ENABLED
};
static const SDLTest_TestCaseReference platformTest4 =
{ (SDLTest_TestCaseFp)platform_testHasFunctions, "platform_testHasFunctions", "Tests various SDL_HasXYZ functions", TEST_ENABLED};
static const SDLTest_TestCaseReference platformTest4 = {
(SDLTest_TestCaseFp)platform_testHasFunctions, "platform_testHasFunctions", "Tests various SDL_HasXYZ functions", TEST_ENABLED
};
static const SDLTest_TestCaseReference platformTest5 =
{ (SDLTest_TestCaseFp)platform_testGetVersion, "platform_testGetVersion", "Tests SDL_GetVersion function", TEST_ENABLED};
static const SDLTest_TestCaseReference platformTest5 = {
(SDLTest_TestCaseFp)platform_testGetVersion, "platform_testGetVersion", "Tests SDL_GetVersion function", TEST_ENABLED
};
static const SDLTest_TestCaseReference platformTest6 =
{ (SDLTest_TestCaseFp)platform_testSDLVersion, "platform_testSDLVersion", "Tests SDL_VERSION macro", TEST_ENABLED};
static const SDLTest_TestCaseReference platformTest6 = {
(SDLTest_TestCaseFp)platform_testSDLVersion, "platform_testSDLVersion", "Tests SDL_VERSION macro", TEST_ENABLED
};
static const SDLTest_TestCaseReference platformTest7 =
{ (SDLTest_TestCaseFp)platform_testDefaultInit, "platform_testDefaultInit", "Tests default SDL_Init", TEST_ENABLED};
static const SDLTest_TestCaseReference platformTest7 = {
(SDLTest_TestCaseFp)platform_testDefaultInit, "platform_testDefaultInit", "Tests default SDL_Init", TEST_ENABLED
};
static const SDLTest_TestCaseReference platformTest8 =
{ (SDLTest_TestCaseFp)platform_testGetSetClearError, "platform_testGetSetClearError", "Tests SDL_Get/Set/ClearError", TEST_ENABLED};
static const SDLTest_TestCaseReference platformTest8 = {
(SDLTest_TestCaseFp)platform_testGetSetClearError, "platform_testGetSetClearError", "Tests SDL_Get/Set/ClearError", TEST_ENABLED
};
static const SDLTest_TestCaseReference platformTest9 =
{ (SDLTest_TestCaseFp)platform_testSetErrorEmptyInput, "platform_testSetErrorEmptyInput", "Tests SDL_SetError with empty input", TEST_ENABLED};
static const SDLTest_TestCaseReference platformTest9 = {
(SDLTest_TestCaseFp)platform_testSetErrorEmptyInput, "platform_testSetErrorEmptyInput", "Tests SDL_SetError with empty input", TEST_ENABLED
};
static const SDLTest_TestCaseReference platformTest10 =
{ (SDLTest_TestCaseFp)platform_testSetErrorInvalidInput, "platform_testSetErrorInvalidInput", "Tests SDL_SetError with invalid input", TEST_ENABLED};
static const SDLTest_TestCaseReference platformTest10 = {
(SDLTest_TestCaseFp)platform_testSetErrorInvalidInput, "platform_testSetErrorInvalidInput", "Tests SDL_SetError with invalid input", TEST_ENABLED
};
static const SDLTest_TestCaseReference platformTest11 =
{ (SDLTest_TestCaseFp)platform_testGetPowerInfo, "platform_testGetPowerInfo", "Tests SDL_GetPowerInfo function", TEST_ENABLED };
static const SDLTest_TestCaseReference platformTest11 = {
(SDLTest_TestCaseFp)platform_testGetPowerInfo, "platform_testGetPowerInfo", "Tests SDL_GetPowerInfo function", TEST_ENABLED
};
/* Sequence of Platform test cases */
static const SDLTest_TestCaseReference *platformTests[] = {
static const SDLTest_TestCaseReference *platformTests[] = {
&platformTest1,
&platformTest2,
&platformTest3,

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -11,7 +11,7 @@
/* quiet windows compiler warnings */
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
# define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdio.h>
@@ -21,9 +21,9 @@
/* ================= Test Case Implementation ================== */
const char* RWopsReadTestFilename = "rwops_read";
const char* RWopsWriteTestFilename = "rwops_write";
const char* RWopsAlphabetFilename = "rwops_alphabet";
const char *RWopsReadTestFilename = "rwops_read";
const char *RWopsWriteTestFilename = "rwops_write";
const char *RWopsAlphabetFilename = "rwops_alphabet";
static const char RWopsHelloWorldTestString[] = "Hello World!";
static const char RWopsHelloWorldCompString[] = "Hello World!";
@@ -31,8 +31,7 @@ static const char RWopsAlphabetString[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/* Fixture */
void
RWopsSetUp(void *arg)
void RWopsSetUp(void *arg)
{
size_t fileLen;
FILE *handle;
@@ -47,36 +46,35 @@ 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);
writtenLen = fwrite(RWopsHelloWorldTestString, 1, fileLen, handle);
SDLTest_AssertCheck(fileLen == writtenLen, "Verify number of written bytes, expected %i, got %i", (int) fileLen, (int) writtenLen);
SDLTest_AssertCheck(fileLen == writtenLen, "Verify number of written bytes, expected %i, got %i", (int)fileLen, (int)writtenLen);
result = fclose(handle);
SDLTest_AssertCheck(result == 0, "Verify result from fclose, expected 0, got %i", result);
/* 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);
writtenLen = fwrite(RWopsAlphabetString, 1, fileLen, handle);
SDLTest_AssertCheck(fileLen == writtenLen, "Verify number of written bytes, expected %i, got %i", (int) fileLen, (int) writtenLen);
SDLTest_AssertCheck(fileLen == writtenLen, "Verify number of written bytes, expected %i, got %i", (int)fileLen, (int)writtenLen);
result = fclose(handle);
SDLTest_AssertCheck(result == 0, "Verify result from fclose, expected 0, got %i", result);
SDLTest_AssertPass("Creation of test file completed");
}
void
RWopsTearDown(void *arg)
void RWopsTearDown(void *arg)
{
int result;
@@ -97,77 +95,76 @@ RWopsTearDown(void *arg)
* http://wiki.libsdl.org/SDL_RWseek
* http://wiki.libsdl.org/SDL_RWread
*/
void
_testGenericRWopsValidations(SDL_RWops *rw, int write)
void _testGenericRWopsValidations(SDL_RWops *rw, int write)
{
char buf[sizeof(RWopsHelloWorldTestString)];
Sint64 i;
size_t s;
int seekPos = SDLTest_RandomIntegerInRange(4, 8);
char buf[sizeof(RWopsHelloWorldTestString)];
Sint64 i;
size_t s;
int seekPos = SDLTest_RandomIntegerInRange(4, 8);
/* Clear buffer */
SDL_zeroa(buf);
/* Clear buffer */
SDL_zeroa(buf);
/* Set to start. */
i = SDL_RWseek(rw, 0, RW_SEEK_SET );
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %"SDL_PRIs64, i);
/* Set to start. */
i = SDL_RWseek(rw, 0, RW_SEEK_SET);
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %" SDL_PRIs64, i);
/* Test write. */
s = SDL_RWwrite(rw, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1, 1);
SDLTest_AssertPass("Call to SDL_RWwrite succeeded");
if (write) {
SDLTest_AssertCheck(s == (size_t)1, "Verify result of writing one byte with SDL_RWwrite, expected 1, got %i", (int) s);
} else {
SDLTest_AssertCheck(s == (size_t)0, "Verify result of writing with SDL_RWwrite, expected: 0, got %i", (int) s);
}
/* Test write. */
s = SDL_RWwrite(rw, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString) - 1, 1);
SDLTest_AssertPass("Call to SDL_RWwrite succeeded");
if (write) {
SDLTest_AssertCheck(s == (size_t)1, "Verify result of writing one byte with SDL_RWwrite, expected 1, got %i", (int)s);
} else {
SDLTest_AssertCheck(s == (size_t)0, "Verify result of writing with SDL_RWwrite, expected: 0, got %i", (int)s);
}
/* Test seek to random position */
i = SDL_RWseek( rw, seekPos, RW_SEEK_SET );
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
SDLTest_AssertCheck(i == (Sint64)seekPos, "Verify seek to %i with SDL_RWseek (RW_SEEK_SET), expected %i, got %"SDL_PRIs64, seekPos, seekPos, i);
/* Test seek to random position */
i = SDL_RWseek(rw, seekPos, RW_SEEK_SET);
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
SDLTest_AssertCheck(i == (Sint64)seekPos, "Verify seek to %i with SDL_RWseek (RW_SEEK_SET), expected %i, got %" SDL_PRIs64, seekPos, seekPos, i);
/* Test seek back to start */
i = SDL_RWseek(rw, 0, RW_SEEK_SET );
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %"SDL_PRIs64, i);
/* Test seek back to start */
i = SDL_RWseek(rw, 0, RW_SEEK_SET);
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %" SDL_PRIs64, i);
/* Test read */
s = SDL_RWread( rw, buf, 1, sizeof(RWopsHelloWorldTestString)-1 );
SDLTest_AssertPass("Call to SDL_RWread succeeded");
SDLTest_AssertCheck(
s == (size_t)(sizeof(RWopsHelloWorldTestString)-1),
"Verify result from SDL_RWread, expected %i, got %i",
(int) (sizeof(RWopsHelloWorldTestString)-1),
(int) s);
SDLTest_AssertCheck(
SDL_memcmp(buf, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1 ) == 0,
"Verify read bytes match expected string, expected '%s', got '%s'", RWopsHelloWorldTestString, buf);
/* Test read */
s = SDL_RWread(rw, buf, 1, sizeof(RWopsHelloWorldTestString) - 1);
SDLTest_AssertPass("Call to SDL_RWread succeeded");
SDLTest_AssertCheck(
s == (size_t)(sizeof(RWopsHelloWorldTestString) - 1),
"Verify result from SDL_RWread, expected %i, got %i",
(int)(sizeof(RWopsHelloWorldTestString) - 1),
(int)s);
SDLTest_AssertCheck(
SDL_memcmp(buf, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString) - 1) == 0,
"Verify read bytes match expected string, expected '%s', got '%s'", RWopsHelloWorldTestString, buf);
/* More seek tests. */
i = SDL_RWseek( rw, -4, RW_SEEK_CUR );
SDLTest_AssertPass("Call to SDL_RWseek(...,-4,RW_SEEK_CUR) succeeded");
SDLTest_AssertCheck(
i == (Sint64)(sizeof(RWopsHelloWorldTestString)-5),
"Verify seek to -4 with SDL_RWseek (RW_SEEK_CUR), expected %i, got %i",
(int) (sizeof(RWopsHelloWorldTestString)-5),
(int) i);
/* More seek tests. */
i = SDL_RWseek(rw, -4, RW_SEEK_CUR);
SDLTest_AssertPass("Call to SDL_RWseek(...,-4,RW_SEEK_CUR) succeeded");
SDLTest_AssertCheck(
i == (Sint64)(sizeof(RWopsHelloWorldTestString) - 5),
"Verify seek to -4 with SDL_RWseek (RW_SEEK_CUR), expected %i, got %i",
(int)(sizeof(RWopsHelloWorldTestString) - 5),
(int)i);
i = SDL_RWseek( rw, -1, RW_SEEK_END );
SDLTest_AssertPass("Call to SDL_RWseek(...,-1,RW_SEEK_END) succeeded");
SDLTest_AssertCheck(
i == (Sint64)(sizeof(RWopsHelloWorldTestString)-2),
"Verify seek to -1 with SDL_RWseek (RW_SEEK_END), expected %i, got %i",
(int) (sizeof(RWopsHelloWorldTestString)-2),
(int) i);
i = SDL_RWseek(rw, -1, RW_SEEK_END);
SDLTest_AssertPass("Call to SDL_RWseek(...,-1,RW_SEEK_END) succeeded");
SDLTest_AssertCheck(
i == (Sint64)(sizeof(RWopsHelloWorldTestString) - 2),
"Verify seek to -1 with SDL_RWseek (RW_SEEK_END), expected %i, got %i",
(int)(sizeof(RWopsHelloWorldTestString) - 2),
(int)i);
/* Invalid whence seek */
i = SDL_RWseek( rw, 0, 999 );
SDLTest_AssertPass("Call to SDL_RWseek(...,0,invalid_whence) succeeded");
SDLTest_AssertCheck(
i == (Sint64)(-1),
"Verify seek with SDL_RWseek (invalid_whence); expected: -1, got %i",
(int) i);
/* Invalid whence seek */
i = SDL_RWseek(rw, 0, 999);
SDLTest_AssertPass("Call to SDL_RWseek(...,0,invalid_whence) succeeded");
SDLTest_AssertCheck(
i == (Sint64)(-1),
"Verify seek with SDL_RWseek (invalid_whence); expected: -1, got %i",
(int)i);
}
/* !
@@ -176,45 +173,44 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write)
* \sa http://wiki.libsdl.org/SDL_RWFromFile
*
*/
int
rwops_testParamNegative (void)
int rwops_testParamNegative(void)
{
SDL_RWops *rwops;
SDL_RWops *rwops;
/* These should all fail. */
rwops = SDL_RWFromFile(NULL, NULL);
SDLTest_AssertPass("Call to SDL_RWFromFile(NULL, NULL) succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(NULL, NULL) returns NULL");
/* These should all fail. */
rwops = SDL_RWFromFile(NULL, NULL);
SDLTest_AssertPass("Call to SDL_RWFromFile(NULL, NULL) succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(NULL, NULL) returns NULL");
rwops = SDL_RWFromFile(NULL, "ab+");
SDLTest_AssertPass("Call to SDL_RWFromFile(NULL, \"ab+\") succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(NULL, \"ab+\") returns NULL");
rwops = SDL_RWFromFile(NULL, "ab+");
SDLTest_AssertPass("Call to SDL_RWFromFile(NULL, \"ab+\") succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(NULL, \"ab+\") returns NULL");
rwops = SDL_RWFromFile(NULL, "sldfkjsldkfj");
SDLTest_AssertPass("Call to SDL_RWFromFile(NULL, \"sldfkjsldkfj\") succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(NULL, \"sldfkjsldkfj\") returns NULL");
rwops = SDL_RWFromFile(NULL, "sldfkjsldkfj");
SDLTest_AssertPass("Call to SDL_RWFromFile(NULL, \"sldfkjsldkfj\") succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(NULL, \"sldfkjsldkfj\") returns NULL");
rwops = SDL_RWFromFile("something", "");
SDLTest_AssertPass("Call to SDL_RWFromFile(\"something\", \"\") succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(\"something\", \"\") returns NULL");
rwops = SDL_RWFromFile("something", "");
SDLTest_AssertPass("Call to SDL_RWFromFile(\"something\", \"\") succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(\"something\", \"\") returns NULL");
rwops = SDL_RWFromFile("something", NULL);
SDLTest_AssertPass("Call to SDL_RWFromFile(\"something\", NULL) succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(\"something\", NULL) returns NULL");
rwops = SDL_RWFromFile("something", NULL);
SDLTest_AssertPass("Call to SDL_RWFromFile(\"something\", NULL) succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(\"something\", NULL) returns NULL");
rwops = SDL_RWFromMem((void *)NULL, 10);
SDLTest_AssertPass("Call to SDL_RWFromMem(NULL, 10) succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromMem(NULL, 10) returns NULL");
rwops = SDL_RWFromMem((void *)NULL, 10);
SDLTest_AssertPass("Call to SDL_RWFromMem(NULL, 10) succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromMem(NULL, 10) returns NULL");
rwops = SDL_RWFromMem((void *)RWopsAlphabetString, 0);
SDLTest_AssertPass("Call to SDL_RWFromMem(data, 0) succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromMem(data, 0) returns NULL");
rwops = SDL_RWFromMem((void *)RWopsAlphabetString, 0);
SDLTest_AssertPass("Call to SDL_RWFromMem(data, 0) succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromMem(data, 0) returns NULL");
rwops = SDL_RWFromConstMem((const void *)RWopsAlphabetString, 0);
SDLTest_AssertPass("Call to SDL_RWFromConstMem(data, 0) succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromConstMem(data, 0) returns NULL");
rwops = SDL_RWFromConstMem((const void *)RWopsAlphabetString, 0);
SDLTest_AssertPass("Call to SDL_RWFromConstMem(data, 0) succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromConstMem(data, 0) returns NULL");
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
@@ -223,41 +219,39 @@ rwops_testParamNegative (void)
* \sa http://wiki.libsdl.org/SDL_RWFromMem
* \sa http://wiki.libsdl.org/SDL_RWClose
*/
int
rwops_testMem (void)
int rwops_testMem(void)
{
char mem[sizeof(RWopsHelloWorldTestString)];
SDL_RWops *rw;
int result;
char mem[sizeof(RWopsHelloWorldTestString)];
SDL_RWops *rw;
int result;
/* Clear buffer */
SDL_zeroa(mem);
/* Clear buffer */
SDL_zeroa(mem);
/* Open */
rw = SDL_RWFromMem(mem, sizeof(RWopsHelloWorldTestString)-1);
SDLTest_AssertPass("Call to SDL_RWFromMem() succeeded");
SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromMem does not return NULL");
/* Open */
rw = SDL_RWFromMem(mem, sizeof(RWopsHelloWorldTestString) - 1);
SDLTest_AssertPass("Call to SDL_RWFromMem() succeeded");
SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromMem does not return NULL");
/* Bail out if NULL */
if (rw == NULL) {
return TEST_ABORTED;
}
/* Bail out if NULL */
if (rw == NULL) {
return TEST_ABORTED;
}
/* Check type */
SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY, "Verify RWops type is SDL_RWOPS_MEMORY; expected: %d, got: %" SDL_PRIu32, SDL_RWOPS_MEMORY, rw->type);
/* 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);
/* Run generic tests */
_testGenericRWopsValidations(rw, 1);
/* Run generic tests */
_testGenericRWopsValidations(rw, 1);
/* Close */
result = SDL_RWclose(rw);
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
/* Close */
result = SDL_RWclose(rw);
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
* @brief Tests opening from memory.
*
@@ -265,37 +259,35 @@ rwops_testMem (void)
* http://wiki.libsdl.org/SDL_RWFromConstMem
* http://wiki.libsdl.org/SDL_RWClose
*/
int
rwops_testConstMem (void)
int rwops_testConstMem(void)
{
SDL_RWops *rw;
int result;
SDL_RWops *rw;
int result;
/* Open handle */
rw = SDL_RWFromConstMem( RWopsHelloWorldCompString, sizeof(RWopsHelloWorldCompString)-1 );
SDLTest_AssertPass("Call to SDL_RWFromConstMem() succeeded");
SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromConstMem does not return NULL");
/* Open handle */
rw = SDL_RWFromConstMem(RWopsHelloWorldCompString, sizeof(RWopsHelloWorldCompString) - 1);
SDLTest_AssertPass("Call to SDL_RWFromConstMem() succeeded");
SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromConstMem does not return NULL");
/* Bail out if NULL */
if (rw == NULL) {
return TEST_ABORTED;
}
/* Bail out if NULL */
if (rw == NULL) {
return TEST_ABORTED;
}
/* Check type */
SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY_RO, "Verify RWops type is SDL_RWOPS_MEMORY_RO; expected: %d, got: %" SDL_PRIu32, SDL_RWOPS_MEMORY_RO, rw->type);
/* 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);
/* Run generic tests */
_testGenericRWopsValidations( rw, 0 );
/* Run generic tests */
_testGenericRWopsValidations(rw, 0);
/* Close handle */
result = SDL_RWclose(rw);
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
/* Close handle */
result = SDL_RWclose(rw);
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
* @brief Tests reading from file.
*
@@ -303,46 +295,45 @@ rwops_testConstMem (void)
* http://wiki.libsdl.org/SDL_RWFromFile
* http://wiki.libsdl.org/SDL_RWClose
*/
int
rwops_testFileRead(void)
int rwops_testFileRead(void)
{
SDL_RWops *rw;
int result;
SDL_RWops *rw;
int result;
/* Read test. */
rw = SDL_RWFromFile(RWopsReadTestFilename, "r");
SDLTest_AssertPass("Call to SDL_RWFromFile(..,\"r\") succeeded");
SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in read mode does not return NULL");
/* Read test. */
rw = SDL_RWFromFile(RWopsReadTestFilename, "r");
SDLTest_AssertPass("Call to SDL_RWFromFile(..,\"r\") succeeded");
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;
}
/* Bail out if NULL */
if (rw == NULL) {
return TEST_ABORTED;
}
/* Check type */
/* Check type */
#if defined(__ANDROID__)
SDLTest_AssertCheck(
rw->type == SDL_RWOPS_STDFILE || rw->type == SDL_RWOPS_JNIFILE,
"Verify RWops type is SDL_RWOPS_STDFILE or SDL_RWOPS_JNIFILE; expected: %d|%d, got: %d", SDL_RWOPS_STDFILE, SDL_RWOPS_JNIFILE, rw->type);
SDLTest_AssertCheck(
rw->type == SDL_RWOPS_STDFILE || rw->type == SDL_RWOPS_JNIFILE,
"Verify RWops type is SDL_RWOPS_STDFILE or SDL_RWOPS_JNIFILE; expected: %d|%d, got: %d", SDL_RWOPS_STDFILE, SDL_RWOPS_JNIFILE, rw->type);
#elif defined(__WIN32__)
SDLTest_AssertCheck(
rw->type == SDL_RWOPS_WINFILE,
"Verify RWops type is SDL_RWOPS_WINFILE; expected: %d, got: %d", SDL_RWOPS_WINFILE, rw->type);
SDLTest_AssertCheck(
rw->type == SDL_RWOPS_WINFILE,
"Verify RWops type is SDL_RWOPS_WINFILE; expected: %d, got: %d", SDL_RWOPS_WINFILE, rw->type);
#else
SDLTest_AssertCheck(
rw->type == SDL_RWOPS_STDFILE,
"Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %" SDL_PRIu32, SDL_RWOPS_STDFILE, rw->type);
SDLTest_AssertCheck(
rw->type == SDL_RWOPS_STDFILE,
"Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %" SDL_PRIu32, SDL_RWOPS_STDFILE, rw->type);
#endif
/* Run generic tests */
_testGenericRWopsValidations( rw, 0 );
/* Run generic tests */
_testGenericRWopsValidations(rw, 0);
/* Close handle */
result = SDL_RWclose(rw);
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
/* Close handle */
result = SDL_RWclose(rw);
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
@@ -352,49 +343,47 @@ rwops_testFileRead(void)
* http://wiki.libsdl.org/SDL_RWFromFile
* http://wiki.libsdl.org/SDL_RWClose
*/
int
rwops_testFileWrite(void)
int rwops_testFileWrite(void)
{
SDL_RWops *rw;
int result;
SDL_RWops *rw;
int result;
/* Write test. */
rw = SDL_RWFromFile(RWopsWriteTestFilename, "w+");
SDLTest_AssertPass("Call to SDL_RWFromFile(..,\"w+\") succeeded");
SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in write mode does not return NULL");
/* Write test. */
rw = SDL_RWFromFile(RWopsWriteTestFilename, "w+");
SDLTest_AssertPass("Call to SDL_RWFromFile(..,\"w+\") succeeded");
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;
}
/* Bail out if NULL */
if (rw == NULL) {
return TEST_ABORTED;
}
/* Check type */
/* Check type */
#if defined(__ANDROID__)
SDLTest_AssertCheck(
rw->type == SDL_RWOPS_STDFILE || rw->type == SDL_RWOPS_JNIFILE,
"Verify RWops type is SDL_RWOPS_STDFILE or SDL_RWOPS_JNIFILE; expected: %d|%d, got: %d", SDL_RWOPS_STDFILE, SDL_RWOPS_JNIFILE, rw->type);
SDLTest_AssertCheck(
rw->type == SDL_RWOPS_STDFILE || rw->type == SDL_RWOPS_JNIFILE,
"Verify RWops type is SDL_RWOPS_STDFILE or SDL_RWOPS_JNIFILE; expected: %d|%d, got: %d", SDL_RWOPS_STDFILE, SDL_RWOPS_JNIFILE, rw->type);
#elif defined(__WIN32__)
SDLTest_AssertCheck(
rw->type == SDL_RWOPS_WINFILE,
"Verify RWops type is SDL_RWOPS_WINFILE; expected: %d, got: %d", SDL_RWOPS_WINFILE, rw->type);
SDLTest_AssertCheck(
rw->type == SDL_RWOPS_WINFILE,
"Verify RWops type is SDL_RWOPS_WINFILE; expected: %d, got: %d", SDL_RWOPS_WINFILE, rw->type);
#else
SDLTest_AssertCheck(
rw->type == SDL_RWOPS_STDFILE,
"Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %" SDL_PRIu32, SDL_RWOPS_STDFILE, rw->type);
SDLTest_AssertCheck(
rw->type == SDL_RWOPS_STDFILE,
"Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %" SDL_PRIu32, SDL_RWOPS_STDFILE, rw->type);
#endif
/* Run generic tests */
_testGenericRWopsValidations( rw, 1 );
/* Run generic tests */
_testGenericRWopsValidations(rw, 1);
/* Close handle */
result = SDL_RWclose(rw);
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
/* Close handle */
result = SDL_RWclose(rw);
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
* @brief Tests reading from file handle
*
@@ -506,27 +495,26 @@ rwops_testFPWrite(void)
* \sa http://wiki.libsdl.org/SDL_AllocRW
* \sa http://wiki.libsdl.org/SDL_FreeRW
*/
int
rwops_testAllocFree (void)
int rwops_testAllocFree(void)
{
/* Allocate context */
SDL_RWops *rw = SDL_AllocRW();
SDLTest_AssertPass("Call to SDL_AllocRW() succeeded");
SDLTest_AssertCheck(rw != NULL, "Validate result from SDL_AllocRW() is not NULL");
if (rw == NULL) {
return TEST_ABORTED;
}
/* Allocate context */
SDL_RWops *rw = SDL_AllocRW();
SDLTest_AssertPass("Call to SDL_AllocRW() succeeded");
SDLTest_AssertCheck(rw != NULL, "Validate result from SDL_AllocRW() is not NULL");
if (rw == NULL) {
return TEST_ABORTED;
}
/* Check type */
SDLTest_AssertCheck(
rw->type == SDL_RWOPS_UNKNOWN,
"Verify RWops type is SDL_RWOPS_UNKNOWN; expected: %d, got: %" SDL_PRIu32, SDL_RWOPS_UNKNOWN, rw->type);
/* Check type */
SDLTest_AssertCheck(
rw->type == SDL_RWOPS_UNKNOWN,
"Verify RWops type is SDL_RWOPS_UNKNOWN; expected: %d, got: %" SDL_PRIu32, SDL_RWOPS_UNKNOWN, rw->type);
/* Free context again */
SDL_FreeRW(rw);
SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
/* Free context again */
SDL_FreeRW(rw);
SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
@@ -535,63 +523,61 @@ rwops_testAllocFree (void)
* \sa http://wiki.libsdl.org/SDL_RWFromMem
* \sa http://wiki.libsdl.org/SDL_RWFromFile
*/
int
rwops_testCompareRWFromMemWithRWFromFile(void)
int rwops_testCompareRWFromMemWithRWFromFile(void)
{
int slen = 26;
char buffer_file[27];
char buffer_mem[27];
size_t rv_file;
size_t rv_mem;
Uint64 sv_file;
Uint64 sv_mem;
SDL_RWops* rwops_file;
SDL_RWops* rwops_mem;
int size;
int result;
int slen = 26;
char buffer_file[27];
char buffer_mem[27];
size_t rv_file;
size_t rv_mem;
Uint64 sv_file;
Uint64 sv_mem;
SDL_RWops *rwops_file;
SDL_RWops *rwops_mem;
int size;
int result;
for (size = 5; size < 10; size++) {
/* Terminate buffer */
buffer_file[slen] = 0;
buffer_mem[slen] = 0;
for (size=5; size<10; size++) {
/* Terminate buffer */
buffer_file[slen] = 0;
buffer_mem[slen] = 0;
/* Read/seek from memory */
rwops_mem = SDL_RWFromMem((void *)RWopsAlphabetString, slen);
SDLTest_AssertPass("Call to SDL_RWFromMem()");
rv_mem = SDL_RWread(rwops_mem, buffer_mem, size, 6);
SDLTest_AssertPass("Call to SDL_RWread(mem, size=%d)", size);
sv_mem = SDL_RWseek(rwops_mem, 0, SEEK_END);
SDLTest_AssertPass("Call to SDL_RWseek(mem,SEEK_END)");
result = SDL_RWclose(rwops_mem);
SDLTest_AssertPass("Call to SDL_RWclose(mem)");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
/* Read/seek from memory */
rwops_mem = SDL_RWFromMem((void *)RWopsAlphabetString, slen);
SDLTest_AssertPass("Call to SDL_RWFromMem()");
rv_mem = SDL_RWread(rwops_mem, buffer_mem, size, 6);
SDLTest_AssertPass("Call to SDL_RWread(mem, size=%d)", size);
sv_mem = SDL_RWseek(rwops_mem, 0, SEEK_END);
SDLTest_AssertPass("Call to SDL_RWseek(mem,SEEK_END)");
result = SDL_RWclose(rwops_mem);
SDLTest_AssertPass("Call to SDL_RWclose(mem)");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
/* Read/see from file */
rwops_file = SDL_RWFromFile(RWopsAlphabetFilename, "r");
SDLTest_AssertPass("Call to SDL_RWFromFile()");
rv_file = SDL_RWread(rwops_file, buffer_file, size, 6);
SDLTest_AssertPass("Call to SDL_RWread(file, size=%d)", size);
sv_file = SDL_RWseek(rwops_file, 0, SEEK_END);
SDLTest_AssertPass("Call to SDL_RWseek(file,SEEK_END)");
result = SDL_RWclose(rwops_file);
SDLTest_AssertPass("Call to SDL_RWclose(file)");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
/* Read/see from file */
rwops_file = SDL_RWFromFile(RWopsAlphabetFilename, "r");
SDLTest_AssertPass("Call to SDL_RWFromFile()");
rv_file = SDL_RWread(rwops_file, buffer_file, size, 6);
SDLTest_AssertPass("Call to SDL_RWread(file, size=%d)", size);
sv_file = SDL_RWseek(rwops_file, 0, SEEK_END);
SDLTest_AssertPass("Call to SDL_RWseek(file,SEEK_END)");
result = SDL_RWclose(rwops_file);
SDLTest_AssertPass("Call to SDL_RWclose(file)");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
/* Compare */
SDLTest_AssertCheck(rv_mem == rv_file, "Verify returned read blocks matches for mem and file reads; got: rv_mem=%d rv_file=%d", (int)rv_mem, (int)rv_file);
SDLTest_AssertCheck(sv_mem == sv_file, "Verify SEEK_END position matches for mem and file seeks; got: sv_mem=%d sv_file=%d", (int)sv_mem, (int)sv_file);
SDLTest_AssertCheck(buffer_mem[slen] == 0, "Verify mem buffer termination; expected: 0, got: %d", buffer_mem[slen]);
SDLTest_AssertCheck(buffer_file[slen] == 0, "Verify file buffer termination; expected: 0, got: %d", buffer_file[slen]);
SDLTest_AssertCheck(
SDL_strncmp(buffer_mem, RWopsAlphabetString, slen) == 0,
"Verify mem buffer contain alphabet string; expected: %s, got: %s", RWopsAlphabetString, buffer_mem);
SDLTest_AssertCheck(
SDL_strncmp(buffer_file, RWopsAlphabetString, slen) == 0,
"Verify file buffer contain alphabet string; expected: %s, got: %s", RWopsAlphabetString, buffer_file);
}
/* Compare */
SDLTest_AssertCheck(rv_mem == rv_file, "Verify returned read blocks matches for mem and file reads; got: rv_mem=%d rv_file=%d", (int) rv_mem, (int) rv_file);
SDLTest_AssertCheck(sv_mem == sv_file, "Verify SEEK_END position matches for mem and file seeks; got: sv_mem=%d sv_file=%d", (int) sv_mem, (int) sv_file);
SDLTest_AssertCheck(buffer_mem[slen] == 0, "Verify mem buffer termination; expected: 0, got: %d", buffer_mem[slen]);
SDLTest_AssertCheck(buffer_file[slen] == 0, "Verify file buffer termination; expected: 0, got: %d", buffer_file[slen]);
SDLTest_AssertCheck(
SDL_strncmp(buffer_mem, RWopsAlphabetString, slen) == 0,
"Verify mem buffer contain alphabet string; expected: %s, got: %s", RWopsAlphabetString, buffer_mem);
SDLTest_AssertCheck(
SDL_strncmp(buffer_file, RWopsAlphabetString, slen) == 0,
"Verify file buffer contain alphabet string; expected: %s, got: %s", RWopsAlphabetString, buffer_file);
}
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
@@ -603,143 +589,146 @@ rwops_testCompareRWFromMemWithRWFromFile(void)
* http://wiki.libsdl.org/SDL_ReadBE16
* http://wiki.libsdl.org/SDL_WriteBE16
*/
int
rwops_testFileWriteReadEndian(void)
int rwops_testFileWriteReadEndian(void)
{
SDL_RWops *rw;
Sint64 result;
int mode;
size_t objectsWritten;
Uint16 BE16value;
Uint32 BE32value;
Uint64 BE64value;
Uint16 LE16value;
Uint32 LE32value;
Uint64 LE64value;
Uint16 BE16test;
Uint32 BE32test;
Uint64 BE64test;
Uint16 LE16test;
Uint32 LE32test;
Uint64 LE64test;
int cresult;
SDL_RWops *rw;
Sint64 result;
int mode;
size_t objectsWritten;
Uint16 BE16value;
Uint32 BE32value;
Uint64 BE64value;
Uint16 LE16value;
Uint32 LE32value;
Uint64 LE64value;
Uint16 BE16test;
Uint32 BE32test;
Uint64 BE64test;
Uint16 LE16test;
Uint32 LE32test;
Uint64 LE64test;
int cresult;
for (mode = 0; mode < 3; mode++) {
for (mode = 0; mode < 3; mode++) {
/* Create test data */
switch (mode) {
default:
case 0:
SDLTest_Log("All 0 values");
BE16value = 0;
BE32value = 0;
BE64value = 0;
LE16value = 0;
LE32value = 0;
LE64value = 0;
break;
case 1:
SDLTest_Log("All 1 values");
BE16value = 1;
BE32value = 1;
BE64value = 1;
LE16value = 1;
LE32value = 1;
LE64value = 1;
break;
case 2:
SDLTest_Log("Random values");
BE16value = SDLTest_RandomUint16();
BE32value = SDLTest_RandomUint32();
BE64value = SDLTest_RandomUint64();
LE16value = SDLTest_RandomUint16();
LE32value = SDLTest_RandomUint32();
LE64value = SDLTest_RandomUint64();
break;
}
/* Create test data */
switch (mode) {
default:
case 0:
SDLTest_Log("All 0 values");
BE16value = 0;
BE32value = 0;
BE64value = 0;
LE16value = 0;
LE32value = 0;
LE64value = 0;
break;
case 1:
SDLTest_Log("All 1 values");
BE16value = 1;
BE32value = 1;
BE64value = 1;
LE16value = 1;
LE32value = 1;
LE64value = 1;
break;
case 2:
SDLTest_Log("Random values");
BE16value = SDLTest_RandomUint16();
BE32value = SDLTest_RandomUint32();
BE64value = SDLTest_RandomUint64();
LE16value = SDLTest_RandomUint16();
LE32value = SDLTest_RandomUint32();
LE64value = SDLTest_RandomUint64();
break;
}
/* Write test. */
rw = SDL_RWFromFile(RWopsWriteTestFilename, "w+");
SDLTest_AssertPass("Call to SDL_RWFromFile(..,\"w+\")");
SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in write mode does not return NULL");
/* Write test. */
rw = SDL_RWFromFile(RWopsWriteTestFilename, "w+");
SDLTest_AssertPass("Call to SDL_RWFromFile(..,\"w+\")");
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;
}
/* Bail out if NULL */
if (rw == NULL) {
return TEST_ABORTED;
}
/* Write test data */
objectsWritten = SDL_WriteBE16(rw, BE16value);
SDLTest_AssertPass("Call to SDL_WriteBE16()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int) objectsWritten);
objectsWritten = SDL_WriteBE32(rw, BE32value);
SDLTest_AssertPass("Call to SDL_WriteBE32()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int) objectsWritten);
objectsWritten = SDL_WriteBE64(rw, BE64value);
SDLTest_AssertPass("Call to SDL_WriteBE64()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int) objectsWritten);
objectsWritten = SDL_WriteLE16(rw, LE16value);
SDLTest_AssertPass("Call to SDL_WriteLE16()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int) objectsWritten);
objectsWritten = SDL_WriteLE32(rw, LE32value);
SDLTest_AssertPass("Call to SDL_WriteLE32()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int) objectsWritten);
objectsWritten = SDL_WriteLE64(rw, LE64value);
SDLTest_AssertPass("Call to SDL_WriteLE64()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int) objectsWritten);
/* Write test data */
objectsWritten = SDL_WriteBE16(rw, BE16value);
SDLTest_AssertPass("Call to SDL_WriteBE16()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int)objectsWritten);
objectsWritten = SDL_WriteBE32(rw, BE32value);
SDLTest_AssertPass("Call to SDL_WriteBE32()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int)objectsWritten);
objectsWritten = SDL_WriteBE64(rw, BE64value);
SDLTest_AssertPass("Call to SDL_WriteBE64()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int)objectsWritten);
objectsWritten = SDL_WriteLE16(rw, LE16value);
SDLTest_AssertPass("Call to SDL_WriteLE16()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int)objectsWritten);
objectsWritten = SDL_WriteLE32(rw, LE32value);
SDLTest_AssertPass("Call to SDL_WriteLE32()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int)objectsWritten);
objectsWritten = SDL_WriteLE64(rw, LE64value);
SDLTest_AssertPass("Call to SDL_WriteLE64()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int)objectsWritten);
/* Test seek to start */
result = SDL_RWseek( rw, 0, RW_SEEK_SET );
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
SDLTest_AssertCheck(result == 0, "Verify result from position 0 with SDL_RWseek, expected 0, got %i", (int) result);
/* Test seek to start */
result = SDL_RWseek(rw, 0, RW_SEEK_SET);
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
SDLTest_AssertCheck(result == 0, "Verify result from position 0 with SDL_RWseek, expected 0, got %i", (int)result);
/* Read test data */
BE16test = SDL_ReadBE16(rw);
SDLTest_AssertPass("Call to SDL_ReadBE16()");
SDLTest_AssertCheck(BE16test == BE16value, "Validate return value from SDL_ReadBE16, expected: %hu, got: %hu", BE16value, BE16test);
BE32test = SDL_ReadBE32(rw);
SDLTest_AssertPass("Call to SDL_ReadBE32()");
SDLTest_AssertCheck(BE32test == BE32value, "Validate return value from SDL_ReadBE32, expected: %" SDL_PRIu32 ", got: %" SDL_PRIu32, BE32value, BE32test);
BE64test = SDL_ReadBE64(rw);
SDLTest_AssertPass("Call to SDL_ReadBE64()");
SDLTest_AssertCheck(BE64test == BE64value, "Validate return value from SDL_ReadBE64, expected: %"SDL_PRIu64", got: %"SDL_PRIu64, BE64value, BE64test);
LE16test = SDL_ReadLE16(rw);
SDLTest_AssertPass("Call to SDL_ReadLE16()");
SDLTest_AssertCheck(LE16test == LE16value, "Validate return value from SDL_ReadLE16, expected: %hu, got: %hu", LE16value, LE16test);
LE32test = SDL_ReadLE32(rw);
SDLTest_AssertPass("Call to SDL_ReadLE32()");
SDLTest_AssertCheck(LE32test == LE32value, "Validate return value from SDL_ReadLE32, expected: %" SDL_PRIu32 ", got: %" SDL_PRIu32, LE32value, LE32test);
LE64test = SDL_ReadLE64(rw);
SDLTest_AssertPass("Call to SDL_ReadLE64()");
SDLTest_AssertCheck(LE64test == LE64value, "Validate return value from SDL_ReadLE64, expected: %"SDL_PRIu64", got: %"SDL_PRIu64, LE64value, LE64test);
/* Read test data */
BE16test = SDL_ReadBE16(rw);
SDLTest_AssertPass("Call to SDL_ReadBE16()");
SDLTest_AssertCheck(BE16test == BE16value, "Validate return value from SDL_ReadBE16, expected: %hu, got: %hu", BE16value, BE16test);
BE32test = SDL_ReadBE32(rw);
SDLTest_AssertPass("Call to SDL_ReadBE32()");
SDLTest_AssertCheck(BE32test == BE32value, "Validate return value from SDL_ReadBE32, expected: %" SDL_PRIu32 ", got: %" SDL_PRIu32, BE32value, BE32test);
BE64test = SDL_ReadBE64(rw);
SDLTest_AssertPass("Call to SDL_ReadBE64()");
SDLTest_AssertCheck(BE64test == BE64value, "Validate return value from SDL_ReadBE64, expected: %" SDL_PRIu64 ", got: %" SDL_PRIu64, BE64value, BE64test);
LE16test = SDL_ReadLE16(rw);
SDLTest_AssertPass("Call to SDL_ReadLE16()");
SDLTest_AssertCheck(LE16test == LE16value, "Validate return value from SDL_ReadLE16, expected: %hu, got: %hu", LE16value, LE16test);
LE32test = SDL_ReadLE32(rw);
SDLTest_AssertPass("Call to SDL_ReadLE32()");
SDLTest_AssertCheck(LE32test == LE32value, "Validate return value from SDL_ReadLE32, expected: %" SDL_PRIu32 ", got: %" SDL_PRIu32, LE32value, LE32test);
LE64test = SDL_ReadLE64(rw);
SDLTest_AssertPass("Call to SDL_ReadLE64()");
SDLTest_AssertCheck(LE64test == LE64value, "Validate return value from SDL_ReadLE64, expected: %" SDL_PRIu64 ", got: %" SDL_PRIu64, LE64value, LE64test);
/* Close handle */
cresult = SDL_RWclose(rw);
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
SDLTest_AssertCheck(cresult == 0, "Verify result value is 0; got: %d", cresult);
}
/* Close handle */
cresult = SDL_RWclose(rw);
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
SDLTest_AssertCheck(cresult == 0, "Verify result value is 0; got: %d", cresult);
}
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* RWops test cases */
static const SDLTest_TestCaseReference rwopsTest1 =
{ (SDLTest_TestCaseFp)rwops_testParamNegative, "rwops_testParamNegative", "Negative test for SDL_RWFromFile parameters", TEST_ENABLED };
static const SDLTest_TestCaseReference rwopsTest1 = {
(SDLTest_TestCaseFp)rwops_testParamNegative, "rwops_testParamNegative", "Negative test for SDL_RWFromFile parameters", TEST_ENABLED
};
static const SDLTest_TestCaseReference rwopsTest2 =
{ (SDLTest_TestCaseFp)rwops_testMem, "rwops_testMem", "Tests opening from memory", TEST_ENABLED };
static const SDLTest_TestCaseReference rwopsTest2 = {
(SDLTest_TestCaseFp)rwops_testMem, "rwops_testMem", "Tests opening from memory", TEST_ENABLED
};
static const SDLTest_TestCaseReference rwopsTest3 =
{ (SDLTest_TestCaseFp)rwops_testConstMem, "rwops_testConstMem", "Tests opening from (const) memory", TEST_ENABLED };
static const SDLTest_TestCaseReference rwopsTest3 = {
(SDLTest_TestCaseFp)rwops_testConstMem, "rwops_testConstMem", "Tests opening from (const) memory", TEST_ENABLED
};
static const SDLTest_TestCaseReference rwopsTest4 =
{ (SDLTest_TestCaseFp)rwops_testFileRead, "rwops_testFileRead", "Tests reading from a file", TEST_ENABLED };
static const SDLTest_TestCaseReference rwopsTest4 = {
(SDLTest_TestCaseFp)rwops_testFileRead, "rwops_testFileRead", "Tests reading from a file", TEST_ENABLED
};
static const SDLTest_TestCaseReference rwopsTest5 =
{ (SDLTest_TestCaseFp)rwops_testFileWrite, "rwops_testFileWrite", "Test writing to a file", TEST_ENABLED };
static const SDLTest_TestCaseReference rwopsTest5 = {
(SDLTest_TestCaseFp)rwops_testFileWrite, "rwops_testFileWrite", "Test writing to a file", TEST_ENABLED
};
static const SDLTest_TestCaseReference rwopsTest6 =
{ (SDLTest_TestCaseFp)rwops_testFPRead, "rwops_testFPRead", "Test reading from file pointer", TEST_ENABLED };
@@ -757,7 +746,7 @@ static const SDLTest_TestCaseReference rwopsTest10 =
{ (SDLTest_TestCaseFp)rwops_testCompareRWFromMemWithRWFromFile, "rwops_testCompareRWFromMemWithRWFromFile", "Compare RWFromMem and RWFromFile RWops for read and seek", TEST_ENABLED };
/* Sequence of RWops test cases */
static const SDLTest_TestCaseReference *rwopsTests[] = {
static const SDLTest_TestCaseReference *rwopsTests[] = {
&rwopsTest1, &rwopsTest2, &rwopsTest3, &rwopsTest4, &rwopsTest5, &rwopsTest6,
&rwopsTest7, &rwopsTest8, &rwopsTest9, &rwopsTest10, NULL
};

File diff suppressed because it is too large Load Diff

View File

@@ -13,26 +13,25 @@
* @brief Call to SDL_strlcpy
*/
#undef SDL_strlcpy
int
stdlib_strlcpy(void *arg)
int stdlib_strlcpy(void *arg)
{
size_t result;
char text[1024];
const char *expected;
size_t result;
char text[1024];
const char *expected;
result = SDL_strlcpy(text, "foo", sizeof(text));
expected = "foo";
SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\")");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), (int) result);
result = SDL_strlcpy(text, "foo", sizeof(text));
expected = "foo";
SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\")");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), (int)result);
result = SDL_strlcpy(text, "foo", 2);
expected = "f";
SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\") with buffer size 2");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", (int) result);
result = SDL_strlcpy(text, "foo", 2);
expected = "f";
SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\") with buffer size 2");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", (int)result);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
#if defined(HAVE_WFORMAT) || defined(HAVE_WFORMAT_EXTRA_ARGS)
@@ -49,123 +48,122 @@ stdlib_strlcpy(void *arg)
* @brief Call to SDL_snprintf
*/
#undef SDL_snprintf
int
stdlib_snprintf(void *arg)
int stdlib_snprintf(void *arg)
{
int result;
int predicted;
char text[1024];
const char *expected;
size_t size;
int result;
int predicted;
char text[1024];
const char *expected;
size_t size;
result = SDL_snprintf(text, sizeof(text), "%s", "foo");
expected = "foo";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\", \"foo\")");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
result = SDL_snprintf(text, sizeof(text), "%s", "foo");
expected = "foo";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\", \"foo\")");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
result = SDL_snprintf(text, 2, "%s", "foo");
expected = "f";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\", \"foo\") with buffer size 2");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
result = SDL_snprintf(text, 2, "%s", "foo");
expected = "f";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\", \"foo\") with buffer size 2");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
result = SDL_snprintf(NULL, 0, "%s", "foo");
SDLTest_AssertPass("Call to SDL_snprintf(NULL, 0, \"%%s\", \"foo\")");
SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
result = SDL_snprintf(NULL, 0, "%s", "foo");
SDLTest_AssertPass("Call to SDL_snprintf(NULL, 0, \"%%s\", \"foo\")");
SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
result = SDL_snprintf(text, 2, "%s\n", "foo");
expected = "f";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\\n\", \"foo\") with buffer size 2");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == 4, "Check result value, expected: 4, got: %d", result);
result = SDL_snprintf(text, 2, "%s\n", "foo");
expected = "f";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\\n\", \"foo\") with buffer size 2");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == 4, "Check result value, expected: 4, got: %d", result);
result = SDL_snprintf(text, sizeof(text), "%f", 0.0);
predicted = SDL_snprintf(NULL, 0, "%f", 0.0);
expected = "0.000000";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 0.0)");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
result = SDL_snprintf(text, sizeof(text), "%f", 0.0);
predicted = SDL_snprintf(NULL, 0, "%f", 0.0);
expected = "0.000000";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 0.0)");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
result = SDL_snprintf(text, sizeof(text), "%f", 1.0);
predicted = SDL_snprintf(NULL, 0, "%f", 1.0);
expected = "1.000000";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0)");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
result = SDL_snprintf(text, sizeof(text), "%f", 1.0);
predicted = SDL_snprintf(NULL, 0, "%f", 1.0);
expected = "1.000000";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0)");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
result = SDL_snprintf(text, sizeof(text), "%.f", 1.0);
predicted = SDL_snprintf(NULL, 0, "%.f", 1.0);
expected = "1";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%.f\", 1.0)");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
result = SDL_snprintf(text, sizeof(text), "%.f", 1.0);
predicted = SDL_snprintf(NULL, 0, "%.f", 1.0);
expected = "1";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%.f\", 1.0)");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
result = SDL_snprintf(text, sizeof(text), "%#.f", 1.0);
predicted = SDL_snprintf(NULL, 0, "%#.f", 1.0);
expected = "1.";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%#.f\", 1.0)");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
result = SDL_snprintf(text, sizeof(text), "%#.f", 1.0);
predicted = SDL_snprintf(NULL, 0, "%#.f", 1.0);
expected = "1.";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%#.f\", 1.0)");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
result = SDL_snprintf(text, sizeof(text), "%f", 1.0 + 1.0 / 3.0);
predicted = SDL_snprintf(NULL, 0, "%f", 1.0 + 1.0 / 3.0);
expected = "1.333333";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0 + 1.0 / 3.0)");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
result = SDL_snprintf(text, sizeof(text), "%f", 1.0 + 1.0 / 3.0);
predicted = SDL_snprintf(NULL, 0, "%f", 1.0 + 1.0 / 3.0);
expected = "1.333333";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0 + 1.0 / 3.0)");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
result = SDL_snprintf(text, sizeof(text), "%+f", 1.0 + 1.0 / 3.0);
predicted = SDL_snprintf(NULL, 0, "%+f", 1.0 + 1.0 / 3.0);
expected = "+1.333333";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%+f\", 1.0 + 1.0 / 3.0)");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
result = SDL_snprintf(text, sizeof(text), "%+f", 1.0 + 1.0 / 3.0);
predicted = SDL_snprintf(NULL, 0, "%+f", 1.0 + 1.0 / 3.0);
expected = "+1.333333";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%+f\", 1.0 + 1.0 / 3.0)");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
result = SDL_snprintf(text, sizeof(text), "%.2f", 1.0 + 1.0 / 3.0);
predicted = SDL_snprintf(NULL, 0, "%.2f", 1.0 + 1.0 / 3.0);
expected = "1.33";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%.2f\", 1.0 + 1.0 / 3.0)");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
result = SDL_snprintf(text, sizeof(text), "%.2f", 1.0 + 1.0 / 3.0);
predicted = SDL_snprintf(NULL, 0, "%.2f", 1.0 + 1.0 / 3.0);
expected = "1.33";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%.2f\", 1.0 + 1.0 / 3.0)");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
result = SDL_snprintf(text, sizeof(text), "%6.2f", 1.0 + 1.0 / 3.0);
predicted = SDL_snprintf(NULL, 0, "%6.2f", 1.0 + 1.0 / 3.0);
expected = " 1.33";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%6.2f\", 1.0 + 1.0 / 3.0)");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
result = SDL_snprintf(text, sizeof(text), "%6.2f", 1.0 + 1.0 / 3.0);
predicted = SDL_snprintf(NULL, 0, "%6.2f", 1.0 + 1.0 / 3.0);
expected = " 1.33";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%6.2f\", 1.0 + 1.0 / 3.0)");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
result = SDL_snprintf(text, sizeof(text), "%06.2f", 1.0 + 1.0 / 3.0);
predicted = SDL_snprintf(NULL, 0, "%06.2f", 1.0 + 1.0 / 3.0);
expected = "001.33";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%06.2f\", 1.0 + 1.0 / 3.0)");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
result = SDL_snprintf(text, sizeof(text), "%06.2f", 1.0 + 1.0 / 3.0);
predicted = SDL_snprintf(NULL, 0, "%06.2f", 1.0 + 1.0 / 3.0);
expected = "001.33";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%06.2f\", 1.0 + 1.0 / 3.0)");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
result = SDL_snprintf(text, 5, "%06.2f", 1.0 + 1.0 / 3.0);
expected = "001.";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%06.2f\", 1.0 + 1.0 / 3.0) with buffer size 5");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
SDLTest_AssertCheck(result == 6, "Check result value, expected: 6, got: %d", result);
result = SDL_snprintf(text, 5, "%06.2f", 1.0 + 1.0 / 3.0);
expected = "001.";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%06.2f\", 1.0 + 1.0 / 3.0) with buffer size 5");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
SDLTest_AssertCheck(result == 6, "Check result value, expected: 6, got: %d", result);
size = 64;
result = SDL_snprintf(text, sizeof(text), "%zu %s", size, "test");
expected = "64 test";
SDLTest_AssertPass("Call to SDL_snprintf(text, sizeof(text), \"%%zu %%s\", size, \"test\")");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
SDLTest_AssertCheck(result == 7, "Check result value, expected: 7, got: %d", result);
size = 64;
result = SDL_snprintf(text, sizeof(text), "%zu %s", size, "test");
expected = "64 test";
SDLTest_AssertPass("Call to SDL_snprintf(text, sizeof(text), \"%%zu %%s\", size, \"test\")");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
SDLTest_AssertCheck(result == 7, "Check result value, expected: 7, got: %d", result);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
#if defined(HAVE_WFORMAT) || defined(HAVE_WFORMAT_EXTRA_ARGS)
@@ -175,135 +173,134 @@ stdlib_snprintf(void *arg)
/**
* @brief Call to SDL_getenv and SDL_setenv
*/
int
stdlib_getsetenv(void *arg)
int stdlib_getsetenv(void *arg)
{
const int nameLen = 16;
char name[17];
int counter;
int result;
char * value1;
char * value2;
char * expected;
int overwrite;
char * text;
const int nameLen = 16;
char name[17];
int counter;
int result;
char *value1;
char *value2;
char *expected;
int overwrite;
char *text;
/* Create a random name. This tests SDL_getenv, since we need to */
/* make sure the variable is not set yet (it shouldn't). */
do {
for (counter = 0; counter < nameLen; counter++) {
name[counter] = (char)SDLTest_RandomIntegerInRange(65, 90);
}
name[nameLen] = '\0';
/* Create a random name. This tests SDL_getenv, since we need to */
/* make sure the variable is not set yet (it shouldn't). */
do {
for (counter = 0; counter < nameLen; counter++) {
name[counter] = (char)SDLTest_RandomIntegerInRange(65, 90);
}
name[nameLen] = '\0';
text = SDL_getenv(name);
SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
if (text != NULL) {
SDLTest_Log("Expected: NULL, Got: '%s' (%i)", text, (int)SDL_strlen(text));
}
} while (text != NULL);
/* Create random values to set */
value1 = SDLTest_RandomAsciiStringOfSize(10);
value2 = SDLTest_RandomAsciiStringOfSize(10);
/* Set value 1 without overwrite */
overwrite = 0;
expected = value1;
result = SDL_setenv(name, value1, overwrite);
SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value1, overwrite);
SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);
/* Check value */
text = SDL_getenv(name);
SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
if (text != NULL) {
SDLTest_Log("Expected: NULL, Got: '%s' (%i)", text, (int) SDL_strlen(text));
SDLTest_AssertCheck(
SDL_strcmp(text, expected) == 0,
"Verify returned text, expected: %s, got: %s",
expected,
text);
}
} while (text != NULL);
/* Create random values to set */
value1 = SDLTest_RandomAsciiStringOfSize(10);
value2 = SDLTest_RandomAsciiStringOfSize(10);
/* Set value 1 without overwrite */
overwrite = 0;
expected = value1;
result = SDL_setenv(name, value1, overwrite);
SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value1, overwrite);
SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);
/* Set value 2 with overwrite */
overwrite = 1;
expected = value2;
result = SDL_setenv(name, value2, overwrite);
SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value2, overwrite);
SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);
/* Check value */
text = SDL_getenv(name);
SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
if (text != NULL) {
SDLTest_AssertCheck(
SDL_strcmp(text, expected) == 0,
"Verify returned text, expected: %s, got: %s",
expected,
text);
}
/* Set value 2 with overwrite */
overwrite = 1;
expected = value2;
result = SDL_setenv(name, value2, overwrite);
SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value2, overwrite);
SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);
/* Check value */
text = SDL_getenv(name);
SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
if (text != NULL) {
SDLTest_AssertCheck(
SDL_strcmp(text, expected) == 0,
"Verify returned text, expected: %s, got: %s",
expected,
text);
}
/* Check value */
text = SDL_getenv(name);
SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
if (text != NULL) {
SDLTest_AssertCheck(
SDL_strcmp(text, expected) == 0,
"Verify returned text, expected: %s, got: %s",
expected,
text);
}
/* Set value 1 without overwrite */
overwrite = 0;
expected = value2;
result = SDL_setenv(name, value1, overwrite);
SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value1, overwrite);
SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);
/* Set value 1 without overwrite */
overwrite = 0;
expected = value2;
result = SDL_setenv(name, value1, overwrite);
SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value1, overwrite);
SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);
/* Check value */
text = SDL_getenv(name);
SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
if (text != NULL) {
SDLTest_AssertCheck(
SDL_strcmp(text, expected) == 0,
"Verify returned text, expected: %s, got: %s",
expected,
text);
}
/* Check value */
text = SDL_getenv(name);
SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
if (text != NULL) {
SDLTest_AssertCheck(
SDL_strcmp(text, expected) == 0,
"Verify returned text, expected: %s, got: %s",
expected,
text);
}
/* Set value 1 without overwrite */
overwrite = 1;
expected = value1;
result = SDL_setenv(name, value1, overwrite);
SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value1, overwrite);
SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);
/* Set value 1 without overwrite */
overwrite = 1;
expected = value1;
result = SDL_setenv(name, value1, overwrite);
SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value1, overwrite);
SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);
/* Check value */
text = SDL_getenv(name);
SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
if (text != NULL) {
SDLTest_AssertCheck(
SDL_strcmp(text, expected) == 0,
"Verify returned text, expected: %s, got: %s",
expected,
text);
}
/* Check value */
text = SDL_getenv(name);
SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
if (text != NULL) {
SDLTest_AssertCheck(
SDL_strcmp(text, expected) == 0,
"Verify returned text, expected: %s, got: %s",
expected,
text);
}
/* Negative cases */
for (overwrite=0; overwrite <= 1; overwrite++) {
result = SDL_setenv(NULL, value1, overwrite);
SDLTest_AssertPass("Call to SDL_setenv(NULL,'%s', %i)", value1, overwrite);
SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
result = SDL_setenv("", value1, overwrite);
SDLTest_AssertPass("Call to SDL_setenv('','%s', %i)", value1, overwrite);
SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
result = SDL_setenv("=", value1, overwrite);
SDLTest_AssertPass("Call to SDL_setenv('=','%s', %i)", value1, overwrite);
SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
result = SDL_setenv(name, NULL, overwrite);
SDLTest_AssertPass("Call to SDL_setenv('%s', NULL, %i)", name, overwrite);
SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
}
/* Negative cases */
for (overwrite = 0; overwrite <= 1; overwrite++) {
result = SDL_setenv(NULL, value1, overwrite);
SDLTest_AssertPass("Call to SDL_setenv(NULL,'%s', %i)", value1, overwrite);
SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
result = SDL_setenv("", value1, overwrite);
SDLTest_AssertPass("Call to SDL_setenv('','%s', %i)", value1, overwrite);
SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
result = SDL_setenv("=", value1, overwrite);
SDLTest_AssertPass("Call to SDL_setenv('=','%s', %i)", value1, overwrite);
SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
result = SDL_setenv(name, NULL, overwrite);
SDLTest_AssertPass("Call to SDL_setenv('%s', NULL, %i)", name, overwrite);
SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
}
/* Clean up */
SDL_free(value1);
SDL_free(value2);
return TEST_COMPLETED;
/* Clean up */
SDL_free(value1);
SDL_free(value2);
return TEST_COMPLETED;
}
#if defined(HAVE_WFORMAT) || defined(HAVE_WFORMAT_EXTRA_ARGS)
@@ -320,82 +317,81 @@ stdlib_getsetenv(void *arg)
* @brief Call to SDL_sscanf
*/
#undef SDL_sscanf
int
stdlib_sscanf(void *arg)
int stdlib_sscanf(void *arg)
{
int output;
int result;
int expected_output;
int expected_result;
short short_output, expected_short_output;
long long_output, expected_long_output;
long long long_long_output, expected_long_long_output;
size_t size_output, expected_size_output;
char text[128];
int output;
int result;
int expected_output;
int expected_result;
short short_output, expected_short_output;
long long_output, expected_long_output;
long long long_long_output, expected_long_long_output;
size_t size_output, expected_size_output;
char text[128];
expected_output = output = 123;
expected_result = -1;
result = SDL_sscanf("", "%i", &output);
SDLTest_AssertPass("Call to SDL_sscanf(\"\", \"%%i\", &output)");
SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
expected_output = output = 123;
expected_result = -1;
result = SDL_sscanf("", "%i", &output);
SDLTest_AssertPass("Call to SDL_sscanf(\"\", \"%%i\", &output)");
SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
expected_output = output = 123;
expected_result = 0;
result = SDL_sscanf("a", "%i", &output);
SDLTest_AssertPass("Call to SDL_sscanf(\"a\", \"%%i\", &output)");
SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
expected_output = output = 123;
expected_result = 0;
result = SDL_sscanf("a", "%i", &output);
SDLTest_AssertPass("Call to SDL_sscanf(\"a\", \"%%i\", &output)");
SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
output = 123;
expected_output = 2;
expected_result = 1;
result = SDL_sscanf("2", "%i", &output);
SDLTest_AssertPass("Call to SDL_sscanf(\"2\", \"%%i\", &output)");
SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
output = 123;
expected_output = 2;
expected_result = 1;
result = SDL_sscanf("2", "%i", &output);
SDLTest_AssertPass("Call to SDL_sscanf(\"2\", \"%%i\", &output)");
SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
output = 123;
expected_output = 0xa;
expected_result = 1;
result = SDL_sscanf("aa", "%1x", &output);
SDLTest_AssertPass("Call to SDL_sscanf(\"aa\", \"%%1x\", &output)");
SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
output = 123;
expected_output = 0xa;
expected_result = 1;
result = SDL_sscanf("aa", "%1x", &output);
SDLTest_AssertPass("Call to SDL_sscanf(\"aa\", \"%%1x\", &output)");
SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
#define SIZED_TEST_CASE(type, var, format_specifier) \
var##_output = 123; \
expected_##var##_output = (type)(((unsigned type)(~0)) >> 1); \
expected_result = 1; \
result = SDL_snprintf(text, sizeof(text), format_specifier, expected_##var##_output); \
result = SDL_sscanf(text, format_specifier, &var##_output); \
SDLTest_AssertPass("Call to SDL_sscanf(\"%s\", \"%s\", &output)", text, #format_specifier); \
SDLTest_AssertCheck(expected_##var##_output == var##_output, "Check output, expected: " format_specifier ", got: " format_specifier, expected_##var##_output, var##_output); \
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result); \
\
var##_output = 123; \
expected_##var##_output = ~(type)(((unsigned type)(~0)) >> 1); \
expected_result = 1; \
result = SDL_snprintf(text, sizeof(text), format_specifier, expected_##var##_output); \
result = SDL_sscanf(text, format_specifier, &var##_output); \
SDLTest_AssertPass("Call to SDL_sscanf(\"%s\", \"%s\", &output)", text, #format_specifier); \
SDLTest_AssertCheck(expected_##var##_output == var##_output, "Check output, expected: " format_specifier ", got: " format_specifier, expected_##var##_output, var##_output); \
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result); \
#define SIZED_TEST_CASE(type, var, format_specifier) \
var##_output = 123; \
expected_##var##_output = (type)(((unsigned type)(~0)) >> 1); \
expected_result = 1; \
result = SDL_snprintf(text, sizeof(text), format_specifier, expected_##var##_output); \
result = SDL_sscanf(text, format_specifier, &var##_output); \
SDLTest_AssertPass("Call to SDL_sscanf(\"%s\", \"%s\", &output)", text, #format_specifier); \
SDLTest_AssertCheck(expected_##var##_output == var##_output, "Check output, expected: " format_specifier ", got: " format_specifier, expected_##var##_output, var##_output); \
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result); \
\
var##_output = 123; \
expected_##var##_output = ~(type)(((unsigned type)(~0)) >> 1); \
expected_result = 1; \
result = SDL_snprintf(text, sizeof(text), format_specifier, expected_##var##_output); \
result = SDL_sscanf(text, format_specifier, &var##_output); \
SDLTest_AssertPass("Call to SDL_sscanf(\"%s\", \"%s\", &output)", text, #format_specifier); \
SDLTest_AssertCheck(expected_##var##_output == var##_output, "Check output, expected: " format_specifier ", got: " format_specifier, expected_##var##_output, var##_output); \
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
SIZED_TEST_CASE(short, short, "%hd")
SIZED_TEST_CASE(long, long, "%ld")
SIZED_TEST_CASE(long long, long_long, "%lld")
SIZED_TEST_CASE(short, short, "%hd")
SIZED_TEST_CASE(long, long, "%ld")
SIZED_TEST_CASE(long long, long_long, "%lld")
size_output = 123;
expected_size_output = (size_t)~0;
expected_result = 1;
result = SDL_snprintf(text, sizeof(text), "%zu", expected_size_output);
result = SDL_sscanf(text, "%zu", &size_output);
SDLTest_AssertPass("Call to SDL_sscanf(\"%s\", \"%%zu\", &output)", text);
SDLTest_AssertCheck(expected_size_output == size_output, "Check output, expected: %zu, got: %zu", expected_size_output, size_output);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
size_output = 123;
expected_size_output = (size_t)~0;
expected_result = 1;
result = SDL_snprintf(text, sizeof(text), "%zu", expected_size_output);
result = SDL_sscanf(text, "%zu", &size_output);
SDLTest_AssertPass("Call to SDL_sscanf(\"%s\", \"%%zu\", &output)", text);
SDLTest_AssertCheck(expected_size_output == size_output, "Check output, expected: %zu, got: %zu", expected_size_output, size_output);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
#if defined(HAVE_WFORMAT) || defined(HAVE_WFORMAT_EXTRA_ARGS)
@@ -403,11 +399,11 @@ stdlib_sscanf(void *arg)
#endif
#if defined(_WIN64)
# define SIZE_FORMAT "I64u"
#define SIZE_FORMAT "I64u"
#elif defined(__WIN32__)
# define SIZE_FORMAT "I32u"
#define SIZE_FORMAT "I32u"
#else
# define SIZE_FORMAT "zu"
#define SIZE_FORMAT "zu"
#endif
typedef struct
@@ -418,8 +414,7 @@ typedef struct
int status;
} overflow_test;
static const overflow_test multiplications[] =
{
static const overflow_test multiplications[] = {
{ 1, 1, 1, 0 },
{ 0, 0, 0, 0 },
{ SDL_SIZE_MAX, 0, 0, 0 },
@@ -432,8 +427,7 @@ static const overflow_test multiplications[] =
{ SDL_SIZE_MAX, SDL_SIZE_MAX, 0, -1 },
};
static const overflow_test additions[] =
{
static const overflow_test additions[] = {
{ 1, 1, 2, 0 },
{ 0, 0, 0, 0 },
{ SDL_SIZE_MAX, 0, SDL_SIZE_MAX, 0 },
@@ -448,142 +442,147 @@ static const overflow_test additions[] =
static int
stdlib_overflow(void *arg)
{
size_t i;
size_t useBuiltin;
size_t i;
size_t useBuiltin;
for (useBuiltin = 0; useBuiltin < 2; useBuiltin++) {
if (useBuiltin) {
SDLTest_Log("Using gcc/clang builtins if possible");
} else {
SDLTest_Log("Not using gcc/clang builtins");
}
for (useBuiltin = 0; useBuiltin < 2; useBuiltin++) {
if (useBuiltin) {
SDLTest_Log("Using gcc/clang builtins if possible");
} else {
SDLTest_Log("Not using gcc/clang builtins");
}
for (i = 0; i < SDL_arraysize(multiplications); i++) {
const overflow_test *t = &multiplications[i];
int status;
size_t result = ~t->result;
for (i = 0; i < SDL_arraysize(multiplications); i++) {
const overflow_test *t = &multiplications[i];
int status;
size_t result = ~t->result;
if (useBuiltin) {
status = SDL_size_mul_overflow(t->a, t->b, &result);
} else {
/* This disables the macro that tries to use a gcc/clang
* builtin, so we test the fallback implementation instead. */
status = (SDL_size_mul_overflow)(t->a, t->b, &result);
}
if (useBuiltin) {
status = SDL_size_mul_overflow(t->a, t->b, &result);
} else {
/* This disables the macro that tries to use a gcc/clang
* builtin, so we test the fallback implementation instead. */
status = (SDL_size_mul_overflow)(t->a, t->b, &result);
}
if (t->status == 0) {
SDLTest_AssertCheck(status == 0,
"(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should succeed",
t->a, t->b);
SDLTest_AssertCheck(result == t->result,
"(%" SIZE_FORMAT " * %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT,
t->a, t->b, t->result, result);
} else {
SDLTest_AssertCheck(status == -1,
"(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should fail",
t->a, t->b);
}
if (t->status == 0) {
SDLTest_AssertCheck(status == 0,
"(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should succeed",
t->a, t->b);
SDLTest_AssertCheck(result == t->result,
"(%" SIZE_FORMAT " * %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT,
t->a, t->b, t->result, result);
} else {
SDLTest_AssertCheck(status == -1,
"(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should fail",
t->a, t->b);
}
if (t->a == t->b) {
continue;
}
if (t->a == t->b) {
continue;
}
result = ~t->result;
result = ~t->result;
if (useBuiltin) {
status = SDL_size_mul_overflow(t->b, t->a, &result);
} else {
status = (SDL_size_mul_overflow)(t->b, t->a, &result);
}
if (useBuiltin) {
status = SDL_size_mul_overflow(t->b, t->a, &result);
} else {
status = (SDL_size_mul_overflow)(t->b, t->a, &result);
}
if (t->status == 0) {
SDLTest_AssertCheck(status == 0,
"(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should succeed",
t->b, t->a);
SDLTest_AssertCheck(result == t->result,
"(%" SIZE_FORMAT " * %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT,
t->b, t->a, t->result, result);
} else {
SDLTest_AssertCheck(status == -1,
"(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should fail",
t->b, t->a);
}
}
if (t->status == 0) {
SDLTest_AssertCheck(status == 0,
"(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should succeed",
t->b, t->a);
SDLTest_AssertCheck(result == t->result,
"(%" SIZE_FORMAT " * %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT,
t->b, t->a, t->result, result);
} else {
SDLTest_AssertCheck(status == -1,
"(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should fail",
t->b, t->a);
}
}
for (i = 0; i < SDL_arraysize(additions); i++) {
const overflow_test *t = &additions[i];
int status;
size_t result = ~t->result;
for (i = 0; i < SDL_arraysize(additions); i++) {
const overflow_test *t = &additions[i];
int status;
size_t result = ~t->result;
if (useBuiltin) {
status = SDL_size_add_overflow(t->a, t->b, &result);
} else {
status = (SDL_size_add_overflow)(t->a, t->b, &result);
}
if (useBuiltin) {
status = SDL_size_add_overflow(t->a, t->b, &result);
} else {
status = (SDL_size_add_overflow)(t->a, t->b, &result);
}
if (t->status == 0) {
SDLTest_AssertCheck(status == 0,
"(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should succeed",
t->a, t->b);
SDLTest_AssertCheck(result == t->result,
"(%" SIZE_FORMAT " + %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT,
t->a, t->b, t->result, result);
} else {
SDLTest_AssertCheck(status == -1,
"(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should fail",
t->a, t->b);
}
if (t->status == 0) {
SDLTest_AssertCheck(status == 0,
"(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should succeed",
t->a, t->b);
SDLTest_AssertCheck(result == t->result,
"(%" SIZE_FORMAT " + %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT,
t->a, t->b, t->result, result);
} else {
SDLTest_AssertCheck(status == -1,
"(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should fail",
t->a, t->b);
}
if (t->a == t->b) {
continue;
}
if (t->a == t->b) {
continue;
}
result = ~t->result;
result = ~t->result;
if (useBuiltin) {
status = SDL_size_add_overflow(t->b, t->a, &result);
} else {
status = (SDL_size_add_overflow)(t->b, t->a, &result);
}
if (useBuiltin) {
status = SDL_size_add_overflow(t->b, t->a, &result);
} else {
status = (SDL_size_add_overflow)(t->b, t->a, &result);
}
if (t->status == 0) {
SDLTest_AssertCheck(status == 0,
"(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should succeed",
t->b, t->a);
SDLTest_AssertCheck(result == t->result,
"(%" SIZE_FORMAT " + %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT,
t->b, t->a, t->result, result);
} else {
SDLTest_AssertCheck(status == -1,
"(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should fail",
t->b, t->a);
}
}
}
if (t->status == 0) {
SDLTest_AssertCheck(status == 0,
"(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should succeed",
t->b, t->a);
SDLTest_AssertCheck(result == t->result,
"(%" SIZE_FORMAT " + %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT,
t->b, t->a, t->result, result);
} else {
SDLTest_AssertCheck(status == -1,
"(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should fail",
t->b, t->a);
}
}
}
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Standard C routine test cases */
static const SDLTest_TestCaseReference stdlibTest1 =
{ (SDLTest_TestCaseFp)stdlib_strlcpy, "stdlib_strlcpy", "Call to SDL_strlcpy", TEST_ENABLED };
static const SDLTest_TestCaseReference stdlibTest1 = {
(SDLTest_TestCaseFp)stdlib_strlcpy, "stdlib_strlcpy", "Call to SDL_strlcpy", TEST_ENABLED
};
static const SDLTest_TestCaseReference stdlibTest2 =
{ (SDLTest_TestCaseFp)stdlib_snprintf, "stdlib_snprintf", "Call to SDL_snprintf", TEST_ENABLED };
static const SDLTest_TestCaseReference stdlibTest2 = {
(SDLTest_TestCaseFp)stdlib_snprintf, "stdlib_snprintf", "Call to SDL_snprintf", TEST_ENABLED
};
static const SDLTest_TestCaseReference stdlibTest3 =
{ (SDLTest_TestCaseFp)stdlib_getsetenv, "stdlib_getsetenv", "Call to SDL_getenv and SDL_setenv", TEST_ENABLED };
static const SDLTest_TestCaseReference stdlibTest3 = {
(SDLTest_TestCaseFp)stdlib_getsetenv, "stdlib_getsetenv", "Call to SDL_getenv and SDL_setenv", TEST_ENABLED
};
static const SDLTest_TestCaseReference stdlibTest4 =
{ (SDLTest_TestCaseFp)stdlib_sscanf, "stdlib_sscanf", "Call to SDL_sscanf", TEST_ENABLED };
static const SDLTest_TestCaseReference stdlibTest4 = {
(SDLTest_TestCaseFp)stdlib_sscanf, "stdlib_sscanf", "Call to SDL_sscanf", TEST_ENABLED
};
static const SDLTest_TestCaseReference stdlibTestOverflow =
{ stdlib_overflow, "stdlib_overflow", "Overflow detection", TEST_ENABLED };
static const SDLTest_TestCaseReference stdlibTestOverflow = {
stdlib_overflow, "stdlib_overflow", "Overflow detection", TEST_ENABLED
};
/* Sequence of Standard C routine test cases */
static const SDLTest_TestCaseReference *stdlibTests[] = {
static const SDLTest_TestCaseReference *stdlibTests[] = {
&stdlibTest1,
&stdlibTest2,
&stdlibTest3,

View File

@@ -32,7 +32,7 @@ extern SDLTest_TestSuiteReference timerTestSuite;
extern SDLTest_TestSuiteReference videoTestSuite;
/* All test suites */
SDLTest_TestSuiteReference *testSuites[] = {
SDLTest_TestSuiteReference *testSuites[] = {
&audioTestSuite,
&clipboardTestSuite,
&eventsTestSuite,

View File

@@ -29,14 +29,13 @@ static SDL_Surface *testSurface = NULL;
/* Helper functions for the test cases */
#define TEST_SURFACE_WIDTH testSurface->w
#define TEST_SURFACE_WIDTH testSurface->w
#define TEST_SURFACE_HEIGHT testSurface->h
/* Fixture */
/* Create a 32-bit writable surface for blitting tests */
void
_surfaceSetUp(void *arg)
void _surfaceSetUp(void *arg)
{
int result;
SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
@@ -58,17 +57,16 @@ _surfaceSetUp(void *arg)
testSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, referenceSurface->w, referenceSurface->h, 32, rmask, gmask, bmask, amask);
SDLTest_AssertCheck(testSurface != NULL, "Check that testSurface is not NULL");
if (testSurface != NULL) {
/* Disable blend mode for target surface */
result = SDL_SetSurfaceBlendMode(testSurface, blendMode);
SDLTest_AssertCheck(result == 0, "Validate result from SDL_SetSurfaceBlendMode, expected: 0, got: %i", result);
result = SDL_GetSurfaceBlendMode(testSurface, &currentBlendMode);
SDLTest_AssertCheck(result == 0, "Validate result from SDL_GetSurfaceBlendMode, expected: 0, got: %i", result);
SDLTest_AssertCheck(currentBlendMode == blendMode, "Validate blendMode, expected: %i, got: %i", blendMode, currentBlendMode);
/* Disable blend mode for target surface */
result = SDL_SetSurfaceBlendMode(testSurface, blendMode);
SDLTest_AssertCheck(result == 0, "Validate result from SDL_SetSurfaceBlendMode, expected: 0, got: %i", result);
result = SDL_GetSurfaceBlendMode(testSurface, &currentBlendMode);
SDLTest_AssertCheck(result == 0, "Validate result from SDL_GetSurfaceBlendMode, expected: 0, got: %i", result);
SDLTest_AssertCheck(currentBlendMode == blendMode, "Validate blendMode, expected: %i, got: %i", blendMode, currentBlendMode);
}
}
void
_surfaceTearDown(void *arg)
void _surfaceTearDown(void *arg)
{
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
@@ -85,9 +83,9 @@ void _clearTestSurface()
Uint32 color;
/* Clear surface. */
color = SDL_MapRGBA( testSurface->format, 0, 0, 0, 0);
color = SDL_MapRGBA(testSurface->format, 0, 0, 0, 0);
SDLTest_AssertPass("Call to SDL_MapRGBA()");
ret = SDL_FillRect( testSurface, NULL, color);
ret = SDL_FillRect(testSurface, NULL, color);
SDLTest_AssertPass("Call to SDL_FillRect()");
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_FillRect, expected: 0, got: %i", ret);
}
@@ -121,23 +119,23 @@ void _testBlitBlendMode(int mode)
return;
}
/* Reset alpha modulation */
/* Reset alpha modulation */
ret = SDL_SetSurfaceAlphaMod(face, 255);
SDLTest_AssertPass("Call to SDL_SetSurfaceAlphaMod()");
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceAlphaMod(), expected: 0, got: %i", ret);
/* Reset color modulation */
/* Reset color modulation */
ret = SDL_SetSurfaceColorMod(face, 255, 255, 255);
SDLTest_AssertPass("Call to SDL_SetSurfaceColorMod()");
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceColorMod(), expected: 0, got: %i", ret);
/* Reset color key */
/* Reset color key */
ret = SDL_SetColorKey(face, SDL_FALSE, 0);
SDLTest_AssertPass("Call to SDL_SetColorKey()");
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey(), expected: 0, got: %i", ret);
/* Clear the test surface */
_clearTestSurface();
_clearTestSurface();
/* Target rect size */
rect.w = face->w;
@@ -149,7 +147,7 @@ void _testBlitBlendMode(int mode)
/* Optionally set blend mode. */
if (mode >= 0) {
ret = SDL_SetSurfaceBlendMode( face, (SDL_BlendMode)mode );
ret = SDL_SetSurfaceBlendMode(face, (SDL_BlendMode)mode);
SDLTest_AssertPass("Call to SDL_SetSurfaceBlendMode()");
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceBlendMode(..., %i), expected: 0, got: %i", mode, ret);
}
@@ -159,50 +157,50 @@ void _testBlitBlendMode(int mode)
checkFailCount2 = 0;
checkFailCount3 = 0;
checkFailCount4 = 0;
for (j=0; j <= nj; j+=4) {
for (i=0; i <= ni; i+=4) {
if (mode == -2) {
/* Set color mod. */
ret = SDL_SetSurfaceColorMod( face, (255/nj)*j, (255/ni)*i, (255/nj)*j );
if (ret != 0) {
checkFailCount2++;
for (j = 0; j <= nj; j += 4) {
for (i = 0; i <= ni; i += 4) {
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) {
/* Set alpha mod. */
ret = SDL_SetSurfaceAlphaMod(face, (255 / ni) * i);
if (ret != 0) {
checkFailCount3++;
}
} else if (mode == -4) {
/* Crazy blending mode magic. */
nmode = (i / 4 * j / 4) % 4;
if (nmode == 0) {
bmode = SDL_BLENDMODE_NONE;
} else if (nmode == 1) {
bmode = SDL_BLENDMODE_BLEND;
} else if (nmode == 2) {
bmode = SDL_BLENDMODE_ADD;
} else if (nmode == 3) {
bmode = SDL_BLENDMODE_MOD;
} else {
/* Should be impossible, but some static checkers are too imprecise and will complain */
SDLTest_LogError("Invalid: nmode=%d", nmode);
return;
}
ret = SDL_SetSurfaceBlendMode(face, bmode);
if (ret != 0) {
checkFailCount4++;
}
}
} else if (mode == -3) {
/* Set alpha mod. */
ret = SDL_SetSurfaceAlphaMod( face, (255/ni)*i );
/* Blitting. */
rect.x = i;
rect.y = j;
ret = SDL_BlitSurface(face, NULL, testSurface, &rect);
if (ret != 0) {
checkFailCount3++;
}
} else if (mode == -4) {
/* Crazy blending mode magic. */
nmode = (i/4*j/4) % 4;
if (nmode==0) {
bmode = SDL_BLENDMODE_NONE;
} else if (nmode==1) {
bmode = SDL_BLENDMODE_BLEND;
} else if (nmode==2) {
bmode = SDL_BLENDMODE_ADD;
} else if (nmode==3) {
bmode = SDL_BLENDMODE_MOD;
} else {
/* Should be impossible, but some static checkers are too imprecise and will complain */
SDLTest_LogError("Invalid: nmode=%d", nmode);
return;
}
ret = SDL_SetSurfaceBlendMode( face, bmode );
if (ret != 0) {
checkFailCount4++;
checkFailCount1++;
}
}
/* Blitting. */
rect.x = i;
rect.y = j;
ret = SDL_BlitSurface( face, NULL, testSurface, &rect );
if (ret != 0) {
checkFailCount1++;
}
}
}
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_BlitSurface, expected: 0, got: %i", checkFailCount1);
SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetSurfaceColorMod, expected: 0, got: %i", checkFailCount2);
@@ -215,8 +213,7 @@ void _testBlitBlendMode(int mode)
}
/* Helper to check that a file exists */
void
_AssertFileExist(const char *filename)
void _AssertFileExist(const char *filename)
{
struct stat st;
int ret = stat(filename, &st);
@@ -224,14 +221,12 @@ _AssertFileExist(const char *filename)
SDLTest_AssertCheck(ret == 0, "Verify file '%s' exists", filename);
}
/* Test case functions */
/**
* @brief Tests sprite saving and loading
*/
int
surface_testSaveLoadBitmap(void *arg)
int surface_testSaveLoadBitmap(void *arg)
{
int ret;
const char *sampleFilename = "testSaveLoadBitmap.bmp";
@@ -278,8 +273,7 @@ surface_testSaveLoadBitmap(void *arg)
/* !
* Tests surface conversion.
*/
int
surface_testSurfaceConversion(void *arg)
int surface_testSurfaceConversion(void *arg)
{
SDL_Surface *rface = NULL, *face = NULL;
int ret = 0;
@@ -293,9 +287,9 @@ surface_testSurfaceConversion(void *arg)
/* Set transparent pixel as the pixel at (0,0) */
if (face->format->palette) {
ret = SDL_SetColorKey(face, SDL_RLEACCEL, *(Uint8 *) face->pixels);
SDLTest_AssertPass("Call to SDL_SetColorKey()");
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey, expected: 0, got: %i", ret);
ret = SDL_SetColorKey(face, SDL_RLEACCEL, *(Uint8 *)face->pixels);
SDLTest_AssertPass("Call to SDL_SetColorKey()");
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey, expected: 0, got: %i", ret);
}
/* Convert to 32 bit to compare. */
@@ -304,7 +298,7 @@ surface_testSurfaceConversion(void *arg)
SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_ConvertSurface is not NULL");
/* Compare surface. */
ret = SDLTest_CompareSurfaces( rface, face, 0 );
ret = SDLTest_CompareSurfaces(rface, face, 0);
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
@@ -316,12 +310,10 @@ surface_testSurfaceConversion(void *arg)
return TEST_COMPLETED;
}
/* !
* Tests surface conversion across all pixel formats.
*/
int
surface_testCompleteSurfaceConversion(void *arg)
int surface_testCompleteSurfaceConversion(void *arg)
{
Uint32 pixel_formats[] = {
SDL_PIXELFORMAT_INDEX8,
@@ -365,13 +357,13 @@ surface_testCompleteSurfaceConversion(void *arg)
/* Set transparent pixel as the pixel at (0,0) */
if (face->format->palette) {
ret = SDL_SetColorKey(face, SDL_RLEACCEL, *(Uint8 *) face->pixels);
SDLTest_AssertPass("Call to SDL_SetColorKey()");
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey, expected: 0, got: %i", ret);
ret = SDL_SetColorKey(face, SDL_RLEACCEL, *(Uint8 *)face->pixels);
SDLTest_AssertPass("Call to SDL_SetColorKey()");
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey, expected: 0, got: %i", ret);
}
for ( i = 0; i < SDL_arraysize(pixel_formats); ++i ) {
for ( j = 0; j < SDL_arraysize(pixel_formats); ++j ) {
for (i = 0; i < SDL_arraysize(pixel_formats); ++i) {
for (j = 0; j < SDL_arraysize(pixel_formats); ++j) {
fmt1 = SDL_AllocFormat(pixel_formats[i]);
SDL_assert(fmt1 != NULL);
cvt1 = SDL_ConvertSurface(face, fmt1, 0);
@@ -390,7 +382,7 @@ surface_testCompleteSurfaceConversion(void *arg)
SDL_assert(final != NULL);
/* Compare surface. */
ret = SDLTest_CompareSurfaces( face, final, 0 );
ret = SDLTest_CompareSurfaces(face, final, 0);
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
SDL_FreeSurface(final);
}
@@ -403,17 +395,15 @@ surface_testCompleteSurfaceConversion(void *arg)
}
/* Clean up. */
SDL_FreeSurface( face );
SDL_FreeSurface(face);
return TEST_COMPLETED;
}
/**
* @brief Tests sprite loading. A failure case.
*/
int
surface_testLoadFailure(void *arg)
int surface_testLoadFailure(void *arg)
{
SDL_Surface *face = SDL_LoadBMP("nonexistant.bmp");
SDLTest_AssertCheck(face == NULL, "SDL_CreateLoadBmp");
@@ -424,191 +414,181 @@ surface_testLoadFailure(void *arg)
/**
* @brief Tests some blitting routines.
*/
int
surface_testBlit(void *arg)
int surface_testBlit(void *arg)
{
int ret;
SDL_Surface *compareSurface;
int ret;
SDL_Surface *compareSurface;
/* Basic blitting */
_testBlitBlendMode(-1);
/* Basic blitting */
_testBlitBlendMode(-1);
/* Verify result by comparing surfaces */
compareSurface = SDLTest_ImageBlit();
ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Verify result by comparing surfaces */
compareSurface = SDLTest_ImageBlit();
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0);
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
SDL_FreeSurface(compareSurface);
/* Clean up. */
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
* @brief Tests some blitting routines with color mod
*/
int
surface_testBlitColorMod(void *arg)
int surface_testBlitColorMod(void *arg)
{
int ret;
SDL_Surface *compareSurface;
int ret;
SDL_Surface *compareSurface;
/* Basic blitting with color mod */
_testBlitBlendMode(-2);
/* Basic blitting with color mod */
_testBlitBlendMode(-2);
/* Verify result by comparing surfaces */
compareSurface = SDLTest_ImageBlitColor();
ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Verify result by comparing surfaces */
compareSurface = SDLTest_ImageBlitColor();
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0);
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
SDL_FreeSurface(compareSurface);
/* Clean up. */
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
* @brief Tests some blitting routines with alpha mod
*/
int
surface_testBlitAlphaMod(void *arg)
int surface_testBlitAlphaMod(void *arg)
{
int ret;
SDL_Surface *compareSurface;
int ret;
SDL_Surface *compareSurface;
/* Basic blitting with alpha mod */
_testBlitBlendMode(-3);
/* Basic blitting with alpha mod */
_testBlitBlendMode(-3);
/* Verify result by comparing surfaces */
compareSurface = SDLTest_ImageBlitAlpha();
ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Verify result by comparing surfaces */
compareSurface = SDLTest_ImageBlitAlpha();
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0);
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
SDL_FreeSurface(compareSurface);
/* Clean up. */
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
}
/**
* @brief Tests some more blitting routines.
*/
int
surface_testBlitBlendNone(void *arg)
{
int ret;
SDL_Surface *compareSurface;
/* Basic blitting */
_testBlitBlendMode(SDL_BLENDMODE_NONE);
/* Verify result by comparing surfaces */
compareSurface = SDLTest_ImageBlitBlendNone();
ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
* @brief Tests some more blitting routines.
*/
int
surface_testBlitBlendBlend(void *arg)
int surface_testBlitBlendNone(void *arg)
{
int ret;
SDL_Surface *compareSurface;
int ret;
SDL_Surface *compareSurface;
/* Blend blitting */
_testBlitBlendMode(SDL_BLENDMODE_BLEND);
/* Basic blitting */
_testBlitBlendMode(SDL_BLENDMODE_NONE);
/* Verify result by comparing surfaces */
compareSurface = SDLTest_ImageBlitBlend();
ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Verify result by comparing surfaces */
compareSurface = SDLTest_ImageBlitBlendNone();
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0);
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
SDL_FreeSurface(compareSurface);
/* Clean up. */
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
* @brief Tests some more blitting routines.
*/
int
surface_testBlitBlendAdd(void *arg)
int surface_testBlitBlendBlend(void *arg)
{
int ret;
SDL_Surface *compareSurface;
int ret;
SDL_Surface *compareSurface;
/* Add blitting */
_testBlitBlendMode(SDL_BLENDMODE_ADD);
/* Blend blitting */
_testBlitBlendMode(SDL_BLENDMODE_BLEND);
/* Verify result by comparing surfaces */
compareSurface = SDLTest_ImageBlitBlendAdd();
ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Verify result by comparing surfaces */
compareSurface = SDLTest_ImageBlitBlend();
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0);
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
SDL_FreeSurface(compareSurface);
/* Clean up. */
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
* @brief Tests some more blitting routines.
*/
int
surface_testBlitBlendMod(void *arg)
int surface_testBlitBlendAdd(void *arg)
{
int ret;
SDL_Surface *compareSurface;
int ret;
SDL_Surface *compareSurface;
/* Mod blitting */
_testBlitBlendMode(SDL_BLENDMODE_MOD);
/* Add blitting */
_testBlitBlendMode(SDL_BLENDMODE_ADD);
/* Verify result by comparing surfaces */
compareSurface = SDLTest_ImageBlitBlendMod();
ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Verify result by comparing surfaces */
compareSurface = SDLTest_ImageBlitBlendAdd();
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0);
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
SDL_FreeSurface(compareSurface);
/* Clean up. */
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
* @brief Tests some more blitting routines.
*/
int surface_testBlitBlendMod(void *arg)
{
int ret;
SDL_Surface *compareSurface;
/* Mod blitting */
_testBlitBlendMode(SDL_BLENDMODE_MOD);
/* Verify result by comparing surfaces */
compareSurface = SDLTest_ImageBlitBlendMod();
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0);
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
}
/**
* @brief Tests some more blitting routines with loop
*/
int
surface_testBlitBlendLoop(void *arg) {
int surface_testBlitBlendLoop(void *arg)
{
int ret;
SDL_Surface *compareSurface;
int ret;
SDL_Surface *compareSurface;
/* All blitting modes */
_testBlitBlendMode(-4);
/* All blitting modes */
_testBlitBlendMode(-4);
/* Verify result by comparing surfaces */
compareSurface = SDLTest_ImageBlitBlendAll();
ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Verify result by comparing surfaces */
compareSurface = SDLTest_ImageBlitBlendAll();
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0);
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
/* Clean up. */
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
}
int
surface_testOverflow(void *arg)
int surface_testOverflow(void *arg)
{
char buf[1024];
const char *expectedError;
@@ -752,7 +732,7 @@ surface_testOverflow(void *arg)
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
if (sizeof (size_t) == 4 && sizeof (int) >= 4) {
if (sizeof(size_t) == 4 && sizeof(int) >= 4) {
expectedError = "Out of memory";
surface = SDL_CreateRGBSurfaceWithFormat(0, SDL_MAX_SINT32, 1, 8, SDL_PIXELFORMAT_INDEX8);
SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width + alignment");
@@ -780,50 +760,63 @@ surface_testOverflow(void *arg)
/* ================= Test References ================== */
/* Surface test cases */
static const SDLTest_TestCaseReference surfaceTest1 =
{ (SDLTest_TestCaseFp)surface_testSaveLoadBitmap, "surface_testSaveLoadBitmap", "Tests sprite saving and loading.", TEST_ENABLED};
static const SDLTest_TestCaseReference surfaceTest1 = {
(SDLTest_TestCaseFp)surface_testSaveLoadBitmap, "surface_testSaveLoadBitmap", "Tests sprite saving and loading.", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTest2 =
{ (SDLTest_TestCaseFp)surface_testBlit, "surface_testBlit", "Tests basic blitting.", TEST_ENABLED};
static const SDLTest_TestCaseReference surfaceTest2 = {
(SDLTest_TestCaseFp)surface_testBlit, "surface_testBlit", "Tests basic blitting.", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTest3 =
{ (SDLTest_TestCaseFp)surface_testBlitBlendNone, "surface_testBlitBlendNone", "Tests blitting routines with none blending mode.", TEST_ENABLED};
static const SDLTest_TestCaseReference surfaceTest3 = {
(SDLTest_TestCaseFp)surface_testBlitBlendNone, "surface_testBlitBlendNone", "Tests blitting routines with none blending mode.", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTest4 =
{ (SDLTest_TestCaseFp)surface_testLoadFailure, "surface_testLoadFailure", "Tests sprite loading. A failure case.", TEST_ENABLED};
static const SDLTest_TestCaseReference surfaceTest4 = {
(SDLTest_TestCaseFp)surface_testLoadFailure, "surface_testLoadFailure", "Tests sprite loading. A failure case.", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTest5 =
{ (SDLTest_TestCaseFp)surface_testSurfaceConversion, "surface_testSurfaceConversion", "Tests surface conversion.", TEST_ENABLED};
static const SDLTest_TestCaseReference surfaceTest5 = {
(SDLTest_TestCaseFp)surface_testSurfaceConversion, "surface_testSurfaceConversion", "Tests surface conversion.", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTest6 =
{ (SDLTest_TestCaseFp)surface_testCompleteSurfaceConversion, "surface_testCompleteSurfaceConversion", "Tests surface conversion across all pixel formats", TEST_ENABLED};
static const SDLTest_TestCaseReference surfaceTest6 = {
(SDLTest_TestCaseFp)surface_testCompleteSurfaceConversion, "surface_testCompleteSurfaceConversion", "Tests surface conversion across all pixel formats", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTest7 =
{ (SDLTest_TestCaseFp)surface_testBlitColorMod, "surface_testBlitColorMod", "Tests some blitting routines with color mod.", TEST_ENABLED};
static const SDLTest_TestCaseReference surfaceTest7 = {
(SDLTest_TestCaseFp)surface_testBlitColorMod, "surface_testBlitColorMod", "Tests some blitting routines with color mod.", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTest8 =
{ (SDLTest_TestCaseFp)surface_testBlitAlphaMod, "surface_testBlitAlphaMod", "Tests some blitting routines with alpha mod.", TEST_ENABLED};
static const SDLTest_TestCaseReference surfaceTest8 = {
(SDLTest_TestCaseFp)surface_testBlitAlphaMod, "surface_testBlitAlphaMod", "Tests some blitting routines with alpha mod.", TEST_ENABLED
};
/* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
static const SDLTest_TestCaseReference surfaceTest9 =
{ (SDLTest_TestCaseFp)surface_testBlitBlendLoop, "surface_testBlitBlendLoop", "Test blitting routines with various blending modes", TEST_DISABLED};
static const SDLTest_TestCaseReference surfaceTest9 = {
(SDLTest_TestCaseFp)surface_testBlitBlendLoop, "surface_testBlitBlendLoop", "Test blitting routines with various blending modes", TEST_DISABLED
};
/* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
static const SDLTest_TestCaseReference surfaceTest10 =
{ (SDLTest_TestCaseFp)surface_testBlitBlendBlend, "surface_testBlitBlendBlend", "Tests blitting routines with blend blending mode.", TEST_DISABLED};
static const SDLTest_TestCaseReference surfaceTest10 = {
(SDLTest_TestCaseFp)surface_testBlitBlendBlend, "surface_testBlitBlendBlend", "Tests blitting routines with blend blending mode.", TEST_DISABLED
};
/* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
static const SDLTest_TestCaseReference surfaceTest11 =
{ (SDLTest_TestCaseFp)surface_testBlitBlendAdd, "surface_testBlitBlendAdd", "Tests blitting routines with add blending mode.", TEST_DISABLED};
static const SDLTest_TestCaseReference surfaceTest11 = {
(SDLTest_TestCaseFp)surface_testBlitBlendAdd, "surface_testBlitBlendAdd", "Tests blitting routines with add blending mode.", TEST_DISABLED
};
static const SDLTest_TestCaseReference surfaceTest12 =
{ (SDLTest_TestCaseFp)surface_testBlitBlendMod, "surface_testBlitBlendMod", "Tests blitting routines with mod blending mode.", TEST_ENABLED};
static const SDLTest_TestCaseReference surfaceTest12 = {
(SDLTest_TestCaseFp)surface_testBlitBlendMod, "surface_testBlitBlendMod", "Tests blitting routines with mod blending mode.", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTestOverflow =
{ surface_testOverflow, "surface_testOverflow", "Test overflow detection.", TEST_ENABLED};
static const SDLTest_TestCaseReference surfaceTestOverflow = {
surface_testOverflow, "surface_testOverflow", "Test overflow detection.", TEST_ENABLED
};
/* Sequence of Surface test cases */
static const SDLTest_TestCaseReference *surfaceTests[] = {
static const SDLTest_TestCaseReference *surfaceTests[] = {
&surfaceTest1, &surfaceTest2, &surfaceTest3, &surfaceTest4, &surfaceTest5,
&surfaceTest6, &surfaceTest7, &surfaceTest8, &surfaceTest9, &surfaceTest10,
&surfaceTest11, &surfaceTest12, &surfaceTestOverflow, NULL

View File

@@ -13,19 +13,18 @@
/**
* @brief Call to SDL_GetWindowWMInfo
*/
int
syswm_getWindowWMInfo(void *arg)
int syswm_getWindowWMInfo(void *arg)
{
SDL_bool result;
SDL_Window *window;
SDL_SysWMinfo info;
window = SDL_CreateWindow("", 0, 0, 0, 0, SDL_WINDOW_HIDDEN);
SDLTest_AssertPass("Call to SDL_CreateWindow()");
SDLTest_AssertCheck(window != NULL, "Check that value returned from SDL_CreateWindow is not NULL");
if (window == NULL) {
return TEST_ABORTED;
}
window = SDL_CreateWindow("", 0, 0, 0, 0, SDL_WINDOW_HIDDEN);
SDLTest_AssertPass("Call to SDL_CreateWindow()");
SDLTest_AssertCheck(window != NULL, "Check that value returned from SDL_CreateWindow is not NULL");
if (window == NULL) {
return TEST_ABORTED;
}
/* Initialize info structure with SDL version info */
SDL_VERSION(&info.version);
@@ -35,20 +34,21 @@ syswm_getWindowWMInfo(void *arg)
SDLTest_AssertPass("Call to SDL_GetWindowWMInfo()");
SDLTest_Log((result == SDL_TRUE) ? "Got window information" : "Couldn't get window information");
SDL_DestroyWindow(window);
SDLTest_AssertPass("Call to SDL_DestroyWindow()");
SDL_DestroyWindow(window);
SDLTest_AssertPass("Call to SDL_DestroyWindow()");
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* SysWM test cases */
static const SDLTest_TestCaseReference syswmTest1 =
{ (SDLTest_TestCaseFp)syswm_getWindowWMInfo, "syswm_getWindowWMInfo", "Call to SDL_GetWindowWMInfo", TEST_ENABLED };
static const SDLTest_TestCaseReference syswmTest1 = {
(SDLTest_TestCaseFp)syswm_getWindowWMInfo, "syswm_getWindowWMInfo", "Call to SDL_GetWindowWMInfo", TEST_ENABLED
};
/* Sequence of SysWM test cases */
static const SDLTest_TestCaseReference *syswmTests[] = {
static const SDLTest_TestCaseReference *syswmTests[] = {
&syswmTest1, NULL
};

View File

@@ -18,16 +18,15 @@ int _timerCallbackCalled = 0;
/* Fixture */
void
_timerSetUp(void *arg)
void _timerSetUp(void *arg)
{
/* Start SDL timer subsystem */
int ret = SDL_InitSubSystem( SDL_INIT_TIMER );
SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_TIMER)");
SDLTest_AssertCheck(ret==0, "Check result from SDL_InitSubSystem(SDL_INIT_TIMER)");
int ret = SDL_InitSubSystem(SDL_INIT_TIMER);
SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_TIMER)");
SDLTest_AssertCheck(ret == 0, "Check result from SDL_InitSubSystem(SDL_INIT_TIMER)");
if (ret != 0) {
SDLTest_LogError("%s", SDL_GetError());
}
SDLTest_LogError("%s", SDL_GetError());
}
}
/* Test case functions */
@@ -35,160 +34,160 @@ _timerSetUp(void *arg)
/**
* @brief Call to SDL_GetPerformanceCounter
*/
int
timer_getPerformanceCounter(void *arg)
int timer_getPerformanceCounter(void *arg)
{
Uint64 result;
Uint64 result;
result = SDL_GetPerformanceCounter();
SDLTest_AssertPass("Call to SDL_GetPerformanceCounter()");
SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %"SDL_PRIu64, result);
result = SDL_GetPerformanceCounter();
SDLTest_AssertPass("Call to SDL_GetPerformanceCounter()");
SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %" SDL_PRIu64, result);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
* @brief Call to SDL_GetPerformanceFrequency
*/
int
timer_getPerformanceFrequency(void *arg)
int timer_getPerformanceFrequency(void *arg)
{
Uint64 result;
Uint64 result;
result = SDL_GetPerformanceFrequency();
SDLTest_AssertPass("Call to SDL_GetPerformanceFrequency()");
SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %"SDL_PRIu64, result);
result = SDL_GetPerformanceFrequency();
SDLTest_AssertPass("Call to SDL_GetPerformanceFrequency()");
SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %" SDL_PRIu64, result);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
* @brief Call to SDL_Delay and SDL_GetTicks
*/
int
timer_delayAndGetTicks(void *arg)
int timer_delayAndGetTicks(void *arg)
{
const Uint32 testDelay = 100;
const Uint32 marginOfError = 25;
Uint32 result;
Uint32 result2;
Uint32 difference;
const Uint32 testDelay = 100;
const Uint32 marginOfError = 25;
Uint32 result;
Uint32 result2;
Uint32 difference;
/* Zero delay */
SDL_Delay(0);
SDLTest_AssertPass("Call to SDL_Delay(0)");
/* Zero delay */
SDL_Delay(0);
SDLTest_AssertPass("Call to SDL_Delay(0)");
/* Non-zero delay */
SDL_Delay(1);
SDLTest_AssertPass("Call to SDL_Delay(1)");
/* Non-zero delay */
SDL_Delay(1);
SDLTest_AssertPass("Call to SDL_Delay(1)");
SDL_Delay(SDLTest_RandomIntegerInRange(5, 15));
SDLTest_AssertPass("Call to SDL_Delay()");
SDL_Delay(SDLTest_RandomIntegerInRange(5, 15));
SDLTest_AssertPass("Call to SDL_Delay()");
/* Get ticks count - should be non-zero by now */
result = SDL_GetTicks();
SDLTest_AssertPass("Call to SDL_GetTicks()");
SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %" SDL_PRIu32, result);
/* Get ticks count - should be non-zero by now */
result = SDL_GetTicks();
SDLTest_AssertPass("Call to SDL_GetTicks()");
SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %" SDL_PRIu32, result);
/* Delay a bit longer and measure ticks and verify difference */
SDL_Delay(testDelay);
SDLTest_AssertPass("Call to SDL_Delay(%" SDL_PRIu32 ")", testDelay);
result2 = SDL_GetTicks();
SDLTest_AssertPass("Call to SDL_GetTicks()");
SDLTest_AssertCheck(result2 > 0, "Check result value, expected: >0, got: %" SDL_PRIu32, result2);
difference = result2 - result;
SDLTest_AssertCheck(difference > (testDelay - marginOfError), "Check difference, expected: >%" SDL_PRIu32 ", got: %" SDL_PRIu32, testDelay - marginOfError, difference);
SDLTest_AssertCheck(difference < (testDelay + marginOfError), "Check difference, expected: <%" SDL_PRIu32 ", got: %" SDL_PRIu32, testDelay + marginOfError, difference);
/* Delay a bit longer and measure ticks and verify difference */
SDL_Delay(testDelay);
SDLTest_AssertPass("Call to SDL_Delay(%" SDL_PRIu32 ")", testDelay);
result2 = SDL_GetTicks();
SDLTest_AssertPass("Call to SDL_GetTicks()");
SDLTest_AssertCheck(result2 > 0, "Check result value, expected: >0, got: %" SDL_PRIu32, result2);
difference = result2 - result;
SDLTest_AssertCheck(difference > (testDelay - marginOfError), "Check difference, expected: >%" SDL_PRIu32 ", got: %" SDL_PRIu32, testDelay - marginOfError, difference);
SDLTest_AssertCheck(difference < (testDelay + marginOfError), "Check difference, expected: <%" SDL_PRIu32 ", got: %" SDL_PRIu32, testDelay + marginOfError, difference);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/* Test callback */
Uint32 SDLCALL _timerTestCallback(Uint32 interval, void *param)
{
_timerCallbackCalled = 1;
_timerCallbackCalled = 1;
if (_paramCheck != 0) {
SDLTest_AssertCheck(param != NULL, "Check param pointer, expected: non-NULL, got: %s", (param != NULL) ? "non-NULL" : "NULL");
if (param != NULL) {
SDLTest_AssertCheck(*(int *)param == _paramValue, "Check param value, expected: %i, got: %i", _paramValue, *(int *)param);
}
}
if (_paramCheck != 0) {
SDLTest_AssertCheck(param != NULL, "Check param pointer, expected: non-NULL, got: %s", (param != NULL) ? "non-NULL" : "NULL");
if (param != NULL) {
SDLTest_AssertCheck(*(int *)param == _paramValue, "Check param value, expected: %i, got: %i", _paramValue, *(int *)param);
}
}
return 0;
return 0;
}
/**
* @brief Call to SDL_AddTimer and SDL_RemoveTimer
*/
int
timer_addRemoveTimer(void *arg)
int timer_addRemoveTimer(void *arg)
{
SDL_TimerID id;
SDL_bool result;
int param;
SDL_TimerID id;
SDL_bool result;
int param;
/* Reset state */
_paramCheck = 0;
_timerCallbackCalled = 0;
/* Reset state */
_paramCheck = 0;
_timerCallbackCalled = 0;
/* Set timer with a long delay */
id = SDL_AddTimer(10000, _timerTestCallback, NULL);
SDLTest_AssertPass("Call to SDL_AddTimer(10000,...)");
SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %d", id);
/* Set timer with a long delay */
id = SDL_AddTimer(10000, _timerTestCallback, NULL);
SDLTest_AssertPass("Call to SDL_AddTimer(10000,...)");
SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %d", id);
/* Remove timer again and check that callback was not called */
result = SDL_RemoveTimer(id);
SDLTest_AssertPass("Call to SDL_RemoveTimer()");
SDLTest_AssertCheck(result == SDL_TRUE, "Check result value, expected: %i, got: %i", SDL_TRUE, result);
SDLTest_AssertCheck(_timerCallbackCalled == 0, "Check callback WAS NOT called, expected: 0, got: %i", _timerCallbackCalled);
/* Remove timer again and check that callback was not called */
result = SDL_RemoveTimer(id);
SDLTest_AssertPass("Call to SDL_RemoveTimer()");
SDLTest_AssertCheck(result == SDL_TRUE, "Check result value, expected: %i, got: %i", SDL_TRUE, result);
SDLTest_AssertCheck(_timerCallbackCalled == 0, "Check callback WAS NOT called, expected: 0, got: %i", _timerCallbackCalled);
/* Try to remove timer again (should be a NOOP) */
result = SDL_RemoveTimer(id);
SDLTest_AssertPass("Call to SDL_RemoveTimer()");
SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected: %i, got: %i", SDL_FALSE, result);
/* Try to remove timer again (should be a NOOP) */
result = SDL_RemoveTimer(id);
SDLTest_AssertPass("Call to SDL_RemoveTimer()");
SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected: %i, got: %i", SDL_FALSE, result);
/* Reset state */
param = SDLTest_RandomIntegerInRange(-1024, 1024);
_paramCheck = 1;
_paramValue = param;
_timerCallbackCalled = 0;
/* Reset state */
param = SDLTest_RandomIntegerInRange(-1024, 1024);
_paramCheck = 1;
_paramValue = param;
_timerCallbackCalled = 0;
/* Set timer with a short delay */
id = SDL_AddTimer(10, _timerTestCallback, (void *)&param);
SDLTest_AssertPass("Call to SDL_AddTimer(10, param)");
SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %d", id);
/* Set timer with a short delay */
id = SDL_AddTimer(10, _timerTestCallback, (void *)&param);
SDLTest_AssertPass("Call to SDL_AddTimer(10, param)");
SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %d", id);
/* Wait to let timer trigger callback */
SDL_Delay(100);
SDLTest_AssertPass("Call to SDL_Delay(100)");
/* Wait to let timer trigger callback */
SDL_Delay(100);
SDLTest_AssertPass("Call to SDL_Delay(100)");
/* Remove timer again and check that callback was called */
result = SDL_RemoveTimer(id);
SDLTest_AssertPass("Call to SDL_RemoveTimer()");
SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected: %i, got: %i", SDL_FALSE, result);
SDLTest_AssertCheck(_timerCallbackCalled == 1, "Check callback WAS called, expected: 1, got: %i", _timerCallbackCalled);
/* Remove timer again and check that callback was called */
result = SDL_RemoveTimer(id);
SDLTest_AssertPass("Call to SDL_RemoveTimer()");
SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected: %i, got: %i", SDL_FALSE, result);
SDLTest_AssertCheck(_timerCallbackCalled == 1, "Check callback WAS called, expected: 1, got: %i", _timerCallbackCalled);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Timer test cases */
static const SDLTest_TestCaseReference timerTest1 =
{ (SDLTest_TestCaseFp)timer_getPerformanceCounter, "timer_getPerformanceCounter", "Call to SDL_GetPerformanceCounter", TEST_ENABLED };
static const SDLTest_TestCaseReference timerTest1 = {
(SDLTest_TestCaseFp)timer_getPerformanceCounter, "timer_getPerformanceCounter", "Call to SDL_GetPerformanceCounter", TEST_ENABLED
};
static const SDLTest_TestCaseReference timerTest2 =
{ (SDLTest_TestCaseFp)timer_getPerformanceFrequency, "timer_getPerformanceFrequency", "Call to SDL_GetPerformanceFrequency", TEST_ENABLED };
static const SDLTest_TestCaseReference timerTest2 = {
(SDLTest_TestCaseFp)timer_getPerformanceFrequency, "timer_getPerformanceFrequency", "Call to SDL_GetPerformanceFrequency", TEST_ENABLED
};
static const SDLTest_TestCaseReference timerTest3 =
{ (SDLTest_TestCaseFp)timer_delayAndGetTicks, "timer_delayAndGetTicks", "Call to SDL_Delay and SDL_GetTicks", TEST_ENABLED };
static const SDLTest_TestCaseReference timerTest3 = {
(SDLTest_TestCaseFp)timer_delayAndGetTicks, "timer_delayAndGetTicks", "Call to SDL_Delay and SDL_GetTicks", TEST_ENABLED
};
static const SDLTest_TestCaseReference timerTest4 =
{ (SDLTest_TestCaseFp)timer_addRemoveTimer, "timer_addRemoveTimer", "Call to SDL_AddTimer and SDL_RemoveTimer", TEST_ENABLED };
static const SDLTest_TestCaseReference timerTest4 = {
(SDLTest_TestCaseFp)timer_addRemoveTimer, "timer_addRemoveTimer", "Call to SDL_AddTimer and SDL_RemoveTimer", TEST_ENABLED
};
/* Sequence of Timer test cases */
static const SDLTest_TestCaseReference *timerTests[] = {
static const SDLTest_TestCaseReference *timerTests[] = {
&timerTest1, &timerTest2, &timerTest3, &timerTest4, NULL
};

File diff suppressed because it is too large Load Diff

View File

@@ -23,7 +23,7 @@ int main(int argc, char **argv)
total = SDL_GetNumVideoDisplays();
for (i = 0; i < total; i++) {
SDL_Rect bounds = { -1,-1,-1,-1 }, usable = { -1,-1,-1,-1 };
SDL_Rect bounds = { -1, -1, -1, -1 }, usable = { -1, -1, -1, -1 };
SDL_GetDisplayBounds(i, &bounds);
SDL_GetDisplayUsableBounds(i, &usable);
SDL_Log("Display #%d ('%s'): bounds={(%d,%d),%dx%d}, usable={(%d,%d),%dx%d}",

View File

@@ -22,59 +22,58 @@
/* Stolen from the mailing list */
/* Creates a new mouse cursor from an XPM */
/* XPM */
static const char *arrow[] = {
/* width height num_colors chars_per_pixel */
" 32 32 3 1",
/* colors */
"X c #000000",
". c #ffffff",
" c None",
/* pixels */
"X ",
"XX ",
"X.X ",
"X..X ",
"X...X ",
"X....X ",
"X.....X ",
"X......X ",
"X.......X ",
"X........X ",
"X.....XXXXX ",
"X..X..X ",
"X.X X..X ",
"XX X..X ",
"X X..X ",
" X..X ",
" X..X ",
" X..X ",
" XX ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
"0,0"
};
/* width height num_colors chars_per_pixel */
" 32 32 3 1",
/* colors */
"X c #000000",
". c #ffffff",
" c None",
/* pixels */
"X ",
"XX ",
"X.X ",
"X..X ",
"X...X ",
"X....X ",
"X.....X ",
"X......X ",
"X.......X ",
"X........X ",
"X.....XXXXX ",
"X..X..X ",
"X.X X..X ",
"XX X..X ",
"X X..X ",
" X..X ",
" X..X ",
" X..X ",
" XX ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
"0,0"
};
static SDL_Cursor*
static SDL_Cursor *
init_color_cursor(const char *file)
{
SDL_Cursor *cursor = NULL;
SDL_Surface *surface = SDL_LoadBMP(file);
if (surface) {
if (surface->format->palette) {
SDL_SetColorKey(surface, 1, *(Uint8 *) surface->pixels);
SDL_SetColorKey(surface, 1, *(Uint8 *)surface->pixels);
} else {
switch (surface->format->BitsPerPixel) {
case 15:
@@ -97,45 +96,45 @@ init_color_cursor(const char *file)
return cursor;
}
static SDL_Cursor*
static SDL_Cursor *
init_system_cursor(const char *image[])
{
int i, row, col;
Uint8 data[4*32];
Uint8 mask[4*32];
int hot_x, hot_y;
int i, row, col;
Uint8 data[4 * 32];
Uint8 mask[4 * 32];
int hot_x, hot_y;
i = -1;
for (row=0; row<32; ++row) {
for (col=0; col<32; ++col) {
if (col % 8) {
data[i] <<= 1;
mask[i] <<= 1;
} else {
++i;
data[i] = mask[i] = 0;
}
switch (image[4+row][col]) {
case 'X':
data[i] |= 0x01;
mask[i] |= 0x01;
break;
case '.':
mask[i] |= 0x01;
break;
case ' ':
break;
}
i = -1;
for (row = 0; row < 32; ++row) {
for (col = 0; col < 32; ++col) {
if (col % 8) {
data[i] <<= 1;
mask[i] <<= 1;
} else {
++i;
data[i] = mask[i] = 0;
}
switch (image[4 + row][col]) {
case 'X':
data[i] |= 0x01;
mask[i] |= 0x01;
break;
case '.':
mask[i] |= 0x01;
break;
case ' ':
break;
}
}
}
}
SDL_sscanf(image[4+row], "%d,%d", &hot_x, &hot_y);
return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y);
SDL_sscanf(image[4 + row], "%d,%d", &hot_x, &hot_y);
return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y);
}
static SDLTest_CommonState *state;
int done;
static SDL_Cursor *cursors[1+SDL_NUM_SYSTEM_CURSORS];
static SDL_SystemCursor cursor_types[1+SDL_NUM_SYSTEM_CURSORS];
static SDL_Cursor *cursors[1 + SDL_NUM_SYSTEM_CURSORS];
static SDL_SystemCursor cursor_types[1 + SDL_NUM_SYSTEM_CURSORS];
static int num_cursors;
static int current_cursor;
static int show_cursor;
@@ -148,8 +147,7 @@ quit(int rc)
exit(rc);
}
void
loop()
void loop()
{
int i;
SDL_Event event;
@@ -170,20 +168,48 @@ loop()
SDL_SetCursor(cursors[current_cursor]);
switch ((int)cursor_types[current_cursor]) {
case (SDL_SystemCursor)-1: SDL_Log("Custom cursor"); break;
case SDL_SYSTEM_CURSOR_ARROW: SDL_Log("Arrow"); break;
case SDL_SYSTEM_CURSOR_IBEAM: SDL_Log("I-beam"); break;
case SDL_SYSTEM_CURSOR_WAIT: SDL_Log("Wait"); break;
case SDL_SYSTEM_CURSOR_CROSSHAIR: SDL_Log("Crosshair"); break;
case SDL_SYSTEM_CURSOR_WAITARROW: SDL_Log("Small wait cursor (or Wait if not available)"); break;
case SDL_SYSTEM_CURSOR_SIZENWSE: SDL_Log("Double arrow pointing northwest and southeast"); break;
case SDL_SYSTEM_CURSOR_SIZENESW: SDL_Log("Double arrow pointing northeast and southwest"); break;
case SDL_SYSTEM_CURSOR_SIZEWE: SDL_Log("Double arrow pointing west and east"); break;
case SDL_SYSTEM_CURSOR_SIZENS: SDL_Log("Double arrow pointing north and south"); break;
case SDL_SYSTEM_CURSOR_SIZEALL: SDL_Log("Four pointed arrow pointing north, south, east, and west"); break;
case SDL_SYSTEM_CURSOR_NO: SDL_Log("Slashed circle or crossbones"); break;
case SDL_SYSTEM_CURSOR_HAND: SDL_Log("Hand"); break;
default: SDL_Log("UNKNOWN CURSOR TYPE, FIX THIS PROGRAM."); break;
case (SDL_SystemCursor)-1:
SDL_Log("Custom cursor");
break;
case SDL_SYSTEM_CURSOR_ARROW:
SDL_Log("Arrow");
break;
case SDL_SYSTEM_CURSOR_IBEAM:
SDL_Log("I-beam");
break;
case SDL_SYSTEM_CURSOR_WAIT:
SDL_Log("Wait");
break;
case SDL_SYSTEM_CURSOR_CROSSHAIR:
SDL_Log("Crosshair");
break;
case SDL_SYSTEM_CURSOR_WAITARROW:
SDL_Log("Small wait cursor (or Wait if not available)");
break;
case SDL_SYSTEM_CURSOR_SIZENWSE:
SDL_Log("Double arrow pointing northwest and southeast");
break;
case SDL_SYSTEM_CURSOR_SIZENESW:
SDL_Log("Double arrow pointing northeast and southwest");
break;
case SDL_SYSTEM_CURSOR_SIZEWE:
SDL_Log("Double arrow pointing west and east");
break;
case SDL_SYSTEM_CURSOR_SIZENS:
SDL_Log("Double arrow pointing north and south");
break;
case SDL_SYSTEM_CURSOR_SIZEALL:
SDL_Log("Four pointed arrow pointing north, south, east, and west");
break;
case SDL_SYSTEM_CURSOR_NO:
SDL_Log("Slashed circle or crossbones");
break;
case SDL_SYSTEM_CURSOR_HAND:
SDL_Log("Hand");
break;
default:
SDL_Log("UNKNOWN CURSOR TYPE, FIX THIS PROGRAM.");
break;
}
} else {
@@ -192,7 +218,7 @@ loop()
}
}
}
for (i = 0; i < state->num_windows; ++i) {
SDL_Renderer *renderer = state->renderers[i];
SDL_RenderClear(renderer);
@@ -205,8 +231,7 @@ loop()
#endif
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int i;
const char *color_cursor = NULL;

View File

@@ -29,8 +29,7 @@ print_mode(const char *prefix, const SDL_DisplayMode *mode)
mode->w, mode->h, mode->refresh_rate);
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
SDL_DisplayMode mode;
int num_displays, dpy;
@@ -81,7 +80,7 @@ main(int argc, char *argv[])
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " MODE %d: failed to query (%s)\n", m, SDL_GetError());
} else {
char prefix[64];
SDL_snprintf(prefix, sizeof (prefix), " MODE %d", m);
SDL_snprintf(prefix, sizeof(prefix), " MODE %d", m);
print_mode(prefix, &mode);
}
}

View File

@@ -37,8 +37,7 @@ static const Uint32 fps_check_delay = 5000;
int done;
void
DrawPoints(SDL_Renderer * renderer)
void DrawPoints(SDL_Renderer *renderer)
{
int i;
int x, y;
@@ -71,8 +70,8 @@ DrawPoints(SDL_Renderer * renderer)
cycle_direction = -cycle_direction;
}
}
SDL_SetRenderDrawColor(renderer, 255, (Uint8) current_color,
(Uint8) current_color, (Uint8) current_alpha);
SDL_SetRenderDrawColor(renderer, 255, (Uint8)current_color,
(Uint8)current_color, (Uint8)current_alpha);
x = rand() % viewport.w;
y = rand() % viewport.h;
@@ -80,8 +79,7 @@ DrawPoints(SDL_Renderer * renderer)
}
}
void
DrawLines(SDL_Renderer * renderer)
void DrawLines(SDL_Renderer *renderer)
{
int i;
int x1, y1, x2, y2;
@@ -114,8 +112,8 @@ DrawLines(SDL_Renderer * renderer)
cycle_direction = -cycle_direction;
}
}
SDL_SetRenderDrawColor(renderer, 255, (Uint8) current_color,
(Uint8) current_color, (Uint8) current_alpha);
SDL_SetRenderDrawColor(renderer, 255, (Uint8)current_color,
(Uint8)current_color, (Uint8)current_alpha);
if (i == 0) {
SDL_RenderDrawLine(renderer, 0, 0, viewport.w - 1, viewport.h - 1);
@@ -123,17 +121,16 @@ DrawLines(SDL_Renderer * renderer)
SDL_RenderDrawLine(renderer, 0, viewport.h / 2, viewport.w - 1, viewport.h / 2);
SDL_RenderDrawLine(renderer, viewport.w / 2, 0, viewport.w / 2, viewport.h - 1);
} else {
x1 = (rand() % (viewport.w*2)) - viewport.w;
x2 = (rand() % (viewport.w*2)) - viewport.w;
y1 = (rand() % (viewport.h*2)) - viewport.h;
y2 = (rand() % (viewport.h*2)) - viewport.h;
x1 = (rand() % (viewport.w * 2)) - viewport.w;
x2 = (rand() % (viewport.w * 2)) - viewport.w;
y1 = (rand() % (viewport.h * 2)) - viewport.h;
y2 = (rand() % (viewport.h * 2)) - viewport.h;
SDL_RenderDrawLine(renderer, x1, y1, x2, y2);
}
}
}
void
DrawRects(SDL_Renderer * renderer)
void DrawRects(SDL_Renderer *renderer)
{
int i;
SDL_Rect rect;
@@ -166,19 +163,18 @@ DrawRects(SDL_Renderer * renderer)
cycle_direction = -cycle_direction;
}
}
SDL_SetRenderDrawColor(renderer, 255, (Uint8) current_color,
(Uint8) current_color, (Uint8) current_alpha);
SDL_SetRenderDrawColor(renderer, 255, (Uint8)current_color,
(Uint8)current_color, (Uint8)current_alpha);
rect.w = rand() % (viewport.h / 2);
rect.h = rand() % (viewport.h / 2);
rect.x = (rand() % (viewport.w*2) - viewport.w) - (rect.w / 2);
rect.y = (rand() % (viewport.h*2) - viewport.h) - (rect.h / 2);
rect.x = (rand() % (viewport.w * 2) - viewport.w) - (rect.w / 2);
rect.y = (rand() % (viewport.h * 2) - viewport.h) - (rect.h / 2);
SDL_RenderFillRect(renderer, &rect);
}
}
void
loop()
void loop()
{
Uint32 now;
int i;
@@ -212,16 +208,14 @@ loop()
if (SDL_TICKS_PASSED(now, next_fps_check)) {
/* Print out some timing information */
const Uint32 then = next_fps_check - fps_check_delay;
const double fps = ((double) frames * 1000) / (now - then);
const double fps = ((double)frames * 1000) / (now - then);
SDL_Log("%2.2f frames per second\n", fps);
next_fps_check = now + fps_check_delay;
frames = 0;
}
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int i;
@@ -270,12 +264,13 @@ main(int argc, char *argv[])
}
}
if (consumed < 0) {
static const char *options[] = {
"[--blend none|blend|add|mod]",
static const char *options[] = {
"[--blend none|blend|add|mod]",
"[--cyclecolor]",
"[--cyclealpha]",
"[num_objects]",
NULL };
NULL
};
SDLTest_CommonLogUsage(state, argv[0], options);
return 1;
}
@@ -308,7 +303,6 @@ main(int argc, char *argv[])
}
#endif
SDLTest_CommonQuit(state);
return 0;

View File

@@ -28,25 +28,22 @@ SDL_Renderer *renderer;
SDL_Surface *surface;
int done;
void
DrawChessBoard()
void DrawChessBoard()
{
int row = 0,column = 0,x = 0;
int row = 0, column = 0, x = 0;
SDL_Rect rect, darea;
/* Get the Size of drawing surface */
SDL_RenderGetViewport(renderer, &darea);
for ( ; row < 8; row++)
{
column = row%2;
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);
rect.w = darea.w/8;
rect.h = darea.h/8;
rect.w = darea.w / 8;
rect.h = darea.h / 8;
rect.x = x * rect.w;
rect.y = row * rect.h;
x = x + 2;
@@ -55,25 +52,24 @@ DrawChessBoard()
}
}
void
loop()
void loop()
{
SDL_Event e;
while (SDL_PollEvent(&e)) {
/* Re-create when window has been resized */
if ((e.type == SDL_WINDOWEVENT) && (e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)) {
SDL_DestroyRenderer(renderer);
/* Re-create when window has been resized */
if ((e.type == SDL_WINDOWEVENT) && (e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)) {
surface = SDL_GetWindowSurface(window);
renderer = SDL_CreateSoftwareRenderer(surface);
/* Clear the rendering surface with the specified color */
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
SDL_RenderClear(renderer);
}
SDL_DestroyRenderer(renderer);
if (e.type == SDL_QUIT) {
surface = SDL_GetWindowSurface(window);
renderer = SDL_CreateSoftwareRenderer(surface);
/* Clear the rendering surface with the specified color */
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
SDL_RenderClear(renderer);
}
if (e.type == SDL_QUIT) {
done = 1;
#ifdef __EMSCRIPTEN__
emscripten_cancel_main_loop();
@@ -97,8 +93,7 @@ loop()
SDL_UpdateWindowSurface(window);
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
@@ -109,17 +104,16 @@ main(int argc, char *argv[])
return 1;
}
/* 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 == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n",SDL_GetError());
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 == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n",SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n", SDL_GetError());
return 1;
}
@@ -127,7 +121,6 @@ main(int argc, char *argv[])
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
SDL_RenderClear(renderer);
/* Draw the Image on rendering surface */
done = 0;
#ifdef __EMSCRIPTEN__

View File

@@ -25,8 +25,7 @@ quit(int rc)
exit(rc);
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int i, done;
SDL_Event event;
@@ -76,13 +75,13 @@ main(int argc, char *argv[])
/* Check for events */
while (SDL_PollEvent(&event)) {
if (event.type == SDL_DROPBEGIN) {
SDL_Log("Drop beginning on window %u", (unsigned int) event.drop.windowID);
SDL_Log("Drop beginning on window %u", (unsigned int)event.drop.windowID);
} else if (event.type == SDL_DROPCOMPLETE) {
SDL_Log("Drop complete on window %u", (unsigned int) event.drop.windowID);
SDL_Log("Drop complete on window %u", (unsigned int)event.drop.windowID);
} else if ((event.type == SDL_DROPFILE) || (event.type == SDL_DROPTEXT)) {
const char *typestr = (event.type == SDL_DROPFILE) ? "File" : "Text";
char *dropped_filedir = event.drop.file;
SDL_Log("%s dropped on window %u: %s", typestr, (unsigned int) event.drop.windowID, dropped_filedir);
SDL_Log("%s dropped on window %u: %s", typestr, (unsigned int)event.drop.windowID, dropped_filedir);
/* Normally you'd have to do this, but this is freed in SDLTest_CommonEvent() */
/*SDL_free(dropped_filedir);*/
}

View File

@@ -32,17 +32,16 @@ ThreadFunc(void *data)
{
/* Set the child thread error string */
SDL_SetError("Thread %s (%lu) had a problem: %s",
(char *) data, SDL_ThreadID(), "nevermind");
(char *)data, SDL_ThreadID(), "nevermind");
while (alive) {
SDL_Log("Thread '%s' is alive!\n", (char *) data);
SDL_Log("Thread '%s' is alive!\n", (char *)data);
SDL_Delay(1 * 1000);
}
SDL_Log("Child thread error string: %s\n", SDL_GetError());
return 0;
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
SDL_Thread *thread;

View File

@@ -31,10 +31,11 @@ static const struct
{
int code;
const char *name;
} device_classes[] =
{
#define CLS(x) \
{ SDL_UDEV_DEVICE_ ## x, #x }
} device_classes[] = {
#define CLS(x) \
{ \
SDL_UDEV_DEVICE_##x, #x \
}
CLS(MOUSE),
CLS(KEYBOARD),
CLS(JOYSTICK),
@@ -48,18 +49,18 @@ static const struct
typedef struct
{
const char *name;
uint16_t bus_type;
uint16_t vendor_id;
uint16_t product_id;
uint16_t version;
uint8_t ev[(EV_MAX + 1) / 8];
uint8_t keys[(KEY_MAX + 1) / 8];
uint8_t abs[(ABS_MAX + 1) / 8];
uint8_t rel[(REL_MAX + 1) / 8];
uint8_t ff[(FF_MAX + 1) / 8];
uint8_t props[INPUT_PROP_MAX / 8];
int expected;
const char *name;
uint16_t bus_type;
uint16_t vendor_id;
uint16_t product_id;
uint16_t version;
uint8_t ev[(EV_MAX + 1) / 8];
uint8_t keys[(KEY_MAX + 1) / 8];
uint8_t abs[(ABS_MAX + 1) / 8];
uint8_t rel[(REL_MAX + 1) / 8];
uint8_t ff[(FF_MAX + 1) / 8];
uint8_t props[INPUT_PROP_MAX / 8];
int expected;
} GuessTest;
/*
@@ -73,10 +74,11 @@ typedef struct
*/
#define ZEROx4 0, 0, 0, 0
#define ZEROx8 ZEROx4, ZEROx4
#define FFx4 0xff, 0xff, 0xff, 0xff
#define FFx8 FFx4, FFx4
#define FFx4 0xff, 0xff, 0xff, 0xff
#define FFx8 FFx4, FFx4
/* Test-cases derived from real devices or from Linux kernel source */
/* *INDENT-OFF* */ /* clang-format off */
static const GuessTest guess_tests[] =
{
{
@@ -934,6 +936,7 @@ static const GuessTest guess_tests[] =
.expected = SDL_UDEV_DEVICE_UNKNOWN,
}
};
/* *INDENT-ON* */ /* clang-format on */
/* The Linux kernel provides capability info in EVIOCGBIT and in /sys
* as an array of unsigned long in native byte order, rather than an array
@@ -950,7 +953,7 @@ static const GuessTest guess_tests[] =
* an appropriate byteswapping function for the architecture's word size. */
SDL_COMPILE_TIME_ASSERT(sizeof_long, sizeof(unsigned long) == 4 || sizeof(unsigned long) == 8);
#define SwapLongLE(X) \
((sizeof(unsigned long) == 4) ? SDL_SwapLE32(X) : SDL_SwapLE64(X))
((sizeof(unsigned long) == 4) ? SDL_SwapLE32(X) : SDL_SwapLE64(X))
static int
run_test(void)
@@ -962,7 +965,8 @@ run_test(void)
const GuessTest *t = &guess_tests[i];
size_t j;
int actual;
struct {
struct
{
unsigned long ev[NBITS(EV_MAX)];
unsigned long abs[NBITS(ABS_MAX)];
unsigned long keys[NBITS(KEY_MAX)];
@@ -1033,8 +1037,7 @@ run_test(void)
#endif
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
return run_test() ? 0 : 1;
}

View File

@@ -32,8 +32,8 @@
#define FBASENAME1 "../Documents/sdldata1" /* this file will be created during tests */
#define FBASENAME2 "../Documents/sdldata2" /* this file should not exist before starting test */
#else
#define FBASENAME1 "sdldata1" /* this file will be created during tests */
#define FBASENAME2 "sdldata2" /* this file should not exist before starting test */
#define FBASENAME1 "sdldata1" /* this file will be created during tests */
#define FBASENAME2 "sdldata2" /* this file should not exist before starting test */
#endif
#ifndef NULL
@@ -48,22 +48,19 @@ cleanup(void)
}
static void
rwops_error_quit(unsigned line, SDL_RWops * rwops)
rwops_error_quit(unsigned line, SDL_RWops *rwops)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "testfile.c(%d): failed\n", line);
if (rwops) {
rwops->close(rwops); /* This calls SDL_FreeRW(rwops); */
rwops->close(rwops); /* This calls SDL_FreeRW(rwops); */
}
cleanup();
exit(1); /* quit with rwops error (test failed) */
exit(1); /* quit with rwops error (test failed) */
}
#define RWOP_ERR_QUIT(x) rwops_error_quit( __LINE__, (x) )
#define RWOP_ERR_QUIT(x) rwops_error_quit(__LINE__, (x))
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
SDL_RWops *rwops = NULL;
char test_buf[30];
@@ -73,7 +70,7 @@ main(int argc, char *argv[])
cleanup();
/* test 1 : basic argument test: all those calls to SDL_RWFromFile should fail */
/* test 1 : basic argument test: all those calls to SDL_RWFromFile should fail */
rwops = SDL_RWFromFile(NULL, NULL);
if (rwops) {
@@ -97,16 +94,16 @@ main(int argc, char *argv[])
}
SDL_Log("test1 OK\n");
/* test 2 : check that inexistent file is not successfully opened/created when required */
/* modes : r, r+ imply that file MUST exist
modes : a, a+, w, w+ checks that it succeeds (file may not exists)
/* test 2 : check that inexistent file is not successfully opened/created when required */
/* modes : r, r+ imply that file MUST exist
modes : a, a+, w, w+ checks that it succeeds (file may not exists)
*/
rwops = SDL_RWFromFile(FBASENAME2, "rb"); /* this file doesn't exist that call must fail */
*/
rwops = SDL_RWFromFile(FBASENAME2, "rb"); /* this file doesn't exist that call must fail */
if (rwops) {
RWOP_ERR_QUIT(rwops);
}
rwops = SDL_RWFromFile(FBASENAME2, "rb+"); /* this file doesn't exist that call must fail */
rwops = SDL_RWFromFile(FBASENAME2, "rb+"); /* this file doesn't exist that call must fail */
if (rwops) {
RWOP_ERR_QUIT(rwops);
}
@@ -136,10 +133,10 @@ main(int argc, char *argv[])
unlink(FBASENAME2);
SDL_Log("test2 OK\n");
/* test 3 : creation, writing , reading, seeking,
test : w mode, r mode, w+ mode
*/
rwops = SDL_RWFromFile(FBASENAME1, "wb"); /* write only */
/* test 3 : creation, writing , reading, seeking,
test : w mode, r mode, w+ mode
*/
rwops = SDL_RWFromFile(FBASENAME1, "wb"); /* write only */
if (rwops == NULL) {
RWOP_ERR_QUIT(rwops);
}
@@ -157,11 +154,11 @@ main(int argc, char *argv[])
}
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 */
rwops = SDL_RWFromFile(FBASENAME1, "rb"); /* read mode, file must exists */
if (rwops == NULL) {
RWOP_ERR_QUIT(rwops);
}
@@ -198,8 +195,8 @@ main(int argc, char *argv[])
rwops->close(rwops);
/* test 3: same with w+ mode */
rwops = SDL_RWFromFile(FBASENAME1, "wb+"); /* write + read + truncation */
/* test 3: same with w+ mode */
rwops = SDL_RWFromFile(FBASENAME1, "wb+"); /* write + read + truncation */
if (rwops == NULL) {
RWOP_ERR_QUIT(rwops);
}
@@ -249,8 +246,8 @@ main(int argc, char *argv[])
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 */
/* test 4: same in r+ mode */
rwops = SDL_RWFromFile(FBASENAME1, "rb+"); /* write + read + file must exists, no truncation */
if (rwops == NULL) {
RWOP_ERR_QUIT(rwops);
}
@@ -300,8 +297,8 @@ main(int argc, char *argv[])
rwops->close(rwops);
SDL_Log("test4 OK\n");
/* test5 : append mode */
rwops = SDL_RWFromFile(FBASENAME1, "ab+"); /* write + read + append */
/* test5 : append mode */
rwops = SDL_RWFromFile(FBASENAME1, "ab+"); /* write + read + append */
if (rwops == NULL) {
RWOP_ERR_QUIT(rwops);
}
@@ -357,5 +354,5 @@ main(int argc, char *argv[])
rwops->close(rwops);
SDL_Log("test5 OK\n");
cleanup();
return 0; /* all ok */
return 0; /* all ok */
}

View File

@@ -14,8 +14,7 @@
#include <stdio.h>
#include "SDL.h"
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
char *base_path;
char *pref_path;
@@ -30,8 +29,8 @@ main(int argc, char *argv[])
base_path = SDL_GetBasePath();
if (base_path == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find base path: %s\n",
SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find base path: %s\n",
SDL_GetError());
} else {
SDL_Log("base path: '%s'\n", base_path);
SDL_free(base_path);
@@ -39,8 +38,8 @@ main(int argc, char *argv[])
pref_path = SDL_GetPrefPath("libsdl", "test_filesystem");
if (pref_path == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find pref path: %s\n",
SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find pref path: %s\n",
SDL_GetError());
} else {
SDL_Log("pref path: '%s'\n", pref_path);
SDL_free(pref_path);
@@ -48,8 +47,8 @@ main(int argc, char *argv[])
pref_path = SDL_GetPrefPath(NULL, "test_filesystem");
if (pref_path == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find pref path without organization: %s\n",
SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find pref path without organization: %s\n",
SDL_GetError());
} else {
SDL_Log("pref path: '%s'\n", pref_path);
SDL_free(pref_path);

View File

@@ -31,46 +31,57 @@
#define BUTTON_SIZE 50
#define AXIS_SIZE 50
#define BUTTON_SIZE 50
#define AXIS_SIZE 50
/* This is indexed by SDL_GameControllerButton. */
static const struct { int x; int y; } button_positions[] = {
{387, 167}, /* SDL_CONTROLLER_BUTTON_A */
{431, 132}, /* SDL_CONTROLLER_BUTTON_B */
{342, 132}, /* SDL_CONTROLLER_BUTTON_X */
{389, 101}, /* SDL_CONTROLLER_BUTTON_Y */
{174, 132}, /* SDL_CONTROLLER_BUTTON_BACK */
{232, 128}, /* SDL_CONTROLLER_BUTTON_GUIDE */
{289, 132}, /* SDL_CONTROLLER_BUTTON_START */
{75, 154}, /* SDL_CONTROLLER_BUTTON_LEFTSTICK */
{305, 230}, /* SDL_CONTROLLER_BUTTON_RIGHTSTICK */
{77, 40}, /* SDL_CONTROLLER_BUTTON_LEFTSHOULDER */
{396, 36}, /* SDL_CONTROLLER_BUTTON_RIGHTSHOULDER */
{154, 188}, /* SDL_CONTROLLER_BUTTON_DPAD_UP */
{154, 249}, /* SDL_CONTROLLER_BUTTON_DPAD_DOWN */
{116, 217}, /* SDL_CONTROLLER_BUTTON_DPAD_LEFT */
{186, 217}, /* SDL_CONTROLLER_BUTTON_DPAD_RIGHT */
{232, 174}, /* SDL_CONTROLLER_BUTTON_MISC1 */
{132, 135}, /* SDL_CONTROLLER_BUTTON_PADDLE1 */
{330, 135}, /* SDL_CONTROLLER_BUTTON_PADDLE2 */
{132, 175}, /* SDL_CONTROLLER_BUTTON_PADDLE3 */
{330, 175}, /* SDL_CONTROLLER_BUTTON_PADDLE4 */
{0, 0}, /* SDL_CONTROLLER_BUTTON_TOUCHPAD */
static const struct
{
int x;
int y;
} button_positions[] = {
{ 387, 167 }, /* SDL_CONTROLLER_BUTTON_A */
{ 431, 132 }, /* SDL_CONTROLLER_BUTTON_B */
{ 342, 132 }, /* SDL_CONTROLLER_BUTTON_X */
{ 389, 101 }, /* SDL_CONTROLLER_BUTTON_Y */
{ 174, 132 }, /* SDL_CONTROLLER_BUTTON_BACK */
{ 232, 128 }, /* SDL_CONTROLLER_BUTTON_GUIDE */
{ 289, 132 }, /* SDL_CONTROLLER_BUTTON_START */
{ 75, 154 }, /* SDL_CONTROLLER_BUTTON_LEFTSTICK */
{ 305, 230 }, /* SDL_CONTROLLER_BUTTON_RIGHTSTICK */
{ 77, 40 }, /* SDL_CONTROLLER_BUTTON_LEFTSHOULDER */
{ 396, 36 }, /* SDL_CONTROLLER_BUTTON_RIGHTSHOULDER */
{ 154, 188 }, /* SDL_CONTROLLER_BUTTON_DPAD_UP */
{ 154, 249 }, /* SDL_CONTROLLER_BUTTON_DPAD_DOWN */
{ 116, 217 }, /* SDL_CONTROLLER_BUTTON_DPAD_LEFT */
{ 186, 217 }, /* SDL_CONTROLLER_BUTTON_DPAD_RIGHT */
{ 232, 174 }, /* SDL_CONTROLLER_BUTTON_MISC1 */
{ 132, 135 }, /* SDL_CONTROLLER_BUTTON_PADDLE1 */
{ 330, 135 }, /* SDL_CONTROLLER_BUTTON_PADDLE2 */
{ 132, 175 }, /* SDL_CONTROLLER_BUTTON_PADDLE3 */
{ 330, 175 }, /* SDL_CONTROLLER_BUTTON_PADDLE4 */
{ 0, 0 }, /* SDL_CONTROLLER_BUTTON_TOUCHPAD */
};
SDL_COMPILE_TIME_ASSERT(button_positions, SDL_arraysize(button_positions) == SDL_CONTROLLER_BUTTON_MAX);
/* This is indexed by SDL_GameControllerAxis. */
static const struct { int x; int y; double angle; } axis_positions[] = {
{74, 153, 270.0}, /* LEFTX */
{74, 153, 0.0}, /* LEFTY */
{306, 231, 270.0}, /* RIGHTX */
{306, 231, 0.0}, /* RIGHTY */
{91, -20, 0.0}, /* TRIGGERLEFT */
{375, -20, 0.0}, /* TRIGGERRIGHT */
static const struct
{
int x;
int y;
double angle;
} axis_positions[] = {
{ 74, 153, 270.0 }, /* LEFTX */
{ 74, 153, 0.0 }, /* LEFTY */
{ 306, 231, 270.0 }, /* RIGHTX */
{ 306, 231, 0.0 }, /* RIGHTY */
{ 91, -20, 0.0 }, /* TRIGGERLEFT */
{ 375, -20, 0.0 }, /* TRIGGERRIGHT */
};
SDL_COMPILE_TIME_ASSERT(axis_positions, SDL_arraysize(axis_positions) == SDL_CONTROLLER_AXIS_MAX);
/* This is indexed by SDL_JoystickPowerLevel + 1. */
static const char* power_level_strings[] = {
static const char *power_level_strings[] = {
"unknown", /* SDL_JOYSTICK_POWER_UNKNOWN */
"empty", /* SDL_JOYSTICK_POWER_EMPTY */
"low", /* SDL_JOYSTICK_POWER_LOW */
@@ -267,7 +278,7 @@ static void DelController(SDL_JoystickID controller)
--num_controllers;
if (i < num_controllers) {
SDL_memcpy(&gamecontrollers[i], &gamecontrollers[i+1], (num_controllers - i) * sizeof(*gamecontrollers));
SDL_memcpy(&gamecontrollers[i], &gamecontrollers[i + 1], (num_controllers - i) * sizeof(*gamecontrollers));
}
if (num_controllers > 0) {
@@ -294,35 +305,34 @@ static Uint16 ConvertAxisToRumble(Sint16 axisval)
*/
typedef struct
{
Uint8 ucEnableBits1; /* 0 */
Uint8 ucEnableBits2; /* 1 */
Uint8 ucRumbleRight; /* 2 */
Uint8 ucRumbleLeft; /* 3 */
Uint8 ucHeadphoneVolume; /* 4 */
Uint8 ucSpeakerVolume; /* 5 */
Uint8 ucMicrophoneVolume; /* 6 */
Uint8 ucAudioEnableBits; /* 7 */
Uint8 ucMicLightMode; /* 8 */
Uint8 ucAudioMuteBits; /* 9 */
Uint8 rgucRightTriggerEffect[11]; /* 10 */
Uint8 rgucLeftTriggerEffect[11]; /* 21 */
Uint8 rgucUnknown1[6]; /* 32 */
Uint8 ucLedFlags; /* 38 */
Uint8 rgucUnknown2[2]; /* 39 */
Uint8 ucLedAnim; /* 41 */
Uint8 ucLedBrightness; /* 42 */
Uint8 ucPadLights; /* 43 */
Uint8 ucLedRed; /* 44 */
Uint8 ucLedGreen; /* 45 */
Uint8 ucLedBlue; /* 46 */
Uint8 ucEnableBits1; /* 0 */
Uint8 ucEnableBits2; /* 1 */
Uint8 ucRumbleRight; /* 2 */
Uint8 ucRumbleLeft; /* 3 */
Uint8 ucHeadphoneVolume; /* 4 */
Uint8 ucSpeakerVolume; /* 5 */
Uint8 ucMicrophoneVolume; /* 6 */
Uint8 ucAudioEnableBits; /* 7 */
Uint8 ucMicLightMode; /* 8 */
Uint8 ucAudioMuteBits; /* 9 */
Uint8 rgucRightTriggerEffect[11]; /* 10 */
Uint8 rgucLeftTriggerEffect[11]; /* 21 */
Uint8 rgucUnknown1[6]; /* 32 */
Uint8 ucLedFlags; /* 38 */
Uint8 rgucUnknown2[2]; /* 39 */
Uint8 ucLedAnim; /* 41 */
Uint8 ucLedBrightness; /* 42 */
Uint8 ucPadLights; /* 43 */
Uint8 ucLedRed; /* 44 */
Uint8 ucLedGreen; /* 45 */
Uint8 ucLedBlue; /* 46 */
} DS5EffectsState_t;
static void CyclePS5TriggerEffect()
{
DS5EffectsState_t state;
Uint8 effects[3][11] =
{
Uint8 effects[3][11] = {
/* Clear trigger effect */
{ 0x05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
/* Constant resistance across entire trigger pull */
@@ -413,7 +423,7 @@ static void CloseVirtualController()
{
int i;
for (i = SDL_NumJoysticks(); i--; ) {
for (i = SDL_NumJoysticks(); i--;) {
if (SDL_JoystickIsVirtual(i)) {
SDL_JoystickDetachVirtual(i);
}
@@ -508,7 +518,7 @@ static void VirtualControllerMouseMotion(int x, int y)
valueY = (Sint16)(distanceY * -SDL_JOYSTICK_AXIS_MIN);
}
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active, valueX);
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active+1, valueY);
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active + 1, valueY);
}
}
}
@@ -545,14 +555,13 @@ static void VirtualControllerMouseUp(int x, int y)
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active, SDL_JOYSTICK_AXIS_MIN);
} else {
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active, 0);
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active+1, 0);
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active + 1, 0);
}
virtual_axis_active = SDL_CONTROLLER_AXIS_INVALID;
}
}
void
loop(void *arg)
void loop(void *arg)
{
SDL_Event event;
int i;
@@ -565,12 +574,12 @@ loop(void *arg)
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) == 1) {
switch (event.type) {
case SDL_CONTROLLERDEVICEADDED:
SDL_Log("Game controller device %d added.\n", (int) SDL_JoystickGetDeviceInstanceID(event.cdevice.which));
SDL_Log("Game controller device %d added.\n", (int)SDL_JoystickGetDeviceInstanceID(event.cdevice.which));
AddController(event.cdevice.which, SDL_TRUE);
break;
case SDL_CONTROLLERDEVICEREMOVED:
SDL_Log("Game controller device %d removed.\n", (int) event.cdevice.which);
SDL_Log("Game controller device %d removed.\n", (int)event.cdevice.which);
DelController(event.cdevice.which);
break;
@@ -592,7 +601,7 @@ loop(void *arg)
case SDL_CONTROLLERSENSORUPDATE:
SDL_Log("Controller %" SDL_PRIs32 " sensor %s: %.2f, %.2f, %.2f (%" SDL_PRIu64 ")\n",
event.csensor.which,
GetSensorName((SDL_SensorType) event.csensor.sensor),
GetSensorName((SDL_SensorType)event.csensor.sensor),
event.csensor.data[0],
event.csensor.data[1],
event.csensor.data[2],
@@ -606,7 +615,7 @@ loop(void *arg)
if (event.caxis.value <= (-SDL_JOYSTICK_AXIS_MAX / 2) || event.caxis.value >= (SDL_JOYSTICK_AXIS_MAX / 2)) {
SetController(event.caxis.which);
}
SDL_Log("Controller %" SDL_PRIs32 " axis %s changed to %d\n", event.caxis.which, SDL_GameControllerGetStringForAxis((SDL_GameControllerAxis) event.caxis.axis), event.caxis.value);
SDL_Log("Controller %" SDL_PRIs32 " axis %s changed to %d\n", event.caxis.which, SDL_GameControllerGetStringForAxis((SDL_GameControllerAxis)event.caxis.axis), event.caxis.value);
break;
#endif /* VERBOSE_AXES */
@@ -615,7 +624,7 @@ loop(void *arg)
if (event.type == SDL_CONTROLLERBUTTONDOWN) {
SetController(event.cbutton.which);
}
SDL_Log("Controller %" SDL_PRIs32 " button %s %s\n", event.cbutton.which, SDL_GameControllerGetStringForButton((SDL_GameControllerButton) event.cbutton.button), event.cbutton.state ? "pressed" : "released");
SDL_Log("Controller %" SDL_PRIs32 " button %s %s\n", event.cbutton.which, SDL_GameControllerGetStringForButton((SDL_GameControllerButton)event.cbutton.button), event.cbutton.state ? "pressed" : "released");
/* Cycle PS5 trigger effects when the microphone button is pressed */
if (event.type == SDL_CONTROLLERBUTTONDOWN &&
@@ -701,7 +710,7 @@ loop(void *arg)
if (showing_front) {
for (i = 0; i < SDL_CONTROLLER_AXIS_MAX; ++i) {
const Sint16 deadzone = 8000; /* !!! FIXME: real deadzone */
const Sint16 deadzone = 8000; /* !!! FIXME: real deadzone */
const Sint16 value = SDL_GameControllerGetAxis(gamecontroller, (SDL_GameControllerAxis)(i));
if (value < -deadzone) {
const double angle = axis_positions[i].angle;
@@ -739,10 +748,10 @@ loop(void *arg)
b = 0;
} else {
r = 0;
b = (Uint8)(((int)(x) * 255) / 32767);
b = (Uint8)(((int)(x)*255) / 32767);
}
if (y > 0) {
g = (Uint8)(((int)(y) * 255) / 32767);
g = (Uint8)(((int)(y)*255) / 32767);
} else {
g = 0;
}
@@ -782,8 +791,7 @@ loop(void *arg)
#endif
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int i;
int controller_count = 0;
@@ -802,7 +810,7 @@ main(int argc, char *argv[])
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize SDL (Note: video is required to start event loop) */
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER ) < 0) {
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
@@ -829,7 +837,7 @@ main(int argc, char *argv[])
const char *description;
SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(i),
guid, sizeof (guid));
guid, sizeof(guid));
if (SDL_IsGameController(i)) {
controller_count++;
@@ -879,8 +887,8 @@ main(int argc, char *argv[])
description = "Joystick";
}
SDL_Log("%s %d: %s%s%s (guid %s, VID 0x%.4x, PID 0x%.4x, player index = %d)\n",
description, i, name ? name : "Unknown", path ? ", " : "", path ? path : "", guid,
SDL_JoystickGetDeviceVendor(i), SDL_JoystickGetDeviceProduct(i), SDL_JoystickGetDevicePlayerIndex(i));
description, i, name ? name : "Unknown", path ? ", " : "", path ? path : "", guid,
SDL_JoystickGetDeviceVendor(i), SDL_JoystickGetDeviceProduct(i), SDL_JoystickGetDevicePlayerIndex(i));
}
SDL_Log("There are %d game controller(s) attached (%d joystick(s))\n", controller_count, SDL_NumJoysticks());

View File

@@ -41,8 +41,7 @@ quit(int rc)
exit(rc);
}
int
LoadSprite(const char *file)
int LoadSprite(const char *file)
{
int i;
@@ -63,9 +62,7 @@ LoadSprite(const char *file)
return 0;
}
void
loop()
void loop()
{
int i;
SDL_Event event;
@@ -164,8 +161,7 @@ loop()
#endif
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int i;
const char *icon = "icon.bmp";
@@ -219,7 +215,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));
(SDL_Texture **)SDL_malloc(state->num_windows * sizeof(*sprites));
if (sprites == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
quit(2);
@@ -238,7 +234,6 @@ main(int argc, char *argv[])
}
}
srand((unsigned int)time(NULL));
/* Main render loop */
@@ -252,16 +247,16 @@ main(int argc, char *argv[])
while (!done) {
++frames;
loop();
}
}
#endif
/* Print out some timing information */
now = SDL_GetTicks();
if (now > then) {
double fps = ((double) frames * 1000) / (now - then);
double fps = ((double)frames * 1000) / (now - then);
SDL_Log("%2.2f frames per second\n", fps);
}
quit(0);
return 0;

View File

@@ -26,9 +26,9 @@
#include "SDL_test.h"
#include "SDL_test_common.h"
#define WIDTH 640
#define WIDTH 640
#define HEIGHT 480
#define BPP 4
#define BPP 4
/* MUST BE A POWER OF 2! */
#define EVENT_BUF_SIZE 256
@@ -38,7 +38,7 @@
static SDLTest_CommonState *state;
static SDL_Event events[EVENT_BUF_SIZE];
static int eventWrite;
static int colors[7] = {0xFF,0xFF00,0xFF0000,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF};
static int colors[7] = { 0xFF, 0xFF00, 0xFF0000, 0xFFFF00, 0x00FFFF, 0xFF00FF, 0xFFFFFF };
static int quitting = 0;
typedef struct
@@ -54,7 +54,6 @@ typedef struct
static Knob knob = { 0.0f, 0.1f, { 0.0f, 0.0f } };
static void
setpix(SDL_Surface *screen, float _x, float _y, unsigned int col)
{
@@ -65,26 +64,26 @@ setpix(SDL_Surface *screen, float _x, float _y, unsigned int col)
const int y = (int)_y;
float a;
if ( (x < 0) || (x >= screen->w) || (y < 0) || (y >= screen->h) ) {
if ((x < 0) || (x >= screen->w) || (y < 0) || (y >= screen->h)) {
return;
}
pixmem32 = (Uint32 *) screen->pixels + y * screen->pitch / BPP + x;
pixmem32 = (Uint32 *)screen->pixels + y * screen->pitch / BPP + x;
SDL_memcpy(&colour, pixmem32, screen->format->BytesPerPixel);
SDL_GetRGB(colour,screen->format,&r,&g,&b);
SDL_GetRGB(colour, screen->format, &r, &g, &b);
/* r = 0;g = 0; b = 0; */
a = (float) ((col >> 24) & 0xFF);
a = (float)((col >> 24) & 0xFF);
if (a == 0) {
a = 0xFF; /* Hack, to make things easier. */
}
a = (a == 0.0f) ? 1 : (a / 255.0f);
r = (Uint8) (r * (1 - a) + ((col >> 16) & 0xFF) * a);
g = (Uint8) (g * (1 - a) + ((col >> 8) & 0xFF) * a);
b = (Uint8) (b * (1 - a) + ((col >> 0) & 0xFF) * a);
r = (Uint8)(r * (1 - a) + ((col >> 16) & 0xFF) * a);
g = (Uint8)(g * (1 - a) + ((col >> 8) & 0xFF) * a);
b = (Uint8)(b * (1 - a) + ((col >> 0) & 0xFF) * a);
colour = SDL_MapRGB(screen->format, r, g, b);
*pixmem32 = colour;
@@ -104,9 +103,9 @@ drawLine(SDL_Surface *screen, float x0, float y0, float x1, float y1, unsigned i
static void
drawCircle(SDL_Surface *screen, float x, float y, float r, unsigned int c)
{
float tx,ty, xr;
for (ty = (float) -SDL_fabs(r); ty <= (float) SDL_fabs((int) r); ty++) {
xr = (float) SDL_sqrt(r * r - ty * ty);
float tx, ty, xr;
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++) {
setpix(screen, x + tx, y + ty, c);
@@ -145,15 +144,15 @@ DrawScreen(SDL_Window *window)
float x, y;
unsigned int c, col;
if ( (event->type == SDL_FINGERMOTION) ||
(event->type == SDL_FINGERDOWN) ||
(event->type == SDL_FINGERUP) ) {
if ((event->type == SDL_FINGERMOTION) ||
(event->type == SDL_FINGERDOWN) ||
(event->type == SDL_FINGERUP)) {
x = event->tfinger.x;
y = event->tfinger.y;
/* draw the touch: */
c = colors[event->tfinger.fingerId % 7];
col = ((unsigned int) (c * (0.1f + 0.85f))) | (unsigned int) (0xFF * age) << 24;
col = ((unsigned int)(c * (0.1f + 0.85f))) | (unsigned int)(0xFF * age) << 24;
if (event->type == SDL_FINGERMOTION) {
drawCircle(screen, x * screen->w, y * screen->h, 5, col);
@@ -181,78 +180,79 @@ loop(void)
SDLTest_CommonEvent(state, &event, &quitting);
/* Record _all_ events */
events[eventWrite & (EVENT_BUF_SIZE-1)] = event;
events[eventWrite & (EVENT_BUF_SIZE - 1)] = event;
eventWrite++;
switch (event.type) {
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
case SDLK_i: {
for (i = 0; i < SDL_GetNumTouchDevices(); ++i) {
const SDL_TouchID id = SDL_GetTouchDevice(i);
const char *name = SDL_GetTouchName(i);
SDL_Log("Fingers Down on device %"SDL_PRIs64" (%s): %d", id, name, SDL_GetNumTouchFingers(id));
}
break;
}
case SDLK_SPACE:
SDL_RecordGesture(-1);
break;
case SDLK_s:
stream = SDL_RWFromFile("gestureSave", "w");
SDL_Log("Wrote %i templates", SDL_SaveAllDollarTemplates(stream));
SDL_RWclose(stream);
break;
case SDLK_l:
stream = SDL_RWFromFile("gestureSave", "r");
SDL_Log("Loaded: %i", SDL_LoadDollarTemplates(-1, stream));
SDL_RWclose(stream);
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
case SDLK_i:
{
for (i = 0; i < SDL_GetNumTouchDevices(); ++i) {
const SDL_TouchID id = SDL_GetTouchDevice(i);
const char *name = SDL_GetTouchName(i);
SDL_Log("Fingers Down on device %" SDL_PRIs64 " (%s): %d", id, name, SDL_GetNumTouchFingers(id));
}
break;
}
case SDLK_SPACE:
SDL_RecordGesture(-1);
break;
case SDLK_s:
stream = SDL_RWFromFile("gestureSave", "w");
SDL_Log("Wrote %i templates", SDL_SaveAllDollarTemplates(stream));
SDL_RWclose(stream);
break;
case SDLK_l:
stream = SDL_RWFromFile("gestureSave", "r");
SDL_Log("Loaded: %i", SDL_LoadDollarTemplates(-1, stream));
SDL_RWclose(stream);
break;
}
break;
#if VERBOSE
case SDL_FINGERMOTION:
SDL_Log("Finger: %"SDL_PRIs64", x: %f, y: %f",event.tfinger.fingerId,
event.tfinger.x,event.tfinger.y);
break;
case SDL_FINGERMOTION:
SDL_Log("Finger: %" SDL_PRIs64 ", x: %f, y: %f", event.tfinger.fingerId,
event.tfinger.x, event.tfinger.y);
break;
case SDL_FINGERDOWN:
SDL_Log("Finger: %"SDL_PRIs64" down - x: %f, y: %f",
event.tfinger.fingerId,event.tfinger.x,event.tfinger.y);
break;
case SDL_FINGERDOWN:
SDL_Log("Finger: %" SDL_PRIs64 " down - x: %f, y: %f",
event.tfinger.fingerId, event.tfinger.x, event.tfinger.y);
break;
case SDL_FINGERUP:
SDL_Log("Finger: %"SDL_PRIs64" up - x: %f, y: %f",
event.tfinger.fingerId,event.tfinger.x,event.tfinger.y);
break;
case SDL_FINGERUP:
SDL_Log("Finger: %" SDL_PRIs64 " up - x: %f, y: %f",
event.tfinger.fingerId, event.tfinger.x, event.tfinger.y);
break;
#endif
case SDL_MULTIGESTURE:
case SDL_MULTIGESTURE:
#if VERBOSE
SDL_Log("Multi Gesture: x = %f, y = %f, dAng = %f, dR = %f",
event.mgesture.x, event.mgesture.y,
event.mgesture.dTheta, event.mgesture.dDist);
SDL_Log("MG: numDownTouch = %i",event.mgesture.numFingers);
SDL_Log("Multi Gesture: x = %f, y = %f, dAng = %f, dR = %f",
event.mgesture.x, event.mgesture.y,
event.mgesture.dTheta, event.mgesture.dDist);
SDL_Log("MG: numDownTouch = %i", event.mgesture.numFingers);
#endif
knob.p.x = event.mgesture.x;
knob.p.y = event.mgesture.y;
knob.ang += event.mgesture.dTheta;
knob.r += event.mgesture.dDist;
break;
knob.p.x = event.mgesture.x;
knob.p.y = event.mgesture.y;
knob.ang += event.mgesture.dTheta;
knob.r += event.mgesture.dDist;
break;
case SDL_DOLLARGESTURE:
SDL_Log("Gesture %"SDL_PRIs64" performed, error: %f",
event.dgesture.gestureId, event.dgesture.error);
break;
case SDL_DOLLARGESTURE:
SDL_Log("Gesture %" SDL_PRIs64 " performed, error: %f",
event.dgesture.gestureId, event.dgesture.error);
break;
case SDL_DOLLARRECORD:
SDL_Log("Recorded gesture: %"SDL_PRIs64"",event.dgesture.gestureId);
break;
case SDL_DOLLARRECORD:
SDL_Log("Recorded gesture: %" SDL_PRIs64 "", event.dgesture.gestureId);
break;
}
}
@@ -269,7 +269,7 @@ loop(void)
#endif
}
int main(int argc, char* argv[])
int main(int argc, char *argv[])
{
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {

View File

@@ -26,12 +26,11 @@
typedef struct GL_Context
{
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
#define SDL_PROC(ret, func, params) ret(APIENTRY *func) params;
#include "../src/render/opengl/SDL_glfuncs.h"
#undef SDL_PROC
} GL_Context;
/* Undefine this if you want a flat cube instead of a rainbow cube */
#define SHADED_CUBE
@@ -39,7 +38,7 @@ static SDLTest_CommonState *state;
static SDL_GLContext context;
static GL_Context ctx;
static int LoadContext(GL_Context * data)
static int LoadContext(GL_Context *data)
{
#if SDL_VIDEO_DRIVER_UIKIT
#define __SDL_NOGETPROCADDR__
@@ -50,15 +49,15 @@ static int LoadContext(GL_Context * data)
#endif
#if defined __SDL_NOGETPROCADDR__
#define SDL_PROC(ret,func,params) data->func=func;
#define SDL_PROC(ret, func, params) data->func = func;
#else
#define SDL_PROC(ret,func,params) \
do { \
data->func = SDL_GL_GetProcAddress(#func); \
if ( ! data->func ) { \
#define SDL_PROC(ret, func, params) \
do { \
data->func = SDL_GL_GetProcAddress(#func); \
if (!data->func) { \
return SDL_SetError("Couldn't load GL function %s: %s", #func, SDL_GetError()); \
} \
} while ( 0 );
} \
} while (0);
#endif /* __SDL_NOGETPROCADDR__ */
#include "../src/render/opengl/SDL_glfuncs.h"
@@ -66,13 +65,12 @@ static int LoadContext(GL_Context * data)
return 0;
}
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
quit(int rc)
{
if (context) {
/* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */
/* SDL_GL_MakeCurrent(0, NULL); */ /* doesn't do anything */
SDL_GL_DeleteContext(context);
}
SDLTest_CommonQuit(state);
@@ -83,24 +81,24 @@ static void
Render()
{
static float color[8][3] = {
{1.0, 1.0, 0.0},
{1.0, 0.0, 0.0},
{0.0, 0.0, 0.0},
{0.0, 1.0, 0.0},
{0.0, 1.0, 1.0},
{1.0, 1.0, 1.0},
{1.0, 0.0, 1.0},
{0.0, 0.0, 1.0}
{ 1.0, 1.0, 0.0 },
{ 1.0, 0.0, 0.0 },
{ 0.0, 0.0, 0.0 },
{ 0.0, 1.0, 0.0 },
{ 0.0, 1.0, 1.0 },
{ 1.0, 1.0, 1.0 },
{ 1.0, 0.0, 1.0 },
{ 0.0, 0.0, 1.0 }
};
static float cube[8][3] = {
{0.5, 0.5, -0.5},
{0.5, -0.5, -0.5},
{-0.5, -0.5, -0.5},
{-0.5, 0.5, -0.5},
{-0.5, 0.5, 0.5},
{0.5, 0.5, 0.5},
{0.5, -0.5, 0.5},
{-0.5, -0.5, 0.5}
{ 0.5, 0.5, -0.5 },
{ 0.5, -0.5, -0.5 },
{ -0.5, -0.5, -0.5 },
{ -0.5, 0.5, -0.5 },
{ -0.5, 0.5, 0.5 },
{ 0.5, 0.5, 0.5 },
{ 0.5, -0.5, 0.5 },
{ -0.5, -0.5, 0.5 }
};
/* Do our drawing, too. */
@@ -163,7 +161,7 @@ Render()
ctx.glVertex3fv(cube[2]);
ctx.glColor3fv(color[7]);
ctx.glVertex3fv(cube[7]);
#else /* flat cube */
#else /* flat cube */
ctx.glColor3f(1.0, 0.0, 0.0);
ctx.glVertex3fv(cube[0]);
ctx.glVertex3fv(cube[1]);
@@ -207,8 +205,7 @@ Render()
ctx.glRotatef(5.0, 1.0, 1.0, 1.0);
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int fsaa, accel;
int value;
@@ -237,11 +234,11 @@ main(int argc, char *argv[])
consumed = SDLTest_CommonArg(state, i);
if (consumed == 0) {
if (SDL_strcasecmp(argv[i], "--fsaa") == 0 && i+1 < argc) {
fsaa = SDL_atoi(argv[i+1]);
if (SDL_strcasecmp(argv[i], "--fsaa") == 0 && i + 1 < argc) {
fsaa = SDL_atoi(argv[i + 1]);
consumed = 2;
} else if (SDL_strcasecmp(argv[i], "--accel") == 0 && i+1 < argc) {
accel = SDL_atoi(argv[i+1]);
} else if (SDL_strcasecmp(argv[i], "--accel") == 0 && i + 1 < argc) {
accel = SDL_atoi(argv[i + 1]);
consumed = 2;
} else {
consumed = -1;
@@ -280,7 +277,7 @@ main(int argc, char *argv[])
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
quit(2);
}
/* Important: call this *after* creating the context */
if (LoadContext(&ctx) < 0) {
SDL_Log("Could not load GL functions\n");
@@ -297,7 +294,7 @@ main(int argc, char *argv[])
swap_interval = 1;
}
} else {
SDL_GL_SetSwapInterval(0); /* disable vsync. */
SDL_GL_SetSwapInterval(0); /* disable vsync. */
swap_interval = 0;
}
@@ -345,25 +342,25 @@ main(int argc, char *argv[])
SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
SDL_GetError());
SDL_GetError());
}
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
if (!status) {
SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
value);
value);
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
SDL_GetError());
SDL_GetError());
}
}
if (accel >= 0) {
status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
if (!status) {
SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested %d, got %d\n", accel,
value);
value);
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
SDL_GetError());
SDL_GetError());
}
}
@@ -376,7 +373,7 @@ main(int argc, char *argv[])
ctx.glEnable(GL_DEPTH_TEST);
ctx.glDepthFunc(GL_LESS);
ctx.glShadeModel(GL_SMOOTH);
/* Main render loop */
frames = 0;
then = SDL_GetTicks();
@@ -423,7 +420,7 @@ main(int argc, char *argv[])
now = SDL_GetTicks();
if (now > then) {
SDL_Log("%2.2f frames per second\n",
((double) frames * 1000) / (now - then));
((double)frames * 1000) / (now - then));
}
quit(0);
return 0;
@@ -431,8 +428,7 @@ main(int argc, char *argv[])
#else /* HAVE_OPENGL */
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No OpenGL support on this system\n");
return 1;

View File

@@ -51,38 +51,34 @@ quit(int rc)
static void
Render()
{
static GLubyte color[8][4] = { {255, 0, 0, 0},
{255, 0, 0, 255},
{0, 255, 0, 255},
{0, 255, 0, 255},
{0, 255, 0, 255},
{255, 255, 255, 255},
{255, 0, 255, 255},
{0, 0, 255, 255}
};
static GLfloat cube[8][3] = { {0.5, 0.5, -0.5},
{0.5f, -0.5f, -0.5f},
{-0.5f, -0.5f, -0.5f},
{-0.5f, 0.5f, -0.5f},
{-0.5f, 0.5f, 0.5f},
{0.5f, 0.5f, 0.5f},
{0.5f, -0.5f, 0.5f},
{-0.5f, -0.5f, 0.5f}
};
static GLubyte color[8][4] = { { 255, 0, 0, 0 },
{ 255, 0, 0, 255 },
{ 0, 255, 0, 255 },
{ 0, 255, 0, 255 },
{ 0, 255, 0, 255 },
{ 255, 255, 255, 255 },
{ 255, 0, 255, 255 },
{ 0, 0, 255, 255 } };
static GLfloat cube[8][3] = { { 0.5, 0.5, -0.5 },
{ 0.5f, -0.5f, -0.5f },
{ -0.5f, -0.5f, -0.5f },
{ -0.5f, 0.5f, -0.5f },
{ -0.5f, 0.5f, 0.5f },
{ 0.5f, 0.5f, 0.5f },
{ 0.5f, -0.5f, 0.5f },
{ -0.5f, -0.5f, 0.5f } };
static GLubyte indices[36] = { 0, 3, 4,
4, 5, 0,
0, 5, 6,
6, 1, 0,
6, 7, 2,
2, 1, 6,
7, 4, 3,
3, 2, 7,
5, 4, 7,
7, 6, 5,
2, 3, 1,
3, 0, 1
};
4, 5, 0,
0, 5, 6,
6, 1, 0,
6, 7, 2,
2, 1, 6,
7, 4, 3,
3, 2, 7,
5, 4, 7,
7, 6, 5,
2, 3, 1,
3, 0, 1 };
/* Do our drawing, too. */
glClearColor(0.0, 0.0, 0.0, 1.0);
@@ -99,8 +95,7 @@ Render()
glRotatef(5.0, 1.0, 1.0, 1.0);
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int fsaa, accel;
int value;
@@ -163,11 +158,11 @@ main(int argc, char *argv[])
state->gl_minor_version = 1;
state->gl_profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
if (fsaa) {
state->gl_multisamplebuffers=1;
state->gl_multisamplesamples=fsaa;
state->gl_multisamplebuffers = 1;
state->gl_multisamplesamples = fsaa;
}
if (accel) {
state->gl_accelerated=1;
state->gl_accelerated = 1;
}
if (!SDLTest_CommonInit(state)) {
quit(2);
@@ -208,28 +203,28 @@ main(int argc, char *argv[])
SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_RED_SIZE: %s\n",
SDL_GetError());
SDL_GetError());
}
status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
if (!status) {
SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_GREEN_SIZE: %s\n",
SDL_GetError());
SDL_GetError());
}
status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
if (!status) {
SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_BLUE_SIZE: %s\n",
SDL_GetError());
SDL_GetError());
}
status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
if (!status) {
SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value);
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_DEPTH_SIZE: %s\n",
SDL_GetError());
SDL_GetError());
}
if (fsaa) {
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
@@ -237,15 +232,15 @@ main(int argc, char *argv[])
SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
SDL_GetError());
SDL_GetError());
}
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
if (!status) {
SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
value);
value);
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
SDL_GetError());
SDL_GetError());
}
}
if (accel) {
@@ -254,7 +249,7 @@ main(int argc, char *argv[])
SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
SDL_GetError());
SDL_GetError());
}
}
@@ -293,23 +288,23 @@ main(int argc, char *argv[])
switch (event.type) {
case SDL_WINDOWEVENT:
switch (event.window.event) {
case SDL_WINDOWEVENT_RESIZED:
for (i = 0; i < state->num_windows; ++i) {
if (event.window.windowID == SDL_GetWindowID(state->windows[i])) {
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
if (status) {
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
break;
}
/* Change view port to the new window dimensions */
glViewport(0, 0, event.window.data1, event.window.data2);
/* Update window content */
Render();
SDL_GL_SwapWindow(state->windows[i]);
case SDL_WINDOWEVENT_RESIZED:
for (i = 0; i < state->num_windows; ++i) {
if (event.window.windowID == SDL_GetWindowID(state->windows[i])) {
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
if (status) {
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
break;
}
/* Change view port to the new window dimensions */
glViewport(0, 0, event.window.data1, event.window.data2);
/* Update window content */
Render();
SDL_GL_SwapWindow(state->windows[i]);
break;
}
break;
}
break;
}
}
SDLTest_CommonEvent(state, &event, &done);
@@ -334,18 +329,17 @@ main(int argc, char *argv[])
now = SDL_GetTicks();
if (now > then) {
SDL_Log("%2.2f frames per second\n",
((double) frames * 1000) / (now - then));
((double)frames * 1000) / (now - then));
}
#if !defined(__ANDROID__)
quit(0);
#endif
#endif
return 0;
}
#else /* HAVE_OPENGLES */
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No OpenGL ES support on this system\n");
return 1;

View File

@@ -33,7 +33,7 @@
typedef struct GLES2_Context
{
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
#define SDL_PROC(ret, func, params) ret(APIENTRY *func) params;
#include "../src/render/opengles2/SDL_gles2funcs.h"
#undef SDL_PROC
} GLES2_Context;
@@ -63,7 +63,7 @@ static SDL_GLContext *context = NULL;
static int depth = 16;
static GLES2_Context ctx;
static int LoadContext(GLES2_Context * data)
static int LoadContext(GLES2_Context *data)
{
#if SDL_VIDEO_DRIVER_UIKIT
#define __SDL_NOGETPROCADDR__
@@ -74,15 +74,15 @@ static int LoadContext(GLES2_Context * data)
#endif
#if defined __SDL_NOGETPROCADDR__
#define SDL_PROC(ret,func,params) data->func=func;
#define SDL_PROC(ret, func, params) data->func = func;
#else
#define SDL_PROC(ret,func,params) \
do { \
data->func = SDL_GL_GetProcAddress(#func); \
if ( ! data->func ) { \
#define SDL_PROC(ret, func, params) \
do { \
data->func = SDL_GL_GetProcAddress(#func); \
if (!data->func) { \
return SDL_SetError("Couldn't load GLES2 function %s: %s", #func, SDL_GetError()); \
} \
} while ( 0 );
} \
} while (0);
#endif /* __SDL_NOGETPROCADDR__ */
#include "../src/render/opengles2/SDL_gles2funcs.h"
@@ -110,19 +110,19 @@ quit(int rc)
exit(rc);
}
#define GL_CHECK(x) \
x; \
{ \
GLenum glError = ctx.glGetError(); \
if (glError != GL_NO_ERROR) { \
#define GL_CHECK(x) \
x; \
{ \
GLenum glError = ctx.glGetError(); \
if (glError != GL_NO_ERROR) { \
SDL_Log("glGetError() = %i (0x%.8x) at line %i\n", glError, glError, __LINE__); \
quit(1); \
} \
}
quit(1); \
} \
}
/*
* Simulates desktop's glRotatef. The matrix is returned in column-major
* order.
/*
* Simulates desktop's glRotatef. The matrix is returned in column-major
* order.
*/
static void
rotate_matrix(float angle, float x, float y, float z, float *r)
@@ -161,16 +161,16 @@ rotate_matrix(float angle, float x, float y, float z, float *r)
}
}
/*
* Simulates gluPerspectiveMatrix
/*
* Simulates gluPerspectiveMatrix
*/
static void
static void
perspective_matrix(float fovy, float aspect, float znear, float zfar, float *r)
{
int i;
float f;
f = 1.0f/SDL_tanf(fovy * 0.5f);
f = 1.0f / SDL_tanf(fovy * 0.5f);
for (i = 0; i < 16; i++) {
r[i] = 0.0;
@@ -184,7 +184,7 @@ perspective_matrix(float fovy, float aspect, float znear, float zfar, float *r)
r[15] = 0.0f;
}
/*
/*
* Multiplies lhs by rhs and writes out to r. All matrices are 4x4 and column
* major. In-place multiplication is supported.
*/
@@ -209,7 +209,7 @@ multiply_matrix(float *lhs, float *rhs, float *r)
}
}
/*
/*
* Create shader, load in source, compile, dump debug as necessary.
*
* shader: Pointer to return created shader ID.
@@ -217,7 +217,7 @@ multiply_matrix(float *lhs, float *rhs, float *r)
* shader_type: Passed to GL, e.g. GL_VERTEX_SHADER.
*/
static void
process_shader(GLuint *shader, const char * source, GLint shader_type)
process_shader(GLuint *shader, const char *source, GLint shader_type)
{
GLint status = GL_FALSE;
const char *shaders[1] = { NULL };
@@ -270,67 +270,137 @@ link_program(struct shader_data *data)
}
/* 3D data. Vertex range -0.5..0.5 in all axes.
* Z -0.5 is near, 0.5 is far. */
const float _vertices[] =
{
* Z -0.5 is near, 0.5 is far. */
const float _vertices[] = {
/* Front face. */
/* Bottom left */
-0.5, 0.5, -0.5,
0.5, -0.5, -0.5,
-0.5, -0.5, -0.5,
-0.5,
0.5,
-0.5,
0.5,
-0.5,
-0.5,
-0.5,
-0.5,
-0.5,
/* Top right */
-0.5, 0.5, -0.5,
0.5, 0.5, -0.5,
0.5, -0.5, -0.5,
-0.5,
0.5,
-0.5,
0.5,
0.5,
-0.5,
0.5,
-0.5,
-0.5,
/* Left face */
/* Bottom left */
-0.5, 0.5, 0.5,
-0.5, -0.5, -0.5,
-0.5, -0.5, 0.5,
-0.5,
0.5,
0.5,
-0.5,
-0.5,
-0.5,
-0.5,
-0.5,
0.5,
/* Top right */
-0.5, 0.5, 0.5,
-0.5, 0.5, -0.5,
-0.5, -0.5, -0.5,
-0.5,
0.5,
0.5,
-0.5,
0.5,
-0.5,
-0.5,
-0.5,
-0.5,
/* Top face */
/* Bottom left */
-0.5, 0.5, 0.5,
0.5, 0.5, -0.5,
-0.5, 0.5, -0.5,
-0.5,
0.5,
0.5,
0.5,
0.5,
-0.5,
-0.5,
0.5,
-0.5,
/* Top right */
-0.5, 0.5, 0.5,
0.5, 0.5, 0.5,
0.5, 0.5, -0.5,
-0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
-0.5,
/* Right face */
/* Bottom left */
0.5, 0.5, -0.5,
0.5, -0.5, 0.5,
0.5, -0.5, -0.5,
0.5,
0.5,
-0.5,
0.5,
-0.5,
0.5,
0.5,
-0.5,
-0.5,
/* Top right */
0.5, 0.5, -0.5,
0.5, 0.5, 0.5,
0.5, -0.5, 0.5,
0.5,
0.5,
-0.5,
0.5,
0.5,
0.5,
0.5,
-0.5,
0.5,
/* Back face */
/* Bottom left */
0.5, 0.5, 0.5,
-0.5, -0.5, 0.5,
0.5, -0.5, 0.5,
0.5,
0.5,
0.5,
-0.5,
-0.5,
0.5,
0.5,
-0.5,
0.5,
/* Top right */
0.5, 0.5, 0.5,
-0.5, 0.5, 0.5,
-0.5, -0.5, 0.5,
0.5,
0.5,
0.5,
-0.5,
0.5,
0.5,
-0.5,
-0.5,
0.5,
/* Bottom face */
/* Bottom left */
-0.5, -0.5, -0.5,
0.5, -0.5, 0.5,
-0.5, -0.5, 0.5,
-0.5,
-0.5,
-0.5,
0.5,
-0.5,
0.5,
-0.5,
-0.5,
0.5,
/* Top right */
-0.5, -0.5, -0.5,
0.5, -0.5, -0.5,
0.5, -0.5, 0.5,
-0.5,
-0.5,
-0.5,
0.5,
-0.5,
-0.5,
0.5,
-0.5,
0.5,
};
const float _colors[] =
{
const float _colors[] = {
/* Front face */
/* Bottom left */
1.0, 0.0, 0.0, /* red */
@@ -387,32 +457,32 @@ const float _colors[] =
1.0, 0.0, 1.0, /* magenta */
};
const char* _shader_vert_src =
" attribute vec4 av4position; "
" attribute vec3 av3color; "
" uniform mat4 mvp; "
" varying vec3 vv3color; "
" void main() { "
" vv3color = av3color; "
" gl_Position = mvp * av4position; "
" } ";
const char *_shader_vert_src =
" attribute vec4 av4position; "
" attribute vec3 av3color; "
" uniform mat4 mvp; "
" varying vec3 vv3color; "
" void main() { "
" vv3color = av3color; "
" gl_Position = mvp * av4position; "
" } ";
const char* _shader_frag_src =
" precision lowp float; "
" varying vec3 vv3color; "
" void main() { "
" gl_FragColor = vec4(vv3color, 1.0); "
" } ";
const char *_shader_frag_src =
" precision lowp float; "
" varying vec3 vv3color; "
" void main() { "
" gl_FragColor = vec4(vv3color, 1.0); "
" } ";
static void
Render(unsigned int width, unsigned int height, shader_data* data)
Render(unsigned int width, unsigned int height, shader_data *data)
{
float matrix_rotate[16], matrix_modelview[16], matrix_perspective[16], matrix_mvp[16];
/*
* Do some rotation with Euler angles. It is not a fixed axis as
* quaterions would be, but the effect is cool.
*/
/*
* Do some rotation with Euler angles. It is not a fixed axis as
* quaterions would be, but the effect is cool.
*/
rotate_matrix((float)data->angle_x, 1.0f, 0.0f, 0.0f, matrix_modelview);
rotate_matrix((float)data->angle_y, 0.0f, 1.0f, 0.0f, matrix_rotate);
@@ -425,7 +495,7 @@ Render(unsigned int width, unsigned int height, shader_data* data)
/* Pull the camera back from the cube */
matrix_modelview[14] -= 2.5;
perspective_matrix(45.0f, (float)width/height, 0.01f, 100.0f, matrix_perspective);
perspective_matrix(45.0f, (float)width / height, 0.01f, 100.0f, matrix_perspective);
multiply_matrix(matrix_perspective, matrix_modelview, matrix_mvp);
GL_CHECK(ctx.glUniformMatrix4fv(data->attr_mvp, 1, GL_FALSE, matrix_mvp));
@@ -486,7 +556,7 @@ render_window(int index)
#ifndef __EMSCRIPTEN__
static int SDLCALL
render_thread_fn(void* render_ctx)
render_thread_fn(void *render_ctx)
{
thread_data *thread = render_ctx;
@@ -549,8 +619,7 @@ loop()
#endif
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int fsaa, accel, threaded;
int value;
@@ -615,11 +684,11 @@ main(int argc, char *argv[])
state->gl_profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
if (fsaa) {
state->gl_multisamplebuffers=1;
state->gl_multisamplesamples=fsaa;
state->gl_multisamplebuffers = 1;
state->gl_multisamplesamples = fsaa;
}
if (accel) {
state->gl_accelerated=1;
state->gl_accelerated = 1;
}
if (!SDLTest_CommonInit(state)) {
quit(2);
@@ -631,7 +700,7 @@ main(int argc, char *argv[])
SDL_Log("Out of memory!\n");
quit(2);
}
/* Create OpenGL ES contexts */
for (i = 0; i < state->num_windows; i++) {
context[i] = SDL_GL_CreateContext(state->windows[i]);
@@ -648,8 +717,6 @@ main(int argc, char *argv[])
return 0;
}
if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
SDL_GL_SetSwapInterval(1);
} else {
@@ -670,28 +737,28 @@ main(int argc, char *argv[])
if (!status) {
SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
} else {
SDL_Log( "Failed to get SDL_GL_RED_SIZE: %s\n",
SDL_Log("Failed to get SDL_GL_RED_SIZE: %s\n",
SDL_GetError());
}
status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
if (!status) {
SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
} else {
SDL_Log( "Failed to get SDL_GL_GREEN_SIZE: %s\n",
SDL_Log("Failed to get SDL_GL_GREEN_SIZE: %s\n",
SDL_GetError());
}
status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
if (!status) {
SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
} else {
SDL_Log( "Failed to get SDL_GL_BLUE_SIZE: %s\n",
SDL_Log("Failed to get SDL_GL_BLUE_SIZE: %s\n",
SDL_GetError());
}
status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
if (!status) {
SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value);
} else {
SDL_Log( "Failed to get SDL_GL_DEPTH_SIZE: %s\n",
SDL_Log("Failed to get SDL_GL_DEPTH_SIZE: %s\n",
SDL_GetError());
}
if (fsaa) {
@@ -699,15 +766,15 @@ main(int argc, char *argv[])
if (!status) {
SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
} else {
SDL_Log( "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
SDL_Log("Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
SDL_GetError());
}
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
if (!status) {
SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
value);
value);
} else {
SDL_Log( "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
SDL_Log("Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
SDL_GetError());
}
}
@@ -716,7 +783,7 @@ main(int argc, char *argv[])
if (!status) {
SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
} else {
SDL_Log( "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
SDL_Log("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
SDL_GetError());
}
}
@@ -738,7 +805,9 @@ main(int argc, char *argv[])
ctx.glViewport(0, 0, w, h);
data = &datas[i];
data->angle_x = 0; data->angle_y = 0; data->angle_z = 0;
data->angle_x = 0;
data->angle_y = 0;
data->angle_z = 0;
/* Shader Initialization */
process_shader(&data->shader_vert, _shader_vert_src, GL_VERTEX_SHADER);
@@ -792,7 +861,7 @@ main(int argc, char *argv[])
emscripten_set_main_loop(loop, 0, 1);
#else
if (threaded) {
threads = (thread_data*)SDL_calloc(state->num_windows, sizeof(thread_data));
threads = (thread_data *)SDL_calloc(state->num_windows, sizeof(thread_data));
/* Start a render thread for each window */
for (i = 0; i < state->num_windows; ++i) {
@@ -822,7 +891,7 @@ main(int argc, char *argv[])
now = SDL_GetTicks();
if (now > then) {
SDL_Log("%2.2f frames per second\n",
((double) frames * 1000) / (now - then));
((double)frames * 1000) / (now - then));
}
#if !defined(__ANDROID__) && !defined(__NACL__)
quit(0);
@@ -832,8 +901,7 @@ main(int argc, char *argv[])
#else /* HAVE_OPENGLES2 */
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
SDL_Log("No OpenGL ES support on this system\n");
return 1;

View File

@@ -31,12 +31,11 @@
typedef struct GLES2_Context
{
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
#define SDL_PROC(ret, func, params) ret(APIENTRY *func) params;
#include "../src/render/opengles2/SDL_gles2funcs.h"
#undef SDL_PROC
} GLES2_Context;
static SDL_Surface *g_surf_sdf = NULL;
GLenum g_texture;
GLenum g_texture_type = GL_TEXTURE_2D;
@@ -59,14 +58,12 @@ typedef enum
GLuint g_uniform_locations[16];
static SDLTest_CommonState *state;
static SDL_GLContext *context = NULL;
static int depth = 16;
static GLES2_Context ctx;
static int LoadContext(GLES2_Context * data)
static int LoadContext(GLES2_Context *data)
{
#if SDL_VIDEO_DRIVER_UIKIT
#define __SDL_NOGETPROCADDR__
@@ -77,15 +74,15 @@ static int LoadContext(GLES2_Context * data)
#endif
#if defined __SDL_NOGETPROCADDR__
#define SDL_PROC(ret,func,params) data->func=func;
#define SDL_PROC(ret, func, params) data->func = func;
#else
#define SDL_PROC(ret,func,params) \
do { \
data->func = SDL_GL_GetProcAddress(#func); \
if ( ! data->func ) { \
#define SDL_PROC(ret, func, params) \
do { \
data->func = SDL_GL_GetProcAddress(#func); \
if (!data->func) { \
return SDL_SetError("Couldn't load GLES2 function %s: %s", #func, SDL_GetError()); \
} \
} while ( 0 );
} \
} while (0);
#endif /* __SDL_NOGETPROCADDR__ */
#include "../src/render/opengles2/SDL_gles2funcs.h"
@@ -113,18 +110,17 @@ quit(int rc)
exit(rc);
}
#define GL_CHECK(x) \
x; \
{ \
GLenum glError = ctx.glGetError(); \
if (glError != GL_NO_ERROR) { \
#define GL_CHECK(x) \
x; \
{ \
GLenum glError = ctx.glGetError(); \
if (glError != GL_NO_ERROR) { \
SDL_Log("glGetError() = %i (0x%.8x) at line %i\n", glError, glError, __LINE__); \
quit(1); \
} \
}
quit(1); \
} \
}
/*
/*
* Create shader, load in source, compile, dump debug as necessary.
*
* shader: Pointer to return created shader ID.
@@ -242,16 +238,12 @@ static const char *GLES2_FragmentSrc_TextureABGRSrc_SDF_dbg = " \
} \
";
static float g_val = 1.0f;
static int g_use_SDF = 1;
static int g_use_SDF_debug = 0;
static int g_use_SDF = 1;
static int g_use_SDF_debug = 0;
static float g_angle = 0.0f;
static float matrix_mvp[4][4];
typedef struct shader_data
{
GLuint shader_program, shader_frag, shader_vert;
@@ -272,15 +264,14 @@ Render(unsigned int width, unsigned int height, shader_data* data)
GL_CHECK(ctx.glUniformMatrix4fv(g_uniform_locations[GLES2_UNIFORM_PROJECTION], 1, GL_FALSE, (const float *)matrix_mvp));
GL_CHECK(ctx.glUniform4f(g_uniform_locations[GLES2_UNIFORM_COLOR], 1.0f, 1.0f, 1.0f, 1.0f));
GL_CHECK(ctx.glVertexAttribPointer(GLES2_ATTRIBUTE_ANGLE, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *) (verts + 16)));
GL_CHECK(ctx.glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *) (verts + 8)));
GL_CHECK(ctx.glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *) verts));
GL_CHECK(ctx.glVertexAttribPointer(GLES2_ATTRIBUTE_ANGLE, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *)(verts + 16)));
GL_CHECK(ctx.glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *)(verts + 8)));
GL_CHECK(ctx.glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *)verts));
GL_CHECK(ctx.glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
}
void renderCopy_angle(float degree_angle)
void renderCopy_angle(float degree_angle)
{
const float radian_angle = (float)(3.141592 * degree_angle) / 180.0;
const GLfloat s = (GLfloat) SDL_sin(radian_angle);
@@ -296,8 +287,7 @@ void renderCopy_angle(float degree_angle)
*(verts++) = c;
}
void renderCopy_position(SDL_Rect *srcrect, SDL_Rect *dstrect)
void renderCopy_position(SDL_Rect *srcrect, SDL_Rect *dstrect)
{
GLfloat minx, miny, maxx, maxy;
GLfloat minu, maxu, minv, maxv;
@@ -347,8 +337,8 @@ void loop()
while (SDL_PollEvent(&event) && !done) {
switch (event.type) {
case SDL_KEYDOWN:
{
const int sym = event.key.keysym.sym;
{
const int sym = event.key.keysym.sym;
if (sym == SDLK_TAB) {
SDL_Log("Tab");
@@ -374,35 +364,50 @@ void loop()
break;
}
if (sym == SDLK_LEFT) {
g_val -= 0.05f;
}
if (sym == SDLK_RIGHT) {
g_val += 0.05f;
}
if (sym == SDLK_UP) {
g_angle -= 1.0f;
}
if (sym == SDLK_DOWN) {
g_angle += 1.0f;
}
break;
}
case SDL_WINDOWEVENT:
switch (event.window.event) {
case SDL_WINDOWEVENT_RESIZED:
for (i = 0; i < state->num_windows; ++i) {
if (event.window.windowID == SDL_GetWindowID(state->windows[i])) {
int w, h;
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
if (status) {
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
break;
}
/* Change view port to the new window dimensions */
SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
ctx.glViewport(0, 0, w, h);
state->window_w = event.window.data1;
state->window_h = event.window.data2;
/* Update window content */
Render(event.window.data1, event.window.data2, &datas[i]);
SDL_GL_SwapWindow(state->windows[i]);
case SDL_WINDOWEVENT_RESIZED:
for (i = 0; i < state->num_windows; ++i) {
if (event.window.windowID == SDL_GetWindowID(state->windows[i])) {
int w, h;
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
if (status) {
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
break;
}
/* Change view port to the new window dimensions */
SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
ctx.glViewport(0, 0, w, h);
state->window_w = event.window.data1;
state->window_h = event.window.data2;
/* Update window content */
Render(event.window.data1, event.window.data2, &datas[i]);
SDL_GL_SwapWindow(state->windows[i]);
break;
}
break;
}
break;
}
}
SDLTest_CommonEvent(state, &event, &done);
}
matrix_mvp[3][0] = -1.0f;
matrix_mvp[3][3] = 1.0f;
@@ -433,20 +438,19 @@ void loop()
rd.x = (w - rd.w) / 2; rd.y = (h - rd.h) / 2;
renderCopy_position(&rs, &rd);
}
if (!done) {
for (i = 0; i < state->num_windows; ++i) {
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
if (status) {
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
for (i = 0; i < state->num_windows; ++i) {
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
if (status) {
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
/* Continue for next window */
continue;
}
Render(state->window_w, state->window_h, &datas[i]);
SDL_GL_SwapWindow(state->windows[i]);
}
/* Continue for next window */
continue;
}
Render(state->window_w, state->window_h, &datas[i]);
SDL_GL_SwapWindow(state->windows[i]);
}
}
#ifdef __EMSCRIPTEN__
else {
@@ -455,8 +459,7 @@ void loop()
#endif
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int fsaa, accel;
int value;
@@ -518,11 +521,11 @@ main(int argc, char *argv[])
state->gl_profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
if (fsaa) {
state->gl_multisamplebuffers=1;
state->gl_multisamplesamples=fsaa;
state->gl_multisamplebuffers = 1;
state->gl_multisamplesamples = fsaa;
}
if (accel) {
state->gl_accelerated=1;
state->gl_accelerated = 1;
}
if (!SDLTest_CommonInit(state)) {
quit(2);
@@ -534,7 +537,7 @@ main(int argc, char *argv[])
SDL_Log("Out of memory!\n");
quit(2);
}
/* Create OpenGL ES contexts */
for (i = 0; i < state->num_windows; i++) {
context[i] = SDL_GL_CreateContext(state->windows[i]);
@@ -551,8 +554,8 @@ main(int argc, char *argv[])
return 0;
}
SDL_memset(matrix_mvp, 0, sizeof (matrix_mvp));
SDL_memset(matrix_mvp, 0, sizeof(matrix_mvp));
{
SDL_Surface *tmp;
char *f;
@@ -564,7 +567,7 @@ main(int argc, char *argv[])
} else {
f = "testgles2_sdf_img_normal.bmp";
}
SDL_Log("SDF is %s", g_use_SDF ? "enabled" : "disabled");
/* Load SDF BMP image */
@@ -592,10 +595,10 @@ main(int argc, char *argv[])
#else
/* Generate SDF image using SDL_ttf */
#include "SDL_ttf.h"
#include "SDL_ttf.h"
char *font_file = "./font/DroidSansFallback.ttf";
char *str = "Abcde";
SDL_Color color = { 0, 0,0, 255};
SDL_Color color = { 0, 0, 0, 255 };
TTF_Init();
TTF_Font *font = TTF_OpenFont(font_file, 72);
@@ -623,7 +626,6 @@ main(int argc, char *argv[])
SDL_SetSurfaceBlendMode(g_surf_sdf, SDL_BLENDMODE_BLEND);
}
if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
SDL_GL_SetSwapInterval(1);
} else {
@@ -643,28 +645,28 @@ main(int argc, char *argv[])
if (!status) {
SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
} else {
SDL_Log( "Failed to get SDL_GL_RED_SIZE: %s\n",
SDL_Log("Failed to get SDL_GL_RED_SIZE: %s\n",
SDL_GetError());
}
status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
if (!status) {
SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
} else {
SDL_Log( "Failed to get SDL_GL_GREEN_SIZE: %s\n",
SDL_Log("Failed to get SDL_GL_GREEN_SIZE: %s\n",
SDL_GetError());
}
status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
if (!status) {
SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
} else {
SDL_Log( "Failed to get SDL_GL_BLUE_SIZE: %s\n",
SDL_Log("Failed to get SDL_GL_BLUE_SIZE: %s\n",
SDL_GetError());
}
status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
if (!status) {
SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value);
} else {
SDL_Log( "Failed to get SDL_GL_DEPTH_SIZE: %s\n",
SDL_Log("Failed to get SDL_GL_DEPTH_SIZE: %s\n",
SDL_GetError());
}
if (fsaa) {
@@ -672,15 +674,15 @@ main(int argc, char *argv[])
if (!status) {
SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
} else {
SDL_Log( "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
SDL_Log("Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
SDL_GetError());
}
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
if (!status) {
SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
value);
value);
} else {
SDL_Log( "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
SDL_Log("Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
SDL_GetError());
}
}
@@ -689,7 +691,7 @@ main(int argc, char *argv[])
if (!status) {
SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
} else {
SDL_Log( "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
SDL_Log("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
SDL_GetError());
}
}
@@ -728,7 +730,6 @@ main(int argc, char *argv[])
GL_CHECK(ctx.glTexSubImage2D(g_texture_type, 0, 0 /* xoffset */, 0 /* yoffset */, g_surf_sdf->w, g_surf_sdf->h, format, type, g_surf_sdf->pixels));
}
SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
ctx.glViewport(0, 0, w, h);
@@ -767,23 +768,20 @@ main(int argc, char *argv[])
GL_CHECK(ctx.glUseProgram(data->shader_program));
ctx.glEnableVertexAttribArray((GLenum) GLES2_ATTRIBUTE_ANGLE);
ctx.glDisableVertexAttribArray((GLenum) GLES2_ATTRIBUTE_CENTER);
ctx.glEnableVertexAttribArray((GLenum)GLES2_ATTRIBUTE_ANGLE);
ctx.glDisableVertexAttribArray((GLenum)GLES2_ATTRIBUTE_CENTER);
ctx.glEnableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
ctx.glEnableVertexAttribArray((GLenum) GLES2_ATTRIBUTE_TEXCOORD);
ctx.glUniform1i(g_uniform_locations[GLES2_UNIFORM_TEXTURE], 0); /* always texture unit 0. */
ctx.glActiveTexture(GL_TEXTURE0);
ctx.glBindTexture(g_texture_type, g_texture);
GL_CHECK(ctx.glClearColor(1, 1, 1, 1));
// SDL_BLENDMODE_BLEND
GL_CHECK(ctx.glEnable(GL_BLEND));
ctx.glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
ctx.glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
ctx.glEnableVertexAttribArray((GLenum)GLES2_ATTRIBUTE_TEXCOORD);
ctx.glUniform1i(g_uniform_locations[GLES2_UNIFORM_TEXTURE], 0); /* always texture unit 0. */
ctx.glActiveTexture(GL_TEXTURE0);
ctx.glBindTexture(g_texture_type, g_texture);
GL_CHECK(ctx.glClearColor(1, 1, 1, 1));
// SDL_BLENDMODE_BLEND
GL_CHECK(ctx.glEnable(GL_BLEND));
ctx.glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
ctx.glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
}
/* Main render loop */
@@ -803,7 +801,7 @@ main(int argc, char *argv[])
now = SDL_GetTicks();
if (now > then) {
SDL_Log("%2.2f frames per second\n",
((double) frames * 1000) / (now - then));
((double)frames * 1000) / (now - then));
}
#if !defined(__ANDROID__) && !defined(__NACL__)
quit(0);
@@ -813,8 +811,7 @@ main(int argc, char *argv[])
#else /* HAVE_OPENGLES2 */
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
SDL_Log("No OpenGL ES support on this system\n");
return 1;

View File

@@ -20,21 +20,18 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
static SDL_Haptic *haptic;
/*
* prototypes
*/
static void abort_execution(void);
static void HapticPrintSupported(SDL_Haptic *);
/**
* @brief The entry point of this force feedback demo.
* @param[in] argc Number of arguments.
* @param[in] argv Array of argc arguments.
*/
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
int i;
char *name;
@@ -53,9 +50,9 @@ main(int argc, char **argv)
name = argv[1];
if ((SDL_strcmp(name, "--help") == 0) || (SDL_strcmp(name, "-h") == 0)) {
SDL_Log("USAGE: %s [device]\n"
"If device is a two-digit number it'll use it as an index, otherwise\n"
"it'll use it as if it were part of the device's name.\n",
argv[0]);
"If device is a two-digit number it'll use it as an index, otherwise\n"
"it'll use it as if it were part of the device's name.\n",
argv[0]);
return 0;
}
@@ -85,7 +82,7 @@ main(int argc, char **argv)
if (i >= SDL_NumHaptics()) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n",
name);
name);
return 1;
}
}
@@ -93,7 +90,7 @@ main(int argc, char **argv)
haptic = SDL_HapticOpen(i);
if (haptic == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n",
SDL_GetError());
SDL_GetError());
return 1;
}
SDL_Log("Device: %s\n", SDL_HapticName(i));
@@ -117,8 +114,8 @@ main(int argc, char **argv)
SDL_Log(" effect %d: Sine Wave\n", nefx);
efx[nefx].type = SDL_HAPTIC_SINE;
efx[nefx].periodic.period = 1000;
efx[nefx].periodic.magnitude = -0x2000; /* Negative magnitude and ... */
efx[nefx].periodic.phase = 18000; /* ... 180 degrees phase shift => cancel eachother */
efx[nefx].periodic.magnitude = -0x2000; /* Negative magnitude and ... */
efx[nefx].periodic.phase = 18000; /* ... 180 degrees phase shift => cancel eachother */
efx[nefx].periodic.length = 5000;
efx[nefx].periodic.attack_length = 1000;
efx[nefx].periodic.fade_length = 1000;
@@ -145,13 +142,13 @@ main(int argc, char **argv)
}
nefx++;
}
/* Now the classical constant effect. */
if (supported & SDL_HAPTIC_CONSTANT) {
SDL_Log(" effect %d: Constant Force\n", nefx);
efx[nefx].type = SDL_HAPTIC_CONSTANT;
efx[nefx].constant.direction.type = SDL_HAPTIC_POLAR;
efx[nefx].constant.direction.dir[0] = 20000; /* Force comes from the south-west. */
efx[nefx].constant.direction.dir[0] = 20000; /* Force comes from the south-west. */
efx[nefx].constant.length = 5000;
efx[nefx].constant.level = 0x6000;
efx[nefx].constant.attack_length = 1000;
@@ -163,7 +160,7 @@ main(int argc, char **argv)
}
nefx++;
}
/* The cute spring effect. */
if (supported & SDL_HAPTIC_SPRING) {
SDL_Log(" effect %d: Condition Spring\n", nefx);
@@ -174,7 +171,7 @@ main(int argc, char **argv)
efx[nefx].condition.left_sat[i] = 0xFFFF;
efx[nefx].condition.right_coeff[i] = 0x2000;
efx[nefx].condition.left_coeff[i] = 0x2000;
efx[nefx].condition.center[i] = 0x1000; /* Displace the center for it to move. */
efx[nefx].condition.center[i] = 0x1000; /* Displace the center for it to move. */
}
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
if (id[nefx] < 0) {
@@ -211,7 +208,7 @@ main(int argc, char **argv)
efx[nefx].condition.left_sat[i] = 0xFFFF;
efx[nefx].condition.right_coeff[i] = 0x2000;
efx[nefx].condition.left_coeff[i] = 0x2000;
efx[nefx].condition.deadband[i] = 0x1000; /* 1/16th of axis-range around the center is 'dead'. */
efx[nefx].condition.deadband[i] = 0x1000; /* 1/16th of axis-range around the center is 'dead'. */
}
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
if (id[nefx] < 0) {
@@ -238,14 +235,14 @@ main(int argc, char **argv)
}
nefx++;
}
/* Now we'll try a ramp effect */
if (supported & SDL_HAPTIC_RAMP) {
SDL_Log(" effect %d: Ramp\n", nefx);
efx[nefx].type = SDL_HAPTIC_RAMP;
efx[nefx].ramp.direction.type = SDL_HAPTIC_CARTESIAN;
efx[nefx].ramp.direction.dir[0] = 1; /* Force comes from */
efx[nefx].ramp.direction.dir[1] = -1; /* the north-east. */
efx[nefx].ramp.direction.dir[0] = 1; /* Force comes from */
efx[nefx].ramp.direction.dir[1] = -1; /* the north-east. */
efx[nefx].ramp.length = 5000;
efx[nefx].ramp.start = 0x4000;
efx[nefx].ramp.end = -0x4000;
@@ -274,13 +271,11 @@ main(int argc, char **argv)
nefx++;
}
SDL_Log
("\nNow playing effects for 5 seconds each with 1 second delay between\n");
SDL_Log("\nNow playing effects for 5 seconds each with 1 second delay between\n");
for (i = 0; i < nefx; i++) {
SDL_Log(" Playing effect %d\n", i);
SDL_HapticRunEffect(haptic, id[i], 1);
SDL_Delay(6000); /* Effects only have length 5000 */
SDL_Delay(6000); /* Effects only have length 5000 */
}
/* Quit */
@@ -292,7 +287,6 @@ main(int argc, char **argv)
return 0;
}
/*
* Cleans up a bit.
*/
@@ -307,18 +301,17 @@ abort_execution(void)
exit(1);
}
/*
* Displays information about the haptic device.
*/
static void
HapticPrintSupported(SDL_Haptic * ptr)
HapticPrintSupported(SDL_Haptic *ptr)
{
unsigned int supported;
supported = SDL_HapticQuery(ptr);
SDL_Log(" Supported effects [%d effects, %d playing]:\n",
SDL_HapticNumEffects(ptr), SDL_HapticNumEffectsPlaying(ptr));
SDL_HapticNumEffects(ptr), SDL_HapticNumEffectsPlaying(ptr));
if (supported & SDL_HAPTIC_CONSTANT) {
SDL_Log(" constant\n");
}

View File

@@ -29,9 +29,10 @@ hitTest(SDL_Window *window, const SDL_Point *pt, void *data)
SDL_GetWindowSize(window, &w, &h);
#define REPORT_RESIZE_HIT(name) { \
#define REPORT_RESIZE_HIT(name) \
{ \
SDL_Log("HIT-TEST: RESIZE_" #name "\n"); \
return SDL_HITTEST_RESIZE_##name; \
return SDL_HITTEST_RESIZE_##name; \
}
if (pt->x < RESIZE_BORDER && pt->y < RESIZE_BORDER) {
@@ -56,7 +57,6 @@ hitTest(SDL_Window *window, const SDL_Point *pt, void *data)
return SDL_HITTEST_NORMAL;
}
int main(int argc, char **argv)
{
int done = 0;
@@ -87,39 +87,38 @@ int main(int argc, char **argv)
while (SDL_PollEvent(&e)) {
nothing_to_do = 0;
switch (e.type)
{
case SDL_MOUSEBUTTONDOWN:
SDL_Log("button down!\n");
break;
switch (e.type) {
case SDL_MOUSEBUTTONDOWN:
SDL_Log("button down!\n");
break;
case SDL_MOUSEBUTTONUP:
SDL_Log("button up!\n");
break;
case SDL_MOUSEBUTTONUP:
SDL_Log("button up!\n");
break;
case SDL_WINDOWEVENT:
if (e.window.event == SDL_WINDOWEVENT_MOVED) {
SDL_Log("Window event moved to (%d, %d)!\n", (int) e.window.data1, (int) e.window.data2);
}
break;
case SDL_WINDOWEVENT:
if (e.window.event == SDL_WINDOWEVENT_MOVED) {
SDL_Log("Window event moved to (%d, %d)!\n", (int)e.window.data1, (int)e.window.data2);
}
break;
case SDL_KEYDOWN:
if (e.key.keysym.sym == SDLK_ESCAPE) {
done = 1;
} else if (e.key.keysym.sym == SDLK_x) {
if (areas == NULL) {
areas = drag_areas;
numareas = SDL_arraysize(drag_areas);
} else {
areas = NULL;
numareas = 0;
}
}
break;
case SDL_QUIT:
case SDL_KEYDOWN:
if (e.key.keysym.sym == SDLK_ESCAPE) {
done = 1;
break;
} else if (e.key.keysym.sym == SDLK_x) {
if (areas == NULL) {
areas = drag_areas;
numareas = SDL_arraysize(drag_areas);
} else {
areas = NULL;
numareas = 0;
}
}
break;
case SDL_QUIT:
done = 1;
break;
}
}

View File

@@ -20,8 +20,7 @@
#if !defined SDL_JOYSTICK_DISABLED && !defined SDL_HAPTIC_DISABLED
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
SDL_Joystick *joystick = NULL;
SDL_Haptic *haptic = NULL;
@@ -30,7 +29,7 @@ main(int argc, char *argv[])
int i;
SDL_bool enable_haptic = SDL_TRUE;
Uint32 init_subsystems = SDL_INIT_VIDEO | SDL_INIT_JOYSTICK;
for (i = 1; i < argc; ++i) {
if (SDL_strcasecmp(argv[i], "--nohaptic") == 0) {
enable_haptic = SDL_FALSE;
@@ -40,7 +39,7 @@ main(int argc, char *argv[])
if (enable_haptic) {
init_subsystems |= SDL_INIT_HAPTIC;
}
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
@@ -64,72 +63,71 @@ main(int argc, char *argv[])
while (keepGoing) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch(event.type)
{
case SDL_QUIT:
keepGoing = SDL_FALSE;
break;
case SDL_JOYDEVICEADDED:
if (joystick != NULL) {
SDL_Log("Only one joystick supported by this test\n");
} 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)) {
haptic = SDL_HapticOpenFromJoystick(joystick);
if (haptic) {
SDL_Log("Joy Haptic Opened\n");
if (SDL_HapticRumbleInit( haptic ) != 0) {
SDL_Log("Could not init Rumble!: %s\n", SDL_GetError());
SDL_HapticClose(haptic);
haptic = NULL;
}
} else {
SDL_Log("Joy haptic open FAILED!: %s\n", SDL_GetError());
switch (event.type) {
case SDL_QUIT:
keepGoing = SDL_FALSE;
break;
case SDL_JOYDEVICEADDED:
if (joystick != NULL) {
SDL_Log("Only one joystick supported by this test\n");
} 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)) {
haptic = SDL_HapticOpenFromJoystick(joystick);
if (haptic) {
SDL_Log("Joy Haptic Opened\n");
if (SDL_HapticRumbleInit(haptic) != 0) {
SDL_Log("Could not init Rumble!: %s\n", SDL_GetError());
SDL_HapticClose(haptic);
haptic = NULL;
}
} else {
SDL_Log("No haptic found\n");
SDL_Log("Joy haptic open FAILED!: %s\n", SDL_GetError());
}
} else {
SDL_Log("No haptic found\n");
}
}
break;
case SDL_JOYDEVICEREMOVED:
if (instance == event.jdevice.which) {
SDL_Log("Joy Removed: %" SDL_PRIs32 "\n", event.jdevice.which);
instance = -1;
if (enable_haptic && haptic) {
SDL_HapticClose(haptic);
haptic = NULL;
}
SDL_JoystickClose(joystick);
joystick = NULL;
} else {
SDL_Log("Unknown joystick diconnected\n");
}
break;
case SDL_JOYAXISMOTION:
/*
// SDL_Log("Axis Move: %d\n", event.jaxis.axis);
*/
if (enable_haptic) {
SDL_HapticRumblePlay(haptic, 0.25, 250);
}
break;
case SDL_JOYBUTTONDOWN:
SDL_Log("Button Press: %d\n", event.jbutton.button);
}
break;
case SDL_JOYDEVICEREMOVED:
if (instance == event.jdevice.which) {
SDL_Log("Joy Removed: %" SDL_PRIs32 "\n", event.jdevice.which);
instance = -1;
if (enable_haptic && haptic) {
SDL_HapticRumblePlay(haptic, 0.25, 250);
SDL_HapticClose(haptic);
haptic = NULL;
}
if (event.jbutton.button == 0) {
SDL_Log("Exiting due to button press of button 0\n");
keepGoing = SDL_FALSE;
}
break;
case SDL_JOYBUTTONUP:
SDL_Log("Button Release: %d\n", event.jbutton.button);
break;
SDL_JoystickClose(joystick);
joystick = NULL;
} else {
SDL_Log("Unknown joystick diconnected\n");
}
break;
case SDL_JOYAXISMOTION:
/*
// SDL_Log("Axis Move: %d\n", event.jaxis.axis);
*/
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) {
SDL_HapticRumblePlay(haptic, 0.25, 250);
}
if (event.jbutton.button == 0) {
SDL_Log("Exiting due to button press of button 0\n");
keepGoing = SDL_FALSE;
}
break;
case SDL_JOYBUTTONUP:
SDL_Log("Button Release: %d\n", event.jbutton.button);
break;
}
}
}

View File

@@ -12,7 +12,7 @@
/* quiet windows compiler warnings */
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
# define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdio.h>
@@ -24,15 +24,14 @@ static size_t
widelen(char *data)
{
size_t len = 0;
Uint32 *p = (Uint32 *) data;
Uint32 *p = (Uint32 *)data;
while (*p++) {
++len;
}
return len;
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
const char *formats[] = {
"UTF8",
@@ -49,7 +48,7 @@ main(int argc, char *argv[])
"UCS-4",
};
char * fname;
char *fname;
char buffer[BUFSIZ];
char *ucs4;
char *test[2];

View File

@@ -42,30 +42,31 @@
static SDLTest_CommonState *state;
static SDL_Rect textRect, markedRect;
static SDL_Color lineColor = {0,0,0,255};
static SDL_Color backColor = {255,255,255,255};
static SDL_Color textColor = {0,0,0,255};
static SDL_Color lineColor = { 0, 0, 0, 255 };
static SDL_Color backColor = { 255, 255, 255, 255 };
static SDL_Color textColor = { 0, 0, 0, 255 };
static char text[MAX_TEXT_LENGTH], markedText[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
static int cursor = 0;
#ifdef HAVE_SDL_TTF
static TTF_Font *font;
#else
#define UNIFONT_MAX_CODEPOINT 0x1ffff
#define UNIFONT_NUM_GLYPHS 0x20000
#define UNIFONT_MAX_CODEPOINT 0x1ffff
#define UNIFONT_NUM_GLYPHS 0x20000
/* Using 512x512 textures that are supported everywhere. */
#define UNIFONT_TEXTURE_WIDTH 512
#define UNIFONT_GLYPHS_IN_ROW (UNIFONT_TEXTURE_WIDTH / 16)
#define UNIFONT_TEXTURE_WIDTH 512
#define UNIFONT_GLYPHS_IN_ROW (UNIFONT_TEXTURE_WIDTH / 16)
#define UNIFONT_GLYPHS_IN_TEXTURE (UNIFONT_GLYPHS_IN_ROW * UNIFONT_GLYPHS_IN_ROW)
#define UNIFONT_NUM_TEXTURES ((UNIFONT_NUM_GLYPHS + UNIFONT_GLYPHS_IN_TEXTURE - 1) / UNIFONT_GLYPHS_IN_TEXTURE)
#define UNIFONT_TEXTURE_SIZE (UNIFONT_TEXTURE_WIDTH * UNIFONT_TEXTURE_WIDTH * 4)
#define UNIFONT_TEXTURE_PITCH (UNIFONT_TEXTURE_WIDTH * 4)
#define UNIFONT_DRAW_SCALE 2
struct UnifontGlyph {
#define UNIFONT_NUM_TEXTURES ((UNIFONT_NUM_GLYPHS + UNIFONT_GLYPHS_IN_TEXTURE - 1) / UNIFONT_GLYPHS_IN_TEXTURE)
#define UNIFONT_TEXTURE_SIZE (UNIFONT_TEXTURE_WIDTH * UNIFONT_TEXTURE_WIDTH * 4)
#define UNIFONT_TEXTURE_PITCH (UNIFONT_TEXTURE_WIDTH * 4)
#define UNIFONT_DRAW_SCALE 2
struct UnifontGlyph
{
Uint8 width;
Uint8 data[32];
} *unifontGlyph;
} * unifontGlyph;
static SDL_Texture **unifontTexture;
static Uint8 unifontTextureLoaded[UNIFONT_NUM_TEXTURES] = {0};
static Uint8 unifontTextureLoaded[UNIFONT_NUM_TEXTURES] = { 0 };
/* Unifont loading code start */
@@ -151,7 +152,7 @@ static int unifont_init(const char *fontname)
bytesRead = SDL_RWread(hexFile, hexBuffer, 1, 9);
if (numGlyphs > 0 && bytesRead == 0) {
break; /* EOF */
}
}
if ((numGlyphs == 0 && bytesRead == 0) || (numGlyphs > 0 && bytesRead < 9)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Unexpected end of hex file.\n");
return -1;
@@ -259,7 +260,7 @@ static void unifont_make_rgba(Uint8 *src, Uint8 *dst, Uint8 width)
static int unifont_load_texture(Uint32 textureID)
{
int i;
Uint8 * textureRGBA;
Uint8 *textureRGBA;
if (textureID >= UNIFONT_NUM_TEXTURES) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Tried to load out of range texture %" SDL_PRIu32 "\n", textureID);
@@ -363,7 +364,7 @@ size_t utf8_length(unsigned char c)
c = (unsigned char)(0xff & c);
if (c < 0x80)
return 1;
else if ((c >> 5) ==0x6)
else if ((c >> 5) == 0x6)
return 2;
else if ((c >> 4) == 0xe)
return 3;
@@ -455,13 +456,13 @@ void CleanupVideo()
void _Redraw(int rendererID)
{
SDL_Renderer * renderer = state->renderers[rendererID];
SDL_Renderer *renderer = state->renderers[rendererID];
SDL_Rect drawnTextRect, cursorRect, underlineRect;
drawnTextRect = textRect;
drawnTextRect.w = 0;
SDL_SetRenderDrawColor(renderer, backColor.r, backColor.g, backColor.b, backColor.a);
SDL_RenderFillRect(renderer,&textRect);
SDL_RenderFillRect(renderer, &textRect);
if (*text) {
#ifdef HAVE_SDL_TTF
@@ -473,10 +474,10 @@ void _Redraw(int rendererID)
drawnTextRect.w = textSur->w;
drawnTextRect.h = textSur->h;
texture = SDL_CreateTextureFromSurface(renderer,textSur);
texture = SDL_CreateTextureFromSurface(renderer, textSur);
SDL_FreeSurface(textSur);
SDL_RenderCopy(renderer,texture,NULL,&drawnTextRect);
SDL_RenderCopy(renderer, texture, NULL, &drawnTextRect);
SDL_DestroyTexture(texture);
#else
char *utext = text;
@@ -519,7 +520,7 @@ void _Redraw(int rendererID)
drawnTextRect.w = 0;
SDL_SetRenderDrawColor(renderer, backColor.r, backColor.g, backColor.b, backColor.a);
SDL_RenderFillRect(renderer,&markedRect);
SDL_RenderFillRect(renderer, &markedRect);
if (markedText[0]) {
#ifdef HAVE_SDL_TTF
@@ -544,10 +545,10 @@ void _Redraw(int rendererID)
drawnTextRect.w = textSur->w;
drawnTextRect.h = textSur->h;
texture = SDL_CreateTextureFromSurface(renderer,textSur);
texture = SDL_CreateTextureFromSurface(renderer, textSur);
SDL_FreeSurface(textSur);
SDL_RenderCopy(renderer,texture,NULL,&drawnTextRect);
SDL_RenderCopy(renderer, texture, NULL, &drawnTextRect);
SDL_DestroyTexture(texture);
#else
int i = 0;
@@ -590,7 +591,7 @@ void _Redraw(int rendererID)
}
SDL_SetRenderDrawColor(renderer, lineColor.r, lineColor.g, lineColor.b, lineColor.a);
SDL_RenderFillRect(renderer,&cursorRect);
SDL_RenderFillRect(renderer, &cursorRect);
SDL_SetTextInputRect(&markedRect);
}
@@ -627,7 +628,7 @@ int main(int argc, char *argv[])
if (state == NULL) {
return 1;
}
for (i = 1; i < argc;i++) {
for (i = 1; i < argc; i++) {
SDLTest_CommonArg(state, i);
}
for (argc--, argv++; argc > 0; argc--, argv++) {
@@ -653,7 +654,6 @@ int main(int argc, char *argv[])
return 2;
}
#ifdef HAVE_SDL_TTF
/* Initialize fonts */
TTF_Init();
@@ -686,86 +686,84 @@ int main(int argc, char *argv[])
/* Check for events */
while (SDL_PollEvent(&event)) {
SDLTest_CommonEvent(state, &event, &done);
switch(event.type) {
case SDL_KEYDOWN: {
switch (event.key.keysym.sym)
{
case SDLK_RETURN:
text[0]=0x00;
Redraw();
break;
case SDLK_BACKSPACE:
/* Only delete text if not in editing mode. */
if (!markedText[0]) {
size_t textlen = SDL_strlen(text);
do {
if (textlen==0) {
break;
}
if ((text[textlen-1] & 0x80) == 0x00) {
/* One byte */
text[textlen-1]=0x00;
break;
}
if ((text[textlen-1] & 0xC0) == 0x80) {
/* Byte from the multibyte sequence */
text[textlen-1]=0x00;
textlen--;
}
if ((text[textlen-1] & 0xC0) == 0xC0) {
/* First byte of multibyte sequence */
text[textlen-1]=0x00;
break;
}
} while (1);
Redraw();
}
break;
}
if (done) {
break;
}
SDL_Log("Keyboard: scancode 0x%08X = %s, keycode 0x%08" SDL_PRIX32 " = %s\n",
event.key.keysym.scancode,
SDL_GetScancodeName(event.key.keysym.scancode),
SDL_static_cast(Uint32, event.key.keysym.sym),
SDL_GetKeyName(event.key.keysym.sym));
break;
case SDL_TEXTINPUT:
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)) {
SDL_strlcat(text, event.text.text, sizeof(text));
}
SDL_Log("text inputed: %s\n", text);
/* After text inputed, we can clear up markedText because it */
/* is committed */
markedText[0] = 0;
switch (event.type) {
case SDL_KEYDOWN:
{
switch (event.key.keysym.sym) {
case SDLK_RETURN:
text[0] = 0x00;
Redraw();
break;
case SDLK_BACKSPACE:
/* Only delete text if not in editing mode. */
if (!markedText[0]) {
size_t textlen = SDL_strlen(text);
case SDL_TEXTEDITING:
SDL_Log("text editing \"%s\", selected range (%" SDL_PRIs32 ", %" SDL_PRIs32 ")\n",
event.edit.text, event.edit.start, event.edit.length);
do {
if (textlen == 0) {
break;
}
if ((text[textlen - 1] & 0x80) == 0x00) {
/* One byte */
text[textlen - 1] = 0x00;
break;
}
if ((text[textlen - 1] & 0xC0) == 0x80) {
/* Byte from the multibyte sequence */
text[textlen - 1] = 0x00;
textlen--;
}
if ((text[textlen - 1] & 0xC0) == 0xC0) {
/* First byte of multibyte sequence */
text[textlen - 1] = 0x00;
break;
}
} while (1);
SDL_strlcpy(markedText, event.edit.text, SDL_TEXTEDITINGEVENT_TEXT_SIZE);
cursor = event.edit.start;
Redraw();
Redraw();
}
break;
}
if (done) {
break;
}
SDL_Log("Keyboard: scancode 0x%08X = %s, keycode 0x%08" SDL_PRIX32 " = %s\n",
event.key.keysym.scancode,
SDL_GetScancodeName(event.key.keysym.scancode),
SDL_static_cast(Uint32, event.key.keysym.sym),
SDL_GetKeyName(event.key.keysym.sym));
break;
case SDL_TEXTINPUT:
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)) {
SDL_strlcat(text, event.text.text, sizeof(text));
}
SDL_Log("text inputed: %s\n", text);
/* After text inputed, we can clear up markedText because it */
/* is committed */
markedText[0] = 0;
Redraw();
break;
case SDL_TEXTEDITING:
SDL_Log("text editing \"%s\", selected range (%" SDL_PRIs32 ", %" SDL_PRIs32 ")\n",
event.edit.text, event.edit.start, event.edit.length);
SDL_strlcpy(markedText, event.edit.text, SDL_TEXTEDITINGEVENT_TEXT_SIZE);
cursor = event.edit.start;
Redraw();
break;
} break;
}
}
}

View File

@@ -22,7 +22,12 @@
#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;
@@ -37,8 +42,7 @@ static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
int mouse_begin_x = -1, mouse_begin_y = -1;
int done;
void
DrawPoints(SDL_Renderer * renderer)
void DrawPoints(SDL_Renderer *renderer)
{
int i;
int x, y;
@@ -71,8 +75,8 @@ DrawPoints(SDL_Renderer * renderer)
cycle_direction = -cycle_direction;
}
}
SDL_SetRenderDrawColor(renderer, 255, (Uint8) current_color,
(Uint8) current_color, (Uint8) current_alpha);
SDL_SetRenderDrawColor(renderer, 255, (Uint8)current_color,
(Uint8)current_color, (Uint8)current_alpha);
x = rand() % viewport.w;
y = rand() % viewport.h;
@@ -102,9 +106,7 @@ add_line(int x1, int y1, int x2, int y2)
return ++num_lines;
}
void
DrawLines(SDL_Renderer * renderer)
void DrawLines(SDL_Renderer *renderer)
{
int i;
SDL_Rect viewport;
@@ -147,7 +149,7 @@ add_rect(int x1, int y1, int x2, int y2)
}
SDL_Log("adding rect (%d, %d), (%d, %d) [%dx%d]\n", x1, y1, x2, y2,
x2 - x1, y2 - y1);
x2 - x1, y2 - y1);
rects[num_rects].x = x1;
rects[num_rects].y = y1;
@@ -158,14 +160,14 @@ add_rect(int x1, int y1, int x2, int y2)
}
static void
DrawRects(SDL_Renderer * renderer)
DrawRects(SDL_Renderer *renderer)
{
SDL_SetRenderDrawColor(renderer, 255, 127, 0, 255);
SDL_RenderFillRects(renderer, rects, num_rects);
}
static void
DrawRectLineIntersections(SDL_Renderer * renderer)
DrawRectLineIntersections(SDL_Renderer *renderer)
{
int i, j;
@@ -189,7 +191,7 @@ DrawRectLineIntersections(SDL_Renderer * renderer)
}
static void
DrawRectRectIntersections(SDL_Renderer * renderer)
DrawRectRectIntersections(SDL_Renderer *renderer)
{
int i, j;
@@ -204,8 +206,7 @@ DrawRectRectIntersections(SDL_Renderer * renderer)
}
}
void
loop()
void loop()
{
int i;
SDL_Event event;
@@ -271,8 +272,7 @@ loop()
#endif
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int i;
Uint32 then, now, frames;
@@ -361,7 +361,7 @@ main(int argc, char *argv[])
/* Print out some timing information */
now = SDL_GetTicks();
if (now > then) {
double fps = ((double) frames * 1000) / (now - then);
double fps = ((double)frames * 1000) / (now - then);
SDL_Log("%2.2f frames per second\n", fps);
}
return 0;

View File

@@ -28,8 +28,8 @@
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 480
#else
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#endif
static SDL_Window *window = NULL;
@@ -44,7 +44,7 @@ PrintJoystick(SDL_Joystick *joy)
char guid[64];
SDL_assert(SDL_JoystickFromInstanceID(SDL_JoystickInstanceID(joy)) == joy);
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joy), guid, sizeof (guid));
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joy), guid, sizeof(guid));
switch (SDL_JoystickGetType(joy)) {
case SDL_JOYSTICK_TYPE_GAMECONTROLLER:
type = "Game Controller";
@@ -103,8 +103,7 @@ DrawRect(SDL_Renderer *r, const int x, const int y, const int w, const int h)
SDL_RenderFillRect(r, &area);
}
void
loop(void *arg)
void loop(void *arg)
{
SDL_Event event;
int i;
@@ -117,7 +116,7 @@ loop(void *arg)
switch (event.type) {
case SDL_JOYDEVICEADDED:
SDL_Log("Joystick device %d added.\n", (int) event.jdevice.which);
SDL_Log("Joystick device %d added.\n", (int)event.jdevice.which);
if (joystick == NULL) {
joystick = SDL_JoystickOpen(event.jdevice.which);
if (joystick) {
@@ -129,7 +128,7 @@ loop(void *arg)
break;
case SDL_JOYDEVICEREMOVED:
SDL_Log("Joystick device %d removed.\n", (int) event.jdevice.which);
SDL_Log("Joystick device %d removed.\n", (int)event.jdevice.which);
if (event.jdevice.which == SDL_JoystickInstanceID(joystick)) {
SDL_JoystickClose(joystick);
joystick = SDL_JoystickOpen(0);
@@ -222,7 +221,7 @@ loop(void *arg)
SDL_SetRenderDrawColor(screen, 0xFF, 0x00, 0x00, SDL_ALPHA_OPAQUE);
for (i = 0; i < SDL_JoystickNumAxes(joystick); ++i) {
/* Draw the X/Y axis */
x = (((int) SDL_JoystickGetAxis(joystick, i)) + 32768);
x = (((int)SDL_JoystickGetAxis(joystick, i)) + 32768);
x *= SCREEN_WIDTH;
x /= 65535;
if (x < 0) {
@@ -232,7 +231,7 @@ loop(void *arg)
}
++i;
if (i < SDL_JoystickNumAxes(joystick)) {
y = (((int) SDL_JoystickGetAxis(joystick, i)) + 32768);
y = (((int)SDL_JoystickGetAxis(joystick, i)) + 32768);
} else {
y = 32768;
}
@@ -251,19 +250,19 @@ loop(void *arg)
for (i = 0; i < SDL_JoystickNumHats(joystick); ++i) {
/* Derive the new position */
const Uint8 hat_pos = SDL_JoystickGetHat(joystick, i);
x = SCREEN_WIDTH/2;
y = SCREEN_HEIGHT/2;
x = SCREEN_WIDTH / 2;
y = SCREEN_HEIGHT / 2;
if (hat_pos & SDL_HAT_UP) {
y = 0;
} else if (hat_pos & SDL_HAT_DOWN) {
y = SCREEN_HEIGHT-8;
y = SCREEN_HEIGHT - 8;
}
if (hat_pos & SDL_HAT_LEFT) {
x = 0;
} else if (hat_pos & SDL_HAT_RIGHT) {
x = SCREEN_WIDTH-8;
x = SCREEN_WIDTH - 8;
}
DrawRect(screen, x, y, 8, 8);
@@ -280,8 +279,7 @@ loop(void *arg)
#endif
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0");

View File

@@ -19,8 +19,7 @@
#include "SDL.h"
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
SDL_Scancode scancode;
@@ -33,7 +32,7 @@ main(int argc, char *argv[])
}
for (scancode = 0; scancode < SDL_NUM_SCANCODES; ++scancode) {
SDL_Log("Scancode #%d, \"%s\"\n", scancode,
SDL_GetScancodeName(scancode));
SDL_GetScancodeName(scancode));
}
SDL_Quit();
return 0;

View File

@@ -11,7 +11,7 @@
*/
/* Test program to test dynamic loading with the loadso subsystem.
*/
*/
#include <stdio.h>
#include <stdlib.h>
@@ -19,10 +19,9 @@
#include "SDL.h"
typedef int (*fntype) (const char *);
typedef int (*fntype)(const char *);
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int retval = 0;
int hello = 0;
@@ -56,13 +55,13 @@ main(int argc, char *argv[])
lib = SDL_LoadObject(libname);
if (lib == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_LoadObject('%s') failed: %s\n",
libname, SDL_GetError());
libname, SDL_GetError());
retval = 3;
} else {
fn = (fntype) SDL_LoadFunction(lib, symname);
fn = (fntype)SDL_LoadFunction(lib, symname);
if (fn == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_LoadFunction('%s') failed: %s\n",
symname, SDL_GetError());
symname, SDL_GetError());
retval = 4;
} else {
SDL_Log("Found %s in %s at %p\n", symname, libname, fn);

View File

@@ -61,7 +61,7 @@ int main(int argc, char **argv)
SDL_Quit();
}
return 0;
return 0;
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -35,21 +35,18 @@ SDL_Quit_Wrapper(void)
SDL_Quit();
}
void
printid(void)
void printid(void)
{
SDL_Log("Process %lu: exiting\n", SDL_ThreadID());
}
void
terminate(int sig)
void terminate(int sig)
{
signal(SIGINT, terminate);
SDL_AtomicSet(&doterminate, 1);
}
void
closemutex(int sig)
void closemutex(int sig)
{
SDL_threadID id = SDL_ThreadID();
int i;
@@ -91,8 +88,7 @@ Run(void *data)
return 0;
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int i;
int maxproc = 6;
@@ -119,7 +115,7 @@ main(int argc, char *argv[])
atexit(printid);
for (i = 0; i < maxproc; ++i) {
char name[64];
SDL_snprintf(name, sizeof (name), "Worker%d", i);
SDL_snprintf(name, sizeof(name), "Worker%d", i);
if ((threads[i] = SDL_CreateThread(Run, name, NULL)) == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread!\n");
}
@@ -127,5 +123,5 @@ main(int argc, char *argv[])
signal(SIGINT, terminate);
Run(NULL);
return 0; /* Never reached */
return 0; /* Never reached */
}

View File

@@ -29,15 +29,12 @@ static int SDLCALL
button_messagebox(void *eventNumber)
{
const SDL_MessageBoxButtonData buttons[] = {
{
SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT,
0,
"OK"
},{
SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT,
1,
"Cancel"
},
{ SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT,
0,
"OK" },
{ SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT,
1,
"Cancel" },
};
SDL_MessageBoxData data = {
@@ -46,8 +43,8 @@ button_messagebox(void *eventNumber)
"Custom MessageBox",
"This is a custom messagebox",
2,
NULL,/* buttons */
NULL /* Default color scheme */
NULL, /* buttons */
NULL /* Default color scheme */
};
int button = -1;
@@ -69,7 +66,8 @@ button_messagebox(void *eventNumber)
quit(2);
}
}
SDL_Log("Pressed button: %d, %s\n", button, button == -1 ? "[closed]" : button == 1 ? "Cancel" : "OK");
SDL_Log("Pressed button: %d, %s\n", button, button == -1 ? "[closed]" : button == 1 ? "Cancel"
: "OK");
if (eventNumber) {
SDL_Event event;
@@ -80,8 +78,7 @@ button_messagebox(void *eventNumber)
return 0;
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int success;
@@ -89,36 +86,36 @@ main(int argc, char *argv[])
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Simple MessageBox",
"This is a simple error MessageBox",
NULL);
"Simple MessageBox",
"This is a simple error MessageBox",
NULL);
if (success == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
quit(1);
}
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Simple MessageBox",
"This is a simple MessageBox with a newline:\r\nHello world!",
NULL);
"Simple MessageBox",
"This is a simple MessageBox with a newline:\r\nHello world!",
NULL);
if (success == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
quit(1);
}
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
NULL,
"NULL Title",
NULL);
NULL,
"NULL Title",
NULL);
if (success == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
quit(1);
}
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"NULL Message",
NULL,
NULL);
"NULL Message",
NULL,
NULL);
if (success == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
quit(1);
@@ -126,9 +123,9 @@ main(int argc, char *argv[])
/* Google says this is Traditional Chinese for "beef with broccoli" */
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"UTF-8 Simple MessageBox",
"Unicode text: '牛肉西蘭花' ...",
NULL);
"UTF-8 Simple MessageBox",
"Unicode text: '牛肉西蘭花' ...",
NULL);
if (success == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
quit(1);
@@ -136,9 +133,9 @@ main(int argc, char *argv[])
/* Google says this is Traditional Chinese for "beef with broccoli" */
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"UTF-8 Simple MessageBox",
"Unicode text and newline:\r\n'牛肉西蘭花'\n'牛肉西蘭花'",
NULL);
"UTF-8 Simple MessageBox",
"Unicode text and newline:\r\n'牛肉西蘭花'\n'牛肉西蘭花'",
NULL);
if (success == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
quit(1);
@@ -146,9 +143,9 @@ main(int argc, char *argv[])
/* Google says this is Traditional Chinese for "beef with broccoli" */
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"牛肉西蘭花",
"Unicode text in the title.",
NULL);
"牛肉西蘭花",
"Unicode text in the title.",
NULL);
if (success == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
quit(1);
@@ -170,7 +167,7 @@ main(int argc, char *argv[])
int status = 0;
SDL_Event event;
intptr_t eventNumber = SDL_RegisterEvents(1);
SDL_Thread* thread = SDL_CreateThread(&button_messagebox, "MessageBox", (void*)eventNumber);
SDL_Thread *thread = SDL_CreateThread(&button_messagebox, "MessageBox", (void *)eventNumber);
while (SDL_WaitEvent(&event)) {
if (event.type == eventNumber) {
@@ -195,9 +192,9 @@ main(int argc, char *argv[])
SDL_RenderPresent(renderer);
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Simple MessageBox",
"This is a simple error MessageBox with a parent window. Press a key or close the window after dismissing this messagebox.",
window);
"Simple MessageBox",
"This is a simple error MessageBox with a parent window. Press a key or close the window after dismissing this messagebox.",
window);
if (success == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
quit(1);

View File

@@ -22,13 +22,14 @@
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 480
#else
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#endif
static SDL_Window *window;
typedef struct _Object {
typedef struct _Object
{
struct _Object *next;
int x1, y1, x2, y2;
@@ -49,8 +50,7 @@ static float wheel_y = SCREEN_HEIGHT * 0.5f;
static SDL_bool done = SDL_FALSE;
void
DrawObject(SDL_Renderer * renderer, Object * object)
void DrawObject(SDL_Renderer *renderer, Object *object)
{
SDL_SetRenderDrawColor(renderer, object->r, object->g, object->b, 255);
@@ -80,8 +80,7 @@ DrawObject(SDL_Renderer * renderer, Object * object)
}
}
void
DrawObjects(SDL_Renderer * renderer)
void DrawObjects(SDL_Renderer *renderer)
{
Object *next = objects;
while (next != NULL) {
@@ -90,8 +89,7 @@ DrawObjects(SDL_Renderer * renderer)
}
}
void
AppendObject(Object *object)
void AppendObject(Object *object)
{
if (objects) {
Object *next = objects;
@@ -104,8 +102,7 @@ AppendObject(Object *object)
}
}
void
loop(void *arg)
void loop(void *arg)
{
SDL_Renderer *renderer = (SDL_Renderer *)arg;
SDL_Event event;
@@ -114,23 +111,23 @@ loop(void *arg)
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_MOUSEWHEEL:
if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) {
event.wheel.preciseX *= -1.0f;
event.wheel.preciseY *= -1.0f;
event.wheel.x *= -1;
event.wheel.y *= -1;
}
if (event.wheel.preciseX != 0.0f) {
wheel_x_active = SDL_TRUE;
/* "positive to the right and negative to the left" */
wheel_x += event.wheel.preciseX * 10.0f;
}
if (event.wheel.preciseY != 0.0f) {
wheel_y_active = SDL_TRUE;
/* "positive away from the user and negative towards the user" */
wheel_y -= event.wheel.preciseY * 10.0f;
}
break;
if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) {
event.wheel.preciseX *= -1.0f;
event.wheel.preciseY *= -1.0f;
event.wheel.x *= -1;
event.wheel.y *= -1;
}
if (event.wheel.preciseX != 0.0f) {
wheel_x_active = SDL_TRUE;
/* "positive to the right and negative to the left" */
wheel_x += event.wheel.preciseX * 10.0f;
}
if (event.wheel.preciseY != 0.0f) {
wheel_y_active = SDL_TRUE;
/* "positive away from the user and negative towards the user" */
wheel_y -= event.wheel.preciseY * 10.0f;
}
break;
case SDL_MOUSEMOTION:
if (active == NULL) {
@@ -150,11 +147,28 @@ loop(void *arg)
}
switch (event.button.button) {
case SDL_BUTTON_LEFT: active->r = 255; buttons |= SDL_BUTTON_LMASK; break;
case SDL_BUTTON_MIDDLE: active->g = 255; buttons |= SDL_BUTTON_MMASK; break;
case SDL_BUTTON_RIGHT: active->b = 255; buttons |= SDL_BUTTON_RMASK; break;
case SDL_BUTTON_X1: active->r = 255; active->b = 255; buttons |= SDL_BUTTON_X1MASK; break;
case SDL_BUTTON_X2: active->g = 255; active->b = 255; buttons |= SDL_BUTTON_X2MASK; break;
case SDL_BUTTON_LEFT:
active->r = 255;
buttons |= SDL_BUTTON_LMASK;
break;
case SDL_BUTTON_MIDDLE:
active->g = 255;
buttons |= SDL_BUTTON_MMASK;
break;
case SDL_BUTTON_RIGHT:
active->b = 255;
buttons |= SDL_BUTTON_RMASK;
break;
case SDL_BUTTON_X1:
active->r = 255;
active->b = 255;
buttons |= SDL_BUTTON_X1MASK;
break;
case SDL_BUTTON_X2:
active->g = 255;
active->b = 255;
buttons |= SDL_BUTTON_X2MASK;
break;
}
break;
@@ -164,11 +178,21 @@ loop(void *arg)
}
switch (event.button.button) {
case SDL_BUTTON_LEFT: buttons &= ~SDL_BUTTON_LMASK; break;
case SDL_BUTTON_MIDDLE: buttons &= ~SDL_BUTTON_MMASK; break;
case SDL_BUTTON_RIGHT: buttons &= ~SDL_BUTTON_RMASK; break;
case SDL_BUTTON_X1: buttons &= ~SDL_BUTTON_X1MASK; break;
case SDL_BUTTON_X2: buttons &= ~SDL_BUTTON_X2MASK; break;
case SDL_BUTTON_LEFT:
buttons &= ~SDL_BUTTON_LMASK;
break;
case SDL_BUTTON_MIDDLE:
buttons &= ~SDL_BUTTON_MMASK;
break;
case SDL_BUTTON_RIGHT:
buttons &= ~SDL_BUTTON_RMASK;
break;
case SDL_BUTTON_X1:
buttons &= ~SDL_BUTTON_X1MASK;
break;
case SDL_BUTTON_X2:
buttons &= ~SDL_BUTTON_X2MASK;
break;
}
if (buttons == 0) {
@@ -225,8 +249,7 @@ loop(void *arg)
#endif
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
SDL_Renderer *renderer;

View File

@@ -20,8 +20,8 @@
#include "testutils.h"
static SDL_AudioSpec spec;
static Uint8 *sound = NULL; /* Pointer to wave data */
static Uint32 soundlen = 0; /* Length of wave data */
static Uint8 *sound = NULL; /* Pointer to wave data */
static Uint32 soundlen = 0; /* Length of wave data */
typedef struct
{
@@ -33,9 +33,9 @@ typedef struct
callback_data cbd[64];
void SDLCALL
play_through_once(void *arg, Uint8 * stream, int len)
play_through_once(void *arg, Uint8 *stream, int len)
{
callback_data *cbdata = (callback_data *) arg;
callback_data *cbdata = (callback_data *)arg;
Uint8 *waveptr = sound + cbdata->soundpos;
int waveleft = soundlen - cbdata->soundpos;
int cpy = len;
@@ -53,8 +53,7 @@ play_through_once(void *arg, Uint8 * stream, int len)
}
}
void
loop()
void loop()
{
if (SDL_AtomicGet(&cbd[0].done)) {
#ifdef __EMSCRIPTEN__
@@ -72,17 +71,17 @@ test_multi_audio(int devcount)
{
int keep_going = 1;
int i;
#ifdef __ANDROID__
#ifdef __ANDROID__
SDL_Event event;
/* Create a Window to get fully initialized event processing for testing pause on Android. */
SDL_CreateWindow("testmultiaudio", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 320, 240, 0);
#endif
if (devcount > 64) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Too many devices (%d), clamping to 64...\n",
devcount);
devcount);
devcount = 64;
}
@@ -104,10 +103,11 @@ test_multi_audio(int devcount)
emscripten_set_main_loop(loop, 0, 1);
#else
while (!SDL_AtomicGet(&cbd[0].done)) {
#ifdef __ANDROID__
#ifdef __ANDROID__
/* Empty queue, some application events would prevent pause. */
while (SDL_PollEvent(&event)) {}
#endif
while (SDL_PollEvent(&event)) {
}
#endif
SDL_Delay(100);
}
SDL_PauseAudioDevice(cbd[0].dev, 1);
@@ -142,10 +142,11 @@ test_multi_audio(int devcount)
keep_going = 1;
}
}
#ifdef __ANDROID__
#ifdef __ANDROID__
/* Empty queue, some application events would prevent pause. */
while (SDL_PollEvent(&event)) {}
#endif
while (SDL_PollEvent(&event)) {
}
#endif
SDL_Delay(100);
}
@@ -162,9 +163,7 @@ test_multi_audio(int devcount)
#endif
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
int devcount = 0;
@@ -178,7 +177,7 @@ main(int argc, char **argv)
}
SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
devcount = SDL_GetNumAudioDevices(0);
if (devcount < 1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Don't see any specific audio devices!\n");
@@ -188,7 +187,7 @@ main(int argc, char **argv)
/* Load the wave file into memory */
if (SDL_LoadWAV(file, &spec, &sound, &soundlen) == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", file,
SDL_GetError());
SDL_GetError());
} else {
test_multi_audio(devcount);
SDL_FreeWAV(sound);

View File

@@ -13,7 +13,7 @@
#include <stdio.h>
#include <stdlib.h> /* for srand() */
#include <time.h> /* for time() */
#include <time.h> /* for time() */
#include "testnative.h"
#include "testutils.h"
@@ -53,8 +53,7 @@ quit(int rc)
exit(rc);
}
void
MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
void MoveSprites(SDL_Renderer *renderer, SDL_Texture *sprite)
{
int sprite_w, sprite_h;
int i;
@@ -92,8 +91,7 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
SDL_RenderPresent(renderer);
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int i, done;
const char *driver;
@@ -109,7 +107,7 @@ main(int argc, char *argv[])
if (SDL_VideoInit(NULL) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL video: %s\n",
SDL_GetError());
SDL_GetError());
exit(1);
}
driver = SDL_GetCurrentVideoDriver();
@@ -123,7 +121,7 @@ main(int argc, char *argv[])
}
if (factory == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find native window code for %s driver\n",
driver);
driver);
quit(2);
}
SDL_Log("Creating native window for %s driver\n", driver);
@@ -158,8 +156,8 @@ main(int argc, char *argv[])
/* Allocate memory for the sprite info */
SDL_GetWindowSize(window, &window_w, &window_h);
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));
positions = (SDL_Rect *)SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect));
velocities = (SDL_Rect *)SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect));
if (positions == NULL || velocities == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
quit(2);

View File

@@ -22,8 +22,8 @@
typedef struct
{
const char *tag;
void *(*CreateNativeWindow) (int w, int h);
void (*DestroyNativeWindow) (void *window);
void *(*CreateNativeWindow)(int w, int h);
void (*DestroyNativeWindow)(void *window);
} NativeWindowFactory;
#ifdef SDL_VIDEO_DRIVER_WINDOWS

View File

@@ -52,7 +52,7 @@ CreateWindowNative(int w, int h)
wc.hInstance = GetModuleHandle(NULL);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = "SDL Test";
@@ -80,7 +80,7 @@ CreateWindowNative(int w, int h)
static void
DestroyWindowNative(void *window)
{
DestroyWindow((HWND) window);
DestroyWindow((HWND)window);
}
#endif

View File

@@ -38,14 +38,14 @@ CreateWindowX11(int w, int h)
XMapRaised(dpy, window);
XSync(dpy, False);
}
return (void *) window;
return (void *)window;
}
static void
DestroyWindowX11(void *window)
{
if (dpy) {
XDestroyWindow(dpy, (Window) window);
XDestroyWindow(dpy, (Window)window);
XCloseDisplay(dpy);
}
}

View File

@@ -32,8 +32,7 @@ static int width = 640;
static int height = 480;
static unsigned int max_frames = 200;
void
draw()
void draw()
{
SDL_Rect Rect;
@@ -51,10 +50,9 @@ draw()
SDL_RenderPresent(renderer);
}
void
save_surface_to_bmp()
void save_surface_to_bmp()
{
SDL_Surface* surface;
SDL_Surface *surface;
Uint32 r_mask, g_mask, b_mask, a_mask;
Uint32 pixel_format;
char file[128];
@@ -73,15 +71,14 @@ save_surface_to_bmp()
SDL_FreeSurface(surface);
}
void
loop()
void loop()
{
SDL_Event event;
/* Check for events */
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
case SDL_QUIT:
done = SDL_TRUE;
break;
}
@@ -97,8 +94,7 @@ loop()
#endif
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
#ifndef __EMSCRIPTEN__
Uint32 then, now, frames;
@@ -110,18 +106,18 @@ main(int argc, char *argv[])
/* Force the offscreen renderer, if it cannot be created then fail out */
if (SDL_VideoInit("offscreen") < 0) {
SDL_Log("Couldn't initialize the offscreen video driver: %s\n",
SDL_GetError());
SDL_GetError());
return SDL_FALSE;
}
/* If OPENGL fails to init it will fallback to using a framebuffer for rendering */
/* If OPENGL fails to init it will fallback to using a framebuffer for rendering */
window = SDL_CreateWindow("Offscreen Test",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
width, height, 0);
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
width, height, 0);
if (window == NULL) {
SDL_Log("Couldn't create window: %s\n",
SDL_GetError());
SDL_GetError());
return SDL_FALSE;
}
@@ -129,7 +125,7 @@ main(int argc, char *argv[])
if (renderer == NULL) {
SDL_Log("Couldn't create renderer: %s\n",
SDL_GetError());
SDL_GetError());
return SDL_FALSE;
}
@@ -157,7 +153,7 @@ main(int argc, char *argv[])
if (frames % (max_frames / 10) == 0) {
now = SDL_GetTicks();
if (now > then) {
double fps = ((double) frames * 1000) / (now - then);
double fps = ((double)frames * 1000) / (now - then);
SDL_Log("Frames remaining: %" SDL_PRIu32 " rendering at %2.2f frames per second\n", max_frames - frames, fps);
}
}

View File

@@ -30,9 +30,10 @@
#define MOOSEPIC_W 64
#define MOOSEPIC_H 88
#define MOOSEFRAME_SIZE (MOOSEPIC_W * MOOSEPIC_H)
#define MOOSEFRAME_SIZE (MOOSEPIC_W * MOOSEPIC_H)
#define MOOSEFRAMES_COUNT 10
/* *INDENT-OFF* */ /* clang-format off */
SDL_Color MooseColors[84] = {
{49, 49, 49, SDL_ALPHA_OPAQUE}
, {66, 24, 0, SDL_ALPHA_OPAQUE}
@@ -139,8 +140,9 @@ SDL_Color MooseColors[84] = {
, {231, 231, 231, SDL_ALPHA_OPAQUE}
, {239, 206, 173, SDL_ALPHA_OPAQUE}
};
/* *INDENT-ON* */ /* clang-format on */
Uint8 MooseFrame[MOOSEFRAMES_COUNT][MOOSEFRAME_SIZE*2];
Uint8 MooseFrame[MOOSEFRAMES_COUNT][MOOSEFRAME_SIZE * 2];
SDL_Texture *MooseTexture;
SDL_Rect displayrect;
int window_w;
@@ -176,8 +178,7 @@ PrintUsage(char *argv0)
SDL_Log("\n");
}
void
loop()
void loop()
{
SDL_Event event;
@@ -234,8 +235,7 @@ loop()
#endif
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
Uint8 *RawMooseData;
SDL_RWops *handle;
@@ -260,19 +260,19 @@ main(int argc, char **argv)
fps = SDL_atoi(argv[2]);
if (fps == 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"The -fps option requires an argument [from 1 to 1000], default is 12.\n");
"The -fps option requires an argument [from 1 to 1000], default is 12.\n");
quit(10);
}
if ((fps < 0) || (fps > 1000)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"The -fps option must be in range from 1 to 1000, default is 12.\n");
"The -fps option must be in range from 1 to 1000, default is 12.\n");
quit(10);
}
argv += 2;
argc -= 2;
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"The -fps option requires an argument [from 1 to 1000], default is 12.\n");
"The -fps option requires an argument [from 1 to 1000], default is 12.\n");
quit(10);
}
} else if (SDL_strcmp(argv[1], "-nodelay") == 0) {
@@ -284,23 +284,22 @@ main(int argc, char **argv)
scale = SDL_atoi(argv[2]);
if (scale == 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"The -scale option requires an argument [from 1 to 50], default is 5.\n");
"The -scale option requires an argument [from 1 to 50], default is 5.\n");
quit(10);
}
if ((scale < 0) || (scale > 50)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"The -scale option must be in range from 1 to 50, default is 5.\n");
"The -scale option must be in range from 1 to 50, default is 5.\n");
quit(10);
}
argv += 2;
argc -= 2;
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"The -fps option requires an argument [from 1 to 1000], default is 12.\n");
"The -fps option requires an argument [from 1 to 1000], default is 12.\n");
quit(10);
}
} else if ((SDL_strcmp(argv[1], "-help") == 0)
|| (SDL_strcmp(argv[1], "-h") == 0)) {
} else if ((SDL_strcmp(argv[1], "-help") == 0) || (SDL_strcmp(argv[1], "-h") == 0)) {
PrintUsage(argv[0]);
quit(0);
} else {
@@ -310,7 +309,7 @@ main(int argc, char **argv)
break;
}
RawMooseData = (Uint8 *) SDL_malloc(MOOSEFRAME_SIZE * MOOSEFRAMES_COUNT);
RawMooseData = (Uint8 *)SDL_malloc(MOOSEFRAME_SIZE * MOOSEFRAMES_COUNT);
if (RawMooseData == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't allocate memory for movie !\n");
quit(1);
@@ -365,7 +364,7 @@ main(int argc, char **argv)
/* SDL_SetTextureColorMod(MooseTexture, 0xff, 0x80, 0x80); */
for (i = 0; i < MOOSEFRAMES_COUNT; i++) {
Uint8 MooseFrameRGB[MOOSEFRAME_SIZE*3];
Uint8 MooseFrameRGB[MOOSEFRAME_SIZE * 3];
Uint8 *rgb;
Uint8 *frame;
@@ -377,9 +376,9 @@ main(int argc, char **argv)
rgb[2] = MooseColors[frame[j]].b;
rgb += 3;
}
ConvertRGBtoYUV(SDL_PIXELFORMAT_YV12, MooseFrameRGB, MOOSEPIC_W*3, MooseFrame[i], MOOSEPIC_W, MOOSEPIC_H,
SDL_GetYUVConversionModeForResolution(MOOSEPIC_W, MOOSEPIC_H),
0, 100);
ConvertRGBtoYUV(SDL_PIXELFORMAT_YV12, MooseFrameRGB, MOOSEPIC_W * 3, MooseFrame[i], MOOSEPIC_W, MOOSEPIC_H,
SDL_GetYUVConversionModeForResolution(MOOSEPIC_W, MOOSEPIC_H),
0, 100);
}
SDL_free(RawMooseData);
@@ -406,7 +405,7 @@ main(int argc, char **argv)
#else
while (!done) {
loop();
}
}
#endif
SDL_DestroyRenderer(renderer);

View File

@@ -45,8 +45,7 @@ SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT64, SDL_MIN_SINT64 == ~0x7fffffffffffffffll)
SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT64, SDL_MAX_UINT64 == 18446744073709551615ull);
SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT64, SDL_MIN_UINT64 == 0);
int
TestTypes(SDL_bool verbose)
int TestTypes(SDL_bool verbose)
{
int error = 0;
@@ -81,8 +80,7 @@ TestTypes(SDL_bool verbose)
return error ? 1 : 0;
}
int
TestEndian(SDL_bool verbose)
int TestEndian(SDL_bool verbose)
{
int error = 0;
Uint16 value = 0x1234;
@@ -94,9 +92,10 @@ TestEndian(SDL_bool verbose)
Uint32 swapped32 = 0xDEADBEEF;
Uint64 value64, swapped64;
union {
double d;
Uint32 ui32[2];
union
{
double d;
Uint32 ui32[2];
} value_double;
value64 = 0xEFBEADDE;
@@ -109,9 +108,9 @@ TestEndian(SDL_bool verbose)
if (verbose) {
SDL_Log("Detected a %s endian machine.\n",
(SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big");
(SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big");
}
if ((*((char *) &value) >> 4) == 0x1) {
if ((*((char *)&value) >> 4) == 0x1) {
real_byteorder = SDL_BIG_ENDIAN;
} else {
real_byteorder = SDL_LIL_ENDIAN;
@@ -119,13 +118,13 @@ TestEndian(SDL_bool verbose)
if (real_byteorder != SDL_BYTEORDER) {
if (verbose) {
SDL_Log("Actually a %s endian machine!\n",
(real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big");
(real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big");
}
++error;
}
if (verbose) {
SDL_Log("Detected a %s endian float word order machine.\n",
(SDL_FLOATWORDORDER == SDL_LIL_ENDIAN) ? "little" : "big");
(SDL_FLOATWORDORDER == SDL_LIL_ENDIAN) ? "little" : "big");
}
if (value_double.ui32[0] == 0x82c2bd7f && value_double.ui32[1] == 0x400921fb) {
real_floatwordorder = SDL_LIL_ENDIAN;
@@ -135,13 +134,14 @@ TestEndian(SDL_bool verbose)
if (real_floatwordorder != SDL_FLOATWORDORDER) {
if (verbose) {
SDL_Log("Actually a %s endian float word order machine!\n",
(real_floatwordorder == SDL_LIL_ENDIAN) ? "little" : (real_floatwordorder == SDL_BIG_ENDIAN) ? "big" : "unknown" );
(real_floatwordorder == SDL_LIL_ENDIAN) ? "little" : (real_floatwordorder == SDL_BIG_ENDIAN) ? "big"
: "unknown");
}
++error;
}
if (verbose) {
SDL_Log("Value 16 = 0x%X, swapped = 0x%X\n", value16,
SDL_Swap16(value16));
SDL_Swap16(value16));
}
if (SDL_Swap16(value16) != swapped16) {
if (verbose) {
@@ -161,8 +161,8 @@ TestEndian(SDL_bool verbose)
++error;
}
if (verbose) {
SDL_Log("Value 64 = 0x%"SDL_PRIX64", swapped = 0x%"SDL_PRIX64"\n", value64,
SDL_Swap64(value64));
SDL_Log("Value 64 = 0x%" SDL_PRIX64 ", swapped = 0x%" SDL_PRIX64 "\n", value64,
SDL_Swap64(value64));
}
if (SDL_Swap64(value64) != swapped64) {
if (verbose) {
@@ -173,64 +173,64 @@ TestEndian(SDL_bool verbose)
return error ? 1 : 0;
}
static int TST_allmul (void *a, void *b, int arg, void *result, void *expected)
static int TST_allmul(void *a, void *b, int arg, void *result, void *expected)
{
(*(long long *)result) = ((*(long long *)a) * (*(long long *)b));
return (*(long long *)result) == (*(long long *)expected);
}
static int TST_alldiv (void *a, void *b, int arg, void *result, void *expected)
static int TST_alldiv(void *a, void *b, int arg, void *result, void *expected)
{
(*(long long *)result) = ((*(long long *)a) / (*(long long *)b));
return (*(long long *)result) == (*(long long *)expected);
}
static int TST_allrem (void *a, void *b, int arg, void *result, void *expected)
static int TST_allrem(void *a, void *b, int arg, void *result, void *expected)
{
(*(long long *)result) = ((*(long long *)a) % (*(long long *)b));
return (*(long long *)result) == (*(long long *)expected);
}
static int TST_ualldiv (void *a, void *b, int arg, void *result, void *expected)
static int TST_ualldiv(void *a, void *b, int arg, void *result, void *expected)
{
(*(unsigned long long *)result) = ((*(unsigned long long *)a) / (*(unsigned long long *)b));
return (*(unsigned long long *)result) == (*(unsigned long long *)expected);
}
static int TST_uallrem (void *a, void *b, int arg, void *result, void *expected)
static int TST_uallrem(void *a, void *b, int arg, void *result, void *expected)
{
(*(unsigned long long *)result) = ((*(unsigned long long *)a) % (*(unsigned long long *)b));
return (*(unsigned long long *)result) == (*(unsigned long long *)expected);
}
static int TST_allshl (void *a, void *b, int arg, void *result, void *expected)
static int TST_allshl(void *a, void *b, int arg, void *result, void *expected)
{
(*(long long *)result) = (*(long long *)a) << arg;
return (*(long long *)result) == (*(long long *)expected);
}
static int TST_aullshl (void *a, void *b, int arg, void *result, void *expected)
static int TST_aullshl(void *a, void *b, int arg, void *result, void *expected)
{
(*(unsigned long long *)result) = (*(unsigned long long *)a) << arg;
return (*(unsigned long long *)result) == (*(unsigned long long *)expected);
}
static int TST_allshr (void *a, void *b, int arg, void *result, void *expected)
static int TST_allshr(void *a, void *b, int arg, void *result, void *expected)
{
(*(long long *)result) = (*(long long *)a) >> arg;
return (*(long long *)result) == (*(long long *)expected);
}
static int TST_aullshr (void *a, void *b, int arg, void *result, void *expected)
static int TST_aullshr(void *a, void *b, int arg, void *result, void *expected)
{
(*(unsigned long long *)result) = (*(unsigned long long *)a) >> arg;
return (*(unsigned long long *)result) == (*(unsigned long long *)expected);
}
typedef int (*LL_Intrinsic)(void *a, void *b, int arg, void *result, void *expected);
typedef struct {
typedef struct
{
const char *operation;
LL_Intrinsic routine;
unsigned long long a, b;
@@ -238,133 +238,130 @@ typedef struct {
unsigned long long expected_result;
} LL_Test;
static LL_Test LL_Tests[] =
{
static LL_Test LL_Tests[] = {
/* UNDEFINED {"_allshl", &TST_allshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 65, 0x0000000000000000ll}, */
{"_allshl", &TST_allshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 1, 0xFFFFFFFFFFFFFFFEll},
{"_allshl", &TST_allshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 32, 0xFFFFFFFF00000000ll},
{"_allshl", &TST_allshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 33, 0xFFFFFFFE00000000ll},
{"_allshl", &TST_allshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 0, 0xFFFFFFFFFFFFFFFFll},
{ "_allshl", &TST_allshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 1, 0xFFFFFFFFFFFFFFFEll },
{ "_allshl", &TST_allshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 32, 0xFFFFFFFF00000000ll },
{ "_allshl", &TST_allshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 33, 0xFFFFFFFE00000000ll },
{ "_allshl", &TST_allshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 0, 0xFFFFFFFFFFFFFFFFll },
{"_allshr", &TST_allshr, 0xAAAAAAAA55555555ll, 0ll, 63, 0xFFFFFFFFFFFFFFFFll},
{ "_allshr", &TST_allshr, 0xAAAAAAAA55555555ll, 0ll, 63, 0xFFFFFFFFFFFFFFFFll },
/* UNDEFINED {"_allshr", &TST_allshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 65, 0xFFFFFFFFFFFFFFFFll}, */
{"_allshr", &TST_allshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 1, 0xFFFFFFFFFFFFFFFFll},
{"_allshr", &TST_allshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 32, 0xFFFFFFFFFFFFFFFFll},
{"_allshr", &TST_allshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 33, 0xFFFFFFFFFFFFFFFFll},
{"_allshr", &TST_allshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 0, 0xFFFFFFFFFFFFFFFFll},
{ "_allshr", &TST_allshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 1, 0xFFFFFFFFFFFFFFFFll },
{ "_allshr", &TST_allshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 32, 0xFFFFFFFFFFFFFFFFll },
{ "_allshr", &TST_allshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 33, 0xFFFFFFFFFFFFFFFFll },
{ "_allshr", &TST_allshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 0, 0xFFFFFFFFFFFFFFFFll },
/* UNDEFINED {"_allshr", &TST_allshr, 0x5F5F5F5F5F5F5F5Fll, 0ll, 65, 0x0000000000000000ll}, */
{"_allshr", &TST_allshr, 0x5F5F5F5F5F5F5F5Fll, 0ll, 1, 0x2FAFAFAFAFAFAFAFll},
{"_allshr", &TST_allshr, 0x5F5F5F5F5F5F5F5Fll, 0ll, 32, 0x000000005F5F5F5Fll},
{"_allshr", &TST_allshr, 0x5F5F5F5F5F5F5F5Fll, 0ll, 33, 0x000000002FAFAFAFll},
{ "_allshr", &TST_allshr, 0x5F5F5F5F5F5F5F5Fll, 0ll, 1, 0x2FAFAFAFAFAFAFAFll },
{ "_allshr", &TST_allshr, 0x5F5F5F5F5F5F5F5Fll, 0ll, 32, 0x000000005F5F5F5Fll },
{ "_allshr", &TST_allshr, 0x5F5F5F5F5F5F5F5Fll, 0ll, 33, 0x000000002FAFAFAFll },
/* UNDEFINED {"_aullshl", &TST_aullshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 65, 0x0000000000000000ll}, */
{"_aullshl", &TST_aullshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 1, 0xFFFFFFFFFFFFFFFEll},
{"_aullshl", &TST_aullshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 32, 0xFFFFFFFF00000000ll},
{"_aullshl", &TST_aullshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 33, 0xFFFFFFFE00000000ll},
{"_aullshl", &TST_aullshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 0, 0xFFFFFFFFFFFFFFFFll},
{ "_aullshl", &TST_aullshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 1, 0xFFFFFFFFFFFFFFFEll },
{ "_aullshl", &TST_aullshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 32, 0xFFFFFFFF00000000ll },
{ "_aullshl", &TST_aullshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 33, 0xFFFFFFFE00000000ll },
{ "_aullshl", &TST_aullshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 0, 0xFFFFFFFFFFFFFFFFll },
/* UNDEFINED {"_aullshr", &TST_aullshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 65, 0x0000000000000000ll}, */
{"_aullshr", &TST_aullshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 1, 0x7FFFFFFFFFFFFFFFll},
{"_aullshr", &TST_aullshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 32, 0x00000000FFFFFFFFll},
{"_aullshr", &TST_aullshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 33, 0x000000007FFFFFFFll},
{"_aullshr", &TST_aullshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 0, 0xFFFFFFFFFFFFFFFFll},
{ "_aullshr", &TST_aullshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 1, 0x7FFFFFFFFFFFFFFFll },
{ "_aullshr", &TST_aullshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 32, 0x00000000FFFFFFFFll },
{ "_aullshr", &TST_aullshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 33, 0x000000007FFFFFFFll },
{ "_aullshr", &TST_aullshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 0, 0xFFFFFFFFFFFFFFFFll },
{"_allmul", &TST_allmul, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000000ll, 0, 0x0000000000000000ll},
{"_allmul", &TST_allmul, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
{"_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x000000000FFFFFFFll},
{"_allmul", &TST_allmul, 0x0000000000000001ll, 0x000000000FFFFFFFll, 0, 0x000000000FFFFFFFll},
{"_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000000000010ll, 0, 0x00000000FFFFFFF0ll},
{"_allmul", &TST_allmul, 0x0000000000000010ll, 0x000000000FFFFFFFll, 0, 0x00000000FFFFFFF0ll},
{"_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000000000100ll, 0, 0x0000000FFFFFFF00ll},
{"_allmul", &TST_allmul, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000FFFFFFF00ll},
{"_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000010000000ll, 0, 0x00FFFFFFF0000000ll},
{"_allmul", &TST_allmul, 0x0000000010000000ll, 0x000000000FFFFFFFll, 0, 0x00FFFFFFF0000000ll},
{"_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000080000000ll, 0, 0x07FFFFFF80000000ll},
{"_allmul", &TST_allmul, 0x0000000080000000ll, 0x000000000FFFFFFFll, 0, 0x07FFFFFF80000000ll},
{"_allmul", &TST_allmul, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0xFFFFFFFF00000000ll},
{"_allmul", &TST_allmul, 0x0000000080000000ll, 0xFFFFFFFFFFFFFFFEll, 0, 0xFFFFFFFF00000000ll},
{"_allmul", &TST_allmul, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000008ll, 0, 0xFFFFFFFEFFFFFFF0ll},
{"_allmul", &TST_allmul, 0x0000000080000008ll, 0xFFFFFFFFFFFFFFFEll, 0, 0xFFFFFFFEFFFFFFF0ll},
{"_allmul", &TST_allmul, 0x00000000FFFFFFFFll, 0x00000000FFFFFFFFll, 0, 0xFFFFFFFE00000001ll},
{ "_allmul", &TST_allmul, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000000ll, 0, 0x0000000000000000ll },
{ "_allmul", &TST_allmul, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll },
{ "_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x000000000FFFFFFFll },
{ "_allmul", &TST_allmul, 0x0000000000000001ll, 0x000000000FFFFFFFll, 0, 0x000000000FFFFFFFll },
{ "_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000000000010ll, 0, 0x00000000FFFFFFF0ll },
{ "_allmul", &TST_allmul, 0x0000000000000010ll, 0x000000000FFFFFFFll, 0, 0x00000000FFFFFFF0ll },
{ "_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000000000100ll, 0, 0x0000000FFFFFFF00ll },
{ "_allmul", &TST_allmul, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000FFFFFFF00ll },
{ "_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000010000000ll, 0, 0x00FFFFFFF0000000ll },
{ "_allmul", &TST_allmul, 0x0000000010000000ll, 0x000000000FFFFFFFll, 0, 0x00FFFFFFF0000000ll },
{ "_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000080000000ll, 0, 0x07FFFFFF80000000ll },
{ "_allmul", &TST_allmul, 0x0000000080000000ll, 0x000000000FFFFFFFll, 0, 0x07FFFFFF80000000ll },
{ "_allmul", &TST_allmul, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0xFFFFFFFF00000000ll },
{ "_allmul", &TST_allmul, 0x0000000080000000ll, 0xFFFFFFFFFFFFFFFEll, 0, 0xFFFFFFFF00000000ll },
{ "_allmul", &TST_allmul, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000008ll, 0, 0xFFFFFFFEFFFFFFF0ll },
{ "_allmul", &TST_allmul, 0x0000000080000008ll, 0xFFFFFFFFFFFFFFFEll, 0, 0xFFFFFFFEFFFFFFF0ll },
{ "_allmul", &TST_allmul, 0x00000000FFFFFFFFll, 0x00000000FFFFFFFFll, 0, 0xFFFFFFFE00000001ll },
{"_alldiv", &TST_alldiv, 0x0000000000000000ll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
{"_alldiv", &TST_alldiv, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
{"_alldiv", &TST_alldiv, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0xFFFFFFFFFFFFFFFFll},
{"_alldiv", &TST_alldiv, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll, 0, 0xFFFFFFFFFFFFFFFFll},
{"_alldiv", &TST_alldiv, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0xFFFFFFFFFFFFFFFFll},
{"_alldiv", &TST_alldiv, 0x0000000000000001ll, 0x0000000000000001ll, 0, 0x0000000000000001ll},
{"_alldiv", &TST_alldiv, 0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000001ll},
{"_alldiv", &TST_alldiv, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x000000000FFFFFFFll},
{"_alldiv", &TST_alldiv, 0x0000000FFFFFFFFFll, 0x0000000000000010ll, 0, 0x00000000FFFFFFFFll},
{"_alldiv", &TST_alldiv, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000000000000ll},
{"_alldiv", &TST_alldiv, 0x00FFFFFFF0000000ll, 0x0000000010000000ll, 0, 0x000000000FFFFFFFll},
{"_alldiv", &TST_alldiv, 0x07FFFFFF80000000ll, 0x0000000080000000ll, 0, 0x000000000FFFFFFFll},
{"_alldiv", &TST_alldiv, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0x0000000000000000ll},
{"_alldiv", &TST_alldiv, 0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000080000008ll},
{"_alldiv", &TST_alldiv, 0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0xC000000080000008ll},
{"_alldiv", &TST_alldiv, 0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll, 0, 0x0000000000007FFFll},
{"_alldiv", &TST_alldiv, 0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll, 0, 0x0000000000000001ll},
{ "_alldiv", &TST_alldiv, 0x0000000000000000ll, 0x0000000000000001ll, 0, 0x0000000000000000ll },
{ "_alldiv", &TST_alldiv, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll },
{ "_alldiv", &TST_alldiv, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0xFFFFFFFFFFFFFFFFll },
{ "_alldiv", &TST_alldiv, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll, 0, 0xFFFFFFFFFFFFFFFFll },
{ "_alldiv", &TST_alldiv, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0xFFFFFFFFFFFFFFFFll },
{ "_alldiv", &TST_alldiv, 0x0000000000000001ll, 0x0000000000000001ll, 0, 0x0000000000000001ll },
{ "_alldiv", &TST_alldiv, 0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000001ll },
{ "_alldiv", &TST_alldiv, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x000000000FFFFFFFll },
{ "_alldiv", &TST_alldiv, 0x0000000FFFFFFFFFll, 0x0000000000000010ll, 0, 0x00000000FFFFFFFFll },
{ "_alldiv", &TST_alldiv, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000000000000ll },
{ "_alldiv", &TST_alldiv, 0x00FFFFFFF0000000ll, 0x0000000010000000ll, 0, 0x000000000FFFFFFFll },
{ "_alldiv", &TST_alldiv, 0x07FFFFFF80000000ll, 0x0000000080000000ll, 0, 0x000000000FFFFFFFll },
{ "_alldiv", &TST_alldiv, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0x0000000000000000ll },
{ "_alldiv", &TST_alldiv, 0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000080000008ll },
{ "_alldiv", &TST_alldiv, 0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0xC000000080000008ll },
{ "_alldiv", &TST_alldiv, 0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll, 0, 0x0000000000007FFFll },
{ "_alldiv", &TST_alldiv, 0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll, 0, 0x0000000000000001ll },
{"_allrem", &TST_allrem, 0x0000000000000000ll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
{"_allrem", &TST_allrem, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
{"_allrem", &TST_allrem, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
{"_allrem", &TST_allrem, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
{"_allrem", &TST_allrem, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
{"_allrem", &TST_allrem, 0x0000000000000001ll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
{"_allrem", &TST_allrem, 0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
{"_allrem", &TST_allrem, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
{"_allrem", &TST_allrem, 0x0000000FFFFFFFFFll, 0x0000000000000010ll, 0, 0x000000000000000Fll},
{"_allrem", &TST_allrem, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000000000100ll},
{"_allrem", &TST_allrem, 0x00FFFFFFF0000000ll, 0x0000000010000000ll, 0, 0x0000000000000000ll},
{"_allrem", &TST_allrem, 0x07FFFFFF80000000ll, 0x0000000080000000ll, 0, 0x0000000000000000ll},
{"_allrem", &TST_allrem, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0xFFFFFFFFFFFFFFFEll},
{"_allrem", &TST_allrem, 0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000000000000ll},
{"_allrem", &TST_allrem, 0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000000000000ll},
{"_allrem", &TST_allrem, 0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll, 0, 0x0000FFFF0000FFEEll},
{"_allrem", &TST_allrem, 0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll, 0, 0x0000000000000000ll},
{ "_allrem", &TST_allrem, 0x0000000000000000ll, 0x0000000000000001ll, 0, 0x0000000000000000ll },
{ "_allrem", &TST_allrem, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll },
{ "_allrem", &TST_allrem, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll },
{ "_allrem", &TST_allrem, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll, 0, 0x0000000000000000ll },
{ "_allrem", &TST_allrem, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll },
{ "_allrem", &TST_allrem, 0x0000000000000001ll, 0x0000000000000001ll, 0, 0x0000000000000000ll },
{ "_allrem", &TST_allrem, 0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll },
{ "_allrem", &TST_allrem, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x0000000000000000ll },
{ "_allrem", &TST_allrem, 0x0000000FFFFFFFFFll, 0x0000000000000010ll, 0, 0x000000000000000Fll },
{ "_allrem", &TST_allrem, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000000000100ll },
{ "_allrem", &TST_allrem, 0x00FFFFFFF0000000ll, 0x0000000010000000ll, 0, 0x0000000000000000ll },
{ "_allrem", &TST_allrem, 0x07FFFFFF80000000ll, 0x0000000080000000ll, 0, 0x0000000000000000ll },
{ "_allrem", &TST_allrem, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0xFFFFFFFFFFFFFFFEll },
{ "_allrem", &TST_allrem, 0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000000000000ll },
{ "_allrem", &TST_allrem, 0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000000000000ll },
{ "_allrem", &TST_allrem, 0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll, 0, 0x0000FFFF0000FFEEll },
{ "_allrem", &TST_allrem, 0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll, 0, 0x0000000000000000ll },
{ "_ualldiv", &TST_ualldiv, 0x0000000000000000ll, 0x0000000000000001ll, 0, 0x0000000000000000ll },
{ "_ualldiv", &TST_ualldiv, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll },
{ "_ualldiv", &TST_ualldiv, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll },
{ "_ualldiv", &TST_ualldiv, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll, 0, 0xFFFFFFFFFFFFFFFFll },
{ "_ualldiv", &TST_ualldiv, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll },
{ "_ualldiv", &TST_ualldiv, 0x0000000000000001ll, 0x0000000000000001ll, 0, 0x0000000000000001ll },
{ "_ualldiv", &TST_ualldiv, 0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000001ll },
{ "_ualldiv", &TST_ualldiv, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x000000000FFFFFFFll },
{ "_ualldiv", &TST_ualldiv, 0x0000000FFFFFFFFFll, 0x0000000000000010ll, 0, 0x00000000FFFFFFFFll },
{ "_ualldiv", &TST_ualldiv, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000000000000ll },
{ "_ualldiv", &TST_ualldiv, 0x00FFFFFFF0000000ll, 0x0000000010000000ll, 0, 0x000000000FFFFFFFll },
{ "_ualldiv", &TST_ualldiv, 0x07FFFFFF80000000ll, 0x0000000080000000ll, 0, 0x000000000FFFFFFFll },
{ "_ualldiv", &TST_ualldiv, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0x00000001FFFFFFFFll },
{ "_ualldiv", &TST_ualldiv, 0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000000000000ll },
{ "_ualldiv", &TST_ualldiv, 0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000000000000ll },
{ "_ualldiv", &TST_ualldiv, 0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll, 0, 0x0000000000007FFFll },
{ "_ualldiv", &TST_ualldiv, 0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll, 0, 0x0000000000000001ll },
{"_ualldiv", &TST_ualldiv, 0x0000000000000000ll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
{"_ualldiv", &TST_ualldiv, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
{"_ualldiv", &TST_ualldiv, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
{"_ualldiv", &TST_ualldiv, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll, 0, 0xFFFFFFFFFFFFFFFFll},
{"_ualldiv", &TST_ualldiv, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
{"_ualldiv", &TST_ualldiv, 0x0000000000000001ll, 0x0000000000000001ll, 0, 0x0000000000000001ll},
{"_ualldiv", &TST_ualldiv, 0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000001ll},
{"_ualldiv", &TST_ualldiv, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x000000000FFFFFFFll},
{"_ualldiv", &TST_ualldiv, 0x0000000FFFFFFFFFll, 0x0000000000000010ll, 0, 0x00000000FFFFFFFFll},
{"_ualldiv", &TST_ualldiv, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000000000000ll},
{"_ualldiv", &TST_ualldiv, 0x00FFFFFFF0000000ll, 0x0000000010000000ll, 0, 0x000000000FFFFFFFll},
{"_ualldiv", &TST_ualldiv, 0x07FFFFFF80000000ll, 0x0000000080000000ll, 0, 0x000000000FFFFFFFll},
{"_ualldiv", &TST_ualldiv, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0x00000001FFFFFFFFll},
{"_ualldiv", &TST_ualldiv, 0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000000000000ll},
{"_ualldiv", &TST_ualldiv, 0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000000000000ll},
{"_ualldiv", &TST_ualldiv, 0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll, 0, 0x0000000000007FFFll},
{"_ualldiv", &TST_ualldiv, 0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll, 0, 0x0000000000000001ll},
{ "_uallrem", &TST_uallrem, 0x0000000000000000ll, 0x0000000000000001ll, 0, 0x0000000000000000ll },
{ "_uallrem", &TST_uallrem, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll },
{ "_uallrem", &TST_uallrem, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000001ll },
{ "_uallrem", &TST_uallrem, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll, 0, 0x0000000000000000ll },
{ "_uallrem", &TST_uallrem, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000001ll },
{ "_uallrem", &TST_uallrem, 0x0000000000000001ll, 0x0000000000000001ll, 0, 0x0000000000000000ll },
{ "_uallrem", &TST_uallrem, 0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll },
{ "_uallrem", &TST_uallrem, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x0000000000000000ll },
{ "_uallrem", &TST_uallrem, 0x0000000FFFFFFFFFll, 0x0000000000000010ll, 0, 0x000000000000000Fll },
{ "_uallrem", &TST_uallrem, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000000000100ll },
{ "_uallrem", &TST_uallrem, 0x00FFFFFFF0000000ll, 0x0000000010000000ll, 0, 0x0000000000000000ll },
{ "_uallrem", &TST_uallrem, 0x07FFFFFF80000000ll, 0x0000000080000000ll, 0, 0x0000000000000000ll },
{ "_uallrem", &TST_uallrem, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0x000000007FFFFFFEll },
{ "_uallrem", &TST_uallrem, 0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0xFFFFFFFEFFFFFFF0ll },
{ "_uallrem", &TST_uallrem, 0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x7FFFFFFEFFFFFFF0ll },
{ "_uallrem", &TST_uallrem, 0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll, 0, 0x0000FFFF0000FFEEll },
{ "_uallrem", &TST_uallrem, 0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll, 0, 0x0000000000000000ll },
{"_uallrem", &TST_uallrem, 0x0000000000000000ll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
{"_uallrem", &TST_uallrem, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
{"_uallrem", &TST_uallrem, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000001ll},
{"_uallrem", &TST_uallrem, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
{"_uallrem", &TST_uallrem, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000001ll},
{"_uallrem", &TST_uallrem, 0x0000000000000001ll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
{"_uallrem", &TST_uallrem, 0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
{"_uallrem", &TST_uallrem, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
{"_uallrem", &TST_uallrem, 0x0000000FFFFFFFFFll, 0x0000000000000010ll, 0, 0x000000000000000Fll},
{"_uallrem", &TST_uallrem, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000000000100ll},
{"_uallrem", &TST_uallrem, 0x00FFFFFFF0000000ll, 0x0000000010000000ll, 0, 0x0000000000000000ll},
{"_uallrem", &TST_uallrem, 0x07FFFFFF80000000ll, 0x0000000080000000ll, 0, 0x0000000000000000ll},
{"_uallrem", &TST_uallrem, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0x000000007FFFFFFEll},
{"_uallrem", &TST_uallrem, 0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0xFFFFFFFEFFFFFFF0ll},
{"_uallrem", &TST_uallrem, 0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x7FFFFFFEFFFFFFF0ll},
{"_uallrem", &TST_uallrem, 0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll, 0, 0x0000FFFF0000FFEEll},
{"_uallrem", &TST_uallrem, 0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll, 0, 0x0000000000000000ll},
{NULL}
{ NULL }
};
int
Test64Bit (SDL_bool verbose)
int Test64Bit(SDL_bool verbose)
{
LL_Test *t;
int failed = 0;
@@ -390,35 +387,33 @@ Test64Bit (SDL_bool verbose)
return failed ? 1 : 0;
}
int
TestCPUInfo(SDL_bool verbose)
int TestCPUInfo(SDL_bool verbose)
{
if (verbose) {
SDL_Log("CPU count: %d\n", SDL_GetCPUCount());
SDL_Log("CPU cache line size: %d\n", SDL_GetCPUCacheLineSize());
SDL_Log("RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected");
SDL_Log("AltiVec %s\n", SDL_HasAltiVec()? "detected" : "not detected");
SDL_Log("MMX %s\n", SDL_HasMMX()? "detected" : "not detected");
SDL_Log("3DNow! %s\n", SDL_Has3DNow()? "detected" : "not detected");
SDL_Log("SSE %s\n", SDL_HasSSE()? "detected" : "not detected");
SDL_Log("SSE2 %s\n", SDL_HasSSE2()? "detected" : "not detected");
SDL_Log("SSE3 %s\n", SDL_HasSSE3()? "detected" : "not detected");
SDL_Log("SSE4.1 %s\n", SDL_HasSSE41()? "detected" : "not detected");
SDL_Log("SSE4.2 %s\n", SDL_HasSSE42()? "detected" : "not detected");
SDL_Log("AVX %s\n", SDL_HasAVX()? "detected" : "not detected");
SDL_Log("AVX2 %s\n", SDL_HasAVX2()? "detected" : "not detected");
SDL_Log("AVX-512F %s\n", SDL_HasAVX512F()? "detected" : "not detected");
SDL_Log("ARM SIMD %s\n", SDL_HasARMSIMD()? "detected" : "not detected");
SDL_Log("NEON %s\n", SDL_HasNEON()? "detected" : "not detected");
SDL_Log("LSX %s\n", SDL_HasLSX()? "detected" : "not detected");
SDL_Log("LASX %s\n", SDL_HasLASX()? "detected" : "not detected");
SDL_Log("RDTSC %s\n", SDL_HasRDTSC() ? "detected" : "not detected");
SDL_Log("AltiVec %s\n", SDL_HasAltiVec() ? "detected" : "not detected");
SDL_Log("MMX %s\n", SDL_HasMMX() ? "detected" : "not detected");
SDL_Log("3DNow! %s\n", SDL_Has3DNow() ? "detected" : "not detected");
SDL_Log("SSE %s\n", SDL_HasSSE() ? "detected" : "not detected");
SDL_Log("SSE2 %s\n", SDL_HasSSE2() ? "detected" : "not detected");
SDL_Log("SSE3 %s\n", SDL_HasSSE3() ? "detected" : "not detected");
SDL_Log("SSE4.1 %s\n", SDL_HasSSE41() ? "detected" : "not detected");
SDL_Log("SSE4.2 %s\n", SDL_HasSSE42() ? "detected" : "not detected");
SDL_Log("AVX %s\n", SDL_HasAVX() ? "detected" : "not detected");
SDL_Log("AVX2 %s\n", SDL_HasAVX2() ? "detected" : "not detected");
SDL_Log("AVX-512F %s\n", SDL_HasAVX512F() ? "detected" : "not detected");
SDL_Log("ARM SIMD %s\n", SDL_HasARMSIMD() ? "detected" : "not detected");
SDL_Log("NEON %s\n", SDL_HasNEON() ? "detected" : "not detected");
SDL_Log("LSX %s\n", SDL_HasLSX() ? "detected" : "not detected");
SDL_Log("LASX %s\n", SDL_HasLASX() ? "detected" : "not detected");
SDL_Log("System RAM %d MB\n", SDL_GetSystemRAM());
}
return 0;
}
int
TestAssertions(SDL_bool verbose)
int TestAssertions(SDL_bool verbose)
{
SDL_assert(1);
SDL_assert_release(1);
@@ -427,7 +422,7 @@ TestAssertions(SDL_bool verbose)
SDL_assert_release(0 || 1);
SDL_assert_paranoid(0 || 1);
#if 0 /* enable this to test assertion failures. */
#if 0 /* enable this to test assertion failures. */
SDL_assert_release(1 == 2);
SDL_assert_release(5 < 4);
SDL_assert_release(0 && "This is a test");
@@ -437,17 +432,16 @@ TestAssertions(SDL_bool verbose)
const SDL_AssertData *item = SDL_GetAssertionReport();
while (item) {
SDL_Log("'%s', %s (%s:%d), triggered %u times, always ignore: %s.\n",
item->condition, item->function, item->filename,
item->linenum, item->trigger_count,
item->always_ignore ? "yes" : "no");
item->condition, item->function, item->filename,
item->linenum, item->trigger_count,
item->always_ignore ? "yes" : "no");
item = item->next;
}
}
return 0;
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
SDL_bool verbose = SDL_TRUE;
int status = 0;

View File

@@ -54,14 +54,12 @@ report_power(void)
if (seconds == -1) {
SDL_Log("Time left: unknown\n");
} else {
SDL_Log("Time left: %d minutes, %d seconds\n", (int) (seconds / 60),
(int) (seconds % 60));
SDL_Log("Time left: %d minutes, %d seconds\n", (int)(seconds / 60),
(int)(seconds % 60));
}
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);

View File

@@ -15,8 +15,8 @@
static int SDLCALL
num_compare(const void *_a, const void *_b)
{
const int a = *((const int *) _a);
const int b = *((const int *) _b);
const int a = *((const int *)_a);
const int b = *((const int *)_b);
return (a < b) ? -1 : ((a > b) ? 1 : 0);
}
@@ -28,7 +28,7 @@ test_sort(const char *desc, int *nums, const int arraylen)
SDL_Log("test: %s arraylen=%d", desc, arraylen);
SDL_qsort(nums, arraylen, sizeof (nums[0]), num_compare);
SDL_qsort(nums, arraylen, sizeof(nums[0]), num_compare);
prev = nums[0];
for (i = 1; i < arraylen; i++) {
@@ -41,8 +41,7 @@ test_sort(const char *desc, int *nums, const int arraylen)
}
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
static int nums[1024 * 100];
static const int itervals[] = { SDL_arraysize(nums), 12 };
@@ -53,9 +52,9 @@ main(int argc, char *argv[])
int success;
Uint64 seed = 0;
if (argv[1][0] == '0' && argv[1][1] == 'x')
success = SDL_sscanf(argv[1] + 2, "%"SDL_PRIx64, &seed);
success = SDL_sscanf(argv[1] + 2, "%" SDL_PRIx64, &seed);
else
success = SDL_sscanf(argv[1], "%"SDL_PRIu64, &seed);
success = SDL_sscanf(argv[1], "%" SDL_PRIu64, &seed);
if (!success) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid seed. Use a decimal or hexadecimal number.\n");
return 1;
@@ -82,11 +81,11 @@ main(int argc, char *argv[])
for (i = 0; i < arraylen; i++) {
nums[i] = i;
}
nums[arraylen-1] = -1;
nums[arraylen - 1] = -1;
test_sort("already sorted except last element", nums, arraylen);
for (i = 0; i < arraylen; i++) {
nums[i] = (arraylen-1) - i;
nums[i] = (arraylen - 1) - i;
}
test_sort("reverse sorted", nums, arraylen);

View File

@@ -28,24 +28,24 @@ SDL_Rect rect;
SDL_Event event;
static void
DrawRects(SDL_Renderer * renderer)
DrawRects(SDL_Renderer *renderer)
{
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
SDL_RenderFillRect(renderer, &rect);
}
static void
loop() {
loop()
{
/* Check for events */
while (SDL_PollEvent(&event)) {
SDLTest_CommonEvent(state, &event, &done);
switch(event.type) {
switch (event.type) {
case SDL_MOUSEMOTION:
{
rect.x += event.motion.xrel;
rect.y += event.motion.yrel;
}
break;
{
rect.x += event.motion.xrel;
rect.y += event.motion.yrel;
} break;
}
}
for (i = 0; i < state->num_windows; ++i) {
@@ -83,8 +83,7 @@ loop() {
#endif
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
/* Enable standard application logging */
@@ -126,7 +125,7 @@ main(int argc, char *argv[])
#else
while (!done) {
loop();
}
}
#endif
SDLTest_CommonQuit(state);
return 0;

View File

@@ -24,7 +24,8 @@
static SDLTest_CommonState *state;
typedef struct {
typedef struct
{
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *background;
@@ -44,13 +45,12 @@ quit(int rc)
exit(rc);
}
void
Draw(DrawState *s)
void Draw(DrawState *s)
{
SDL_Rect viewport;
SDL_Texture *target;
SDL_Point *center=NULL;
SDL_Point origin = {0,0};
SDL_Point *center = NULL;
SDL_Point origin = { 0, 0 };
SDL_RenderGetViewport(s->renderer, &viewport);
@@ -110,8 +110,7 @@ void loop()
#endif
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int i;
int frames;
@@ -158,12 +157,12 @@ main(int argc, char *argv[])
while (!done) {
++frames;
loop();
}
}
#endif
/* Print out some timing information */
now = SDL_GetTicks();
if (now > then) {
double fps = ((double) frames * 1000) / (now - then);
double fps = ((double)frames * 1000) / (now - then);
SDL_Log("%2.2f frames per second\n", fps);
}

View File

@@ -24,7 +24,8 @@
static SDLTest_CommonState *state;
typedef struct {
typedef struct
{
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *background;
@@ -172,8 +173,7 @@ Draw(DrawState *s)
return SDL_TRUE;
}
void
loop()
void loop()
{
int i;
SDL_Event event;
@@ -203,8 +203,7 @@ loop()
#endif
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int i;
int frames;
@@ -277,7 +276,7 @@ main(int argc, char *argv[])
/* Print out some timing information */
now = SDL_GetTicks();
if (now > then) {
double fps = ((double) frames * 1000) / (now - then);
double fps = ((double)frames * 1000) / (now - then);
SDL_Log("%2.2f frames per second\n", fps);
}

View File

@@ -12,8 +12,7 @@
#include "SDL.h"
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
SDL_AudioSpec spec;
SDL_AudioCVT cvt;
@@ -57,7 +56,7 @@ main(int argc, char **argv)
}
cvt.len = len;
cvt.buf = (Uint8 *) SDL_malloc(len * cvt.len_mult);
cvt.buf = (Uint8 *)SDL_malloc(len * cvt.len_mult);
if (cvt.buf == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory.\n");
SDL_FreeWAV(data);
@@ -88,19 +87,19 @@ main(int argc, char **argv)
blockalign = (bitsize / 8) * cvtchans;
avgbytes = cvtfreq * blockalign;
SDL_WriteLE32(io, 0x46464952); /* RIFF */
SDL_WriteLE32(io, 0x46464952); /* RIFF */
SDL_WriteLE32(io, cvt.len_cvt + 36);
SDL_WriteLE32(io, 0x45564157); /* WAVE */
SDL_WriteLE32(io, 0x20746D66); /* fmt */
SDL_WriteLE32(io, 16); /* chunk size */
SDL_WriteLE16(io, SDL_AUDIO_ISFLOAT(spec.format) ? 3 : 1); /* uncompressed */
SDL_WriteLE16(io, cvtchans); /* channels */
SDL_WriteLE32(io, cvtfreq); /* sample rate */
SDL_WriteLE32(io, avgbytes); /* average bytes per second */
SDL_WriteLE16(io, blockalign); /* block align */
SDL_WriteLE16(io, bitsize); /* significant bits per sample */
SDL_WriteLE32(io, 0x61746164); /* data */
SDL_WriteLE32(io, cvt.len_cvt); /* size */
SDL_WriteLE32(io, 0x45564157); /* WAVE */
SDL_WriteLE32(io, 0x20746D66); /* fmt */
SDL_WriteLE32(io, 16); /* chunk size */
SDL_WriteLE16(io, SDL_AUDIO_ISFLOAT(spec.format) ? 3 : 1); /* uncompressed */
SDL_WriteLE16(io, cvtchans); /* channels */
SDL_WriteLE32(io, cvtfreq); /* sample rate */
SDL_WriteLE32(io, avgbytes); /* average bytes per second */
SDL_WriteLE16(io, blockalign); /* block align */
SDL_WriteLE16(io, bitsize); /* significant bits per sample */
SDL_WriteLE32(io, 0x61746164); /* data */
SDL_WriteLE32(io, cvt.len_cvt); /* size */
SDL_RWwrite(io, cvt.buf, cvt.len_cvt, 1);
if (SDL_RWclose(io) == -1) {
@@ -109,12 +108,12 @@ main(int argc, char **argv)
SDL_FreeWAV(data);
SDL_Quit();
return 8;
} /* if */
} /* if */
SDL_free(cvt.buf);
SDL_FreeWAV(data);
SDL_Quit();
return 0;
} /* main */
} /* main */
/* end of testresample.c ... */

View File

@@ -31,14 +31,12 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
static SDL_Haptic *haptic;
/**
* @brief The entry point of this force feedback demo.
* @param[in] argc Number of arguments.
* @param[in] argv Array of argc arguments.
*/
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
int i;
char *name;
@@ -54,9 +52,9 @@ main(int argc, char **argv)
name = argv[1];
if ((SDL_strcmp(name, "--help") == 0) || (SDL_strcmp(name, "-h") == 0)) {
SDL_Log("USAGE: %s [device]\n"
"If device is a two-digit number it'll use it as an index, otherwise\n"
"it'll use it as if it were part of the device's name.\n",
argv[0]);
"If device is a two-digit number it'll use it as an index, otherwise\n"
"it'll use it as if it were part of the device's name.\n",
argv[0]);
return 0;
}
@@ -86,7 +84,7 @@ main(int argc, char **argv)
if (i >= SDL_NumHaptics()) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n",
name);
name);
return 1;
}
}
@@ -94,7 +92,7 @@ main(int argc, char **argv)
haptic = SDL_HapticOpen(i);
if (haptic == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n",
SDL_GetError());
SDL_GetError());
return 1;
}
SDL_Log("Device: %s\n", SDL_HapticName(i));
@@ -116,8 +114,8 @@ main(int argc, char **argv)
}
SDL_Log("Playing 2 second rumble at 0.5 magnitude.\n");
if (SDL_HapticRumblePlay(haptic, 0.5, 5000) != 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError() );
return 1;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError());
return 1;
}
SDL_Delay(2000);
SDL_Log("Stopping rumble.\n");
@@ -125,8 +123,8 @@ main(int argc, char **argv)
SDL_Delay(2000);
SDL_Log("Playing 2 second rumble at 0.3 magnitude.\n");
if (SDL_HapticRumblePlay(haptic, 0.3f, 5000) != 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError() );
return 1;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError());
return 1;
}
SDL_Delay(2000);

View File

@@ -22,12 +22,13 @@
#include "SDL_test_common.h"
#include "testutils.h"
#define WINDOW_WIDTH 640
#define WINDOW_HEIGHT 480
#define WINDOW_WIDTH 640
#define WINDOW_HEIGHT 480
static SDLTest_CommonState *state;
typedef struct {
typedef struct
{
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *background;
@@ -47,8 +48,7 @@ quit(int rc)
exit(rc);
}
void
Draw(DrawState *s)
void Draw(DrawState *s)
{
SDL_Rect viewport;
@@ -78,8 +78,7 @@ Draw(DrawState *s)
SDL_RenderPresent(s->renderer);
}
void
loop()
void loop()
{
int i;
SDL_Event event;
@@ -101,8 +100,7 @@ loop()
#endif
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int i;
int frames;
@@ -155,7 +153,7 @@ main(int argc, char *argv[])
/* Print out some timing information */
now = SDL_GetTicks();
if (now > then) {
double fps = ((double) frames * 1000) / (now - then);
double fps = ((double)frames * 1000) / (now - then);
SDL_Log("%2.2f frames per second\n", fps);
}

View File

@@ -21,14 +21,15 @@
#define NUM_THREADS 10
/* This value should be smaller than the maximum count of the */
/* semaphore implementation: */
#define NUM_OVERHEAD_OPS 10000
#define NUM_OVERHEAD_OPS 10000
#define NUM_OVERHEAD_OPS_MULT 10
static SDL_sem *sem;
int alive;
typedef struct Thread_State {
SDL_Thread * thread;
typedef struct Thread_State
{
SDL_Thread *thread;
int number;
SDL_bool flag;
int loop_count;
@@ -44,7 +45,7 @@ killed(int sig)
static int SDLCALL
ThreadFuncRealWorld(void *data)
{
Thread_State *state = (Thread_State *) data;
Thread_State *state = (Thread_State *)data;
while (alive) {
SDL_SemWait(sem);
SDL_Log("Thread number %d has got the semaphore (value = %" SDL_PRIu32 ")!\n",
@@ -54,29 +55,30 @@ ThreadFuncRealWorld(void *data)
SDL_Log("Thread number %d has released the semaphore (value = %" SDL_PRIu32 ")!\n",
state->number, SDL_SemValue(sem));
++state->loop_count;
SDL_Delay(1); /* For the scheduler */
SDL_Delay(1); /* For the scheduler */
}
SDL_Log("Thread number %d exiting.\n", state->number);
return 0;
}
static void
TestRealWorld(int init_sem) {
Thread_State thread_states[NUM_THREADS] = { {0} };
TestRealWorld(int init_sem)
{
Thread_State thread_states[NUM_THREADS] = { { 0 } };
int i;
int loop_count;
sem = SDL_CreateSemaphore(init_sem);
SDL_Log("Running %d threads, semaphore value = %d\n", NUM_THREADS,
init_sem);
init_sem);
alive = 1;
/* Create all the threads */
for (i = 0; i < NUM_THREADS; ++i) {
char name[64];
SDL_snprintf(name, sizeof (name), "Thread%u", (unsigned int) i);
SDL_snprintf(name, sizeof(name), "Thread%u", (unsigned int)i);
thread_states[i].number = i;
thread_states[i].thread = SDL_CreateThread(ThreadFuncRealWorld, name, (void *) &thread_states[i]);
thread_states[i].thread = SDL_CreateThread(ThreadFuncRealWorld, name, (void *)&thread_states[i]);
}
/* Wait 10 seconds */
@@ -155,7 +157,7 @@ TestOverheadUncontended(void)
static int SDLCALL
ThreadFuncOverheadContended(void *data)
{
Thread_State *state = (Thread_State *) data;
Thread_State *state = (Thread_State *)data;
if (state->flag) {
while (alive) {
@@ -182,7 +184,7 @@ TestOverheadContended(SDL_bool try_wait)
Uint32 start_ticks;
Uint32 end_ticks;
Uint32 duration;
Thread_State thread_states[NUM_THREADS] = { {0} };
Thread_State thread_states[NUM_THREADS] = { { 0 } };
char textBuffer[1024];
int loop_count;
int content_count;
@@ -196,9 +198,9 @@ TestOverheadContended(SDL_bool try_wait)
/* Create multiple threads to starve the semaphore and cause contention */
for (i = 0; i < NUM_THREADS; ++i) {
char name[64];
SDL_snprintf(name, sizeof (name), "Thread%u", (unsigned int) i);
SDL_snprintf(name, sizeof(name), "Thread%u", (unsigned int)i);
thread_states[i].flag = try_wait;
thread_states[i].thread = SDL_CreateThread(ThreadFuncOverheadContended, name, (void *) &thread_states[i]);
thread_states[i].thread = SDL_CreateThread(ThreadFuncOverheadContended, name, (void *)&thread_states[i]);
}
start_ticks = SDL_GetTicks();
@@ -207,7 +209,8 @@ TestOverheadContended(SDL_bool try_wait)
SDL_SemPost(sem);
}
/* Make sure threads consumed everything */
while (SDL_SemValue(sem)) { }
while (SDL_SemValue(sem)) {
}
}
end_ticks = SDL_GetTicks();
@@ -224,7 +227,7 @@ TestOverheadContended(SDL_bool try_wait)
duration = end_ticks - start_ticks;
SDL_Log("Took %" SDL_PRIu32 " milliseconds, threads %s %d out of %d times in total (%.2f%%)\n",
duration, try_wait ? "where contended" : "timed out", content_count,
loop_count, ((float) content_count * 100) / loop_count);
loop_count, ((float)content_count * 100) / loop_count);
/* Print how many semaphores where consumed per thread */
SDL_snprintf(textBuffer, sizeof(textBuffer), "{ ");
for (i = 0; i < NUM_THREADS; ++i) {
@@ -242,8 +245,7 @@ TestOverheadContended(SDL_bool try_wait)
SDL_DestroySemaphore(sem);
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
int init_sem;

View File

@@ -18,8 +18,7 @@ static const char *GetSensorTypeString(SDL_SensorType type)
{
static char unknown_type[64];
switch (type)
{
switch (type) {
case SDL_SENSOR_INVALID:
return "SDL_SENSOR_INVALID";
case SDL_SENSOR_UNKNOWN:
@@ -55,8 +54,7 @@ static void HandleSensorEvent(SDL_SensorEvent *event)
}
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
int i;
int num_sensors, num_opened;

View File

@@ -17,18 +17,19 @@
#include "SDL_opengl.h"
static SDL_bool shaders_supported;
static int current_shader = 0;
static int current_shader = 0;
enum {
enum
{
SHADER_COLOR,
SHADER_TEXTURE,
SHADER_TEXCOORDS,
NUM_SHADERS
};
typedef struct {
typedef struct
{
GLhandleARB program;
GLhandleARB vert_shader;
GLhandleARB frag_shader;
@@ -40,75 +41,72 @@ static ShaderData shaders[NUM_SHADERS] = {
/* SHADER_COLOR */
{ 0, 0, 0,
/* vertex shader */
"varying vec4 v_color;\n"
"\n"
"void main()\n"
"{\n"
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
" v_color = gl_Color;\n"
"}",
/* fragment shader */
"varying vec4 v_color;\n"
"\n"
"void main()\n"
"{\n"
" gl_FragColor = v_color;\n"
"}"
},
/* vertex shader */
"varying vec4 v_color;\n"
"\n"
"void main()\n"
"{\n"
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
" v_color = gl_Color;\n"
"}",
/* fragment shader */
"varying vec4 v_color;\n"
"\n"
"void main()\n"
"{\n"
" gl_FragColor = v_color;\n"
"}" },
/* SHADER_TEXTURE */
{ 0, 0, 0,
/* vertex shader */
"varying vec4 v_color;\n"
"varying vec2 v_texCoord;\n"
"\n"
"void main()\n"
"{\n"
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
" v_color = gl_Color;\n"
" v_texCoord = vec2(gl_MultiTexCoord0);\n"
"}",
/* fragment shader */
"varying vec4 v_color;\n"
"varying vec2 v_texCoord;\n"
"uniform sampler2D tex0;\n"
"\n"
"void main()\n"
"{\n"
" gl_FragColor = texture2D(tex0, v_texCoord) * v_color;\n"
"}"
},
/* vertex shader */
"varying vec4 v_color;\n"
"varying vec2 v_texCoord;\n"
"\n"
"void main()\n"
"{\n"
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
" v_color = gl_Color;\n"
" v_texCoord = vec2(gl_MultiTexCoord0);\n"
"}",
/* fragment shader */
"varying vec4 v_color;\n"
"varying vec2 v_texCoord;\n"
"uniform sampler2D tex0;\n"
"\n"
"void main()\n"
"{\n"
" gl_FragColor = texture2D(tex0, v_texCoord) * v_color;\n"
"}" },
/* SHADER_TEXCOORDS */
{ 0, 0, 0,
/* vertex shader */
"varying vec2 v_texCoord;\n"
"\n"
"void main()\n"
"{\n"
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
" v_texCoord = vec2(gl_MultiTexCoord0);\n"
"}",
/* fragment shader */
"varying vec2 v_texCoord;\n"
"\n"
"void main()\n"
"{\n"
" vec4 color;\n"
" vec2 delta;\n"
" float dist;\n"
"\n"
" delta = vec2(0.5, 0.5) - v_texCoord;\n"
" dist = dot(delta, delta);\n"
"\n"
" color.r = v_texCoord.x;\n"
" color.g = v_texCoord.x * v_texCoord.y;\n"
" color.b = v_texCoord.y;\n"
" color.a = 1.0 - (dist * 4.0);\n"
" gl_FragColor = color;\n"
"}"
},
/* vertex shader */
"varying vec2 v_texCoord;\n"
"\n"
"void main()\n"
"{\n"
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
" v_texCoord = vec2(gl_MultiTexCoord0);\n"
"}",
/* fragment shader */
"varying vec2 v_texCoord;\n"
"\n"
"void main()\n"
"{\n"
" vec4 color;\n"
" vec2 delta;\n"
" float dist;\n"
"\n"
" delta = vec2(0.5, 0.5) - v_texCoord;\n"
" dist = dot(delta, delta);\n"
"\n"
" color.r = v_texCoord.x;\n"
" color.g = v_texCoord.x * v_texCoord.y;\n"
" color.b = v_texCoord.y;\n"
" color.a = 1.0 - (dist * 4.0);\n"
" gl_FragColor = color;\n"
"}" },
};
static PFNGLATTACHOBJECTARBPROC glAttachObjectARB;
@@ -136,7 +134,7 @@ static SDL_bool CompileShader(GLhandleARB shader, const char *source)
char *info;
glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
info = (char *) SDL_malloc(length + 1);
info = (char *)SDL_malloc(length + 1);
if (info == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
} else {
@@ -164,7 +162,7 @@ static SDL_bool LinkProgram(ShaderData *data)
char *info;
glGetObjectParameterivARB(data->program, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
info = (char *) SDL_malloc(length + 1);
info = (char *)SDL_malloc(length + 1);
if (info == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
} else {
@@ -240,18 +238,18 @@ static SDL_bool InitShaders()
SDL_GL_ExtensionSupported("GL_ARB_shading_language_100") &&
SDL_GL_ExtensionSupported("GL_ARB_vertex_shader") &&
SDL_GL_ExtensionSupported("GL_ARB_fragment_shader")) {
glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) SDL_GL_GetProcAddress("glAttachObjectARB");
glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) SDL_GL_GetProcAddress("glCompileShaderARB");
glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) SDL_GL_GetProcAddress("glCreateProgramObjectARB");
glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) SDL_GL_GetProcAddress("glCreateShaderObjectARB");
glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) SDL_GL_GetProcAddress("glDeleteObjectARB");
glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC) SDL_GL_GetProcAddress("glGetInfoLogARB");
glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC) SDL_GL_GetProcAddress("glGetObjectParameterivARB");
glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) SDL_GL_GetProcAddress("glGetUniformLocationARB");
glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) SDL_GL_GetProcAddress("glLinkProgramARB");
glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) SDL_GL_GetProcAddress("glShaderSourceARB");
glUniform1iARB = (PFNGLUNIFORM1IARBPROC) SDL_GL_GetProcAddress("glUniform1iARB");
glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) SDL_GL_GetProcAddress("glUseProgramObjectARB");
glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)SDL_GL_GetProcAddress("glAttachObjectARB");
glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)SDL_GL_GetProcAddress("glCompileShaderARB");
glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)SDL_GL_GetProcAddress("glCreateProgramObjectARB");
glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)SDL_GL_GetProcAddress("glCreateShaderObjectARB");
glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)SDL_GL_GetProcAddress("glDeleteObjectARB");
glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)SDL_GL_GetProcAddress("glGetInfoLogARB");
glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)SDL_GL_GetProcAddress("glGetObjectParameterivARB");
glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)SDL_GL_GetProcAddress("glGetUniformLocationARB");
glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)SDL_GL_GetProcAddress("glLinkProgramARB");
glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)SDL_GL_GetProcAddress("glShaderSourceARB");
glUniform1iARB = (PFNGLUNIFORM1IARBPROC)SDL_GL_GetProcAddress("glUniform1iARB");
glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)SDL_GL_GetProcAddress("glUseProgramObjectARB");
if (glAttachObjectARB &&
glCompileShaderARB &&
glCreateProgramObjectARB &&
@@ -306,7 +304,7 @@ power_of_two(int input)
}
GLuint
SDL_GL_LoadTexture(SDL_Surface * surface, GLfloat * texcoord)
SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord)
{
GLuint texture;
int w, h;
@@ -317,10 +315,10 @@ SDL_GL_LoadTexture(SDL_Surface * surface, GLfloat * texcoord)
/* Use the surface width and height expanded to powers of 2 */
w = power_of_two(surface->w);
h = power_of_two(surface->h);
texcoord[0] = 0.0f; /* Min X */
texcoord[1] = 0.0f; /* Min Y */
texcoord[2] = (GLfloat) surface->w / w; /* Max X */
texcoord[3] = (GLfloat) surface->h / h; /* Max Y */
texcoord[0] = 0.0f; /* Min X */
texcoord[1] = 0.0f; /* Min Y */
texcoord[2] = (GLfloat)surface->w / w; /* Max X */
texcoord[3] = (GLfloat)surface->h / h; /* Max Y */
image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
@@ -330,7 +328,7 @@ SDL_GL_LoadTexture(SDL_Surface * surface, GLfloat * texcoord)
0xFF000000,
0x00FF0000, 0x0000FF00, 0x000000FF
#endif
);
);
if (image == NULL) {
return 0;
}
@@ -357,25 +355,25 @@ SDL_GL_LoadTexture(SDL_Surface * surface, GLfloat * texcoord)
glTexImage2D(GL_TEXTURE_2D,
0,
GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);
SDL_FreeSurface(image); /* No longer needed */
SDL_FreeSurface(image); /* No longer needed */
return texture;
}
/* A general OpenGL initialization function. Sets all of the initial parameters. */
void InitGL(int Width, int Height) /* We call this right after our OpenGL window is created. */
void InitGL(int Width, int Height) /* We call this right after our OpenGL window is created. */
{
GLdouble aspect;
glViewport(0, 0, Width, Height);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); /* This Will Clear The Background Color To Black */
glClearDepth(1.0); /* Enables Clearing Of The Depth Buffer */
glDepthFunc(GL_LESS); /* The Type Of Depth Test To Do */
glEnable(GL_DEPTH_TEST); /* Enables Depth Testing */
glShadeModel(GL_SMOOTH); /* Enables Smooth Color Shading */
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); /* This Will Clear The Background Color To Black */
glClearDepth(1.0); /* Enables Clearing Of The Depth Buffer */
glDepthFunc(GL_LESS); /* The Type Of Depth Test To Do */
glEnable(GL_DEPTH_TEST); /* Enables Depth Testing */
glShadeModel(GL_SMOOTH); /* Enables Smooth Color Shading */
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); /* Reset The Projection Matrix */
glLoadIdentity(); /* Reset The Projection Matrix */
aspect = (GLdouble)Width / Height;
glOrtho(-3.0, 3.0, -3.0 / aspect, 3.0 / aspect, 0.0, 1.0);
@@ -384,32 +382,33 @@ void InitGL(int Width, int Height) /* We call this right afte
}
/* The main drawing function. */
void DrawGLScene(SDL_Window *window, GLuint texture, GLfloat * texcoord)
void DrawGLScene(SDL_Window *window, GLuint texture, GLfloat *texcoord)
{
/* Texture coordinate lookup, to make it simple */
enum {
enum
{
MINX,
MINY,
MAXX,
MAXY
};
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Clear The Screen And The Depth Buffer */
glLoadIdentity(); /* Reset The View */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Clear The Screen And The Depth Buffer */
glLoadIdentity(); /* Reset The View */
glTranslatef(-1.5f,0.0f,0.0f); /* Move Left 1.5 Units */
glTranslatef(-1.5f, 0.0f, 0.0f); /* Move Left 1.5 Units */
/* draw a triangle (in smooth coloring mode) */
glBegin(GL_POLYGON); /* start drawing a polygon */
glColor3f(1.0f,0.0f,0.0f); /* Set The Color To Red */
glVertex3f( 0.0f, 1.0f, 0.0f); /* Top */
glColor3f(0.0f,1.0f,0.0f); /* Set The Color To Green */
glVertex3f( 1.0f,-1.0f, 0.0f); /* Bottom Right */
glColor3f(0.0f,0.0f,1.0f); /* Set The Color To Blue */
glVertex3f(-1.0f,-1.0f, 0.0f); /* Bottom Left */
glEnd(); /* we're done with the polygon (smooth color interpolation) */
glBegin(GL_POLYGON); /* start drawing a polygon */
glColor3f(1.0f, 0.0f, 0.0f); /* Set The Color To Red */
glVertex3f(0.0f, 1.0f, 0.0f); /* Top */
glColor3f(0.0f, 1.0f, 0.0f); /* Set The Color To Green */
glVertex3f(1.0f, -1.0f, 0.0f); /* Bottom Right */
glColor3f(0.0f, 0.0f, 1.0f); /* Set The Color To Blue */
glVertex3f(-1.0f, -1.0f, 0.0f); /* Bottom Left */
glEnd(); /* we're done with the polygon (smooth color interpolation) */
glTranslatef(3.0f,0.0f,0.0f); /* Move Right 3 Units */
glTranslatef(3.0f, 0.0f, 0.0f); /* Move Right 3 Units */
/* Enable blending */
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
@@ -419,21 +418,21 @@ void DrawGLScene(SDL_Window *window, GLuint texture, GLfloat * texcoord)
/* draw a textured square (quadrilateral) */
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
glColor3f(1.0f,1.0f,1.0f);
glColor3f(1.0f, 1.0f, 1.0f);
if (shaders_supported) {
glUseProgramObjectARB(shaders[current_shader].program);
}
glBegin(GL_QUADS); /* start drawing a polygon (4 sided) */
glBegin(GL_QUADS); /* start drawing a polygon (4 sided) */
glTexCoord2f(texcoord[MINX], texcoord[MINY]);
glVertex3f(-1.0f, 1.0f, 0.0f); /* Top Left */
glVertex3f(-1.0f, 1.0f, 0.0f); /* Top Left */
glTexCoord2f(texcoord[MAXX], texcoord[MINY]);
glVertex3f( 1.0f, 1.0f, 0.0f); /* Top Right */
glVertex3f(1.0f, 1.0f, 0.0f); /* Top Right */
glTexCoord2f(texcoord[MAXX], texcoord[MAXY]);
glVertex3f( 1.0f,-1.0f, 0.0f); /* Bottom Right */
glVertex3f(1.0f, -1.0f, 0.0f); /* Bottom Right */
glTexCoord2f(texcoord[MINX], texcoord[MAXY]);
glVertex3f(-1.0f,-1.0f, 0.0f); /* Bottom Left */
glEnd(); /* done with the polygon */
glVertex3f(-1.0f, -1.0f, 0.0f); /* Bottom Left */
glEnd(); /* done with the polygon */
if (shaders_supported) {
glUseProgramObjectARB(0);
@@ -456,20 +455,20 @@ int main(int argc, char **argv)
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize SDL for video output */
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to initialize SDL: %s\n", SDL_GetError());
exit(1);
}
/* Create a 640x480 OpenGL screen */
window = SDL_CreateWindow( "Shader Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL );
window = SDL_CreateWindow("Shader Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL);
if (window == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create OpenGL window: %s\n", SDL_GetError());
SDL_Quit();
exit(2);
}
if ( !SDL_GL_CreateContext(window)) {
if (!SDL_GL_CreateContext(window)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create OpenGL context: %s\n", SDL_GetError());
SDL_Quit();
exit(2);
@@ -492,20 +491,21 @@ int main(int argc, char **argv)
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Shaders not supported!\n");
}
done = 0;
while ( ! done ) {
while (!done) {
DrawGLScene(window, texture, texcoords);
/* This could go in a separate function */
{ SDL_Event event;
while ( SDL_PollEvent(&event) ) {
if ( event.type == SDL_QUIT ) {
{
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
done = 1;
}
if ( event.type == SDL_KEYDOWN ) {
if ( event.key.keysym.sym == SDLK_SPACE ) {
if (event.type == SDL_KEYDOWN) {
if (event.key.keysym.sym == SDLK_SPACE) {
current_shader = (current_shader + 1) % NUM_SHADERS;
}
if ( event.key.keysym.sym == SDLK_ESCAPE ) {
if (event.key.keysym.sym == SDLK_ESCAPE) {
done = 1;
}
}
@@ -519,8 +519,7 @@ int main(int argc, char **argv)
#else /* HAVE_OPENGL */
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No OpenGL support on this system\n");
return 1;

View File

@@ -15,38 +15,39 @@
#include "SDL.h"
#include "SDL_shape.h"
#define SHAPED_WINDOW_X 150
#define SHAPED_WINDOW_Y 150
#define SHAPED_WINDOW_X 150
#define SHAPED_WINDOW_Y 150
#define SHAPED_WINDOW_DIMENSION 640
typedef struct LoadedPicture {
typedef struct LoadedPicture
{
SDL_Surface *surface;
SDL_Texture *texture;
SDL_WindowShapeMode mode;
const char* name;
const char *name;
} LoadedPicture;
void render(SDL_Renderer *renderer,SDL_Texture *texture,SDL_Rect texture_dimensions)
void render(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Rect texture_dimensions)
{
/* Clear render-target to blue. */
SDL_SetRenderDrawColor(renderer,0x00,0x00,0xff,0xff);
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0xff, 0xff);
SDL_RenderClear(renderer);
/* Render the texture. */
SDL_RenderCopy(renderer,texture,&texture_dimensions,&texture_dimensions);
SDL_RenderCopy(renderer, texture, &texture_dimensions, &texture_dimensions);
SDL_RenderPresent(renderer);
}
int main(int argc,char** argv)
int main(int argc, char **argv)
{
Uint8 num_pictures;
LoadedPicture* pictures;
LoadedPicture *pictures;
int i, j;
SDL_PixelFormat* format = NULL;
SDL_PixelFormat *format = NULL;
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Color black = {0,0,0,0xff};
SDL_Color black = { 0, 0, 0, 0xff };
SDL_Event event;
int should_exit = 0;
unsigned int current_picture;
@@ -69,7 +70,7 @@ int main(int argc,char** argv)
}
num_pictures = argc - 1;
pictures = (LoadedPicture *)SDL_malloc(sizeof(LoadedPicture)*num_pictures);
pictures = (LoadedPicture *)SDL_malloc(sizeof(LoadedPicture) * num_pictures);
if (pictures == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not allocate memory.");
exit(1);
@@ -77,16 +78,16 @@ int main(int argc,char** argv)
for (i = 0; i < num_pictures; i++) {
pictures[i].surface = NULL;
}
for (i=0;i<num_pictures;i++) {
pictures[i].surface = SDL_LoadBMP(argv[i+1]);
pictures[i].name = argv[i+1];
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++) {
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]);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not load surface from named bitmap file: %s", argv[i + 1]);
exit(-3);
}
@@ -101,9 +102,9 @@ int main(int argc,char** argv)
}
window = SDL_CreateShapedWindow("SDL_Shape test",
SHAPED_WINDOW_X, SHAPED_WINDOW_Y,
SHAPED_WINDOW_DIMENSION,SHAPED_WINDOW_DIMENSION,
0);
SHAPED_WINDOW_X, SHAPED_WINDOW_Y,
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++) {
@@ -114,7 +115,7 @@ int main(int argc,char** argv)
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create shaped window for SDL_Shape.");
exit(-4);
}
renderer = SDL_CreateRenderer(window,-1,0);
renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer == NULL) {
SDL_DestroyWindow(window);
for (i = 0; i < num_pictures; i++) {
@@ -129,10 +130,10 @@ int main(int argc,char** argv)
for (i = 0; i < num_pictures; i++) {
pictures[i].texture = NULL;
}
for (i=0;i<num_pictures;i++) {
pictures[i].texture = SDL_CreateTextureFromSurface(renderer,pictures[i].surface);
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++) {
for (i = 0; i < num_pictures; i++) {
if (pictures[i].texture != NULL) {
SDL_DestroyTexture(pictures[i].texture);
}
@@ -157,9 +158,9 @@ int main(int argc,char** argv)
texture_dimensions.x = 0;
texture_dimensions.y = 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);
SDL_SetWindowShape(window,pictures[current_picture].surface,&pictures[current_picture].mode);
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 (SDL_PollEvent(&event)) {
if (event.type == SDL_KEYDOWN) {
@@ -176,16 +177,16 @@ int main(int argc,char** argv)
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);
SDL_SetWindowShape(window,pictures[current_picture].surface,&pictures[current_picture].mode);
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);
}
if (event.type == SDL_QUIT) {
should_exit = 1;
break;
}
}
render(renderer,pictures[current_picture].texture,texture_dimensions);
render(renderer, pictures[current_picture].texture, texture_dimensions);
SDL_Delay(10);
}

View File

@@ -23,8 +23,8 @@
#include "SDL_test_common.h"
#include "testutils.h"
#define NUM_SPRITES 100
#define MAX_SPEED 1
#define NUM_SPRITES 100
#define MAX_SPEED 1
static SDLTest_CommonState *state;
static int num_sprites;
@@ -64,8 +64,7 @@ quit(int rc)
}
}
int
LoadSprite(const char *file)
int LoadSprite(const char *file)
{
int i;
@@ -86,8 +85,7 @@ LoadSprite(const char *file)
return 0;
}
void
MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
void MoveSprites(SDL_Renderer *renderer, SDL_Texture *sprite)
{
int i;
SDL_Rect viewport, temp;
@@ -107,8 +105,8 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
current_color = 255;
cycle_direction = -cycle_direction;
}
SDL_SetTextureColorMod(sprite, 255, (Uint8) current_color,
(Uint8) current_color);
SDL_SetTextureColorMod(sprite, 255, (Uint8)current_color,
(Uint8)current_color);
}
if (cycle_alpha) {
current_alpha += cycle_direction;
@@ -120,7 +118,7 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
current_alpha = 255;
cycle_direction = -cycle_direction;
}
SDL_SetTextureAlphaMod(sprite, (Uint8) current_alpha);
SDL_SetTextureAlphaMod(sprite, (Uint8)current_alpha);
}
/* Draw a gray background */
@@ -130,16 +128,16 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
/* Test points */
SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0x00, 0xFF);
SDL_RenderDrawPoint(renderer, 0, 0);
SDL_RenderDrawPoint(renderer, viewport.w-1, 0);
SDL_RenderDrawPoint(renderer, 0, viewport.h-1);
SDL_RenderDrawPoint(renderer, viewport.w-1, viewport.h-1);
SDL_RenderDrawPoint(renderer, viewport.w - 1, 0);
SDL_RenderDrawPoint(renderer, 0, viewport.h - 1);
SDL_RenderDrawPoint(renderer, viewport.w - 1, viewport.h - 1);
/* Test horizontal and vertical lines */
SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
SDL_RenderDrawLine(renderer, 1, 0, viewport.w-2, 0);
SDL_RenderDrawLine(renderer, 1, viewport.h-1, viewport.w-2, viewport.h-1);
SDL_RenderDrawLine(renderer, 0, 1, 0, viewport.h-2);
SDL_RenderDrawLine(renderer, viewport.w-1, 1, viewport.w-1, viewport.h-2);
SDL_RenderDrawLine(renderer, 1, 0, viewport.w - 2, 0);
SDL_RenderDrawLine(renderer, 1, viewport.h - 1, viewport.w - 2, viewport.h - 1);
SDL_RenderDrawLine(renderer, 0, 1, 0, viewport.h - 2);
SDL_RenderDrawLine(renderer, viewport.w - 1, 1, viewport.w - 1, viewport.h - 2);
/* Test fill and copy */
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
@@ -180,20 +178,20 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
SDL_RenderGeometry(renderer, NULL, verts, 3, NULL, 0);
}
SDL_RenderCopy(renderer, sprite, NULL, &temp);
temp.x = viewport.w-sprite_w-1;
temp.x = viewport.w - sprite_w - 1;
temp.y = 1;
temp.w = sprite_w;
temp.h = sprite_h;
SDL_RenderFillRect(renderer, &temp);
SDL_RenderCopy(renderer, sprite, NULL, &temp);
temp.x = 1;
temp.y = viewport.h-sprite_h-1;
temp.y = viewport.h - sprite_h - 1;
temp.w = sprite_w;
temp.h = sprite_h;
SDL_RenderFillRect(renderer, &temp);
SDL_RenderCopy(renderer, sprite, NULL, &temp);
temp.x = viewport.w-sprite_w-1;
temp.y = viewport.h-sprite_h-1;
temp.x = viewport.w - sprite_w - 1;
temp.y = viewport.h - sprite_h - 1;
temp.w = sprite_w;
temp.h = sprite_h;
SDL_RenderFillRect(renderer, &temp);
@@ -202,9 +200,9 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
/* Test diagonal lines */
SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
SDL_RenderDrawLine(renderer, sprite_w, sprite_h,
viewport.w-sprite_w-2, viewport.h-sprite_h-2);
SDL_RenderDrawLine(renderer, viewport.w-sprite_w-2, sprite_h,
sprite_w, viewport.h-sprite_h-2);
viewport.w - sprite_w - 2, viewport.h - sprite_h - 2);
SDL_RenderDrawLine(renderer, viewport.w - sprite_w - 2, sprite_h,
sprite_w, viewport.h - sprite_h - 2);
/* Conditionally move the sprites, bounce at the wall */
if (iterations == -1 || iterations > 0) {
@@ -221,7 +219,6 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
velocity->y = -velocity->y;
position->y += velocity->y;
}
}
/* Countdown sprite-move iterations and disable color changes at iteration end - used for visual tests. */
@@ -251,7 +248,7 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
*
* Draw sprite2 as triangles that can be recombined as rect by software renderer
*/
SDL_Vertex *verts = (SDL_Vertex *) SDL_malloc(num_sprites * sizeof (SDL_Vertex) * 6);
SDL_Vertex *verts = (SDL_Vertex *)SDL_malloc(num_sprites * sizeof(SDL_Vertex) * 6);
SDL_Vertex *verts2 = verts;
if (verts) {
SDL_Color color;
@@ -319,9 +316,9 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
* Draw sprite2 as triangles that can *not* be recombined as rect by software renderer
* Use an 'indices' array
*/
SDL_Vertex *verts = (SDL_Vertex *) SDL_malloc(num_sprites * sizeof (SDL_Vertex) * 5);
SDL_Vertex *verts = (SDL_Vertex *)SDL_malloc(num_sprites * sizeof(SDL_Vertex) * 5);
SDL_Vertex *verts2 = verts;
int *indices = (int *) SDL_malloc(num_sprites * sizeof (int) * 4 * 3);
int *indices = (int *)SDL_malloc(num_sprites * sizeof(int) * 4 * 3);
int *indices2 = indices;
if (verts && indices) {
int pos = 0;
@@ -395,8 +392,7 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
SDL_RenderPresent(renderer);
}
void
loop()
void loop()
{
Uint32 now;
int i;
@@ -423,16 +419,14 @@ loop()
if (SDL_TICKS_PASSED(now, next_fps_check)) {
/* Print out some timing information */
const Uint32 then = next_fps_check - fps_check_delay;
const double fps = ((double) frames * 1000) / (now - then);
const double fps = ((double)frames * 1000) / (now - then);
SDL_Log("%2.2f frames per second\n", fps);
next_fps_check = now + fps_check_delay;
frames = 0;
}
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int i;
Uint64 seed;
@@ -517,7 +511,8 @@ main(int argc, char *argv[])
"[--use-rendergeometry mode1|mode2]",
"[num_sprites]",
"[icon.bmp]",
NULL };
NULL
};
SDLTest_CommonLogUsage(state, argv[0], options);
quit(1);
}
@@ -529,7 +524,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));
(SDL_Texture **)SDL_malloc(state->num_windows * sizeof(*sprites));
if (sprites == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
quit(2);
@@ -544,8 +539,8 @@ 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));
positions = (SDL_Rect *)SDL_malloc(num_sprites * sizeof(SDL_Rect));
velocities = (SDL_Rect *)SDL_malloc(num_sprites * sizeof(SDL_Rect));
if (positions == NULL || velocities == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
quit(2);

View File

@@ -22,10 +22,10 @@
#include "SDL.h"
#include "testutils.h"
#define WINDOW_WIDTH 640
#define WINDOW_HEIGHT 480
#define NUM_SPRITES 100
#define MAX_SPEED 1
#define WINDOW_WIDTH 640
#define WINDOW_HEIGHT 480
#define NUM_SPRITES 100
#define MAX_SPEED 1
static SDL_Texture *sprite;
static SDL_Rect positions[NUM_SPRITES];
@@ -43,8 +43,7 @@ quit(int rc)
exit(rc);
}
void
MoveSprites()
void MoveSprites()
{
int i;
int window_w = WINDOW_WIDTH;
@@ -96,13 +95,11 @@ void loop()
#endif
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
SDL_Window *window;
int i;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);

View File

@@ -28,9 +28,10 @@
#define MOOSEPIC_W 64
#define MOOSEPIC_H 88
#define MOOSEFRAME_SIZE (MOOSEPIC_W * MOOSEPIC_H)
#define MOOSEFRAME_SIZE (MOOSEPIC_W * MOOSEPIC_H)
#define MOOSEFRAMES_COUNT 10
/* *INDENT-OFF* */ /* clang-format off */
SDL_Color MooseColors[84] = {
{49, 49, 49, 255}, {66, 24, 0, 255}, {66, 33, 0, 255}, {66, 66, 66, 255},
{66, 115, 49, 255}, {74, 33, 0, 255}, {74, 41, 16, 255}, {82, 33, 8, 255},
@@ -54,6 +55,7 @@ SDL_Color MooseColors[84] = {
{214, 173, 140, 255}, {222, 181, 148, 255}, {222, 189, 132, 255}, {222, 189, 156, 255},
{222, 222, 222, 255}, {231, 198, 165, 255}, {231, 231, 231, 255}, {239, 206, 173, 255}
};
/* *INDENT-ON* */ /* clang-format on */
Uint8 MooseFrames[MOOSEFRAMES_COUNT][MOOSEFRAME_SIZE];
@@ -83,17 +85,16 @@ void UpdateTexture(SDL_Texture *texture)
}
src = MooseFrames[frame];
for (row = 0; row < MOOSEPIC_H; ++row) {
dst = (Uint32*)((Uint8*)pixels + row * pitch);
dst = (Uint32 *)((Uint8 *)pixels + row * pitch);
for (col = 0; col < MOOSEPIC_W; ++col) {
color = &MooseColors[*src++];
*dst++ = (0xFF000000|(color->r<<16)|(color->g<<8)|color->b);
*dst++ = (0xFF000000 | (color->r << 16) | (color->g << 8) | color->b);
}
}
SDL_UnlockTexture(texture);
}
void
loop()
void loop()
{
SDL_Event event;
@@ -124,8 +125,7 @@ loop()
#endif
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
SDL_Window *window;
SDL_RWops *handle;
@@ -154,12 +154,11 @@ main(int argc, char **argv)
SDL_RWread(handle, MooseFrames, MOOSEFRAME_SIZE, MOOSEFRAMES_COUNT);
SDL_RWclose(handle);
/* Create the window and renderer */
window = SDL_CreateWindow("Happy Moose",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
MOOSEPIC_W*4, MOOSEPIC_H*4,
MOOSEPIC_W * 4, MOOSEPIC_H * 4,
SDL_WINDOW_RESIZABLE);
if (window == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create window: %s\n", SDL_GetError());
@@ -186,7 +185,7 @@ main(int argc, char **argv)
#else
while (!done) {
loop();
}
}
#endif
SDL_DestroyRenderer(renderer);

View File

@@ -18,16 +18,16 @@
static int total_channels;
static int active_channel;
#define SAMPLE_RATE_HZ 48000
#define QUICK_TEST_TIME_MSEC 100
#define SAMPLE_RATE_HZ 48000
#define QUICK_TEST_TIME_MSEC 100
#define CHANNEL_TEST_TIME_SEC 5
#define MAX_AMPLITUDE SDL_MAX_SINT16
#define MAX_AMPLITUDE SDL_MAX_SINT16
#define SINE_FREQ_HZ 500
#define SINE_FREQ_HZ 500
#define LFE_SINE_FREQ_HZ 50
/* The channel layout is defined in SDL_audio.h */
const char*
const char *
get_channel_name(int channel_index, int channel_count)
{
switch (channel_index) {
@@ -92,9 +92,9 @@ is_lfe_channel(int channel_index, int channel_count)
}
void SDLCALL
fill_buffer(void* unused, Uint8* stream, int len)
fill_buffer(void *unused, Uint8 *stream, int len)
{
Sint16* buffer = (Sint16*)stream;
Sint16 *buffer = (Sint16 *)stream;
int samples = len / sizeof(Sint16);
static int total_samples = 0;
int i;
@@ -132,8 +132,7 @@ fill_buffer(void* unused, Uint8* stream, int len)
}
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int i;

View File

@@ -33,12 +33,15 @@ quit(int rc)
static const char *
getprioritystr(SDL_ThreadPriority priority)
{
switch(priority)
{
case SDL_THREAD_PRIORITY_LOW: return "SDL_THREAD_PRIORITY_LOW";
case SDL_THREAD_PRIORITY_NORMAL: return "SDL_THREAD_PRIORITY_NORMAL";
case SDL_THREAD_PRIORITY_HIGH: return "SDL_THREAD_PRIORITY_HIGH";
case SDL_THREAD_PRIORITY_TIME_CRITICAL: return "SDL_THREAD_PRIORITY_TIME_CRITICAL";
switch (priority) {
case SDL_THREAD_PRIORITY_LOW:
return "SDL_THREAD_PRIORITY_LOW";
case SDL_THREAD_PRIORITY_NORMAL:
return "SDL_THREAD_PRIORITY_NORMAL";
case SDL_THREAD_PRIORITY_HIGH:
return "SDL_THREAD_PRIORITY_HIGH";
case SDL_THREAD_PRIORITY_TIME_CRITICAL:
return "SDL_THREAD_PRIORITY_TIME_CRITICAL";
}
return "???";
@@ -51,9 +54,9 @@ ThreadFunc(void *data)
SDL_TLSSet(tls, "baby thread", NULL);
SDL_Log("Started thread %s: My thread id is %lu, thread data = %s\n",
(char *) data, SDL_ThreadID(), (const char *)SDL_TLSGet(tls));
(char *)data, SDL_ThreadID(), (const char *)SDL_TLSGet(tls));
while (alive) {
SDL_Log("Thread '%s' is alive!\n", (char *) data);
SDL_Log("Thread '%s' is alive!\n", (char *)data);
if (testprio) {
SDL_Log("SDL_SetThreadPriority(%s):%d\n", getprioritystr(prio), SDL_SetThreadPriority(prio));
@@ -64,7 +67,7 @@ ThreadFunc(void *data)
SDL_Delay(1 * 1000);
}
SDL_Log("Thread '%s' exiting!\n", (char *) data);
SDL_Log("Thread '%s' exiting!\n", (char *)data);
return 0;
}
@@ -77,8 +80,7 @@ killed(int sig)
quit(0);
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int arg = 1;
SDL_Thread *thread;
@@ -132,6 +134,6 @@ main(int argc, char *argv[])
}
raise(SIGTERM);
SDL_Quit(); /* Never reached */
return 0; /* Never reached */
SDL_Quit(); /* Never reached */
return 0; /* Never reached */
}

View File

@@ -19,7 +19,7 @@
#include "SDL.h"
#define DEFAULT_RESOLUTION 1
#define DEFAULT_RESOLUTION 1
static int ticks = 0;
@@ -33,12 +33,11 @@ ticktock(Uint32 interval, void *param)
static Uint32 SDLCALL
callback(Uint32 interval, void *param)
{
SDL_Log("Timer %" SDL_PRIu32 " : param = %d\n", interval, (int) (uintptr_t) param);
SDL_Log("Timer %" SDL_PRIu32 " : param = %d\n", interval, (int)(uintptr_t)param);
return interval;
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int i, desired;
SDL_TimerID t1, t2, t3;
@@ -95,20 +94,20 @@ main(int argc, char *argv[])
/* Print the results */
if (ticks) {
SDL_Log("Timer resolution: desired = %d ms, actual = %f ms\n",
desired, (double) (10 * 1000) / ticks);
desired, (double)(10 * 1000) / ticks);
}
/* Test multiple timers */
SDL_Log("Testing multiple timers...\n");
t1 = SDL_AddTimer(100, callback, (void *) 1);
t1 = SDL_AddTimer(100, callback, (void *)1);
if (!t1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create timer 1: %s\n", SDL_GetError());
}
t2 = SDL_AddTimer(50, callback, (void *) 2);
t2 = SDL_AddTimer(50, callback, (void *)2);
if (!t2) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create timer 2: %s\n", SDL_GetError());
}
t3 = SDL_AddTimer(233, callback, (void *) 3);
t3 = SDL_AddTimer(233, callback, (void *)3);
if (!t3) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create timer 3: %s\n", SDL_GetError());
}
@@ -130,9 +129,9 @@ main(int argc, char *argv[])
ticktock(0, NULL);
}
now = SDL_GetPerformanceCounter();
SDL_Log("1 million iterations of ticktock took %f ms\n", (double)((now - start)*1000) / SDL_GetPerformanceFrequency());
SDL_Log("1 million iterations of ticktock took %f ms\n", (double)((now - start) * 1000) / SDL_GetPerformanceFrequency());
SDL_Log("Performance counter frequency: %"SDL_PRIu64"\n", SDL_GetPerformanceFrequency());
SDL_Log("Performance counter frequency: %" SDL_PRIu64 "\n", SDL_GetPerformanceFrequency());
start64 = SDL_GetTicks64();
start32 = SDL_GetTicks();
start = SDL_GetPerformanceCounter();
@@ -140,7 +139,7 @@ main(int argc, char *argv[])
now = SDL_GetPerformanceCounter();
now64 = SDL_GetTicks64();
now32 = SDL_GetTicks();
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_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;

View File

@@ -114,17 +114,17 @@ LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent,
switch (temp->format->BitsPerPixel) {
case 15:
SDL_SetColorKey(temp, SDL_TRUE,
(*(Uint16 *) temp->pixels) & 0x00007FFF);
(*(Uint16 *)temp->pixels) & 0x00007FFF);
break;
case 16:
SDL_SetColorKey(temp, SDL_TRUE, *(Uint16 *) temp->pixels);
SDL_SetColorKey(temp, SDL_TRUE, *(Uint16 *)temp->pixels);
break;
case 24:
SDL_SetColorKey(temp, SDL_TRUE,
(*(Uint32 *) temp->pixels) & 0x00FFFFFF);
(*(Uint32 *)temp->pixels) & 0x00FFFFFF);
break;
case 32:
SDL_SetColorKey(temp, SDL_TRUE, *(Uint32 *) temp->pixels);
SDL_SetColorKey(temp, SDL_TRUE, *(Uint32 *)temp->pixels);
break;
}
}

View File

@@ -20,8 +20,7 @@
#include "SDL.h"
#include "SDL_revision.h"
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
SDL_version compiled;
SDL_version linked;
@@ -36,12 +35,12 @@ main(int argc, char *argv[])
#endif
SDL_VERSION(&compiled);
SDL_Log("Compiled version: %d.%d.%d (%s)\n",
compiled.major, compiled.minor, compiled.patch,
SDL_REVISION);
compiled.major, compiled.minor, compiled.patch,
SDL_REVISION);
SDL_GetVersion(&linked);
SDL_Log("Linked version: %d.%d.%d (%s)\n",
linked.major, linked.minor, linked.patch,
SDL_GetRevision());
linked.major, linked.minor, linked.patch,
SDL_GetRevision());
SDL_Quit();
return 0;
}

View File

@@ -42,43 +42,42 @@ quit(int rc)
exit(rc);
}
void
DrawOnViewport(SDL_Renderer * renderer)
{
void DrawOnViewport(SDL_Renderer *renderer)
{
SDL_Rect rect;
/* Set the viewport */
SDL_RenderSetViewport(renderer, &viewport);
/* Draw a gray background */
SDL_SetRenderDrawColor(renderer, 0x80, 0x80, 0x80, 0xFF);
SDL_RenderClear(renderer);
/* Test inside points */
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0x00, 0xFF);
SDL_RenderDrawPoint(renderer, viewport.h/2 + 20, viewport.w/2);
SDL_RenderDrawPoint(renderer, viewport.h/2 - 20, viewport.w/2);
SDL_RenderDrawPoint(renderer, viewport.h/2 , viewport.w/2 - 20);
SDL_RenderDrawPoint(renderer, viewport.h/2 , viewport.w/2 + 20);
SDL_RenderDrawPoint(renderer, viewport.h / 2 + 20, viewport.w / 2);
SDL_RenderDrawPoint(renderer, viewport.h / 2 - 20, viewport.w / 2);
SDL_RenderDrawPoint(renderer, viewport.h / 2, viewport.w / 2 - 20);
SDL_RenderDrawPoint(renderer, viewport.h / 2, viewport.w / 2 + 20);
/* Test horizontal and vertical lines */
SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
SDL_RenderDrawLine(renderer, 1, 0, viewport.w-2, 0);
SDL_RenderDrawLine(renderer, 1, viewport.h-1, viewport.w-2, viewport.h-1);
SDL_RenderDrawLine(renderer, 0, 1, 0, viewport.h-2);
SDL_RenderDrawLine(renderer, viewport.w-1, 1, viewport.w-1, viewport.h-2);
SDL_RenderDrawLine(renderer, 1, 0, viewport.w - 2, 0);
SDL_RenderDrawLine(renderer, 1, viewport.h - 1, viewport.w - 2, viewport.h - 1);
SDL_RenderDrawLine(renderer, 0, 1, 0, viewport.h - 2);
SDL_RenderDrawLine(renderer, viewport.w - 1, 1, viewport.w - 1, viewport.h - 2);
/* Test diagonal lines */
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0xFF, 0xFF);
SDL_RenderDrawLine(renderer, 0, 0, viewport.w-1, viewport.h-1);
SDL_RenderDrawLine(renderer, viewport.w-1, 0, 0, viewport.h-1);
SDL_RenderDrawLine(renderer, 0, 0, viewport.w - 1, viewport.h - 1);
SDL_RenderDrawLine(renderer, viewport.w - 1, 0, 0, viewport.h - 1);
/* Test outside points */
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0x00, 0xFF);
SDL_RenderDrawPoint(renderer, viewport.h/2 + viewport.h, viewport.w/2);
SDL_RenderDrawPoint(renderer, viewport.h/2 - viewport.h, viewport.w/2);
SDL_RenderDrawPoint(renderer, viewport.h/2, viewport.w/2 - viewport.w);
SDL_RenderDrawPoint(renderer, viewport.h/2, viewport.w/2 + viewport.w);
SDL_RenderDrawPoint(renderer, viewport.h / 2 + viewport.h, viewport.w / 2);
SDL_RenderDrawPoint(renderer, viewport.h / 2 - viewport.h, viewport.w / 2);
SDL_RenderDrawPoint(renderer, viewport.h / 2, viewport.w / 2 - viewport.w);
SDL_RenderDrawPoint(renderer, viewport.h / 2, viewport.w / 2 + viewport.w);
/* Add a box at the top */
rect.w = 8;
@@ -96,8 +95,7 @@ DrawOnViewport(SDL_Renderer * renderer)
SDL_RenderSetClipRect(renderer, NULL);
}
void
loop()
void loop()
{
SDL_Event event;
int i;
@@ -147,8 +145,7 @@ loop()
#endif
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int i;
Uint32 then, now, frames;
@@ -159,7 +156,6 @@ main(int argc, char *argv[])
return 1;
}
for (i = 1; i < argc;) {
int consumed;
@@ -224,7 +220,7 @@ main(int argc, char *argv[])
/* Print out some timing information */
now = SDL_GetTicks();
if (now > then) {
double fps = ((double) frames * 1000) / (now - then);
double fps = ((double)frames * 1000) / (now - then);
SDL_Log("%2.2f frames per second\n", fps);
}
quit(0);

View File

@@ -84,8 +84,8 @@ int main(int argc, char *argv[])
VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfacePresentModesKHR) \
VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfaceSupportKHR)
#define VULKAN_DEVICE_FUNCTION(name) static PFN_##name name = NULL;
#define VULKAN_GLOBAL_FUNCTION(name) static PFN_##name name = NULL;
#define VULKAN_DEVICE_FUNCTION(name) static PFN_##name name = NULL;
#define VULKAN_GLOBAL_FUNCTION(name) static PFN_##name name = NULL;
#define VULKAN_INSTANCE_FUNCTION(name) static PFN_##name name = NULL;
VULKAN_FUNCTIONS()
#undef VULKAN_DEVICE_FUNCTION
@@ -103,16 +103,18 @@ enum
};
#endif
#if VK_HEADER_VERSION < 38
enum {
enum
{
VK_ERROR_OUT_OF_POOL_MEMORY_KHR = -1000069000
};
#endif
static const char *getVulkanResultString(VkResult result)
{
switch((int) result)
{
#define RESULT_CASE(x) case x: return #x
switch ((int)result) {
#define RESULT_CASE(x) \
case x: \
return #x
RESULT_CASE(VK_SUCCESS);
RESULT_CASE(VK_NOT_READY);
RESULT_CASE(VK_TIMEOUT);
@@ -139,8 +141,9 @@ static const char *getVulkanResultString(VkResult result)
RESULT_CASE(VK_ERROR_VALIDATION_FAILED_EXT);
RESULT_CASE(VK_ERROR_OUT_OF_POOL_MEMORY_KHR);
RESULT_CASE(VK_ERROR_INVALID_SHADER_NV);
#undef RESULT_CASE
default: break;
#undef RESULT_CASE
default:
break;
}
return (result < 0) ? "VK_ERROR_<Unknown>" : "VK_<Unknown>";
}
@@ -176,7 +179,7 @@ typedef struct VulkanContext
} VulkanContext;
static SDLTest_CommonState *state;
static VulkanContext *vulkanContexts = NULL; // an array of state->num_windows items
static VulkanContext *vulkanContexts = NULL; // an array of state->num_windows items
static VulkanContext *vulkanContext = NULL; // for the currently-rendering window
static void shutdownVulkan(SDL_bool doDestroySwapchain);
@@ -216,8 +219,8 @@ static void loadGlobalFunctions(void)
static void createInstance(void)
{
VkApplicationInfo appInfo = {0};
VkInstanceCreateInfo instanceCreateInfo = {0};
VkApplicationInfo appInfo = { 0 };
VkInstanceCreateInfo instanceCreateInfo = { 0 };
const char **extensions = NULL;
unsigned extensionCount = 0;
VkResult result;
@@ -232,13 +235,13 @@ static void createInstance(void)
SDL_GetError());
quit(2);
}
extensions = (const char **) SDL_malloc(sizeof(const char *) * extensionCount);
extensions = (const char **)SDL_malloc(sizeof(const char *) * extensionCount);
if (extensions == NULL) {
SDL_OutOfMemory();
quit(2);
}
if (!SDL_Vulkan_GetInstanceExtensions(NULL, &extensionCount, extensions)) {
SDL_free((void*)extensions);
SDL_free((void *)extensions);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_Vulkan_GetInstanceExtensions(): %s\n",
SDL_GetError());
@@ -247,7 +250,7 @@ static void createInstance(void)
instanceCreateInfo.enabledExtensionCount = extensionCount;
instanceCreateInfo.ppEnabledExtensionNames = extensions;
result = vkCreateInstance(&instanceCreateInfo, NULL, &vulkanContext->instance);
SDL_free((void*)extensions);
SDL_free((void *)extensions);
if (result != VK_SUCCESS) {
vulkanContext->instance = VK_NULL_HANDLE;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
@@ -277,8 +280,8 @@ static void loadInstanceFunctions(void)
static void createSurface(void)
{
if (!SDL_Vulkan_CreateSurface(vulkanContext->window,
vulkanContext->instance,
&vulkanContext->surface)) {
vulkanContext->instance,
&vulkanContext->surface)) {
vulkanContext->surface = VK_NULL_HANDLE;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Vulkan_CreateSurface(): %s\n", SDL_GetError());
quit(2);
@@ -308,7 +311,7 @@ static void findPhysicalDevice(void)
"vkEnumeratePhysicalDevices(): no physical devices\n");
quit(2);
}
physicalDevices = (VkPhysicalDevice *) SDL_malloc(sizeof(VkPhysicalDevice) * physicalDeviceCount);
physicalDevices = (VkPhysicalDevice *)SDL_malloc(sizeof(VkPhysicalDevice) * physicalDeviceCount);
if (physicalDevices == NULL) {
SDL_OutOfMemory();
quit(2);
@@ -342,7 +345,7 @@ static void findPhysicalDevice(void)
if (queueFamiliesPropertiesAllocatedSize < queueFamiliesCount) {
SDL_free(queueFamiliesProperties);
queueFamiliesPropertiesAllocatedSize = queueFamiliesCount;
queueFamiliesProperties = (VkQueueFamilyProperties *) SDL_malloc(sizeof(VkQueueFamilyProperties) * queueFamiliesPropertiesAllocatedSize);
queueFamiliesProperties = (VkQueueFamilyProperties *)SDL_malloc(sizeof(VkQueueFamilyProperties) * queueFamiliesPropertiesAllocatedSize);
if (queueFamiliesProperties == NULL) {
SDL_free(physicalDevices);
SDL_free(deviceExtensions);
@@ -382,10 +385,10 @@ static void findPhysicalDevice(void)
}
}
if (vulkanContext->graphicsQueueFamilyIndex == queueFamiliesCount) { // no good queues found
if (vulkanContext->graphicsQueueFamilyIndex == queueFamiliesCount) { // no good queues found
continue;
}
if (vulkanContext->presentQueueFamilyIndex == queueFamiliesCount) { // no good queues found
if (vulkanContext->presentQueueFamilyIndex == queueFamiliesCount) { // no good queues found
continue;
}
result = vkEnumerateDeviceExtensionProperties(physicalDevice, NULL, &deviceExtensionCount, NULL);
@@ -445,9 +448,9 @@ static void findPhysicalDevice(void)
static void createDevice(void)
{
VkDeviceQueueCreateInfo deviceQueueCreateInfo[1] = { {0} };
static const float queuePriority[] = {1.0f};
VkDeviceCreateInfo deviceCreateInfo = {0};
VkDeviceQueueCreateInfo deviceQueueCreateInfo[1] = { { 0 } };
static const float queuePriority[] = { 1.0f };
VkDeviceCreateInfo deviceCreateInfo = { 0 };
static const char *const deviceExtensionNames[] = {
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
};
@@ -511,7 +514,7 @@ static void createSemaphore(VkSemaphore *semaphore)
{
VkResult result;
VkSemaphoreCreateInfo createInfo = {0};
VkSemaphoreCreateInfo createInfo = { 0 };
createInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
result = vkCreateSemaphore(vulkanContext->device, &createInfo, NULL, semaphore);
if (result != VK_SUCCESS) {
@@ -563,7 +566,7 @@ static void getSurfaceFormats(void)
if (vulkanContext->surfaceFormatsCount > vulkanContext->surfaceFormatsAllocatedCount) {
vulkanContext->surfaceFormatsAllocatedCount = vulkanContext->surfaceFormatsCount;
SDL_free(vulkanContext->surfaceFormats);
vulkanContext->surfaceFormats = (VkSurfaceFormatKHR *) SDL_malloc(sizeof(VkSurfaceFormatKHR) * vulkanContext->surfaceFormatsAllocatedCount);
vulkanContext->surfaceFormats = (VkSurfaceFormatKHR *)SDL_malloc(sizeof(VkSurfaceFormatKHR) * vulkanContext->surfaceFormatsAllocatedCount);
if (!vulkanContext->surfaceFormats) {
vulkanContext->surfaceFormatsCount = 0;
SDL_OutOfMemory();
@@ -621,19 +624,19 @@ static SDL_bool createSwapchain(void)
{
uint32_t i;
int w, h;
VkSwapchainCreateInfoKHR createInfo = {0};
VkSwapchainCreateInfoKHR createInfo = { 0 };
VkResult result;
// pick an image count
vulkanContext->swapchainDesiredImageCount = vulkanContext->surfaceCapabilities.minImageCount + 1;
if ( (vulkanContext->swapchainDesiredImageCount > vulkanContext->surfaceCapabilities.maxImageCount) &&
(vulkanContext->surfaceCapabilities.maxImageCount > 0) ) {
if ((vulkanContext->swapchainDesiredImageCount > vulkanContext->surfaceCapabilities.maxImageCount) &&
(vulkanContext->surfaceCapabilities.maxImageCount > 0)) {
vulkanContext->swapchainDesiredImageCount = vulkanContext->surfaceCapabilities.maxImageCount;
}
// pick a format
if ( (vulkanContext->surfaceFormatsCount == 1) &&
(vulkanContext->surfaceFormats[0].format == VK_FORMAT_UNDEFINED) ) {
if ((vulkanContext->surfaceFormatsCount == 1) &&
(vulkanContext->surfaceFormats[0].format == VK_FORMAT_UNDEFINED)) {
// aren't any preferred formats, so we pick
vulkanContext->surfaceFormat.colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR;
vulkanContext->surfaceFormat.format = VK_FORMAT_R8G8B8A8_UNORM;
@@ -652,13 +655,13 @@ static SDL_bool createSwapchain(void)
// Clamp the size to the allowable image extent.
// SDL_Vulkan_GetDrawableSize()'s result it not always in this range (bug #3287)
vulkanContext->swapchainSize.width = SDL_clamp((uint32_t) w,
vulkanContext->surfaceCapabilities.minImageExtent.width,
vulkanContext->surfaceCapabilities.maxImageExtent.width);
vulkanContext->swapchainSize.width = SDL_clamp((uint32_t)w,
vulkanContext->surfaceCapabilities.minImageExtent.width,
vulkanContext->surfaceCapabilities.maxImageExtent.width);
vulkanContext->swapchainSize.height = SDL_clamp((uint32_t) h,
vulkanContext->surfaceCapabilities.minImageExtent.height,
vulkanContext->surfaceCapabilities.maxImageExtent.height);
vulkanContext->swapchainSize.height = SDL_clamp((uint32_t)h,
vulkanContext->surfaceCapabilities.minImageExtent.height,
vulkanContext->surfaceCapabilities.maxImageExtent.height);
if (w == 0 || h == 0) {
return SDL_FALSE;
@@ -731,7 +734,7 @@ static void destroyCommandPool(void)
static void createCommandPool(void)
{
VkResult result;
VkCommandPoolCreateInfo createInfo = {0};
VkCommandPoolCreateInfo createInfo = { 0 };
createInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
createInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT | VK_COMMAND_POOL_CREATE_TRANSIENT_BIT;
createInfo.queueFamilyIndex = vulkanContext->graphicsQueueFamilyIndex;
@@ -748,12 +751,12 @@ static void createCommandPool(void)
static void createCommandBuffers(void)
{
VkResult result;
VkCommandBufferAllocateInfo allocateInfo = {0};
VkCommandBufferAllocateInfo allocateInfo = { 0 };
allocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocateInfo.commandPool = vulkanContext->commandPool;
allocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
allocateInfo.commandBufferCount = vulkanContext->swapchainImageCount;
vulkanContext->commandBuffers = (VkCommandBuffer *) SDL_malloc(sizeof(VkCommandBuffer) * vulkanContext->swapchainImageCount);
vulkanContext->commandBuffers = (VkCommandBuffer *)SDL_malloc(sizeof(VkCommandBuffer) * vulkanContext->swapchainImageCount);
result = vkAllocateCommandBuffers(vulkanContext->device, &allocateInfo, vulkanContext->commandBuffers);
if (result != VK_SUCCESS) {
SDL_free(vulkanContext->commandBuffers);
@@ -776,7 +779,7 @@ static void createFences(void)
}
for (i = 0; i < vulkanContext->swapchainImageCount; i++) {
VkResult result;
VkFenceCreateInfo createInfo = {0};
VkFenceCreateInfo createInfo = { 0 };
createInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
createInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
result = vkCreateFence(vulkanContext->device, &createInfo, NULL, &vulkanContext->fences[i]);
@@ -816,7 +819,7 @@ static void recordPipelineImageBarrier(VkCommandBuffer commandBuffer,
VkImageLayout destLayout,
VkImage image)
{
VkImageMemoryBarrier barrier = {0};
VkImageMemoryBarrier barrier = { 0 };
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
barrier.srcAccessMask = sourceAccessMask;
barrier.dstAccessMask = destAccessMask;
@@ -846,8 +849,8 @@ static void rerecordCommandBuffer(uint32_t frameIndex, const VkClearColorValue *
{
VkCommandBuffer commandBuffer = vulkanContext->commandBuffers[frameIndex];
VkImage image = vulkanContext->swapchainImages[frameIndex];
VkCommandBufferBeginInfo beginInfo = {0};
VkImageSubresourceRange clearRange = {0};
VkCommandBufferBeginInfo beginInfo = { 0 };
VkImageSubresourceRange clearRange = { 0 };
VkResult result = vkResetCommandBuffer(commandBuffer, 0);
if (result != VK_SUCCESS) {
@@ -923,7 +926,7 @@ static void initVulkan(void)
SDL_Vulkan_LoadLibrary(NULL);
vulkanContexts = (VulkanContext *) SDL_calloc(state->num_windows, sizeof (VulkanContext));
vulkanContexts = (VulkanContext *)SDL_calloc(state->num_windows, sizeof(VulkanContext));
if (vulkanContexts == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
quit(2);
@@ -991,10 +994,10 @@ static SDL_bool render(void)
uint32_t frameIndex;
VkResult result;
double currentTime;
VkClearColorValue clearColor = { {0} };
VkClearColorValue clearColor = { { 0 } };
VkPipelineStageFlags waitDestStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT;
VkSubmitInfo submitInfo = {0};
VkPresentInfoKHR presentInfo = {0};
VkSubmitInfo submitInfo = { 0 };
VkPresentInfoKHR presentInfo = { 0 };
int w, h;
if (!vulkanContext->swapchain) {
@@ -1005,11 +1008,11 @@ static SDL_bool render(void)
return retval;
}
result = vkAcquireNextImageKHR(vulkanContext->device,
vulkanContext->swapchain,
UINT64_MAX,
vulkanContext->imageAvailableSemaphore,
VK_NULL_HANDLE,
&frameIndex);
vulkanContext->swapchain,
UINT64_MAX,
vulkanContext->imageAvailableSemaphore,
VK_NULL_HANDLE,
&frameIndex);
if (result == VK_ERROR_OUT_OF_DATE_KHR) {
return createNewSwapchainAndSwapchainSpecificStuff();
}

View File

@@ -24,18 +24,18 @@ static SDLTest_CommonState *state;
int done;
static const char *cursorNames[] = {
"arrow",
"ibeam",
"wait",
"crosshair",
"waitarrow",
"sizeNWSE",
"sizeNESW",
"sizeWE",
"sizeNS",
"sizeALL",
"NO",
"hand",
"arrow",
"ibeam",
"wait",
"crosshair",
"waitarrow",
"sizeNWSE",
"sizeNESW",
"sizeWE",
"sizeNS",
"sizeALL",
"NO",
"hand",
};
int system_cursor = -1;
SDL_Cursor *cursor = NULL;
@@ -108,13 +108,13 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_Rect viewport)
}
SDL_snprintf(text, sizeof(text), "%d: %dx%d@%dHz",
i, mode.w, mode.h, mode.refresh_rate);
i, mode.w, mode.h, mode.refresh_rate);
/* Update column width */
text_length = (int)SDL_strlen(text);
column_chars = SDL_max(column_chars, text_length);
/* Check if under mouse */
/* Check if under mouse */
cell_rect.x = x;
cell_rect.y = y;
cell_rect.w = text_length * FONT_CHARACTER_SIZE;
@@ -143,108 +143,107 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_Rect viewport)
}
}
void
loop()
void loop()
{
int i;
SDL_Event event;
/* Check for events */
while (SDL_PollEvent(&event)) {
SDLTest_CommonEvent(state, &event, &done);
/* Check for events */
while (SDL_PollEvent(&event)) {
SDLTest_CommonEvent(state, &event, &done);
if (event.type == SDL_WINDOWEVENT) {
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
if (window) {
SDL_Log("Window %" SDL_PRIu32 " resized to %" SDL_PRIs32 "x%" SDL_PRIs32 "\n",
event.window.windowID,
event.window.data1,
event.window.data2);
}
}
if (event.window.event == SDL_WINDOWEVENT_MOVED) {
SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
if (window) {
SDL_Log("Window %" SDL_PRIu32 " moved to %" SDL_PRIs32 ",%" SDL_PRIs32 " (display %s)\n",
event.window.windowID,
event.window.data1,
event.window.data2,
SDL_GetDisplayName(SDL_GetWindowDisplayIndex(window)));
}
}
if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) {
relative_mode = SDL_GetRelativeMouseMode();
if (relative_mode) {
SDL_SetRelativeMouseMode(SDL_FALSE);
}
}
if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) {
if (relative_mode) {
SDL_SetRelativeMouseMode(SDL_TRUE);
}
if (event.type == SDL_WINDOWEVENT) {
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
if (window) {
SDL_Log("Window %" SDL_PRIu32 " resized to %" SDL_PRIs32 "x%" SDL_PRIs32 "\n",
event.window.windowID,
event.window.data1,
event.window.data2);
}
}
if (event.type == SDL_KEYUP) {
SDL_bool updateCursor = SDL_FALSE;
if (event.key.keysym.sym == SDLK_LEFT) {
--system_cursor;
if (system_cursor < 0) {
system_cursor = SDL_NUM_SYSTEM_CURSORS - 1;
}
updateCursor = SDL_TRUE;
} else if (event.key.keysym.sym == SDLK_RIGHT) {
++system_cursor;
if (system_cursor >= SDL_NUM_SYSTEM_CURSORS) {
system_cursor = 0;
}
updateCursor = SDL_TRUE;
}
if (updateCursor) {
SDL_Log("Changing cursor to \"%s\"", cursorNames[system_cursor]);
SDL_FreeCursor(cursor);
cursor = SDL_CreateSystemCursor((SDL_SystemCursor)system_cursor);
SDL_SetCursor(cursor);
if (event.window.event == SDL_WINDOWEVENT_MOVED) {
SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
if (window) {
SDL_Log("Window %" SDL_PRIu32 " moved to %" SDL_PRIs32 ",%" SDL_PRIs32 " (display %s)\n",
event.window.windowID,
event.window.data1,
event.window.data2,
SDL_GetDisplayName(SDL_GetWindowDisplayIndex(window)));
}
}
if (event.type == SDL_MOUSEBUTTONUP) {
SDL_Window* window = SDL_GetMouseFocus();
if (highlighted_mode != -1 && window != NULL) {
const int display_index = SDL_GetWindowDisplayIndex(window);
SDL_DisplayMode mode;
if (0 != SDL_GetDisplayMode(display_index, highlighted_mode, &mode)) {
SDL_Log("Couldn't get display mode");
} else {
SDL_SetWindowDisplayMode(window, &mode);
}
if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) {
relative_mode = SDL_GetRelativeMouseMode();
if (relative_mode) {
SDL_SetRelativeMouseMode(SDL_FALSE);
}
}
if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) {
if (relative_mode) {
SDL_SetRelativeMouseMode(SDL_TRUE);
}
}
}
if (event.type == SDL_KEYUP) {
SDL_bool updateCursor = SDL_FALSE;
for (i = 0; i < state->num_windows; ++i) {
SDL_Window* window = state->windows[i];
SDL_Renderer *renderer = state->renderers[i];
if (window != NULL && renderer != NULL) {
int y = 0;
SDL_Rect viewport, menurect;
SDL_RenderGetViewport(renderer, &viewport);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDLTest_CommonDrawWindowInfo(renderer, state->windows[i], &y);
menurect.x = 0;
menurect.y = y;
menurect.w = viewport.w;
menurect.h = viewport.h - y;
draw_modes_menu(window, renderer, menurect);
SDL_RenderPresent(renderer);
if (event.key.keysym.sym == SDLK_LEFT) {
--system_cursor;
if (system_cursor < 0) {
system_cursor = SDL_NUM_SYSTEM_CURSORS - 1;
}
updateCursor = SDL_TRUE;
} else if (event.key.keysym.sym == SDLK_RIGHT) {
++system_cursor;
if (system_cursor >= SDL_NUM_SYSTEM_CURSORS) {
system_cursor = 0;
}
updateCursor = SDL_TRUE;
}
if (updateCursor) {
SDL_Log("Changing cursor to \"%s\"", cursorNames[system_cursor]);
SDL_FreeCursor(cursor);
cursor = SDL_CreateSystemCursor((SDL_SystemCursor)system_cursor);
SDL_SetCursor(cursor);
}
}
if (event.type == SDL_MOUSEBUTTONUP) {
SDL_Window *window = SDL_GetMouseFocus();
if (highlighted_mode != -1 && window != NULL) {
const int display_index = SDL_GetWindowDisplayIndex(window);
SDL_DisplayMode mode;
if (0 != SDL_GetDisplayMode(display_index, highlighted_mode, &mode)) {
SDL_Log("Couldn't get display mode");
} else {
SDL_SetWindowDisplayMode(window, &mode);
}
}
}
}
for (i = 0; i < state->num_windows; ++i) {
SDL_Window *window = state->windows[i];
SDL_Renderer *renderer = state->renderers[i];
if (window != NULL && renderer != NULL) {
int y = 0;
SDL_Rect viewport, menurect;
SDL_RenderGetViewport(renderer, &viewport);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDLTest_CommonDrawWindowInfo(renderer, state->windows[i], &y);
menurect.x = 0;
menurect.y = y;
menurect.w = viewport.w;
menurect.h = viewport.h - y;
draw_modes_menu(window, renderer, menurect);
SDL_RenderPresent(renderer);
}
}
#ifdef __EMSCRIPTEN__
if (done) {
emscripten_cancel_main_loop();
@@ -252,8 +251,7 @@ loop()
#endif
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int i;
@@ -281,7 +279,7 @@ main(int argc, char *argv[])
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderClear(renderer);
}
/* Main render loop */
done = 0;
#ifdef __EMSCRIPTEN__

View File

@@ -17,10 +17,8 @@
#include "SDL_test_font.h"
#include "testyuv_cvt.h"
/* 422 (YUY2, etc) formats are the largest */
#define MAX_YUV_SURFACE_SIZE(W, H, P) (H*4*(W+P+1)/2)
#define MAX_YUV_SURFACE_SIZE(W, H, P) (H * 4 * (W + P + 1) / 2)
/* Return true if the YUV format is packed pixels */
static SDL_bool is_packed_yuv_format(Uint32 format)
@@ -36,12 +34,12 @@ static SDL_Surface *generate_test_pattern(int pattern_size)
if (pattern) {
int i, x, y;
Uint8 *p, c;
const int thickness = 2; /* Important so 2x2 blocks of color are the same, to avoid Cr/Cb interpolation over pixels */
const int thickness = 2; /* Important so 2x2 blocks of color are the same, to avoid Cr/Cb interpolation over pixels */
/* R, G, B in alternating horizontal bands */
for (y = 0; y < pattern->h; y += thickness) {
for (i = 0; i < thickness; ++i) {
p = (Uint8 *)pattern->pixels + (y + i) * pattern->pitch + ((y/thickness) % 3);
p = (Uint8 *)pattern->pixels + (y + i) * pattern->pitch + ((y / thickness) % 3);
for (x = 0; x < pattern->w; ++x) {
*p = 0xFF;
p += 3;
@@ -51,9 +49,9 @@ static SDL_Surface *generate_test_pattern(int pattern_size)
/* Black and white in alternating vertical bands */
c = 0xFF;
for (x = 1*thickness; x < pattern->w; x += 2*thickness) {
for (x = 1 * thickness; x < pattern->w; x += 2 * thickness) {
for (i = 0; i < thickness; ++i) {
p = (Uint8 *)pattern->pixels + (x + i)*3;
p = (Uint8 *)pattern->pixels + (x + i) * 3;
for (y = 0; y < pattern->h; ++y) {
SDL_memset(p, c, 3);
p += pattern->pitch;
@@ -127,7 +125,7 @@ static int run_automated_tests(int pattern_size, int extra_pitch)
Uint8 *yuv2 = (Uint8 *)SDL_malloc(yuv_len);
int yuv1_pitch, yuv2_pitch;
int result = -1;
if (pattern == NULL || yuv1 == NULL || yuv2 == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't allocate test surfaces");
goto done;
@@ -204,7 +202,6 @@ static int run_automated_tests(int pattern_size, int extra_pitch)
}
}
result = 0;
done:
@@ -214,10 +211,10 @@ done:
return result;
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
struct {
struct
{
SDL_bool enable_intrinsics;
int pattern_size;
int extra_pitch;
@@ -313,10 +310,10 @@ main(int argc, char **argv)
/* Run automated tests */
if (should_run_automated_tests) {
for (i = 0; i < SDL_arraysize(automated_test_params); ++i) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Running automated test, pattern size %d, extra pitch %d, intrinsics %s\n",
automated_test_params[i].pattern_size,
automated_test_params[i].extra_pitch,
automated_test_params[i].enable_intrinsics ? "enabled" : "disabled");
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Running automated test, pattern size %d, extra pitch %d, intrinsics %s\n",
automated_test_params[i].pattern_size,
automated_test_params[i].extra_pitch,
automated_test_params[i].enable_intrinsics ? "enabled" : "disabled");
if (run_automated_tests(automated_test_params[i].pattern_size, automated_test_params[i].extra_pitch) < 0) {
return 2;
}
@@ -337,8 +334,8 @@ main(int argc, char **argv)
raw_yuv = SDL_calloc(1, MAX_YUV_SURFACE_SIZE(original->w, original->h, 0));
ConvertRGBtoYUV(yuv_format, original->pixels, original->pitch, raw_yuv, original->w, original->h,
SDL_GetYUVConversionModeForResolution(original->w, original->h),
0, 100);
SDL_GetYUVConversionModeForResolution(original->w, original->h),
0, 100);
pitch = CalculateYUVPitch(yuv_format, original->w);
converted = SDL_CreateRGBSurfaceWithFormat(0, original->w, original->h, 0, rgb_format);
@@ -348,11 +345,11 @@ main(int argc, char **argv)
}
then = SDL_GetTicks();
for ( i = 0; i < iterations; ++i ) {
for (i = 0; i < iterations; ++i) {
SDL_ConvertPixels(original->w, original->h, yuv_format, raw_yuv, pitch, rgb_format, converted->pixels, converted->pitch);
}
now = SDL_GetTicks();
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "%" SDL_PRIu32 " iterations in %" SDL_PRIu32 " ms, %.2fms each\n", iterations, (now - then), (float) (now - then) / iterations);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "%" SDL_PRIu32 " iterations in %" SDL_PRIu32 " ms, %.2fms each\n", iterations, (now - then), (float)(now - then) / iterations);
window = SDL_CreateWindow("YUV test",
SDL_WINDOWPOS_UNDEFINED,
@@ -378,7 +375,7 @@ main(int argc, char **argv)
return 5;
}
SDL_UpdateTexture(output[2], NULL, raw_yuv, pitch);
yuv_name = SDL_GetPixelFormatName(yuv_format);
if (SDL_strncmp(yuv_name, "SDL_PIXELFORMAT_", 16) == 0) {
yuv_name += 16;
@@ -399,8 +396,9 @@ main(int argc, char **argv)
break;
}
{ int done = 0;
while ( !done ) {
{
int done = 0;
while (!done) {
SDL_Event event;
while (SDL_PollEvent(&event) > 0) {
if (event.type == SDL_QUIT) {
@@ -416,7 +414,7 @@ main(int argc, char **argv)
}
}
if (event.type == SDL_MOUSEBUTTONDOWN) {
if (event.button.x < (original->w/2)) {
if (event.button.x < (original->w / 2)) {
--current;
} else {
++current;

View File

@@ -14,13 +14,12 @@
#include "testyuv_cvt.h"
static float clip3(float x, float y, float 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)
static void RGBtoYUV(Uint8 *rgb, int *yuv, SDL_YUV_CONVERSION_MODE mode, int monochrome, int luminance)
{
if (mode == SDL_YUV_CONVERSION_JPEG) {
/* Full range YUV */
@@ -52,9 +51,9 @@ static void RGBtoYUV(Uint8 * rgb, int *yuv, SDL_YUV_CONVERSION_MODE mode, int mo
G = rgb[1];
B = rgb[2];
L = Kr * R + Kb * B + (1 - Kr - Kb) * G;
Y = (Uint8)SDL_floorf((219*(L-Z)/S + 16) + 0.5f);
U = (Uint8)clip3(0, 255, SDL_floorf((112.0f*(B-L) / ((1.0f-Kb)*S) + 128) + 0.5f));
V = (Uint8)clip3(0, 255, SDL_floorf((112.0f*(R-L) / ((1.0f-Kr)*S) + 128) + 0.5f));
Y = (Uint8)SDL_floorf((219 * (L - Z) / S + 16) + 0.5f);
U = (Uint8)clip3(0, 255, SDL_floorf((112.0f * (B - L) / ((1.0f - Kb) * S) + 128) + 0.5f));
V = (Uint8)clip3(0, 255, SDL_floorf((112.0f * (R - L) / ((1.0f - Kr) * S) + 128) + 0.5f));
yuv[0] = (Uint8)Y;
yuv[1] = (Uint8)U;
@@ -80,7 +79,7 @@ static void ConvertRGBtoPlanar2x2(Uint32 format, Uint8 *src, int pitch, Uint8 *o
int yuv[4][3];
Uint8 *Y1, *Y2, *U, *V;
Uint8 *rgb1, *rgb2;
int rgb_row_advance = (pitch - w*3) + pitch;
int rgb_row_advance = (pitch - w * 3) + pitch;
int UV_advance;
rgb1 = src;
@@ -91,12 +90,12 @@ static void ConvertRGBtoPlanar2x2(Uint32 format, Uint8 *src, int pitch, Uint8 *o
switch (format) {
case SDL_PIXELFORMAT_YV12:
V = (Y1 + h * w);
U = V + ((h + 1)/2)*((w + 1)/2);
U = V + ((h + 1) / 2) * ((w + 1) / 2);
UV_advance = 1;
break;
case SDL_PIXELFORMAT_IYUV:
U = (Y1 + h * w);
V = U + ((h + 1)/2)*((w + 1)/2);
V = U + ((h + 1) / 2) * ((w + 1) / 2);
UV_advance = 1;
break;
case SDL_PIXELFORMAT_NV12:
@@ -132,10 +131,10 @@ static void ConvertRGBtoPlanar2x2(Uint32 format, Uint8 *src, int pitch, Uint8 *o
rgb2 += 3;
*Y2++ = (Uint8)yuv[3][0];
*U = (Uint8)SDL_floorf((yuv[0][1] + yuv[1][1] + yuv[2][1] + yuv[3][1])/4.0f + 0.5f);
*U = (Uint8)SDL_floorf((yuv[0][1] + yuv[1][1] + yuv[2][1] + yuv[3][1]) / 4.0f + 0.5f);
U += UV_advance;
*V = (Uint8)SDL_floorf((yuv[0][2] + yuv[1][2] + yuv[2][2] + yuv[3][2])/4.0f + 0.5f);
*V = (Uint8)SDL_floorf((yuv[0][2] + yuv[1][2] + yuv[2][2] + yuv[3][2]) / 4.0f + 0.5f);
V += UV_advance;
}
/* Last column */
@@ -148,10 +147,10 @@ static void ConvertRGBtoPlanar2x2(Uint32 format, Uint8 *src, int pitch, Uint8 *o
rgb2 += 3;
*Y2++ = (Uint8)yuv[2][0];
*U = (Uint8)SDL_floorf((yuv[0][1] + yuv[2][1])/2.0f + 0.5f);
*U = (Uint8)SDL_floorf((yuv[0][1] + yuv[2][1]) / 2.0f + 0.5f);
U += UV_advance;
*V = (Uint8)SDL_floorf((yuv[0][2] + yuv[2][2])/2.0f + 0.5f);
*V = (Uint8)SDL_floorf((yuv[0][2] + yuv[2][2]) / 2.0f + 0.5f);
V += UV_advance;
}
Y1 += w;
@@ -170,10 +169,10 @@ static void ConvertRGBtoPlanar2x2(Uint32 format, Uint8 *src, int pitch, Uint8 *o
rgb1 += 3;
*Y1++ = (Uint8)yuv[1][0];
*U = (Uint8)SDL_floorf((yuv[0][1] + yuv[1][1])/2.0f + 0.5f);
*U = (Uint8)SDL_floorf((yuv[0][1] + yuv[1][1]) / 2.0f + 0.5f);
U += UV_advance;
*V = (Uint8)SDL_floorf((yuv[0][2] + yuv[1][2])/2.0f + 0.5f);
*V = (Uint8)SDL_floorf((yuv[0][2] + yuv[1][2]) / 2.0f + 0.5f);
V += UV_advance;
}
/* Last column */
@@ -196,28 +195,28 @@ static void ConvertRGBtoPacked4(Uint32 format, Uint8 *src, int pitch, Uint8 *out
int yuv[2][3];
Uint8 *Y1, *Y2, *U, *V;
Uint8 *rgb;
int rgb_row_advance = (pitch - w*3);
int rgb_row_advance = (pitch - w * 3);
rgb = src;
switch (format) {
case SDL_PIXELFORMAT_YUY2:
Y1 = out;
U = out+1;
Y2 = out+2;
V = out+3;
U = out + 1;
Y2 = out + 2;
V = out + 3;
break;
case SDL_PIXELFORMAT_UYVY:
U = out;
Y1 = out+1;
V = out+2;
Y2 = out+3;
Y1 = out + 1;
V = out + 2;
Y2 = out + 3;
break;
case SDL_PIXELFORMAT_YVYU:
Y1 = out;
V = out+1;
Y2 = out+2;
U = out+3;
V = out + 1;
Y2 = out + 2;
U = out + 3;
break;
default:
SDL_assert(!"Unsupported packed YUV format");
@@ -236,10 +235,10 @@ static void ConvertRGBtoPacked4(Uint32 format, Uint8 *src, int pitch, Uint8 *out
*Y2 = (Uint8)yuv[1][0];
Y2 += 4;
*U = (Uint8)SDL_floorf((yuv[0][1] + yuv[1][1])/2.0f + 0.5f);
*U = (Uint8)SDL_floorf((yuv[0][1] + yuv[1][1]) / 2.0f + 0.5f);
U += 4;
*V = (Uint8)SDL_floorf((yuv[0][2] + yuv[1][2])/2.0f + 0.5f);
*V = (Uint8)SDL_floorf((yuv[0][2] + yuv[1][2]) / 2.0f + 0.5f);
V += 4;
}
/* Last column */
@@ -262,8 +261,7 @@ static void ConvertRGBtoPacked4(Uint32 format, Uint8 *src, int pitch, Uint8 *out
SDL_bool ConvertRGBtoYUV(Uint32 format, Uint8 *src, int pitch, Uint8 *out, int w, int h, SDL_YUV_CONVERSION_MODE mode, int monochrome, int luminance)
{
switch (format)
{
switch (format) {
case SDL_PIXELFORMAT_YV12:
case SDL_PIXELFORMAT_IYUV:
case SDL_PIXELFORMAT_NV12:
@@ -282,8 +280,7 @@ SDL_bool ConvertRGBtoYUV(Uint32 format, Uint8 *src, int pitch, Uint8 *out, int w
int CalculateYUVPitch(Uint32 format, int width)
{
switch (format)
{
switch (format) {
case SDL_PIXELFORMAT_YV12:
case SDL_PIXELFORMAT_IYUV:
case SDL_PIXELFORMAT_NV12:

View File

@@ -34,8 +34,8 @@ quit(int rc)
int SDLCALL
SubThreadFunc(void *data)
{
while (!*(int volatile *) data) {
; /* SDL_Delay(10); *//* do nothing */
while (!*(int volatile *)data) {
; /* SDL_Delay(10); */ /* do nothing */
}
return 0;
}
@@ -46,20 +46,20 @@ ThreadFunc(void *data)
SDL_Thread *sub_threads[NUMTHREADS];
int flags[NUMTHREADS];
int i;
int tid = (int) (uintptr_t) data;
int tid = (int)(uintptr_t)data;
SDL_Log("Creating Thread %d\n", tid);
for (i = 0; i < NUMTHREADS; i++) {
char name[64];
SDL_snprintf(name, sizeof (name), "Child%d_%d", tid, i);
SDL_snprintf(name, sizeof(name), "Child%d_%d", tid, i);
flags[i] = 0;
sub_threads[i] = SDL_CreateThread(SubThreadFunc, name, &flags[i]);
}
SDL_Log("Thread '%d' waiting for signal\n", tid);
while (SDL_AtomicGet(&time_for_threads_to_die[tid]) != 1) {
; /* do nothing */
; /* do nothing */
}
SDL_Log("Thread '%d' sending signals to subthreads\n", tid);
@@ -73,8 +73,7 @@ ThreadFunc(void *data)
return 0;
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
SDL_Thread *threads[NUMTHREADS];
int i;
@@ -91,9 +90,9 @@ main(int argc, char *argv[])
signal(SIGSEGV, SIG_DFL);
for (i = 0; i < NUMTHREADS; i++) {
char name[64];
SDL_snprintf(name, sizeof (name), "Parent%d", i);
SDL_snprintf(name, sizeof(name), "Parent%d", i);
SDL_AtomicSet(&time_for_threads_to_die[i], 0);
threads[i] = SDL_CreateThread(ThreadFunc, name, (void*) (uintptr_t) i);
threads[i] = SDL_CreateThread(ThreadFunc, name, (void *)(uintptr_t)i);
if (threads[i] == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());