Added a README file regarding WinRT support
To note, this file is currently formatted with CRLF line endings, rather than LF, to allow the file to be viewed with Notepad.
8
test/COPYING
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
The test programs in this directory tree are for demonstrating and
|
||||
testing the functionality of the SDL library, and are placed in the
|
||||
public domain.
|
||||
|
||||
October 28, 1997
|
||||
--
|
||||
Sam Lantinga (slouken@libsdl.org)
|
257
test/Makefile.in
Normal file
@@ -0,0 +1,257 @@
|
||||
# Makefile to build the SDL tests
|
||||
|
||||
srcdir = @srcdir@
|
||||
|
||||
CC = @CC@
|
||||
EXE = @EXE@
|
||||
CFLAGS = @CFLAGS@ -g
|
||||
LIBS = @LIBS@
|
||||
|
||||
TARGETS = \
|
||||
checkkeys$(EXE) \
|
||||
loopwave$(EXE) \
|
||||
testaudioinfo$(EXE) \
|
||||
testautomation$(EXE) \
|
||||
testdraw2$(EXE) \
|
||||
testdrawchessboard$(EXE) \
|
||||
testdropfile$(EXE) \
|
||||
testerror$(EXE) \
|
||||
testfile$(EXE) \
|
||||
testgamecontroller$(EXE) \
|
||||
testgesture$(EXE) \
|
||||
testgl2$(EXE) \
|
||||
testgles$(EXE) \
|
||||
testgles2$(EXE) \
|
||||
testhaptic$(EXE) \
|
||||
testrumble$(EXE) \
|
||||
testhotplug$(EXE) \
|
||||
testthread$(EXE) \
|
||||
testiconv$(EXE) \
|
||||
testime$(EXE) \
|
||||
testintersections$(EXE) \
|
||||
testrelative$(EXE) \
|
||||
testjoystick$(EXE) \
|
||||
testkeys$(EXE) \
|
||||
testloadso$(EXE) \
|
||||
testlock$(EXE) \
|
||||
testmultiaudio$(EXE) \
|
||||
testnative$(EXE) \
|
||||
testoverlay2$(EXE) \
|
||||
testplatform$(EXE) \
|
||||
testpower$(EXE) \
|
||||
testfilesystem$(EXE) \
|
||||
testrendertarget$(EXE) \
|
||||
testresample$(EXE) \
|
||||
testscale$(EXE) \
|
||||
testsem$(EXE) \
|
||||
testshader$(EXE) \
|
||||
testshape$(EXE) \
|
||||
testsprite2$(EXE) \
|
||||
testspriteminimal$(EXE) \
|
||||
teststreaming$(EXE) \
|
||||
testtimer$(EXE) \
|
||||
testver$(EXE) \
|
||||
testviewport$(EXE) \
|
||||
testwm2$(EXE) \
|
||||
torturethread$(EXE) \
|
||||
testrendercopyex$(EXE) \
|
||||
testmessage$(EXE) \
|
||||
controllermap$(EXE) \
|
||||
|
||||
all: Makefile $(TARGETS)
|
||||
|
||||
Makefile: $(srcdir)/Makefile.in
|
||||
$(SHELL) config.status $@
|
||||
|
||||
checkkeys$(EXE): $(srcdir)/checkkeys.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
loopwave$(EXE): $(srcdir)/loopwave.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testresample$(EXE): $(srcdir)/testresample.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testaudioinfo$(EXE): $(srcdir)/testaudioinfo.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testautomation$(EXE): $(srcdir)/testautomation.c \
|
||||
$(srcdir)/testautomation_audio.c \
|
||||
$(srcdir)/testautomation_clipboard.c \
|
||||
$(srcdir)/testautomation_events.c \
|
||||
$(srcdir)/testautomation_keyboard.c \
|
||||
$(srcdir)/testautomation_main.c \
|
||||
$(srcdir)/testautomation_mouse.c \
|
||||
$(srcdir)/testautomation_pixels.c \
|
||||
$(srcdir)/testautomation_platform.c \
|
||||
$(srcdir)/testautomation_rect.c \
|
||||
$(srcdir)/testautomation_render.c \
|
||||
$(srcdir)/testautomation_rwops.c \
|
||||
$(srcdir)/testautomation_sdltest.c \
|
||||
$(srcdir)/testautomation_stdlib.c \
|
||||
$(srcdir)/testautomation_surface.c \
|
||||
$(srcdir)/testautomation_syswm.c \
|
||||
$(srcdir)/testautomation_timer.c \
|
||||
$(srcdir)/testautomation_video.c \
|
||||
$(srcdir)/testautomation_hints.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testmultiaudio$(EXE): $(srcdir)/testmultiaudio.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testatomic$(EXE): $(srcdir)/testatomic.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testintersections$(EXE): $(srcdir)/testintersections.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testrelative$(EXE): $(srcdir)/testrelative.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testdraw2$(EXE): $(srcdir)/testdraw2.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testdrawchessboard$(EXE): $(srcdir)/testdrawchessboard.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testdropfile$(EXE): $(srcdir)/testdropfile.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testerror$(EXE): $(srcdir)/testerror.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
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@
|
||||
|
||||
testgl2$(EXE): $(srcdir)/testgl2.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
|
||||
|
||||
testgles$(EXE): $(srcdir)/testgles.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @GLESLIB@ @MATHLIB@
|
||||
|
||||
testgles2$(EXE): $(srcdir)/testgles2.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
|
||||
|
||||
testhaptic$(EXE): $(srcdir)/testhaptic.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testhotplug$(EXE): $(srcdir)/testhotplug.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testrumble$(EXE): $(srcdir)/testrumble.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testthread$(EXE): $(srcdir)/testthread.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testiconv$(EXE): $(srcdir)/testiconv.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testime$(EXE): $(srcdir)/testime.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @SDL_TTF_LIB@
|
||||
|
||||
testjoystick$(EXE): $(srcdir)/testjoystick.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testkeys$(EXE): $(srcdir)/testkeys.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testloadso$(EXE): $(srcdir)/testloadso.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testlock$(EXE): $(srcdir)/testlock.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
ifeq (@ISMACOSX@,true)
|
||||
testnative$(EXE): $(srcdir)/testnative.c \
|
||||
$(srcdir)/testnativecocoa.m \
|
||||
$(srcdir)/testnativex11.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) -framework Cocoa @XLIB@
|
||||
endif
|
||||
|
||||
ifeq (@ISWINDOWS@,true)
|
||||
testnative$(EXE): $(srcdir)/testnative.c \
|
||||
$(srcdir)/testnativew32.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
endif
|
||||
|
||||
ifeq (@ISUNIX@,true)
|
||||
testnative$(EXE): $(srcdir)/testnative.c \
|
||||
$(srcdir)/testnativex11.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @XLIB@
|
||||
endif
|
||||
|
||||
testoverlay2$(EXE): $(srcdir)/testoverlay2.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testplatform$(EXE): $(srcdir)/testplatform.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testpower$(EXE): $(srcdir)/testpower.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testfilesystem$(EXE): $(srcdir)/testfilesystem.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testrendertarget$(EXE): $(srcdir)/testrendertarget.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testscale$(EXE): $(srcdir)/testscale.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testsem$(EXE): $(srcdir)/testsem.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testshader$(EXE): $(srcdir)/testshader.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @GLLIB@ @MATHLIB@
|
||||
|
||||
testshape$(EXE): $(srcdir)/testshape.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testsprite2$(EXE): $(srcdir)/testsprite2.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testspriteminimal$(EXE): $(srcdir)/testspriteminimal.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
|
||||
|
||||
teststreaming$(EXE): $(srcdir)/teststreaming.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
|
||||
|
||||
testtimer$(EXE): $(srcdir)/testtimer.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testver$(EXE): $(srcdir)/testver.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testviewport$(EXE): $(srcdir)/testviewport.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testwm2$(EXE): $(srcdir)/testwm2.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
torturethread$(EXE): $(srcdir)/torturethread.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testrendercopyex$(EXE): $(srcdir)/testrendercopyex.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
|
||||
|
||||
testmessage$(EXE): $(srcdir)/testmessage.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
controllermap$(EXE): $(srcdir)/controllermap.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
|
||||
clean:
|
||||
rm -f $(TARGETS)
|
||||
|
||||
distclean: clean
|
||||
rm -f Makefile
|
||||
rm -f config.status config.cache config.log
|
||||
rm -rf $(srcdir)/autom4te*
|
30
test/README
Normal file
@@ -0,0 +1,30 @@
|
||||
|
||||
These are test programs for the SDL library:
|
||||
|
||||
checkkeys Watch the key events to check the keyboard
|
||||
loopwave Audio test -- loop playing a WAV file
|
||||
testaudioinfo Lists audio device capabilities
|
||||
testcdrom Sample audio CD control program
|
||||
testerror Tests multi-threaded error handling
|
||||
testfile Tests RWops layer
|
||||
testgl2 A very simple example of using OpenGL with SDL
|
||||
testhread Hacked up test of multi-threading
|
||||
testiconv Tests international string conversion
|
||||
testjoystick List joysticks and watch joystick events
|
||||
testkeys List the available keyboard keys
|
||||
testloadso Tests the loadable library layer
|
||||
testlock Hacked up test of multi-threading and locking
|
||||
testmultiaudio Tests using several audio devices
|
||||
testoverlay2 Tests the overlay flickering/scaling during playback.
|
||||
testpalette Tests palette color cycling
|
||||
testplatform Tests types, endianness and cpu capabilities
|
||||
testsem Tests SDL's semaphore implementation
|
||||
testshape Tests shaped windows
|
||||
testsprite2 Example of fast sprite movement on the screen
|
||||
testtimer Test the timer facilities
|
||||
testver Check the version and dynamic loading and endianness
|
||||
testwm2 Test window manager -- title, icon, events
|
||||
torturethread Simple test for thread creation/destruction
|
||||
controllermap Useful to generate Game Controller API compatible maps
|
||||
|
||||
|
359
test/acinclude.m4
Normal file
@@ -0,0 +1,359 @@
|
||||
# Configure paths for SDL
|
||||
# Sam Lantinga 9/21/99
|
||||
# stolen from Manish Singh
|
||||
# stolen back from Frank Belew
|
||||
# stolen from Manish Singh
|
||||
# Shamelessly stolen from Owen Taylor
|
||||
|
||||
# serial 1
|
||||
|
||||
dnl AM_PATH_SDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
|
||||
dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
|
||||
dnl
|
||||
AC_DEFUN([AM_PATH_SDL2],
|
||||
[dnl
|
||||
dnl Get the cflags and libraries from the sdl2-config script
|
||||
dnl
|
||||
AC_ARG_WITH(sdl-prefix,[ --with-sdl-prefix=PFX Prefix where SDL is installed (optional)],
|
||||
sdl_prefix="$withval", sdl_prefix="")
|
||||
AC_ARG_WITH(sdl-exec-prefix,[ --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)],
|
||||
sdl_exec_prefix="$withval", sdl_exec_prefix="")
|
||||
AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run a test SDL program],
|
||||
, enable_sdltest=yes)
|
||||
|
||||
min_sdl_version=ifelse([$1], ,0.9.0,$1)
|
||||
|
||||
if test "x$sdl_prefix$sdl_exec_prefix" = x ; then
|
||||
PKG_CHECK_MODULES([SDL], [sdl2 >= $min_sdl_version],
|
||||
[sdl_pc=yes],
|
||||
[sdl_pc=no])
|
||||
else
|
||||
sdl_pc=no
|
||||
if test x$sdl_exec_prefix != x ; then
|
||||
sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix"
|
||||
if test x${SDL_CONFIG+set} != xset ; then
|
||||
SDL_CONFIG=$sdl_exec_prefix/bin/sdl2-config
|
||||
fi
|
||||
fi
|
||||
if test x$sdl_prefix != x ; then
|
||||
sdl_config_args="$sdl_config_args --prefix=$sdl_prefix"
|
||||
if test x${SDL_CONFIG+set} != xset ; then
|
||||
SDL_CONFIG=$sdl_prefix/bin/sdl2-config
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "x$sdl_pc" = xyes ; then
|
||||
no_sdl=""
|
||||
SDL_CONFIG="pkg-config sdl2"
|
||||
else
|
||||
as_save_PATH="$PATH"
|
||||
if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then
|
||||
PATH="$prefix/bin:$prefix/usr/bin:$PATH"
|
||||
fi
|
||||
AC_PATH_PROG(SDL_CONFIG, sdl2-config, no, [$PATH])
|
||||
PATH="$as_save_PATH"
|
||||
AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
|
||||
no_sdl=""
|
||||
|
||||
if test "$SDL_CONFIG" = "no" ; then
|
||||
no_sdl=yes
|
||||
else
|
||||
SDL_CFLAGS=`$SDL_CONFIG $sdl_config_args --cflags`
|
||||
SDL_LIBS=`$SDL_CONFIG $sdl_config_args --libs`
|
||||
|
||||
sdl_major_version=`$SDL_CONFIG $sdl_config_args --version | \
|
||||
sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
|
||||
sdl_minor_version=`$SDL_CONFIG $sdl_config_args --version | \
|
||||
sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
|
||||
sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \
|
||||
sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
|
||||
if test "x$enable_sdltest" = "xyes" ; then
|
||||
ac_save_CFLAGS="$CFLAGS"
|
||||
ac_save_CXXFLAGS="$CXXFLAGS"
|
||||
ac_save_LIBS="$LIBS"
|
||||
CFLAGS="$CFLAGS $SDL_CFLAGS"
|
||||
CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
|
||||
LIBS="$LIBS $SDL_LIBS"
|
||||
dnl
|
||||
dnl Now check if the installed SDL is sufficiently new. (Also sanity
|
||||
dnl checks the results of sdl2-config to some extent
|
||||
dnl
|
||||
rm -f conf.sdltest
|
||||
AC_TRY_RUN([
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "SDL.h"
|
||||
|
||||
char*
|
||||
my_strdup (char *str)
|
||||
{
|
||||
char *new_str;
|
||||
|
||||
if (str)
|
||||
{
|
||||
new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
|
||||
strcpy (new_str, str);
|
||||
}
|
||||
else
|
||||
new_str = NULL;
|
||||
|
||||
return new_str;
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int major, minor, micro;
|
||||
char *tmp_version;
|
||||
|
||||
/* This hangs on some systems (?)
|
||||
system ("touch conf.sdltest");
|
||||
*/
|
||||
{ FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); }
|
||||
|
||||
/* HP/UX 9 (%@#!) writes to sscanf strings */
|
||||
tmp_version = my_strdup("$min_sdl_version");
|
||||
if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) {
|
||||
printf("%s, bad version string\n", "$min_sdl_version");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (($sdl_major_version > major) ||
|
||||
(($sdl_major_version == major) && ($sdl_minor_version > minor)) ||
|
||||
(($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\n*** 'sdl2-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
|
||||
printf("*** of SDL required is %d.%d.%d. If sdl2-config is correct, then it is\n", major, minor, micro);
|
||||
printf("*** best to upgrade to the required version.\n");
|
||||
printf("*** If sdl2-config was wrong, set the environment variable SDL_CONFIG\n");
|
||||
printf("*** to point to the correct copy of sdl2-config, and remove the file\n");
|
||||
printf("*** config.cache before re-running configure\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
|
||||
CFLAGS="$ac_save_CFLAGS"
|
||||
CXXFLAGS="$ac_save_CXXFLAGS"
|
||||
LIBS="$ac_save_LIBS"
|
||||
fi
|
||||
fi
|
||||
if test "x$no_sdl" = x ; then
|
||||
AC_MSG_RESULT(yes)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
fi
|
||||
if test "x$no_sdl" = x ; then
|
||||
ifelse([$2], , :, [$2])
|
||||
else
|
||||
if test "$SDL_CONFIG" = "no" ; then
|
||||
echo "*** The sdl2-config script installed by SDL could not be found"
|
||||
echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in"
|
||||
echo "*** your path, or set the SDL_CONFIG environment variable to the"
|
||||
echo "*** full path to sdl2-config."
|
||||
else
|
||||
if test -f conf.sdltest ; then
|
||||
:
|
||||
else
|
||||
echo "*** Could not run SDL test program, checking why..."
|
||||
CFLAGS="$CFLAGS $SDL_CFLAGS"
|
||||
CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
|
||||
LIBS="$LIBS $SDL_LIBS"
|
||||
AC_TRY_LINK([
|
||||
#include <stdio.h>
|
||||
#include "SDL.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{ return 0; }
|
||||
#undef main
|
||||
#define main K_and_R_C_main
|
||||
], [ return 0; ],
|
||||
[ echo "*** The test program compiled, but did not run. This usually means"
|
||||
echo "*** that the run-time linker is not finding SDL or finding the wrong"
|
||||
echo "*** version of SDL. If it is not finding SDL, you'll need to set your"
|
||||
echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
|
||||
echo "*** to the installed location Also, make sure you have run ldconfig if that"
|
||||
echo "*** is required on your system"
|
||||
echo "***"
|
||||
echo "*** If you have an old version installed, it is best to remove it, although"
|
||||
echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
|
||||
[ echo "*** The test program failed to compile or link. See the file config.log for the"
|
||||
echo "*** exact error that occured. This usually means SDL was incorrectly installed"
|
||||
echo "*** or that you have moved SDL since it was installed. In the latter case, you"
|
||||
echo "*** may want to edit the sdl2-config script: $SDL_CONFIG" ])
|
||||
CFLAGS="$ac_save_CFLAGS"
|
||||
CXXFLAGS="$ac_save_CXXFLAGS"
|
||||
LIBS="$ac_save_LIBS"
|
||||
fi
|
||||
fi
|
||||
SDL_CFLAGS=""
|
||||
SDL_LIBS=""
|
||||
ifelse([$3], , :, [$3])
|
||||
fi
|
||||
AC_SUBST(SDL_CFLAGS)
|
||||
AC_SUBST(SDL_LIBS)
|
||||
rm -f conf.sdltest
|
||||
])
|
||||
# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
|
||||
# serial 1 (pkg-config-0.24)
|
||||
#
|
||||
# Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# As a special exception to the GNU General Public License, if you
|
||||
# distribute this file as part of a program that contains a
|
||||
# configuration script generated by Autoconf, you may include it under
|
||||
# the same distribution terms that you use for the rest of that program.
|
||||
|
||||
# PKG_PROG_PKG_CONFIG([MIN-VERSION])
|
||||
# ----------------------------------
|
||||
AC_DEFUN([PKG_PROG_PKG_CONFIG],
|
||||
[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
|
||||
m4_pattern_allow([^PKG_CONFIG(_PATH)?$])
|
||||
AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
|
||||
AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
|
||||
AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
|
||||
|
||||
if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
|
||||
AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
|
||||
fi
|
||||
if test -n "$PKG_CONFIG"; then
|
||||
_pkg_min_version=m4_default([$1], [0.9.0])
|
||||
AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
|
||||
if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
|
||||
AC_MSG_RESULT([yes])
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
PKG_CONFIG=""
|
||||
fi
|
||||
fi[]dnl
|
||||
])# PKG_PROG_PKG_CONFIG
|
||||
|
||||
# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
|
||||
#
|
||||
# Check to see whether a particular set of modules exists. Similar
|
||||
# to PKG_CHECK_MODULES(), but does not set variables or print errors.
|
||||
#
|
||||
# Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
|
||||
# only at the first occurence in configure.ac, so if the first place
|
||||
# it's called might be skipped (such as if it is within an "if", you
|
||||
# have to call PKG_CHECK_EXISTS manually
|
||||
# --------------------------------------------------------------
|
||||
AC_DEFUN([PKG_CHECK_EXISTS],
|
||||
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
|
||||
if test -n "$PKG_CONFIG" && \
|
||||
AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
|
||||
m4_default([$2], [:])
|
||||
m4_ifvaln([$3], [else
|
||||
$3])dnl
|
||||
fi])
|
||||
|
||||
# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
|
||||
# ---------------------------------------------
|
||||
m4_define([_PKG_CONFIG],
|
||||
[if test -n "$$1"; then
|
||||
pkg_cv_[]$1="$$1"
|
||||
elif test -n "$PKG_CONFIG"; then
|
||||
PKG_CHECK_EXISTS([$3],
|
||||
[pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`],
|
||||
[pkg_failed=yes])
|
||||
else
|
||||
pkg_failed=untried
|
||||
fi[]dnl
|
||||
])# _PKG_CONFIG
|
||||
|
||||
# _PKG_SHORT_ERRORS_SUPPORTED
|
||||
# -----------------------------
|
||||
AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
|
||||
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])
|
||||
if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
|
||||
_pkg_short_errors_supported=yes
|
||||
else
|
||||
_pkg_short_errors_supported=no
|
||||
fi[]dnl
|
||||
])# _PKG_SHORT_ERRORS_SUPPORTED
|
||||
|
||||
|
||||
# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
|
||||
# [ACTION-IF-NOT-FOUND])
|
||||
#
|
||||
#
|
||||
# Note that if there is a possibility the first call to
|
||||
# PKG_CHECK_MODULES might not happen, you should be sure to include an
|
||||
# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
|
||||
#
|
||||
#
|
||||
# --------------------------------------------------------------
|
||||
AC_DEFUN([PKG_CHECK_MODULES],
|
||||
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
|
||||
AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
|
||||
AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
|
||||
|
||||
pkg_failed=no
|
||||
AC_MSG_CHECKING([for $1])
|
||||
|
||||
_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
|
||||
_PKG_CONFIG([$1][_LIBS], [libs], [$2])
|
||||
|
||||
m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
|
||||
and $1[]_LIBS to avoid the need to call pkg-config.
|
||||
See the pkg-config man page for more details.])
|
||||
|
||||
if test $pkg_failed = yes; then
|
||||
AC_MSG_RESULT([no])
|
||||
_PKG_SHORT_ERRORS_SUPPORTED
|
||||
if test $_pkg_short_errors_supported = yes; then
|
||||
$1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "$2" 2>&1`
|
||||
else
|
||||
$1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors "$2" 2>&1`
|
||||
fi
|
||||
# Put the nasty error message in config.log where it belongs
|
||||
echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
|
||||
|
||||
m4_default([$4], [AC_MSG_ERROR(
|
||||
[Package requirements ($2) were not met:
|
||||
|
||||
$$1_PKG_ERRORS
|
||||
|
||||
Consider adjusting the PKG_CONFIG_PATH environment variable if you
|
||||
installed software in a non-standard prefix.
|
||||
|
||||
_PKG_TEXT])dnl
|
||||
])
|
||||
elif test $pkg_failed = untried; then
|
||||
AC_MSG_RESULT([no])
|
||||
m4_default([$4], [AC_MSG_FAILURE(
|
||||
[The pkg-config script could not be found or is too old. Make sure it
|
||||
is in your PATH or set the PKG_CONFIG environment variable to the full
|
||||
path to pkg-config.
|
||||
|
||||
_PKG_TEXT
|
||||
|
||||
To get pkg-config, see <http://pkg-config.freedesktop.org/>.])dnl
|
||||
])
|
||||
else
|
||||
$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
|
||||
$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
|
||||
AC_MSG_RESULT([yes])
|
||||
$3
|
||||
fi[]dnl
|
||||
])# PKG_CHECK_MODULES
|
359
test/aclocal.m4
vendored
Normal file
@@ -0,0 +1,359 @@
|
||||
# Configure paths for SDL
|
||||
# Sam Lantinga 9/21/99
|
||||
# stolen from Manish Singh
|
||||
# stolen back from Frank Belew
|
||||
# stolen from Manish Singh
|
||||
# Shamelessly stolen from Owen Taylor
|
||||
|
||||
# serial 1
|
||||
|
||||
dnl AM_PATH_SDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
|
||||
dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
|
||||
dnl
|
||||
AC_DEFUN([AM_PATH_SDL2],
|
||||
[dnl
|
||||
dnl Get the cflags and libraries from the sdl2-config script
|
||||
dnl
|
||||
AC_ARG_WITH(sdl-prefix,[ --with-sdl-prefix=PFX Prefix where SDL is installed (optional)],
|
||||
sdl_prefix="$withval", sdl_prefix="")
|
||||
AC_ARG_WITH(sdl-exec-prefix,[ --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)],
|
||||
sdl_exec_prefix="$withval", sdl_exec_prefix="")
|
||||
AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run a test SDL program],
|
||||
, enable_sdltest=yes)
|
||||
|
||||
min_sdl_version=ifelse([$1], ,0.9.0,$1)
|
||||
|
||||
if test "x$sdl_prefix$sdl_exec_prefix" = x ; then
|
||||
PKG_CHECK_MODULES([SDL], [sdl2 >= $min_sdl_version],
|
||||
[sdl_pc=yes],
|
||||
[sdl_pc=no])
|
||||
else
|
||||
sdl_pc=no
|
||||
if test x$sdl_exec_prefix != x ; then
|
||||
sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix"
|
||||
if test x${SDL_CONFIG+set} != xset ; then
|
||||
SDL_CONFIG=$sdl_exec_prefix/bin/sdl2-config
|
||||
fi
|
||||
fi
|
||||
if test x$sdl_prefix != x ; then
|
||||
sdl_config_args="$sdl_config_args --prefix=$sdl_prefix"
|
||||
if test x${SDL_CONFIG+set} != xset ; then
|
||||
SDL_CONFIG=$sdl_prefix/bin/sdl2-config
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "x$sdl_pc" = xyes ; then
|
||||
no_sdl=""
|
||||
SDL_CONFIG="pkg-config sdl2"
|
||||
else
|
||||
as_save_PATH="$PATH"
|
||||
if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then
|
||||
PATH="$prefix/bin:$prefix/usr/bin:$PATH"
|
||||
fi
|
||||
AC_PATH_PROG(SDL_CONFIG, sdl2-config, no, [$PATH])
|
||||
PATH="$as_save_PATH"
|
||||
AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
|
||||
no_sdl=""
|
||||
|
||||
if test "$SDL_CONFIG" = "no" ; then
|
||||
no_sdl=yes
|
||||
else
|
||||
SDL_CFLAGS=`$SDL_CONFIG $sdl_config_args --cflags`
|
||||
SDL_LIBS=`$SDL_CONFIG $sdl_config_args --libs`
|
||||
|
||||
sdl_major_version=`$SDL_CONFIG $sdl_config_args --version | \
|
||||
sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
|
||||
sdl_minor_version=`$SDL_CONFIG $sdl_config_args --version | \
|
||||
sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
|
||||
sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \
|
||||
sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
|
||||
if test "x$enable_sdltest" = "xyes" ; then
|
||||
ac_save_CFLAGS="$CFLAGS"
|
||||
ac_save_CXXFLAGS="$CXXFLAGS"
|
||||
ac_save_LIBS="$LIBS"
|
||||
CFLAGS="$CFLAGS $SDL_CFLAGS"
|
||||
CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
|
||||
LIBS="$LIBS $SDL_LIBS"
|
||||
dnl
|
||||
dnl Now check if the installed SDL is sufficiently new. (Also sanity
|
||||
dnl checks the results of sdl2-config to some extent
|
||||
dnl
|
||||
rm -f conf.sdltest
|
||||
AC_TRY_RUN([
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "SDL.h"
|
||||
|
||||
char*
|
||||
my_strdup (char *str)
|
||||
{
|
||||
char *new_str;
|
||||
|
||||
if (str)
|
||||
{
|
||||
new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
|
||||
strcpy (new_str, str);
|
||||
}
|
||||
else
|
||||
new_str = NULL;
|
||||
|
||||
return new_str;
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int major, minor, micro;
|
||||
char *tmp_version;
|
||||
|
||||
/* This hangs on some systems (?)
|
||||
system ("touch conf.sdltest");
|
||||
*/
|
||||
{ FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); }
|
||||
|
||||
/* HP/UX 9 (%@#!) writes to sscanf strings */
|
||||
tmp_version = my_strdup("$min_sdl_version");
|
||||
if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) {
|
||||
printf("%s, bad version string\n", "$min_sdl_version");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (($sdl_major_version > major) ||
|
||||
(($sdl_major_version == major) && ($sdl_minor_version > minor)) ||
|
||||
(($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\n*** 'sdl2-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
|
||||
printf("*** of SDL required is %d.%d.%d. If sdl2-config is correct, then it is\n", major, minor, micro);
|
||||
printf("*** best to upgrade to the required version.\n");
|
||||
printf("*** If sdl2-config was wrong, set the environment variable SDL_CONFIG\n");
|
||||
printf("*** to point to the correct copy of sdl2-config, and remove the file\n");
|
||||
printf("*** config.cache before re-running configure\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
|
||||
CFLAGS="$ac_save_CFLAGS"
|
||||
CXXFLAGS="$ac_save_CXXFLAGS"
|
||||
LIBS="$ac_save_LIBS"
|
||||
fi
|
||||
fi
|
||||
if test "x$no_sdl" = x ; then
|
||||
AC_MSG_RESULT(yes)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
fi
|
||||
if test "x$no_sdl" = x ; then
|
||||
ifelse([$2], , :, [$2])
|
||||
else
|
||||
if test "$SDL_CONFIG" = "no" ; then
|
||||
echo "*** The sdl2-config script installed by SDL could not be found"
|
||||
echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in"
|
||||
echo "*** your path, or set the SDL_CONFIG environment variable to the"
|
||||
echo "*** full path to sdl2-config."
|
||||
else
|
||||
if test -f conf.sdltest ; then
|
||||
:
|
||||
else
|
||||
echo "*** Could not run SDL test program, checking why..."
|
||||
CFLAGS="$CFLAGS $SDL_CFLAGS"
|
||||
CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
|
||||
LIBS="$LIBS $SDL_LIBS"
|
||||
AC_TRY_LINK([
|
||||
#include <stdio.h>
|
||||
#include "SDL.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{ return 0; }
|
||||
#undef main
|
||||
#define main K_and_R_C_main
|
||||
], [ return 0; ],
|
||||
[ echo "*** The test program compiled, but did not run. This usually means"
|
||||
echo "*** that the run-time linker is not finding SDL or finding the wrong"
|
||||
echo "*** version of SDL. If it is not finding SDL, you'll need to set your"
|
||||
echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
|
||||
echo "*** to the installed location Also, make sure you have run ldconfig if that"
|
||||
echo "*** is required on your system"
|
||||
echo "***"
|
||||
echo "*** If you have an old version installed, it is best to remove it, although"
|
||||
echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
|
||||
[ echo "*** The test program failed to compile or link. See the file config.log for the"
|
||||
echo "*** exact error that occured. This usually means SDL was incorrectly installed"
|
||||
echo "*** or that you have moved SDL since it was installed. In the latter case, you"
|
||||
echo "*** may want to edit the sdl2-config script: $SDL_CONFIG" ])
|
||||
CFLAGS="$ac_save_CFLAGS"
|
||||
CXXFLAGS="$ac_save_CXXFLAGS"
|
||||
LIBS="$ac_save_LIBS"
|
||||
fi
|
||||
fi
|
||||
SDL_CFLAGS=""
|
||||
SDL_LIBS=""
|
||||
ifelse([$3], , :, [$3])
|
||||
fi
|
||||
AC_SUBST(SDL_CFLAGS)
|
||||
AC_SUBST(SDL_LIBS)
|
||||
rm -f conf.sdltest
|
||||
])
|
||||
# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
|
||||
# serial 1 (pkg-config-0.24)
|
||||
#
|
||||
# Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# As a special exception to the GNU General Public License, if you
|
||||
# distribute this file as part of a program that contains a
|
||||
# configuration script generated by Autoconf, you may include it under
|
||||
# the same distribution terms that you use for the rest of that program.
|
||||
|
||||
# PKG_PROG_PKG_CONFIG([MIN-VERSION])
|
||||
# ----------------------------------
|
||||
AC_DEFUN([PKG_PROG_PKG_CONFIG],
|
||||
[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
|
||||
m4_pattern_allow([^PKG_CONFIG(_PATH)?$])
|
||||
AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
|
||||
AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
|
||||
AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
|
||||
|
||||
if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
|
||||
AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
|
||||
fi
|
||||
if test -n "$PKG_CONFIG"; then
|
||||
_pkg_min_version=m4_default([$1], [0.9.0])
|
||||
AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
|
||||
if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
|
||||
AC_MSG_RESULT([yes])
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
PKG_CONFIG=""
|
||||
fi
|
||||
fi[]dnl
|
||||
])# PKG_PROG_PKG_CONFIG
|
||||
|
||||
# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
|
||||
#
|
||||
# Check to see whether a particular set of modules exists. Similar
|
||||
# to PKG_CHECK_MODULES(), but does not set variables or print errors.
|
||||
#
|
||||
# Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
|
||||
# only at the first occurence in configure.ac, so if the first place
|
||||
# it's called might be skipped (such as if it is within an "if", you
|
||||
# have to call PKG_CHECK_EXISTS manually
|
||||
# --------------------------------------------------------------
|
||||
AC_DEFUN([PKG_CHECK_EXISTS],
|
||||
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
|
||||
if test -n "$PKG_CONFIG" && \
|
||||
AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
|
||||
m4_default([$2], [:])
|
||||
m4_ifvaln([$3], [else
|
||||
$3])dnl
|
||||
fi])
|
||||
|
||||
# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
|
||||
# ---------------------------------------------
|
||||
m4_define([_PKG_CONFIG],
|
||||
[if test -n "$$1"; then
|
||||
pkg_cv_[]$1="$$1"
|
||||
elif test -n "$PKG_CONFIG"; then
|
||||
PKG_CHECK_EXISTS([$3],
|
||||
[pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`],
|
||||
[pkg_failed=yes])
|
||||
else
|
||||
pkg_failed=untried
|
||||
fi[]dnl
|
||||
])# _PKG_CONFIG
|
||||
|
||||
# _PKG_SHORT_ERRORS_SUPPORTED
|
||||
# -----------------------------
|
||||
AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
|
||||
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])
|
||||
if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
|
||||
_pkg_short_errors_supported=yes
|
||||
else
|
||||
_pkg_short_errors_supported=no
|
||||
fi[]dnl
|
||||
])# _PKG_SHORT_ERRORS_SUPPORTED
|
||||
|
||||
|
||||
# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
|
||||
# [ACTION-IF-NOT-FOUND])
|
||||
#
|
||||
#
|
||||
# Note that if there is a possibility the first call to
|
||||
# PKG_CHECK_MODULES might not happen, you should be sure to include an
|
||||
# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
|
||||
#
|
||||
#
|
||||
# --------------------------------------------------------------
|
||||
AC_DEFUN([PKG_CHECK_MODULES],
|
||||
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
|
||||
AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
|
||||
AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
|
||||
|
||||
pkg_failed=no
|
||||
AC_MSG_CHECKING([for $1])
|
||||
|
||||
_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
|
||||
_PKG_CONFIG([$1][_LIBS], [libs], [$2])
|
||||
|
||||
m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
|
||||
and $1[]_LIBS to avoid the need to call pkg-config.
|
||||
See the pkg-config man page for more details.])
|
||||
|
||||
if test $pkg_failed = yes; then
|
||||
AC_MSG_RESULT([no])
|
||||
_PKG_SHORT_ERRORS_SUPPORTED
|
||||
if test $_pkg_short_errors_supported = yes; then
|
||||
$1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "$2" 2>&1`
|
||||
else
|
||||
$1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors "$2" 2>&1`
|
||||
fi
|
||||
# Put the nasty error message in config.log where it belongs
|
||||
echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
|
||||
|
||||
m4_default([$4], [AC_MSG_ERROR(
|
||||
[Package requirements ($2) were not met:
|
||||
|
||||
$$1_PKG_ERRORS
|
||||
|
||||
Consider adjusting the PKG_CONFIG_PATH environment variable if you
|
||||
installed software in a non-standard prefix.
|
||||
|
||||
_PKG_TEXT])dnl
|
||||
])
|
||||
elif test $pkg_failed = untried; then
|
||||
AC_MSG_RESULT([no])
|
||||
m4_default([$4], [AC_MSG_FAILURE(
|
||||
[The pkg-config script could not be found or is too old. Make sure it
|
||||
is in your PATH or set the PKG_CONFIG environment variable to the full
|
||||
path to pkg-config.
|
||||
|
||||
_PKG_TEXT
|
||||
|
||||
To get pkg-config, see <http://pkg-config.freedesktop.org/>.])dnl
|
||||
])
|
||||
else
|
||||
$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
|
||||
$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
|
||||
AC_MSG_RESULT([yes])
|
||||
$3
|
||||
fi[]dnl
|
||||
])# PKG_CHECK_MODULES
|
12
test/autogen.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Regenerate configuration files
|
||||
cp acinclude.m4 aclocal.m4
|
||||
found=false
|
||||
for autoconf in autoconf autoconf259 autoconf-2.59
|
||||
do if which $autoconf >/dev/null 2>&1; then $autoconf && found=true; break; fi
|
||||
done
|
||||
if test x$found = xfalse; then
|
||||
echo "Couldn't find autoconf, aborting"
|
||||
exit 1
|
||||
fi
|
BIN
test/axis.bmp
Normal file
After Width: | Height: | Size: 3.7 KiB |
BIN
test/button.bmp
Normal file
After Width: | Height: | Size: 3.7 KiB |
191
test/checkkeys.c
Normal file
@@ -0,0 +1,191 @@
|
||||
/*
|
||||
Copyright (C) 1997-2014 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: Loop, watching keystrokes
|
||||
Note that you need to call SDL_PollEvent() or SDL_WaitEvent() to
|
||||
pump the event loop and catch keystrokes.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
{
|
||||
SDL_Quit();
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
static void
|
||||
print_string(char **text, size_t *maxlen, const char *fmt, ...)
|
||||
{
|
||||
int len;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
len = SDL_vsnprintf(*text, *maxlen, fmt, ap);
|
||||
if (len > 0) {
|
||||
*text += len;
|
||||
if ( ((size_t) len) < *maxlen ) {
|
||||
*maxlen -= (size_t) len;
|
||||
} else {
|
||||
*maxlen = 0;
|
||||
}
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
static void
|
||||
print_modifiers(char **text, size_t *maxlen)
|
||||
{
|
||||
int mod;
|
||||
print_string(text, maxlen, " modifiers:");
|
||||
mod = SDL_GetModState();
|
||||
if (!mod) {
|
||||
print_string(text, maxlen, " (none)");
|
||||
return;
|
||||
}
|
||||
if (mod & KMOD_LSHIFT)
|
||||
print_string(text, maxlen, " LSHIFT");
|
||||
if (mod & KMOD_RSHIFT)
|
||||
print_string(text, maxlen, " RSHIFT");
|
||||
if (mod & KMOD_LCTRL)
|
||||
print_string(text, maxlen, " LCTRL");
|
||||
if (mod & KMOD_RCTRL)
|
||||
print_string(text, maxlen, " RCTRL");
|
||||
if (mod & KMOD_LALT)
|
||||
print_string(text, maxlen, " LALT");
|
||||
if (mod & KMOD_RALT)
|
||||
print_string(text, maxlen, " RALT");
|
||||
if (mod & KMOD_LGUI)
|
||||
print_string(text, maxlen, " LGUI");
|
||||
if (mod & KMOD_RGUI)
|
||||
print_string(text, maxlen, " RGUI");
|
||||
if (mod & KMOD_NUM)
|
||||
print_string(text, maxlen, " NUM");
|
||||
if (mod & KMOD_CAPS)
|
||||
print_string(text, maxlen, " CAPS");
|
||||
if (mod & KMOD_MODE)
|
||||
print_string(text, maxlen, " MODE");
|
||||
}
|
||||
|
||||
static void
|
||||
PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat)
|
||||
{
|
||||
char message[512];
|
||||
char *spot;
|
||||
size_t left;
|
||||
|
||||
spot = message;
|
||||
left = sizeof(message);
|
||||
|
||||
/* 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));
|
||||
} else {
|
||||
print_string(&spot, &left,
|
||||
"Unknown Key (scancode %d = %s) %s ",
|
||||
sym->scancode,
|
||||
SDL_GetScancodeName(sym->scancode),
|
||||
pressed ? "pressed " : "released");
|
||||
}
|
||||
print_modifiers(&spot, &left);
|
||||
if (repeat) {
|
||||
print_string(&spot, &left, " (repeat)");
|
||||
}
|
||||
SDL_Log("%s\n", message);
|
||||
}
|
||||
|
||||
static void
|
||||
PrintText(char *text)
|
||||
{
|
||||
char *spot, expanded[1024];
|
||||
|
||||
expanded[0] = '\0';
|
||||
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("Text (%s): \"%s%s\"\n", expanded, *text == '"' ? "\\" : "", text);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Window *window;
|
||||
SDL_Event event;
|
||||
int done;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Initialize SDL */
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Set 640x480 video mode */
|
||||
window = SDL_CreateWindow("CheckKeys Test",
|
||||
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||
640, 480, 0);
|
||||
if (!window) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create 640x480 window: %s\n",
|
||||
SDL_GetError());
|
||||
quit(2);
|
||||
}
|
||||
|
||||
#if __IPHONEOS__
|
||||
/* Creating the context creates the view, which we need to show keyboard */
|
||||
SDL_GL_CreateContext(window);
|
||||
#endif
|
||||
|
||||
SDL_StartTextInput();
|
||||
|
||||
/* Watch keystrokes */
|
||||
done = 0;
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
SDL_WaitEvent(&event);
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
PrintKey(&event.key.keysym, (event.key.state == SDL_PRESSED) ? SDL_TRUE : SDL_FALSE, (event.key.repeat) ? SDL_TRUE : SDL_FALSE);
|
||||
break;
|
||||
case SDL_TEXTINPUT:
|
||||
PrintText(event.text.text);
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
/* Any button press quits the app... */
|
||||
case SDL_QUIT:
|
||||
done = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
5119
test/configure
vendored
Executable file
185
test/configure.in
Normal file
@@ -0,0 +1,185 @@
|
||||
dnl Process this file with autoconf to produce a configure script.
|
||||
AC_INIT(README)
|
||||
|
||||
dnl Detect the canonical build and host environments
|
||||
AC_CONFIG_AUX_DIRS($srcdir/../build-scripts)
|
||||
AC_CANONICAL_HOST
|
||||
|
||||
dnl Check for tools
|
||||
|
||||
AC_PROG_CC
|
||||
|
||||
dnl Check for compiler environment
|
||||
|
||||
AC_C_CONST
|
||||
|
||||
dnl We only care about this for building testnative at the moment, so these
|
||||
dnl values shouldn't be considered absolute truth.
|
||||
dnl (Haiku, for example, sets none of these.)
|
||||
ISUNIX="false"
|
||||
ISWINDOWS="false"
|
||||
ISMACOSX="false"
|
||||
|
||||
dnl Figure out which math library to use
|
||||
case "$host" in
|
||||
*-*-cygwin* | *-*-mingw32*)
|
||||
ISWINDOWS="true"
|
||||
EXE=".exe"
|
||||
MATHLIB=""
|
||||
SYS_GL_LIBS="-lopengl32"
|
||||
;;
|
||||
*-*-haiku*)
|
||||
EXE=""
|
||||
MATHLIB=""
|
||||
SYS_GL_LIBS="-lGL"
|
||||
;;
|
||||
*-*-darwin* )
|
||||
ISMACOSX="true"
|
||||
EXE=""
|
||||
MATHLIB=""
|
||||
SYS_GL_LIBS="-Wl,-framework,OpenGL"
|
||||
;;
|
||||
*-*-aix*)
|
||||
ISUNIX="true"
|
||||
EXE=""
|
||||
if test x$ac_cv_prog_gcc = xyes; then
|
||||
CFLAGS="-mthreads"
|
||||
fi
|
||||
SYS_GL_LIBS=""
|
||||
;;
|
||||
*-*-mint*)
|
||||
EXE=""
|
||||
MATHLIB=""
|
||||
AC_PATH_PROG(OSMESA_CONFIG, osmesa-config, no)
|
||||
if test "x$OSMESA_CONFIG" = "xyes"; then
|
||||
OSMESA_CFLAGS=`$OSMESA_CONFIG --cflags`
|
||||
OSMESA_LIBS=`$OSMESA_CONFIG --libs`
|
||||
CFLAGS="$CFLAGS $OSMESA_CFLAGS"
|
||||
SYS_GL_LIBS="$OSMESA_LIBS"
|
||||
else
|
||||
SYS_GL_LIBS="-lOSMesa"
|
||||
fi
|
||||
;;
|
||||
*-*-qnx*)
|
||||
EXE=""
|
||||
MATHLIB=""
|
||||
SYS_GL_LIBS="-lGLES_CM"
|
||||
;;
|
||||
*)
|
||||
dnl Oh well, call it Unix...
|
||||
ISUNIX="true"
|
||||
EXE=""
|
||||
MATHLIB="-lm"
|
||||
SYS_GL_LIBS="-lGL"
|
||||
;;
|
||||
esac
|
||||
AC_SUBST(EXE)
|
||||
AC_SUBST(MATHLIB)
|
||||
AC_SUBST(ISMACOSX)
|
||||
AC_SUBST(ISWINDOWS)
|
||||
AC_SUBST(ISUNIX)
|
||||
|
||||
dnl Check for SDL
|
||||
SDL_VERSION=2.0.0
|
||||
AM_PATH_SDL2($SDL_VERSION,
|
||||
:,
|
||||
AC_MSG_ERROR([*** SDL version $SDL_VERSION not found!])
|
||||
)
|
||||
CFLAGS="$CFLAGS $SDL_CFLAGS"
|
||||
LIBS="$LIBS -lSDL2_test $SDL_LIBS"
|
||||
|
||||
dnl Check for X11 path, needed for OpenGL on some systems
|
||||
AC_PATH_X
|
||||
if test x$have_x = xyes; then
|
||||
if test x$ac_x_includes = xno || test "x$ac_x_includes" = xNone || test "x$ac_x_includes" = x; then
|
||||
:
|
||||
else
|
||||
CFLAGS="$CFLAGS -I$ac_x_includes"
|
||||
fi
|
||||
if test x$ac_x_libraries = xno || test "x$ac_x_libraries" = xNone; then
|
||||
:
|
||||
else
|
||||
if test "x$ac_x_libraries" = x; then
|
||||
XPATH=""
|
||||
XLIB="-lX11"
|
||||
else
|
||||
XPATH="-L$ac_x_libraries"
|
||||
XLIB="-L$ac_x_libraries -lX11"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
dnl Check for OpenGL
|
||||
AC_MSG_CHECKING(for OpenGL support)
|
||||
have_opengl=no
|
||||
AC_TRY_COMPILE([
|
||||
#include "SDL_opengl.h"
|
||||
],[
|
||||
],[
|
||||
have_opengl=yes
|
||||
])
|
||||
AC_MSG_RESULT($have_opengl)
|
||||
|
||||
dnl Check for OpenGL ES
|
||||
AC_MSG_CHECKING(for OpenGL ES support)
|
||||
have_opengles=no
|
||||
AC_TRY_COMPILE([
|
||||
#if defined (__IPHONEOS__)
|
||||
#include <OpenGLES/ES1/gl.h>
|
||||
#else
|
||||
#include <GLES/gl.h>
|
||||
#endif /* __QNXNTO__ */
|
||||
],[
|
||||
],[
|
||||
have_opengles=yes
|
||||
])
|
||||
AC_MSG_RESULT($have_opengles)
|
||||
|
||||
dnl Check for OpenGL ES2
|
||||
AC_MSG_CHECKING(for OpenGL ES2 support)
|
||||
have_opengles2=no
|
||||
AC_TRY_COMPILE([
|
||||
#if defined (__IPHONEOS__)
|
||||
#include <OpenGLES/ES2/gl.h>
|
||||
#include <OpenGLES/ES2/glext.h>
|
||||
#else
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
#endif
|
||||
],[
|
||||
],[
|
||||
have_opengles2=yes
|
||||
])
|
||||
AC_MSG_RESULT($have_opengles2)
|
||||
|
||||
GLLIB=""
|
||||
GLESLIB=""
|
||||
GLES2LIB=""
|
||||
if test x$have_opengles = xyes; then
|
||||
CFLAGS="$CFLAGS -DHAVE_OPENGLES"
|
||||
GLESLIB="$XPATH -lGLESv1_CM"
|
||||
fi
|
||||
if test x$have_opengles2 = xyes; then
|
||||
CFLAGS="$CFLAGS -DHAVE_OPENGLES2"
|
||||
#GLES2LIB="$XPATH -lGLESv2"
|
||||
fi
|
||||
if test x$have_opengl = xyes; then
|
||||
CFLAGS="$CFLAGS -DHAVE_OPENGL"
|
||||
GLLIB="$XPATH $SYS_GL_LIBS"
|
||||
fi
|
||||
|
||||
AC_SUBST(GLLIB)
|
||||
AC_SUBST(GLESLIB)
|
||||
AC_SUBST(GLES2LIB)
|
||||
AC_SUBST(XLIB)
|
||||
|
||||
dnl Check for SDL_ttf
|
||||
AC_CHECK_LIB(SDL2_ttf, TTF_Init, have_SDL_ttf=yes)
|
||||
if test x$have_SDL_ttf = xyes; then
|
||||
CFLAGS="$CFLAGS -DHAVE_SDL_TTF"
|
||||
SDL_TTF_LIB="-lSDL2_ttf"
|
||||
fi
|
||||
AC_SUBST(SDL_TTF_LIB)
|
||||
|
||||
dnl Finally create all the generated files
|
||||
AC_OUTPUT([Makefile])
|
BIN
test/controllermap.bmp
Normal file
After Width: | Height: | Size: 160 KiB |
441
test/controllermap.c
Normal file
@@ -0,0 +1,441 @@
|
||||
/*
|
||||
Copyright (C) 1997-2014 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.
|
||||
*/
|
||||
|
||||
/* Game controller mapping generator */
|
||||
/* Gabriel Jacobo <gabomdq@gmail.com> */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#ifndef SDL_JOYSTICK_DISABLED
|
||||
|
||||
#ifdef __IPHONEOS__
|
||||
#define SCREEN_WIDTH 320
|
||||
#define SCREEN_HEIGHT 480
|
||||
#else
|
||||
#define SCREEN_WIDTH 512
|
||||
#define SCREEN_HEIGHT 317
|
||||
#endif
|
||||
|
||||
#define MAP_WIDTH 512
|
||||
#define MAP_HEIGHT 317
|
||||
|
||||
#define MARKER_BUTTON 1
|
||||
#define MARKER_AXIS 2
|
||||
|
||||
typedef struct MappingStep
|
||||
{
|
||||
int x, y;
|
||||
double angle;
|
||||
int marker;
|
||||
char *field;
|
||||
int axis, button, hat, hat_value;
|
||||
char mapping[4096];
|
||||
}MappingStep;
|
||||
|
||||
|
||||
SDL_Texture *
|
||||
LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
|
||||
{
|
||||
SDL_Surface *temp;
|
||||
SDL_Texture *texture;
|
||||
|
||||
/* Load the sprite image */
|
||||
temp = SDL_LoadBMP(file);
|
||||
if (temp == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Set transparent pixel as the pixel at (0,0) */
|
||||
if (transparent) {
|
||||
if (temp->format->palette) {
|
||||
SDL_SetColorKey(temp, SDL_TRUE, *(Uint8 *) temp->pixels);
|
||||
} else {
|
||||
switch (temp->format->BitsPerPixel) {
|
||||
case 15:
|
||||
SDL_SetColorKey(temp, SDL_TRUE,
|
||||
(*(Uint16 *) temp->pixels) & 0x00007FFF);
|
||||
break;
|
||||
case 16:
|
||||
SDL_SetColorKey(temp, SDL_TRUE, *(Uint16 *) temp->pixels);
|
||||
break;
|
||||
case 24:
|
||||
SDL_SetColorKey(temp, SDL_TRUE,
|
||||
(*(Uint32 *) temp->pixels) & 0x00FFFFFF);
|
||||
break;
|
||||
case 32:
|
||||
SDL_SetColorKey(temp, SDL_TRUE, *(Uint32 *) temp->pixels);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Create textures from the image */
|
||||
texture = SDL_CreateTextureFromSurface(renderer, temp);
|
||||
if (!texture) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
|
||||
SDL_FreeSurface(temp);
|
||||
return NULL;
|
||||
}
|
||||
SDL_FreeSurface(temp);
|
||||
|
||||
/* We're ready to roll. :) */
|
||||
return texture;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
WatchJoystick(SDL_Joystick * joystick)
|
||||
{
|
||||
SDL_Window *window = NULL;
|
||||
SDL_Renderer *screen = NULL;
|
||||
SDL_Texture *background, *button, *axis, *marker;
|
||||
const char *name = NULL;
|
||||
SDL_bool retval = SDL_FALSE;
|
||||
SDL_bool done = SDL_FALSE, next=SDL_FALSE;
|
||||
SDL_Event event;
|
||||
SDL_Rect dst;
|
||||
int s, _s;
|
||||
Uint8 alpha=200, alpha_step = -1;
|
||||
Uint32 alpha_ticks;
|
||||
char mapping[4096], temp[4096];
|
||||
MappingStep *step, *prev_step;
|
||||
MappingStep steps[] = {
|
||||
{342, 132, 0.0, MARKER_BUTTON, "x", -1, -1, -1, -1, ""},
|
||||
{387, 167, 0.0, MARKER_BUTTON, "a", -1, -1, -1, -1, ""},
|
||||
{431, 132, 0.0, MARKER_BUTTON, "b", -1, -1, -1, -1, ""},
|
||||
{389, 101, 0.0, MARKER_BUTTON, "y", -1, -1, -1, -1, ""},
|
||||
{174, 132, 0.0, MARKER_BUTTON, "back", -1, -1, -1, -1, ""},
|
||||
{233, 132, 0.0, MARKER_BUTTON, "guide", -1, -1, -1, -1, ""},
|
||||
{289, 132, 0.0, MARKER_BUTTON, "start", -1, -1, -1, -1, ""},
|
||||
{116, 217, 0.0, MARKER_BUTTON, "dpleft", -1, -1, -1, -1, ""},
|
||||
{154, 249, 0.0, MARKER_BUTTON, "dpdown", -1, -1, -1, -1, ""},
|
||||
{186, 217, 0.0, MARKER_BUTTON, "dpright", -1, -1, -1, -1, ""},
|
||||
{154, 188, 0.0, MARKER_BUTTON, "dpup", -1, -1, -1, -1, ""},
|
||||
{77, 40, 0.0, MARKER_BUTTON, "leftshoulder", -1, -1, -1, -1, ""},
|
||||
{91, 0, 0.0, MARKER_BUTTON, "lefttrigger", -1, -1, -1, -1, ""},
|
||||
{396, 36, 0.0, MARKER_BUTTON, "rightshoulder", -1, -1, -1, -1, ""},
|
||||
{375, 0, 0.0, MARKER_BUTTON, "righttrigger", -1, -1, -1, -1, ""},
|
||||
{75, 154, 0.0, MARKER_BUTTON, "leftstick", -1, -1, -1, -1, ""},
|
||||
{305, 230, 0.0, MARKER_BUTTON, "rightstick", -1, -1, -1, -1, ""},
|
||||
{75, 154, 0.0, MARKER_AXIS, "leftx", -1, -1, -1, -1, ""},
|
||||
{75, 154, 90.0, MARKER_AXIS, "lefty", -1, -1, -1, -1, ""},
|
||||
{305, 230, 0.0, MARKER_AXIS, "rightx", -1, -1, -1, -1, ""},
|
||||
{305, 230, 90.0, MARKER_AXIS, "righty", -1, -1, -1, -1, ""},
|
||||
};
|
||||
|
||||
/* Create a window to display joystick axis position */
|
||||
window = SDL_CreateWindow("Game Controller Map", SDL_WINDOWPOS_CENTERED,
|
||||
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
|
||||
SCREEN_HEIGHT, 0);
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
screen = SDL_CreateRenderer(window, -1, 0);
|
||||
if (screen == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
|
||||
SDL_DestroyWindow(window);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
background = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
|
||||
button = LoadTexture(screen, "button.bmp", SDL_TRUE);
|
||||
axis = LoadTexture(screen, "axis.bmp", SDL_TRUE);
|
||||
SDL_RaiseWindow(window);
|
||||
|
||||
/* scale for platforms that don't give you the window size you asked for. */
|
||||
SDL_RenderSetLogicalSize(screen, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
|
||||
/* Print info about the joystick we are watching */
|
||||
name = SDL_JoystickName(joystick);
|
||||
SDL_Log("Watching joystick %d: (%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_Log("\n\n\
|
||||
====================================================================================\n\
|
||||
Press the buttons on your controller when indicated\n\
|
||||
(Your controller may look different than the picture)\n\
|
||||
If you want to correct a mistake, press backspace or the back button on your device\n\
|
||||
To skip a button, press SPACE or click/touch the screen\n\
|
||||
To exit, press ESC\n\
|
||||
====================================================================================\n");
|
||||
|
||||
/* Initialize mapping with GUID and name */
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, SDL_arraysize(temp));
|
||||
SDL_snprintf(mapping, SDL_arraysize(mapping), "%s,%s,platform:%s,",
|
||||
temp, name ? name : "Unknown Joystick", SDL_GetPlatform());
|
||||
|
||||
/* Loop, getting joystick events! */
|
||||
for(s=0; s<SDL_arraysize(steps) && !done;) {
|
||||
/* blank screen, set up for drawing this frame. */
|
||||
step = &steps[s];
|
||||
SDL_strlcpy(step->mapping, mapping, SDL_arraysize(step->mapping));
|
||||
step->axis = -1;
|
||||
step->button = -1;
|
||||
step->hat = -1;
|
||||
step->hat_value = -1;
|
||||
SDL_SetClipboardText("TESTING TESTING 123");
|
||||
|
||||
switch(step->marker) {
|
||||
case MARKER_AXIS:
|
||||
marker = axis;
|
||||
break;
|
||||
case MARKER_BUTTON:
|
||||
marker = button;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
dst.x = step->x;
|
||||
dst.y = step->y;
|
||||
SDL_QueryTexture(marker, NULL, NULL, &dst.w, &dst.h);
|
||||
next=SDL_FALSE;
|
||||
|
||||
SDL_SetRenderDrawColor(screen, 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE);
|
||||
|
||||
while (!done && !next) {
|
||||
if (SDL_GetTicks() - alpha_ticks > 5) {
|
||||
alpha_ticks = SDL_GetTicks();
|
||||
alpha += alpha_step;
|
||||
if (alpha == 255) {
|
||||
alpha_step = -1;
|
||||
}
|
||||
if (alpha < 128) {
|
||||
alpha_step = 1;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_RenderClear(screen);
|
||||
SDL_RenderCopy(screen, background, NULL, NULL);
|
||||
SDL_SetTextureAlphaMod(marker, alpha);
|
||||
SDL_SetTextureColorMod(marker, 10, 255, 21);
|
||||
SDL_RenderCopyEx(screen, marker, NULL, &dst, step->angle, NULL, 0);
|
||||
SDL_RenderPresent(screen);
|
||||
|
||||
if (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_JOYAXISMOTION:
|
||||
if (event.jaxis.value > 20000 || event.jaxis.value < -20000) {
|
||||
for (_s = 0; _s < s; _s++) {
|
||||
if (steps[_s].axis == event.jaxis.axis) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (_s == s) {
|
||||
step->axis = event.jaxis.axis;
|
||||
SDL_strlcat(mapping, step->field, SDL_arraysize(mapping));
|
||||
SDL_snprintf(temp, SDL_arraysize(temp), ":a%u,", event.jaxis.axis);
|
||||
SDL_strlcat(mapping, temp, SDL_arraysize(mapping));
|
||||
s++;
|
||||
next=SDL_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case SDL_JOYHATMOTION:
|
||||
if (event.jhat.value == SDL_HAT_CENTERED) {
|
||||
break; /* ignore centering, we're probably just coming back to the center from the previous item we set. */
|
||||
}
|
||||
for (_s = 0; _s < s; _s++) {
|
||||
if (steps[_s].hat == event.jhat.hat && steps[_s].hat_value == event.jhat.value) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (_s == s) {
|
||||
step->hat = event.jhat.hat;
|
||||
step->hat_value = event.jhat.value;
|
||||
SDL_strlcat(mapping, step->field, SDL_arraysize(mapping));
|
||||
SDL_snprintf(temp, SDL_arraysize(temp), ":h%u.%u,", event.jhat.hat, event.jhat.value );
|
||||
SDL_strlcat(mapping, temp, SDL_arraysize(mapping));
|
||||
s++;
|
||||
next=SDL_TRUE;
|
||||
}
|
||||
break;
|
||||
case SDL_JOYBALLMOTION:
|
||||
break;
|
||||
case SDL_JOYBUTTONUP:
|
||||
for (_s = 0; _s < s; _s++) {
|
||||
if (steps[_s].button == event.jbutton.button) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (_s == s) {
|
||||
step->button = event.jbutton.button;
|
||||
SDL_strlcat(mapping, step->field, SDL_arraysize(mapping));
|
||||
SDL_snprintf(temp, SDL_arraysize(temp), ":b%u,", event.jbutton.button);
|
||||
SDL_strlcat(mapping, temp, SDL_arraysize(mapping));
|
||||
s++;
|
||||
next=SDL_TRUE;
|
||||
}
|
||||
break;
|
||||
case SDL_FINGERDOWN:
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
/* Skip this step */
|
||||
s++;
|
||||
next=SDL_TRUE;
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym == SDLK_BACKSPACE || event.key.keysym.sym == SDLK_AC_BACK) {
|
||||
/* Undo! */
|
||||
if (s > 0) {
|
||||
prev_step = &steps[--s];
|
||||
SDL_strlcpy(mapping, prev_step->mapping, SDL_arraysize(prev_step->mapping));
|
||||
next = SDL_TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (event.key.keysym.sym == SDLK_SPACE) {
|
||||
/* Skip this step */
|
||||
s++;
|
||||
next=SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((event.key.keysym.sym != SDLK_ESCAPE)) {
|
||||
break;
|
||||
}
|
||||
/* Fall through to signal quit */
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (s == SDL_arraysize(steps) ) {
|
||||
SDL_Log("Mapping:\n\n%s\n\n", mapping);
|
||||
/* Print to stdout as well so the user can cat the output somewhere */
|
||||
printf("%s\n", mapping);
|
||||
}
|
||||
|
||||
while(SDL_PollEvent(&event)) {};
|
||||
|
||||
SDL_DestroyRenderer(screen);
|
||||
SDL_DestroyWindow(window);
|
||||
return retval;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
const char *name;
|
||||
int i;
|
||||
SDL_Joystick *joystick;
|
||||
|
||||
/* Enable standard application logging */
|
||||
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) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Print information about the joysticks */
|
||||
SDL_Log("There are %d joysticks attached\n", SDL_NumJoysticks());
|
||||
for (i = 0; i < SDL_NumJoysticks(); ++i) {
|
||||
name = SDL_JoystickNameForIndex(i);
|
||||
SDL_Log("Joystick %d: %s\n", i, name ? name : "Unknown Joystick");
|
||||
joystick = SDL_JoystickOpen(i);
|
||||
if (joystick == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_JoystickOpen(%d) failed: %s\n", i,
|
||||
SDL_GetError());
|
||||
} else {
|
||||
char guid[64];
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick),
|
||||
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));
|
||||
SDL_Log(" buttons: %d\n", SDL_JoystickNumButtons(joystick));
|
||||
SDL_Log("instance id: %d\n", SDL_JoystickInstanceID(joystick));
|
||||
SDL_Log(" guid: %s\n", guid);
|
||||
SDL_JoystickClose(joystick);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ANDROID
|
||||
if (SDL_NumJoysticks() > 0) {
|
||||
#else
|
||||
if (argv[1]) {
|
||||
#endif
|
||||
SDL_bool reportederror = SDL_FALSE;
|
||||
SDL_bool keepGoing = SDL_TRUE;
|
||||
SDL_Event event;
|
||||
int device;
|
||||
#ifdef ANDROID
|
||||
device = 0;
|
||||
#else
|
||||
device = atoi(argv[1]);
|
||||
#endif
|
||||
joystick = SDL_JoystickOpen(device);
|
||||
|
||||
while ( keepGoing ) {
|
||||
if (joystick == NULL) {
|
||||
if ( !reportederror ) {
|
||||
SDL_Log("Couldn't open joystick %d: %s\n", device, SDL_GetError());
|
||||
keepGoing = SDL_FALSE;
|
||||
reportederror = SDL_TRUE;
|
||||
}
|
||||
} else {
|
||||
reportederror = SDL_FALSE;
|
||||
keepGoing = WatchJoystick(joystick);
|
||||
SDL_JoystickClose(joystick);
|
||||
}
|
||||
|
||||
joystick = NULL;
|
||||
if (keepGoing) {
|
||||
SDL_Log("Waiting for attach\n");
|
||||
}
|
||||
while (keepGoing) {
|
||||
SDL_WaitEvent(&event);
|
||||
if ((event.type == SDL_QUIT) || (event.type == SDL_FINGERDOWN)
|
||||
|| (event.type == SDL_MOUSEBUTTONDOWN)) {
|
||||
keepGoing = SDL_FALSE;
|
||||
} else if (event.type == SDL_JOYDEVICEADDED) {
|
||||
joystick = SDL_JoystickOpen(device);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
SDL_Log("\n\nUsage: ./controllermap number\nFor example: ./controllermap 0\nOr: ./controllermap 0 >> gamecontrollerdb.txt");
|
||||
}
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Joystick support.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#endif
|
110
test/gcc-fat.sh
Executable file
@@ -0,0 +1,110 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Build Universal binaries on Mac OS X, thanks Ryan!
|
||||
#
|
||||
# Usage: ./configure CC="sh gcc-fat.sh" && make && rm -rf ppc x86
|
||||
|
||||
# PowerPC compiler flags (10.2 runtime compatibility)
|
||||
GCC_COMPILE_PPC="gcc-3.3 -arch ppc \
|
||||
-DMAC_OS_X_VERSION_MIN_REQUIRED=1020 \
|
||||
-nostdinc \
|
||||
-F/Developer/SDKs/MacOSX10.2.8.sdk/System/Library/Frameworks \
|
||||
-I/Developer/SDKs/MacOSX10.2.8.sdk/usr/include/gcc/darwin/3.3 \
|
||||
-isystem /Developer/SDKs/MacOSX10.2.8.sdk/usr/include"
|
||||
|
||||
GCC_LINK_PPC="\
|
||||
-L/Developer/SDKs/MacOSX10.2.8.sdk/usr/lib/gcc/darwin/3.3 \
|
||||
-F/Developer/SDKs/MacOSX10.2.8.sdk/System/Library/Frameworks \
|
||||
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.2.8.sdk"
|
||||
|
||||
# Intel compiler flags (10.4 runtime compatibility)
|
||||
GCC_COMPILE_X86="gcc-4.0 -arch i386 -mmacosx-version-min=10.4 \
|
||||
-DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
|
||||
-nostdinc \
|
||||
-F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
|
||||
-I/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.1/include \
|
||||
-isystem /Developer/SDKs/MacOSX10.4u.sdk/usr/include"
|
||||
|
||||
GCC_LINK_X86="\
|
||||
-L/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.0 \
|
||||
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk"
|
||||
|
||||
# Output both PowerPC and Intel object files
|
||||
args="$*"
|
||||
compile=yes
|
||||
link=yes
|
||||
while test x$1 != x; do
|
||||
case $1 in
|
||||
--version) exec gcc $1;;
|
||||
-v) exec gcc $1;;
|
||||
-V) exec gcc $1;;
|
||||
-print-prog-name=*) exec gcc $1;;
|
||||
-print-search-dirs) exec gcc $1;;
|
||||
-E) GCC_COMPILE_PPC="$GCC_COMPILE_PPC -E"
|
||||
GCC_COMPILE_X86="$GCC_COMPILE_X86 -E"
|
||||
compile=no; link=no;;
|
||||
-c) link=no;;
|
||||
-o) output=$2;;
|
||||
*.c|*.cc|*.cpp|*.S) source=$1;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
if test x$link = xyes; then
|
||||
GCC_COMPILE_PPC="$GCC_COMPILE_PPC $GCC_LINK_PPC"
|
||||
GCC_COMPILE_X86="$GCC_COMPILE_X86 $GCC_LINK_X86"
|
||||
fi
|
||||
if test x"$output" = x; then
|
||||
if test x$link = xyes; then
|
||||
output=a.out
|
||||
elif test x$compile = xyes; then
|
||||
output=`echo $source | sed -e 's|.*/||' -e 's|\(.*\)\.[^\.]*|\1|'`.o
|
||||
fi
|
||||
fi
|
||||
|
||||
if test x"$output" != x; then
|
||||
dir=ppc/`dirname $output`
|
||||
if test -d $dir; then
|
||||
:
|
||||
else
|
||||
mkdir -p $dir
|
||||
fi
|
||||
fi
|
||||
set -- $args
|
||||
while test x$1 != x; do
|
||||
if test -f "ppc/$1" && test "$1" != "$output"; then
|
||||
ppc_args="$ppc_args ppc/$1"
|
||||
else
|
||||
ppc_args="$ppc_args $1"
|
||||
fi
|
||||
shift
|
||||
done
|
||||
$GCC_COMPILE_PPC $ppc_args || exit $?
|
||||
if test x"$output" != x; then
|
||||
cp $output ppc/$output
|
||||
fi
|
||||
|
||||
if test x"$output" != x; then
|
||||
dir=x86/`dirname $output`
|
||||
if test -d $dir; then
|
||||
:
|
||||
else
|
||||
mkdir -p $dir
|
||||
fi
|
||||
fi
|
||||
set -- $args
|
||||
while test x$1 != x; do
|
||||
if test -f "x86/$1" && test "$1" != "$output"; then
|
||||
x86_args="$x86_args x86/$1"
|
||||
else
|
||||
x86_args="$x86_args $1"
|
||||
fi
|
||||
shift
|
||||
done
|
||||
$GCC_COMPILE_X86 $x86_args || exit $?
|
||||
if test x"$output" != x; then
|
||||
cp $output x86/$output
|
||||
fi
|
||||
|
||||
if test x"$output" != x; then
|
||||
lipo -create -o $output ppc/$output x86/$output
|
||||
fi
|
BIN
test/icon.bmp
Normal file
After Width: | Height: | Size: 578 B |
144
test/loopwave.c
Normal file
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
Copyright (C) 1997-2014 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.
|
||||
*/
|
||||
|
||||
/* Program to load a wave file and loop playing it using SDL sound */
|
||||
|
||||
/* loopwaves.c is much more robust in handling WAVE files --
|
||||
This is only for simple WAVEs
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if HAVE_SIGNAL_H
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_audio.h"
|
||||
|
||||
struct
|
||||
{
|
||||
SDL_AudioSpec spec;
|
||||
Uint8 *sound; /* Pointer to wave data */
|
||||
Uint32 soundlen; /* Length of wave data */
|
||||
int soundpos; /* Current play position */
|
||||
} wave;
|
||||
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
{
|
||||
SDL_Quit();
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
|
||||
void SDLCALL
|
||||
fillerup(void *unused, Uint8 * stream, int len)
|
||||
{
|
||||
Uint8 *waveptr;
|
||||
int waveleft;
|
||||
|
||||
/* Set up the pointers */
|
||||
waveptr = wave.sound + wave.soundpos;
|
||||
waveleft = wave.soundlen - wave.soundpos;
|
||||
|
||||
/* Go! */
|
||||
while (waveleft <= len) {
|
||||
SDL_memcpy(stream, waveptr, waveleft);
|
||||
stream += waveleft;
|
||||
len -= waveleft;
|
||||
waveptr = wave.sound;
|
||||
waveleft = wave.soundlen;
|
||||
wave.soundpos = 0;
|
||||
}
|
||||
SDL_memcpy(stream, waveptr, len);
|
||||
wave.soundpos += len;
|
||||
}
|
||||
|
||||
static int done = 0;
|
||||
void
|
||||
poked(int sig)
|
||||
{
|
||||
done = 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
char filename[4096];
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Load the SDL library */
|
||||
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (argc >= 1) {
|
||||
SDL_strlcpy(filename, argv[1], sizeof(filename));
|
||||
} else {
|
||||
SDL_strlcpy(filename, "sample.wav", sizeof(filename));
|
||||
}
|
||||
/* Load the wave file into memory */
|
||||
if (SDL_LoadWAV(filename, &wave.spec, &wave.sound, &wave.soundlen) == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", argv[1], SDL_GetError());
|
||||
quit(1);
|
||||
}
|
||||
|
||||
wave.spec.callback = fillerup;
|
||||
#if HAVE_SIGNAL_H
|
||||
/* Set the signals */
|
||||
#ifdef SIGHUP
|
||||
signal(SIGHUP, poked);
|
||||
#endif
|
||||
signal(SIGINT, poked);
|
||||
#ifdef SIGQUIT
|
||||
signal(SIGQUIT, poked);
|
||||
#endif
|
||||
signal(SIGTERM, poked);
|
||||
#endif /* HAVE_SIGNAL_H */
|
||||
|
||||
/* Show the list of available drivers */
|
||||
SDL_Log("Available audio drivers:");
|
||||
for (i = 0; i < SDL_GetNumAudioDrivers(); ++i) {
|
||||
SDL_Log("%i: %s", i, SDL_GetAudioDriver(i));
|
||||
}
|
||||
|
||||
/* Initialize fillerup() variables */
|
||||
if (SDL_OpenAudio(&wave.spec, NULL) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open audio: %s\n", SDL_GetError());
|
||||
SDL_FreeWAV(wave.sound);
|
||||
quit(2);
|
||||
}
|
||||
|
||||
SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
|
||||
|
||||
/* Let the audio run */
|
||||
SDL_PauseAudio(0);
|
||||
while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING))
|
||||
SDL_Delay(1000);
|
||||
|
||||
/* Clean up on signal */
|
||||
SDL_CloseAudio();
|
||||
SDL_FreeWAV(wave.sound);
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
BIN
test/moose.dat
Normal file
14
test/picture.xbm
Normal file
@@ -0,0 +1,14 @@
|
||||
#define picture_width 32
|
||||
#define picture_height 32
|
||||
static char picture_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x80, 0x01, 0x18,
|
||||
0x64, 0x6f, 0xf6, 0x26, 0x0a, 0x00, 0x00, 0x50, 0xf2, 0xff, 0xff, 0x4f,
|
||||
0x14, 0x04, 0x00, 0x28, 0x14, 0x0e, 0x00, 0x28, 0x10, 0x32, 0x00, 0x08,
|
||||
0x94, 0x03, 0x00, 0x08, 0xf4, 0x04, 0x00, 0x08, 0xb0, 0x08, 0x00, 0x08,
|
||||
0x34, 0x01, 0x00, 0x28, 0x34, 0x01, 0x00, 0x28, 0x12, 0x00, 0x40, 0x48,
|
||||
0x12, 0x20, 0xa6, 0x48, 0x14, 0x50, 0x11, 0x29, 0x14, 0x50, 0x48, 0x2a,
|
||||
0x10, 0x27, 0xac, 0x0e, 0xd4, 0x71, 0xe8, 0x0a, 0x74, 0x20, 0xa8, 0x0a,
|
||||
0x14, 0x20, 0x00, 0x08, 0x10, 0x50, 0x00, 0x08, 0x14, 0x00, 0x00, 0x28,
|
||||
0x14, 0x00, 0x00, 0x28, 0xf2, 0xff, 0xff, 0x4f, 0x0a, 0x00, 0x00, 0x50,
|
||||
0x64, 0x6f, 0xf6, 0x26, 0x18, 0x80, 0x01, 0x18, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
56
test/relative_mode.markdown
Normal file
@@ -0,0 +1,56 @@
|
||||
Relative mode testing
|
||||
=====================
|
||||
|
||||
See test program at the bottom of this file.
|
||||
|
||||
Initial tests:
|
||||
|
||||
- When in relative mode, the mouse shouldn't be moveable outside of the window.
|
||||
- When the cursor is outside the window when relative mode is enabled, mouse
|
||||
clicks should not go to whatever app was under the cursor previously.
|
||||
- When alt/cmd-tabbing between a relative mode app and another app, clicks when
|
||||
in the relative mode app should also not go to whatever app was under the
|
||||
cursor previously.
|
||||
|
||||
|
||||
Code
|
||||
====
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
int PollEvents()
|
||||
{
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_QUIT:
|
||||
return 1;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
|
||||
SDL_Window *win = SDL_CreateWindow("Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, 0);
|
||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (PollEvents())
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_DestroyWindow(win);
|
||||
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
BIN
test/sample.bmp
Normal file
After Width: | Height: | Size: 68 KiB |
BIN
test/sample.wav
Normal file
BIN
test/shapes/p01_shape24.bmp
Normal file
After Width: | Height: | Size: 1.2 MiB |
BIN
test/shapes/p01_shape32alpha.bmp
Normal file
After Width: | Height: | Size: 1.6 MiB |
BIN
test/shapes/p01_shape8.bmp
Normal file
After Width: | Height: | Size: 401 KiB |
BIN
test/shapes/p02_shape24.bmp
Normal file
After Width: | Height: | Size: 1.2 MiB |
BIN
test/shapes/p02_shape32alpha.bmp
Normal file
After Width: | Height: | Size: 1.6 MiB |
BIN
test/shapes/p02_shape8.bmp
Normal file
After Width: | Height: | Size: 401 KiB |
BIN
test/shapes/p03_shape24.bmp
Normal file
After Width: | Height: | Size: 1.2 MiB |
BIN
test/shapes/p03_shape8.bmp
Normal file
After Width: | Height: | Size: 401 KiB |
BIN
test/shapes/p04_shape1.bmp
Normal file
After Width: | Height: | Size: 50 KiB |
BIN
test/shapes/p04_shape24.bmp
Normal file
After Width: | Height: | Size: 1.2 MiB |
BIN
test/shapes/p04_shape32alpha.bmp
Normal file
After Width: | Height: | Size: 1.6 MiB |
BIN
test/shapes/p04_shape8.bmp
Normal file
After Width: | Height: | Size: 401 KiB |
BIN
test/shapes/p05_shape8.bmp
Normal file
After Width: | Height: | Size: 401 KiB |
BIN
test/shapes/p06_shape1alpha.bmp
Normal file
After Width: | Height: | Size: 1.6 MiB |
BIN
test/shapes/p06_shape24.bmp
Normal file
After Width: | Height: | Size: 1.2 MiB |
BIN
test/shapes/p06_shape32alpha.bmp
Normal file
After Width: | Height: | Size: 1.6 MiB |
BIN
test/shapes/p06_shape8.bmp
Normal file
After Width: | Height: | Size: 401 KiB |
BIN
test/shapes/p07_shape24.bmp
Normal file
After Width: | Height: | Size: 1.2 MiB |
BIN
test/shapes/p07_shape32alpha.bmp
Normal file
After Width: | Height: | Size: 1.6 MiB |
BIN
test/shapes/p07_shape8.bmp
Normal file
After Width: | Height: | Size: 401 KiB |
BIN
test/shapes/p08_shape24.bmp
Normal file
After Width: | Height: | Size: 1.2 MiB |
BIN
test/shapes/p08_shape32alpha.bmp
Normal file
After Width: | Height: | Size: 1.6 MiB |
BIN
test/shapes/p08_shape8.bmp
Normal file
After Width: | Height: | Size: 401 KiB |
BIN
test/shapes/p09_shape24.bmp
Normal file
After Width: | Height: | Size: 1.2 MiB |
BIN
test/shapes/p09_shape32alpha.bmp
Normal file
After Width: | Height: | Size: 1.6 MiB |
BIN
test/shapes/p09_shape8.bmp
Normal file
After Width: | Height: | Size: 401 KiB |
BIN
test/shapes/p10_shape1.bmp
Normal file
After Width: | Height: | Size: 50 KiB |
BIN
test/shapes/p10_shape24.bmp
Normal file
After Width: | Height: | Size: 1.2 MiB |
BIN
test/shapes/p10_shape32alpha.bmp
Normal file
After Width: | Height: | Size: 1.6 MiB |
BIN
test/shapes/p10_shape8.bmp
Normal file
After Width: | Height: | Size: 401 KiB |
BIN
test/shapes/p11_shape24.bmp
Normal file
After Width: | Height: | Size: 1.2 MiB |
BIN
test/shapes/p11_shape32alpha.bmp
Normal file
After Width: | Height: | Size: 1.6 MiB |
BIN
test/shapes/p11_shape8.bmp
Normal file
After Width: | Height: | Size: 401 KiB |
BIN
test/shapes/p12_shape24.bmp
Normal file
After Width: | Height: | Size: 1.2 MiB |
BIN
test/shapes/p12_shape8.bmp
Normal file
After Width: | Height: | Size: 401 KiB |
BIN
test/shapes/p13_shape24.bmp
Normal file
After Width: | Height: | Size: 1.2 MiB |
BIN
test/shapes/p13_shape32alpha.bmp
Normal file
After Width: | Height: | Size: 1.6 MiB |
BIN
test/shapes/p13_shape8.bmp
Normal file
After Width: | Height: | Size: 401 KiB |
BIN
test/shapes/p14_shape24.bmp
Normal file
After Width: | Height: | Size: 1.2 MiB |
BIN
test/shapes/p14_shape8.bmp
Normal file
After Width: | Height: | Size: 401 KiB |
BIN
test/shapes/p15_shape24.bmp
Normal file
After Width: | Height: | Size: 1.2 MiB |
BIN
test/shapes/p15_shape32alpha.bmp
Normal file
After Width: | Height: | Size: 1.6 MiB |
BIN
test/shapes/p15_shape8.bmp
Normal file
After Width: | Height: | Size: 401 KiB |
BIN
test/shapes/p16_shape1.bmp
Normal file
After Width: | Height: | Size: 50 KiB |
BIN
test/shapes/p16_shape24.bmp
Normal file
After Width: | Height: | Size: 1.2 MiB |
BIN
test/shapes/p16_shape8.bmp
Normal file
After Width: | Height: | Size: 401 KiB |
BIN
test/shapes/trollface_24.bmp
Normal file
After Width: | Height: | Size: 192 KiB |
BIN
test/shapes/trollface_32alpha.bmp
Normal file
After Width: | Height: | Size: 256 KiB |
726
test/testatomic.c
Normal file
@@ -0,0 +1,726 @@
|
||||
/*
|
||||
Copyright (C) 1997-2014 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 <stdio.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_atomic.h"
|
||||
#include "SDL_assert.h"
|
||||
#include "SDL_cpuinfo.h"
|
||||
|
||||
/*
|
||||
Absolutely basic tests just to see if we get the expected value
|
||||
after calling each function.
|
||||
*/
|
||||
|
||||
static
|
||||
char *
|
||||
tf(SDL_bool tf)
|
||||
{
|
||||
static char *t = "TRUE";
|
||||
static char *f = "FALSE";
|
||||
|
||||
if (tf)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
static
|
||||
void RunBasicTest()
|
||||
{
|
||||
int value;
|
||||
SDL_SpinLock lock = 0;
|
||||
|
||||
SDL_atomic_t v;
|
||||
SDL_bool tfret = SDL_FALSE;
|
||||
|
||||
SDL_Log("\nspin lock---------------------------------------\n\n");
|
||||
|
||||
SDL_AtomicLock(&lock);
|
||||
SDL_Log("AtomicLock lock=%d\n", lock);
|
||||
SDL_AtomicUnlock(&lock);
|
||||
SDL_Log("AtomicUnlock lock=%d\n", lock);
|
||||
|
||||
SDL_Log("\natomic -----------------------------------------\n\n");
|
||||
|
||||
SDL_AtomicSet(&v, 0);
|
||||
tfret = SDL_AtomicSet(&v, 10) == 0 ? SDL_TRUE : SDL_FALSE;
|
||||
SDL_Log("AtomicSet(10) tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
|
||||
tfret = SDL_AtomicAdd(&v, 10) == 10 ? SDL_TRUE : SDL_FALSE;
|
||||
SDL_Log("AtomicAdd(10) tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
|
||||
|
||||
SDL_AtomicSet(&v, 0);
|
||||
SDL_AtomicIncRef(&v);
|
||||
tfret = (SDL_AtomicGet(&v) == 1) ? SDL_TRUE : SDL_FALSE;
|
||||
SDL_Log("AtomicIncRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
|
||||
SDL_AtomicIncRef(&v);
|
||||
tfret = (SDL_AtomicGet(&v) == 2) ? SDL_TRUE : SDL_FALSE;
|
||||
SDL_Log("AtomicIncRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
|
||||
tfret = (SDL_AtomicDecRef(&v) == SDL_FALSE) ? SDL_TRUE : SDL_FALSE;
|
||||
SDL_Log("AtomicDecRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
|
||||
tfret = (SDL_AtomicDecRef(&v) == SDL_TRUE) ? SDL_TRUE : SDL_FALSE;
|
||||
SDL_Log("AtomicDecRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
|
||||
|
||||
SDL_AtomicSet(&v, 10);
|
||||
tfret = (SDL_AtomicCAS(&v, 0, 20) == SDL_FALSE) ? SDL_TRUE : SDL_FALSE;
|
||||
SDL_Log("AtomicCAS() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
|
||||
value = SDL_AtomicGet(&v);
|
||||
tfret = (SDL_AtomicCAS(&v, value, 20) == SDL_TRUE) ? SDL_TRUE : SDL_FALSE;
|
||||
SDL_Log("AtomicCAS() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/* Atomic operation test
|
||||
* Adapted with permission from code by Michael Davidsaver at:
|
||||
* http://bazaar.launchpad.net/~mdavidsaver/epics-base/atomic/revision/12105#src/libCom/test/epicsAtomicTest.c
|
||||
* Original copyright 2010 Brookhaven Science Associates as operator of Brookhaven National Lab
|
||||
* http://www.aps.anl.gov/epics/license/open.php
|
||||
*/
|
||||
|
||||
/* Tests semantics of atomic operations. Also a stress test
|
||||
* to see if they are really atomic.
|
||||
*
|
||||
* Several threads adding to the same variable.
|
||||
* at the end the value is compared with the expected
|
||||
* and with a non-atomic counter.
|
||||
*/
|
||||
|
||||
/* Number of concurrent incrementers */
|
||||
#define NThreads 2
|
||||
#define CountInc 100
|
||||
#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)
|
||||
|
||||
SDL_COMPILE_TIME_ASSERT(size, CountTo>0); /* check for rollover */
|
||||
|
||||
static SDL_atomic_t good = { 42 };
|
||||
|
||||
static atomicValue bad = 42;
|
||||
|
||||
static SDL_atomic_t threadsRunning;
|
||||
|
||||
static SDL_sem *threadDone;
|
||||
|
||||
static
|
||||
int adder(void* junk)
|
||||
{
|
||||
unsigned long N=NInter;
|
||||
SDL_Log("Thread subtracting %d %lu times\n",CountInc,N);
|
||||
while (N--) {
|
||||
SDL_AtomicAdd(&good, -CountInc);
|
||||
bad-=CountInc;
|
||||
}
|
||||
SDL_AtomicAdd(&threadsRunning, -1);
|
||||
SDL_SemPost(threadDone);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
void runAdder(void)
|
||||
{
|
||||
Uint32 start, end;
|
||||
int T=NThreads;
|
||||
|
||||
start = SDL_GetTicks();
|
||||
|
||||
threadDone = SDL_CreateSemaphore(0);
|
||||
|
||||
SDL_AtomicSet(&threadsRunning, NThreads);
|
||||
|
||||
while (T--)
|
||||
SDL_CreateThread(adder, "Adder", NULL);
|
||||
|
||||
while (SDL_AtomicGet(&threadsRunning) > 0)
|
||||
SDL_SemWait(threadDone);
|
||||
|
||||
SDL_DestroySemaphore(threadDone);
|
||||
|
||||
end = SDL_GetTicks();
|
||||
|
||||
SDL_Log("Finished in %f sec\n", (end - start) / 1000.f);
|
||||
}
|
||||
|
||||
static
|
||||
void RunEpicTest()
|
||||
{
|
||||
int b;
|
||||
atomicValue v;
|
||||
|
||||
SDL_Log("\nepic test---------------------------------------\n\n");
|
||||
|
||||
SDL_Log("Size asserted to be >= 32-bit\n");
|
||||
SDL_assert(sizeof(atomicValue)>=4);
|
||||
|
||||
SDL_Log("Check static initializer\n");
|
||||
v=SDL_AtomicGet(&good);
|
||||
SDL_assert(v==42);
|
||||
|
||||
SDL_assert(bad==42);
|
||||
|
||||
SDL_Log("Test negative values\n");
|
||||
SDL_AtomicSet(&good, -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);
|
||||
|
||||
SDL_Log("Test compare and exchange\n");
|
||||
|
||||
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 */
|
||||
|
||||
b=SDL_AtomicCAS(&good, CountTo, 44);
|
||||
SDL_assert(!!b); /* will swap */
|
||||
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, 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, -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);
|
||||
|
||||
SDL_Log("Reset before count down test\n");
|
||||
SDL_AtomicSet(&good, CountTo);
|
||||
v=SDL_AtomicGet(&good);
|
||||
SDL_assert(v==CountTo);
|
||||
|
||||
bad=CountTo;
|
||||
SDL_assert(bad==CountTo);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/* End atomic operation test */
|
||||
/**************************************************************************/
|
||||
|
||||
/**************************************************************************/
|
||||
/* Lock-free FIFO test */
|
||||
|
||||
/* This is useful to test the impact of another thread locking the queue
|
||||
entirely for heavy-weight manipulation.
|
||||
*/
|
||||
#define TEST_SPINLOCK_FIFO
|
||||
|
||||
#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)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SDL_atomic_t sequence;
|
||||
SDL_Event event;
|
||||
} SDL_EventQueueEntry;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SDL_EventQueueEntry entries[MAX_ENTRIES];
|
||||
|
||||
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)];
|
||||
|
||||
SDL_atomic_t dequeue_pos;
|
||||
|
||||
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)];
|
||||
#endif
|
||||
|
||||
volatile SDL_bool active;
|
||||
|
||||
/* Only needed for the mutex test */
|
||||
SDL_mutex *mutex;
|
||||
|
||||
} SDL_EventQueue;
|
||||
|
||||
static void InitEventQueue(SDL_EventQueue *queue)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MAX_ENTRIES; ++i) {
|
||||
SDL_AtomicSet(&queue->entries[i].sequence, i);
|
||||
}
|
||||
SDL_AtomicSet(&queue->enqueue_pos, 0);
|
||||
SDL_AtomicSet(&queue->dequeue_pos, 0);
|
||||
#ifdef TEST_SPINLOCK_FIFO
|
||||
queue->lock = 0;
|
||||
SDL_AtomicSet(&queue->rwcount, 0);
|
||||
#endif
|
||||
queue->active = SDL_TRUE;
|
||||
}
|
||||
|
||||
static SDL_bool EnqueueEvent_LockFree(SDL_EventQueue *queue, const SDL_Event *event)
|
||||
{
|
||||
SDL_EventQueueEntry *entry;
|
||||
unsigned queue_pos;
|
||||
unsigned entry_seq;
|
||||
int delta;
|
||||
SDL_bool status;
|
||||
|
||||
#ifdef TEST_SPINLOCK_FIFO
|
||||
/* This is a gate so an external thread can lock the queue */
|
||||
SDL_AtomicLock(&queue->lock);
|
||||
SDL_assert(SDL_AtomicGet(&queue->watcher) == 0);
|
||||
SDL_AtomicIncRef(&queue->rwcount);
|
||||
SDL_AtomicUnlock(&queue->lock);
|
||||
#endif
|
||||
|
||||
queue_pos = (unsigned)SDL_AtomicGet(&queue->enqueue_pos);
|
||||
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))) {
|
||||
/* We own the object, fill it! */
|
||||
entry->event = *event;
|
||||
SDL_AtomicSet(&entry->sequence, (int)(queue_pos + 1));
|
||||
status = SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
} else if (delta < 0) {
|
||||
/* We ran into an old queue entry, which means it still needs to be dequeued */
|
||||
status = SDL_FALSE;
|
||||
break;
|
||||
} else {
|
||||
/* We ran into a new queue entry, get the new queue position */
|
||||
queue_pos = (unsigned)SDL_AtomicGet(&queue->enqueue_pos);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TEST_SPINLOCK_FIFO
|
||||
SDL_AtomicDecRef(&queue->rwcount);
|
||||
#endif
|
||||
return status;
|
||||
}
|
||||
|
||||
static SDL_bool DequeueEvent_LockFree(SDL_EventQueue *queue, SDL_Event *event)
|
||||
{
|
||||
SDL_EventQueueEntry *entry;
|
||||
unsigned queue_pos;
|
||||
unsigned entry_seq;
|
||||
int delta;
|
||||
SDL_bool status;
|
||||
|
||||
#ifdef TEST_SPINLOCK_FIFO
|
||||
/* This is a gate so an external thread can lock the queue */
|
||||
SDL_AtomicLock(&queue->lock);
|
||||
SDL_assert(SDL_AtomicGet(&queue->watcher) == 0);
|
||||
SDL_AtomicIncRef(&queue->rwcount);
|
||||
SDL_AtomicUnlock(&queue->lock);
|
||||
#endif
|
||||
|
||||
queue_pos = (unsigned)SDL_AtomicGet(&queue->dequeue_pos);
|
||||
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))) {
|
||||
/* We own the object, fill it! */
|
||||
*event = entry->event;
|
||||
SDL_AtomicSet(&entry->sequence, (int)(queue_pos+MAX_ENTRIES));
|
||||
status = SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
} else if (delta < 0) {
|
||||
/* We ran into an old queue entry, which means we've hit empty */
|
||||
status = SDL_FALSE;
|
||||
break;
|
||||
} else {
|
||||
/* We ran into a new queue entry, get the new queue position */
|
||||
queue_pos = (unsigned)SDL_AtomicGet(&queue->dequeue_pos);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TEST_SPINLOCK_FIFO
|
||||
SDL_AtomicDecRef(&queue->rwcount);
|
||||
#endif
|
||||
return status;
|
||||
}
|
||||
|
||||
static SDL_bool EnqueueEvent_Mutex(SDL_EventQueue *queue, const SDL_Event *event)
|
||||
{
|
||||
SDL_EventQueueEntry *entry;
|
||||
unsigned queue_pos;
|
||||
unsigned entry_seq;
|
||||
int delta;
|
||||
SDL_bool status = SDL_FALSE;
|
||||
|
||||
SDL_LockMutex(queue->mutex);
|
||||
|
||||
queue_pos = (unsigned)queue->enqueue_pos.value;
|
||||
entry = &queue->entries[queue_pos & WRAP_MASK];
|
||||
entry_seq = (unsigned)entry->sequence.value;
|
||||
|
||||
delta = (int)(entry_seq - queue_pos);
|
||||
if (delta == 0) {
|
||||
++queue->enqueue_pos.value;
|
||||
|
||||
/* We own the object, fill it! */
|
||||
entry->event = *event;
|
||||
entry->sequence.value = (int)(queue_pos + 1);
|
||||
status = SDL_TRUE;
|
||||
} else if (delta < 0) {
|
||||
/* We ran into an old queue entry, which means it still needs to be dequeued */
|
||||
} else {
|
||||
SDL_Log("ERROR: mutex failed!\n");
|
||||
}
|
||||
|
||||
SDL_UnlockMutex(queue->mutex);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static SDL_bool DequeueEvent_Mutex(SDL_EventQueue *queue, SDL_Event *event)
|
||||
{
|
||||
SDL_EventQueueEntry *entry;
|
||||
unsigned queue_pos;
|
||||
unsigned entry_seq;
|
||||
int delta;
|
||||
SDL_bool status = SDL_FALSE;
|
||||
|
||||
SDL_LockMutex(queue->mutex);
|
||||
|
||||
queue_pos = (unsigned)queue->dequeue_pos.value;
|
||||
entry = &queue->entries[queue_pos & WRAP_MASK];
|
||||
entry_seq = (unsigned)entry->sequence.value;
|
||||
|
||||
delta = (int)(entry_seq - (queue_pos + 1));
|
||||
if (delta == 0) {
|
||||
++queue->dequeue_pos.value;
|
||||
|
||||
/* We own the object, fill it! */
|
||||
*event = entry->event;
|
||||
entry->sequence.value = (int)(queue_pos + MAX_ENTRIES);
|
||||
status = SDL_TRUE;
|
||||
} else if (delta < 0) {
|
||||
/* We ran into an old queue entry, which means we've hit empty */
|
||||
} else {
|
||||
SDL_Log("ERROR: mutex failed!\n");
|
||||
}
|
||||
|
||||
SDL_UnlockMutex(queue->mutex);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static SDL_sem *writersDone;
|
||||
static SDL_sem *readersDone;
|
||||
static SDL_atomic_t writersRunning;
|
||||
static SDL_atomic_t readersRunning;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SDL_EventQueue *queue;
|
||||
int index;
|
||||
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)];
|
||||
} WriterData;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SDL_EventQueue *queue;
|
||||
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];
|
||||
} ReaderData;
|
||||
|
||||
static int FIFO_Writer(void* _data)
|
||||
{
|
||||
WriterData *data = (WriterData *)_data;
|
||||
SDL_EventQueue *queue = data->queue;
|
||||
int i;
|
||||
SDL_Event event;
|
||||
|
||||
event.type = SDL_USEREVENT;
|
||||
event.user.windowID = 0;
|
||||
event.user.code = 0;
|
||||
event.user.data1 = data;
|
||||
event.user.data2 = NULL;
|
||||
|
||||
if (data->lock_free) {
|
||||
for (i = 0; i < EVENTS_PER_WRITER; ++i) {
|
||||
event.user.code = i;
|
||||
while (!EnqueueEvent_LockFree(queue, &event)) {
|
||||
++data->waits;
|
||||
SDL_Delay(0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < EVENTS_PER_WRITER; ++i) {
|
||||
event.user.code = i;
|
||||
while (!EnqueueEvent_Mutex(queue, &event)) {
|
||||
++data->waits;
|
||||
SDL_Delay(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_AtomicAdd(&writersRunning, -1);
|
||||
SDL_SemPost(writersDone);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int FIFO_Reader(void* _data)
|
||||
{
|
||||
ReaderData *data = (ReaderData *)_data;
|
||||
SDL_EventQueue *queue = data->queue;
|
||||
SDL_Event event;
|
||||
|
||||
if (data->lock_free) {
|
||||
for ( ; ; ) {
|
||||
if (DequeueEvent_LockFree(queue, &event)) {
|
||||
WriterData *writer = (WriterData*)event.user.data1;
|
||||
++data->counters[writer->index];
|
||||
} else if (queue->active) {
|
||||
++data->waits;
|
||||
SDL_Delay(0);
|
||||
} else {
|
||||
/* We drained the queue, we're done! */
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for ( ; ; ) {
|
||||
if (DequeueEvent_Mutex(queue, &event)) {
|
||||
WriterData *writer = (WriterData*)event.user.data1;
|
||||
++data->counters[writer->index];
|
||||
} else if (queue->active) {
|
||||
++data->waits;
|
||||
SDL_Delay(0);
|
||||
} else {
|
||||
/* We drained the queue, we're done! */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_AtomicAdd(&readersRunning, -1);
|
||||
SDL_SemPost(readersDone);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef TEST_SPINLOCK_FIFO
|
||||
/* This thread periodically locks the queue for no particular reason */
|
||||
static int FIFO_Watcher(void* _data)
|
||||
{
|
||||
SDL_EventQueue *queue = (SDL_EventQueue *)_data;
|
||||
|
||||
while (queue->active) {
|
||||
SDL_AtomicLock(&queue->lock);
|
||||
SDL_AtomicIncRef(&queue->watcher);
|
||||
while (SDL_AtomicGet(&queue->rwcount) > 0) {
|
||||
SDL_Delay(0);
|
||||
}
|
||||
/* Do queue manipulation here... */
|
||||
SDL_AtomicDecRef(&queue->watcher);
|
||||
SDL_AtomicUnlock(&queue->lock);
|
||||
|
||||
/* Wait a bit... */
|
||||
SDL_Delay(1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_SPINLOCK_FIFO */
|
||||
|
||||
static void RunFIFOTest(SDL_bool lock_free)
|
||||
{
|
||||
SDL_EventQueue queue;
|
||||
WriterData writerData[NUM_WRITERS];
|
||||
ReaderData readerData[NUM_READERS];
|
||||
Uint32 start, end;
|
||||
int i, j;
|
||||
int grand_total;
|
||||
char textBuffer[1024];
|
||||
int len;
|
||||
|
||||
SDL_Log("\nFIFO test---------------------------------------\n\n");
|
||||
SDL_Log("Mode: %s\n", lock_free ? "LockFree" : "Mutex");
|
||||
|
||||
readersDone = SDL_CreateSemaphore(0);
|
||||
writersDone = SDL_CreateSemaphore(0);
|
||||
|
||||
SDL_memset(&queue, 0xff, sizeof(queue));
|
||||
|
||||
InitEventQueue(&queue);
|
||||
if (!lock_free) {
|
||||
queue.mutex = SDL_CreateMutex();
|
||||
}
|
||||
|
||||
start = SDL_GetTicks();
|
||||
|
||||
#ifdef TEST_SPINLOCK_FIFO
|
||||
/* Start a monitoring thread */
|
||||
if (lock_free) {
|
||||
SDL_CreateThread(FIFO_Watcher, "FIFOWatcher", &queue);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Start the readers first */
|
||||
SDL_Log("Starting %d readers\n", NUM_READERS);
|
||||
SDL_zero(readerData);
|
||||
SDL_AtomicSet(&readersRunning, NUM_READERS);
|
||||
for (i = 0; i < NUM_READERS; ++i) {
|
||||
char name[64];
|
||||
SDL_snprintf(name, sizeof (name), "FIFOReader%d", i);
|
||||
readerData[i].queue = &queue;
|
||||
readerData[i].lock_free = lock_free;
|
||||
SDL_CreateThread(FIFO_Reader, name, &readerData[i]);
|
||||
}
|
||||
|
||||
/* Start up the writers */
|
||||
SDL_Log("Starting %d writers\n", NUM_WRITERS);
|
||||
SDL_zero(writerData);
|
||||
SDL_AtomicSet(&writersRunning, NUM_WRITERS);
|
||||
for (i = 0; i < NUM_WRITERS; ++i) {
|
||||
char name[64];
|
||||
SDL_snprintf(name, sizeof (name), "FIFOWriter%d", i);
|
||||
writerData[i].queue = &queue;
|
||||
writerData[i].index = i;
|
||||
writerData[i].lock_free = lock_free;
|
||||
SDL_CreateThread(FIFO_Writer, name, &writerData[i]);
|
||||
}
|
||||
|
||||
/* Wait for the writers */
|
||||
while (SDL_AtomicGet(&writersRunning) > 0) {
|
||||
SDL_SemWait(writersDone);
|
||||
}
|
||||
|
||||
/* Shut down the queue so readers exit */
|
||||
queue.active = SDL_FALSE;
|
||||
|
||||
/* Wait for the readers */
|
||||
while (SDL_AtomicGet(&readersRunning) > 0) {
|
||||
SDL_SemWait(readersDone);
|
||||
}
|
||||
|
||||
end = SDL_GetTicks();
|
||||
|
||||
SDL_DestroySemaphore(readersDone);
|
||||
SDL_DestroySemaphore(writersDone);
|
||||
|
||||
if (!lock_free) {
|
||||
SDL_DestroyMutex(queue.mutex);
|
||||
}
|
||||
|
||||
SDL_Log("Finished in %f sec\n", (end - start) / 1000.f);
|
||||
|
||||
SDL_Log("\n");
|
||||
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);
|
||||
|
||||
/* Print a breakdown of which readers read messages from which writer */
|
||||
SDL_Log("\n");
|
||||
grand_total = 0;
|
||||
for (i = 0; i < NUM_READERS; ++i) {
|
||||
int total = 0;
|
||||
for (j = 0; j < NUM_WRITERS; ++j) {
|
||||
total += readerData[i].counters[j];
|
||||
}
|
||||
grand_total += total;
|
||||
SDL_Log("Reader %d read %d events, had %d waits\n", i, total, readerData[i].waits);
|
||||
SDL_snprintf(textBuffer, sizeof(textBuffer), " { ");
|
||||
for (j = 0; j < NUM_WRITERS; ++j) {
|
||||
if (j > 0) {
|
||||
len = SDL_strlen(textBuffer);
|
||||
SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, ", ");
|
||||
}
|
||||
len = SDL_strlen(textBuffer);
|
||||
SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, "%d", readerData[i].counters[j]);
|
||||
}
|
||||
len = SDL_strlen(textBuffer);
|
||||
SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, " }\n");
|
||||
SDL_Log(textBuffer);
|
||||
}
|
||||
SDL_Log("Readers read %d total events\n", grand_total);
|
||||
}
|
||||
|
||||
/* End FIFO test */
|
||||
/**************************************************************************/
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
RunBasicTest();
|
||||
RunEpicTest();
|
||||
/* This test is really slow, so don't run it by default */
|
||||
#if 0
|
||||
RunFIFOTest(SDL_FALSE);
|
||||
#endif
|
||||
RunFIFOTest(SDL_TRUE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
70
test/testaudioinfo.c
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
Copyright (C) 1997-2014 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 <stdio.h>
|
||||
#include "SDL.h"
|
||||
|
||||
static void
|
||||
print_devices(int iscapture)
|
||||
{
|
||||
const char *typestr = ((iscapture) ? "capture" : "output");
|
||||
int n = SDL_GetNumAudioDevices(iscapture);
|
||||
|
||||
SDL_Log("%s devices:\n", typestr);
|
||||
|
||||
if (n == -1)
|
||||
SDL_Log(" Driver can't detect specific %s devices.\n\n", typestr);
|
||||
else if (n == 0)
|
||||
SDL_Log(" No %s devices found.\n\n", typestr);
|
||||
else {
|
||||
int i;
|
||||
for (i = 0; i < n; i++) {
|
||||
SDL_Log(" %s\n", SDL_GetAudioDeviceName(i, iscapture));
|
||||
}
|
||||
SDL_Log("\n");
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int n;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Load the SDL library */
|
||||
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Print available audio drivers */
|
||||
n = SDL_GetNumAudioDrivers();
|
||||
if (n == 0) {
|
||||
SDL_Log("No built-in audio drivers\n\n");
|
||||
} else {
|
||||
int i;
|
||||
SDL_Log("Built-in audio drivers:\n");
|
||||
for (i = 0; i < n; ++i) {
|
||||
SDL_Log(" %s\n", SDL_GetAudioDriver(i));
|
||||
}
|
||||
SDL_Log("\n");
|
||||
}
|
||||
|
||||
SDL_Log("Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver());
|
||||
|
||||
print_devices(0);
|
||||
print_devices(1);
|
||||
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
124
test/testautomation.c
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
Copyright (C) 1997-2014 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 "testautomation_suites.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;
|
||||
char *filter = NULL;
|
||||
int i, done;
|
||||
SDL_Event event;
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* 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", (long long unsigned int *)&userExecKey);
|
||||
consumed = 2;
|
||||
}
|
||||
}
|
||||
else if (SDL_strcasecmp(argv[i], "--seed") == 0) {
|
||||
if (argv[i + 1]) {
|
||||
userRunSeed = SDL_strdup(argv[i + 1]);
|
||||
consumed = 2;
|
||||
}
|
||||
}
|
||||
else if (SDL_strcasecmp(argv[i], "--filter") == 0) {
|
||||
if (argv[i + 1]) {
|
||||
filter = SDL_strdup(argv[i + 1]);
|
||||
consumed = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (consumed < 0) {
|
||||
SDL_Log("Usage: %s %s [--iterations #] [--execKey #] [--seed string] [--filter suite_name|test_name]\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, (const char *)userRunSeed, userExecKey, (const char *)filter, testIterations);
|
||||
|
||||
/* Empty event queue */
|
||||
done = 0;
|
||||
for (i=0; i<100; i++) {
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
SDL_Delay(10);
|
||||
}
|
||||
|
||||
/* Clean up */
|
||||
SDL_free(userRunSeed);
|
||||
SDL_free(filter);
|
||||
|
||||
/* Shutdown everything */
|
||||
quit(result);
|
||||
return(result);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
893
test/testautomation_audio.c
Normal file
@@ -0,0 +1,893 @@
|
||||
/**
|
||||
* Original code: automated SDL audio test written by Edgar Simo "bobbens"
|
||||
* New/updated tests: aschiffler at ferzkopp dot net
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_test.h"
|
||||
|
||||
/* ================= Test Case Implementation ================== */
|
||||
|
||||
/* Fixture */
|
||||
|
||||
void
|
||||
_audioSetUp(void *arg)
|
||||
{
|
||||
/* Start SDL audio subsystem */
|
||||
int ret = SDL_InitSubSystem( SDL_INIT_AUDIO );
|
||||
SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_AUDIO)");
|
||||
SDLTest_AssertCheck(ret==0, "Check result from SDL_InitSubSystem(SDL_INIT_AUDIO)");
|
||||
if (ret != 0) {
|
||||
SDLTest_LogError("%s", SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Test callback function */
|
||||
void _audio_testCallback(void *userdata, Uint8 *stream, int len)
|
||||
{
|
||||
/* TODO: add tracking if callback was called */
|
||||
}
|
||||
|
||||
|
||||
/* Test case functions */
|
||||
|
||||
/**
|
||||
* \brief Stop and restart audio subsystem
|
||||
*
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_QuitSubSystem
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_InitSubSystem
|
||||
*/
|
||||
int audio_quitInitAudioSubSystem()
|
||||
{
|
||||
/* Stop SDL audio subsystem */
|
||||
SDL_QuitSubSystem( SDL_INIT_AUDIO );
|
||||
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
|
||||
|
||||
/* Restart audio again */
|
||||
_audioSetUp(NULL);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Start and stop audio directly
|
||||
*
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_InitAudio
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_QuitAudio
|
||||
*/
|
||||
int audio_initQuitAudio()
|
||||
{
|
||||
int result;
|
||||
int i, iMax;
|
||||
const char* audioDriver;
|
||||
|
||||
/* Stop SDL audio subsystem */
|
||||
SDL_QuitSubSystem( SDL_INIT_AUDIO );
|
||||
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
|
||||
|
||||
/* Loop over all available audio drivers */
|
||||
iMax = SDL_GetNumAudioDrivers();
|
||||
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers");
|
||||
SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
|
||||
for (i = 0; i < iMax; i++) {
|
||||
audioDriver = SDL_GetAudioDriver(i);
|
||||
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
|
||||
SDLTest_AssertCheck(audioDriver != NULL, "Audio driver name is not NULL");
|
||||
SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver);
|
||||
|
||||
/* Call Init */
|
||||
result = SDL_AudioInit(audioDriver);
|
||||
SDLTest_AssertPass("Call to SDL_AudioInit('%s')", audioDriver);
|
||||
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
|
||||
|
||||
/* Call Quit */
|
||||
SDL_AudioQuit();
|
||||
SDLTest_AssertPass("Call to SDL_AudioQuit()");
|
||||
}
|
||||
|
||||
/* NULL driver specification */
|
||||
audioDriver = NULL;
|
||||
|
||||
/* Call Init */
|
||||
result = SDL_AudioInit(audioDriver);
|
||||
SDLTest_AssertPass("Call to SDL_AudioInit(NULL)");
|
||||
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
|
||||
|
||||
/* Call Quit */
|
||||
SDL_AudioQuit();
|
||||
SDLTest_AssertPass("Call to SDL_AudioQuit()");
|
||||
|
||||
/* Restart audio again */
|
||||
_audioSetUp(NULL);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Start, open, close and stop audio
|
||||
*
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_InitAudio
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_OpenAudio
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_CloseAudio
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_QuitAudio
|
||||
*/
|
||||
int audio_initOpenCloseQuitAudio()
|
||||
{
|
||||
int result;
|
||||
int i, iMax, j;
|
||||
const char* audioDriver;
|
||||
SDL_AudioSpec desired;
|
||||
|
||||
/* Stop SDL audio subsystem */
|
||||
SDL_QuitSubSystem( SDL_INIT_AUDIO );
|
||||
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
|
||||
|
||||
/* Loop over all available audio drivers */
|
||||
iMax = SDL_GetNumAudioDrivers();
|
||||
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers");
|
||||
SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
|
||||
for (i = 0; i < iMax; i++) {
|
||||
audioDriver = SDL_GetAudioDriver(i);
|
||||
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
|
||||
SDLTest_AssertCheck(audioDriver != NULL, "Audio driver name is not NULL");
|
||||
SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver);
|
||||
|
||||
/* Change specs */
|
||||
for (j = 0; j < 2; j++) {
|
||||
|
||||
/* Call Init */
|
||||
result = SDL_AudioInit(audioDriver);
|
||||
SDLTest_AssertPass("Call to SDL_AudioInit('%s')", audioDriver);
|
||||
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
|
||||
|
||||
/* Set spec */
|
||||
SDL_memset(&desired, 0, sizeof(desired));
|
||||
switch (j) {
|
||||
case 0:
|
||||
/* Set standard desired spec */
|
||||
desired.freq = 22050;
|
||||
desired.format = AUDIO_S16SYS;
|
||||
desired.channels = 2;
|
||||
desired.samples = 4096;
|
||||
desired.callback = _audio_testCallback;
|
||||
desired.userdata = NULL;
|
||||
|
||||
case 1:
|
||||
/* Set custom desired spec */
|
||||
desired.freq = 48000;
|
||||
desired.format = AUDIO_F32SYS;
|
||||
desired.channels = 2;
|
||||
desired.samples = 2048;
|
||||
desired.callback = _audio_testCallback;
|
||||
desired.userdata = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Call Open */
|
||||
result = SDL_OpenAudio(&desired, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_OpenAudio(desired_spec_%d, NULL)", j);
|
||||
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0 got: %d", result);
|
||||
|
||||
/* Call Close */
|
||||
SDL_CloseAudio();
|
||||
SDLTest_AssertPass("Call to SDL_CloseAudio()");
|
||||
|
||||
/* Call Quit */
|
||||
SDL_AudioQuit();
|
||||
SDLTest_AssertPass("Call to SDL_AudioQuit()");
|
||||
|
||||
} /* spec loop */
|
||||
} /* driver loop */
|
||||
|
||||
/* Restart audio again */
|
||||
_audioSetUp(NULL);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Enumerate and name available audio devices (output and capture).
|
||||
*
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_GetNumAudioDevices
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_GetAudioDeviceName
|
||||
*/
|
||||
int audio_enumerateAndNameAudioDevices()
|
||||
{
|
||||
int t, tt;
|
||||
int i, n, nn;
|
||||
const char *name, *nameAgain;
|
||||
|
||||
/* Iterate over types: t=0 output device, t=1 input/capture device */
|
||||
for (t=0; t<2; t++) {
|
||||
|
||||
/* Get number of devices. */
|
||||
n = SDL_GetNumAudioDevices(t);
|
||||
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(%i)", t);
|
||||
SDLTest_Log("Number of %s devices < 0, reported as %i", (t) ? "capture" : "output", n);
|
||||
SDLTest_AssertCheck(n >= 0, "Validate result is >= 0, got: %i", n);
|
||||
|
||||
/* Variation of non-zero type */
|
||||
if (t==1) {
|
||||
tt = t + SDLTest_RandomIntegerInRange(1,10);
|
||||
nn = SDL_GetNumAudioDevices(tt);
|
||||
SDLTest_AssertCheck(n==nn, "Verify result from SDL_GetNumAudioDevices(%i), expected same number of audio devices %i, got %i", tt, n, nn);
|
||||
nn = SDL_GetNumAudioDevices(-tt);
|
||||
SDLTest_AssertCheck(n==nn, "Verify result from SDL_GetNumAudioDevices(%i), expected same number of audio devices %i, got %i", -tt, n, nn);
|
||||
}
|
||||
|
||||
/* List devices. */
|
||||
if (n>0) {
|
||||
for (i=0; i<n; i++) {
|
||||
name = SDL_GetAudioDeviceName(i, t);
|
||||
SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
|
||||
SDLTest_AssertCheck(name != NULL, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not NULL", i, t);
|
||||
if (name != NULL) {
|
||||
SDLTest_AssertCheck(name[0] != '\0', "verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, t, name);
|
||||
if (t==1) {
|
||||
/* Also try non-zero type */
|
||||
tt = t + SDLTest_RandomIntegerInRange(1,10);
|
||||
nameAgain = SDL_GetAudioDeviceName(i, tt);
|
||||
SDLTest_AssertCheck(nameAgain != NULL, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not NULL", i, tt);
|
||||
if (nameAgain != NULL) {
|
||||
SDLTest_AssertCheck(nameAgain[0] != '\0', "Verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, tt, nameAgain);
|
||||
SDLTest_AssertCheck(SDL_strcmp(name, nameAgain)==0,
|
||||
"Verify SDL_GetAudioDeviceName(%i, %i) and SDL_GetAudioDeviceName(%i %i) return the same string",
|
||||
i, t, i, tt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Negative tests around enumeration and naming of audio devices.
|
||||
*
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_GetNumAudioDevices
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_GetAudioDeviceName
|
||||
*/
|
||||
int audio_enumerateAndNameAudioDevicesNegativeTests()
|
||||
{
|
||||
int t;
|
||||
int i, j, no, nc;
|
||||
const char *name;
|
||||
|
||||
/* Get number of devices. */
|
||||
no = SDL_GetNumAudioDevices(0);
|
||||
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
|
||||
nc = SDL_GetNumAudioDevices(1);
|
||||
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(1)");
|
||||
|
||||
/* Invalid device index when getting name */
|
||||
for (t=0; t<2; t++) {
|
||||
/* Negative device index */
|
||||
i = SDLTest_RandomIntegerInRange(-10,-1);
|
||||
name = SDL_GetAudioDeviceName(i, t);
|
||||
SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
|
||||
SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result NULL, expected NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
|
||||
|
||||
/* Device index past range */
|
||||
for (j=0; j<3; j++) {
|
||||
i = (t) ? nc+j : no+j;
|
||||
name = SDL_GetAudioDeviceName(i, t);
|
||||
SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
|
||||
SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result, expected: NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
|
||||
}
|
||||
|
||||
/* Capture index past capture range but within output range */
|
||||
if ((no>0) && (no>nc) && (t==1)) {
|
||||
i = no-1;
|
||||
name = SDL_GetAudioDeviceName(i, t);
|
||||
SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
|
||||
SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result, expected: NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
|
||||
}
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Checks available audio driver names.
|
||||
*
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_GetNumAudioDrivers
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_GetAudioDriver
|
||||
*/
|
||||
int audio_printAudioDrivers()
|
||||
{
|
||||
int i, n;
|
||||
const char *name;
|
||||
|
||||
/* Get number of drivers */
|
||||
n = SDL_GetNumAudioDrivers();
|
||||
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
|
||||
SDLTest_AssertCheck(n>=0, "Verify number of audio drivers >= 0, got: %i", n);
|
||||
|
||||
/* List drivers. */
|
||||
if (n>0)
|
||||
{
|
||||
for (i=0; i<n; i++) {
|
||||
name = SDL_GetAudioDriver(i);
|
||||
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%i)", i);
|
||||
SDLTest_AssertCheck(name != NULL, "Verify returned name is not NULL");
|
||||
if (name != NULL) {
|
||||
SDLTest_AssertCheck(name[0] != '\0', "Verify returned name is not empty, got: '%s'", name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Checks current audio driver name with initialized audio.
|
||||
*
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_GetCurrentAudioDriver
|
||||
*/
|
||||
int audio_printCurrentAudioDriver()
|
||||
{
|
||||
/* Check current audio driver */
|
||||
const char *name = SDL_GetCurrentAudioDriver();
|
||||
SDLTest_AssertPass("Call to SDL_GetCurrentAudioDriver()");
|
||||
SDLTest_AssertCheck(name != NULL, "Verify returned name is not NULL");
|
||||
if (name != NULL) {
|
||||
SDLTest_AssertCheck(name[0] != '\0', "Verify returned name is not empty, got: '%s'", name);
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* Definition of all formats, channels, and frequencies used to test audio conversions */
|
||||
const int _numAudioFormats = 18;
|
||||
SDL_AudioFormat _audioFormats[] = { AUDIO_S8, AUDIO_U8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_S16SYS, AUDIO_S16, AUDIO_U16LSB,
|
||||
AUDIO_U16MSB, AUDIO_U16SYS, AUDIO_U16, AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_S32SYS, AUDIO_S32,
|
||||
AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_F32SYS, AUDIO_F32 };
|
||||
char *_audioFormatsVerbose[] = { "AUDIO_S8", "AUDIO_U8", "AUDIO_S16LSB", "AUDIO_S16MSB", "AUDIO_S16SYS", "AUDIO_S16", "AUDIO_U16LSB",
|
||||
"AUDIO_U16MSB", "AUDIO_U16SYS", "AUDIO_U16", "AUDIO_S32LSB", "AUDIO_S32MSB", "AUDIO_S32SYS", "AUDIO_S32",
|
||||
"AUDIO_F32LSB", "AUDIO_F32MSB", "AUDIO_F32SYS", "AUDIO_F32" };
|
||||
const int _numAudioChannels = 4;
|
||||
Uint8 _audioChannels[] = { 1, 2, 4, 6 };
|
||||
const int _numAudioFrequencies = 4;
|
||||
int _audioFrequencies[] = { 11025, 22050, 44100, 48000 };
|
||||
|
||||
|
||||
/**
|
||||
* \brief Builds various audio conversion structures
|
||||
*
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_BuildAudioCVT
|
||||
*/
|
||||
int audio_buildAudioCVT()
|
||||
{
|
||||
int result;
|
||||
SDL_AudioCVT cvt;
|
||||
SDL_AudioSpec spec1;
|
||||
SDL_AudioSpec spec2;
|
||||
int i, ii, j, jj, k, kk;
|
||||
|
||||
/* No conversion needed */
|
||||
spec1.format = AUDIO_S16LSB;
|
||||
spec1.channels = 2;
|
||||
spec1.freq = 22050;
|
||||
result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
|
||||
spec1.format, spec1.channels, spec1.freq);
|
||||
SDLTest_AssertPass("Call to SDL_BuildAudioCVT(spec1 ==> spec1)");
|
||||
SDLTest_AssertCheck(result == 0, "Verify result value; expected: 0, got: %i", result);
|
||||
|
||||
/* Typical conversion */
|
||||
spec1.format = AUDIO_S8;
|
||||
spec1.channels = 1;
|
||||
spec1.freq = 22050;
|
||||
spec2.format = AUDIO_S16LSB;
|
||||
spec2.channels = 2;
|
||||
spec2.freq = 44100;
|
||||
result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
|
||||
spec2.format, spec2.channels, spec2.freq);
|
||||
SDLTest_AssertPass("Call to SDL_BuildAudioCVT(spec1 ==> spec2)");
|
||||
SDLTest_AssertCheck(result == 1, "Verify result value; expected: 1, got: %i", result);
|
||||
|
||||
/* All source conversions with random conversion targets, allow 'null' conversions */
|
||||
for (i = 0; i < _numAudioFormats; i++) {
|
||||
for (j = 0; j < _numAudioChannels; j++) {
|
||||
for (k = 0; k < _numAudioFrequencies; k++) {
|
||||
spec1.format = _audioFormats[i];
|
||||
spec1.channels = _audioChannels[j];
|
||||
spec1.freq = _audioFrequencies[k];
|
||||
ii = SDLTest_RandomIntegerInRange(0, _numAudioFormats - 1);
|
||||
jj = SDLTest_RandomIntegerInRange(0, _numAudioChannels - 1);
|
||||
kk = SDLTest_RandomIntegerInRange(0, _numAudioFrequencies - 1);
|
||||
spec2.format = _audioFormats[ii];
|
||||
spec2.channels = _audioChannels[jj];
|
||||
spec2.freq = _audioFrequencies[kk];
|
||||
result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
|
||||
spec2.format, spec2.channels, spec2.freq);
|
||||
SDLTest_AssertPass("Call to SDL_BuildAudioCVT(format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i ==> format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i)",
|
||||
i, _audioFormatsVerbose[i], spec1.format, j, spec1.channels, k, spec1.freq, ii, _audioFormatsVerbose[ii], spec2.format, jj, spec2.channels, kk, spec2.freq);
|
||||
SDLTest_AssertCheck(result == 0 || result == 1, "Verify result value; expected: 0 or 1, got: %i", result);
|
||||
if (result<0) {
|
||||
SDLTest_LogError(SDL_GetError());
|
||||
} else {
|
||||
SDLTest_AssertCheck(cvt.len_mult > 0, "Verify that cvt.len_mult value; expected: >0, got: %i", cvt.len_mult);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Checkes calls with invalid input to SDL_BuildAudioCVT
|
||||
*
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_BuildAudioCVT
|
||||
*/
|
||||
int audio_buildAudioCVTNegative()
|
||||
{
|
||||
const char *expectedError = "Parameter 'cvt' is invalid";
|
||||
const char *error;
|
||||
int result;
|
||||
SDL_AudioCVT cvt;
|
||||
SDL_AudioSpec spec1;
|
||||
SDL_AudioSpec spec2;
|
||||
int i;
|
||||
char message[256];
|
||||
|
||||
/* Valid format */
|
||||
spec1.format = AUDIO_S8;
|
||||
spec1.channels = 1;
|
||||
spec1.freq = 22050;
|
||||
spec2.format = AUDIO_S16LSB;
|
||||
spec2.channels = 2;
|
||||
spec2.freq = 44100;
|
||||
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
|
||||
/* NULL input for CVT buffer */
|
||||
result = SDL_BuildAudioCVT((SDL_AudioCVT *)NULL, spec1.format, spec1.channels, spec1.freq,
|
||||
spec2.format, spec2.channels, spec2.freq);
|
||||
SDLTest_AssertPass("Call to SDL_BuildAudioCVT(NULL,...)");
|
||||
SDLTest_AssertCheck(result == -1, "Verify result value; expected: -1, got: %i", result);
|
||||
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 conversions */
|
||||
for (i = 1; i < 64; i++) {
|
||||
/* Valid format to start with */
|
||||
spec1.format = AUDIO_S8;
|
||||
spec1.channels = 1;
|
||||
spec1.freq = 22050;
|
||||
spec2.format = AUDIO_S16LSB;
|
||||
spec2.channels = 2;
|
||||
spec2.freq = 44100;
|
||||
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
|
||||
/* Set various invalid format inputs */
|
||||
SDL_strlcpy(message, "Invalid: ", 256);
|
||||
if (i & 1) {
|
||||
SDL_strlcat(message, " spec1.format", 256);
|
||||
spec1.format = 0;
|
||||
}
|
||||
if (i & 2) {
|
||||
SDL_strlcat(message, " spec1.channels", 256);
|
||||
spec1.channels = 0;
|
||||
}
|
||||
if (i & 4) {
|
||||
SDL_strlcat(message, " spec1.freq", 256);
|
||||
spec1.freq = 0;
|
||||
}
|
||||
if (i & 8) {
|
||||
SDL_strlcat(message, " spec2.format", 256);
|
||||
spec2.format = 0;
|
||||
}
|
||||
if (i & 16) {
|
||||
SDL_strlcat(message, " spec2.channels", 256);
|
||||
spec2.channels = 0;
|
||||
}
|
||||
if (i & 32) {
|
||||
SDL_strlcat(message, " spec2.freq", 256);
|
||||
spec2.freq = 0;
|
||||
}
|
||||
SDLTest_Log(message);
|
||||
result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
|
||||
spec2.format, spec2.channels, spec2.freq);
|
||||
SDLTest_AssertPass("Call to SDL_BuildAudioCVT(spec1 ==> spec2)");
|
||||
SDLTest_AssertCheck(result == -1, "Verify result value; expected: -1, got: %i", result);
|
||||
error = SDL_GetError();
|
||||
SDLTest_AssertPass("Call to SDL_GetError()");
|
||||
SDLTest_AssertCheck(error != NULL && error[0] != '\0', "Validate that error message was not NULL or empty");
|
||||
}
|
||||
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Checks current audio status.
|
||||
*
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_GetAudioStatus
|
||||
*/
|
||||
int audio_getAudioStatus()
|
||||
{
|
||||
SDL_AudioStatus result;
|
||||
|
||||
/* Check current audio status */
|
||||
result = SDL_GetAudioStatus();
|
||||
SDLTest_AssertPass("Call to SDL_GetAudioStatus()");
|
||||
SDLTest_AssertCheck(result == SDL_AUDIO_STOPPED || result == SDL_AUDIO_PLAYING || result == SDL_AUDIO_PAUSED,
|
||||
"Verify returned value; expected: STOPPED (%i) | PLAYING (%i) | PAUSED (%i), got: %i",
|
||||
SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED, result);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \brief Opens, checks current audio status, and closes a device.
|
||||
*
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_GetAudioStatus
|
||||
*/
|
||||
int audio_openCloseAndGetAudioStatus()
|
||||
{
|
||||
SDL_AudioStatus result;
|
||||
int i;
|
||||
int count;
|
||||
char *device;
|
||||
SDL_AudioDeviceID id;
|
||||
SDL_AudioSpec desired, obtained;
|
||||
|
||||
/* Get number of devices. */
|
||||
count = SDL_GetNumAudioDevices(0);
|
||||
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
|
||||
if (count > 0) {
|
||||
for (i = 0; i < count; i++) {
|
||||
/* Get device name */
|
||||
device = (char *)SDL_GetAudioDeviceName(i, 0);
|
||||
SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
|
||||
SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
|
||||
if (device == NULL) return TEST_ABORTED;
|
||||
|
||||
/* Set standard desired spec */
|
||||
desired.freq=22050;
|
||||
desired.format=AUDIO_S16SYS;
|
||||
desired.channels=2;
|
||||
desired.samples=4096;
|
||||
desired.callback=_audio_testCallback;
|
||||
desired.userdata=NULL;
|
||||
|
||||
/* Open device */
|
||||
id = SDL_OpenAudioDevice((const char *)device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
|
||||
SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
|
||||
SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >=2, got: %i", id);
|
||||
if (id > 1) {
|
||||
|
||||
/* Check device audio status */
|
||||
result = SDL_GetAudioDeviceStatus(id);
|
||||
SDLTest_AssertPass("Call to SDL_GetAudioDeviceStatus()");
|
||||
SDLTest_AssertCheck(result == SDL_AUDIO_STOPPED || result == SDL_AUDIO_PLAYING || result == SDL_AUDIO_PAUSED,
|
||||
"Verify returned value; expected: STOPPED (%i) | PLAYING (%i) | PAUSED (%i), got: %i",
|
||||
SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED, result);
|
||||
|
||||
/* Close device again */
|
||||
SDL_CloseAudioDevice(id);
|
||||
SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SDLTest_Log("No devices to test with");
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Locks and unlocks open audio device.
|
||||
*
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_LockAudioDevice
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_UnlockAudioDevice
|
||||
*/
|
||||
int audio_lockUnlockOpenAudioDevice()
|
||||
{
|
||||
int i;
|
||||
int count;
|
||||
char *device;
|
||||
SDL_AudioDeviceID id;
|
||||
SDL_AudioSpec desired, obtained;
|
||||
|
||||
/* Get number of devices. */
|
||||
count = SDL_GetNumAudioDevices(0);
|
||||
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
|
||||
if (count > 0) {
|
||||
for (i = 0; i < count; i++) {
|
||||
/* Get device name */
|
||||
device = (char *)SDL_GetAudioDeviceName(i, 0);
|
||||
SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
|
||||
SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
|
||||
if (device == NULL) return TEST_ABORTED;
|
||||
|
||||
/* Set standard desired spec */
|
||||
desired.freq=22050;
|
||||
desired.format=AUDIO_S16SYS;
|
||||
desired.channels=2;
|
||||
desired.samples=4096;
|
||||
desired.callback=_audio_testCallback;
|
||||
desired.userdata=NULL;
|
||||
|
||||
/* Open device */
|
||||
id = SDL_OpenAudioDevice((const char *)device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
|
||||
SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
|
||||
SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >=2, got: %i", id);
|
||||
if (id > 1) {
|
||||
/* Lock to protect callback */
|
||||
SDL_LockAudioDevice(id);
|
||||
SDLTest_AssertPass("SDL_LockAudioDevice(%i)", id);
|
||||
|
||||
/* Simulate callback processing */
|
||||
SDL_Delay(10);
|
||||
SDLTest_Log("Simulate callback processing - delay");
|
||||
|
||||
/* Unlock again */
|
||||
SDL_UnlockAudioDevice(id);
|
||||
SDLTest_AssertPass("SDL_UnlockAudioDevice(%i)", id);
|
||||
|
||||
/* Close device again */
|
||||
SDL_CloseAudioDevice(id);
|
||||
SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SDLTest_Log("No devices to test with");
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Convert audio using various conversion structures
|
||||
*
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_BuildAudioCVT
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_ConvertAudio
|
||||
*/
|
||||
int audio_convertAudio()
|
||||
{
|
||||
int result;
|
||||
SDL_AudioCVT cvt;
|
||||
SDL_AudioSpec spec1;
|
||||
SDL_AudioSpec spec2;
|
||||
int c;
|
||||
char message[128];
|
||||
int i, ii, j, jj, k, kk, l, ll;
|
||||
|
||||
/* Iterate over bitmask that determines which parameters are modified in the conversion */
|
||||
for (c = 1; c < 8; c++) {
|
||||
SDL_strlcpy(message, "Changing:", 128);
|
||||
if (c & 1) {
|
||||
SDL_strlcat(message, " Format", 128);
|
||||
}
|
||||
if (c & 2) {
|
||||
SDL_strlcat(message, " Channels", 128);
|
||||
}
|
||||
if (c & 4) {
|
||||
SDL_strlcat(message, " Frequencies", 128);
|
||||
}
|
||||
SDLTest_Log(message);
|
||||
/* All source conversions with random conversion targets */
|
||||
for (i = 0; i < _numAudioFormats; i++) {
|
||||
for (j = 0; j < _numAudioChannels; j++) {
|
||||
for (k = 0; k < _numAudioFrequencies; k++) {
|
||||
spec1.format = _audioFormats[i];
|
||||
spec1.channels = _audioChannels[j];
|
||||
spec1.freq = _audioFrequencies[k];
|
||||
|
||||
/* Ensure we have a different target format */
|
||||
do {
|
||||
if (c & 1) {
|
||||
ii = SDLTest_RandomIntegerInRange(0, _numAudioFormats - 1);
|
||||
} else {
|
||||
ii = 1;
|
||||
}
|
||||
if (c & 2) {
|
||||
jj = SDLTest_RandomIntegerInRange(0, _numAudioChannels - 1);
|
||||
} else {
|
||||
jj= j;
|
||||
}
|
||||
if (c & 4) {
|
||||
kk = SDLTest_RandomIntegerInRange(0, _numAudioFrequencies - 1);
|
||||
} else {
|
||||
kk = k;
|
||||
}
|
||||
} while ((i == ii) && (j == jj) && (k == kk));
|
||||
spec2.format = _audioFormats[ii];
|
||||
spec2.channels = _audioChannels[jj];
|
||||
spec2.freq = _audioFrequencies[kk];
|
||||
|
||||
result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
|
||||
spec2.format, spec2.channels, spec2.freq);
|
||||
SDLTest_AssertPass("Call to SDL_BuildAudioCVT(format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i ==> format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i)",
|
||||
i, _audioFormatsVerbose[i], spec1.format, j, spec1.channels, k, spec1.freq, ii, _audioFormatsVerbose[ii], spec2.format, jj, spec2.channels, kk, spec2.freq);
|
||||
SDLTest_AssertCheck(result == 1, "Verify result value; expected: 1, got: %i", result);
|
||||
if (result != 1) {
|
||||
SDLTest_LogError(SDL_GetError());
|
||||
} else {
|
||||
SDLTest_AssertCheck(cvt.len_mult > 0, "Verify that cvt.len_mult value; expected: >0, got: %i", cvt.len_mult);
|
||||
if (cvt.len_mult < 1) return TEST_ABORTED;
|
||||
|
||||
/* Create some random data to convert */
|
||||
l = 64;
|
||||
ll = l * cvt.len_mult;
|
||||
SDLTest_Log("Creating dummy sample buffer of %i length (%i bytes)", l, ll);
|
||||
cvt.len = l;
|
||||
cvt.buf = (Uint8 *)SDL_malloc(ll);
|
||||
SDLTest_AssertCheck(cvt.buf != NULL, "Check data buffer to convert is not NULL");
|
||||
if (cvt.buf == NULL) return TEST_ABORTED;
|
||||
|
||||
/* Convert the data */
|
||||
result = SDL_ConvertAudio(&cvt);
|
||||
SDLTest_AssertPass("Call to SDL_ConvertAudio()");
|
||||
SDLTest_AssertCheck(result == 0, "Verify result value; expected: 0; got: %i", result);
|
||||
SDLTest_AssertCheck(cvt.buf != NULL, "Verify conversion buffer is not NULL");
|
||||
SDLTest_AssertCheck(cvt.len_ratio > 0.0, "Verify conversion length ratio; expected: >0; got: %f", cvt.len_ratio);
|
||||
|
||||
/* Free converted buffer */
|
||||
SDL_free(cvt.buf);
|
||||
cvt.buf = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Opens, checks current connected status, and closes a device.
|
||||
*
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_AudioDeviceConnected
|
||||
*/
|
||||
int audio_openCloseAudioDeviceConnected()
|
||||
{
|
||||
int result = -1;
|
||||
int i;
|
||||
int count;
|
||||
char *device;
|
||||
SDL_AudioDeviceID id;
|
||||
SDL_AudioSpec desired, obtained;
|
||||
|
||||
/* Get number of devices. */
|
||||
count = SDL_GetNumAudioDevices(0);
|
||||
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
|
||||
if (count > 0) {
|
||||
for (i = 0; i < count; i++) {
|
||||
/* Get device name */
|
||||
device = (char *)SDL_GetAudioDeviceName(i, 0);
|
||||
SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
|
||||
SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
|
||||
if (device == NULL) return TEST_ABORTED;
|
||||
|
||||
/* Set standard desired spec */
|
||||
desired.freq=22050;
|
||||
desired.format=AUDIO_S16SYS;
|
||||
desired.channels=2;
|
||||
desired.samples=4096;
|
||||
desired.callback=_audio_testCallback;
|
||||
desired.userdata=NULL;
|
||||
|
||||
/* Open device */
|
||||
id = SDL_OpenAudioDevice((const char *)device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
|
||||
SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
|
||||
SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >1, got: %i", id);
|
||||
if (id > 1) {
|
||||
|
||||
/* TODO: enable test code when function is available in SDL2 */
|
||||
|
||||
#ifdef AUDIODEVICECONNECTED_DEFINED
|
||||
/* Get connected status */
|
||||
result = SDL_AudioDeviceConnected(id);
|
||||
SDLTest_AssertPass("Call to SDL_AudioDeviceConnected()");
|
||||
#endif
|
||||
SDLTest_AssertCheck(result == 1, "Verify returned value; expected: 1; got: %i", result);
|
||||
|
||||
/* Close device again */
|
||||
SDL_CloseAudioDevice(id);
|
||||
SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SDLTest_Log("No devices to test with");
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ================= Test Case References ================== */
|
||||
|
||||
/* Audio test cases */
|
||||
static const SDLTest_TestCaseReference audioTest1 =
|
||||
{ (SDLTest_TestCaseFp)audio_enumerateAndNameAudioDevices, "audio_enumerateAndNameAudioDevices", "Enumerate and name available audio devices (output and capture)", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference audioTest2 =
|
||||
{ (SDLTest_TestCaseFp)audio_enumerateAndNameAudioDevicesNegativeTests, "audio_enumerateAndNameAudioDevicesNegativeTests", "Negative tests around enumeration and naming of audio devices.", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference audioTest3 =
|
||||
{ (SDLTest_TestCaseFp)audio_printAudioDrivers, "audio_printAudioDrivers", "Checks available audio driver names.", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference audioTest4 =
|
||||
{ (SDLTest_TestCaseFp)audio_printCurrentAudioDriver, "audio_printCurrentAudioDriver", "Checks current audio driver name with initialized audio.", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference audioTest5 =
|
||||
{ (SDLTest_TestCaseFp)audio_buildAudioCVT, "audio_buildAudioCVT", "Builds various audio conversion structures.", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference audioTest6 =
|
||||
{ (SDLTest_TestCaseFp)audio_buildAudioCVTNegative, "audio_buildAudioCVTNegative", "Checks calls with invalid input to SDL_BuildAudioCVT", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference audioTest7 =
|
||||
{ (SDLTest_TestCaseFp)audio_getAudioStatus, "audio_getAudioStatus", "Checks current audio status.", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference audioTest8 =
|
||||
{ (SDLTest_TestCaseFp)audio_openCloseAndGetAudioStatus, "audio_openCloseAndGetAudioStatus", "Opens and closes audio device and get audio status.", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference audioTest9 =
|
||||
{ (SDLTest_TestCaseFp)audio_lockUnlockOpenAudioDevice, "audio_lockUnlockOpenAudioDevice", "Locks and unlocks an open audio device.", TEST_ENABLED };
|
||||
|
||||
/* TODO: enable test when SDL_ConvertAudio segfaults on cygwin have been fixed. */
|
||||
/* For debugging, test case can be run manually using --filter audio_convertAudio */
|
||||
|
||||
static const SDLTest_TestCaseReference audioTest10 =
|
||||
{ (SDLTest_TestCaseFp)audio_convertAudio, "audio_convertAudio", "Convert audio using available formats.", TEST_DISABLED };
|
||||
|
||||
/* TODO: enable test when SDL_AudioDeviceConnected has been implemented. */
|
||||
|
||||
static const SDLTest_TestCaseReference audioTest11 =
|
||||
{ (SDLTest_TestCaseFp)audio_openCloseAudioDeviceConnected, "audio_openCloseAudioDeviceConnected", "Opens and closes audio device and get connected status.", TEST_DISABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference audioTest12 =
|
||||
{ (SDLTest_TestCaseFp)audio_quitInitAudioSubSystem, "audio_quitInitAudioSubSystem", "Quit and re-init audio subsystem.", TEST_ENABLED };
|
||||
|
||||
/* TODO: enable when bugs 1343 and 1396 are fixed. */
|
||||
/* For debugging, test case can be run manually using --filter audio_initQuitAudio */
|
||||
|
||||
static const SDLTest_TestCaseReference audioTest13 =
|
||||
{ (SDLTest_TestCaseFp)audio_initQuitAudio, "audio_initQuitAudio", "Init and quit audio drivers directly.", TEST_DISABLED };
|
||||
|
||||
/* TODO: enable when bugs 1343 and 1396 are fixed. */
|
||||
/* For debugging, test case can be run manually using --filter audio_initOpenCloseQuitAudio */
|
||||
|
||||
static const SDLTest_TestCaseReference audioTest14 =
|
||||
{ (SDLTest_TestCaseFp)audio_initOpenCloseQuitAudio, "audio_initOpenCloseQuitAudio", "Cycle through init, open, close and quit with various audio specs.", TEST_DISABLED };
|
||||
|
||||
/* Sequence of Audio test cases */
|
||||
static const SDLTest_TestCaseReference *audioTests[] = {
|
||||
&audioTest1, &audioTest2, &audioTest3, &audioTest4, &audioTest5, &audioTest6,
|
||||
&audioTest7, &audioTest8, &audioTest9, &audioTest10, &audioTest11,
|
||||
&audioTest12, &audioTest13, &audioTest14, NULL
|
||||
};
|
||||
|
||||
/* Audio test suite (global) */
|
||||
SDLTest_TestSuiteReference audioTestSuite = {
|
||||
"Audio",
|
||||
_audioSetUp,
|
||||
audioTests,
|
||||
NULL
|
||||
};
|
182
test/testautomation_clipboard.c
Normal file
@@ -0,0 +1,182 @@
|
||||
/**
|
||||
* New/updated tests: aschiffler at ferzkopp dot net
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_test.h"
|
||||
|
||||
/* ================= Test Case Implementation ================== */
|
||||
|
||||
/* Test case functions */
|
||||
|
||||
/**
|
||||
* \brief Check call to SDL_HasClipboardText
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasClipboardText
|
||||
*/
|
||||
int
|
||||
clipboard_testHasClipboardText(void *arg)
|
||||
{
|
||||
SDL_bool result;
|
||||
result = SDL_HasClipboardText();
|
||||
SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Check call to SDL_GetClipboardText
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetClipboardText
|
||||
*/
|
||||
int
|
||||
clipboard_testGetClipboardText(void *arg)
|
||||
{
|
||||
char *charResult;
|
||||
charResult = SDL_GetClipboardText();
|
||||
SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
|
||||
|
||||
SDL_free(charResult);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Check call to SDL_SetClipboardText
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetClipboardText
|
||||
*/
|
||||
int
|
||||
clipboard_testSetClipboardText(void *arg)
|
||||
{
|
||||
char *textRef = SDLTest_RandomAsciiString();
|
||||
char *text = SDL_strdup(textRef);
|
||||
int result;
|
||||
result = SDL_SetClipboardText((const char *)text);
|
||||
SDLTest_AssertPass("Call to SDL_SetClipboardText succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
result == 0,
|
||||
"Validate SDL_SetClipboardText result, expected 0, got %i",
|
||||
result);
|
||||
SDLTest_AssertCheck(
|
||||
SDL_strcmp(textRef, text) == 0,
|
||||
"Verify SDL_SetClipboardText did not modify input string, expected '%s', got '%s'",
|
||||
textRef, text);
|
||||
|
||||
/* Cleanup */
|
||||
SDL_free(textRef);
|
||||
SDL_free(text);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief End-to-end test of SDL_xyzClipboardText functions
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasClipboardText
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetClipboardText
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetClipboardText
|
||||
*/
|
||||
int
|
||||
clipboard_testClipboardTextFunctions(void *arg)
|
||||
{
|
||||
char *textRef = SDLTest_RandomAsciiString();
|
||||
char *text = SDL_strdup(textRef);
|
||||
SDL_bool boolResult;
|
||||
int intResult;
|
||||
char *charResult;
|
||||
|
||||
/* Clear clipboard text state */
|
||||
boolResult = SDL_HasClipboardText();
|
||||
SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
|
||||
if (boolResult == SDL_TRUE) {
|
||||
intResult = SDL_SetClipboardText((const char *)NULL);
|
||||
SDLTest_AssertPass("Call to SDL_SetClipboardText(NULL) succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
intResult == 0,
|
||||
"Verify result from SDL_SetClipboardText(NULL), expected 0, got %i",
|
||||
intResult);
|
||||
charResult = SDL_GetClipboardText();
|
||||
SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
|
||||
boolResult = SDL_HasClipboardText();
|
||||
SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
boolResult == SDL_FALSE,
|
||||
"Verify SDL_HasClipboardText returned SDL_FALSE, got %s",
|
||||
(boolResult) ? "SDL_TRUE" : "SDL_FALSE");
|
||||
}
|
||||
|
||||
/* Empty clipboard */
|
||||
charResult = SDL_GetClipboardText();
|
||||
SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
charResult != NULL,
|
||||
"Verify SDL_GetClipboardText did not return NULL");
|
||||
SDLTest_AssertCheck(
|
||||
charResult[0] == '\0',
|
||||
"Verify SDL_GetClipboardText returned string with length 0, got length %i",
|
||||
SDL_strlen(charResult));
|
||||
intResult = SDL_SetClipboardText((const char *)text);
|
||||
SDLTest_AssertPass("Call to SDL_SetClipboardText succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
intResult == 0,
|
||||
"Verify result from SDL_SetClipboardText(NULL), expected 0, got %i",
|
||||
intResult);
|
||||
SDLTest_AssertCheck(
|
||||
SDL_strcmp(textRef, text) == 0,
|
||||
"Verify SDL_SetClipboardText did not modify input string, expected '%s', got '%s'",
|
||||
textRef, text);
|
||||
boolResult = SDL_HasClipboardText();
|
||||
SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
boolResult == SDL_TRUE,
|
||||
"Verify SDL_HasClipboardText returned SDL_TRUE, got %s",
|
||||
(boolResult) ? "SDL_TRUE" : "SDL_FALSE");
|
||||
charResult = SDL_GetClipboardText();
|
||||
SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
SDL_strcmp(textRef, charResult) == 0,
|
||||
"Verify SDL_GetClipboardText returned correct string, expected '%s', got '%s'",
|
||||
textRef, charResult);
|
||||
|
||||
/* Cleanup */
|
||||
SDL_free(textRef);
|
||||
SDL_free(text);
|
||||
SDL_free(charResult);
|
||||
|
||||
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 clipboardTest2 =
|
||||
{ (SDLTest_TestCaseFp)clipboard_testGetClipboardText, "clipboard_testGetClipboardText", "Check call to SDL_GetClipboardText", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference clipboardTest3 =
|
||||
{ (SDLTest_TestCaseFp)clipboard_testSetClipboardText, "clipboard_testSetClipboardText", "Check call to SDL_SetClipboardText", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference clipboardTest4 =
|
||||
{ (SDLTest_TestCaseFp)clipboard_testClipboardTextFunctions, "clipboard_testClipboardTextFunctions", "End-to-end test of SDL_xyzClipboardText functions", TEST_ENABLED };
|
||||
|
||||
/* Sequence of Clipboard test cases */
|
||||
static const SDLTest_TestCaseReference *clipboardTests[] = {
|
||||
&clipboardTest1, &clipboardTest2, &clipboardTest3, &clipboardTest4, NULL
|
||||
};
|
||||
|
||||
/* Clipboard test suite (global) */
|
||||
SDLTest_TestSuiteReference clipboardTestSuite = {
|
||||
"Clipboard",
|
||||
NULL,
|
||||
clipboardTests,
|
||||
NULL
|
||||
};
|
201
test/testautomation_events.c
Normal file
@@ -0,0 +1,201 @@
|
||||
/**
|
||||
* Events test suite
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_test.h"
|
||||
|
||||
/* ================= Test Case Implementation ================== */
|
||||
|
||||
/* Test case functions */
|
||||
|
||||
/* Flag indicating if the userdata should be checked */
|
||||
int _userdataCheck = 0;
|
||||
|
||||
/* Userdata value to check */
|
||||
int _userdataValue = 0;
|
||||
|
||||
/* Flag indicating that the filter was called */
|
||||
int _eventFilterCalled = 0;
|
||||
|
||||
/* Userdata values for event */
|
||||
int _userdataValue1 = 1;
|
||||
int _userdataValue2 = 2;
|
||||
|
||||
/* Event filter that sets some flags and optionally checks userdata */
|
||||
int _events_sampleNullEventFilter(void *userdata, SDL_Event *event)
|
||||
{
|
||||
_eventFilterCalled = 1;
|
||||
|
||||
if (_userdataCheck != 0) {
|
||||
SDLTest_AssertCheck(userdata != NULL, "Check userdata pointer, expected: non-NULL, got: %s", (userdata != NULL) ? "non-NULL" : "NULL");
|
||||
if (userdata != NULL) {
|
||||
SDLTest_AssertCheck(*(int *)userdata == _userdataValue, "Check userdata value, expected: %i, got: %i", _userdataValue, *(int *)userdata);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test pumping and peeking events.
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_PumpEvents
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_PollEvent
|
||||
*/
|
||||
int
|
||||
events_pushPumpAndPollUserevent(void *arg)
|
||||
{
|
||||
SDL_Event event1;
|
||||
SDL_Event event2;
|
||||
int result;
|
||||
|
||||
/* Create user event */
|
||||
event1.type = SDL_USEREVENT;
|
||||
event1.user.code = SDLTest_RandomSint32();
|
||||
event1.user.data1 = (void *)&_userdataValue1;
|
||||
event1.user.data2 = (void *)&_userdataValue2;
|
||||
|
||||
/* Push a user event onto the queue and force queue update */
|
||||
SDL_PushEvent(&event1);
|
||||
SDLTest_AssertPass("Call to SDL_PushEvent()");
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("Call to SDL_PumpEvents()");
|
||||
|
||||
/* Poll for user event */
|
||||
result = SDL_PollEvent(&event2);
|
||||
SDLTest_AssertPass("Call to SDL_PollEvent()");
|
||||
SDLTest_AssertCheck(result == 1, "Check result from SDL_PollEvent, expected: 1, got: %d", result);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Adds and deletes an event watch function with NULL userdata
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_AddEventWatch
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_DelEventWatch
|
||||
*
|
||||
*/
|
||||
int
|
||||
events_addDelEventWatch(void *arg)
|
||||
{
|
||||
SDL_Event event;
|
||||
|
||||
/* Create user event */
|
||||
event.type = SDL_USEREVENT;
|
||||
event.user.code = SDLTest_RandomSint32();;
|
||||
event.user.data1 = (void *)&_userdataValue1;
|
||||
event.user.data2 = (void *)&_userdataValue2;
|
||||
|
||||
/* Disable userdata check */
|
||||
_userdataCheck = 0;
|
||||
|
||||
/* Reset event filter call tracker */
|
||||
_eventFilterCalled = 0;
|
||||
|
||||
/* 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");
|
||||
|
||||
/* 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");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Adds and deletes an event watch function with userdata
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_AddEventWatch
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_DelEventWatch
|
||||
*
|
||||
*/
|
||||
int
|
||||
events_addDelEventWatchWithUserdata(void *arg)
|
||||
{
|
||||
SDL_Event event;
|
||||
|
||||
/* Create user event */
|
||||
event.type = SDL_USEREVENT;
|
||||
event.user.code = SDLTest_RandomSint32();;
|
||||
event.user.data1 = (void *)&_userdataValue1;
|
||||
event.user.data2 = (void *)&_userdataValue2;
|
||||
|
||||
/* Enable userdata check and set a value to check */
|
||||
_userdataCheck = 1;
|
||||
_userdataValue = SDLTest_RandomIntegerInRange(-1024, 1024);
|
||||
|
||||
/* Reset event filter call tracker */
|
||||
_eventFilterCalled = 0;
|
||||
|
||||
/* Add watch */
|
||||
SDL_AddEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
|
||||
SDLTest_AssertPass("Call to SDL_AddEventWatch()");
|
||||
|
||||
/* Push a user event onto the queue and force queue update */
|
||||
SDL_PushEvent(&event);
|
||||
SDLTest_AssertPass("Call to SDL_PushEvent()");
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("Call to SDL_PumpEvents()");
|
||||
SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
|
||||
|
||||
/* Delete watch */
|
||||
SDL_DelEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
|
||||
SDLTest_AssertPass("Call to SDL_DelEventWatch()");
|
||||
|
||||
/* Push a user event onto the queue and force queue update */
|
||||
_eventFilterCalled = 0;
|
||||
SDL_PushEvent(&event);
|
||||
SDLTest_AssertPass("Call to SDL_PushEvent()");
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("Call to SDL_PumpEvents()");
|
||||
SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
/* ================= 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 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 };
|
||||
|
||||
/* Sequence of Events test cases */
|
||||
static const SDLTest_TestCaseReference *eventsTests[] = {
|
||||
&eventsTest1, &eventsTest2, &eventsTest3, NULL
|
||||
};
|
||||
|
||||
/* Events test suite (global) */
|
||||
SDLTest_TestSuiteReference eventsTestSuite = {
|
||||
"Events",
|
||||
NULL,
|
||||
eventsTests,
|
||||
NULL
|
||||
};
|
168
test/testautomation_hints.c
Normal file
@@ -0,0 +1,168 @@
|
||||
/**
|
||||
* Hints test suite
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_test.h"
|
||||
|
||||
|
||||
const int _numHintsEnum = 25;
|
||||
char* _HintsEnum[] =
|
||||
{
|
||||
SDL_HINT_ACCELEROMETER_AS_JOYSTICK,
|
||||
SDL_HINT_FRAMEBUFFER_ACCELERATION,
|
||||
SDL_HINT_GAMECONTROLLERCONFIG,
|
||||
SDL_HINT_GRAB_KEYBOARD,
|
||||
SDL_HINT_IDLE_TIMER_DISABLED,
|
||||
SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,
|
||||
SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK,
|
||||
SDL_HINT_MOUSE_RELATIVE_MODE_WARP,
|
||||
SDL_HINT_ORIENTATIONS,
|
||||
SDL_HINT_RENDER_DIRECT3D_THREADSAFE,
|
||||
SDL_HINT_RENDER_DRIVER,
|
||||
SDL_HINT_RENDER_OPENGL_SHADERS,
|
||||
SDL_HINT_RENDER_SCALE_QUALITY,
|
||||
SDL_HINT_RENDER_VSYNC,
|
||||
SDL_HINT_TIMER_RESOLUTION,
|
||||
SDL_HINT_VIDEO_ALLOW_SCREENSAVER,
|
||||
SDL_HINT_VIDEO_HIGHDPI_DISABLED,
|
||||
SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES,
|
||||
SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
|
||||
SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT,
|
||||
SDL_HINT_VIDEO_WIN_D3DCOMPILER,
|
||||
SDL_HINT_VIDEO_X11_XINERAMA,
|
||||
SDL_HINT_VIDEO_X11_XRANDR,
|
||||
SDL_HINT_VIDEO_X11_XVIDMODE,
|
||||
SDL_HINT_XINPUT_ENABLED,
|
||||
};
|
||||
char* _HintsVerbose[] =
|
||||
{
|
||||
"SDL_HINT_ACCELEROMETER_AS_JOYSTICK",
|
||||
"SDL_HINT_FRAMEBUFFER_ACCELERATION",
|
||||
"SDL_HINT_GAMECONTROLLERCONFIG",
|
||||
"SDL_HINT_GRAB_KEYBOARD",
|
||||
"SDL_HINT_IDLE_TIMER_DISABLED",
|
||||
"SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS",
|
||||
"SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK",
|
||||
"SDL_HINT_MOUSE_RELATIVE_MODE_WARP",
|
||||
"SDL_HINT_ORIENTATIONS",
|
||||
"SDL_HINT_RENDER_DIRECT3D_THREADSAFE",
|
||||
"SDL_HINT_RENDER_DRIVER",
|
||||
"SDL_HINT_RENDER_OPENGL_SHADERS",
|
||||
"SDL_HINT_RENDER_SCALE_QUALITY",
|
||||
"SDL_HINT_RENDER_VSYNC",
|
||||
"SDL_HINT_TIMER_RESOLUTION",
|
||||
"SDL_HINT_VIDEO_ALLOW_SCREENSAVER",
|
||||
"SDL_HINT_VIDEO_HIGHDPI_DISABLED",
|
||||
"SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES",
|
||||
"SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS",
|
||||
"SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT",
|
||||
"SDL_HINT_VIDEO_WIN_D3DCOMPILER",
|
||||
"SDL_HINT_VIDEO_X11_XINERAMA",
|
||||
"SDL_HINT_VIDEO_X11_XRANDR",
|
||||
"SDL_HINT_VIDEO_X11_XVIDMODE",
|
||||
"SDL_HINT_XINPUT_ENABLED"
|
||||
};
|
||||
|
||||
|
||||
/* Test case functions */
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_GetHint
|
||||
*/
|
||||
int
|
||||
hints_getHint(void *arg)
|
||||
{
|
||||
char *result1;
|
||||
char *result2;
|
||||
int i;
|
||||
|
||||
for (i=0; i<_numHintsEnum; i++) {
|
||||
result1 = (char *)SDL_GetHint((char*)_HintsEnum[i]);
|
||||
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using define definition", (char*)_HintsEnum[i]);
|
||||
result2 = (char *)SDL_GetHint((char *)_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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_SetHint
|
||||
*/
|
||||
int
|
||||
hints_setHint(void *arg)
|
||||
{
|
||||
char *originalValue;
|
||||
char *value;
|
||||
char *testValue;
|
||||
SDL_bool result;
|
||||
int i, j;
|
||||
|
||||
/* Create random values to set */
|
||||
value = SDLTest_RandomAsciiStringOfSize(10);
|
||||
|
||||
for (i=0; i<_numHintsEnum; i++) {
|
||||
/* Capture current value */
|
||||
originalValue = (char *)SDL_GetHint((char*)_HintsEnum[i]);
|
||||
SDLTest_AssertPass("Call to SDL_GetHint(%s)", (char*)_HintsEnum[i]);
|
||||
|
||||
/* Set value (twice) */
|
||||
for (j=1; j<=2; j++) {
|
||||
result = SDL_SetHint((char*)_HintsEnum[i], value);
|
||||
SDLTest_AssertPass("Call to SDL_SetHint(%s, %s) (iteration %i)", (char*)_HintsEnum[i], value, j);
|
||||
SDLTest_AssertCheck(
|
||||
result == SDL_TRUE || result == SDL_FALSE,
|
||||
"Verify valid result was returned, got: %i",
|
||||
(int)result);
|
||||
testValue = (char *)SDL_GetHint((char*)_HintsEnum[i]);
|
||||
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char*)_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((char*)_HintsEnum[i], originalValue);
|
||||
SDLTest_AssertPass("Call to SDL_SetHint(%s, originalValue)", (char*)_HintsEnum[i]);
|
||||
SDLTest_AssertCheck(
|
||||
result == SDL_TRUE || result == SDL_FALSE,
|
||||
"Verify valid result was returned, got: %i",
|
||||
(int)result);
|
||||
}
|
||||
|
||||
SDL_free(value);
|
||||
|
||||
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 hintsTest2 =
|
||||
{ (SDLTest_TestCaseFp)hints_setHint, "hints_setHint", "Call to SDL_SetHint", TEST_ENABLED };
|
||||
|
||||
/* Sequence of Hints test cases */
|
||||
static const SDLTest_TestCaseReference *hintsTests[] = {
|
||||
&hintsTest1, &hintsTest2, NULL
|
||||
};
|
||||
|
||||
/* Hints test suite (global) */
|
||||
SDLTest_TestSuiteReference hintsTestSuite = {
|
||||
"Hints",
|
||||
NULL,
|
||||
hintsTests,
|
||||
NULL
|
||||
};
|
713
test/testautomation_keyboard.c
Normal file
@@ -0,0 +1,713 @@
|
||||
/**
|
||||
* Keyboard test suite
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "SDL_config.h"
|
||||
#include "SDL.h"
|
||||
#include "SDL_test.h"
|
||||
|
||||
/* ================= Test Case Implementation ================== */
|
||||
|
||||
/* Test case functions */
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_GetKeyboardState with and without numkeys reference.
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyboardState
|
||||
*/
|
||||
int
|
||||
keyboard_getKeyboardState(void *arg)
|
||||
{
|
||||
int numkeys;
|
||||
Uint8 *state;
|
||||
|
||||
/* Case where numkeys pointer is NULL */
|
||||
state = (Uint8 *)SDL_GetKeyboardState(NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyboardState(NULL)");
|
||||
SDLTest_AssertCheck(state != NULL, "Validate that return value from SDL_GetKeyboardState is not NULL");
|
||||
|
||||
/* Case where numkeys pointer is not NULL */
|
||||
numkeys = -1;
|
||||
state = (Uint8 *)SDL_GetKeyboardState(&numkeys);
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyboardState(&numkeys)");
|
||||
SDLTest_AssertCheck(state != NULL, "Validate that return value from SDL_GetKeyboardState is not NULL");
|
||||
SDLTest_AssertCheck(numkeys >= 0, "Validate that value of numkeys is >= 0, got: %i", numkeys);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_GetKeyboardFocus
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyboardFocus
|
||||
*/
|
||||
int
|
||||
keyboard_getKeyboardFocus(void *arg)
|
||||
{
|
||||
SDL_Window* window;
|
||||
|
||||
/* Call, but ignore return value */
|
||||
window = SDL_GetKeyboardFocus();
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyboardFocus()");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_GetKeyFromName for known, unknown and invalid name.
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyFromName
|
||||
*/
|
||||
int
|
||||
keyboard_getKeyFromName(void *arg)
|
||||
{
|
||||
SDL_Keycode result;
|
||||
|
||||
/* Case where Key is known, 1 character input */
|
||||
result = SDL_GetKeyFromName("A");
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/single)");
|
||||
SDLTest_AssertCheck(result == SDLK_a, "Verify result from call, expected: %i, got: %i", SDLK_a, result);
|
||||
|
||||
/* Case where Key is known, 2 character input */
|
||||
result = SDL_GetKeyFromName("F1");
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/double)");
|
||||
SDLTest_AssertCheck(result == SDLK_F1, "Verify result from call, expected: %i, got: %i", SDLK_F1, result);
|
||||
|
||||
/* Case where Key is known, 3 character input */
|
||||
result = SDL_GetKeyFromName("End");
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/triple)");
|
||||
SDLTest_AssertCheck(result == SDLK_END, "Verify result from call, expected: %i, got: %i", SDLK_END, result);
|
||||
|
||||
/* Case where Key is known, 4 character input */
|
||||
result = SDL_GetKeyFromName("Find");
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/quad)");
|
||||
SDLTest_AssertCheck(result == SDLK_FIND, "Verify result from call, expected: %i, got: %i", SDLK_FIND, result);
|
||||
|
||||
/* Case where Key is known, multiple character input */
|
||||
result = SDL_GetKeyFromName("AudioStop");
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/multi)");
|
||||
SDLTest_AssertCheck(result == SDLK_AUDIOSTOP, "Verify result from call, expected: %i, got: %i", SDLK_AUDIOSTOP, result);
|
||||
|
||||
/* Case where Key is unknown */
|
||||
result = SDL_GetKeyFromName("NotThere");
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyFromName(unknown)");
|
||||
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
|
||||
|
||||
/* Case where input is NULL/invalid */
|
||||
result = SDL_GetKeyFromName(NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyFromName(NULL)");
|
||||
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/*
|
||||
* Local helper to check for the invalid scancode error message
|
||||
*/
|
||||
void
|
||||
_checkInvalidScancodeError()
|
||||
{
|
||||
const char *expectedError = "Parameter 'scancode' is invalid";
|
||||
const char *error;
|
||||
error = SDL_GetError();
|
||||
SDLTest_AssertPass("Call to SDL_GetError()");
|
||||
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
|
||||
if (error != NULL) {
|
||||
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
|
||||
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_GetKeyFromScancode
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyFromScancode
|
||||
*/
|
||||
int
|
||||
keyboard_getKeyFromScancode(void *arg)
|
||||
{
|
||||
SDL_Keycode result;
|
||||
|
||||
/* Case where input is valid */
|
||||
result = SDL_GetKeyFromScancode(SDL_SCANCODE_A);
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(valid)");
|
||||
SDLTest_AssertCheck(result == SDLK_a, "Verify result from call, expected: %i, got: %i", SDLK_a, result);
|
||||
|
||||
/* Case where input is zero */
|
||||
result = SDL_GetKeyFromScancode(0);
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(0)");
|
||||
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
|
||||
|
||||
/* Clear error message */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
|
||||
/* Case where input is invalid (too small) */
|
||||
result = SDL_GetKeyFromScancode(-999);
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(-999)");
|
||||
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
|
||||
_checkInvalidScancodeError();
|
||||
|
||||
/* Case where input is invalid (too big) */
|
||||
result = SDL_GetKeyFromScancode(999);
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(999)");
|
||||
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
|
||||
_checkInvalidScancodeError();
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_GetKeyName
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyName
|
||||
*/
|
||||
int
|
||||
keyboard_getKeyName(void *arg)
|
||||
{
|
||||
char *result;
|
||||
char *expected;
|
||||
|
||||
/* Case where key has a 1 character name */
|
||||
expected = "3";
|
||||
result = (char *)SDL_GetKeyName(SDLK_3);
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyName()");
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
|
||||
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
|
||||
|
||||
/* Case where key has a 2 character name */
|
||||
expected = "F1";
|
||||
result = (char *)SDL_GetKeyName(SDLK_F1);
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyName()");
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
|
||||
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
|
||||
|
||||
/* Case where key has a 3 character name */
|
||||
expected = "Cut";
|
||||
result = (char *)SDL_GetKeyName(SDLK_CUT);
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyName()");
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
|
||||
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
|
||||
|
||||
/* Case where key has a 4 character name */
|
||||
expected = "Down";
|
||||
result = (char *)SDL_GetKeyName(SDLK_DOWN);
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyName()");
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
|
||||
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
|
||||
|
||||
/* Case where key has a N character name */
|
||||
expected = "BrightnessUp";
|
||||
result = (char *)SDL_GetKeyName(SDLK_BRIGHTNESSUP);
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyName()");
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
|
||||
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
|
||||
|
||||
/* Case where key has a N character name with space */
|
||||
expected = "Keypad MemStore";
|
||||
result = (char *)SDL_GetKeyName(SDLK_KP_MEMSTORE);
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyName()");
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
|
||||
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SDL_GetScancodeName negative cases
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeName
|
||||
*/
|
||||
int
|
||||
keyboard_getScancodeNameNegative(void *arg)
|
||||
{
|
||||
SDL_Scancode scancode;
|
||||
char *result;
|
||||
char *expected = "";
|
||||
|
||||
/* Clear error message */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
|
||||
/* Out-of-bounds scancode */
|
||||
scancode = (SDL_Scancode)SDL_NUM_SCANCODES;
|
||||
result = (char *)SDL_GetScancodeName(scancode);
|
||||
SDLTest_AssertPass("Call to SDL_GetScancodeName(%d/large)", scancode);
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
|
||||
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result);
|
||||
_checkInvalidScancodeError();
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SDL_GetKeyName negative cases
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyName
|
||||
*/
|
||||
int
|
||||
keyboard_getKeyNameNegative(void *arg)
|
||||
{
|
||||
SDL_Keycode keycode;
|
||||
char *result;
|
||||
char *expected = "";
|
||||
|
||||
/* Unknown keycode */
|
||||
keycode = SDLK_UNKNOWN;
|
||||
result = (char *)SDL_GetKeyName(keycode);
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyName(%d/unknown)", keycode);
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
|
||||
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result);
|
||||
|
||||
/* Clear error message */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
|
||||
/* Negative keycode */
|
||||
keycode = (SDL_Keycode)SDLTest_RandomIntegerInRange(-255, -1);
|
||||
result = (char *)SDL_GetKeyName(keycode);
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyName(%d/negative)", keycode);
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
|
||||
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result);
|
||||
_checkInvalidScancodeError();
|
||||
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_GetModState and SDL_SetModState
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetModState
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_SetModState
|
||||
*/
|
||||
int
|
||||
keyboard_getSetModState(void *arg)
|
||||
{
|
||||
SDL_Keymod result;
|
||||
SDL_Keymod currentState;
|
||||
SDL_Keymod newState;
|
||||
SDL_Keymod allStates =
|
||||
KMOD_NONE |
|
||||
KMOD_LSHIFT |
|
||||
KMOD_RSHIFT |
|
||||
KMOD_LCTRL |
|
||||
KMOD_RCTRL |
|
||||
KMOD_LALT |
|
||||
KMOD_RALT |
|
||||
KMOD_LGUI |
|
||||
KMOD_RGUI |
|
||||
KMOD_NUM |
|
||||
KMOD_CAPS |
|
||||
KMOD_MODE |
|
||||
KMOD_RESERVED;
|
||||
|
||||
/* Get state, cache for later reset */
|
||||
result = SDL_GetModState();
|
||||
SDLTest_AssertPass("Call to SDL_GetModState()");
|
||||
SDLTest_AssertCheck(result >=0 && result <= allStates, "Verify result from call is valid, expected: 0 <= result <= %i, got: %i", allStates, result);
|
||||
currentState = result;
|
||||
|
||||
/* Set random state */
|
||||
newState = SDLTest_RandomIntegerInRange(0, allStates);
|
||||
SDL_SetModState(newState);
|
||||
SDLTest_AssertPass("Call to SDL_SetModState(%i)", newState);
|
||||
result = SDL_GetModState();
|
||||
SDLTest_AssertPass("Call to SDL_GetModState()");
|
||||
SDLTest_AssertCheck(result == newState, "Verify result from call is valid, expected: %i, got: %i", newState, result);
|
||||
|
||||
/* Set zero state */
|
||||
SDL_SetModState(0);
|
||||
SDLTest_AssertPass("Call to SDL_SetModState(0)");
|
||||
result = SDL_GetModState();
|
||||
SDLTest_AssertPass("Call to SDL_GetModState()");
|
||||
SDLTest_AssertCheck(result == 0, "Verify result from call is valid, expected: 0, got: %i", result);
|
||||
|
||||
/* Revert back to cached current state if needed */
|
||||
if (currentState != 0) {
|
||||
SDL_SetModState(currentState);
|
||||
SDLTest_AssertPass("Call to SDL_SetModState(%i)", currentState);
|
||||
result = SDL_GetModState();
|
||||
SDLTest_AssertPass("Call to SDL_GetModState()");
|
||||
SDLTest_AssertCheck(result == currentState, "Verify result from call is valid, expected: %i, got: %i", currentState, result);
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_StartTextInput and SDL_StopTextInput
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_StartTextInput
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_StopTextInput
|
||||
*/
|
||||
int
|
||||
keyboard_startStopTextInput(void *arg)
|
||||
{
|
||||
/* Start-Stop */
|
||||
SDL_StartTextInput();
|
||||
SDLTest_AssertPass("Call to SDL_StartTextInput()");
|
||||
SDL_StopTextInput();
|
||||
SDLTest_AssertPass("Call to SDL_StopTextInput()");
|
||||
|
||||
/* Stop-Start */
|
||||
SDL_StartTextInput();
|
||||
SDLTest_AssertPass("Call to SDL_StartTextInput()");
|
||||
|
||||
/* Start-Start */
|
||||
SDL_StartTextInput();
|
||||
SDLTest_AssertPass("Call to SDL_StartTextInput()");
|
||||
|
||||
/* Stop-Stop */
|
||||
SDL_StopTextInput();
|
||||
SDLTest_AssertPass("Call to SDL_StopTextInput()");
|
||||
SDL_StopTextInput();
|
||||
SDLTest_AssertPass("Call to SDL_StopTextInput()");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* Internal function to test SDL_SetTextInputRect */
|
||||
void _testSetTextInputRect(SDL_Rect refRect)
|
||||
{
|
||||
SDL_Rect testRect;
|
||||
|
||||
testRect = refRect;
|
||||
SDL_SetTextInputRect(&testRect);
|
||||
SDLTest_AssertPass("Call to SDL_SetTextInputRect with refRect(x:%i,y:%i,w:%i,h:%i)", refRect.x, refRect.y, refRect.w, refRect.h);
|
||||
SDLTest_AssertCheck(
|
||||
(refRect.x == testRect.x) && (refRect.y == testRect.y) && (refRect.w == testRect.w) && (refRect.h == testRect.h),
|
||||
"Check that input data was not modified, expected: x:%i,y:%i,w:%i,h:%i, got: x:%i,y:%i,w:%i,h:%i",
|
||||
refRect.x, refRect.y, refRect.w, refRect.h,
|
||||
testRect.x, testRect.y, testRect.w, testRect.h);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_SetTextInputRect
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_SetTextInputRect
|
||||
*/
|
||||
int
|
||||
keyboard_setTextInputRect(void *arg)
|
||||
{
|
||||
SDL_Rect refRect;
|
||||
|
||||
/* Normal visible refRect, origin inside */
|
||||
refRect.x = SDLTest_RandomIntegerInRange(1, 50);;
|
||||
refRect.y = SDLTest_RandomIntegerInRange(1, 50);;
|
||||
refRect.w = SDLTest_RandomIntegerInRange(10, 50);
|
||||
refRect.h = SDLTest_RandomIntegerInRange(10, 50);
|
||||
_testSetTextInputRect(refRect);
|
||||
|
||||
/* Normal visible refRect, origin 0,0 */
|
||||
refRect.x = 0;
|
||||
refRect.y = 0;
|
||||
refRect.w = SDLTest_RandomIntegerInRange(10, 50);
|
||||
refRect.h = SDLTest_RandomIntegerInRange(10, 50);
|
||||
_testSetTextInputRect(refRect);
|
||||
|
||||
/* 1Pixel refRect */
|
||||
refRect.x = SDLTest_RandomIntegerInRange(10, 50);;
|
||||
refRect.y = SDLTest_RandomIntegerInRange(10, 50);;
|
||||
refRect.w = 1;
|
||||
refRect.h = 1;
|
||||
_testSetTextInputRect(refRect);
|
||||
|
||||
/* 0pixel refRect */
|
||||
refRect.x = 1;
|
||||
refRect.y = 1;
|
||||
refRect.w = 1;
|
||||
refRect.h = 0;
|
||||
_testSetTextInputRect(refRect);
|
||||
|
||||
/* 0pixel refRect */
|
||||
refRect.x = 1;
|
||||
refRect.y = 1;
|
||||
refRect.w = 0;
|
||||
refRect.h = 1;
|
||||
_testSetTextInputRect(refRect);
|
||||
|
||||
/* 0pixel refRect */
|
||||
refRect.x = 1;
|
||||
refRect.y = 1;
|
||||
refRect.w = 0;
|
||||
refRect.h = 0;
|
||||
_testSetTextInputRect(refRect);
|
||||
|
||||
/* 0pixel refRect */
|
||||
refRect.x = 0;
|
||||
refRect.y = 0;
|
||||
refRect.w = 0;
|
||||
refRect.h = 0;
|
||||
_testSetTextInputRect(refRect);
|
||||
|
||||
/* negative refRect */
|
||||
refRect.x = SDLTest_RandomIntegerInRange(-200, -100);;
|
||||
refRect.y = SDLTest_RandomIntegerInRange(-200, -100);;
|
||||
refRect.w = 50;
|
||||
refRect.h = 50;
|
||||
_testSetTextInputRect(refRect);
|
||||
|
||||
/* oversized refRect */
|
||||
refRect.x = SDLTest_RandomIntegerInRange(1, 50);;
|
||||
refRect.y = SDLTest_RandomIntegerInRange(1, 50);;
|
||||
refRect.w = 5000;
|
||||
refRect.h = 5000;
|
||||
_testSetTextInputRect(refRect);
|
||||
|
||||
/* NULL refRect */
|
||||
SDL_SetTextInputRect(NULL);
|
||||
SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_SetTextInputRect with invalid data
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_SetTextInputRect
|
||||
*/
|
||||
int
|
||||
keyboard_setTextInputRectNegative(void *arg)
|
||||
{
|
||||
/* Some platforms set also an error message; prepare for checking it */
|
||||
#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_COCOA
|
||||
const char *expectedError = "Parameter 'rect' is invalid";
|
||||
const char *error;
|
||||
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
#endif
|
||||
|
||||
/* NULL refRect */
|
||||
SDL_SetTextInputRect(NULL);
|
||||
SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");
|
||||
|
||||
/* Some platforms set also an error message; so check it */
|
||||
#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_COCOA
|
||||
error = SDL_GetError();
|
||||
SDLTest_AssertPass("Call to SDL_GetError()");
|
||||
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
|
||||
if (error != NULL) {
|
||||
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
|
||||
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
|
||||
}
|
||||
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
#endif
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_GetScancodeFromKey
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromKey
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
|
||||
*/
|
||||
int
|
||||
keyboard_getScancodeFromKey(void *arg)
|
||||
{
|
||||
SDL_Scancode scancode;
|
||||
|
||||
/* Regular key */
|
||||
scancode = SDL_GetScancodeFromKey(SDLK_4);
|
||||
SDLTest_AssertPass("Call to SDL_GetScancodeFromKey(SDLK_4)");
|
||||
SDLTest_AssertCheck(scancode == SDL_SCANCODE_4, "Validate return value from SDL_GetScancodeFromKey, expected: %i, got: %i", SDL_SCANCODE_4, scancode);
|
||||
|
||||
/* Virtual key */
|
||||
scancode = SDL_GetScancodeFromKey(SDLK_PLUS);
|
||||
SDLTest_AssertPass("Call to SDL_GetScancodeFromKey(SDLK_PLUS)");
|
||||
SDLTest_AssertCheck(scancode == 0, "Validate return value from SDL_GetScancodeFromKey, expected: 0, got: %i", scancode);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_GetScancodeFromName
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromName
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
|
||||
*/
|
||||
int
|
||||
keyboard_getScancodeFromName(void *arg)
|
||||
{
|
||||
SDL_Scancode scancode;
|
||||
|
||||
/* Regular key, 1 character, first name in list */
|
||||
scancode = SDL_GetScancodeFromName("A");
|
||||
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('A')");
|
||||
SDLTest_AssertCheck(scancode == SDL_SCANCODE_A, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_A, scancode);
|
||||
|
||||
/* Regular key, 1 character */
|
||||
scancode = SDL_GetScancodeFromName("4");
|
||||
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('4')");
|
||||
SDLTest_AssertCheck(scancode == SDL_SCANCODE_4, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_4, scancode);
|
||||
|
||||
/* Regular key, 2 characters */
|
||||
scancode = SDL_GetScancodeFromName("F1");
|
||||
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('F1')");
|
||||
SDLTest_AssertCheck(scancode == SDL_SCANCODE_F1, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_F1, scancode);
|
||||
|
||||
/* Regular key, 3 characters */
|
||||
scancode = SDL_GetScancodeFromName("End");
|
||||
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('End')");
|
||||
SDLTest_AssertCheck(scancode == SDL_SCANCODE_END, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_END, scancode);
|
||||
|
||||
/* Regular key, 4 characters */
|
||||
scancode = SDL_GetScancodeFromName("Find");
|
||||
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Find')");
|
||||
SDLTest_AssertCheck(scancode == SDL_SCANCODE_FIND, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_FIND, scancode);
|
||||
|
||||
/* Regular key, several characters */
|
||||
scancode = SDL_GetScancodeFromName("Backspace");
|
||||
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Backspace')");
|
||||
SDLTest_AssertCheck(scancode == SDL_SCANCODE_BACKSPACE, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_BACKSPACE, scancode);
|
||||
|
||||
/* Regular key, several characters with space */
|
||||
scancode = SDL_GetScancodeFromName("Keypad Enter");
|
||||
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Keypad Enter')");
|
||||
SDLTest_AssertCheck(scancode == SDL_SCANCODE_KP_ENTER, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_KP_ENTER, scancode);
|
||||
|
||||
/* Regular key, last name in list */
|
||||
scancode = SDL_GetScancodeFromName("Sleep");
|
||||
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Sleep')");
|
||||
SDLTest_AssertCheck(scancode == SDL_SCANCODE_SLEEP, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_SLEEP, scancode);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/*
|
||||
* Local helper to check for the invalid scancode error message
|
||||
*/
|
||||
void
|
||||
_checkInvalidNameError()
|
||||
{
|
||||
const char *expectedError = "Parameter 'name' is invalid";
|
||||
const char *error;
|
||||
error = SDL_GetError();
|
||||
SDLTest_AssertPass("Call to SDL_GetError()");
|
||||
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
|
||||
if (error != NULL) {
|
||||
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
|
||||
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_GetScancodeFromName with invalid data
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromName
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
|
||||
*/
|
||||
int
|
||||
keyboard_getScancodeFromNameNegative(void *arg)
|
||||
{
|
||||
char *name;
|
||||
SDL_Scancode scancode;
|
||||
|
||||
/* Clear error message */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
|
||||
/* Random string input */
|
||||
name = SDLTest_RandomAsciiStringOfSize(32);
|
||||
SDLTest_Assert(name != NULL, "Check that random name is not NULL");
|
||||
if (name == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
scancode = SDL_GetScancodeFromName((const char *)name);
|
||||
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('%s')", name);
|
||||
SDL_free(name);
|
||||
SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
|
||||
_checkInvalidNameError();
|
||||
|
||||
/* Zero length string input */
|
||||
name = "";
|
||||
scancode = SDL_GetScancodeFromName((const char *)name);
|
||||
SDLTest_AssertPass("Call to SDL_GetScancodeFromName(NULL)");
|
||||
SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
|
||||
_checkInvalidNameError();
|
||||
|
||||
/* NULL input */
|
||||
name = NULL;
|
||||
scancode = SDL_GetScancodeFromName((const char *)name);
|
||||
SDLTest_AssertPass("Call to SDL_GetScancodeFromName(NULL)");
|
||||
SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
|
||||
_checkInvalidNameError();
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ================= Test References ================== */
|
||||
|
||||
/* Keyboard test cases */
|
||||
static const SDLTest_TestCaseReference keyboardTest1 =
|
||||
{ (SDLTest_TestCaseFp)keyboard_getKeyboardState, "keyboard_getKeyboardState", "Check call to SDL_GetKeyboardState with and without numkeys reference", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest2 =
|
||||
{ (SDLTest_TestCaseFp)keyboard_getKeyboardFocus, "keyboard_getKeyboardFocus", "Check call to SDL_GetKeyboardFocus", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest3 =
|
||||
{ (SDLTest_TestCaseFp)keyboard_getKeyFromName, "keyboard_getKeyFromName", "Check call to SDL_GetKeyFromName for known, unknown and invalid name", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest4 =
|
||||
{ (SDLTest_TestCaseFp)keyboard_getKeyFromScancode, "keyboard_getKeyFromScancode", "Check call to SDL_GetKeyFromScancode", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest5 =
|
||||
{ (SDLTest_TestCaseFp)keyboard_getKeyName, "keyboard_getKeyName", "Check call to SDL_GetKeyName", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest6 =
|
||||
{ (SDLTest_TestCaseFp)keyboard_getSetModState, "keyboard_getSetModState", "Check call to SDL_GetModState and SDL_SetModState", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest7 =
|
||||
{ (SDLTest_TestCaseFp)keyboard_startStopTextInput, "keyboard_startStopTextInput", "Check call to SDL_StartTextInput and SDL_StopTextInput", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest8 =
|
||||
{ (SDLTest_TestCaseFp)keyboard_setTextInputRect, "keyboard_setTextInputRect", "Check call to SDL_SetTextInputRect", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest9 =
|
||||
{ (SDLTest_TestCaseFp)keyboard_setTextInputRectNegative, "keyboard_setTextInputRectNegative", "Check call to SDL_SetTextInputRect with invalid data", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest10 =
|
||||
{ (SDLTest_TestCaseFp)keyboard_getScancodeFromKey, "keyboard_getScancodeFromKey", "Check call to SDL_GetScancodeFromKey", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest11 =
|
||||
{ (SDLTest_TestCaseFp)keyboard_getScancodeFromName, "keyboard_getScancodeFromName", "Check call to SDL_GetScancodeFromName", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest12 =
|
||||
{ (SDLTest_TestCaseFp)keyboard_getScancodeFromNameNegative, "keyboard_getScancodeFromNameNegative", "Check call to SDL_GetScancodeFromName with invalid data", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest13 =
|
||||
{ (SDLTest_TestCaseFp)keyboard_getKeyNameNegative, "keyboard_getKeyNameNegative", "Check call to SDL_GetKeyName with invalid data", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest14 =
|
||||
{ (SDLTest_TestCaseFp)keyboard_getScancodeNameNegative, "keyboard_getScancodeNameNegative", "Check call to SDL_GetScancodeName with invalid data", TEST_ENABLED };
|
||||
|
||||
/* Sequence of Keyboard test cases */
|
||||
static const SDLTest_TestCaseReference *keyboardTests[] = {
|
||||
&keyboardTest1, &keyboardTest2, &keyboardTest3, &keyboardTest4, &keyboardTest5, &keyboardTest6,
|
||||
&keyboardTest7, &keyboardTest8, &keyboardTest9, &keyboardTest10, &keyboardTest11, &keyboardTest12,
|
||||
&keyboardTest13, &keyboardTest14, NULL
|
||||
};
|
||||
|
||||
/* Keyboard test suite (global) */
|
||||
SDLTest_TestSuiteReference keyboardTestSuite = {
|
||||
"Keyboard",
|
||||
NULL,
|
||||
keyboardTests,
|
||||
NULL
|
||||
};
|
157
test/testautomation_main.c
Normal file
@@ -0,0 +1,157 @@
|
||||
/**
|
||||
* Automated SDL subsystems management test.
|
||||
*
|
||||
* Written by J<>rgen Tjern<72> "jorgenpt"
|
||||
*
|
||||
* Released under Public Domain.
|
||||
*/
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_test.h"
|
||||
|
||||
|
||||
/* !
|
||||
* \brief Tests SDL_Init() and SDL_Quit() of Joystick and Haptic subsystems
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_Init
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_Quit
|
||||
*/
|
||||
static int main_testInitQuitJoystickHaptic (void *arg)
|
||||
{
|
||||
#if defined SDL_JOYSTICK_DISABLED || defined SDL_HAPTIC_DISABLED
|
||||
return TEST_SKIPPED;
|
||||
#else
|
||||
int enabled_subsystems;
|
||||
int initialized_subsystems = SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC;
|
||||
|
||||
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 );
|
||||
|
||||
SDL_Quit();
|
||||
|
||||
enabled_subsystems = SDL_WasInit(initialized_subsystems);
|
||||
SDLTest_AssertCheck( enabled_subsystems == 0, "SDL_Quit should shut down everything (%i)", enabled_subsystems );
|
||||
|
||||
return TEST_COMPLETED;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* !
|
||||
* \brief Tests SDL_InitSubSystem() and SDL_QuitSubSystem()
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_Init
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_Quit
|
||||
*/
|
||||
static int main_testInitQuitSubSystem (void *arg)
|
||||
{
|
||||
#if defined SDL_JOYSTICK_DISABLED || defined SDL_HAPTIC_DISABLED || defined SDL_GAMECONTROLLER_DISABLED
|
||||
return TEST_SKIPPED;
|
||||
#else
|
||||
int i;
|
||||
int subsystems[] = { SDL_INIT_JOYSTICK, SDL_INIT_HAPTIC, SDL_INIT_GAMECONTROLLER };
|
||||
|
||||
for (i = 0; i < SDL_arraysize(subsystems); ++i) {
|
||||
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 );
|
||||
|
||||
initialized_system = SDL_WasInit(subsystem);
|
||||
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 );
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
#endif
|
||||
}
|
||||
|
||||
const int joy_and_controller = SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER;
|
||||
static int main_testImpliedJoystickInit (void *arg)
|
||||
{
|
||||
#if defined SDL_JOYSTICK_DISABLED || defined SDL_GAMECONTROLLER_DISABLED
|
||||
return TEST_SKIPPED;
|
||||
#else
|
||||
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)" );
|
||||
|
||||
/* 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 );
|
||||
|
||||
/* 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 );
|
||||
|
||||
return TEST_COMPLETED;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int main_testImpliedJoystickQuit (void *arg)
|
||||
{
|
||||
#if defined SDL_JOYSTICK_DISABLED || defined SDL_GAMECONTROLLER_DISABLED
|
||||
return TEST_SKIPPED;
|
||||
#else
|
||||
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)" );
|
||||
|
||||
/* 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 );
|
||||
|
||||
/* 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 );
|
||||
|
||||
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
#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 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 mainTest4 =
|
||||
{ (SDLTest_TestCaseFp)main_testImpliedJoystickQuit, "main_testImpliedJoystickQuit", "Tests that quit for gamecontroller doesn't quit joystick if you inited it explicitly", TEST_ENABLED};
|
||||
|
||||
/* Sequence of Platform test cases */
|
||||
static const SDLTest_TestCaseReference *mainTests[] = {
|
||||
&mainTest1,
|
||||
&mainTest2,
|
||||
&mainTest3,
|
||||
&mainTest4,
|
||||
NULL
|
||||
};
|
||||
|
||||
/* Platform test suite (global) */
|
||||
SDLTest_TestSuiteReference mainTestSuite = {
|
||||
"Main",
|
||||
NULL,
|
||||
mainTests,
|
||||
NULL
|
||||
};
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
594
test/testautomation_mouse.c
Normal file
@@ -0,0 +1,594 @@
|
||||
/**
|
||||
* Mouse test suite
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_test.h"
|
||||
|
||||
/* ================= Test Case Implementation ================== */
|
||||
|
||||
/* Test case functions */
|
||||
|
||||
/* 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));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_GetMouseState
|
||||
*
|
||||
*/
|
||||
int
|
||||
mouse_getMouseState(void *arg)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
Uint32 state;
|
||||
|
||||
/* 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: %i", 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: %i", 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: %i", 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: %i", state);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_GetRelativeMouseState
|
||||
*
|
||||
*/
|
||||
int
|
||||
mouse_getRelativeMouseState(void *arg)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
Uint32 state;
|
||||
|
||||
/* 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: %i", 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: %i", 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: %i", 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: %i", state);
|
||||
|
||||
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 ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" "
|
||||
};
|
||||
|
||||
/* 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];
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_CreateCursor and SDL_FreeCursor
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_CreateCursor
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_FreeCursor
|
||||
*/
|
||||
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");
|
||||
if (cursor == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Free cursor again */
|
||||
SDL_FreeCursor(cursor);
|
||||
SDLTest_AssertPass("Call to SDL_FreeCursor()");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_CreateColorCursor and SDL_FreeCursor
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_CreateColorCursor
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_FreeCursor
|
||||
*/
|
||||
int
|
||||
mouse_createFreeColorCursor(void *arg)
|
||||
{
|
||||
SDL_Surface *face;
|
||||
SDL_Cursor *cursor;
|
||||
|
||||
/* Get sample surface */
|
||||
face = SDLTest_ImageFace();
|
||||
SDLTest_AssertCheck(face != NULL, "Validate sample input image is not NULL");
|
||||
if (face == NULL) return TEST_ABORTED;
|
||||
|
||||
/* Create a color cursor from surface */
|
||||
cursor = SDL_CreateColorCursor(face, 0, 0);
|
||||
SDLTest_AssertPass("Call to SDL_CreateColorCursor()");
|
||||
SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateColorCursor() is not NULL");
|
||||
if (cursor == NULL) {
|
||||
SDL_FreeSurface(face);
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Free cursor again */
|
||||
SDL_FreeCursor(cursor);
|
||||
SDLTest_AssertPass("Call to SDL_FreeCursor()");
|
||||
|
||||
/* Clean up */
|
||||
SDL_FreeSurface(face);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* Helper that changes cursor visibility */
|
||||
void _changeCursorVisibility(int state)
|
||||
{
|
||||
int oldState;
|
||||
int newState;
|
||||
int result;
|
||||
|
||||
oldState = SDL_ShowCursor(SDL_QUERY);
|
||||
SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)");
|
||||
|
||||
result = SDL_ShowCursor(state);
|
||||
SDLTest_AssertPass("Call to SDL_ShowCursor(%s)", (state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE");
|
||||
SDLTest_AssertCheck(result == oldState, "Validate result from SDL_ShowCursor(%s), expected: %i, got: %i",
|
||||
(state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE", oldState, result);
|
||||
|
||||
newState = SDL_ShowCursor(SDL_QUERY);
|
||||
SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)");
|
||||
SDLTest_AssertCheck(state == newState, "Validate new state, expected: %i, got: %i",
|
||||
state, newState);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_ShowCursor
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_ShowCursor
|
||||
*/
|
||||
int
|
||||
mouse_showCursor(void *arg)
|
||||
{
|
||||
int currentState;
|
||||
|
||||
/* Get current state */
|
||||
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);
|
||||
if (currentState == SDL_DISABLE) {
|
||||
/* Show the cursor, then hide it again */
|
||||
_changeCursorVisibility(SDL_ENABLE);
|
||||
_changeCursorVisibility(SDL_DISABLE);
|
||||
} else if (currentState == SDL_ENABLE) {
|
||||
/* Hide the cursor, then show it again */
|
||||
_changeCursorVisibility(SDL_DISABLE);
|
||||
_changeCursorVisibility(SDL_ENABLE);
|
||||
} else {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_SetCursor
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_SetCursor
|
||||
*/
|
||||
int
|
||||
mouse_setCursor(void *arg)
|
||||
{
|
||||
SDL_Cursor *cursor;
|
||||
|
||||
/* Create a cursor */
|
||||
cursor = _initArrowCursor(_mouseArrowData);
|
||||
SDLTest_AssertPass("Call to SDL_CreateCursor()");
|
||||
SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL");
|
||||
if (cursor == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Set the arrow cursor */
|
||||
SDL_SetCursor(cursor);
|
||||
SDLTest_AssertPass("Call to SDL_SetCursor(cursor)");
|
||||
|
||||
/* Force redraw */
|
||||
SDL_SetCursor(NULL);
|
||||
SDLTest_AssertPass("Call to SDL_SetCursor(NULL)");
|
||||
|
||||
/* Free cursor again */
|
||||
SDL_FreeCursor(cursor);
|
||||
SDLTest_AssertPass("Call to SDL_FreeCursor()");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_GetCursor
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetCursor
|
||||
*/
|
||||
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");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetRelativeMouseMode
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_SetRelativeMouseMode
|
||||
*/
|
||||
int
|
||||
mouse_getSetRelativeMouseMode(void *arg)
|
||||
{
|
||||
int result;
|
||||
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()");
|
||||
|
||||
/* 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 */
|
||||
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;
|
||||
}
|
||||
|
||||
#define MOUSE_TESTWINDOW_WIDTH 320
|
||||
#define MOUSE_TESTWINDOW_HEIGHT 200
|
||||
|
||||
/**
|
||||
* Creates a test window
|
||||
*/
|
||||
SDL_Window *_createMouseSuiteTestWindow()
|
||||
{
|
||||
int posX = 100, posY = 100, width = MOUSE_TESTWINDOW_WIDTH, height = MOUSE_TESTWINDOW_HEIGHT;
|
||||
SDL_Window *window;
|
||||
window = SDL_CreateWindow("mouse_createMouseSuiteTestWindow", posX, posY, width, height, 0);
|
||||
SDLTest_AssertPass("SDL_CreateWindow()");
|
||||
SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result");
|
||||
return window;
|
||||
}
|
||||
|
||||
/*
|
||||
* Destroy test window
|
||||
*/
|
||||
void _destroyMouseSuiteTestWindow(SDL_Window *window)
|
||||
{
|
||||
if (window != NULL) {
|
||||
SDL_DestroyWindow(window);
|
||||
window = NULL;
|
||||
SDLTest_AssertPass("SDL_DestroyWindow()");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_WarpMouseInWindow
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_WarpMouseInWindow
|
||||
*/
|
||||
int
|
||||
mouse_warpMouseInWindow(void *arg)
|
||||
{
|
||||
const int w = MOUSE_TESTWINDOW_WIDTH, h = MOUSE_TESTWINDOW_HEIGHT;
|
||||
int numPositions = 6;
|
||||
int xPositions[] = {-1, 0, 1, w-1, w, w+1 };
|
||||
int yPositions[] = {-1, 0, 1, h-1, h, h+1 };
|
||||
int x, y, i, j;
|
||||
SDL_Window *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);
|
||||
SDL_WarpMouseInWindow(window, x, y);
|
||||
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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 */
|
||||
_destroyMouseSuiteTestWindow(window);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_GetMouseFocus
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetMouseFocus
|
||||
*/
|
||||
int
|
||||
mouse_getMouseFocus(void *arg)
|
||||
{
|
||||
const int w = MOUSE_TESTWINDOW_WIDTH, h = MOUSE_TESTWINDOW_HEIGHT;
|
||||
int x, y;
|
||||
SDL_Window *window;
|
||||
SDL_Window *focusWindow;
|
||||
|
||||
/* Get focus - focus non-deterministic */
|
||||
focusWindow = SDL_GetMouseFocus();
|
||||
SDLTest_AssertPass("SDL_GetMouseFocus()");
|
||||
|
||||
/* Create test window */
|
||||
window = _createMouseSuiteTestWindow();
|
||||
if (window == NULL) return TEST_ABORTED;
|
||||
|
||||
/* Mouse to random position inside window */
|
||||
x = SDLTest_RandomIntegerInRange(1, w-1);
|
||||
y = SDLTest_RandomIntegerInRange(1, h-1);
|
||||
SDL_WarpMouseInWindow(window, x, y);
|
||||
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
|
||||
|
||||
/* Pump events to update focus state */
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("SDL_PumpEvents()");
|
||||
|
||||
/* Get focus with explicit window setup - focus deterministic */
|
||||
focusWindow = SDL_GetMouseFocus();
|
||||
SDLTest_AssertPass("SDL_GetMouseFocus()");
|
||||
SDLTest_AssertCheck (focusWindow != NULL, "Check returned window value is not NULL");
|
||||
SDLTest_AssertCheck (focusWindow == window, "Check returned window value is test window");
|
||||
|
||||
/* Mouse to random position outside window */
|
||||
x = SDLTest_RandomIntegerInRange(-9, -1);
|
||||
y = SDLTest_RandomIntegerInRange(-9, -1);
|
||||
SDL_WarpMouseInWindow(window, x, y);
|
||||
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
|
||||
|
||||
/* Clean up test window */
|
||||
_destroyMouseSuiteTestWindow(window);
|
||||
|
||||
/* Pump events to update focus state */
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("SDL_PumpEvents()");
|
||||
|
||||
/* Get focus for non-existing window */
|
||||
focusWindow = SDL_GetMouseFocus();
|
||||
SDLTest_AssertPass("SDL_GetMouseFocus()");
|
||||
SDLTest_AssertCheck (focusWindow == NULL, "Check returned window value is NULL");
|
||||
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* ================= 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 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 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 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 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 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[] = {
|
||||
&mouseTest1, &mouseTest2, &mouseTest3, &mouseTest4, &mouseTest5, &mouseTest6,
|
||||
&mouseTest7, &mouseTest8, &mouseTest9, &mouseTest10, NULL
|
||||
};
|
||||
|
||||
/* Mouse test suite (global) */
|
||||
SDLTest_TestSuiteReference mouseTestSuite = {
|
||||
"Mouse",
|
||||
NULL,
|
||||
mouseTests,
|
||||
NULL
|
||||
};
|
525
test/testautomation_pixels.c
Normal file
@@ -0,0 +1,525 @@
|
||||
/**
|
||||
* Pixels test suite
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_test.h"
|
||||
|
||||
/* Test case functions */
|
||||
|
||||
/* Definition of all RGB formats used to test pixel conversions */
|
||||
const int _numRGBPixelFormats = 30;
|
||||
Uint32 _RGBPixelFormats[] =
|
||||
{
|
||||
SDL_PIXELFORMAT_INDEX1LSB,
|
||||
SDL_PIXELFORMAT_INDEX1MSB,
|
||||
SDL_PIXELFORMAT_INDEX4LSB,
|
||||
SDL_PIXELFORMAT_INDEX4MSB,
|
||||
SDL_PIXELFORMAT_INDEX8,
|
||||
SDL_PIXELFORMAT_RGB332,
|
||||
SDL_PIXELFORMAT_RGB444,
|
||||
SDL_PIXELFORMAT_RGB555,
|
||||
SDL_PIXELFORMAT_BGR555,
|
||||
SDL_PIXELFORMAT_ARGB4444,
|
||||
SDL_PIXELFORMAT_RGBA4444,
|
||||
SDL_PIXELFORMAT_ABGR4444,
|
||||
SDL_PIXELFORMAT_BGRA4444,
|
||||
SDL_PIXELFORMAT_ARGB1555,
|
||||
SDL_PIXELFORMAT_RGBA5551,
|
||||
SDL_PIXELFORMAT_ABGR1555,
|
||||
SDL_PIXELFORMAT_BGRA5551,
|
||||
SDL_PIXELFORMAT_RGB565,
|
||||
SDL_PIXELFORMAT_BGR565,
|
||||
SDL_PIXELFORMAT_RGB24,
|
||||
SDL_PIXELFORMAT_BGR24,
|
||||
SDL_PIXELFORMAT_RGB888,
|
||||
SDL_PIXELFORMAT_RGBX8888,
|
||||
SDL_PIXELFORMAT_BGR888,
|
||||
SDL_PIXELFORMAT_BGRX8888,
|
||||
SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_PIXELFORMAT_RGBA8888,
|
||||
SDL_PIXELFORMAT_ABGR8888,
|
||||
SDL_PIXELFORMAT_BGRA8888,
|
||||
SDL_PIXELFORMAT_ARGB2101010
|
||||
};
|
||||
char* _RGBPixelFormatsVerbose[] =
|
||||
{
|
||||
"SDL_PIXELFORMAT_INDEX1LSB",
|
||||
"SDL_PIXELFORMAT_INDEX1MSB",
|
||||
"SDL_PIXELFORMAT_INDEX4LSB",
|
||||
"SDL_PIXELFORMAT_INDEX4MSB",
|
||||
"SDL_PIXELFORMAT_INDEX8",
|
||||
"SDL_PIXELFORMAT_RGB332",
|
||||
"SDL_PIXELFORMAT_RGB444",
|
||||
"SDL_PIXELFORMAT_RGB555",
|
||||
"SDL_PIXELFORMAT_BGR555",
|
||||
"SDL_PIXELFORMAT_ARGB4444",
|
||||
"SDL_PIXELFORMAT_RGBA4444",
|
||||
"SDL_PIXELFORMAT_ABGR4444",
|
||||
"SDL_PIXELFORMAT_BGRA4444",
|
||||
"SDL_PIXELFORMAT_ARGB1555",
|
||||
"SDL_PIXELFORMAT_RGBA5551",
|
||||
"SDL_PIXELFORMAT_ABGR1555",
|
||||
"SDL_PIXELFORMAT_BGRA5551",
|
||||
"SDL_PIXELFORMAT_RGB565",
|
||||
"SDL_PIXELFORMAT_BGR565",
|
||||
"SDL_PIXELFORMAT_RGB24",
|
||||
"SDL_PIXELFORMAT_BGR24",
|
||||
"SDL_PIXELFORMAT_RGB888",
|
||||
"SDL_PIXELFORMAT_RGBX8888",
|
||||
"SDL_PIXELFORMAT_BGR888",
|
||||
"SDL_PIXELFORMAT_BGRX8888",
|
||||
"SDL_PIXELFORMAT_ARGB8888",
|
||||
"SDL_PIXELFORMAT_RGBA8888",
|
||||
"SDL_PIXELFORMAT_ABGR8888",
|
||||
"SDL_PIXELFORMAT_BGRA8888",
|
||||
"SDL_PIXELFORMAT_ARGB2101010"
|
||||
};
|
||||
|
||||
/* Definition of all Non-RGB formats used to test pixel conversions */
|
||||
const int _numNonRGBPixelFormats = 5;
|
||||
Uint32 _nonRGBPixelFormats[] =
|
||||
{
|
||||
SDL_PIXELFORMAT_YV12,
|
||||
SDL_PIXELFORMAT_IYUV,
|
||||
SDL_PIXELFORMAT_YUY2,
|
||||
SDL_PIXELFORMAT_UYVY,
|
||||
SDL_PIXELFORMAT_YVYU
|
||||
};
|
||||
char* _nonRGBPixelFormatsVerbose[] =
|
||||
{
|
||||
"SDL_PIXELFORMAT_YV12",
|
||||
"SDL_PIXELFORMAT_IYUV",
|
||||
"SDL_PIXELFORMAT_YUY2",
|
||||
"SDL_PIXELFORMAT_UYVY",
|
||||
"SDL_PIXELFORMAT_YVYU"
|
||||
};
|
||||
|
||||
/* Definition of some invalid formats for negative tests */
|
||||
const int _numInvalidPixelFormats = 2;
|
||||
Uint32 _invalidPixelFormats[] =
|
||||
{
|
||||
0xfffffffe,
|
||||
0xffffffff
|
||||
};
|
||||
char* _invalidPixelFormatsVerbose[] =
|
||||
{
|
||||
"SDL_PIXELFORMAT_UNKNOWN",
|
||||
"SDL_PIXELFORMAT_UNKNOWN"
|
||||
};
|
||||
|
||||
/* Test case functions */
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_AllocFormat and SDL_FreeFormat
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_AllocFormat
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_FreeFormat
|
||||
*/
|
||||
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;
|
||||
|
||||
/* Blank/unknown format */
|
||||
format = 0;
|
||||
SDLTest_Log("RGB Format: %s (%u)", 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: %u, got %u", 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 %u", 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 (%u)", _RGBPixelFormatsVerbose[i], 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: %u, got %u", 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 %u", masks);
|
||||
}
|
||||
|
||||
/* 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 (%u)", _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(%u)", 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()");
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_GetPixelFormatName
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_GetPixelFormatName
|
||||
*/
|
||||
int
|
||||
pixels_getPixelFormatName(void *arg)
|
||||
{
|
||||
const char *unknownFormat = "SDL_PIXELFORMAT_UNKNOWN";
|
||||
const char *error;
|
||||
int i;
|
||||
Uint32 format;
|
||||
char* result;
|
||||
|
||||
/* Blank/undefined format */
|
||||
format = 0;
|
||||
SDLTest_Log("RGB Format: %s (%u)", unknownFormat, format);
|
||||
|
||||
/* Get name of format */
|
||||
result = (char *)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 (%u)", _RGBPixelFormatsVerbose[i], format);
|
||||
|
||||
/* Get name of format */
|
||||
result = (char *)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);
|
||||
}
|
||||
}
|
||||
|
||||
/* Non-RGB formats */
|
||||
for (i = 0; i < _numNonRGBPixelFormats; i++) {
|
||||
format = _nonRGBPixelFormats[i];
|
||||
SDLTest_Log("non-RGB Format: %s (%u)", _nonRGBPixelFormatsVerbose[i], format);
|
||||
|
||||
/* Get name of format */
|
||||
result = (char *)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);
|
||||
}
|
||||
}
|
||||
|
||||
/* Negative cases */
|
||||
|
||||
/* Invalid Formats */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
for (i = 0; i < _numInvalidPixelFormats; i++) {
|
||||
format = _invalidPixelFormats[i];
|
||||
result = (char *)SDL_GetPixelFormatName(format);
|
||||
SDLTest_AssertPass("Call to SDL_GetPixelFormatName(%u)", 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_AllocPalette and SDL_FreePalette
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_AllocPalette
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_FreePalette
|
||||
*/
|
||||
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;
|
||||
|
||||
/* Allocate palette */
|
||||
for (variation = 1; variation <= 3; variation++) {
|
||||
switch (variation) {
|
||||
/* Just one color */
|
||||
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()");
|
||||
}
|
||||
}
|
||||
|
||||
/* Negative cases */
|
||||
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_CalculateGammaRamp
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_CalculateGammaRamp
|
||||
*/
|
||||
int
|
||||
pixels_calcGammaRamp(void *arg)
|
||||
{
|
||||
const char *expectedError1 = "Parameter 'gamma' is invalid";
|
||||
const char *expectedError2 = "Parameter 'ramp' is invalid";
|
||||
const char *error;
|
||||
float gamma;
|
||||
Uint16 *ramp;
|
||||
int variation;
|
||||
int i;
|
||||
int changed;
|
||||
Uint16 magic = 0xbeef;
|
||||
|
||||
/* Allocate temp ramp array and fill with some value */
|
||||
ramp = (Uint16 *)SDL_malloc(256 * sizeof(Uint16));
|
||||
SDLTest_AssertCheck(ramp != NULL, "Validate temp ramp array could be allocated");
|
||||
if (ramp == NULL) return TEST_ABORTED;
|
||||
|
||||
/* Make call with different gamma values */
|
||||
for (variation = 0; variation < 4; variation++) {
|
||||
switch (variation) {
|
||||
/* gamma = 0 all black */
|
||||
case 0:
|
||||
gamma = 0.0f;
|
||||
break;
|
||||
/* gamma = 1 identity */
|
||||
case 1:
|
||||
gamma = 1.0f;
|
||||
break;
|
||||
/* gamma = [0.2,0.8] normal range */
|
||||
case 2:
|
||||
gamma = 0.2f + 0.8f * SDLTest_RandomUnitFloat();
|
||||
break;
|
||||
/* gamma = >1.1 non-standard range */
|
||||
case 3:
|
||||
gamma = 1.1f + SDLTest_RandomUnitFloat();
|
||||
break;
|
||||
}
|
||||
|
||||
/* Make call and check that values were updated */
|
||||
for (i = 0; i < 256; i++) ramp[i] = magic;
|
||||
SDL_CalculateGammaRamp(gamma, ramp);
|
||||
SDLTest_AssertPass("Call to SDL_CalculateGammaRamp(%f)", gamma);
|
||||
changed = 0;
|
||||
for (i = 0; i < 256; i++) if (ramp[i] != magic) changed++;
|
||||
SDLTest_AssertCheck(changed > 250, "Validate that ramp was calculated; expected: >250 values changed, got: %d values changed", changed);
|
||||
|
||||
/* Additional value checks for some cases */
|
||||
i = SDLTest_RandomIntegerInRange(64,192);
|
||||
switch (variation) {
|
||||
case 0:
|
||||
SDLTest_AssertCheck(ramp[i] == 0, "Validate value at position %d; expected: 0, got: %d", i, ramp[i]);
|
||||
break;
|
||||
case 1:
|
||||
SDLTest_AssertCheck(ramp[i] == ((i << 8) | i), "Validate value at position %d; expected: %d, got: %d", i, (i << 8) | i, ramp[i]);
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
SDLTest_AssertCheck(ramp[i] > 0, "Validate value at position %d; expected: >0, got: %d", i, ramp[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Negative cases */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
gamma = -1;
|
||||
for (i=0; i<256; i++) ramp[i] = magic;
|
||||
SDL_CalculateGammaRamp(gamma, ramp);
|
||||
SDLTest_AssertPass("Call to SDL_CalculateGammaRamp(%f)", gamma);
|
||||
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);
|
||||
}
|
||||
changed = 0;
|
||||
for (i = 0; i < 256; i++) if (ramp[i] != magic) changed++;
|
||||
SDLTest_AssertCheck(changed ==0, "Validate that ramp unchanged; expected: 0 values changed got: %d values changed", changed);
|
||||
|
||||
SDL_CalculateGammaRamp(0.5f, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_CalculateGammaRamp(0.5,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);
|
||||
}
|
||||
|
||||
/* Cleanup */
|
||||
SDL_free(ramp);
|
||||
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* ================= 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 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 };
|
||||
|
||||
static const SDLTest_TestCaseReference pixelsTest4 =
|
||||
{ (SDLTest_TestCaseFp)pixels_getPixelFormatName, "pixels_getPixelFormatName", "Call to SDL_GetPixelFormatName", TEST_ENABLED };
|
||||
|
||||
/* Sequence of Pixels test cases */
|
||||
static const SDLTest_TestCaseReference *pixelsTests[] = {
|
||||
&pixelsTest1, &pixelsTest2, &pixelsTest3, &pixelsTest4, NULL
|
||||
};
|
||||
|
||||
/* Pixels test suite (global) */
|
||||
SDLTest_TestSuiteReference pixelsTestSuite = {
|
||||
"Pixels",
|
||||
NULL,
|
||||
pixelsTests,
|
||||
NULL
|
||||
};
|
597
test/testautomation_platform.c
Normal file
@@ -0,0 +1,597 @@
|
||||
/**
|
||||
* 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 = SDL_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
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasAVX
|
||||
*/
|
||||
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()");
|
||||
|
||||
ret = SDL_HasAVX();
|
||||
SDLTest_AssertPass("SDL_HasAVX()");
|
||||
|
||||
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)
|
||||
{
|
||||
int result;
|
||||
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 = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == 0,
|
||||
"SDL_GetError(): no message expected, len: %i", 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",
|
||||
SDL_strlen(testError),
|
||||
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()");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* !
|
||||
* \brief Tests SDL_SetError with empty input
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetError
|
||||
*/
|
||||
int platform_testSetErrorEmptyInput(void *arg)
|
||||
{
|
||||
int result;
|
||||
const char *testError = "";
|
||||
char *lastError;
|
||||
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",
|
||||
SDL_strlen(testError),
|
||||
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()");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* !
|
||||
* \brief Tests SDL_SetError with invalid input
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetError
|
||||
*/
|
||||
int platform_testSetErrorInvalidInput(void *arg)
|
||||
{
|
||||
int result;
|
||||
const char *invalidError = NULL;
|
||||
const char *probeError = "Testing";
|
||||
char *lastError;
|
||||
int len;
|
||||
|
||||
/* Reset */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("SDL_ClearError()");
|
||||
|
||||
/* Check for no-op */
|
||||
result = SDL_SetError(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_GetError(): expected message len 0, was len: %i",
|
||||
0,
|
||||
len);
|
||||
SDLTest_AssertCheck(SDL_strcmp(lastError, "") == 0,
|
||||
"SDL_GetError(): expected message '', was message: '%s'",
|
||||
lastError);
|
||||
}
|
||||
|
||||
/* Set */
|
||||
result = SDL_SetError(probeError);
|
||||
SDLTest_AssertPass("SDL_SetError()");
|
||||
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
|
||||
|
||||
/* Check for no-op */
|
||||
result = SDL_SetError(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 == SDL_strlen(probeError),
|
||||
"SDL_GetError(): expected message len %i, was len: %i",
|
||||
SDL_strlen(probeError),
|
||||
len);
|
||||
SDLTest_AssertCheck(SDL_strcmp(lastError, probeError) == 0,
|
||||
"SDL_GetError(): expected message '%s', was message: '%s'",
|
||||
probeError,
|
||||
lastError);
|
||||
}
|
||||
|
||||
/* Reset */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("SDL_ClearError()");
|
||||
|
||||
/* Set and check */
|
||||
result = SDL_SetError(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",
|
||||
SDL_strlen(probeError),
|
||||
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()");
|
||||
|
||||
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
|
||||
};
|
1696
test/testautomation_rect.c
Normal file
1051
test/testautomation_render.c
Normal file
748
test/testautomation_rwops.c
Normal file
@@ -0,0 +1,748 @@
|
||||
|
||||
/**
|
||||
* Automated SDL_RWops test.
|
||||
*
|
||||
* Original code written by Edgar Simo "bobbens"
|
||||
* Ported by Markus Kauppila (markus.kauppila@gmail.com)
|
||||
* Updated and extended for SDL_test by aschiffler at ferzkopp dot net
|
||||
*
|
||||
* Released under Public Domain.
|
||||
*/
|
||||
|
||||
/* quiet windows compiler warnings */
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_test.h"
|
||||
|
||||
/* ================= Test Case Implementation ================== */
|
||||
|
||||
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!";
|
||||
static const char RWopsAlphabetString[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
/* Fixture */
|
||||
|
||||
void
|
||||
RWopsSetUp(void *arg)
|
||||
{
|
||||
int fileLen;
|
||||
FILE *handle;
|
||||
int writtenLen;
|
||||
int result;
|
||||
|
||||
/* Clean up from previous runs (if any); ignore errors */
|
||||
remove(RWopsReadTestFilename);
|
||||
remove(RWopsWriteTestFilename);
|
||||
remove(RWopsAlphabetFilename);
|
||||
|
||||
/* Create a test file */
|
||||
handle = fopen(RWopsReadTestFilename, "w");
|
||||
SDLTest_AssertCheck(handle != NULL, "Verify creation of file '%s' returned non NULL handle", RWopsReadTestFilename);
|
||||
if (handle == NULL) return;
|
||||
|
||||
/* Write some known text into it */
|
||||
fileLen = SDL_strlen(RWopsHelloWorldTestString);
|
||||
writtenLen = (int)fwrite(RWopsHelloWorldTestString, 1, fileLen, handle);
|
||||
SDLTest_AssertCheck(fileLen == writtenLen, "Verify number of written bytes, expected %i, got %i", fileLen, writtenLen);
|
||||
result = fclose(handle);
|
||||
SDLTest_AssertCheck(result == 0, "Verify result from fclose, expected 0, got %i", result);
|
||||
|
||||
/* 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;
|
||||
|
||||
/* Write alphabet text into it */
|
||||
fileLen = SDL_strlen(RWopsAlphabetString);
|
||||
writtenLen = (int)fwrite(RWopsAlphabetString, 1, fileLen, handle);
|
||||
SDLTest_AssertCheck(fileLen == writtenLen, "Verify number of written bytes, expected %i, got %i", fileLen, writtenLen);
|
||||
result = fclose(handle);
|
||||
SDLTest_AssertCheck(result == 0, "Verify result from fclose, expected 0, got %i", result);
|
||||
|
||||
SDLTest_AssertPass("Creation of test file completed");
|
||||
}
|
||||
|
||||
void
|
||||
RWopsTearDown(void *arg)
|
||||
{
|
||||
int result;
|
||||
|
||||
/* Remove the created files to clean up; ignore errors for write filename */
|
||||
result = remove(RWopsReadTestFilename);
|
||||
SDLTest_AssertCheck(result == 0, "Verify result from remove(%s), expected 0, got %i", RWopsReadTestFilename, result);
|
||||
remove(RWopsWriteTestFilename);
|
||||
result = remove(RWopsAlphabetFilename);
|
||||
SDLTest_AssertCheck(result == 0, "Verify result from remove(%s), expected 0, got %i", RWopsAlphabetFilename, result);
|
||||
|
||||
SDLTest_AssertPass("Cleanup of test files completed");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Makes sure parameters work properly. Local helper function.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWseek
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWread
|
||||
*/
|
||||
void
|
||||
_testGenericRWopsValidations(SDL_RWops *rw, int write)
|
||||
{
|
||||
char buf[sizeof(RWopsHelloWorldTestString)];
|
||||
Sint64 i;
|
||||
size_t s;
|
||||
int seekPos = SDLTest_RandomIntegerInRange(4, 8);
|
||||
|
||||
/* Clear buffer */
|
||||
SDL_zero(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 %i", 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", s);
|
||||
}
|
||||
else {
|
||||
SDLTest_AssertCheck(s == (size_t)0, "Verify result of writing with SDL_RWwrite, expected: 0, got %i", 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 %i", 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 %i", 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",
|
||||
sizeof(RWopsHelloWorldTestString)-1,
|
||||
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",
|
||||
sizeof(RWopsHelloWorldTestString)-5,
|
||||
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",
|
||||
sizeof(RWopsHelloWorldTestString)-2,
|
||||
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",
|
||||
i);
|
||||
}
|
||||
|
||||
/* !
|
||||
* Negative test for SDL_RWFromFile parameters
|
||||
*
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
|
||||
*
|
||||
*/
|
||||
int
|
||||
rwops_testParamNegative (void)
|
||||
{
|
||||
SDL_RWops *rwops;
|
||||
|
||||
/* These should all fail. */
|
||||
rwops = SDL_RWFromFile(NULL, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_RWFromFile(NULL, NULL) succeeded");
|
||||
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(NULL, NULL) returns NULL");
|
||||
|
||||
rwops = SDL_RWFromFile(NULL, "ab+");
|
||||
SDLTest_AssertPass("Call to SDL_RWFromFile(NULL, \"ab+\") succeeded");
|
||||
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(NULL, \"ab+\") returns NULL");
|
||||
|
||||
rwops = SDL_RWFromFile(NULL, "sldfkjsldkfj");
|
||||
SDLTest_AssertPass("Call to SDL_RWFromFile(NULL, \"sldfkjsldkfj\") succeeded");
|
||||
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(NULL, \"sldfkjsldkfj\") returns NULL");
|
||||
|
||||
rwops = SDL_RWFromFile("something", "");
|
||||
SDLTest_AssertPass("Call to SDL_RWFromFile(\"something\", \"\") succeeded");
|
||||
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(\"something\", \"\") returns NULL");
|
||||
|
||||
rwops = SDL_RWFromFile("something", NULL);
|
||||
SDLTest_AssertPass("Call to SDL_RWFromFile(\"something\", NULL) succeeded");
|
||||
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(\"something\", NULL) returns NULL");
|
||||
|
||||
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_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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests opening from memory.
|
||||
*
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromMem
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_RWClose
|
||||
*/
|
||||
int
|
||||
rwops_testMem (void)
|
||||
{
|
||||
char mem[sizeof(RWopsHelloWorldTestString)];
|
||||
SDL_RWops *rw;
|
||||
int result;
|
||||
|
||||
/* Clear buffer */
|
||||
SDL_zero(mem);
|
||||
|
||||
/* Open */
|
||||
rw = SDL_RWFromMem(mem, sizeof(RWopsHelloWorldTestString)-1);
|
||||
SDLTest_AssertPass("Call to SDL_RWFromMem() succeeded");
|
||||
SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromMem does not return NULL");
|
||||
|
||||
/* Bail out if NULL */
|
||||
if (rw == NULL) return TEST_ABORTED;
|
||||
|
||||
/* Check type */
|
||||
SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY, "Verify RWops type is SDL_RWOPS_MEMORY; expected: %d, got: %d", SDL_RWOPS_MEMORY, rw->type);
|
||||
|
||||
/* Run generic tests */
|
||||
_testGenericRWopsValidations(rw, 1);
|
||||
|
||||
/* Close */
|
||||
result = SDL_RWclose(rw);
|
||||
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
|
||||
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Tests opening from memory.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWFromConstMem
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWClose
|
||||
*/
|
||||
int
|
||||
rwops_testConstMem (void)
|
||||
{
|
||||
SDL_RWops *rw;
|
||||
int result;
|
||||
|
||||
/* Open handle */
|
||||
rw = SDL_RWFromConstMem( RWopsHelloWorldCompString, sizeof(RWopsHelloWorldCompString)-1 );
|
||||
SDLTest_AssertPass("Call to SDL_RWFromConstMem() succeeded");
|
||||
SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromConstMem does not return NULL");
|
||||
|
||||
/* Bail out if NULL */
|
||||
if (rw == NULL) return TEST_ABORTED;
|
||||
|
||||
/* Check type */
|
||||
SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY_RO, "Verify RWops type is SDL_RWOPS_MEMORY_RO; expected: %d, got: %d", SDL_RWOPS_MEMORY_RO, rw->type);
|
||||
|
||||
/* Run generic tests */
|
||||
_testGenericRWopsValidations( rw, 0 );
|
||||
|
||||
/* Close handle */
|
||||
result = SDL_RWclose(rw);
|
||||
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
|
||||
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Tests reading from file.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWClose
|
||||
*/
|
||||
int
|
||||
rwops_testFileRead(void)
|
||||
{
|
||||
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");
|
||||
|
||||
/* Bail out if NULL */
|
||||
if (rw == NULL) return TEST_ABORTED;
|
||||
|
||||
/* 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);
|
||||
#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);
|
||||
#else
|
||||
SDLTest_AssertCheck(
|
||||
rw->type == SDL_RWOPS_STDFILE,
|
||||
"Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type);
|
||||
#endif
|
||||
|
||||
/* Run generic tests */
|
||||
_testGenericRWopsValidations( rw, 0 );
|
||||
|
||||
/* Close handle */
|
||||
result = SDL_RWclose(rw);
|
||||
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
|
||||
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests writing from file.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWClose
|
||||
*/
|
||||
int
|
||||
rwops_testFileWrite(void)
|
||||
{
|
||||
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");
|
||||
|
||||
/* Bail out if NULL */
|
||||
if (rw == NULL) return TEST_ABORTED;
|
||||
|
||||
/* 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);
|
||||
#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);
|
||||
#else
|
||||
SDLTest_AssertCheck(
|
||||
rw->type == SDL_RWOPS_STDFILE,
|
||||
"Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type);
|
||||
#endif
|
||||
|
||||
/* 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);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Tests reading from file handle
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWFromFP
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWClose
|
||||
*
|
||||
*/
|
||||
int
|
||||
rwops_testFPRead(void)
|
||||
{
|
||||
FILE *fp;
|
||||
SDL_RWops *rw;
|
||||
int result;
|
||||
|
||||
/* Run read tests. */
|
||||
fp = fopen(RWopsReadTestFilename, "r");
|
||||
SDLTest_AssertCheck(fp != NULL, "Verify handle from opening file '%s' in read mode is not NULL", RWopsReadTestFilename);
|
||||
|
||||
/* Bail out if NULL */
|
||||
if (fp == NULL) return TEST_ABORTED;
|
||||
|
||||
/* Open */
|
||||
rw = SDL_RWFromFP( fp, SDL_TRUE );
|
||||
SDLTest_AssertPass("Call to SDL_RWFromFP() succeeded");
|
||||
SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFP in read mode does not return NULL");
|
||||
|
||||
/* Bail out if NULL */
|
||||
if (rw == NULL) {
|
||||
fclose(fp);
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Check type */
|
||||
SDLTest_AssertCheck(
|
||||
rw->type == SDL_RWOPS_STDFILE,
|
||||
"Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type);
|
||||
|
||||
/* Run generic tests */
|
||||
_testGenericRWopsValidations( rw, 0 );
|
||||
|
||||
/* Close handle - does fclose() */
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Tests writing to file handle
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWFromFP
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWClose
|
||||
*
|
||||
*/
|
||||
int
|
||||
rwops_testFPWrite(void)
|
||||
{
|
||||
FILE *fp;
|
||||
SDL_RWops *rw;
|
||||
int result;
|
||||
|
||||
/* Run write tests. */
|
||||
fp = fopen(RWopsWriteTestFilename, "w+");
|
||||
SDLTest_AssertCheck(fp != NULL, "Verify handle from opening file '%s' in write mode is not NULL", RWopsWriteTestFilename);
|
||||
|
||||
/* Bail out if NULL */
|
||||
if (fp == NULL) return TEST_ABORTED;
|
||||
|
||||
/* Open */
|
||||
rw = SDL_RWFromFP( fp, SDL_TRUE );
|
||||
SDLTest_AssertPass("Call to SDL_RWFromFP() succeeded");
|
||||
SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFP in write mode does not return NULL");
|
||||
|
||||
/* Bail out if NULL */
|
||||
if (rw == NULL) {
|
||||
fclose(fp);
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Check type */
|
||||
SDLTest_AssertCheck(
|
||||
rw->type == SDL_RWOPS_STDFILE,
|
||||
"Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type);
|
||||
|
||||
/* Run generic tests */
|
||||
_testGenericRWopsValidations( rw, 1 );
|
||||
|
||||
/* Close handle - does fclose() */
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests alloc and free RW context.
|
||||
*
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_AllocRW
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_FreeRW
|
||||
*/
|
||||
int
|
||||
rwops_testAllocFree (void)
|
||||
{
|
||||
/* Allocate context */
|
||||
SDL_RWops *rw = SDL_AllocRW();
|
||||
SDLTest_AssertPass("Call to SDL_AllocRW() succeeded");
|
||||
SDLTest_AssertCheck(rw != NULL, "Validate result from SDL_AllocRW() is not NULL");
|
||||
if (rw==NULL) return TEST_ABORTED;
|
||||
|
||||
/* Check type */
|
||||
SDLTest_AssertCheck(
|
||||
rw->type == SDL_RWOPS_UNKNOWN,
|
||||
"Verify RWops type is SDL_RWOPS_UNKNOWN; expected: %d, got: %d", SDL_RWOPS_UNKNOWN, rw->type);
|
||||
|
||||
/* Free context again */
|
||||
SDL_FreeRW(rw);
|
||||
SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Compare memory and file reads
|
||||
*
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromMem
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
|
||||
*/
|
||||
int
|
||||
rwops_testCompareRWFromMemWithRWFromFile(void)
|
||||
{
|
||||
int slen = 26;
|
||||
char buffer_file[27];
|
||||
char buffer_mem[27];
|
||||
size_t rv_file;
|
||||
size_t rv_mem;
|
||||
Uint64 sv_file;
|
||||
Uint64 sv_mem;
|
||||
SDL_RWops* rwops_file;
|
||||
SDL_RWops* rwops_mem;
|
||||
int size;
|
||||
int result;
|
||||
|
||||
|
||||
for (size=5; size<10; size++)
|
||||
{
|
||||
/* Terminate buffer */
|
||||
buffer_file[slen] = 0;
|
||||
buffer_mem[slen] = 0;
|
||||
|
||||
/* Read/seek from memory */
|
||||
rwops_mem = SDL_RWFromMem((void *)RWopsAlphabetString, slen);
|
||||
SDLTest_AssertPass("Call to SDL_RWFromMem()");
|
||||
rv_mem = SDL_RWread(rwops_mem, buffer_mem, size, 6);
|
||||
SDLTest_AssertPass("Call to SDL_RWread(mem, size=%d)", size);
|
||||
sv_mem = SDL_RWseek(rwops_mem, 0, SEEK_END);
|
||||
SDLTest_AssertPass("Call to SDL_RWseek(mem,SEEK_END)");
|
||||
result = SDL_RWclose(rwops_mem);
|
||||
SDLTest_AssertPass("Call to SDL_RWclose(mem)");
|
||||
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
|
||||
|
||||
/* Read/see from file */
|
||||
rwops_file = SDL_RWFromFile(RWopsAlphabetFilename, "r");
|
||||
SDLTest_AssertPass("Call to SDL_RWFromFile()");
|
||||
rv_file = SDL_RWread(rwops_file, buffer_file, size, 6);
|
||||
SDLTest_AssertPass("Call to SDL_RWread(file, size=%d)", size);
|
||||
sv_file = SDL_RWseek(rwops_file, 0, SEEK_END);
|
||||
SDLTest_AssertPass("Call to SDL_RWseek(file,SEEK_END)");
|
||||
result = SDL_RWclose(rwops_file);
|
||||
SDLTest_AssertPass("Call to SDL_RWclose(file)");
|
||||
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
|
||||
|
||||
/* Compare */
|
||||
SDLTest_AssertCheck(rv_mem == rv_file, "Verify returned read blocks matches for mem and file reads; got: rv_mem=%d rv_file=%d", rv_mem, rv_file);
|
||||
SDLTest_AssertCheck(sv_mem == sv_file, "Verify SEEK_END position matches for mem and file seeks; got: sv_mem=%llu sv_file=%llu", sv_mem, sv_file);
|
||||
SDLTest_AssertCheck(buffer_mem[slen] == 0, "Verify mem buffer termination; expected: 0, got: %d", buffer_mem[slen]);
|
||||
SDLTest_AssertCheck(buffer_file[slen] == 0, "Verify file buffer termination; expected: 0, got: %d", buffer_file[slen]);
|
||||
SDLTest_AssertCheck(
|
||||
SDL_strncmp(buffer_mem, RWopsAlphabetString, slen) == 0,
|
||||
"Verify mem buffer contain alphabet string; expected: %s, got: %s", RWopsAlphabetString, buffer_mem);
|
||||
SDLTest_AssertCheck(
|
||||
SDL_strncmp(buffer_file, RWopsAlphabetString, slen) == 0,
|
||||
"Verify file buffer contain alphabet string; expected: %s, got: %s", RWopsAlphabetString, buffer_file);
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests writing and reading from file using endian aware functions.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWClose
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_ReadBE16
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_WriteBE16
|
||||
*/
|
||||
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;
|
||||
|
||||
for (mode = 0; mode < 3; mode++) {
|
||||
|
||||
/* Create test data */
|
||||
switch (mode) {
|
||||
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");
|
||||
|
||||
/* 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", 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", 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", 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", 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", 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", 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", 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: %u, got: %u", BE32value, BE32test);
|
||||
BE64test = SDL_ReadBE64(rw);
|
||||
SDLTest_AssertPass("Call to SDL_ReadBE64");
|
||||
SDLTest_AssertCheck(BE64test == BE64value, "Validate return value from SDL_ReadBE64, expected: %llu, got: %llu", 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: %u, got: %u", LE32value, LE32test);
|
||||
LE64test = SDL_ReadLE64(rw);
|
||||
SDLTest_AssertPass("Call to SDL_ReadLE64");
|
||||
SDLTest_AssertCheck(LE64test == LE64value, "Validate return value from SDL_ReadLE64, expected: %llu, got: %llu", 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);
|
||||
}
|
||||
|
||||
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 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 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 rwopsTest6 =
|
||||
{ (SDLTest_TestCaseFp)rwops_testFPRead, "rwops_testFPRead", "Test reading from file pointer", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference rwopsTest7 =
|
||||
{ (SDLTest_TestCaseFp)rwops_testFPWrite, "rwops_testFPWrite", "Test writing to file pointer", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference rwopsTest8 =
|
||||
{ (SDLTest_TestCaseFp)rwops_testAllocFree, "rwops_testAllocFree", "Test alloc and free of RW context", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference rwopsTest9 =
|
||||
{ (SDLTest_TestCaseFp)rwops_testFileWriteReadEndian, "rwops_testFileWriteReadEndian", "Test writing and reading via the Endian aware functions", TEST_ENABLED };
|
||||
|
||||
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[] = {
|
||||
&rwopsTest1, &rwopsTest2, &rwopsTest3, &rwopsTest4, &rwopsTest5, &rwopsTest6,
|
||||
&rwopsTest7, &rwopsTest8, &rwopsTest9, &rwopsTest10, NULL
|
||||
};
|
||||
|
||||
/* RWops test suite (global) */
|
||||
SDLTest_TestSuiteReference rwopsTestSuite = {
|
||||
"RWops",
|
||||
RWopsSetUp,
|
||||
rwopsTests,
|
||||
RWopsTearDown
|
||||
};
|
1315
test/testautomation_sdltest.c
Normal file
279
test/testautomation_stdlib.c
Normal file
@@ -0,0 +1,279 @@
|
||||
/**
|
||||
* Standard C library routine test suite
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_test.h"
|
||||
|
||||
|
||||
/* Test case functions */
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_strlcpy
|
||||
*/
|
||||
#undef SDL_strlcpy
|
||||
int
|
||||
stdlib_strlcpy(void *arg)
|
||||
{
|
||||
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", SDL_strlen(text), 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", result);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_snprintf
|
||||
*/
|
||||
#undef SDL_snprintf
|
||||
int
|
||||
stdlib_snprintf(void *arg)
|
||||
{
|
||||
int result;
|
||||
char text[1024];
|
||||
const char *expected;
|
||||
|
||||
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", 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(NULL, 0, "%s", "foo");
|
||||
SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%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", SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%.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", SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%#.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", SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%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", SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%+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", SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%.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", SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%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", SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%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", SDL_strlen(text), 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);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_getenv and SDL_setenv
|
||||
*/
|
||||
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;
|
||||
|
||||
/* 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, 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_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);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* ================= 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 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 };
|
||||
|
||||
/* Sequence of Standard C routine test cases */
|
||||
static const SDLTest_TestCaseReference *stdlibTests[] = {
|
||||
&stdlibTest1, &stdlibTest2, &stdlibTest3, NULL
|
||||
};
|
||||
|
||||
/* Timer test suite (global) */
|
||||
SDLTest_TestSuiteReference stdlibTestSuite = {
|
||||
"Stdlib",
|
||||
NULL,
|
||||
stdlibTests,
|
||||
NULL
|
||||
};
|
54
test/testautomation_suites.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* 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 mainTestSuite;
|
||||
extern SDLTest_TestSuiteReference mouseTestSuite;
|
||||
extern SDLTest_TestSuiteReference pixelsTestSuite;
|
||||
extern SDLTest_TestSuiteReference platformTestSuite;
|
||||
extern SDLTest_TestSuiteReference rectTestSuite;
|
||||
extern SDLTest_TestSuiteReference renderTestSuite;
|
||||
extern SDLTest_TestSuiteReference rwopsTestSuite;
|
||||
extern SDLTest_TestSuiteReference sdltestTestSuite;
|
||||
extern SDLTest_TestSuiteReference stdlibTestSuite;
|
||||
extern SDLTest_TestSuiteReference surfaceTestSuite;
|
||||
extern SDLTest_TestSuiteReference syswmTestSuite;
|
||||
extern SDLTest_TestSuiteReference timerTestSuite;
|
||||
extern SDLTest_TestSuiteReference videoTestSuite;
|
||||
extern SDLTest_TestSuiteReference hintsTestSuite;
|
||||
|
||||
/* All test suites */
|
||||
SDLTest_TestSuiteReference *testSuites[] = {
|
||||
&audioTestSuite,
|
||||
&clipboardTestSuite,
|
||||
&eventsTestSuite,
|
||||
&keyboardTestSuite,
|
||||
&mainTestSuite,
|
||||
&mouseTestSuite,
|
||||
&pixelsTestSuite,
|
||||
&platformTestSuite,
|
||||
&rectTestSuite,
|
||||
&renderTestSuite,
|
||||
&rwopsTestSuite,
|
||||
&sdltestTestSuite,
|
||||
&stdlibTestSuite,
|
||||
&surfaceTestSuite,
|
||||
&syswmTestSuite,
|
||||
&timerTestSuite,
|
||||
&videoTestSuite,
|
||||
&hintsTestSuite,
|
||||
NULL
|
||||
};
|
||||
|
||||
#endif
|
644
test/testautomation_surface.c
Normal file
@@ -0,0 +1,644 @@
|
||||
/**
|
||||
* Original code: automated SDL surface test written by Edgar Simo "bobbens"
|
||||
* Adapted/rewritten for test lib by Andreas Schiffler
|
||||
*/
|
||||
|
||||
/* Supress C4996 VS compiler warnings for unlink() */
|
||||
#define _CRT_SECURE_NO_DEPRECATE
|
||||
#define _CRT_NONSTDC_NO_DEPRECATE
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_test.h"
|
||||
|
||||
#ifdef __MACOSX__
|
||||
#include <unistd.h> /* For unlink() */
|
||||
#endif
|
||||
|
||||
/* ================= Test Case Implementation ================== */
|
||||
|
||||
/* Shared test surface */
|
||||
|
||||
static SDL_Surface *referenceSurface = NULL;
|
||||
static SDL_Surface *testSurface = NULL;
|
||||
|
||||
/* Helper functions for the test cases */
|
||||
|
||||
#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)
|
||||
{
|
||||
int result;
|
||||
SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
|
||||
SDL_BlendMode currentBlendMode;
|
||||
Uint32 rmask, gmask, bmask, amask;
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
rmask = 0xff000000;
|
||||
gmask = 0x00ff0000;
|
||||
bmask = 0x0000ff00;
|
||||
amask = 0x000000ff;
|
||||
#else
|
||||
rmask = 0x000000ff;
|
||||
gmask = 0x0000ff00;
|
||||
bmask = 0x00ff0000;
|
||||
amask = 0xff000000;
|
||||
#endif
|
||||
|
||||
referenceSurface = SDLTest_ImageBlit(); /* For size info */
|
||||
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, ¤tBlendMode);
|
||||
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)
|
||||
{
|
||||
SDL_FreeSurface(referenceSurface);
|
||||
referenceSurface = NULL;
|
||||
SDL_FreeSurface(testSurface);
|
||||
testSurface = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper that clears the test surface
|
||||
*/
|
||||
void _clearTestSurface()
|
||||
{
|
||||
int ret;
|
||||
Uint32 color;
|
||||
|
||||
/* Clear surface. */
|
||||
color = SDL_MapRGBA( testSurface->format, 0, 0, 0, 0);
|
||||
SDLTest_AssertPass("Call to SDL_MapRGBA()");
|
||||
ret = SDL_FillRect( testSurface, NULL, color);
|
||||
SDLTest_AssertPass("Call to SDL_FillRect()");
|
||||
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_FillRect, expected: 0, got: %i", ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper that blits in a specific blend mode, -1 for basic blitting, -2 for color mod, -3 for alpha mod, -4 for mixed blend modes.
|
||||
*/
|
||||
void _testBlitBlendMode(int mode)
|
||||
{
|
||||
int ret;
|
||||
int i, j, ni, nj;
|
||||
SDL_Surface *face;
|
||||
SDL_Rect rect;
|
||||
int nmode;
|
||||
SDL_BlendMode bmode;
|
||||
int checkFailCount1;
|
||||
int checkFailCount2;
|
||||
int checkFailCount3;
|
||||
int checkFailCount4;
|
||||
|
||||
/* Check test surface */
|
||||
SDLTest_AssertCheck(testSurface != NULL, "Verify testSurface is not NULL");
|
||||
if (testSurface == NULL) return;
|
||||
|
||||
/* Create sample surface */
|
||||
face = SDLTest_ImageFace();
|
||||
SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
|
||||
if (face == NULL) return;
|
||||
|
||||
/* 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 */
|
||||
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 */
|
||||
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();
|
||||
|
||||
/* Target rect size */
|
||||
rect.w = face->w;
|
||||
rect.h = face->h;
|
||||
|
||||
/* Steps to take */
|
||||
ni = testSurface->w - face->w;
|
||||
nj = testSurface->h - face->h;
|
||||
|
||||
/* Optionally set blend mode. */
|
||||
if (mode >= 0) {
|
||||
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);
|
||||
}
|
||||
|
||||
/* Test blend mode. */
|
||||
checkFailCount1 = 0;
|
||||
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++;
|
||||
}
|
||||
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;
|
||||
}
|
||||
ret = SDL_SetSurfaceBlendMode( face, bmode );
|
||||
if (ret != 0) checkFailCount4++;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
SDLTest_AssertCheck(checkFailCount3 == 0, "Validate results from calls to SDL_SetSurfaceAlphaMod, expected: 0, got: %i", checkFailCount3);
|
||||
SDLTest_AssertCheck(checkFailCount4 == 0, "Validate results from calls to SDL_SetSurfaceBlendMode, expected: 0, got: %i", checkFailCount4);
|
||||
|
||||
/* Clean up */
|
||||
SDL_FreeSurface(face);
|
||||
face = NULL;
|
||||
}
|
||||
|
||||
/* Helper to check that a file exists */
|
||||
void
|
||||
_AssertFileExist(const char *filename)
|
||||
{
|
||||
struct stat st;
|
||||
int ret = stat(filename, &st);
|
||||
|
||||
SDLTest_AssertCheck(ret == 0, "Verify file '%s' exists", filename);
|
||||
}
|
||||
|
||||
|
||||
/* Test case functions */
|
||||
|
||||
/**
|
||||
* @brief Tests sprite saving and loading
|
||||
*/
|
||||
int
|
||||
surface_testSaveLoadBitmap(void *arg)
|
||||
{
|
||||
int ret;
|
||||
const char *sampleFilename = "testSaveLoadBitmap.bmp";
|
||||
SDL_Surface *face;
|
||||
SDL_Surface *rface;
|
||||
|
||||
/* Create sample surface */
|
||||
face = SDLTest_ImageFace();
|
||||
SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
|
||||
if (face == NULL) return TEST_ABORTED;
|
||||
|
||||
/* Delete test file; ignore errors */
|
||||
unlink(sampleFilename);
|
||||
|
||||
/* Save a surface */
|
||||
ret = SDL_SaveBMP(face, sampleFilename);
|
||||
SDLTest_AssertPass("Call to SDL_SaveBMP()");
|
||||
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SaveBMP, expected: 0, got: %i", ret);
|
||||
_AssertFileExist(sampleFilename);
|
||||
|
||||
/* Load a surface */
|
||||
rface = SDL_LoadBMP(sampleFilename);
|
||||
SDLTest_AssertPass("Call to SDL_LoadBMP()");
|
||||
SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_LoadBMP is not NULL");
|
||||
if (rface != NULL) {
|
||||
SDLTest_AssertCheck(face->w == rface->w, "Verify width of loaded surface, expected: %i, got: %i", face->w, rface->w);
|
||||
SDLTest_AssertCheck(face->h == rface->h, "Verify height of loaded surface, expected: %i, got: %i", face->h, rface->h);
|
||||
}
|
||||
|
||||
/* Delete test file; ignore errors */
|
||||
unlink(sampleFilename);
|
||||
|
||||
/* Clean up */
|
||||
SDL_FreeSurface(face);
|
||||
face = NULL;
|
||||
SDL_FreeSurface(rface);
|
||||
rface = NULL;
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* !
|
||||
* Tests surface conversion.
|
||||
*/
|
||||
int
|
||||
surface_testSurfaceConversion(void *arg)
|
||||
{
|
||||
SDL_Surface *rface = NULL, *face = NULL;
|
||||
int ret = 0;
|
||||
|
||||
/* Create sample surface */
|
||||
face = SDLTest_ImageFace();
|
||||
SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
|
||||
if (face == NULL)
|
||||
return TEST_ABORTED;
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* Convert to 32 bit to compare. */
|
||||
rface = SDL_ConvertSurface( face, testSurface->format, 0 );
|
||||
SDLTest_AssertPass("Call to SDL_ConvertSurface()");
|
||||
SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_ConvertSurface is not NULL");
|
||||
|
||||
/* Compare surface. */
|
||||
ret = SDLTest_CompareSurfaces( rface, face, 0 );
|
||||
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
|
||||
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface(face);
|
||||
face = NULL;
|
||||
SDL_FreeSurface(rface);
|
||||
rface = NULL;
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
/* !
|
||||
* Tests surface conversion across all pixel formats.
|
||||
*/
|
||||
int
|
||||
surface_testCompleteSurfaceConversion(void *arg)
|
||||
{
|
||||
Uint32 pixel_formats[] = {
|
||||
SDL_PIXELFORMAT_INDEX8,
|
||||
SDL_PIXELFORMAT_RGB332,
|
||||
SDL_PIXELFORMAT_RGB444,
|
||||
SDL_PIXELFORMAT_RGB555,
|
||||
SDL_PIXELFORMAT_BGR555,
|
||||
SDL_PIXELFORMAT_ARGB4444,
|
||||
SDL_PIXELFORMAT_RGBA4444,
|
||||
SDL_PIXELFORMAT_ABGR4444,
|
||||
SDL_PIXELFORMAT_BGRA4444,
|
||||
SDL_PIXELFORMAT_ARGB1555,
|
||||
SDL_PIXELFORMAT_RGBA5551,
|
||||
SDL_PIXELFORMAT_ABGR1555,
|
||||
SDL_PIXELFORMAT_BGRA5551,
|
||||
SDL_PIXELFORMAT_RGB565,
|
||||
SDL_PIXELFORMAT_BGR565,
|
||||
SDL_PIXELFORMAT_RGB24,
|
||||
SDL_PIXELFORMAT_BGR24,
|
||||
SDL_PIXELFORMAT_RGB888,
|
||||
SDL_PIXELFORMAT_RGBX8888,
|
||||
SDL_PIXELFORMAT_BGR888,
|
||||
SDL_PIXELFORMAT_BGRX8888,
|
||||
SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_PIXELFORMAT_RGBA8888,
|
||||
SDL_PIXELFORMAT_ABGR8888,
|
||||
SDL_PIXELFORMAT_BGRA8888,
|
||||
SDL_PIXELFORMAT_ARGB2101010,
|
||||
};
|
||||
SDL_Surface *face = NULL, *cvt1, *cvt2, *final;
|
||||
SDL_PixelFormat *fmt1, *fmt2;
|
||||
int i, j, ret = 0;
|
||||
|
||||
/* Create sample surface */
|
||||
face = SDLTest_ImageFace();
|
||||
SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
|
||||
if (face == NULL)
|
||||
return TEST_ABORTED;
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
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);
|
||||
SDL_assert(cvt1 != NULL);
|
||||
|
||||
fmt2 = SDL_AllocFormat(pixel_formats[j]);
|
||||
SDL_assert(fmt1 != NULL);
|
||||
cvt2 = SDL_ConvertSurface(cvt1, fmt2, 0);
|
||||
SDL_assert(cvt2 != NULL);
|
||||
|
||||
if ( fmt1->BytesPerPixel == face->format->BytesPerPixel &&
|
||||
fmt2->BytesPerPixel == face->format->BytesPerPixel &&
|
||||
(fmt1->Amask != 0) == (face->format->Amask != 0) &&
|
||||
(fmt2->Amask != 0) == (face->format->Amask != 0) ) {
|
||||
final = SDL_ConvertSurface( cvt2, face->format, 0 );
|
||||
SDL_assert(final != NULL);
|
||||
|
||||
/* Compare surface. */
|
||||
ret = SDLTest_CompareSurfaces( face, final, 0 );
|
||||
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
|
||||
SDL_FreeSurface(final);
|
||||
}
|
||||
|
||||
SDL_FreeSurface(cvt1);
|
||||
SDL_FreeFormat(fmt1);
|
||||
SDL_FreeSurface(cvt2);
|
||||
SDL_FreeFormat(fmt2);
|
||||
}
|
||||
}
|
||||
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface( face );
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Tests sprite loading. A failure case.
|
||||
*/
|
||||
int
|
||||
surface_testLoadFailure(void *arg)
|
||||
{
|
||||
SDL_Surface *face = SDL_LoadBMP("nonexistant.bmp");
|
||||
SDLTest_AssertCheck(face == NULL, "SDL_CreateLoadBmp");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests some blitting routines.
|
||||
*/
|
||||
int
|
||||
surface_testBlit(void *arg)
|
||||
{
|
||||
int ret;
|
||||
SDL_Surface *compareSurface;
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface(compareSurface);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests some blitting routines with color mod
|
||||
*/
|
||||
int
|
||||
surface_testBlitColorMod(void *arg)
|
||||
{
|
||||
int ret;
|
||||
SDL_Surface *compareSurface;
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface(compareSurface);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests some blitting routines with alpha mod
|
||||
*/
|
||||
int
|
||||
surface_testBlitAlphaMod(void *arg)
|
||||
{
|
||||
int ret;
|
||||
SDL_Surface *compareSurface;
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests some more blitting routines.
|
||||
*/
|
||||
int
|
||||
surface_testBlitBlendBlend(void *arg)
|
||||
{
|
||||
int ret;
|
||||
SDL_Surface *compareSurface;
|
||||
|
||||
/* Blend blitting */
|
||||
_testBlitBlendMode(SDL_BLENDMODE_BLEND);
|
||||
|
||||
/* 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);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests some more blitting routines.
|
||||
*/
|
||||
int
|
||||
surface_testBlitBlendAdd(void *arg)
|
||||
{
|
||||
int ret;
|
||||
SDL_Surface *compareSurface;
|
||||
|
||||
/* Add blitting */
|
||||
_testBlitBlendMode(SDL_BLENDMODE_ADD);
|
||||
|
||||
/* 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);
|
||||
|
||||
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 ret;
|
||||
SDL_Surface *compareSurface;
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface(compareSurface);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
|
||||
}
|
||||
|
||||
/* ================= 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 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 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 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 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 blittin routines with verious 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};
|
||||
|
||||
/* 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 surfaceTest12 =
|
||||
{ (SDLTest_TestCaseFp)surface_testBlitBlendMod, "surface_testBlitBlendMod", "Tests blitting routines with mod blending mode.", TEST_ENABLED};
|
||||
|
||||
/* Sequence of Surface test cases */
|
||||
static const SDLTest_TestCaseReference *surfaceTests[] = {
|
||||
&surfaceTest1, &surfaceTest2, &surfaceTest3, &surfaceTest4, &surfaceTest5,
|
||||
&surfaceTest6, &surfaceTest7, &surfaceTest8, &surfaceTest9, &surfaceTest10,
|
||||
&surfaceTest11, &surfaceTest12, NULL
|
||||
};
|
||||
|
||||
/* Surface test suite (global) */
|
||||
SDLTest_TestSuiteReference surfaceTestSuite = {
|
||||
"Surface",
|
||||
_surfaceSetUp,
|
||||
surfaceTests,
|
||||
_surfaceTearDown
|
||||
|
||||
};
|
61
test/testautomation_syswm.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* SysWM test suite
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_syswm.h"
|
||||
#include "SDL_test.h"
|
||||
|
||||
/* Test case functions */
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_GetWindowWMInfo
|
||||
*/
|
||||
int
|
||||
syswm_getWindowWMInfo(void *arg)
|
||||
{
|
||||
SDL_bool result;
|
||||
SDL_Window *window;
|
||||
SDL_SysWMinfo info;
|
||||
|
||||
window = SDL_CreateWindow("", 0, 0, 0, 0, SDL_WINDOW_HIDDEN);
|
||||
SDLTest_AssertPass("Call to SDL_CreateWindow()");
|
||||
SDLTest_AssertCheck(window != NULL, "Check that value returned from SDL_CreateWindow is not NULL");
|
||||
if (window == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Initialize info structure with SDL version info */
|
||||
SDL_VERSION(&info.version);
|
||||
|
||||
/* Make call */
|
||||
result = SDL_GetWindowWMInfo(window, &info);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowWMInfo");
|
||||
SDLTest_Log((result == SDL_TRUE) ? "Got window information" : "Couldn't get window information");
|
||||
|
||||
SDL_DestroyWindow(window);
|
||||
SDLTest_AssertPass("Call to SDL_DestroyWindow()");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* ================= Test References ================== */
|
||||
|
||||
/* SysWM test cases */
|
||||
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[] = {
|
||||
&syswmTest1, NULL
|
||||
};
|
||||
|
||||
/* SysWM test suite (global) */
|
||||
SDLTest_TestSuiteReference syswmTestSuite = {
|
||||
"SysWM",
|
||||
NULL,
|
||||
syswmTests,
|
||||
NULL
|
||||
};
|
201
test/testautomation_timer.c
Normal file
@@ -0,0 +1,201 @@
|
||||
/**
|
||||
* Timer test suite
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_test.h"
|
||||
|
||||
/* Flag indicating if the param should be checked */
|
||||
int _paramCheck = 0;
|
||||
|
||||
/* Userdata value to check */
|
||||
int _paramValue = 0;
|
||||
|
||||
/* Flag indicating that the callback was called */
|
||||
int _timerCallbackCalled = 0;
|
||||
|
||||
/* Fixture */
|
||||
|
||||
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)");
|
||||
if (ret != 0) {
|
||||
SDLTest_LogError("%s", SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
/* Test case functions */
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_GetPerformanceCounter
|
||||
*/
|
||||
int
|
||||
timer_getPerformanceCounter(void *arg)
|
||||
{
|
||||
Uint64 result;
|
||||
|
||||
result = SDL_GetPerformanceCounter();
|
||||
SDLTest_AssertPass("Call to SDL_GetPerformanceCounter()");
|
||||
SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %lu", result);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_GetPerformanceFrequency
|
||||
*/
|
||||
int
|
||||
timer_getPerformanceFrequency(void *arg)
|
||||
{
|
||||
Uint64 result;
|
||||
|
||||
result = SDL_GetPerformanceFrequency();
|
||||
SDLTest_AssertPass("Call to SDL_GetPerformanceFrequency()");
|
||||
SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %lu", result);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_Delay and SDL_GetTicks
|
||||
*/
|
||||
int
|
||||
timer_delayAndGetTicks(void *arg)
|
||||
{
|
||||
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)");
|
||||
|
||||
/* 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()");
|
||||
|
||||
/* 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: %d", result);
|
||||
|
||||
/* Delay a bit longer and measure ticks and verify difference */
|
||||
SDL_Delay(testDelay);
|
||||
SDLTest_AssertPass("Call to SDL_Delay(%d)", testDelay);
|
||||
result2 = SDL_GetTicks();
|
||||
SDLTest_AssertPass("Call to SDL_GetTicks()");
|
||||
SDLTest_AssertCheck(result2 > 0, "Check result value, expected: >0, got: %d", result2);
|
||||
difference = result2 - result;
|
||||
SDLTest_AssertCheck(difference > (testDelay - marginOfError), "Check difference, expected: >%d, got: %d", testDelay - marginOfError, difference);
|
||||
SDLTest_AssertCheck(difference < (testDelay + marginOfError), "Check difference, expected: <%d, got: %d", testDelay + marginOfError, difference);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* Test callback */
|
||||
Uint32 _timerTestCallback(Uint32 interval, void *param)
|
||||
{
|
||||
_timerCallbackCalled = 1;
|
||||
|
||||
if (_paramCheck != 0) {
|
||||
SDLTest_AssertCheck(param != NULL, "Check param pointer, expected: non-NULL, got: %s", (param != NULL) ? "non-NULL" : "NULL");
|
||||
if (param != NULL) {
|
||||
SDLTest_AssertCheck(*(int *)param == _paramValue, "Check param value, expected: %i, got: %i", _paramValue, *(int *)param);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_AddTimer and SDL_RemoveTimer
|
||||
*/
|
||||
int
|
||||
timer_addRemoveTimer(void *arg)
|
||||
{
|
||||
SDL_TimerID id;
|
||||
SDL_bool result;
|
||||
int param;
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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 *)¶m);
|
||||
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)");
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* ================= 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 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 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[] = {
|
||||
&timerTest1, &timerTest2, &timerTest3, &timerTest4, NULL
|
||||
};
|
||||
|
||||
/* Timer test suite (global) */
|
||||
SDLTest_TestSuiteReference timerTestSuite = {
|
||||
"Timer",
|
||||
_timerSetUp,
|
||||
timerTests,
|
||||
NULL
|
||||
};
|
1813
test/testautomation_video.c
Normal file
280
test/testdraw2.c
Normal file
@@ -0,0 +1,280 @@
|
||||
/*
|
||||
Copyright (C) 1997-2014 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: draw as many random objects on the screen as possible */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "SDL_test_common.h"
|
||||
|
||||
#define NUM_OBJECTS 100
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
static int num_objects;
|
||||
static SDL_bool cycle_color;
|
||||
static SDL_bool cycle_alpha;
|
||||
static int cycle_direction = 1;
|
||||
static int current_alpha = 255;
|
||||
static int current_color = 255;
|
||||
static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
|
||||
|
||||
void
|
||||
DrawPoints(SDL_Renderer * renderer)
|
||||
{
|
||||
int i;
|
||||
int x, y;
|
||||
SDL_Rect viewport;
|
||||
|
||||
/* Query the sizes */
|
||||
SDL_RenderGetViewport(renderer, &viewport);
|
||||
|
||||
for (i = 0; i < num_objects * 4; ++i) {
|
||||
/* Cycle the color and alpha, if desired */
|
||||
if (cycle_color) {
|
||||
current_color += cycle_direction;
|
||||
if (current_color < 0) {
|
||||
current_color = 0;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
if (current_color > 255) {
|
||||
current_color = 255;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
}
|
||||
if (cycle_alpha) {
|
||||
current_alpha += cycle_direction;
|
||||
if (current_alpha < 0) {
|
||||
current_alpha = 0;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
if (current_alpha > 255) {
|
||||
current_alpha = 255;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer, 255, (Uint8) current_color,
|
||||
(Uint8) current_color, (Uint8) current_alpha);
|
||||
|
||||
x = rand() % viewport.w;
|
||||
y = rand() % viewport.h;
|
||||
SDL_RenderDrawPoint(renderer, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DrawLines(SDL_Renderer * renderer)
|
||||
{
|
||||
int i;
|
||||
int x1, y1, x2, y2;
|
||||
SDL_Rect viewport;
|
||||
|
||||
/* Query the sizes */
|
||||
SDL_RenderGetViewport(renderer, &viewport);
|
||||
|
||||
for (i = 0; i < num_objects; ++i) {
|
||||
/* Cycle the color and alpha, if desired */
|
||||
if (cycle_color) {
|
||||
current_color += cycle_direction;
|
||||
if (current_color < 0) {
|
||||
current_color = 0;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
if (current_color > 255) {
|
||||
current_color = 255;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
}
|
||||
if (cycle_alpha) {
|
||||
current_alpha += cycle_direction;
|
||||
if (current_alpha < 0) {
|
||||
current_alpha = 0;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
if (current_alpha > 255) {
|
||||
current_alpha = 255;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
}
|
||||
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);
|
||||
SDL_RenderDrawLine(renderer, 0, viewport.h - 1, viewport.w - 1, 0);
|
||||
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;
|
||||
SDL_RenderDrawLine(renderer, x1, y1, x2, y2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DrawRects(SDL_Renderer * renderer)
|
||||
{
|
||||
int i;
|
||||
SDL_Rect rect;
|
||||
SDL_Rect viewport;
|
||||
|
||||
/* Query the sizes */
|
||||
SDL_RenderGetViewport(renderer, &viewport);
|
||||
|
||||
for (i = 0; i < num_objects / 4; ++i) {
|
||||
/* Cycle the color and alpha, if desired */
|
||||
if (cycle_color) {
|
||||
current_color += cycle_direction;
|
||||
if (current_color < 0) {
|
||||
current_color = 0;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
if (current_color > 255) {
|
||||
current_color = 255;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
}
|
||||
if (cycle_alpha) {
|
||||
current_alpha += cycle_direction;
|
||||
if (current_alpha < 0) {
|
||||
current_alpha = 0;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
if (current_alpha > 255) {
|
||||
current_alpha = 255;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
}
|
||||
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);
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i, done;
|
||||
SDL_Event event;
|
||||
Uint32 then, now, frames;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Initialize parameters */
|
||||
num_objects = NUM_OBJECTS;
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
int consumed;
|
||||
|
||||
consumed = SDLTest_CommonArg(state, i);
|
||||
if (consumed == 0) {
|
||||
consumed = -1;
|
||||
if (SDL_strcasecmp(argv[i], "--blend") == 0) {
|
||||
if (argv[i + 1]) {
|
||||
if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
|
||||
blendMode = SDL_BLENDMODE_NONE;
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) {
|
||||
blendMode = SDL_BLENDMODE_BLEND;
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "add") == 0) {
|
||||
blendMode = SDL_BLENDMODE_ADD;
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) {
|
||||
blendMode = SDL_BLENDMODE_MOD;
|
||||
consumed = 2;
|
||||
}
|
||||
}
|
||||
} else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) {
|
||||
cycle_color = SDL_TRUE;
|
||||
consumed = 1;
|
||||
} else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) {
|
||||
cycle_alpha = SDL_TRUE;
|
||||
consumed = 1;
|
||||
} else if (SDL_isdigit(*argv[i])) {
|
||||
num_objects = SDL_atoi(argv[i]);
|
||||
consumed = 1;
|
||||
}
|
||||
}
|
||||
if (consumed < 0) {
|
||||
SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha]\n",
|
||||
argv[0], SDLTest_CommonUsage(state));
|
||||
return 1;
|
||||
}
|
||||
i += consumed;
|
||||
}
|
||||
if (!SDLTest_CommonInit(state)) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
/* Create the windows and initialize the renderers */
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
SDL_SetRenderDrawBlendMode(renderer, blendMode);
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
}
|
||||
|
||||
srand((unsigned int)time(NULL));
|
||||
|
||||
/* Main render loop */
|
||||
frames = 0;
|
||||
then = SDL_GetTicks();
|
||||
done = 0;
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
++frames;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
DrawRects(renderer);
|
||||
DrawLines(renderer);
|
||||
DrawPoints(renderer);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
SDLTest_CommonQuit(state);
|
||||
|
||||
/* Print out some timing information */
|
||||
now = SDL_GetTicks();
|
||||
if (now > then) {
|
||||
double fps = ((double) frames * 1000) / (now - then);
|
||||
SDL_Log("%2.2f frames per second\n", fps);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
110
test/testdrawchessboard.c
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
Copyright (C) 1997-2014 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.
|
||||
|
||||
This file is created by : Nitin Jain (nitin.j4@samsung.com)
|
||||
*/
|
||||
|
||||
/* Sample program: Draw a Chess Board by using SDL_CreateSoftwareRenderer API */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
void
|
||||
DrawChessBoard(SDL_Renderer * renderer)
|
||||
{
|
||||
int row = 0,coloum = 0,x = 0;
|
||||
SDL_Rect rect, darea;
|
||||
|
||||
/* Get the Size of drawing surface */
|
||||
SDL_RenderGetViewport(renderer, &darea);
|
||||
|
||||
for(row; row < 8; row++)
|
||||
{
|
||||
coloum = row%2;
|
||||
x = x + coloum;
|
||||
for(coloum; coloum < 4+(row%2); coloum++)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0xFF);
|
||||
|
||||
rect.w = darea.w/8;
|
||||
rect.h = darea.h/8;
|
||||
rect.x = x * rect.w;
|
||||
rect.y = row * rect.h;
|
||||
x = x + 2;
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
}
|
||||
x=0;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Window *window;
|
||||
SDL_Surface *surface;
|
||||
SDL_Renderer *renderer;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Initialize SDL */
|
||||
if(SDL_Init(SDL_INIT_VIDEO) != 0)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init fail : %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Create window and renderer for given surface */
|
||||
window = SDL_CreateWindow("Chess Board", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
|
||||
if(!window)
|
||||
{
|
||||
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)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n",SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Clear the rendering surface with the specified color */
|
||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
|
||||
/* Draw the Image on rendering surface */
|
||||
while(1)
|
||||
{
|
||||
SDL_Event e;
|
||||
if (SDL_PollEvent(&e)) {
|
||||
if (e.type == SDL_QUIT)
|
||||
break;
|
||||
|
||||
if(e.key.keysym.sym == SDLK_ESCAPE)
|
||||
break;
|
||||
}
|
||||
|
||||
DrawChessBoard(renderer);
|
||||
|
||||
/* Got everything on rendering surface,
|
||||
now Update the drawing image on window screen */
|
||||
SDL_UpdateWindowSurface(window);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
93
test/testdropfile.c
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
Copyright (C) 1997-2014 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 "SDL_test_common.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 i, done;
|
||||
SDL_Event event;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 1; i < argc;) {
|
||||
int consumed;
|
||||
|
||||
consumed = SDLTest_CommonArg(state, i);
|
||||
// needed vodoo to allow app to launch via OS X Finder
|
||||
if (SDL_strncmp(argv[i], "-psn", 4)==0) {
|
||||
consumed = 1;
|
||||
}
|
||||
if (consumed == 0) {
|
||||
consumed = -1;
|
||||
}
|
||||
if (consumed < 0) {
|
||||
SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
|
||||
quit(1);
|
||||
}
|
||||
i += consumed;
|
||||
}
|
||||
if (!SDLTest_CommonInit(state)) {
|
||||
quit(2);
|
||||
}
|
||||
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
|
||||
|
||||
/* Main render loop */
|
||||
done = 0;
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
|
||||
if (event.type == SDL_DROPFILE) {
|
||||
char *dropped_filedir = event.drop.file;
|
||||
SDL_Log("File dropped on window: %s", dropped_filedir);
|
||||
SDL_free(dropped_filedir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
quit(0);
|
||||
/* keep the compiler happy ... */
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
78
test/testerror.c
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
Copyright (C) 1997-2014 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 test of the SDL threading code and error handling */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_thread.h"
|
||||
|
||||
static int alive = 0;
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
{
|
||||
SDL_Quit();
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
int SDLCALL
|
||||
ThreadFunc(void *data)
|
||||
{
|
||||
/* Set the child thread error string */
|
||||
SDL_SetError("Thread %s (%lu) had a problem: %s",
|
||||
(char *) data, SDL_ThreadID(), "nevermind");
|
||||
while (alive) {
|
||||
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[])
|
||||
{
|
||||
SDL_Thread *thread;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Load the SDL library */
|
||||
if (SDL_Init(0) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Set the error value for the main thread */
|
||||
SDL_SetError("No worries");
|
||||
|
||||
alive = 1;
|
||||
thread = SDL_CreateThread(ThreadFunc, NULL, "#1");
|
||||
if (thread == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
|
||||
quit(1);
|
||||
}
|
||||
SDL_Delay(5 * 1000);
|
||||
SDL_Log("Waiting for thread #1\n");
|
||||
alive = 0;
|
||||
SDL_WaitThread(thread, NULL);
|
||||
|
||||
SDL_Log("Main thread error string: %s\n", SDL_GetError());
|
||||
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
}
|
284
test/testfile.c
Normal file
@@ -0,0 +1,284 @@
|
||||
/*
|
||||
Copyright (C) 1997-2014 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.
|
||||
*/
|
||||
|
||||
/* sanity tests on SDL_rwops.c (usefull for alternative implementations of stdio rwops) */
|
||||
|
||||
/* quiet windows compiler warnings */
|
||||
#define _CRT_NONSTDC_NO_WARNINGS
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_endian.h"
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* WARNING ! those 2 files will be destroyed by this test program */
|
||||
|
||||
#ifdef __IPHONEOS__
|
||||
#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 */
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
|
||||
static void
|
||||
cleanup(void)
|
||||
{
|
||||
unlink(FBASENAME1);
|
||||
unlink(FBASENAME2);
|
||||
}
|
||||
|
||||
static void
|
||||
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); */
|
||||
}
|
||||
cleanup();
|
||||
exit(1); /* quit with rwops error (test failed) */
|
||||
}
|
||||
|
||||
#define RWOP_ERR_QUIT(x) rwops_error_quit( __LINE__, (x) )
|
||||
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SDL_RWops *rwops = NULL;
|
||||
char test_buf[30];
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
cleanup();
|
||||
|
||||
/* test 1 : basic argument test: all those calls to SDL_RWFromFile should fail */
|
||||
|
||||
rwops = SDL_RWFromFile(NULL, NULL);
|
||||
if (rwops)
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
rwops = SDL_RWFromFile(NULL, "ab+");
|
||||
if (rwops)
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
rwops = SDL_RWFromFile(NULL, "sldfkjsldkfj");
|
||||
if (rwops)
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
rwops = SDL_RWFromFile("something", "");
|
||||
if (rwops)
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
rwops = SDL_RWFromFile("something", NULL);
|
||||
if (rwops)
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
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)
|
||||
|
||||
*/
|
||||
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 */
|
||||
if (rwops)
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
rwops = SDL_RWFromFile(FBASENAME2, "wb");
|
||||
if (!rwops)
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
rwops->close(rwops);
|
||||
unlink(FBASENAME2);
|
||||
rwops = SDL_RWFromFile(FBASENAME2, "wb+");
|
||||
if (!rwops)
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
rwops->close(rwops);
|
||||
unlink(FBASENAME2);
|
||||
rwops = SDL_RWFromFile(FBASENAME2, "ab");
|
||||
if (!rwops)
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
rwops->close(rwops);
|
||||
unlink(FBASENAME2);
|
||||
rwops = SDL_RWFromFile(FBASENAME2, "ab+");
|
||||
if (!rwops)
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
rwops->close(rwops);
|
||||
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 */
|
||||
if (!rwops)
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (1 != rwops->write(rwops, "1234567890", 10, 1))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (10 != rwops->write(rwops, "1234567890", 1, 10))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->write(rwops, "1234567", 1, 7))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1))
|
||||
RWOP_ERR_QUIT(rwops); /* we are in write only mode */
|
||||
rwops->close(rwops);
|
||||
|
||||
rwops = SDL_RWFromFile(FBASENAME1, "rb"); /* read mode, file must exists */
|
||||
if (!rwops)
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (20 != rwops->seek(rwops, -7, RW_SEEK_END))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->read(rwops, test_buf, 1, 7))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "1234567", 7))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 10, 100))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (2 != rwops->read(rwops, test_buf, 10, 3))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "12345678901234567890", 20))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->write(rwops, test_buf, 1, 1))
|
||||
RWOP_ERR_QUIT(rwops); /* readonly mode */
|
||||
rwops->close(rwops);
|
||||
|
||||
/* test 3: same with w+ mode */
|
||||
rwops = SDL_RWFromFile(FBASENAME1, "wb+"); /* write + read + truncation */
|
||||
if (!rwops)
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (1 != rwops->write(rwops, "1234567890", 10, 1))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (10 != rwops->write(rwops, "1234567890", 1, 10))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->write(rwops, "1234567", 1, 7))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (1 != rwops->read(rwops, test_buf, 1, 1))
|
||||
RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (20 != rwops->seek(rwops, -7, RW_SEEK_END))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->read(rwops, test_buf, 1, 7))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "1234567", 7))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 10, 100))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (2 != rwops->read(rwops, test_buf, 10, 3))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "12345678901234567890", 20))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
rwops->close(rwops);
|
||||
SDL_Log("test3 OK\n");
|
||||
|
||||
/* test 4: same in r+ mode */
|
||||
rwops = SDL_RWFromFile(FBASENAME1, "rb+"); /* write + read + file must exists, no truncation */
|
||||
if (!rwops)
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (1 != rwops->write(rwops, "1234567890", 10, 1))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (10 != rwops->write(rwops, "1234567890", 1, 10))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->write(rwops, "1234567", 1, 7))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (1 != rwops->read(rwops, test_buf, 1, 1))
|
||||
RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (20 != rwops->seek(rwops, -7, RW_SEEK_END))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->read(rwops, test_buf, 1, 7))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "1234567", 7))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 10, 100))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (2 != rwops->read(rwops, test_buf, 10, 3))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "12345678901234567890", 20))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
rwops->close(rwops);
|
||||
SDL_Log("test4 OK\n");
|
||||
|
||||
/* test5 : append mode */
|
||||
rwops = SDL_RWFromFile(FBASENAME1, "ab+"); /* write + read + append */
|
||||
if (!rwops)
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (1 != rwops->write(rwops, "1234567890", 10, 1))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (10 != rwops->write(rwops, "1234567890", 1, 10))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->write(rwops, "1234567", 1, 7))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
|
||||
if (1 != rwops->read(rwops, test_buf, 1, 1))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
|
||||
if (20 + 27 != rwops->seek(rwops, -7, RW_SEEK_END))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->read(rwops, test_buf, 1, 7))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "1234567", 7))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 10, 100))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
|
||||
if (27 != rwops->seek(rwops, -27, RW_SEEK_CUR))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (3 != rwops->read(rwops, test_buf, 10, 3))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "123456789012345678901234567123", 30))
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
rwops->close(rwops);
|
||||
SDL_Log("test5 OK\n");
|
||||
cleanup();
|
||||
return 0; /* all ok */
|
||||
}
|
33
test/testfilesystem.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
Copyright (C) 1997-2014 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 test of power subsystem. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "SDL.h"
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
if (SDL_Init(0) == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_Log("base path: '%s'\n", SDL_GetBasePath());
|
||||
SDL_Log("pref path: '%s'\n", SDL_GetPrefPath("libsdl", "testfilesystem"));
|
||||
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
357
test/testgamecontroller.c
Normal file
@@ -0,0 +1,357 @@
|
||||
/*
|
||||
Copyright (C) 1997-2014 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"
|
||||
|
||||
#ifndef SDL_JOYSTICK_DISABLED
|
||||
|
||||
#ifdef __IPHONEOS__
|
||||
#define SCREEN_WIDTH 320
|
||||
#define SCREEN_HEIGHT 480
|
||||
#else
|
||||
#define SCREEN_WIDTH 512
|
||||
#define SCREEN_HEIGHT 317
|
||||
#endif
|
||||
|
||||
static const char *
|
||||
ControllerAxisName(const SDL_GameControllerAxis axis)
|
||||
{
|
||||
switch (axis)
|
||||
{
|
||||
#define AXIS_CASE(ax) case SDL_CONTROLLER_AXIS_##ax: return #ax
|
||||
AXIS_CASE(INVALID);
|
||||
AXIS_CASE(LEFTX);
|
||||
AXIS_CASE(LEFTY);
|
||||
AXIS_CASE(RIGHTX);
|
||||
AXIS_CASE(RIGHTY);
|
||||
AXIS_CASE(TRIGGERLEFT);
|
||||
AXIS_CASE(TRIGGERRIGHT);
|
||||
#undef AXIS_CASE
|
||||
default: return "???";
|
||||
}
|
||||
}
|
||||
|
||||
static const char *
|
||||
ControllerButtonName(const SDL_GameControllerButton button)
|
||||
{
|
||||
switch (button)
|
||||
{
|
||||
#define BUTTON_CASE(btn) case SDL_CONTROLLER_BUTTON_##btn: return #btn
|
||||
BUTTON_CASE(INVALID);
|
||||
BUTTON_CASE(A);
|
||||
BUTTON_CASE(B);
|
||||
BUTTON_CASE(X);
|
||||
BUTTON_CASE(Y);
|
||||
BUTTON_CASE(BACK);
|
||||
BUTTON_CASE(GUIDE);
|
||||
BUTTON_CASE(START);
|
||||
BUTTON_CASE(LEFTSTICK);
|
||||
BUTTON_CASE(RIGHTSTICK);
|
||||
BUTTON_CASE(LEFTSHOULDER);
|
||||
BUTTON_CASE(RIGHTSHOULDER);
|
||||
BUTTON_CASE(DPAD_UP);
|
||||
BUTTON_CASE(DPAD_DOWN);
|
||||
BUTTON_CASE(DPAD_LEFT);
|
||||
BUTTON_CASE(DPAD_RIGHT);
|
||||
#undef BUTTON_CASE
|
||||
default: return "???";
|
||||
}
|
||||
}
|
||||
|
||||
static SDL_Texture *
|
||||
LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
|
||||
{
|
||||
SDL_Surface *temp = NULL;
|
||||
SDL_Texture *texture = NULL;
|
||||
|
||||
temp = SDL_LoadBMP(file);
|
||||
if (temp == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
|
||||
} else {
|
||||
/* Set transparent pixel as the pixel at (0,0) */
|
||||
if (transparent) {
|
||||
if (temp->format->BytesPerPixel == 1) {
|
||||
SDL_SetColorKey(temp, SDL_TRUE, *(Uint8 *)temp->pixels);
|
||||
} else {
|
||||
SDL_assert(!temp->format->palette);
|
||||
SDL_assert(temp->format->BitsPerPixel == 24);
|
||||
SDL_SetColorKey(temp, SDL_TRUE, (*(Uint32 *)temp->pixels) & 0x00FFFFFF);
|
||||
}
|
||||
}
|
||||
|
||||
texture = SDL_CreateTextureFromSurface(renderer, temp);
|
||||
if (!texture) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
|
||||
}
|
||||
}
|
||||
if (temp) {
|
||||
SDL_FreeSurface(temp);
|
||||
}
|
||||
return texture;
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
WatchGameController(SDL_GameController * gamecontroller)
|
||||
{
|
||||
/* This is indexed by SDL_GameControllerButton. */
|
||||
static const struct { int x; int y; } button_positions[] = {
|
||||
{387, 167}, /* A */
|
||||
{431, 132}, /* B */
|
||||
{342, 132}, /* X */
|
||||
{389, 101}, /* Y */
|
||||
{174, 132}, /* BACK */
|
||||
{233, 132}, /* GUIDE */
|
||||
{289, 132}, /* START */
|
||||
{75, 154}, /* LEFTSTICK */
|
||||
{305, 230}, /* RIGHTSTICK */
|
||||
{77, 40}, /* LEFTSHOULDER */
|
||||
{396, 36}, /* RIGHTSHOULDER */
|
||||
{154, 188}, /* DPAD_UP */
|
||||
{154, 249}, /* DPAD_DOWN */
|
||||
{116, 217}, /* DPAD_LEFT */
|
||||
{186, 217}, /* DPAD_RIGHT */
|
||||
};
|
||||
|
||||
/* This is indexed by SDL_GameControllerAxis. */
|
||||
static const struct { int x; int y; double angle; } axis_positions[] = {
|
||||
{75, 154, 0.0}, /* LEFTX */
|
||||
{75, 154, 90.0}, /* LEFTY */
|
||||
{305, 230, 0.0}, /* RIGHTX */
|
||||
{305, 230, 90.0}, /* RIGHTY */
|
||||
{91, 0, 90.0}, /* TRIGGERLEFT */
|
||||
{375, 0, 90.0}, /* TRIGGERRIGHT */
|
||||
};
|
||||
|
||||
const char *name = SDL_GameControllerName(gamecontroller);
|
||||
const char *basetitle = "Game Controller Test: ";
|
||||
const size_t titlelen = SDL_strlen(basetitle) + SDL_strlen(name) + 1;
|
||||
char *title = (char *)SDL_malloc(titlelen);
|
||||
SDL_Texture *background, *button, *axis;
|
||||
SDL_Window *window = NULL;
|
||||
SDL_Renderer *screen = NULL;
|
||||
SDL_bool retval = SDL_FALSE;
|
||||
SDL_bool done = SDL_FALSE;
|
||||
SDL_Event event;
|
||||
int i;
|
||||
|
||||
if (title) {
|
||||
SDL_snprintf(title, titlelen, "%s%s", basetitle, name);
|
||||
}
|
||||
|
||||
/* Create a window to display controller state */
|
||||
window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED,
|
||||
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
|
||||
SCREEN_HEIGHT, 0);
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
screen = SDL_CreateRenderer(window, -1, 0);
|
||||
if (screen == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "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);
|
||||
|
||||
/* scale for platforms that don't give you the window size you asked for. */
|
||||
SDL_RenderSetLogicalSize(screen, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
|
||||
background = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
|
||||
button = LoadTexture(screen, "button.bmp", SDL_TRUE);
|
||||
axis = LoadTexture(screen, "axis.bmp", SDL_TRUE);
|
||||
|
||||
if (!background || !button || !axis) {
|
||||
SDL_DestroyRenderer(screen);
|
||||
SDL_DestroyWindow(window);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
SDL_SetTextureColorMod(button, 10, 255, 21);
|
||||
SDL_SetTextureColorMod(axis, 10, 255, 21);
|
||||
|
||||
/* !!! FIXME: */
|
||||
/*SDL_RenderSetLogicalSize(screen, background->w, background->h);*/
|
||||
|
||||
/* Print info about the controller we are watching */
|
||||
SDL_Log("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, 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(screen);
|
||||
SDL_RenderCopy(screen, background, NULL, NULL);
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym != SDLK_ESCAPE) {
|
||||
break;
|
||||
}
|
||||
/* Fall through to signal quit */
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Update visual controller state */
|
||||
for (i = 0; i < SDL_CONTROLLER_BUTTON_MAX; ++i) {
|
||||
if (SDL_GameControllerGetButton(gamecontroller, (SDL_GameControllerButton)i) == SDL_PRESSED) {
|
||||
const SDL_Rect dst = { button_positions[i].x, button_positions[i].y, 50, 50 };
|
||||
SDL_RenderCopyEx(screen, button, NULL, &dst, 0, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < SDL_CONTROLLER_AXIS_MAX; ++i) {
|
||||
const Sint16 deadzone = 8000; /* !!! FIXME: real deadzone */
|
||||
const Sint16 value = SDL_GameControllerGetAxis(gamecontroller, (SDL_GameControllerAxis)(i));
|
||||
if (value < -deadzone) {
|
||||
const SDL_Rect dst = { axis_positions[i].x, axis_positions[i].y, 50, 50 };
|
||||
const double angle = axis_positions[i].angle;
|
||||
SDL_RenderCopyEx(screen, axis, NULL, &dst, angle, NULL, 0);
|
||||
} else if (value > deadzone) {
|
||||
const SDL_Rect dst = { axis_positions[i].x, axis_positions[i].y, 50, 50 };
|
||||
const double angle = axis_positions[i].angle + 180.0;
|
||||
SDL_RenderCopyEx(screen, axis, NULL, &dst, angle, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_RenderPresent(screen);
|
||||
|
||||
if (!SDL_GameControllerGetAttached(gamecontroller)) {
|
||||
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[])
|
||||
{
|
||||
int i;
|
||||
int nController = 0;
|
||||
int retcode = 0;
|
||||
char guid[64];
|
||||
SDL_GameController *gamecontroller;
|
||||
|
||||
/* Enable standard application logging */
|
||||
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) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_GameControllerAddMappingsFromFile("gamecontrollerdb.txt");
|
||||
|
||||
/* Print information about the controller */
|
||||
for (i = 0; i < SDL_NumJoysticks(); ++i) {
|
||||
const char *name;
|
||||
const char *description;
|
||||
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(i),
|
||||
guid, sizeof (guid));
|
||||
|
||||
if ( SDL_IsGameController(i) )
|
||||
{
|
||||
nController++;
|
||||
name = SDL_GameControllerNameForIndex(i);
|
||||
description = "Controller";
|
||||
} else {
|
||||
name = SDL_JoystickNameForIndex(i);
|
||||
description = "Joystick";
|
||||
}
|
||||
SDL_Log("%s %d: %s (guid %s)\n", description, i, name ? name : "Unknown", guid);
|
||||
}
|
||||
SDL_Log("There are %d game controller(s) attached (%d joystick(s))\n", nController, SDL_NumJoysticks());
|
||||
|
||||
if (argv[1]) {
|
||||
SDL_bool reportederror = SDL_FALSE;
|
||||
SDL_bool keepGoing = SDL_TRUE;
|
||||
SDL_Event event;
|
||||
int device = atoi(argv[1]);
|
||||
if (device >= SDL_NumJoysticks()) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%i is an invalid joystick index.\n", device);
|
||||
retcode = 1;
|
||||
} else {
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(device),
|
||||
guid, sizeof (guid));
|
||||
SDL_Log("Attempting to open device %i, guid %s\n", device, guid);
|
||||
gamecontroller = SDL_GameControllerOpen(device);
|
||||
while (keepGoing) {
|
||||
if (gamecontroller == NULL) {
|
||||
if (!reportederror) {
|
||||
if (gamecontroller == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open gamecontroller %d: %s\n", device, SDL_GetError());
|
||||
retcode = 1;
|
||||
}
|
||||
keepGoing = SDL_FALSE;
|
||||
reportederror = SDL_TRUE;
|
||||
}
|
||||
} else {
|
||||
reportederror = SDL_FALSE;
|
||||
keepGoing = WatchGameController(gamecontroller);
|
||||
SDL_GameControllerClose(gamecontroller);
|
||||
}
|
||||
|
||||
gamecontroller = NULL;
|
||||
if (keepGoing) {
|
||||
SDL_Log("Waiting for attach\n");
|
||||
}
|
||||
while (keepGoing) {
|
||||
SDL_WaitEvent(&event);
|
||||
if ((event.type == SDL_QUIT) || (event.type == SDL_FINGERDOWN)
|
||||
|| (event.type == SDL_MOUSEBUTTONDOWN)) {
|
||||
keepGoing = SDL_FALSE;
|
||||
} else if (event.type == SDL_CONTROLLERDEVICEADDED) {
|
||||
gamecontroller = SDL_GameControllerOpen(event.cdevice.which);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);
|
||||
|
||||
return retcode;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Joystick support.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#endif
|
314
test/testgesture.c
Normal file
@@ -0,0 +1,314 @@
|
||||
/*
|
||||
Copyright (C) 1997-2014 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.
|
||||
*/
|
||||
/* Usage:
|
||||
* Spacebar to begin recording a gesture on all touches.
|
||||
* s to save all touches into "./gestureSave"
|
||||
* l to load all touches from "./gestureSave"
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_touch.h"
|
||||
#include "SDL_gesture.h"
|
||||
|
||||
/* Make sure we have good macros for printing 32 and 64 bit values */
|
||||
#ifndef PRIs32
|
||||
#define PRIs32 "d"
|
||||
#endif
|
||||
#ifndef PRIu32
|
||||
#define PRIu32 "u"
|
||||
#endif
|
||||
#ifndef PRIs64
|
||||
#ifdef __WIN32__
|
||||
#define PRIs64 "I64"
|
||||
#else
|
||||
#define PRIs64 "lld"
|
||||
#endif
|
||||
#endif
|
||||
#ifndef PRIu64
|
||||
#ifdef __WIN32__
|
||||
#define PRIu64 "I64u"
|
||||
#else
|
||||
#define PRIu64 "llu"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define WIDTH 640
|
||||
#define HEIGHT 480
|
||||
#define BPP 4
|
||||
#define DEPTH 32
|
||||
|
||||
/* MUST BE A POWER OF 2! */
|
||||
#define EVENT_BUF_SIZE 256
|
||||
|
||||
|
||||
#define VERBOSE 0
|
||||
|
||||
static SDL_Window *window;
|
||||
static SDL_Event events[EVENT_BUF_SIZE];
|
||||
static int eventWrite;
|
||||
|
||||
|
||||
static int colors[7] = {0xFF,0xFF00,0xFF0000,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF};
|
||||
|
||||
typedef struct {
|
||||
float x,y;
|
||||
} Point;
|
||||
|
||||
typedef struct {
|
||||
float ang,r;
|
||||
Point p;
|
||||
} Knob;
|
||||
|
||||
static Knob knob;
|
||||
|
||||
void handler (int sig)
|
||||
{
|
||||
SDL_Log ("exiting...(%d)", sig);
|
||||
exit (0);
|
||||
}
|
||||
|
||||
void perror_exit (char *error)
|
||||
{
|
||||
perror (error);
|
||||
handler (9);
|
||||
}
|
||||
|
||||
void setpix(SDL_Surface *screen, float _x, float _y, unsigned int col)
|
||||
{
|
||||
Uint32 *pixmem32;
|
||||
Uint32 colour;
|
||||
Uint8 r,g,b;
|
||||
int x = (int)_x;
|
||||
int y = (int)_y;
|
||||
float a;
|
||||
|
||||
if(x < 0 || x >= screen->w) return;
|
||||
if(y < 0 || y >= screen->h) return;
|
||||
|
||||
pixmem32 = (Uint32*) screen->pixels + y*screen->pitch/BPP + x;
|
||||
|
||||
SDL_memcpy(&colour,pixmem32,screen->format->BytesPerPixel);
|
||||
|
||||
SDL_GetRGB(colour,screen->format,&r,&g,&b);
|
||||
/* r = 0;g = 0; b = 0; */
|
||||
a = (float)((col>>24)&0xFF);
|
||||
if(a == 0) a = 0xFF; /* Hack, to make things easier. */
|
||||
a /= 0xFF;
|
||||
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;
|
||||
}
|
||||
|
||||
void drawLine(SDL_Surface *screen,float x0,float y0,float x1,float y1,unsigned int col) {
|
||||
float t;
|
||||
for(t=0;t<1;t+=(float)(1.f/SDL_max(SDL_fabs(x0-x1),SDL_fabs(y0-y1))))
|
||||
setpix(screen,x1+t*(x0-x1),y1+t*(y0-y1),col);
|
||||
}
|
||||
|
||||
void drawCircle(SDL_Surface* screen,float x,float y,float r,unsigned int c)
|
||||
{
|
||||
float tx,ty;
|
||||
float xr;
|
||||
for(ty = (float)-SDL_fabs(r);ty <= (float)SDL_fabs((int)r);ty++) {
|
||||
xr = (float)sqrt(r*r - ty*ty);
|
||||
if(r > 0) { /* r > 0 ==> filled circle */
|
||||
for(tx=-xr+.5f;tx<=xr-.5;tx++) {
|
||||
setpix(screen,x+tx,y+ty,c);
|
||||
}
|
||||
}
|
||||
else {
|
||||
setpix(screen,x-xr+.5f,y+ty,c);
|
||||
setpix(screen,x+xr-.5f,y+ty,c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void drawKnob(SDL_Surface* screen,Knob k) {
|
||||
drawCircle(screen,k.p.x*screen->w,k.p.y*screen->h,k.r*screen->w,0xFFFFFF);
|
||||
drawCircle(screen,(k.p.x+k.r/2*SDL_cosf(k.ang))*screen->w,
|
||||
(k.p.y+k.r/2*SDL_sinf(k.ang))*screen->h,k.r/4*screen->w,0);
|
||||
}
|
||||
|
||||
void DrawScreen(SDL_Surface* screen)
|
||||
{
|
||||
int i;
|
||||
#if 1
|
||||
SDL_FillRect(screen, NULL, 0);
|
||||
#else
|
||||
int x, y;
|
||||
for(y = 0;y < screen->h;y++)
|
||||
for(x = 0;x < screen->w;x++)
|
||||
setpix(screen,(float)x,(float)y,((x%255)<<16) + ((y%255)<<8) + (x+y)%255);
|
||||
#endif
|
||||
|
||||
/* draw Touch History */
|
||||
for(i = eventWrite; i < eventWrite+EVENT_BUF_SIZE; ++i) {
|
||||
const SDL_Event *event = &events[i&(EVENT_BUF_SIZE-1)];
|
||||
float age = (float)(i - eventWrite) / EVENT_BUF_SIZE;
|
||||
float x, y;
|
||||
unsigned int c, col;
|
||||
|
||||
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*(.1+.85))) | (unsigned int)(0xFF*age)<<24;
|
||||
|
||||
if(event->type == SDL_FINGERMOTION)
|
||||
drawCircle(screen,x*screen->w,y*screen->h,5,col);
|
||||
else if(event->type == SDL_FINGERDOWN)
|
||||
drawCircle(screen,x*screen->w,y*screen->h,-10,col);
|
||||
}
|
||||
}
|
||||
|
||||
if(knob.p.x > 0)
|
||||
drawKnob(screen,knob);
|
||||
|
||||
SDL_UpdateWindowSurface(window);
|
||||
}
|
||||
|
||||
SDL_Surface* initScreen(int width,int height)
|
||||
{
|
||||
if (!window) {
|
||||
window = SDL_CreateWindow("Gesture Test",
|
||||
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||
width, height, SDL_WINDOW_RESIZABLE);
|
||||
}
|
||||
if (!window) {
|
||||
return NULL;
|
||||
}
|
||||
return SDL_GetWindowSurface(window);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
SDL_Surface *screen;
|
||||
SDL_Event event;
|
||||
SDL_bool quitting = SDL_FALSE;
|
||||
SDL_RWops *stream;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* gesture variables */
|
||||
knob.r = .1f;
|
||||
knob.ang = 0;
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
|
||||
|
||||
if (!(screen = initScreen(WIDTH,HEIGHT)))
|
||||
{
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
while(!quitting) {
|
||||
while(SDL_PollEvent(&event))
|
||||
{
|
||||
/* Record _all_ events */
|
||||
events[eventWrite & (EVENT_BUF_SIZE-1)] = event;
|
||||
eventWrite++;
|
||||
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_QUIT:
|
||||
quitting = SDL_TRUE;
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
switch (event.key.keysym.sym)
|
||||
{
|
||||
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 SDLK_ESCAPE:
|
||||
quitting = SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDL_WINDOWEVENT:
|
||||
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
|
||||
if (!(screen = initScreen(event.window.data1, event.window.data2)))
|
||||
{
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_FINGERMOTION:
|
||||
#if VERBOSE
|
||||
SDL_Log("Finger: %i,x: %i, y: %i",event.tfinger.fingerId,
|
||||
event.tfinger.x,event.tfinger.y);
|
||||
#endif
|
||||
break;
|
||||
case SDL_FINGERDOWN:
|
||||
#if VERBOSE
|
||||
SDL_Log("Finger: %"PRIs64" down - x: %i, y: %i",
|
||||
event.tfinger.fingerId,event.tfinger.x,event.tfinger.y);
|
||||
#endif
|
||||
break;
|
||||
case SDL_FINGERUP:
|
||||
#if VERBOSE
|
||||
SDL_Log("Finger: %"PRIs64" up - x: %i, y: %i",
|
||||
event.tfinger.fingerId,event.tfinger.x,event.tfinger.y);
|
||||
#endif
|
||||
break;
|
||||
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);
|
||||
#endif
|
||||
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 %"PRIs64" performed, error: %f",
|
||||
event.dgesture.gestureId,
|
||||
event.dgesture.error);
|
||||
break;
|
||||
case SDL_DOLLARRECORD:
|
||||
SDL_Log("Recorded gesture: %"PRIs64"",event.dgesture.gestureId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
DrawScreen(screen);
|
||||
}
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
416
test/testgl2.c
Normal file
@@ -0,0 +1,416 @@
|
||||
/*
|
||||
Copyright (C) 1997-2014 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 <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "SDL_test_common.h"
|
||||
|
||||
#ifdef __MACOS__
|
||||
#define HAVE_OPENGL
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENGL
|
||||
|
||||
#include "SDL_opengl.h"
|
||||
|
||||
typedef struct GL_Context
|
||||
{
|
||||
#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
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
static SDL_GLContext context;
|
||||
static GL_Context ctx;
|
||||
|
||||
static int LoadContext(GL_Context * data)
|
||||
{
|
||||
#if SDL_VIDEO_DRIVER_UIKIT
|
||||
#define __SDL_NOGETPROCADDR__
|
||||
#elif SDL_VIDEO_DRIVER_ANDROID
|
||||
#define __SDL_NOGETPROCADDR__
|
||||
#elif SDL_VIDEO_DRIVER_PANDORA
|
||||
#define __SDL_NOGETPROCADDR__
|
||||
#endif
|
||||
|
||||
#if defined __SDL_NOGETPROCADDR__
|
||||
#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 ) { \
|
||||
return SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \
|
||||
} \
|
||||
} while ( 0 );
|
||||
#endif /* _SDL_NOGETPROCADDR_ */
|
||||
|
||||
#include "../src/render/opengl/SDL_glfuncs.h"
|
||||
#undef SDL_PROC
|
||||
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_DeleteContext(context);
|
||||
}
|
||||
SDLTest_CommonQuit(state);
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
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}
|
||||
};
|
||||
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}
|
||||
};
|
||||
|
||||
/* Do our drawing, too. */
|
||||
ctx.glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||
ctx.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
ctx.glBegin(GL_QUADS);
|
||||
|
||||
#ifdef SHADED_CUBE
|
||||
ctx.glColor3fv(color[0]);
|
||||
ctx.glVertex3fv(cube[0]);
|
||||
ctx.glColor3fv(color[1]);
|
||||
ctx.glVertex3fv(cube[1]);
|
||||
ctx.glColor3fv(color[2]);
|
||||
ctx.glVertex3fv(cube[2]);
|
||||
ctx.glColor3fv(color[3]);
|
||||
ctx.glVertex3fv(cube[3]);
|
||||
|
||||
ctx.glColor3fv(color[3]);
|
||||
ctx.glVertex3fv(cube[3]);
|
||||
ctx.glColor3fv(color[4]);
|
||||
ctx.glVertex3fv(cube[4]);
|
||||
ctx.glColor3fv(color[7]);
|
||||
ctx.glVertex3fv(cube[7]);
|
||||
ctx.glColor3fv(color[2]);
|
||||
ctx.glVertex3fv(cube[2]);
|
||||
|
||||
ctx.glColor3fv(color[0]);
|
||||
ctx.glVertex3fv(cube[0]);
|
||||
ctx.glColor3fv(color[5]);
|
||||
ctx.glVertex3fv(cube[5]);
|
||||
ctx.glColor3fv(color[6]);
|
||||
ctx.glVertex3fv(cube[6]);
|
||||
ctx.glColor3fv(color[1]);
|
||||
ctx.glVertex3fv(cube[1]);
|
||||
|
||||
ctx.glColor3fv(color[5]);
|
||||
ctx.glVertex3fv(cube[5]);
|
||||
ctx.glColor3fv(color[4]);
|
||||
ctx.glVertex3fv(cube[4]);
|
||||
ctx.glColor3fv(color[7]);
|
||||
ctx.glVertex3fv(cube[7]);
|
||||
ctx.glColor3fv(color[6]);
|
||||
ctx.glVertex3fv(cube[6]);
|
||||
|
||||
ctx.glColor3fv(color[5]);
|
||||
ctx.glVertex3fv(cube[5]);
|
||||
ctx.glColor3fv(color[0]);
|
||||
ctx.glVertex3fv(cube[0]);
|
||||
ctx.glColor3fv(color[3]);
|
||||
ctx.glVertex3fv(cube[3]);
|
||||
ctx.glColor3fv(color[4]);
|
||||
ctx.glVertex3fv(cube[4]);
|
||||
|
||||
ctx.glColor3fv(color[6]);
|
||||
ctx.glVertex3fv(cube[6]);
|
||||
ctx.glColor3fv(color[1]);
|
||||
ctx.glVertex3fv(cube[1]);
|
||||
ctx.glColor3fv(color[2]);
|
||||
ctx.glVertex3fv(cube[2]);
|
||||
ctx.glColor3fv(color[7]);
|
||||
ctx.glVertex3fv(cube[7]);
|
||||
#else /* flat cube */
|
||||
ctx.glColor3f(1.0, 0.0, 0.0);
|
||||
ctx.glVertex3fv(cube[0]);
|
||||
ctx.glVertex3fv(cube[1]);
|
||||
ctx.glVertex3fv(cube[2]);
|
||||
ctx.glVertex3fv(cube[3]);
|
||||
|
||||
ctx.glColor3f(0.0, 1.0, 0.0);
|
||||
ctx.glVertex3fv(cube[3]);
|
||||
ctx.glVertex3fv(cube[4]);
|
||||
ctx.glVertex3fv(cube[7]);
|
||||
ctx.glVertex3fv(cube[2]);
|
||||
|
||||
ctx.glColor3f(0.0, 0.0, 1.0);
|
||||
ctx.glVertex3fv(cube[0]);
|
||||
ctx.glVertex3fv(cube[5]);
|
||||
ctx.glVertex3fv(cube[6]);
|
||||
ctx.glVertex3fv(cube[1]);
|
||||
|
||||
ctx.glColor3f(0.0, 1.0, 1.0);
|
||||
ctx.glVertex3fv(cube[5]);
|
||||
ctx.glVertex3fv(cube[4]);
|
||||
ctx.glVertex3fv(cube[7]);
|
||||
ctx.glVertex3fv(cube[6]);
|
||||
|
||||
ctx.glColor3f(1.0, 1.0, 0.0);
|
||||
ctx.glVertex3fv(cube[5]);
|
||||
ctx.glVertex3fv(cube[0]);
|
||||
ctx.glVertex3fv(cube[3]);
|
||||
ctx.glVertex3fv(cube[4]);
|
||||
|
||||
ctx.glColor3f(1.0, 0.0, 1.0);
|
||||
ctx.glVertex3fv(cube[6]);
|
||||
ctx.glVertex3fv(cube[1]);
|
||||
ctx.glVertex3fv(cube[2]);
|
||||
ctx.glVertex3fv(cube[7]);
|
||||
#endif /* SHADED_CUBE */
|
||||
|
||||
ctx.glEnd();
|
||||
|
||||
ctx.glMatrixMode(GL_MODELVIEW);
|
||||
ctx.glRotatef(5.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int fsaa, accel;
|
||||
int value;
|
||||
int i, done;
|
||||
SDL_DisplayMode mode;
|
||||
SDL_Event event;
|
||||
Uint32 then, now, frames;
|
||||
int status;
|
||||
int dw, dh;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Initialize parameters */
|
||||
fsaa = 0;
|
||||
accel = -1;
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
int consumed;
|
||||
|
||||
consumed = SDLTest_CommonArg(state, i);
|
||||
if (consumed == 0) {
|
||||
if (SDL_strcasecmp(argv[i], "--fsaa") == 0 && i+1 < argc) {
|
||||
fsaa = atoi(argv[i+1]);
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i], "--accel") == 0 && i+1 < argc) {
|
||||
accel = atoi(argv[i+1]);
|
||||
consumed = 2;
|
||||
} else {
|
||||
consumed = -1;
|
||||
}
|
||||
}
|
||||
if (consumed < 0) {
|
||||
SDL_Log("Usage: %s %s [--fsaa n] [--accel n]\n", argv[0],
|
||||
SDLTest_CommonUsage(state));
|
||||
quit(1);
|
||||
}
|
||||
i += consumed;
|
||||
}
|
||||
|
||||
/* Set OpenGL parameters */
|
||||
state->window_flags |= SDL_WINDOW_OPENGL;
|
||||
state->gl_red_size = 5;
|
||||
state->gl_green_size = 5;
|
||||
state->gl_blue_size = 5;
|
||||
state->gl_depth_size = 16;
|
||||
state->gl_double_buffer = 1;
|
||||
if (fsaa) {
|
||||
state->gl_multisamplebuffers = 1;
|
||||
state->gl_multisamplesamples = fsaa;
|
||||
}
|
||||
if (accel >= 0) {
|
||||
state->gl_accelerated = accel;
|
||||
}
|
||||
|
||||
if (!SDLTest_CommonInit(state)) {
|
||||
quit(2);
|
||||
}
|
||||
|
||||
/* Create OpenGL context */
|
||||
context = SDL_GL_CreateContext(state->windows[0]);
|
||||
if (!context) {
|
||||
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");
|
||||
quit(2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
|
||||
/* try late-swap-tearing first. If not supported, try normal vsync. */
|
||||
if (SDL_GL_SetSwapInterval(-1) == -1) {
|
||||
SDL_GL_SetSwapInterval(1);
|
||||
}
|
||||
} else {
|
||||
SDL_GL_SetSwapInterval(0); /* disable vsync. */
|
||||
}
|
||||
|
||||
SDL_GetCurrentDisplayMode(0, &mode);
|
||||
SDL_Log("Screen BPP : %d\n", SDL_BITSPERPIXEL(mode.format));
|
||||
SDL_Log("Swap Interval : %d\n", SDL_GL_GetSwapInterval());
|
||||
SDL_GetWindowSize(state->windows[0], &dw, &dh);
|
||||
SDL_Log("Window Size : %d,%d\n", dw, dh);
|
||||
SDL_GL_GetDrawableSize(state->windows[0], &dw, &dh);
|
||||
SDL_Log("Draw Size : %d,%d\n", dw, dh);
|
||||
SDL_Log("\n");
|
||||
SDL_Log("Vendor : %s\n", ctx.glGetString(GL_VENDOR));
|
||||
SDL_Log("Renderer : %s\n", ctx.glGetString(GL_RENDERER));
|
||||
SDL_Log("Version : %s\n", ctx.glGetString(GL_VERSION));
|
||||
SDL_Log("Extensions : %s\n", ctx.glGetString(GL_EXTENSIONS));
|
||||
SDL_Log("\n");
|
||||
|
||||
status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
|
||||
if (!status) {
|
||||
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());
|
||||
}
|
||||
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());
|
||||
}
|
||||
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());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError());
|
||||
}
|
||||
if (fsaa) {
|
||||
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
|
||||
if (!status) {
|
||||
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());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
|
||||
value);
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
|
||||
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);
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
/* Set rendering settings */
|
||||
ctx.glMatrixMode(GL_PROJECTION);
|
||||
ctx.glLoadIdentity();
|
||||
ctx.glOrtho(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
|
||||
ctx.glMatrixMode(GL_MODELVIEW);
|
||||
ctx.glLoadIdentity();
|
||||
ctx.glEnable(GL_DEPTH_TEST);
|
||||
ctx.glDepthFunc(GL_LESS);
|
||||
ctx.glShadeModel(GL_SMOOTH);
|
||||
|
||||
/* Main render loop */
|
||||
frames = 0;
|
||||
then = SDL_GetTicks();
|
||||
done = 0;
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
++frames;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
int w, h;
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
SDL_GL_MakeCurrent(state->windows[i], context);
|
||||
SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
|
||||
ctx.glViewport(0, 0, w, h);
|
||||
Render();
|
||||
SDL_GL_SwapWindow(state->windows[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Print out some timing information */
|
||||
now = SDL_GetTicks();
|
||||
if (now > then) {
|
||||
SDL_Log("%2.2f frames per second\n",
|
||||
((double) frames * 1000) / (now - then));
|
||||
}
|
||||
quit(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else /* HAVE_OPENGL */
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No OpenGL support on this system\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif /* HAVE_OPENGL */
|