mirror of
https://github.com/yawut/SDL.git
synced 2026-09-08 09:06:29 -05:00
WinRT: merged with the latest official SDL source
This commit is contained in:
@@ -14,6 +14,7 @@ TARGETS = \
|
||||
testdraw2$(EXE) \
|
||||
testerror$(EXE) \
|
||||
testfile$(EXE) \
|
||||
testgamecontroller$(EXE) \
|
||||
testgesture$(EXE) \
|
||||
testgl2$(EXE) \
|
||||
testgles$(EXE) \
|
||||
@@ -87,6 +88,9 @@ testerror$(EXE): $(srcdir)/testerror.c
|
||||
testfile$(EXE): $(srcdir)/testfile.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testgamecontroller$(EXE): $(srcdir)/testgamecontroller.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testgesture$(EXE): $(srcdir)/testgesture.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
|
||||
|
||||
|
||||
@@ -62,13 +62,13 @@ static void rwops_testParam (void)
|
||||
static int rwops_testGeneric( SDL_RWops *rw, int write )
|
||||
{
|
||||
char buf[sizeof(hello_world)];
|
||||
int i;
|
||||
Sint64 i;
|
||||
|
||||
/* Set to start. */
|
||||
i = SDL_RWseek( rw, 0, RW_SEEK_SET );
|
||||
if (SDL_ATvassert( i == 0,
|
||||
"Seeking with SDL_RWseek (RW_SEEK_SET): got %d, expected %d",
|
||||
i, 0 ))
|
||||
(int)i, 0 ))
|
||||
return 1;
|
||||
|
||||
/* Test write. */
|
||||
@@ -86,14 +86,14 @@ static int rwops_testGeneric( SDL_RWops *rw, int write )
|
||||
i = SDL_RWseek( rw, 6, RW_SEEK_SET );
|
||||
if (SDL_ATvassert( i == 6,
|
||||
"Seeking with SDL_RWseek (RW_SEEK_SET): got %d, expected %d",
|
||||
i, 0 ))
|
||||
(int)i, 0 ))
|
||||
return 1;
|
||||
|
||||
/* Test seek. */
|
||||
i = SDL_RWseek( rw, 0, RW_SEEK_SET );
|
||||
if (SDL_ATvassert( i == 0,
|
||||
"Seeking with SDL_RWseek (RW_SEEK_SET): got %d, expected %d",
|
||||
i, 0 ))
|
||||
(int)i, 0 ))
|
||||
return 1;
|
||||
|
||||
/* Test read. */
|
||||
@@ -108,12 +108,12 @@ static int rwops_testGeneric( SDL_RWops *rw, int write )
|
||||
i = SDL_RWseek( rw, -4, RW_SEEK_CUR );
|
||||
if (SDL_ATvassert( i == sizeof(hello_world)-5,
|
||||
"Seeking with SDL_RWseek (RW_SEEK_CUR): got %d, expected %d",
|
||||
i, sizeof(hello_world)-5 ))
|
||||
(int)i, sizeof(hello_world)-5 ))
|
||||
return 1;
|
||||
i = SDL_RWseek( rw, -1, RW_SEEK_END );
|
||||
if (SDL_ATvassert( i == sizeof(hello_world)-2,
|
||||
"Seeking with SDL_RWseek (RW_SEEK_END): got %d, expected %d",
|
||||
i, sizeof(hello_world)-2 ))
|
||||
(int)i, sizeof(hello_world)-2 ))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
|
||||
17
test/automated/surface/surface.c
Executable file → Normal file
17
test/automated/surface/surface.c
Executable file → Normal file
@@ -27,7 +27,7 @@
|
||||
/* Testcases. */
|
||||
static void surface_testLoad( SDL_Surface *testsur );
|
||||
static void surface_testBlit( SDL_Surface *testsur );
|
||||
static int surface_testBlitBlendMode( SDL_Surface *testsur, SDL_Surface *face, int mode );
|
||||
static int surface_testBlitBlendMode( SDL_Surface *testsur, SDL_Surface *face, SDL_BlendMode bMode );
|
||||
static void surface_testBlitBlend( SDL_Surface *testsur );
|
||||
|
||||
|
||||
@@ -212,7 +212,7 @@ static void surface_testBlit( SDL_Surface *testsur )
|
||||
/**
|
||||
* @brief Tests a blend mode.
|
||||
*/
|
||||
static int surface_testBlitBlendMode( SDL_Surface *testsur, SDL_Surface *face, int mode )
|
||||
static int surface_testBlitBlendMode( SDL_Surface *testsur, SDL_Surface *face, SDL_BlendMode bMode )
|
||||
{
|
||||
int ret;
|
||||
int i, j, ni, nj;
|
||||
@@ -236,7 +236,7 @@ static int surface_testBlitBlendMode( SDL_Surface *testsur, SDL_Surface *face, i
|
||||
for (j=0; j <= nj; j+=4) {
|
||||
for (i=0; i <= ni; i+=4) {
|
||||
/* Set blend mode. */
|
||||
ret = SDL_SetSurfaceBlendMode( face, mode );
|
||||
ret = SDL_SetSurfaceBlendMode( face, bMode );
|
||||
if (SDL_ATassert( "SDL_SetSurfaceBlendMode", ret == 0))
|
||||
return 1;
|
||||
|
||||
@@ -263,6 +263,7 @@ static void surface_testBlitBlend( SDL_Surface *testsur )
|
||||
SDL_Surface *face;
|
||||
int i, j, ni, nj;
|
||||
int mode;
|
||||
SDL_BlendMode bMode;
|
||||
|
||||
SDL_ATbegin( "Blit Blending Tests" );
|
||||
|
||||
@@ -353,11 +354,11 @@ static void surface_testBlitBlend( SDL_Surface *testsur )
|
||||
|
||||
/* Crazy blending mode magic. */
|
||||
mode = (i/4*j/4) % 4;
|
||||
if (mode==0) mode = SDL_BLENDMODE_NONE;
|
||||
else if (mode==1) mode = SDL_BLENDMODE_BLEND;
|
||||
else if (mode==2) mode = SDL_BLENDMODE_ADD;
|
||||
else if (mode==3) mode = SDL_BLENDMODE_MOD;
|
||||
ret = SDL_SetSurfaceBlendMode( face, mode );
|
||||
if (mode==0) bMode = SDL_BLENDMODE_NONE;
|
||||
else if (mode==1) bMode = SDL_BLENDMODE_BLEND;
|
||||
else if (mode==2) bMode = SDL_BLENDMODE_ADD;
|
||||
else if (mode==3) bMode = SDL_BLENDMODE_MOD;
|
||||
ret = SDL_SetSurfaceBlendMode( face, bMode );
|
||||
if (SDL_ATassert( "SDL_SetSurfaceBlendMode", ret == 0))
|
||||
return;
|
||||
|
||||
|
||||
4246
test/configure
vendored
4246
test/configure
vendored
File diff suppressed because it is too large
Load Diff
@@ -78,6 +78,7 @@ poked(int sig)
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
char filename[4096];
|
||||
|
||||
/* Load the SDL library */
|
||||
@@ -110,6 +111,17 @@ main(int argc, char *argv[])
|
||||
signal(SIGTERM, poked);
|
||||
#endif /* HAVE_SIGNAL_H */
|
||||
|
||||
/* Show the list of available drivers */
|
||||
printf("Available audio drivers: ");
|
||||
for (i = 0; i < SDL_GetNumAudioDrivers(); ++i) {
|
||||
if (i == 0) {
|
||||
printf("%s", SDL_GetAudioDriver(i));
|
||||
} else {
|
||||
printf(", %s", SDL_GetAudioDriver(i));
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
/* Initialize fillerup() variables */
|
||||
if (SDL_OpenAudio(&wave.spec, NULL) < 0) {
|
||||
fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
|
||||
@@ -130,3 +142,5 @@ main(int argc, char *argv[])
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
0
test/nds-test-progs/general/source/main.c
Executable file → Normal file
0
test/nds-test-progs/general/source/main.c
Executable file → Normal file
113
test/testautomation.c
Normal file
113
test/testautomation.c
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_test.h"
|
||||
|
||||
#include "tests/testsuites.h"
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
{
|
||||
SDLTest_CommonQuit(state);
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int result;
|
||||
int testIterations = 1;
|
||||
Uint64 userExecKey = 0;
|
||||
char *userRunSeed = NULL;
|
||||
int i;
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Needed?
|
||||
// state->window_flags |= SDL_WINDOW_RESIZABLE;
|
||||
|
||||
/* Parse commandline */
|
||||
for (i = 1; i < argc;) {
|
||||
int consumed;
|
||||
|
||||
consumed = SDLTest_CommonArg(state, i);
|
||||
if (consumed == 0) {
|
||||
consumed = -1;
|
||||
if (SDL_strcasecmp(argv[i], "--iterations") == 0) {
|
||||
if (argv[i + 1]) {
|
||||
testIterations = SDL_atoi(argv[i + 1]);
|
||||
if (testIterations < 1) testIterations = 1;
|
||||
consumed = 2;
|
||||
}
|
||||
}
|
||||
else if (SDL_strcasecmp(argv[i], "--execKey") == 0) {
|
||||
if (argv[i + 1]) {
|
||||
SDL_sscanf(argv[i + 1], "%llu", &userExecKey);
|
||||
consumed = 2;
|
||||
}
|
||||
}
|
||||
else if (SDL_strcasecmp(argv[i], "--seed") == 0) {
|
||||
if (argv[i + 1]) {
|
||||
userRunSeed = SDL_strdup(argv[i + 1]);
|
||||
consumed = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (consumed < 0) {
|
||||
fprintf(stderr,
|
||||
"Usage: %s %s [--iterations #] [--execKey #] [--seed string]\n",
|
||||
argv[0], SDLTest_CommonUsage(state));
|
||||
quit(1);
|
||||
}
|
||||
|
||||
i += consumed;
|
||||
}
|
||||
|
||||
/* Initialize common state */
|
||||
if (!SDLTest_CommonInit(state)) {
|
||||
quit(2);
|
||||
}
|
||||
|
||||
/* Create the windows, initialize the renderers */
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
}
|
||||
|
||||
/* Call Harness */
|
||||
result = SDLTest_RunSuites(testSuites, userRunSeed, userExecKey, testIterations);
|
||||
|
||||
/* Clean up */
|
||||
if (userRunSeed != NULL) {
|
||||
SDL_free(userRunSeed);
|
||||
}
|
||||
|
||||
/* Shutdown everything */
|
||||
quit(result);
|
||||
return(result);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
205
test/testgamecontroller.c
Normal file
205
test/testgamecontroller.c
Normal file
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely.
|
||||
*/
|
||||
|
||||
/* Simple program to test the SDL game controller routines */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#ifdef __IPHONEOS__
|
||||
#define SCREEN_WIDTH 320
|
||||
#define SCREEN_HEIGHT 480
|
||||
#else
|
||||
#define SCREEN_WIDTH 640
|
||||
#define SCREEN_HEIGHT 480
|
||||
#endif
|
||||
|
||||
#define MAX_NUM_AXES 6
|
||||
#define MAX_NUM_HATS 2
|
||||
|
||||
static SDL_bool s_ForceQuit = SDL_FALSE;
|
||||
|
||||
static void
|
||||
DrawRect(SDL_Renderer *r, const int x, const int y, const int w, const int h)
|
||||
{
|
||||
const SDL_Rect area = { x, y, w, h };
|
||||
SDL_RenderFillRect(r, &area);
|
||||
}
|
||||
|
||||
void
|
||||
WatchGameController(SDL_GameController * gamecontroller)
|
||||
{
|
||||
SDL_Window *window = NULL;
|
||||
SDL_Renderer *screen = NULL;
|
||||
const char *name = NULL;
|
||||
int done = 0;
|
||||
SDL_Event event;
|
||||
int i;
|
||||
|
||||
/* Create a window to display controller axis position */
|
||||
window = SDL_CreateWindow("Game Controller Test", SDL_WINDOWPOS_CENTERED,
|
||||
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
|
||||
SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
|
||||
if (window == NULL) {
|
||||
fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
|
||||
screen = SDL_CreateRenderer(window, -1, 0);
|
||||
if (screen == NULL) {
|
||||
fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError());
|
||||
SDL_DestroyWindow(window);
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(screen);
|
||||
SDL_RenderPresent(screen);
|
||||
SDL_RaiseWindow(window);
|
||||
|
||||
/* Print info about the controller we are watching */
|
||||
name = SDL_GameControllerName(gamecontroller);
|
||||
printf("Watching controller %s\n", name ? name : "Unknown Controller");
|
||||
|
||||
/* Loop, getting controller events! */
|
||||
while (!done) {
|
||||
/* blank screen, set up for drawing this frame. */
|
||||
SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(screen);
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_CONTROLLERAXISMOTION:
|
||||
printf("Controller %d axis %d value: %d\n",
|
||||
event.caxis.which,
|
||||
event.caxis.axis, event.caxis.value);
|
||||
break;
|
||||
case SDL_CONTROLLERBUTTONDOWN:
|
||||
printf("Controller %d button %d down\n",
|
||||
event.cbutton.which, event.cbutton.button);
|
||||
break;
|
||||
case SDL_CONTROLLERBUTTONUP:
|
||||
printf("Controller %d button %d up\n",
|
||||
event.cbutton.which, event.cbutton.button);
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym != SDLK_ESCAPE) {
|
||||
break;
|
||||
}
|
||||
/* Fall through to signal quit */
|
||||
case SDL_QUIT:
|
||||
done = 1;
|
||||
s_ForceQuit = SDL_TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Update visual controller state */
|
||||
SDL_SetRenderDrawColor(screen, 0x00, 0xFF, 0x00, SDL_ALPHA_OPAQUE);
|
||||
for (i = 0; i <SDL_CONTROLLER_BUTTON_MAX; ++i) {
|
||||
if (SDL_GameControllerGetButton(gamecontroller, i) == SDL_PRESSED) {
|
||||
DrawRect(screen, i * 34, SCREEN_HEIGHT - 34, 32, 32);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(screen, 0xFF, 0x00, 0x00, SDL_ALPHA_OPAQUE);
|
||||
for (i = 0; i < SDL_CONTROLLER_AXIS_MAX / 2; ++i) {
|
||||
/* Draw the X/Y axis */
|
||||
int x, y;
|
||||
x = (((int) SDL_GameControllerGetAxis(gamecontroller, i * 2 + 0)) + 32768);
|
||||
x *= SCREEN_WIDTH;
|
||||
x /= 65535;
|
||||
if (x < 0) {
|
||||
x = 0;
|
||||
} else if (x > (SCREEN_WIDTH - 16)) {
|
||||
x = SCREEN_WIDTH - 16;
|
||||
}
|
||||
y = (((int) SDL_GameControllerGetAxis(gamecontroller, i * 2 + 1)) + 32768);
|
||||
y *= SCREEN_HEIGHT;
|
||||
y /= 65535;
|
||||
if (y < 0) {
|
||||
y = 0;
|
||||
} else if (y > (SCREEN_HEIGHT - 16)) {
|
||||
y = SCREEN_HEIGHT - 16;
|
||||
}
|
||||
|
||||
DrawRect(screen, x, y, 16, 16);
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0xFF, SDL_ALPHA_OPAQUE);
|
||||
|
||||
SDL_RenderPresent(screen);
|
||||
|
||||
if ( !done )
|
||||
done = SDL_GameControllerGetAttached( gamecontroller ) == 0;
|
||||
}
|
||||
|
||||
SDL_DestroyRenderer(screen);
|
||||
SDL_DestroyWindow(window);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
const char *name;
|
||||
int i;
|
||||
int nController = 0;
|
||||
SDL_GameController *gamecontroller;
|
||||
|
||||
SDL_SetHint( SDL_HINT_GAMECONTROLLERCONFIG, "341a3608000000000000504944564944,Aferglow PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7" );
|
||||
/* Initialize SDL (Note: video is required to start event loop) */
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER ) < 0) {
|
||||
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Print information about the controller */
|
||||
for (i = 0; i < SDL_NumJoysticks(); ++i) {
|
||||
if ( SDL_IsGameController(i) )
|
||||
{
|
||||
nController++;
|
||||
name = SDL_GameControllerNameForIndex(i);
|
||||
printf("Game Controller %d: %s\n", i, name ? name : "Unknown Controller");
|
||||
}
|
||||
}
|
||||
printf("There are %d game controllers attached\n", nController);
|
||||
|
||||
if (argv[1]) {
|
||||
int nreportederror = 0;
|
||||
SDL_Event event;
|
||||
gamecontroller = SDL_GameControllerOpen(atoi(argv[1]));
|
||||
while ( s_ForceQuit == SDL_FALSE ) {
|
||||
if (gamecontroller == NULL) {
|
||||
if ( nreportederror == 0 ) {
|
||||
printf("Couldn't open joystick %d: %s\n", atoi(argv[1]), SDL_GetError());
|
||||
nreportederror = 1;
|
||||
}
|
||||
} else {
|
||||
nreportederror = 0;
|
||||
WatchGameController(gamecontroller);
|
||||
SDL_GameControllerClose(gamecontroller);
|
||||
}
|
||||
|
||||
gamecontroller = NULL;
|
||||
SDL_WaitEvent( &event );
|
||||
if ( event.type == SDL_JOYDEVICEADDED )
|
||||
gamecontroller = SDL_GameControllerOpen(atoi(argv[1]));
|
||||
}
|
||||
}
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER );
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -17,10 +17,14 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "common.h"
|
||||
|
||||
static CommonState *state;
|
||||
static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
|
||||
#ifdef __IPHONEOS__
|
||||
#define SCREEN_WIDTH 320
|
||||
#define SCREEN_HEIGHT 480
|
||||
#else
|
||||
#define SCREEN_WIDTH 640
|
||||
#define SCREEN_HEIGHT 480
|
||||
#endif
|
||||
|
||||
#define MAX_NUM_AXES 6
|
||||
#define MAX_NUM_HATS 2
|
||||
@@ -32,21 +36,41 @@ DrawRect(SDL_Renderer *r, const int x, const int y, const int w, const int h)
|
||||
SDL_RenderFillRect(r, &area);
|
||||
}
|
||||
|
||||
void
|
||||
static SDL_bool
|
||||
WatchJoystick(SDL_Joystick * joystick)
|
||||
{
|
||||
SDL_Window *window = NULL;
|
||||
SDL_Renderer *screen = NULL;
|
||||
SDL_Rect viewport;
|
||||
SDL_Event event;
|
||||
|
||||
const char *name = NULL;
|
||||
int done = 0;
|
||||
SDL_bool retval = SDL_FALSE;
|
||||
SDL_bool done = SDL_FALSE;
|
||||
SDL_Event event;
|
||||
int i;
|
||||
|
||||
/* Create a window to display joystick axis position */
|
||||
window = SDL_CreateWindow("Joystick Test", SDL_WINDOWPOS_CENTERED,
|
||||
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
|
||||
SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
|
||||
if (window == NULL) {
|
||||
fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
screen = SDL_CreateRenderer(window, -1, 0);
|
||||
if (screen == NULL) {
|
||||
fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError());
|
||||
SDL_DestroyWindow(window);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(screen);
|
||||
SDL_RenderPresent(screen);
|
||||
SDL_RaiseWindow(window);
|
||||
|
||||
/* Print info about the joystick we are watching */
|
||||
name = SDL_JoystickName(SDL_JoystickIndex(joystick));
|
||||
printf("Watching joystick %d: (%s)\n", SDL_JoystickIndex(joystick),
|
||||
name = SDL_JoystickName(joystick);
|
||||
printf("Watching joystick %d: (%s)\n", SDL_JoystickInstanceID(joystick),
|
||||
name ? name : "Unknown Joystick");
|
||||
printf("Joystick has %d axes, %d hats, %d balls, and %d buttons\n",
|
||||
SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
|
||||
@@ -54,6 +78,10 @@ WatchJoystick(SDL_Joystick * joystick)
|
||||
|
||||
/* Loop, getting joystick events! */
|
||||
while (!done) {
|
||||
/* blank screen, set up for drawing this frame. */
|
||||
SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(screen);
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_JOYAXISMOTION:
|
||||
@@ -95,152 +123,149 @@ WatchJoystick(SDL_Joystick * joystick)
|
||||
}
|
||||
/* Fall through to signal quit */
|
||||
case SDL_QUIT:
|
||||
done = 1;
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Update visual joystick state */
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
screen = state->renderers[i];
|
||||
SDL_SetRenderDrawColor(screen, 0x00, 0xFF, 0x00, SDL_ALPHA_OPAQUE);
|
||||
for (i = 0; i < SDL_JoystickNumButtons(joystick); ++i) {
|
||||
if (SDL_JoystickGetButton(joystick, i) == SDL_PRESSED) {
|
||||
DrawRect(screen, i * 34, SCREEN_HEIGHT - 34, 32, 32);
|
||||
}
|
||||
}
|
||||
|
||||
/* Erase previous axes */
|
||||
SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(screen);
|
||||
|
||||
/* Query the sizes */
|
||||
SDL_RenderGetViewport(screen, &viewport);
|
||||
|
||||
SDL_SetRenderDrawColor(screen, 0x00, 0xFF, 0x00, SDL_ALPHA_OPAQUE);
|
||||
for (i = 0; i < SDL_JoystickNumButtons(joystick); ++i) {
|
||||
if (SDL_JoystickGetButton(joystick, i) == SDL_PRESSED) {
|
||||
DrawRect(screen, i * 34, viewport.h - 34, 32, 32);
|
||||
}
|
||||
SDL_SetRenderDrawColor(screen, 0xFF, 0x00, 0x00, SDL_ALPHA_OPAQUE);
|
||||
for (i = 0; i < SDL_JoystickNumAxes(joystick) / 2; ++i) {
|
||||
/* Draw the X/Y axis */
|
||||
int x, y;
|
||||
x = (((int) SDL_JoystickGetAxis(joystick, i * 2 + 0)) + 32768);
|
||||
x *= SCREEN_WIDTH;
|
||||
x /= 65535;
|
||||
if (x < 0) {
|
||||
x = 0;
|
||||
} else if (x > (SCREEN_WIDTH - 16)) {
|
||||
x = SCREEN_WIDTH - 16;
|
||||
}
|
||||
y = (((int) SDL_JoystickGetAxis(joystick, i * 2 + 1)) + 32768);
|
||||
y *= SCREEN_HEIGHT;
|
||||
y /= 65535;
|
||||
if (y < 0) {
|
||||
y = 0;
|
||||
} else if (y > (SCREEN_HEIGHT - 16)) {
|
||||
y = SCREEN_HEIGHT - 16;
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(screen, 0xFF, 0x00, 0x00, SDL_ALPHA_OPAQUE);
|
||||
for (i = 0; i < SDL_JoystickNumAxes(joystick) / 2; ++i) {
|
||||
/* Draw the X/Y axis */
|
||||
int x, y;
|
||||
x = (((int) SDL_JoystickGetAxis(joystick, i * 2 + 0)) + 32768);
|
||||
x *= viewport.w ;
|
||||
x /= 65535;
|
||||
if (x < 0) {
|
||||
x = 0;
|
||||
} else if (x > (viewport.w - 16)) {
|
||||
x = viewport.w - 16;
|
||||
}
|
||||
y = (((int) SDL_JoystickGetAxis(joystick, i * 2 + 1)) + 32768);
|
||||
y *= viewport.h;
|
||||
y /= 65535;
|
||||
if (y < 0) {
|
||||
y = 0;
|
||||
} else if (y > (viewport.h - 16)) {
|
||||
y = viewport.h - 16;
|
||||
}
|
||||
DrawRect(screen, x, y, 16, 16);
|
||||
}
|
||||
|
||||
DrawRect(screen, x, y, 16, 16);
|
||||
SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0xFF, SDL_ALPHA_OPAQUE);
|
||||
for (i = 0; i < SDL_JoystickNumHats(joystick); ++i) {
|
||||
/* Derive the new position */
|
||||
int x = SCREEN_WIDTH/2;
|
||||
int y = SCREEN_HEIGHT/2;
|
||||
const Uint8 hat_pos = SDL_JoystickGetHat(joystick, i);
|
||||
|
||||
if (hat_pos & SDL_HAT_UP) {
|
||||
y = 0;
|
||||
} else if (hat_pos & SDL_HAT_DOWN) {
|
||||
y = SCREEN_HEIGHT-8;
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0xFF, SDL_ALPHA_OPAQUE);
|
||||
for (i = 0; i < SDL_JoystickNumHats(joystick); ++i) {
|
||||
/* Derive the new position */
|
||||
int x = viewport.w/2;
|
||||
int y = viewport.h/2;
|
||||
const Uint8 hat_pos = SDL_JoystickGetHat(joystick, i);
|
||||
|
||||
if (hat_pos & SDL_HAT_UP) {
|
||||
y = 0;
|
||||
} else if (hat_pos & SDL_HAT_DOWN) {
|
||||
y = viewport.h-8;
|
||||
}
|
||||
|
||||
if (hat_pos & SDL_HAT_LEFT) {
|
||||
x = 0;
|
||||
} else if (hat_pos & SDL_HAT_RIGHT) {
|
||||
x = viewport.w-8;
|
||||
}
|
||||
|
||||
DrawRect(screen, x, y, 8, 8);
|
||||
if (hat_pos & SDL_HAT_LEFT) {
|
||||
x = 0;
|
||||
} else if (hat_pos & SDL_HAT_RIGHT) {
|
||||
x = SCREEN_WIDTH-8;
|
||||
}
|
||||
|
||||
SDL_RenderPresent(screen);
|
||||
DrawRect(screen, x, y, 8, 8);
|
||||
}
|
||||
|
||||
SDL_RenderPresent(screen);
|
||||
|
||||
if (SDL_JoystickGetAttached( joystick ) == 0) {
|
||||
done = SDL_TRUE;
|
||||
retval = SDL_TRUE; /* keep going, wait for reattach. */
|
||||
}
|
||||
}
|
||||
|
||||
SDL_DestroyRenderer(screen);
|
||||
SDL_DestroyWindow(window);
|
||||
return retval;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
const char *name;
|
||||
int i, joy=-1;
|
||||
int i;
|
||||
SDL_Joystick *joystick;
|
||||
|
||||
/* Initialize SDL (Note: video is required to start event loop) */
|
||||
if (SDL_Init(SDL_INIT_JOYSTICK) < 0) {
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
|
||||
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Initialize test framework */
|
||||
state = CommonCreateState(argv, SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
|
||||
if (!state) {
|
||||
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Print information about the joysticks */
|
||||
printf("There are %d joysticks attached\n", SDL_NumJoysticks());
|
||||
for (i = 0; i < SDL_NumJoysticks(); ++i) {
|
||||
name = SDL_JoystickName(i);
|
||||
name = SDL_JoystickNameForIndex(i);
|
||||
printf("Joystick %d: %s\n", i, name ? name : "Unknown Joystick");
|
||||
joystick = SDL_JoystickOpen(i);
|
||||
if (joystick == NULL) {
|
||||
fprintf(stderr, "SDL_JoystickOpen(%d) failed: %s\n", i,
|
||||
SDL_GetError());
|
||||
} else {
|
||||
char guid[64];
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick),
|
||||
guid, sizeof (guid));
|
||||
printf(" axes: %d\n", SDL_JoystickNumAxes(joystick));
|
||||
printf(" balls: %d\n", SDL_JoystickNumBalls(joystick));
|
||||
printf(" hats: %d\n", SDL_JoystickNumHats(joystick));
|
||||
printf(" buttons: %d\n", SDL_JoystickNumButtons(joystick));
|
||||
printf("instance id: %d\n", SDL_JoystickInstanceID(joystick));
|
||||
printf(" guid: %s\n", guid);
|
||||
SDL_JoystickClose(joystick);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 1; i < argc;) {
|
||||
int consumed;
|
||||
if (argv[1]) {
|
||||
SDL_bool reportederror = SDL_FALSE;
|
||||
SDL_bool keepGoing = SDL_TRUE;
|
||||
SDL_Event event;
|
||||
joystick = SDL_JoystickOpen(atoi(argv[1]));
|
||||
while ( keepGoing ) {
|
||||
if (joystick == NULL) {
|
||||
if ( !reportederror ) {
|
||||
printf("Couldn't open joystick %d: %s\n", atoi(argv[1]), SDL_GetError());
|
||||
keepGoing = SDL_FALSE;
|
||||
reportederror = SDL_TRUE;
|
||||
}
|
||||
} else {
|
||||
reportederror = SDL_FALSE;
|
||||
keepGoing = WatchJoystick(joystick);
|
||||
SDL_JoystickClose(joystick);
|
||||
}
|
||||
|
||||
consumed = CommonArg(state, i);
|
||||
if (consumed == 0) {
|
||||
consumed = -1;
|
||||
if (SDL_isdigit(*argv[i])) {
|
||||
joy = SDL_atoi(argv[i]);
|
||||
consumed = 1;
|
||||
joystick = NULL;
|
||||
if (keepGoing) {
|
||||
printf("Waiting for attach\n");
|
||||
}
|
||||
while (keepGoing) {
|
||||
SDL_WaitEvent(&event);
|
||||
if (event.type == SDL_QUIT) {
|
||||
keepGoing = SDL_FALSE;
|
||||
} else if (event.type == SDL_JOYDEVICEADDED) {
|
||||
joystick = SDL_JoystickOpen(atoi(argv[1]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (consumed < 0) {
|
||||
return 1;
|
||||
}
|
||||
i += consumed;
|
||||
}
|
||||
if (!CommonInit(state)) {
|
||||
return 2;
|
||||
}
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
|
||||
|
||||
if (joy > -1) {
|
||||
joystick = SDL_JoystickOpen(joy);
|
||||
if (joystick == NULL) {
|
||||
printf("Couldn't open joystick %d: %s\n", joy,
|
||||
SDL_GetError());
|
||||
} else {
|
||||
WatchJoystick(joystick);
|
||||
SDL_JoystickClose(joystick);
|
||||
}
|
||||
}
|
||||
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
|
||||
CommonQuit(state);
|
||||
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -49,6 +49,35 @@ main(int argc, char *argv[])
|
||||
quit(1);
|
||||
}
|
||||
|
||||
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
|
||||
"Simple MessageBox",
|
||||
"This is a simple MessageBox with a newline:\r\nHello world!",
|
||||
NULL);
|
||||
if (success == -1) {
|
||||
printf("Error Presenting MessageBox: %s\n", SDL_GetError());
|
||||
quit(1);
|
||||
}
|
||||
|
||||
/* Google says this is Traditional Chinese for "beef with broccoli" */
|
||||
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
|
||||
"UTF-8 Simple MessageBox",
|
||||
"Unicode text: '牛肉西蘭花' ...",
|
||||
NULL);
|
||||
if (success == -1) {
|
||||
printf("Error Presenting MessageBox: %s\n", SDL_GetError());
|
||||
quit(1);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
if (success == -1) {
|
||||
printf("Error Presenting MessageBox: %s\n", SDL_GetError());
|
||||
quit(1);
|
||||
}
|
||||
|
||||
{
|
||||
const SDL_MessageBoxButtonData buttons[] = {
|
||||
{
|
||||
|
||||
561
test/tests/testplatform.c
Normal file
561
test/tests/testplatform.c
Normal file
@@ -0,0 +1,561 @@
|
||||
/**
|
||||
* Original code: automated SDL platform test written by Edgar Simo "bobbens"
|
||||
* Extended and updated by aschiffler at ferzkopp dot net
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_test.h"
|
||||
|
||||
/* ================= Test Case Implementation ================== */
|
||||
|
||||
/* Helper functions */
|
||||
|
||||
/**
|
||||
* @brief Compare sizes of types.
|
||||
*
|
||||
* @note Watcom C flags these as Warning 201: "Unreachable code" if you just
|
||||
* 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 )
|
||||
{
|
||||
return sizeoftype != hardcodetype;
|
||||
}
|
||||
|
||||
/* Test case functions */
|
||||
|
||||
/**
|
||||
* @brief Tests type sizes.
|
||||
*/
|
||||
int platform_testTypes(void *arg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = _compareSizeOfType( sizeof(Uint8), 1 );
|
||||
SDLTest_AssertCheck( ret == 0, "sizeof(Uint8) = %lu, expected 1", sizeof(Uint8) );
|
||||
|
||||
ret = _compareSizeOfType( sizeof(Uint16), 2 );
|
||||
SDLTest_AssertCheck( ret == 0, "sizeof(Uint16) = %lu, expected 2", sizeof(Uint16) );
|
||||
|
||||
ret = _compareSizeOfType( sizeof(Uint32), 4 );
|
||||
SDLTest_AssertCheck( ret == 0, "sizeof(Uint32) = %lu, expected 4", sizeof(Uint32) );
|
||||
|
||||
ret = _compareSizeOfType( sizeof(Uint64), 8 );
|
||||
SDLTest_AssertCheck( ret == 0, "sizeof(Uint64) = %lu, expected 8", sizeof(Uint64) );
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests platform endianness and SDL_SwapXY functions.
|
||||
*/
|
||||
int platform_testEndianessAndSwap(void *arg)
|
||||
{
|
||||
int real_byteorder;
|
||||
Uint16 value = 0x1234;
|
||||
Uint16 value16 = 0xCDAB;
|
||||
Uint16 swapped16 = 0xABCD;
|
||||
Uint32 value32 = 0xEFBEADDE;
|
||||
Uint32 swapped32 = 0xDEADBEEF;
|
||||
|
||||
Uint64 value64, swapped64;
|
||||
value64 = 0xEFBEADDE;
|
||||
value64 <<= 32;
|
||||
value64 |= 0xCDAB3412;
|
||||
swapped64 = 0x1234ABCD;
|
||||
swapped64 <<= 32;
|
||||
swapped64 |= 0xDEADBEEF;
|
||||
|
||||
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" );
|
||||
|
||||
/* Test 16 swap. */
|
||||
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%X => 0x%X",
|
||||
value32, SDL_Swap32(value32) );
|
||||
|
||||
/* Test 64 swap. */
|
||||
SDLTest_AssertCheck( SDL_Swap64(value64) == swapped64,
|
||||
#ifdef _MSC_VER
|
||||
"SDL_Swap64(): 64 bit swapped: 0x%I64X => 0x%I64X",
|
||||
#else
|
||||
"SDL_Swap64(): 64 bit swapped: 0x%llX => 0x%llX",
|
||||
#endif
|
||||
value64, SDL_Swap64(value64) );
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Tests SDL_GetXYZ() functions
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetPlatform
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetCPUCount
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetCPUCacheLineSize
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetRevision
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetRevisionNumber
|
||||
*/
|
||||
int platform_testGetFunctions (void *arg)
|
||||
{
|
||||
char *platform;
|
||||
char *revision;
|
||||
int ret;
|
||||
int len;
|
||||
|
||||
platform = (char *)SDL_GetPlatform();
|
||||
SDLTest_AssertPass("SDL_GetPlatform()");
|
||||
SDLTest_AssertCheck(platform != NULL, "SDL_GetPlatform() != NULL");
|
||||
if (platform != NULL) {
|
||||
len = strlen(platform);
|
||||
SDLTest_AssertCheck(len > 0,
|
||||
"SDL_GetPlatform(): expected non-empty platform, was platform: '%s', len: %i",
|
||||
platform,
|
||||
len);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
revision = (char *)SDL_GetRevision();
|
||||
SDLTest_AssertPass("SDL_GetRevision()");
|
||||
SDLTest_AssertCheck(revision != NULL, "SDL_GetRevision() != NULL");
|
||||
|
||||
ret = SDL_GetRevisionNumber();
|
||||
SDLTest_AssertPass("SDL_GetRevisionNumber()");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Tests SDL_HasXYZ() functions
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_Has3DNow
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasAltiVec
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasMMX
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasRDTSC
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasSSE
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasSSE2
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasSSE3
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasSSE41
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasSSE42
|
||||
*/
|
||||
int platform_testHasFunctions (void *arg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
// TODO: independently determine and compare values as well
|
||||
|
||||
ret = SDL_HasRDTSC();
|
||||
SDLTest_AssertPass("SDL_HasRDTSC()");
|
||||
|
||||
ret = SDL_HasAltiVec();
|
||||
SDLTest_AssertPass("SDL_HasAltiVec()");
|
||||
|
||||
ret = SDL_HasMMX();
|
||||
SDLTest_AssertPass("SDL_HasMMX()");
|
||||
|
||||
ret = SDL_Has3DNow();
|
||||
SDLTest_AssertPass("SDL_Has3DNow()");
|
||||
|
||||
ret = SDL_HasSSE();
|
||||
SDLTest_AssertPass("SDL_HasSSE()");
|
||||
|
||||
ret = SDL_HasSSE2();
|
||||
SDLTest_AssertPass("SDL_HasSSE2()");
|
||||
|
||||
ret = SDL_HasSSE3();
|
||||
SDLTest_AssertPass("SDL_HasSSE3()");
|
||||
|
||||
ret = SDL_HasSSE41();
|
||||
SDLTest_AssertPass("SDL_HasSSE41()");
|
||||
|
||||
ret = SDL_HasSSE42();
|
||||
SDLTest_AssertPass("SDL_HasSSE42()");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Tests SDL_GetVersion
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetVersion
|
||||
*/
|
||||
int platform_testGetVersion(void *arg)
|
||||
{
|
||||
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);
|
||||
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Tests default SDL_Init
|
||||
*/
|
||||
int platform_testDefaultInit(void *arg)
|
||||
{
|
||||
int ret;
|
||||
int 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());
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Tests SDL_Get/Set/ClearError
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetError
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetError
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_ClearError
|
||||
*/
|
||||
int platform_testGetSetClearError(void *arg)
|
||||
{
|
||||
const char *testError = "Testing";
|
||||
char *lastError;
|
||||
int len;
|
||||
|
||||
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 = strlen(lastError);
|
||||
SDLTest_AssertCheck(len == 0,
|
||||
"SDL_GetError(): no message expected, len: %i", len);
|
||||
}
|
||||
|
||||
SDL_SetError("%s", testError);
|
||||
SDLTest_AssertPass("SDL_SetError()");
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertCheck(lastError != NULL,
|
||||
"SDL_GetError() != NULL");
|
||||
if (lastError != NULL)
|
||||
{
|
||||
len = strlen(lastError);
|
||||
SDLTest_AssertCheck(len == strlen(testError),
|
||||
"SDL_GetError(): expected message len %i, was len: %i",
|
||||
strlen(testError),
|
||||
len);
|
||||
SDLTest_AssertCheck(strcmp(lastError, testError) == 0,
|
||||
"SDL_GetError(): expected message %s, was message: %s",
|
||||
testError,
|
||||
lastError);
|
||||
}
|
||||
|
||||
// Clean up
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("SDL_ClearError()");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Tests SDL_SetError with empty input
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetError
|
||||
*/
|
||||
int platform_testSetErrorEmptyInput(void *arg)
|
||||
{
|
||||
const char *testError = "";
|
||||
char *lastError;
|
||||
int len;
|
||||
|
||||
SDL_SetError("%s", testError);
|
||||
SDLTest_AssertPass("SDL_SetError()");
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertCheck(lastError != NULL,
|
||||
"SDL_GetError() != NULL");
|
||||
if (lastError != NULL)
|
||||
{
|
||||
len = strlen(lastError);
|
||||
SDLTest_AssertCheck(len == strlen(testError),
|
||||
"SDL_GetError(): expected message len %i, was len: %i",
|
||||
strlen(testError),
|
||||
len);
|
||||
SDLTest_AssertCheck(strcmp(lastError, testError) == 0,
|
||||
"SDL_GetError(): expected message '%s', was message: '%s'",
|
||||
testError,
|
||||
lastError);
|
||||
}
|
||||
|
||||
// Clean up
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("SDL_ClearError()");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Tests SDL_SetError with invalid input
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetError
|
||||
*/
|
||||
int platform_testSetErrorInvalidInput(void *arg)
|
||||
{
|
||||
const char *testError = NULL;
|
||||
const char *probeError = "Testing";
|
||||
char *lastError;
|
||||
int len;
|
||||
|
||||
// Reset
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("SDL_ClearError()");
|
||||
|
||||
// Check for no-op
|
||||
SDL_SetError(testError);
|
||||
SDLTest_AssertPass("SDL_SetError()");
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertCheck(lastError != NULL,
|
||||
"SDL_GetError() != NULL");
|
||||
if (lastError != NULL)
|
||||
{
|
||||
len = strlen(lastError);
|
||||
SDLTest_AssertCheck(len == 0,
|
||||
"SDL_GetError(): expected message len 0, was len: %i",
|
||||
0,
|
||||
len);
|
||||
SDLTest_AssertCheck(strcmp(lastError, "") == 0,
|
||||
"SDL_GetError(): expected message '', was message: '%s'",
|
||||
lastError);
|
||||
}
|
||||
|
||||
// Set
|
||||
SDL_SetError(probeError);
|
||||
SDLTest_AssertPass("SDL_SetError()");
|
||||
|
||||
// Check for no-op
|
||||
SDL_SetError(testError);
|
||||
SDLTest_AssertPass("SDL_SetError()");
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertCheck(lastError != NULL,
|
||||
"SDL_GetError() != NULL");
|
||||
if (lastError != NULL)
|
||||
{
|
||||
len = strlen(lastError);
|
||||
SDLTest_AssertCheck(len == strlen(probeError),
|
||||
"SDL_GetError(): expected message len %i, was len: %i",
|
||||
strlen(probeError),
|
||||
len);
|
||||
SDLTest_AssertCheck(strcmp(lastError, probeError) == 0,
|
||||
"SDL_GetError(): expected message '%s', was message: '%s'",
|
||||
probeError,
|
||||
lastError);
|
||||
}
|
||||
|
||||
// Clean up
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("SDL_ClearError()");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Tests SDL_GetPowerInfo
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetPowerInfo
|
||||
*/
|
||||
int platform_testGetPowerInfo(void *arg)
|
||||
{
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// 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,
|
||||
"Value %i matches when only 'secs' requested",
|
||||
secsAgain);
|
||||
stateAgain = SDL_GetPowerInfo(NULL, &pctAgain);
|
||||
SDLTest_AssertCheck(
|
||||
state==stateAgain,
|
||||
"State %i returned when only 'pct' requested",
|
||||
stateAgain);
|
||||
SDLTest_AssertCheck(
|
||||
pct==pctAgain,
|
||||
"Value %i matches when only 'pct' requested",
|
||||
pctAgain);
|
||||
stateAgain = SDL_GetPowerInfo(NULL, NULL);
|
||||
SDLTest_AssertCheck(
|
||||
state==stateAgain,
|
||||
"State %i returned when no value requested",
|
||||
stateAgain);
|
||||
|
||||
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 platformTest2 =
|
||||
{ (SDLTest_TestCaseFp)platform_testEndianessAndSwap, "platform_testEndianessAndSwap", "Tests endianess 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 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 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 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 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 };
|
||||
|
||||
/* Sequence of Platform test cases */
|
||||
static const SDLTest_TestCaseReference *platformTests[] = {
|
||||
&platformTest1,
|
||||
&platformTest2,
|
||||
&platformTest3,
|
||||
&platformTest4,
|
||||
&platformTest5,
|
||||
&platformTest6,
|
||||
&platformTest7,
|
||||
&platformTest8,
|
||||
&platformTest9,
|
||||
&platformTest10,
|
||||
&platformTest11,
|
||||
NULL
|
||||
};
|
||||
|
||||
/* Platform test suite (global) */
|
||||
SDLTest_TestSuiteReference platformTestSuite = {
|
||||
"Platform",
|
||||
NULL,
|
||||
platformTests,
|
||||
NULL
|
||||
};
|
||||
1677
test/tests/testrect.c
Normal file
1677
test/tests/testrect.c
Normal file
File diff suppressed because it is too large
Load Diff
40
test/tests/testsuites.h
Normal file
40
test/tests/testsuites.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Reference to all test suites.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _testsuites_h
|
||||
#define _testsuites_h
|
||||
|
||||
#include "SDL_test.h"
|
||||
|
||||
// Test collections
|
||||
//extern SDLTest_TestSuiteReference audioTestSuite;
|
||||
//extern SDLTest_TestSuiteReference clipboardTestSuite;
|
||||
//extern SDLTest_TestSuiteReference eventsTestSuite;
|
||||
//extern SDLTest_TestSuiteReference keyboardTestSuite;
|
||||
extern SDLTest_TestSuiteReference platformTestSuite;
|
||||
extern SDLTest_TestSuiteReference rectTestSuite;
|
||||
//extern SDLTest_TestSuiteReference renderTestSuite;
|
||||
//extern SDLTest_TestSuiteReference rwopsTestSuite;
|
||||
//extern SDLTest_TestSuiteReference surfaceTestSuite;
|
||||
//extern SDLTest_TestSuiteReference syswmTestSuite;
|
||||
//extern SDLTest_TestSuiteReference videoTestSuite;
|
||||
|
||||
// All test suites
|
||||
SDLTest_TestSuiteReference *testSuites[] = {
|
||||
// &audioTestSuite,
|
||||
// &clipboardTestSuite,
|
||||
// &eventsTestSuite,
|
||||
// &keyboardTestSuite,
|
||||
&platformTestSuite,
|
||||
&rectTestSuite,
|
||||
// &renderTestSuite,
|
||||
// &rwopsTestSuite,
|
||||
// &surfaceTestSuite,
|
||||
// &syswmTestSuite,
|
||||
// &videoTestSuite,
|
||||
NULL
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user