Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 21-installer-nodd
  • 2210-pre1
  • 2210-pre2
  • 2210-rc1
  • 2210-rc2
  • 2210-rc3
  • 2211-pre1
  • 2211-pre2
  • 2211-rc1
  • 2212-pre1
  • 2212-pre2
  • 2212-pre3
  • 2212-rc1
  • 2213
  • 2214-pre1
  • 2214-pre2
  • 2214-pre3
  • 2214-pre4
  • 2_2_12
  • 64-gl-log
  • COM_ImmedExecute-lua
  • DJGPP
  • accel-momentum
  • acs
  • action-args
  • alpha-fixes
  • any-resolution
  • appveyor
  • blend-locking
  • blentran
  • blua-unary-not-fix
  • boost-tickrate
  • bustablesoundz
  • cleanup-opengl
  • cleanupmusic
  • clipmidtex
  • cmake-valgrind
  • crawlacommander-sprites
  • custom-map-names
  • custom-teams
  • cutscene-cleanup
  • dd-music-bypass
  • dd-music-fix
  • delfile2
  • deprecate-lua-dedicated-server
  • dpl-2
  • dropshadows-spawning
  • dynabsp
  • emblem-drawing
  • exchndl-xp-fix
  • extra-textures
  • few-kart-lua-changes
  • ffloorclip
  • fix-167
  • fix-cvar-conflicts
  • fix-opengl-parameter-crash
  • fix-opengl-shear-roll
  • flipfuncpointers
  • fof-lightlist-fixes
  • font-FUCK
  • frictionrefactor
  • fuck-macros-1
  • gamepad-luakeydown
  • gamepad-morefixes
  • gamepad_experiments
  • gametype-refactor
  • gametype-refactor-1
  • gametype-refactor-player-spawns
  • ghost-networking
  • gif-splitting
  • grr-lj
  • hitboxviewer
  • hwr-texture-cache-refactor
  • hwrender2
  • improve-439
  • increase-maxconditionsets
  • increase-packet-tics
  • input-display
  • input-display-translucency
  • io
  • joystick-juggling-maz
  • just-in-case
  • keycodes-only
  • ksf-wadfiles
  • ld413-mp-fix
  • levelstruct
  • libpng-version-support
  • linedef-actions
  • lj-test
  • lol-states
  • loopedsounds
  • lower-unpegged-fix
  • lua-change-gametype
  • lua-command-netids
  • lua-gfx-2
  • lua-gfx-sprites
  • lua-local
  • makefile-auto-mingw-gcc
  • makefile-tinkering
  • map-components-signedness-fixes
  • SRB2_release_2.1
  • SRB2_release_2.1.1
  • SRB2_release_2.1.10
  • SRB2_release_2.1.11
  • SRB2_release_2.1.12
  • SRB2_release_2.1.14
  • SRB2_release_2.1.15
  • SRB2_release_2.1.16
  • SRB2_release_2.1.16a
  • SRB2_release_2.1.17
  • SRB2_release_2.1.18
  • SRB2_release_2.1.19
  • SRB2_release_2.1.2
  • SRB2_release_2.1.20
  • SRB2_release_2.1.21
  • SRB2_release_2.1.22
  • SRB2_release_2.1.23
  • SRB2_release_2.1.24
  • SRB2_release_2.1.25
  • SRB2_release_2.1.3
  • SRB2_release_2.1.4
  • SRB2_release_2.1.5
  • SRB2_release_2.1.6
  • SRB2_release_2.1.7
  • SRB2_release_2.1.8
  • SRB2_release_2.1.9
  • SRB2_release_2.2.0
  • SRB2_release_2.2.1
  • SRB2_release_2.2.10
  • SRB2_release_2.2.11
  • SRB2_release_2.2.12
  • SRB2_release_2.2.13
  • SRB2_release_2.2.15
  • SRB2_release_2.2.2
  • SRB2_release_2.2.3
  • SRB2_release_2.2.4
  • SRB2_release_2.2.5
  • SRB2_release_2.2.6
  • SRB2_release_2.2.7
  • SRB2_release_2.2.8
  • SRB2_release_2.2.9
  • td-release-v1.0.0
142 results

Target

Select target project
  • STJr/SRB2
  • Sryder/SRB2
  • wolfy852/SRB2
  • Alpha2244/SRB2
  • Inuyasha/SRB2
  • yoshibot/SRB2
  • TehRealSalt/SRB2
  • PrisimaTF/SRB2
  • Hatninja/SRB2
  • SteelT/SRB2
  • james/SRB2
  • ShaderWraith/SRB2
  • SinnamonLat/SRB2
  • mazmazz_/SRB2
  • filpAM/SRB2
  • chaoloveicemdboy/SRB2
  • Whooa21/SRB2
  • Machturne/SRB2
  • Golden/SRB2
  • Tatsuru/SRB2
  • Snu/SRB2
  • Zwip-Zwap_Zapony/SRB2
  • fickleheart/SRB2
  • alphaRexJames/SRB2
  • JJK/SRB2
  • diskpoppy/SRB2
  • Hannu_Hanhi/SRB2
  • ZipperQR/SRB2
  • kays/SRB2
  • spherallic/SRB2
  • Zippy_Zolton/SRB2
  • namiishere/SRB2
  • Ors/SRB2
  • SMS_Alfredo/SRB2
  • sonic_edge/SRB2
  • lavla/SRB2
  • ashi/SRB2
  • X.organic/SRB2
  • Fafabis/SRB2
  • Meziu/SRB2
  • v-rob/SRB2
  • tertu/SRB2
  • bitten2up/SRB2
  • flarn2006/SRB2
  • Krabs/SRB2
  • clairebun/SRB2
  • Lactozilla/SRB2
  • thehackstack/SRB2
  • Spice/SRB2
  • win8linux/SRB2
  • JohnFrostFox/SRB2
  • talktoneon726/SRB2
  • Wane/SRB2
  • Lamibe/SRB2
  • spectrumuk2/srb-2
  • nerdyminer18/srb-2
  • 256nil/SRB2
  • ARJr/SRB2
  • Alam/SRB2
  • Zenya/srb-2-marathon-demos
  • Acelite/srb-2-archivedmodifications
  • MIDIMan/SRB2
  • Lach/SRB2
  • Frostiikin/bounce-tweaks
  • Jaden/SRB2
  • Tyron/SRB2
  • Astronight/SRB2
  • Mari0shi06/SRB2
  • aiire/SRB2
  • Galactice/SRB2
  • srb2-ports/srb2-dreamcast
  • sdasdas/SRB2
  • chreas/srb-2-vr
  • StarManiaKG/the-story-of-sinically-rocketing-and-botching-the-2nd
  • LoganAir/SRB2
  • NepDisk/srb-2
  • alufolie91/SRB2
  • Felicia.iso/SRB2
  • twi/SRB2
  • BarrelsOFun/SRB2
  • Speed2411/SRB2
  • Leather_Realms/SRB2
  • Ayemar/SRB2
  • Acelite/SRB2
  • VladDoc/SRB2
  • kaldrum/model-features
  • strawberryfox417/SRB2
  • Lugent/SRB2
  • Rem/SRB2
  • Refrag/SRB2
  • Henry_3230/srb-3230
  • TehPuertoRicanSpartan2/tprs-srb2
  • Leminn/srb-2-marathon-stuff
  • chromaticpipe2/SRB2
  • MiguelGustavo15/SRB2
  • Maru/srb-2-tests
  • SilicDev/SRB2
  • UnmatchedBracket/SRB2
  • HybridDog/SRB2
  • xordspar0/SRB2
  • jsjhbewfhh/SRB2
  • Fancy2209/SRB2
  • Lorsoen/SRB2
  • shindoukin/SRB2
  • GamerOfDays/SRB2
  • Craftyawesome/SRB2
  • tenshi-tensai-tennoji/SRB2
  • Scarfdudebalder/SRB2
  • luigi-budd/srb-2-fix-interplag-lockon
  • mskluesner/SRB2
  • johnpetersa19/SRB2
  • Pheazant/SRB2
  • chromaticpipe2/srb2classic
  • romoney5/SRB2
  • PAS/SRB2Classic
  • BlueStaggo/SRB2
  • Jisk/srb-2-beef-jerky
117 results
Select Git revision
  • 21-installer-nodd
  • 2212-pre3-appimage
  • 304-the-amount-of-mashing-to-kill-a-pterabyte-should-be-reduced
  • 3ds
  • 3ds-next
  • 3ds-real
  • 3ds-real-wtf-man
  • 64-gl-log
  • COM_ImmedExecute-lua
  • DJGPP
  • S_SKIN-missing-flag
  • addon_loading
  • addplayer
  • alien-breed-3d
  • android-model-bug-bitten-2213
  • appimage-arm
  • appveyor
  • arm-appimage-next
  • better-download
  • better-refusal
  • blend-locking
  • blendmode-rangecheck
  • blentran
  • blua-unary-not-fix
  • boost-tickrate
  • catchup-timeout
  • cleanup-opengl
  • continue_tweaks
  • crawlacommander-sprites
  • custom-save
  • custom_save
  • cutscene-cleanup
  • dashmode-lowroad
  • dd-music-bypass
  • dd-music-fix
  • delete-connection-screen-and-midgame-joins
  • delete-lua
  • delete-slopes
  • deprecate-lua-dedicated-server
  • dofile
  • doom-test
  • dpl-2
  • dropshadows-spawning
  • dummy-renderer
  • easings
  • exchndl-xp-fix
  • few-kart-lua-changes
  • ffloorclip
  • filtering
  • final-hours
  • final-tweaks
  • fix-1288
  • fix-allowjoin
  • fix-autoexec-netvars
  • fix-cvar-conflicts
  • fix-ded-servers
  • fix-fire-shield
  • fix-input-buffer
  • fix-intermission-mouse
  • fix-joiner-consoleplayer
  • fix-keepbody-ping
  • fix-packet-name
  • fix-playercmd
  • fix-polyobject-rotation-crash
  • fix-rollout-rock-crash
  • fix-spawn-desynch
  • fix-splitscreen
  • fix-stacktrace
  • fix-ticcmd-received
  • fix-timeout
  • fixargstr
  • fixmul
  • flipfuncpointers
  • flipfuncpointers-master
  • fof-lightlist-fixes
  • font-FUCK
  • frictionrefactor
  • fuck-macros-1
  • funmenus
  • funmenus-next
  • gamepad_experiments
  • gif-splitting
  • gl-texfmt-p8-ap88-a8-ai8-fix
  • grr-lj
  • high-resolution-timer-2
  • hooklib-refactor
  • hwr-texture-cache-refactor
  • idk-if-this-will-fix-linux-opengl
  • increase-input-buffer
  • increase-input-buffer-more
  • increase-packet-tics
  • input-display
  • input-display-translucency
  • io
  • join-delay
  • joystick-juggling-maz
  • keep-body
  • keycodes-only
  • ksf-wadfiles
  • ld413-mp-fix
  • SRB2_release_2.1
  • SRB2_release_2.1.1
  • SRB2_release_2.1.10
  • SRB2_release_2.1.11
  • SRB2_release_2.1.12
  • SRB2_release_2.1.14
  • SRB2_release_2.1.15
  • SRB2_release_2.1.16
  • SRB2_release_2.1.16a
  • SRB2_release_2.1.17
  • SRB2_release_2.1.18
  • SRB2_release_2.1.19
  • SRB2_release_2.1.2
  • SRB2_release_2.1.20
  • SRB2_release_2.1.21
  • SRB2_release_2.1.22
  • SRB2_release_2.1.23
  • SRB2_release_2.1.24
  • SRB2_release_2.1.25
  • SRB2_release_2.1.3
  • SRB2_release_2.1.4
  • SRB2_release_2.1.5
  • SRB2_release_2.1.6
  • SRB2_release_2.1.7
  • SRB2_release_2.1.8
  • SRB2_release_2.1.9
  • SRB2_release_2.2.0
  • SRB2_release_2.2.1
  • SRB2_release_2.2.2
  • SRB2_release_2.2.3
  • SRB2_release_2.2.4
  • SRB2_release_2.2.5
  • SRB2_release_2.2.6
  • SRB2_release_2.2.7
  • SRB2_release_2.2.8
  • SRB2_release_2.2.9
  • td-release-v1.0.0
137 results
Show changes
Showing
with 8273 additions and 3975 deletions
/*
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
......@@ -86,8 +86,7 @@ loop()
}
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
/* (argv[1] == NULL means "open default device.") */
const char *devname = argv[1];
......@@ -101,7 +100,7 @@ main(int argc, char **argv)
/* Load the SDL library */
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1);
return 1;
}
window = SDL_CreateWindow("testaudiocapture", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 320, 240, 0);
......@@ -157,7 +156,10 @@ main(int argc, char **argv)
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(loop, 0, 1);
#else
while (1) { loop(); SDL_Delay(16); }
while (1) {
loop();
SDL_Delay(16);
}
#endif
return 0;
......
/*
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
......@@ -26,6 +26,7 @@
#endif
#include "SDL.h"
#include "testutils.h"
static SDL_AudioSpec spec;
static Uint8 *sound = NULL; /* Pointer to wave data */
......@@ -68,8 +69,7 @@ fillerup(void *_pos, Uint8 * stream, int len)
}
static int done = 0;
void
poked(int sig)
void poked(int sig)
{
done = 1;
}
......@@ -89,15 +89,16 @@ iteration()
if (e.type == SDL_QUIT) {
done = 1;
} else if (e.type == SDL_KEYUP) {
if (e.key.keysym.sym == SDLK_ESCAPE)
if (e.key.keysym.sym == SDLK_ESCAPE) {
done = 1;
}
} else if (e.type == SDL_AUDIODEVICEADDED) {
int index = e.adevice.which;
int iscapture = e.adevice.iscapture;
const char *name = SDL_GetAudioDeviceName(index, iscapture);
if (name != NULL)
if (name != NULL) {
SDL_Log("New %s audio device at index %u: %s\n", devtypestr(iscapture), (unsigned int)index, name);
else {
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Got new %s device at index %u, but failed to get the name: %s\n",
devtypestr(iscapture), (unsigned int)index, SDL_GetError());
continue;
......@@ -123,8 +124,7 @@ iteration()
}
#ifdef __EMSCRIPTEN__
void
loop()
void loop()
{
if (done)
emscripten_cancel_main_loop();
......@@ -133,11 +133,10 @@ loop()
}
#endif
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int i;
char filename[4096];
char *filename = NULL;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
......@@ -145,17 +144,19 @@ main(int argc, char *argv[])
/* Load the SDL library */
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1);
return 1;
}
/* Some targets (Mac CoreAudio) need an event queue for audio hotplug, so make and immediately hide a window. */
SDL_MinimizeWindow(SDL_CreateWindow("testaudiohotplug", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0));
if (argc > 1) {
SDL_strlcpy(filename, argv[1], sizeof(filename));
} else {
SDL_strlcpy(filename, "sample.wav", sizeof(filename));
filename = GetResourceFilename(argc > 1 ? argv[1] : NULL, "sample.wav");
if (filename == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError());
quit(1);
}
/* Load the wave file into memory */
if (SDL_LoadWAV(filename, &spec, &sound, &soundlen) == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError());
......@@ -165,13 +166,13 @@ main(int argc, char *argv[])
#if HAVE_SIGNAL_H
/* Set the signals */
#ifdef SIGHUP
signal(SIGHUP, poked);
(void)signal(SIGHUP, poked);
#endif
signal(SIGINT, poked);
(void)signal(SIGINT, poked);
#ifdef SIGQUIT
signal(SIGQUIT, poked);
(void)signal(SIGQUIT, poked);
#endif
signal(SIGTERM, poked);
(void)signal(SIGTERM, poked);
#endif /* HAVE_SIGNAL_H */
/* Show the list of available drivers */
......@@ -196,8 +197,9 @@ main(int argc, char *argv[])
/* Quit audio first, then free WAV. This prevents access violations in the audio threads. */
SDL_QuitSubSystem(SDL_INIT_AUDIO);
SDL_FreeWAV(sound);
SDL_free(filename);
SDL_Quit();
return (0);
return 0;
}
/* vi: set ts=4 sw=4 expandtab: */
/*
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
......@@ -15,31 +15,40 @@
static void
print_devices(int iscapture)
{
SDL_AudioSpec spec;
const char *typestr = ((iscapture) ? "capture" : "output");
int n = SDL_GetNumAudioDevices(iscapture);
SDL_Log("Found %d %s device%s:\n", n, typestr, n != 1 ? "s" : "");
if (n == -1)
if (n == -1) {
SDL_Log(" Driver can't detect specific %s devices.\n\n", typestr);
else if (n == 0)
} else if (n == 0) {
SDL_Log(" No %s devices found.\n\n", typestr);
else {
} else {
int i;
for (i = 0; i < n; i++) {
const char *name = SDL_GetAudioDeviceName(i, iscapture);
if (name != NULL)
if (name != NULL) {
SDL_Log(" %d: %s\n", i, name);
else
} else {
SDL_Log(" %d Error: %s\n", i, SDL_GetError());
}
if (SDL_GetAudioDeviceSpec(i, iscapture, &spec) == 0) {
SDL_Log(" Sample Rate: %d\n", spec.freq);
SDL_Log(" Channels: %d\n", spec.channels);
SDL_Log(" SDL_AudioFormat: %X\n", spec.format);
}
}
SDL_Log("\n");
}
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
char *deviceName = NULL;
SDL_AudioSpec spec;
int n;
/* Enable standard application logging */
......@@ -48,7 +57,7 @@ main(int argc, char **argv)
/* Load the SDL library */
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1);
return 1;
}
/* Print available audio drivers */
......@@ -69,6 +78,26 @@ main(int argc, char **argv)
print_devices(0);
print_devices(1);
if (SDL_GetDefaultAudioInfo(&deviceName, &spec, 0) < 0) {
SDL_Log("Error when calling SDL_GetDefaultAudioInfo: %s\n", SDL_GetError());
} else {
SDL_Log("Default Output Name: %s\n", deviceName != NULL ? deviceName : "unknown");
SDL_free(deviceName);
SDL_Log("Sample Rate: %d\n", spec.freq);
SDL_Log("Channels: %d\n", spec.channels);
SDL_Log("SDL_AudioFormat: %X\n", spec.format);
}
if (SDL_GetDefaultAudioInfo(&deviceName, &spec, 1) < 0) {
SDL_Log("Error when calling SDL_GetDefaultAudioInfo: %s\n", SDL_GetError());
} else {
SDL_Log("Default Capture Name: %s\n", deviceName != NULL ? deviceName : "unknown");
SDL_free(deviceName);
SDL_Log("Sample Rate: %d\n", spec.freq);
SDL_Log("Channels: %d\n", spec.channels);
SDL_Log("SDL_AudioFormat: %X\n", spec.format);
}
SDL_Quit();
return 0;
}
/*
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
......@@ -29,8 +29,7 @@ quit(int rc)
exit(rc);
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int result;
int testIterations = 1;
......@@ -42,10 +41,13 @@ main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (!state) {
if (state == NULL) {
return 1;
}
/* No need of windows (or update testautomation_mouse.c:mouse_getMouseFocus() */
state->num_windows = 0;
/* Parse commandline */
for (i = 1; i < argc;) {
int consumed;
......@@ -56,23 +58,22 @@ main(int argc, char *argv[])
if (SDL_strcasecmp(argv[i], "--iterations") == 0) {
if (argv[i + 1]) {
testIterations = SDL_atoi(argv[i + 1]);
if (testIterations < 1) testIterations = 1;
consumed = 2;
if (testIterations < 1) {
testIterations = 1;
}
consumed = 2;
}
else if (SDL_strcasecmp(argv[i], "--execKey") == 0) {
} else if (SDL_strcasecmp(argv[i], "--execKey") == 0) {
if (argv[i + 1]) {
SDL_sscanf(argv[i + 1], "%"SDL_PRIu64, &userExecKey);
(void)SDL_sscanf(argv[i + 1], "%" SDL_PRIu64, &userExecKey);
consumed = 2;
}
}
else if (SDL_strcasecmp(argv[i], "--seed") == 0) {
} else if (SDL_strcasecmp(argv[i], "--seed") == 0) {
if (argv[i + 1]) {
userRunSeed = SDL_strdup(argv[i + 1]);
consumed = 2;
}
}
else if (SDL_strcasecmp(argv[i], "--filter") == 0) {
} else if (SDL_strcasecmp(argv[i], "--filter") == 0) {
if (argv[i + 1]) {
filter = SDL_strdup(argv[i + 1]);
consumed = 2;
......@@ -101,7 +102,7 @@ main(int argc, char *argv[])
}
/* Call Harness */
result = SDLTest_RunSuites(testSuites, (const char *)userRunSeed, userExecKey, (const char *)filter, testIterations);
result = SDLTest_RunSuites(testSuites, userRunSeed, userExecKey, filter, testIterations);
/* Empty event queue */
done = 0;
......@@ -118,7 +119,7 @@ main(int argc, char *argv[])
/* Shutdown everything */
quit(result);
return(result);
return result;
}
/* vi: set ts=4 sw=4 expandtab: */
......@@ -4,8 +4,11 @@
*/
/* quiet windows compiler warnings */
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <math.h>
#include <stdio.h>
#include <string.h>
......@@ -16,8 +19,7 @@
/* Fixture */
void
_audioSetUp(void *arg)
void _audioSetUp(void *arg)
{
/* Start SDL audio subsystem */
int ret = SDL_InitSubSystem(SDL_INIT_AUDIO);
......@@ -28,23 +30,20 @@ _audioSetUp(void *arg)
}
}
void
_audioTearDown(void *arg)
void _audioTearDown(void *arg)
{
/* Remove a possibly created file from SDL disk writer audio driver; ignore errors */
remove("sdlaudio.raw");
(void)remove("sdlaudio.raw");
SDLTest_AssertPass("Cleanup of test files completed");
}
/* Global counter for callback invocation */
int _audio_testCallbackCounter;
/* Global accumulator for total callback length */
int _audio_testCallbackLength;
/* Test callback function */
void SDLCALL _audio_testCallback(void *userdata, Uint8 *stream, int len)
{
......@@ -53,7 +52,6 @@ void SDLCALL _audio_testCallback(void *userdata, Uint8 *stream, int len)
_audio_testCallbackLength += len;
}
/* Test case functions */
/**
......@@ -97,8 +95,8 @@ int audio_initQuitAudio()
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);
SDLTest_Assert(audioDriver != NULL, "Audio driver name is not NULL");
SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver); /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
/* Call Init */
result = SDL_AudioInit(audioDriver);
......@@ -154,8 +152,8 @@ int audio_initOpenCloseQuitAudio()
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);
SDLTest_Assert(audioDriver != NULL, "Audio driver name is not NULL");
SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver); /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
/* Change specs */
for (j = 0; j < 2; j++) {
......@@ -176,7 +174,7 @@ int audio_initOpenCloseQuitAudio()
desired.samples = 4096;
desired.callback = _audio_testCallback;
desired.userdata = NULL;
break;
case 1:
/* Set custom desired spec */
desired.freq = 48000;
......@@ -243,8 +241,8 @@ int audio_pauseUnpauseAudio()
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);
SDLTest_Assert(audioDriver != NULL, "Audio driver name is not NULL");
SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver); /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
/* Change specs */
for (j = 0; j < 2; j++) {
......@@ -265,7 +263,7 @@ int audio_pauseUnpauseAudio()
desired.samples = 4096;
desired.callback = _audio_testCallback;
desired.userdata = NULL;
break;
case 1:
/* Set custom desired spec */
desired.freq = 48000;
......@@ -302,8 +300,7 @@ int audio_pauseUnpauseAudio()
do {
SDL_Delay(10);
totalDelay += 10;
}
while (_audio_testCallbackCounter == 0 && totalDelay < 1000);
} while (_audio_testCallbackCounter == 0 && totalDelay < 1000);
SDLTest_AssertCheck(_audio_testCallbackCounter > 0, "Verify callback counter; expected: >0 got: %d", _audio_testCallbackCounter);
SDLTest_AssertCheck(_audio_testCallbackLength > 0, "Verify callback length; expected: >0 got: %d", _audio_testCallbackLength);
......@@ -441,7 +438,6 @@ int audio_enumerateAndNameAudioDevicesNegativeTests()
return TEST_COMPLETED;
}
/**
* \brief Checks available audio driver names.
*
......@@ -459,8 +455,7 @@ int audio_printAudioDrivers()
SDLTest_AssertCheck(n >= 0, "Verify number of audio drivers >= 0, got: %i", n);
/* List drivers. */
if (n>0)
{
if (n > 0) {
for (i = 0; i < n; i++) {
name = SDL_GetAudioDriver(i);
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%i)", i);
......@@ -474,7 +469,6 @@ int audio_printAudioDrivers()
return TEST_COMPLETED;
}
/**
* \brief Checks current audio driver name with initialized audio.
*
......@@ -506,7 +500,6 @@ Uint8 _audioChannels[] = { 1, 2, 4, 6 };
const int _numAudioFrequencies = 4;
int _audioFrequencies[] = { 11025, 22050, 44100, 48000 };
/**
* \brief Builds various audio conversion structures
*
......@@ -685,8 +678,6 @@ int audio_getAudioStatus()
return TEST_COMPLETED;
}
/**
* \brief Opens, checks current audio status, and closes a device.
*
......@@ -710,7 +701,9 @@ int audio_openCloseAndGetAudioStatus()
device = SDL_GetAudioDeviceName(i, 0);
SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
if (device == NULL) return TEST_ABORTED;
if (device == NULL) {
return TEST_ABORTED;
}
/* Set standard desired spec */
desired.freq = 22050;
......@@ -723,7 +716,7 @@ int audio_openCloseAndGetAudioStatus()
/* Open device */
id = SDL_OpenAudioDevice(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);
SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >=2, got: %" SDL_PRIu32, id);
if (id > 1) {
/* Check device audio status */
......@@ -768,7 +761,9 @@ int audio_lockUnlockOpenAudioDevice()
device = SDL_GetAudioDeviceName(i, 0);
SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
if (device == NULL) return TEST_ABORTED;
if (device == NULL) {
return TEST_ABORTED;
}
/* Set standard desired spec */
desired.freq = 22050;
......@@ -781,11 +776,11 @@ int audio_lockUnlockOpenAudioDevice()
/* Open device */
id = SDL_OpenAudioDevice(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);
SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >=2, got: %" SDL_PRIu32, id);
if (id > 1) {
/* Lock to protect callback */
SDL_LockAudioDevice(id);
SDLTest_AssertPass("SDL_LockAudioDevice(%i)", id);
SDLTest_AssertPass("SDL_LockAudioDevice(%" SDL_PRIu32 ")", id);
/* Simulate callback processing */
SDL_Delay(10);
......@@ -793,7 +788,7 @@ int audio_lockUnlockOpenAudioDevice()
/* Unlock again */
SDL_UnlockAudioDevice(id);
SDLTest_AssertPass("SDL_UnlockAudioDevice(%i)", id);
SDLTest_AssertPass("SDL_UnlockAudioDevice(%" SDL_PRIu32 ")", id);
/* Close device again */
SDL_CloseAudioDevice(id);
......@@ -807,7 +802,6 @@ int audio_lockUnlockOpenAudioDevice()
return TEST_COMPLETED;
}
/**
* \brief Convert audio using various conversion structures
*
......@@ -876,7 +870,9 @@ int audio_convertAudio()
SDLTest_LogError("%s", SDL_GetError());
} else {
SDLTest_AssertCheck(cvt.len_mult > 0, "Verify that cvt.len_mult value; expected: >0, got: %i", cvt.len_mult);
if (cvt.len_mult < 1) return TEST_ABORTED;
if (cvt.len_mult < 1) {
return TEST_ABORTED;
}
/* Create some random data to convert */
l = 64;
......@@ -885,7 +881,9 @@ int audio_convertAudio()
cvt.len = l;
cvt.buf = (Uint8 *)SDL_malloc(ll);
SDLTest_AssertCheck(cvt.buf != NULL, "Check data buffer to convert is not NULL");
if (cvt.buf == NULL) return TEST_ABORTED;
if (cvt.buf == NULL) {
return TEST_ABORTED;
}
/* Convert the data */
result = SDL_ConvertAudio(&cvt);
......@@ -906,7 +904,6 @@ int audio_convertAudio()
return TEST_COMPLETED;
}
/**
* \brief Opens, checks current connected status, and closes a device.
*
......@@ -930,7 +927,9 @@ int audio_openCloseAudioDeviceConnected()
device = SDL_GetAudioDeviceName(i, 0);
SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
if (device == NULL) return TEST_ABORTED;
if (device == NULL) {
return TEST_ABORTED;
}
/* Set standard desired spec */
desired.freq = 22050;
......@@ -943,7 +942,7 @@ int audio_openCloseAudioDeviceConnected()
/* Open device */
id = SDL_OpenAudioDevice(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);
SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >1, got: %" SDL_PRIu32, id);
if (id > 1) {
/* TODO: enable test code when function is available in SDL2 */
......@@ -967,66 +966,196 @@ int audio_openCloseAudioDeviceConnected()
return TEST_COMPLETED;
}
static double sine_wave_sample(const Sint64 idx, const Sint64 rate, const Sint64 freq, const double phase)
{
/* Using integer modulo to avoid precision loss caused by large floating
* point numbers. Sint64 is needed for the large integer multiplication.
* The integers are assumed to be non-negative so that modulo is always
* non-negative.
* sin(i / rate * freq * 2 * M_PI + phase)
* = sin(mod(i / rate * freq, 1) * 2 * M_PI + phase)
* = sin(mod(i * freq, rate) / rate * 2 * M_PI + phase) */
return SDL_sin(((double) (idx * freq % rate)) / ((double) rate) * (M_PI * 2) + phase);
}
/**
* \brief Check signal-to-noise ratio and maximum error of audio resampling.
*
* \sa https://wiki.libsdl.org/SDL_BuildAudioCVT
* \sa https://wiki.libsdl.org/SDL_ConvertAudio
*/
int audio_resampleLoss()
{
/* Note: always test long input time (>= 5s from experience) in some test
* cases because an improper implementation may suffer from low resampling
* precision with long input due to e.g. doing subtraction with large floats. */
struct test_spec_t {
int time;
int freq;
double phase;
int rate_in;
int rate_out;
double signal_to_noise;
double max_error;
} test_specs[] = {
{ 50, 440, 0, 44100, 48000, 60, 0.0025 },
{ 50, 5000, M_PI / 2, 20000, 10000, 65, 0.0010 },
{ 0 }
};
int spec_idx = 0;
for (spec_idx = 0; test_specs[spec_idx].time > 0; ++spec_idx) {
const struct test_spec_t *spec = &test_specs[spec_idx];
const int frames_in = spec->time * spec->rate_in;
const int frames_target = spec->time * spec->rate_out;
const int len_in = frames_in * (int)sizeof(float);
const int len_target = frames_target * (int)sizeof(float);
Uint64 tick_beg = 0;
Uint64 tick_end = 0;
SDL_AudioCVT cvt;
int i = 0;
int ret = 0;
double max_error = 0;
double sum_squared_error = 0;
double sum_squared_value = 0;
double signal_to_noise = 0;
SDLTest_AssertPass("Test resampling of %i s %i Hz %f phase sine wave from sampling rate of %i Hz to %i Hz",
spec->time, spec->freq, spec->phase, spec->rate_in, spec->rate_out);
ret = SDL_BuildAudioCVT(&cvt, AUDIO_F32, 1, spec->rate_in, AUDIO_F32, 1, spec->rate_out);
SDLTest_AssertPass("Call to SDL_BuildAudioCVT(&cvt, AUDIO_F32, 1, %i, AUDIO_F32, 1, %i)", spec->rate_in, spec->rate_out);
SDLTest_AssertCheck(ret == 1, "Expected SDL_BuildAudioCVT to succeed and conversion to be needed.");
if (ret != 1) {
return TEST_ABORTED;
}
cvt.buf = (Uint8 *)SDL_malloc(len_in * cvt.len_mult);
SDLTest_AssertCheck(cvt.buf != NULL, "Expected input buffer to be created.");
if (cvt.buf == NULL) {
return TEST_ABORTED;
}
cvt.len = len_in;
for (i = 0; i < frames_in; ++i) {
*(((float *) cvt.buf) + i) = (float)sine_wave_sample(i, spec->rate_in, spec->freq, spec->phase);
}
tick_beg = SDL_GetPerformanceCounter();
ret = SDL_ConvertAudio(&cvt);
tick_end = SDL_GetPerformanceCounter();
SDLTest_AssertPass("Call to SDL_ConvertAudio(&cvt)");
SDLTest_AssertCheck(ret == 0, "Expected SDL_ConvertAudio to succeed.");
SDLTest_AssertCheck(cvt.len_cvt == len_target, "Expected output length %i, got %i.", len_target, cvt.len_cvt);
if (ret != 0 || cvt.len_cvt != len_target) {
SDL_free(cvt.buf);
return TEST_ABORTED;
}
SDLTest_Log("Resampling used %f seconds.", ((double) (tick_end - tick_beg)) / SDL_GetPerformanceFrequency());
for (i = 0; i < frames_target; ++i) {
const float output = *(((float *) cvt.buf) + i);
const double target = sine_wave_sample(i, spec->rate_out, spec->freq, spec->phase);
const double error = SDL_fabs(target - output);
max_error = SDL_max(max_error, error);
sum_squared_error += error * error;
sum_squared_value += target * target;
}
SDL_free(cvt.buf);
signal_to_noise = 10 * SDL_log10(sum_squared_value / sum_squared_error); /* decibel */
SDLTest_AssertCheck(isfinite(sum_squared_value), "Sum of squared target should be finite.");
SDLTest_AssertCheck(isfinite(sum_squared_error), "Sum of squared error should be finite.");
/* Infinity is theoretically possible when there is very little to no noise */
SDLTest_AssertCheck(!isnan(signal_to_noise), "Signal-to-noise ratio should not be NaN.");
SDLTest_AssertCheck(isfinite(max_error), "Maximum conversion error should be finite.");
SDLTest_AssertCheck(signal_to_noise >= spec->signal_to_noise, "Conversion signal-to-noise ratio %f dB should be no less than %f dB.",
signal_to_noise, spec->signal_to_noise);
SDLTest_AssertCheck(max_error <= spec->max_error, "Maximum conversion error %f should be no more than %f.",
max_error, spec->max_error);
}
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 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 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 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 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 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 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 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 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 };
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 };
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 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
};
static const SDLTest_TestCaseReference audioTest12 =
{ (SDLTest_TestCaseFp)audio_quitInitAudioSubSystem, "audio_quitInitAudioSubSystem", "Quit and re-init audio subsystem.", TEST_ENABLED };
static const SDLTest_TestCaseReference audioTest13 = {
(SDLTest_TestCaseFp)audio_initQuitAudio, "audio_initQuitAudio", "Init and quit audio drivers directly.", TEST_ENABLED
};
static const SDLTest_TestCaseReference audioTest13 =
{ (SDLTest_TestCaseFp)audio_initQuitAudio, "audio_initQuitAudio", "Init and quit audio drivers directly.", TEST_ENABLED };
static const SDLTest_TestCaseReference audioTest14 = {
(SDLTest_TestCaseFp)audio_initOpenCloseQuitAudio, "audio_initOpenCloseQuitAudio", "Cycle through init, open, close and quit with various audio specs.", TEST_ENABLED
};
static const SDLTest_TestCaseReference audioTest14 =
{ (SDLTest_TestCaseFp)audio_initOpenCloseQuitAudio, "audio_initOpenCloseQuitAudio", "Cycle through init, open, close and quit with various audio specs.", TEST_ENABLED };
static const SDLTest_TestCaseReference audioTest15 = {
(SDLTest_TestCaseFp)audio_pauseUnpauseAudio, "audio_pauseUnpauseAudio", "Pause and Unpause audio for various audio specs while testing callback.", TEST_ENABLED
};
static const SDLTest_TestCaseReference audioTest15 =
{ (SDLTest_TestCaseFp)audio_pauseUnpauseAudio, "audio_pauseUnpauseAudio", "Pause and Unpause audio for various audio specs while testing callback.", TEST_ENABLED };
static const SDLTest_TestCaseReference audioTest16 = {
(SDLTest_TestCaseFp)audio_resampleLoss, "audio_resampleLoss", "Check signal-to-noise ratio and maximum error of audio resampling.", TEST_ENABLED
};
/* Sequence of Audio test cases */
static const SDLTest_TestCaseReference *audioTests[] = {
&audioTest1, &audioTest2, &audioTest3, &audioTest4, &audioTest5, &audioTest6,
&audioTest7, &audioTest8, &audioTest9, &audioTest10, &audioTest11,
&audioTest12, &audioTest13, &audioTest14, &audioTest15, NULL
&audioTest12, &audioTest13, &audioTest14, &audioTest15, &audioTest16, NULL
};
/* Audio test suite (global) */
......
......@@ -18,8 +18,7 @@
* \sa
* http://wiki.libsdl.org/SDL_HasClipboardText
*/
int
clipboard_testHasClipboardText(void *arg)
int clipboard_testHasClipboardText(void *arg)
{
SDL_HasClipboardText();
SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
......@@ -27,14 +26,27 @@ clipboard_testHasClipboardText(void *arg)
return TEST_COMPLETED;
}
/**
* \brief Check call to SDL_HasPrimarySelectionText
*
* \sa
* http://wiki.libsdl.org/SDL_HasPrimarySelectionText
*/
int clipboard_testHasPrimarySelectionText(void *arg)
{
SDL_HasPrimarySelectionText();
SDLTest_AssertPass("Call to SDL_HasPrimarySelectionText succeeded");
return TEST_COMPLETED;
}
/**
* \brief Check call to SDL_GetClipboardText
*
* \sa
* http://wiki.libsdl.org/SDL_GetClipboardText
*/
int
clipboard_testGetClipboardText(void *arg)
int clipboard_testGetClipboardText(void *arg)
{
char *charResult;
charResult = SDL_GetClipboardText();
......@@ -45,13 +57,29 @@ clipboard_testGetClipboardText(void *arg)
return TEST_COMPLETED;
}
/**
* \brief Check call to SDL_GetPrimarySelectionText
*
* \sa
* http://wiki.libsdl.org/SDL_GetPrimarySelectionText
*/
int clipboard_testGetPrimarySelectionText(void *arg)
{
char *charResult;
charResult = SDL_GetPrimarySelectionText();
SDLTest_AssertPass("Call to SDL_GetPrimarySelectionText succeeded");
SDL_free(charResult);
return TEST_COMPLETED;
}
/**
* \brief Check call to SDL_SetClipboardText
* \sa
* http://wiki.libsdl.org/SDL_SetClipboardText
*/
int
clipboard_testSetClipboardText(void *arg)
int clipboard_testSetClipboardText(void *arg)
{
char *textRef = SDLTest_RandomAsciiString();
char *text = SDL_strdup(textRef);
......@@ -74,6 +102,34 @@ clipboard_testSetClipboardText(void *arg)
return TEST_COMPLETED;
}
/**
* \brief Check call to SDL_SetPrimarySelectionText
* \sa
* http://wiki.libsdl.org/SDL_SetPrimarySelectionText
*/
int clipboard_testSetPrimarySelectionText(void *arg)
{
char *textRef = SDLTest_RandomAsciiString();
char *text = SDL_strdup(textRef);
int result;
result = SDL_SetPrimarySelectionText((const char *)text);
SDLTest_AssertPass("Call to SDL_SetPrimarySelectionText succeeded");
SDLTest_AssertCheck(
result == 0,
"Validate SDL_SetPrimarySelectionText result, expected 0, got %i",
result);
SDLTest_AssertCheck(
SDL_strcmp(textRef, text) == 0,
"Verify SDL_SetPrimarySelectionText 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
......@@ -81,8 +137,7 @@ clipboard_testSetClipboardText(void *arg)
* http://wiki.libsdl.org/SDL_GetClipboardText
* http://wiki.libsdl.org/SDL_SetClipboardText
*/
int
clipboard_testClipboardTextFunctions(void *arg)
int clipboard_testClipboardTextFunctions(void *arg)
{
char *textRef = SDLTest_RandomAsciiString();
char *text = SDL_strdup(textRef);
......@@ -114,11 +169,11 @@ clipboard_testClipboardTextFunctions(void *arg)
/* Empty clipboard */
charResult = SDL_GetClipboardText();
SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
SDLTest_AssertCheck(
SDLTest_Assert(
charResult != NULL,
"Verify SDL_GetClipboardText did not return NULL");
SDLTest_AssertCheck(
charResult[0] == '\0',
charResult[0] == '\0', /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
"Verify SDL_GetClipboardText returned string with length 0, got length %i",
(int)SDL_strlen(charResult));
intResult = SDL_SetClipboardText((const char *)text);
......@@ -153,25 +208,122 @@ clipboard_testClipboardTextFunctions(void *arg)
return TEST_COMPLETED;
}
/**
* \brief End-to-end test of SDL_xyzPrimarySelectionText functions
* \sa
* http://wiki.libsdl.org/SDL_HasPrimarySelectionText
* http://wiki.libsdl.org/SDL_GetPrimarySelectionText
* http://wiki.libsdl.org/SDL_SetPrimarySelectionText
*/
int clipboard_testPrimarySelectionTextFunctions(void *arg)
{
char *textRef = SDLTest_RandomAsciiString();
char *text = SDL_strdup(textRef);
SDL_bool boolResult;
int intResult;
char *charResult;
/* Clear primary selection text state */
boolResult = SDL_HasPrimarySelectionText();
SDLTest_AssertPass("Call to SDL_HasPrimarySelectionText succeeded");
if (boolResult == SDL_TRUE) {
intResult = SDL_SetPrimarySelectionText((const char *)NULL);
SDLTest_AssertPass("Call to SDL_SetPrimarySelectionText(NULL) succeeded");
SDLTest_AssertCheck(
intResult == 0,
"Verify result from SDL_SetPrimarySelectionText(NULL), expected 0, got %i",
intResult);
charResult = SDL_GetPrimarySelectionText();
SDLTest_AssertPass("Call to SDL_GetPrimarySelectionText succeeded");
SDL_free(charResult);
boolResult = SDL_HasPrimarySelectionText();
SDLTest_AssertPass("Call to SDL_HasPrimarySelectionText succeeded");
SDLTest_AssertCheck(
boolResult == SDL_FALSE,
"Verify SDL_HasPrimarySelectionText returned SDL_FALSE, got %s",
(boolResult) ? "SDL_TRUE" : "SDL_FALSE");
}
/* Empty primary selection */
charResult = SDL_GetPrimarySelectionText();
SDLTest_AssertPass("Call to SDL_GetPrimarySelectionText succeeded");
SDLTest_Assert(
charResult != NULL,
"Verify SDL_GetPrimarySelectionText did not return NULL");
SDLTest_AssertCheck(
charResult[0] == '\0', /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
"Verify SDL_GetPrimarySelectionText returned string with length 0, got length %i",
(int)SDL_strlen(charResult));
intResult = SDL_SetPrimarySelectionText((const char *)text);
SDLTest_AssertPass("Call to SDL_SetPrimarySelectionText succeeded");
SDLTest_AssertCheck(
intResult == 0,
"Verify result from SDL_SetPrimarySelectionText(NULL), expected 0, got %i",
intResult);
SDLTest_AssertCheck(
SDL_strcmp(textRef, text) == 0,
"Verify SDL_SetPrimarySelectionText did not modify input string, expected '%s', got '%s'",
textRef, text);
boolResult = SDL_HasPrimarySelectionText();
SDLTest_AssertPass("Call to SDL_HasPrimarySelectionText succeeded");
SDLTest_AssertCheck(
boolResult == SDL_TRUE,
"Verify SDL_HasPrimarySelectionText returned SDL_TRUE, got %s",
(boolResult) ? "SDL_TRUE" : "SDL_FALSE");
SDL_free(charResult);
charResult = SDL_GetPrimarySelectionText();
SDLTest_AssertPass("Call to SDL_GetPrimarySelectionText succeeded");
SDLTest_AssertCheck(
SDL_strcmp(textRef, charResult) == 0,
"Verify SDL_GetPrimarySelectionText 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 clipboardTest1 = {
(SDLTest_TestCaseFp)clipboard_testHasClipboardText, "clipboard_testHasClipboardText", "Check call to SDL_HasClipboardText", TEST_ENABLED
};
static const SDLTest_TestCaseReference clipboardTest2 = {
(SDLTest_TestCaseFp)clipboard_testHasPrimarySelectionText, "clipboard_testHasPrimarySelectionText", "Check call to SDL_HasPrimarySelectionText", TEST_ENABLED
};
static const SDLTest_TestCaseReference clipboardTest3 = {
(SDLTest_TestCaseFp)clipboard_testGetClipboardText, "clipboard_testGetClipboardText", "Check call to SDL_GetClipboardText", TEST_ENABLED
};
static const SDLTest_TestCaseReference clipboardTest4 = {
(SDLTest_TestCaseFp)clipboard_testGetPrimarySelectionText, "clipboard_testGetPrimarySelectionText", "Check call to SDL_GetPrimarySelectionText", TEST_ENABLED
};
static const SDLTest_TestCaseReference clipboardTest5 = {
(SDLTest_TestCaseFp)clipboard_testSetClipboardText, "clipboard_testSetClipboardText", "Check call to SDL_SetClipboardText", TEST_ENABLED
};
static const SDLTest_TestCaseReference clipboardTest2 =
{ (SDLTest_TestCaseFp)clipboard_testGetClipboardText, "clipboard_testGetClipboardText", "Check call to SDL_GetClipboardText", TEST_ENABLED };
static const SDLTest_TestCaseReference clipboardTest6 = {
(SDLTest_TestCaseFp)clipboard_testSetPrimarySelectionText, "clipboard_testSetPrimarySelectionText", "Check call to SDL_SetPrimarySelectionText", TEST_ENABLED
};
static const SDLTest_TestCaseReference clipboardTest3 =
{ (SDLTest_TestCaseFp)clipboard_testSetClipboardText, "clipboard_testSetClipboardText", "Check call to SDL_SetClipboardText", TEST_ENABLED };
static const SDLTest_TestCaseReference clipboardTest7 = {
(SDLTest_TestCaseFp)clipboard_testClipboardTextFunctions, "clipboard_testClipboardTextFunctions", "End-to-end test of SDL_xyzClipboardText functions", TEST_ENABLED
};
static const SDLTest_TestCaseReference clipboardTest4 =
{ (SDLTest_TestCaseFp)clipboard_testClipboardTextFunctions, "clipboard_testClipboardTextFunctions", "End-to-end test of SDL_xyzClipboardText functions", TEST_ENABLED };
static const SDLTest_TestCaseReference clipboardTest8 = {
(SDLTest_TestCaseFp)clipboard_testPrimarySelectionTextFunctions, "clipboard_testPrimarySelectionTextFunctions", "End-to-end test of SDL_xyzPrimarySelectionText functions", TEST_ENABLED
};
/* Sequence of Clipboard test cases */
static const SDLTest_TestCaseReference *clipboardTests[] = {
&clipboardTest1, &clipboardTest2, &clipboardTest3, &clipboardTest4, NULL
&clipboardTest1, &clipboardTest2, &clipboardTest3, &clipboardTest4, &clipboardTest5, &clipboardTest6, &clipboardTest7, &clipboardTest8, NULL
};
/* Clipboard test suite (global) */
......
......@@ -45,8 +45,7 @@ int SDLCALL _events_sampleNullEventFilter(void *userdata, SDL_Event *event)
* @sa http://wiki.libsdl.org/SDL_PumpEvents
* @sa http://wiki.libsdl.org/SDL_PollEvent
*/
int
events_pushPumpAndPollUserevent(void *arg)
int events_pushPumpAndPollUserevent(void *arg)
{
SDL_Event event1;
SDL_Event event2;
......@@ -72,7 +71,6 @@ events_pushPumpAndPollUserevent(void *arg)
return TEST_COMPLETED;
}
/**
* @brief Adds and deletes an event watch function with NULL userdata
*
......@@ -80,8 +78,7 @@ events_pushPumpAndPollUserevent(void *arg)
* @sa http://wiki.libsdl.org/SDL_DelEventWatch
*
*/
int
events_addDelEventWatch(void *arg)
int events_addDelEventWatch(void *arg)
{
SDL_Event event;
......@@ -130,8 +127,7 @@ events_addDelEventWatch(void *arg)
* @sa http://wiki.libsdl.org/SDL_DelEventWatch
*
*/
int
events_addDelEventWatchWithUserdata(void *arg)
int events_addDelEventWatchWithUserdata(void *arg)
{
SDL_Event event;
......@@ -174,18 +170,20 @@ events_addDelEventWatchWithUserdata(void *arg)
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Events test cases */
static const SDLTest_TestCaseReference eventsTest1 =
{ (SDLTest_TestCaseFp)events_pushPumpAndPollUserevent, "events_pushPumpAndPollUserevent", "Pushes, pumps and polls a user event", TEST_ENABLED };
static const SDLTest_TestCaseReference eventsTest1 = {
(SDLTest_TestCaseFp)events_pushPumpAndPollUserevent, "events_pushPumpAndPollUserevent", "Pushes, pumps and polls a user event", TEST_ENABLED
};
static const SDLTest_TestCaseReference eventsTest2 =
{ (SDLTest_TestCaseFp)events_addDelEventWatch, "events_addDelEventWatch", "Adds and deletes an event watch function with NULL userdata", TEST_ENABLED };
static const SDLTest_TestCaseReference eventsTest2 = {
(SDLTest_TestCaseFp)events_addDelEventWatch, "events_addDelEventWatch", "Adds and deletes an event watch function with NULL userdata", TEST_ENABLED
};
static const SDLTest_TestCaseReference eventsTest3 =
{ (SDLTest_TestCaseFp)events_addDelEventWatchWithUserdata, "events_addDelEventWatchWithUserdata", "Adds and deletes an event watch function with userdata", TEST_ENABLED };
static const SDLTest_TestCaseReference eventsTest3 = {
(SDLTest_TestCaseFp)events_addDelEventWatchWithUserdata, "events_addDelEventWatchWithUserdata", "Adds and deletes an event watch function with userdata", TEST_ENABLED
};
/* Sequence of Events test cases */
static const SDLTest_TestCaseReference *eventsTests[] = {
......
/**
* GUID test suite
*/
#include "SDL.h"
#include "SDL_test.h"
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
/* ================= Test Case Implementation ================== */
/* Helper functions */
#define NUM_TEST_GUIDS 5
#ifndef UINT64_C
#ifdef _MSC_VER
#define UINT64_C(x) x##ui64
#elif defined(_LP64)
#define UINT64_C(x) x##UL
#else
#define UINT64_C(x) x##ULL
#endif
#endif
static struct
{
char *str;
Uint64 upper, lower;
} test_guids[NUM_TEST_GUIDS] = {
{ "0000000000000000"
"ffffffffffffffff",
UINT64_C(0x0000000000000000), UINT64_C(0xffffffffffffffff) },
{ "0011223344556677"
"8091a2b3c4d5e6f0",
UINT64_C(0x0011223344556677), UINT64_C(0x8091a2b3c4d5e6f0) },
{ "a011223344556677"
"8091a2b3c4d5e6f0",
UINT64_C(0xa011223344556677), UINT64_C(0x8091a2b3c4d5e6f0) },
{ "a011223344556677"
"8091a2b3c4d5e6f1",
UINT64_C(0xa011223344556677), UINT64_C(0x8091a2b3c4d5e6f1) },
{ "a011223344556677"
"8191a2b3c4d5e6f0",
UINT64_C(0xa011223344556677), UINT64_C(0x8191a2b3c4d5e6f0) },
};
static void
upper_lower_to_bytestring(Uint8 *out, Uint64 upper, Uint64 lower)
{
Uint64 values[2];
int i, k;
values[0] = upper;
values[1] = lower;
for (i = 0; i < 2; ++i) {
Uint64 v = values[i];
for (k = 0; k < 8; ++k) {
*out++ = v >> 56;
v <<= 8;
}
}
}
/* Test case functions */
/**
* @brief Check String-to-GUID conversion
*
* @sa SDL_GUIDFromString
*/
static int
TestGuidFromString(void *arg)
{
int i;
SDLTest_AssertPass("Call to SDL_GUIDFromString");
for (i = 0; i < NUM_TEST_GUIDS; ++i) {
Uint8 expected[16];
SDL_GUID guid;
upper_lower_to_bytestring(expected,
test_guids[i].upper, test_guids[i].lower);
guid = SDL_GUIDFromString(test_guids[i].str);
SDLTest_AssertCheck(SDL_memcmp(expected, guid.data, 16) == 0, "GUID from string, GUID was: '%s'", test_guids[i].str);
}
return TEST_COMPLETED;
}
/**
* @brief Check GUID-to-String conversion
*
* @sa SDL_GUIDToString
*/
static int
TestGuidToString(void *arg)
{
int i;
SDLTest_AssertPass("Call to SDL_GUIDToString");
for (i = 0; i < NUM_TEST_GUIDS; ++i) {
const int guid_str_offset = 4;
char guid_str_buf[64];
char *guid_str = guid_str_buf + guid_str_offset;
SDL_GUID guid;
int size;
upper_lower_to_bytestring(guid.data,
test_guids[i].upper, test_guids[i].lower);
/* Serialise to limited-length buffers */
for (size = 0; size <= 36; ++size) {
const Uint8 fill_char = size + 0xa0;
Uint32 expected_prefix;
Uint32 actual_prefix;
int written_size;
SDL_memset(guid_str_buf, fill_char, sizeof(guid_str_buf));
SDL_GUIDToString(guid, guid_str, size);
/* Check bytes before guid_str_buf */
expected_prefix = fill_char | (fill_char << 8) | (fill_char << 16) | (fill_char << 24);
SDL_memcpy(&actual_prefix, guid_str_buf, 4);
SDLTest_AssertCheck(expected_prefix == actual_prefix, "String buffer memory before output untouched, expected: %" SDL_PRIu32 ", got: %" SDL_PRIu32 ", at size=%d", expected_prefix, actual_prefix, size);
/* Check that we did not overwrite too much */
written_size = 0;
while ((guid_str[written_size] & 0xff) != fill_char && written_size < 256) {
++written_size;
}
SDLTest_AssertCheck(written_size <= size, "Output length is within expected bounds, with length %d: wrote %d of %d permitted bytes", size, written_size, size);
if (size >= 33) {
SDLTest_AssertCheck(SDL_strcmp(guid_str, test_guids[i].str) == 0, "GUID string equality, from string: %s", test_guids[i].str);
}
}
}
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* GUID routine test cases */
static const SDLTest_TestCaseReference guidTest1 = {
(SDLTest_TestCaseFp)TestGuidFromString, "TestGuidFromString", "Call to SDL_GUIDFromString", TEST_ENABLED
};
static const SDLTest_TestCaseReference guidTest2 = {
(SDLTest_TestCaseFp)TestGuidToString, "TestGuidToString", "Call to SDL_GUIDToString", TEST_ENABLED
};
/* Sequence of GUID routine test cases */
static const SDLTest_TestCaseReference *guidTests[] = {
&guidTest1,
&guidTest2,
NULL
};
/* GUID routine test suite (global) */
SDLTest_TestSuiteReference guidTestSuite = {
"GUID",
NULL,
guidTests,
NULL
};
......@@ -7,10 +7,7 @@
#include "SDL.h"
#include "SDL_test.h"
const int _numHintsEnum = 25;
const char* _HintsEnum[] =
{
const char *_HintsEnum[] = {
SDL_HINT_ACCELEROMETER_AS_JOYSTICK,
SDL_HINT_FRAMEBUFFER_ACCELERATION,
SDL_HINT_GAMECONTROLLERCONFIG,
......@@ -32,13 +29,10 @@ const char* _HintsEnum[] =
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,
};
const char* _HintsVerbose[] =
{
const char *_HintsVerbose[] = {
"SDL_ACCELEROMETER_AS_JOYSTICK",
"SDL_FRAMEBUFFER_ACCELERATION",
"SDL_GAMECONTROLLERCONFIG",
......@@ -60,20 +54,20 @@ const char* _HintsVerbose[] =
"SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS",
"SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT",
"SDL_VIDEO_WIN_D3DCOMPILER",
"SDL_VIDEO_X11_XINERAMA",
"SDL_VIDEO_X11_XRANDR",
"SDL_VIDEO_X11_XVIDMODE",
"SDL_XINPUT_ENABLED"
};
SDL_COMPILE_TIME_ASSERT(HintsEnum, SDL_arraysize(_HintsEnum) == SDL_arraysize(_HintsVerbose));
const int _numHintsEnum = SDL_arraysize(_HintsEnum);
/* Test case functions */
/**
* @brief Call to SDL_GetHint
*/
int
hints_getHint(void *arg)
int hints_getHint(void *arg)
{
const char *result1;
const char *result2;
......@@ -94,15 +88,21 @@ hints_getHint(void *arg)
return TEST_COMPLETED;
}
static void SDLCALL hints_testHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
*(char **)userdata = hint ? SDL_strdup(hint) : NULL;
}
/**
* @brief Call to SDL_SetHint
*/
int
hints_setHint(void *arg)
int hints_setHint(void *arg)
{
const char *testHint = "SDL_AUTOMATED_TEST_HINT";
const char *originalValue;
const char *value;
char *value;
const char *testValue;
char *callbackValue;
SDL_bool result;
int i, j;
......@@ -144,7 +144,99 @@ hints_setHint(void *arg)
SDL_free((void *)originalValue);
}
SDL_free((void *)value);
SDL_free(value);
/* Set default value in environment */
SDL_setenv(testHint, "original", 1);
SDLTest_AssertPass("Call to SDL_GetHint() after saving and restoring hint");
originalValue = SDL_GetHint(testHint);
value = (originalValue == NULL) ? NULL : SDL_strdup(originalValue);
SDL_SetHint(testHint, "temp");
SDL_SetHint(testHint, value);
SDL_free(value);
testValue = SDL_GetHint(testHint);
SDLTest_AssertCheck(
testValue && SDL_strcmp(testValue, "original") == 0,
"testValue = %s, expected \"original\"",
testValue);
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(NULL, SDL_HINT_DEFAULT)");
SDL_SetHintWithPriority(testHint, NULL, SDL_HINT_DEFAULT);
testValue = SDL_GetHint(testHint);
SDLTest_AssertCheck(
testValue && SDL_strcmp(testValue, "original") == 0,
"testValue = %s, expected \"original\"",
testValue);
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE)");
SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE);
testValue = SDL_GetHint(testHint);
SDLTest_AssertCheck(
testValue && SDL_strcmp(testValue, "temp") == 0,
"testValue = %s, expected \"temp\"",
testValue);
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(NULL, SDL_HINT_OVERRIDE)");
SDL_SetHintWithPriority(testHint, NULL, SDL_HINT_OVERRIDE);
testValue = SDL_GetHint(testHint);
SDLTest_AssertCheck(
testValue == NULL,
"testValue = %s, expected NULL",
testValue);
SDLTest_AssertPass("Call to SDL_ResetHint()");
SDL_ResetHint(testHint);
testValue = SDL_GetHint(testHint);
SDLTest_AssertCheck(
testValue && SDL_strcmp(testValue, "original") == 0,
"testValue = %s, expected \"original\"",
testValue);
/* Make sure callback functionality works past a reset */
SDLTest_AssertPass("Call to SDL_AddHintCallback()");
callbackValue = NULL;
SDL_AddHintCallback(testHint, hints_testHintChanged, &callbackValue);
SDLTest_AssertCheck(
callbackValue && SDL_strcmp(callbackValue, "original") == 0,
"callbackValue = %s, expected \"original\"",
callbackValue);
SDL_free(callbackValue);
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE), using callback");
callbackValue = NULL;
SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE);
SDLTest_AssertCheck(
callbackValue && SDL_strcmp(callbackValue, "temp") == 0,
"callbackValue = %s, expected \"temp\"",
callbackValue);
SDL_free(callbackValue);
SDLTest_AssertPass("Call to SDL_ResetHint(), using callback");
callbackValue = NULL;
SDL_ResetHint(testHint);
SDLTest_AssertCheck(
callbackValue && SDL_strcmp(callbackValue, "original") == 0,
"callbackValue = %s, expected \"original\"",
callbackValue);
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE), using callback after reset");
callbackValue = NULL;
SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE);
SDLTest_AssertCheck(
callbackValue && SDL_strcmp(callbackValue, "temp") == 0,
"callbackValue = %s, expected \"temp\"",
callbackValue);
SDL_free(callbackValue);
SDLTest_AssertPass("Call to SDL_ResetHint(), after clearing callback");
callbackValue = NULL;
SDL_DelHintCallback(testHint, hints_testHintChanged, &callbackValue);
SDL_ResetHint(testHint);
SDLTest_AssertCheck(
callbackValue == NULL,
"callbackValue = %s, expected \"(null)\"",
callbackValue);
return TEST_COMPLETED;
}
......@@ -152,11 +244,13 @@ hints_setHint(void *arg)
/* ================= Test References ================== */
/* Hints test cases */
static const SDLTest_TestCaseReference hintsTest1 =
{ (SDLTest_TestCaseFp)hints_getHint, "hints_getHint", "Call to SDL_GetHint", TEST_ENABLED };
static const SDLTest_TestCaseReference hintsTest1 = {
(SDLTest_TestCaseFp)hints_getHint, "hints_getHint", "Call to SDL_GetHint", TEST_ENABLED
};
static const SDLTest_TestCaseReference hintsTest2 =
{ (SDLTest_TestCaseFp)hints_setHint, "hints_setHint", "Call to SDL_SetHint", TEST_ENABLED };
static const SDLTest_TestCaseReference hintsTest2 = {
(SDLTest_TestCaseFp)hints_setHint, "hints_setHint", "Call to SDL_SetHint", TEST_ENABLED
};
/* Sequence of Hints test cases */
static const SDLTest_TestCaseReference *hintsTests[] = {
......
/**
* Joystick test suite
*/
#include "SDL.h"
#include "SDL_test.h"
#include "../src/joystick/usb_ids.h"
/* ================= Test Case Implementation ================== */
/* Test case functions */
/**
* @brief Check virtual joystick creation
*
* @sa SDL_JoystickAttachVirtualEx
*/
static int
TestVirtualJoystick(void *arg)
{
SDL_VirtualJoystickDesc desc;
SDL_Joystick *joystick = NULL;
int device_index;
SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)");
SDL_zero(desc);
desc.version = SDL_VIRTUAL_JOYSTICK_DESC_VERSION;
desc.type = SDL_JOYSTICK_TYPE_GAMECONTROLLER;
desc.naxes = SDL_CONTROLLER_AXIS_MAX;
desc.nbuttons = SDL_CONTROLLER_BUTTON_MAX;
desc.vendor_id = USB_VENDOR_NVIDIA;
desc.product_id = USB_PRODUCT_NVIDIA_SHIELD_CONTROLLER_V104;
desc.name = "Virtual NVIDIA SHIELD Controller";
device_index = SDL_JoystickAttachVirtualEx(&desc);
SDLTest_AssertCheck(device_index >= 0, "SDL_JoystickAttachVirtualEx()");
SDLTest_AssertCheck(SDL_JoystickIsVirtual(device_index), "SDL_JoystickIsVirtual()");
if (device_index >= 0) {
joystick = SDL_JoystickOpen(device_index);
SDLTest_AssertCheck(joystick != NULL, "SDL_JoystickOpen()");
if (joystick) {
SDLTest_AssertCheck(SDL_strcmp(SDL_JoystickName(joystick), desc.name) == 0, "SDL_JoystickName()");
SDLTest_AssertCheck(SDL_JoystickGetVendor(joystick) == desc.vendor_id, "SDL_JoystickGetVendor()");
SDLTest_AssertCheck(SDL_JoystickGetProduct(joystick) == desc.product_id, "SDL_JoystickGetProduct()");
SDLTest_AssertCheck(SDL_JoystickGetProductVersion(joystick) == 0, "SDL_JoystickGetProductVersion()");
SDLTest_AssertCheck(SDL_JoystickGetFirmwareVersion(joystick) == 0, "SDL_JoystickGetFirmwareVersion()");
SDLTest_AssertCheck(SDL_JoystickGetSerial(joystick) == NULL, "SDL_JoystickGetSerial()");
SDLTest_AssertCheck(SDL_JoystickGetType(joystick) == desc.type, "SDL_JoystickGetType()");
SDLTest_AssertCheck(SDL_JoystickNumAxes(joystick) == desc.naxes, "SDL_JoystickNumAxes()");
SDLTest_AssertCheck(SDL_JoystickNumBalls(joystick) == 0, "SDL_JoystickNumBalls()");
SDLTest_AssertCheck(SDL_JoystickNumHats(joystick) == desc.nhats, "SDL_JoystickNumHats()");
SDLTest_AssertCheck(SDL_JoystickNumButtons(joystick) == desc.nbuttons, "SDL_JoystickNumButtons()");
SDLTest_AssertCheck(SDL_JoystickSetVirtualButton(joystick, SDL_CONTROLLER_BUTTON_A, SDL_PRESSED) == 0, "SDL_JoystickSetVirtualButton(SDL_CONTROLLER_BUTTON_A, SDL_PRESSED)");
SDL_JoystickUpdate();
SDLTest_AssertCheck(SDL_JoystickGetButton(joystick, SDL_CONTROLLER_BUTTON_A) == SDL_PRESSED, "SDL_JoystickGetButton(SDL_CONTROLLER_BUTTON_A) == SDL_PRESSED");
SDLTest_AssertCheck(SDL_JoystickSetVirtualButton(joystick, SDL_CONTROLLER_BUTTON_A, SDL_RELEASED) == 0, "SDL_JoystickSetVirtualButton(SDL_CONTROLLER_BUTTON_A, SDL_RELEASED)");
SDL_JoystickUpdate();
SDLTest_AssertCheck(SDL_JoystickGetButton(joystick, SDL_CONTROLLER_BUTTON_A) == SDL_RELEASED, "SDL_JoystickGetButton(SDL_CONTROLLER_BUTTON_A) == SDL_RELEASED");
SDL_JoystickClose(joystick);
}
SDLTest_AssertCheck(SDL_JoystickDetachVirtual(device_index) == 0, "SDL_JoystickDetachVirtual()");
}
SDLTest_AssertCheck(!SDL_JoystickIsVirtual(device_index), "!SDL_JoystickIsVirtual()");
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Joystick routine test cases */
static const SDLTest_TestCaseReference joystickTest1 = {
(SDLTest_TestCaseFp)TestVirtualJoystick, "TestVirtualJoystick", "Test virtual joystick functionality", TEST_ENABLED
};
/* Sequence of Joystick routine test cases */
static const SDLTest_TestCaseReference *joystickTests[] = {
&joystickTest1,
NULL
};
/* Joystick routine test suite (global) */
SDLTest_TestSuiteReference joystickTestSuite = {
"Joystick",
NULL,
joystickTests,
NULL
};
......@@ -18,8 +18,7 @@
*
* @sa http://wiki.libsdl.org/SDL_GetKeyboardState
*/
int
keyboard_getKeyboardState(void *arg)
int keyboard_getKeyboardState(void *arg)
{
int numkeys;
Uint8 *state;
......@@ -44,8 +43,7 @@ keyboard_getKeyboardState(void *arg)
*
* @sa http://wiki.libsdl.org/SDL_GetKeyboardFocus
*/
int
keyboard_getKeyboardFocus(void *arg)
int keyboard_getKeyboardFocus(void *arg)
{
/* Call, but ignore return value */
SDL_GetKeyboardFocus();
......@@ -59,45 +57,44 @@ keyboard_getKeyboardFocus(void *arg)
*
* @sa http://wiki.libsdl.org/SDL_GetKeyFromName
*/
int
keyboard_getKeyFromName(void *arg)
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);
SDLTest_AssertCheck(result == SDLK_a, "Verify result from call, expected: %i, got: %" SDL_PRIs32, 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);
SDLTest_AssertCheck(result == SDLK_F1, "Verify result from call, expected: %i, got: %" SDL_PRIs32, 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);
SDLTest_AssertCheck(result == SDLK_END, "Verify result from call, expected: %i, got: %" SDL_PRIs32, 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);
SDLTest_AssertCheck(result == SDLK_FIND, "Verify result from call, expected: %i, got: %" SDL_PRIs32, 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);
SDLTest_AssertCheck(result == SDLK_AUDIOSTOP, "Verify result from call, expected: %i, got: %" SDL_PRIs32, 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);
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %" SDL_PRIs32, 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);
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %" SDL_PRIs32, SDLK_UNKNOWN, result);
return TEST_COMPLETED;
}
......@@ -105,8 +102,7 @@ keyboard_getKeyFromName(void *arg)
/*
* Local helper to check for the invalid scancode error message
*/
void
_checkInvalidScancodeError()
void _checkInvalidScancodeError()
{
const char *expectedError = "Parameter 'scancode' is invalid";
const char *error;
......@@ -126,20 +122,19 @@ _checkInvalidScancodeError()
*
* @sa http://wiki.libsdl.org/SDL_GetKeyFromScancode
*/
int
keyboard_getKeyFromScancode(void *arg)
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);
SDLTest_AssertCheck(result == SDLK_a, "Verify result from call, expected: %i, got: %" SDL_PRIs32, 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);
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %" SDL_PRIs32, SDLK_UNKNOWN, result);
/* Clear error message */
SDL_ClearError();
......@@ -148,13 +143,13 @@ keyboard_getKeyFromScancode(void *arg)
/* 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);
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %" SDL_PRIs32, 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);
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %" SDL_PRIs32, SDLK_UNKNOWN, result);
_checkInvalidScancodeError();
return TEST_COMPLETED;
......@@ -165,8 +160,7 @@ keyboard_getKeyFromScancode(void *arg)
*
* @sa http://wiki.libsdl.org/SDL_GetKeyName
*/
int
keyboard_getKeyName(void *arg)
int keyboard_getKeyName(void *arg)
{
const char *result;
const char *expected;
......@@ -221,8 +215,7 @@ keyboard_getKeyName(void *arg)
*
* @sa http://wiki.libsdl.org/SDL_GetScancodeName
*/
int
keyboard_getScancodeNameNegative(void *arg)
int keyboard_getScancodeNameNegative(void *arg)
{
SDL_Scancode scancode;
const char *result;
......@@ -248,8 +241,7 @@ keyboard_getScancodeNameNegative(void *arg)
*
* @sa http://wiki.libsdl.org/SDL_GetKeyName
*/
int
keyboard_getKeyNameNegative(void *arg)
int keyboard_getKeyNameNegative(void *arg)
{
SDL_Keycode keycode;
const char *result;
......@@ -258,7 +250,7 @@ keyboard_getKeyNameNegative(void *arg)
/* Unknown keycode */
keycode = SDLK_UNKNOWN;
result = (char *)SDL_GetKeyName(keycode);
SDLTest_AssertPass("Call to SDL_GetKeyName(%d/unknown)", keycode);
SDLTest_AssertPass("Call to SDL_GetKeyName(%" SDL_PRIs32 "/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);
......@@ -269,7 +261,7 @@ keyboard_getKeyNameNegative(void *arg)
/* Negative keycode */
keycode = (SDL_Keycode)SDLTest_RandomIntegerInRange(-255, -1);
result = (char *)SDL_GetKeyName(keycode);
SDLTest_AssertPass("Call to SDL_GetKeyName(%d/negative)", keycode);
SDLTest_AssertPass("Call to SDL_GetKeyName(%" SDL_PRIs32 "/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();
......@@ -286,8 +278,7 @@ keyboard_getKeyNameNegative(void *arg)
* @sa http://wiki.libsdl.org/SDL_GetModState
* @sa http://wiki.libsdl.org/SDL_SetModState
*/
int
keyboard_getSetModState(void *arg)
int keyboard_getSetModState(void *arg)
{
SDL_Keymod result;
SDL_Keymod currentState;
......@@ -340,15 +331,13 @@ keyboard_getSetModState(void *arg)
return TEST_COMPLETED;
}
/**
* @brief Check call to SDL_StartTextInput and SDL_StopTextInput
*
* @sa http://wiki.libsdl.org/SDL_StartTextInput
* @sa http://wiki.libsdl.org/SDL_StopTextInput
*/
int
keyboard_startStopTextInput(void *arg)
int keyboard_startStopTextInput(void *arg)
{
/* Start-Stop */
SDL_StartTextInput();
......@@ -393,8 +382,7 @@ void _testSetTextInputRect(SDL_Rect refRect)
*
* @sa http://wiki.libsdl.org/SDL_SetTextInputRect
*/
int
keyboard_setTextInputRect(void *arg)
int keyboard_setTextInputRect(void *arg)
{
SDL_Rect refRect;
......@@ -473,8 +461,7 @@ keyboard_setTextInputRect(void *arg)
*
* @sa http://wiki.libsdl.org/SDL_SetTextInputRect
*/
int
keyboard_setTextInputRectNegative(void *arg)
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
......@@ -512,8 +499,7 @@ keyboard_setTextInputRectNegative(void *arg)
* @sa http://wiki.libsdl.org/SDL_GetScancodeFromKey
* @sa http://wiki.libsdl.org/SDL_Keycode
*/
int
keyboard_getScancodeFromKey(void *arg)
int keyboard_getScancodeFromKey(void *arg)
{
SDL_Scancode scancode;
......@@ -536,8 +522,7 @@ keyboard_getScancodeFromKey(void *arg)
* @sa http://wiki.libsdl.org/SDL_GetScancodeFromName
* @sa http://wiki.libsdl.org/SDL_Keycode
*/
int
keyboard_getScancodeFromName(void *arg)
int keyboard_getScancodeFromName(void *arg)
{
SDL_Scancode scancode;
......@@ -587,8 +572,7 @@ keyboard_getScancodeFromName(void *arg)
/*
* Local helper to check for the invalid scancode error message
*/
void
_checkInvalidNameError()
void _checkInvalidNameError()
{
const char *expectedError = "Parameter 'name' is invalid";
const char *error;
......@@ -609,8 +593,7 @@ _checkInvalidNameError()
* @sa http://wiki.libsdl.org/SDL_GetScancodeFromName
* @sa http://wiki.libsdl.org/SDL_Keycode
*/
int
keyboard_getScancodeFromNameNegative(void *arg)
int keyboard_getScancodeFromNameNegative(void *arg)
{
const char *name;
SDL_Scancode scancode;
......@@ -633,14 +616,14 @@ keyboard_getScancodeFromNameNegative(void *arg)
/* Zero length string input */
name = "";
scancode = SDL_GetScancodeFromName((const char *)name);
scancode = SDL_GetScancodeFromName(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);
scancode = SDL_GetScancodeFromName(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();
......@@ -648,52 +631,64 @@ keyboard_getScancodeFromNameNegative(void *arg)
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 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 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 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 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 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 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 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 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 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 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 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 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 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 };
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[] = {
......
......@@ -9,7 +9,6 @@
#include "SDL.h"
#include "SDL_test.h"
/* !
* \brief Tests SDL_Init() and SDL_Quit() of Joystick and Haptic subsystems
* \sa
......@@ -125,17 +124,54 @@ static int main_testImpliedJoystickQuit (void *arg)
#endif
}
static const SDLTest_TestCaseReference mainTest1 =
{ (SDLTest_TestCaseFp)main_testInitQuitJoystickHaptic, "main_testInitQuitJoystickHaptic", "Tests SDL_Init/Quit of Joystick and Haptic subsystem", TEST_ENABLED};
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-zero-length"
#endif
static int
main_testSetError(void *arg)
{
size_t i;
char error[1024];
error[0] = '\0';
SDL_SetError("");
SDLTest_AssertCheck(SDL_strcmp(error, SDL_GetError()) == 0, "SDL_SetError(\"\")");
static const SDLTest_TestCaseReference mainTest2 =
{ (SDLTest_TestCaseFp)main_testInitQuitSubSystem, "main_testInitQuitSubSystem", "Tests SDL_InitSubSystem/QuitSubSystem", TEST_ENABLED};
for (i = 0; i < (sizeof(error) - 1); ++i) {
error[i] = 'a' + (i % 26);
}
error[i] = '\0';
SDL_SetError("%s", error);
SDLTest_AssertCheck(SDL_strcmp(error, SDL_GetError()) == 0, "SDL_SetError(\"abc...1023\")");
static const SDLTest_TestCaseReference mainTest3 =
{ (SDLTest_TestCaseFp)main_testImpliedJoystickInit, "main_testImpliedJoystickInit", "Tests that init for gamecontroller properly implies joystick", TEST_ENABLED};
return TEST_COMPLETED;
}
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
static const SDLTest_TestCaseReference mainTest4 =
{ (SDLTest_TestCaseFp)main_testImpliedJoystickQuit, "main_testImpliedJoystickQuit", "Tests that quit for gamecontroller doesn't quit joystick if you inited it explicitly", TEST_ENABLED};
static const SDLTest_TestCaseReference 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
};
static const SDLTest_TestCaseReference mainTest5 = {
(SDLTest_TestCaseFp)main_testSetError, "main_testSetError", "Tests that SDL_SetError() handles arbitrarily large strings", TEST_ENABLED
};
/* Sequence of Main test cases */
static const SDLTest_TestCaseReference *mainTests[] = {
......@@ -143,6 +179,7 @@ static const SDLTest_TestCaseReference *mainTests[] = {
&mainTest2,
&mainTest3,
&mainTest4,
&mainTest5,
NULL
};
......
/**
* Math test suite
*/
#include <float.h>
#include <math.h>
#include "SDL.h"
#include "SDL_test.h"
/* ================= Test Constants ================== */
/* Range tests parameters */
#define RANGE_TEST_ITERATIONS 10000000
#define RANGE_TEST_STEP ((Uint32)(SDL_MAX_UINT32 / RANGE_TEST_ITERATIONS))
/* Margin of error for imprecise tests */
#define EPSILON 1.0E-10
/* Euler constant (used in exp/log) */
#ifndef M_E
#define EULER 2.7182818284590450907955982984276488423347473144531250
#else
#define EULER M_E
#endif
#define IS_INFINITY(V) fpclassify(V) == FP_INFINITE
/* Square root of 3 (used in atan2) */
#define SQRT3 1.7320508075688771931766041234368458390235900878906250
/* ================= Test Structs ================== */
/**
* Stores a single input and the expected result
*/
typedef struct
{
double input;
double expected;
} d_to_d;
/**
* Stores a pair of inputs and the expected result
*/
typedef struct
{
double x_input, y_input;
double expected;
} dd_to_d;
/*
NB: You cannot create an array of these structures containing INFINITY or NAN.
On platforms such as OS/2, they are defined as 'extern const double' making them
not compile-time constant.
*/
/* ================= Test Helpers ================== */
typedef double(SDLCALL *d_to_d_func)(double);
typedef double(SDLCALL *dd_to_d_func)(double, double);
/**
* \brief Runs all the cases on a given function with a signature double -> double.
* The result is expected to be exact.
*
* \param func_name, a printable name for the tested function.
* \param func, the function to call.
* \param cases, an array of all the cases.
* \param cases_size, the size of the cases array.
*/
static int
helper_dtod(const char *func_name, d_to_d_func func,
const d_to_d *cases, const size_t cases_size)
{
Uint32 i;
for (i = 0; i < cases_size; i++) {
const double result = func(cases[i].input);
SDLTest_AssertCheck(result == cases[i].expected,
"%s(%f), expected %f, got %f",
func_name,
cases[i].input,
cases[i].expected, result);
}
return TEST_COMPLETED;
}
/**
* \brief Runs all the cases on a given function with a signature double -> double.
* Checks if the result between expected +/- EPSILON.
*
* \param func_name, a printable name for the tested function.
* \param func, the function to call.
* \param cases, an array of all the cases.
* \param cases_size, the size of the cases array.
*/
static int
helper_dtod_inexact(const char *func_name, d_to_d_func func,
const d_to_d *cases, const size_t cases_size)
{
Uint32 i;
for (i = 0; i < cases_size; i++) {
const double result = func(cases[i].input);
SDLTest_AssertCheck(result >= cases[i].expected - EPSILON &&
result <= cases[i].expected + EPSILON,
"%s(%f), expected [%f,%f], got %f",
func_name,
cases[i].input,
cases[i].expected - EPSILON,
cases[i].expected + EPSILON,
result);
}
return TEST_COMPLETED;
}
/**
* \brief Runs all the cases on a given function with a signature
* (double, double) -> double. The result is expected to be exact.
*
* \param func_name, a printable name for the tested function.
* \param func, the function to call.
* \param cases, an array of all the cases.
* \param cases_size, the size of the cases array.
*/
static int
helper_ddtod(const char *func_name, dd_to_d_func func,
const dd_to_d *cases, const size_t cases_size)
{
Uint32 i;
for (i = 0; i < cases_size; i++) {
const double result = func(cases[i].x_input, cases[i].y_input);
SDLTest_AssertCheck(result == cases[i].expected,
"%s(%f,%f), expected %f, got %f",
func_name,
cases[i].x_input, cases[i].y_input,
cases[i].expected, result);
}
return TEST_COMPLETED;
}
/**
* \brief Runs all the cases on a given function with a signature
* (double, double) -> double. Checks if the result between expected +/- EPSILON.
*
* \param func_name, a printable name for the tested function.
* \param func, the function to call.
* \param cases, an array of all the cases.
* \param cases_size, the size of the cases array.
*/
static int
helper_ddtod_inexact(const char *func_name, dd_to_d_func func,
const dd_to_d *cases, const size_t cases_size)
{
Uint32 i;
for (i = 0; i < cases_size; i++) {
const double result = func(cases[i].x_input, cases[i].y_input);
SDLTest_AssertCheck(result >= cases[i].expected - EPSILON &&
result <= cases[i].expected + EPSILON,
"%s(%f,%f), expected [%f,%f], got %f",
func_name,
cases[i].x_input, cases[i].y_input,
cases[i].expected - EPSILON,
cases[i].expected + EPSILON,
result);
}
return TEST_COMPLETED;
}
/**
* \brief Runs a range of values on a given function with a signature double -> double
*
* This function is only meant to test functions that returns the input value if it is
* integral: f(x) -> x for x in N.
*
* \param func_name, a printable name for the tested function.
* \param func, the function to call.
*/
static int
helper_range(const char *func_name, d_to_d_func func)
{
Uint32 i;
double test_value = 0.0;
SDLTest_AssertPass("%s: Testing a range of %u values with steps of %" SDL_PRIu32,
func_name,
RANGE_TEST_ITERATIONS,
RANGE_TEST_STEP);
for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
double result;
/* These are tested elsewhere */
if (isnan(test_value) || isinf(test_value)) {
continue;
}
result = func(test_value);
if (result != test_value) { /* Only log failures to save performances */
SDLTest_AssertCheck(SDL_FALSE,
"%s(%.1f), expected %.1f, got %.1f",
func_name, test_value,
test_value, result);
return TEST_ABORTED;
}
}
return TEST_COMPLETED;
}
/* ================= Test Case Implementation ================== */
/* SDL_floor tests functions */
/**
* Inputs: +/-Infinity.
* Expected: Infinity is returned as-is.
*/
static int
floor_infCases(void *args)
{
double result;
result = SDL_floor(INFINITY);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Floor(%f), expected %f, got %f",
INFINITY, INFINITY, result);
result = SDL_floor(-INFINITY);
SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Floor(%f), expected %f, got %f",
-INFINITY, -INFINITY, result);
return TEST_COMPLETED;
}
/**
* Inputs: +/-0.0.
* Expected: Zero is returned as-is.
*/
static int
floor_zeroCases(void *args)
{
const d_to_d zero_cases[] = {
{ 0.0, 0.0 },
{ -0.0, -0.0 }
};
return helper_dtod("Floor", SDL_floor, zero_cases, SDL_arraysize(zero_cases));
}
/**
* Input: NAN.
* Expected: NAN is returned.
*/
static int
floor_nanCase(void *args)
{
const double result = SDL_floor(NAN);
SDLTest_AssertCheck(isnan(result),
"Floor(nan), expected nan, got %f",
result);
return TEST_COMPLETED;
}
/**
* Inputs: integral values.
* Expected: the input value is returned as-is.
*/
static int
floor_roundNumbersCases(void *args)
{
const d_to_d round_cases[] = {
{ 1.0, 1.0 },
{ -1.0, -1.0 },
{ 15.0, 15.0 },
{ -15.0, -15.0 },
{ 125.0, 125.0 },
{ -125.0, -125.0 },
{ 1024.0, 1024.0 },
{ -1024.0, -1024.0 }
};
return helper_dtod("Floor", SDL_floor, round_cases, SDL_arraysize(round_cases));
}
/**
* Inputs: fractional values.
* Expected: the lower integral value is returned.
*/
static int
floor_fractionCases(void *args)
{
const d_to_d frac_cases[] = {
{ 1.0 / 2.0, 0.0 },
{ -1.0 / 2.0, -1.0 },
{ 4.0 / 3.0, 1.0 },
{ -4.0 / 3.0, -2.0 },
{ 76.0 / 7.0, 10.0 },
{ -76.0 / 7.0, -11.0 },
{ 535.0 / 8.0, 66.0 },
{ -535.0 / 8.0, -67.0 },
{ 19357.0 / 53.0, 365.0 },
{ -19357.0 / 53.0, -366.0 }
};
return helper_dtod("Floor", SDL_floor, frac_cases, SDL_arraysize(frac_cases));
}
/**
* Inputs: values in the range [0, UINT32_MAX].
* Expected: the input value is returned as-is.
*/
static int
floor_rangeTest(void *args)
{
return helper_range("Floor", SDL_floor);
}
/* SDL_ceil tests functions */
/**
* Inputs: +/-Infinity.
* Expected: Infinity is returned as-is.
*/
static int
ceil_infCases(void *args)
{
double result;
result = SDL_ceil(INFINITY);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Ceil(%f), expected %f, got %f",
INFINITY, INFINITY, result);
result = SDL_ceil(-INFINITY);
SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Ceil(%f), expected %f, got %f",
-INFINITY, -INFINITY, result);
return TEST_COMPLETED;
}
/**
* Inputs: +/-0.0.
* Expected: Zero is returned as-is.
*/
static int
ceil_zeroCases(void *args)
{
const d_to_d zero_cases[] = {
{ 0.0, 0.0 },
{ -0.0, -0.0 }
};
return helper_dtod("Ceil", SDL_ceil, zero_cases, SDL_arraysize(zero_cases));
}
/**
* Input: NAN.
* Expected: NAN is returned.
*/
static int
ceil_nanCase(void *args)
{
const double result = SDL_ceil(NAN);
SDLTest_AssertCheck(isnan(result),
"Ceil(nan), expected nan, got %f",
result);
return TEST_COMPLETED;
}
/**
* Inputs: integral values.
* Expected: the input value is returned as-is.
*/
static int
ceil_roundNumbersCases(void *args)
{
const d_to_d round_cases[] = {
{ 1.0, 1.0 },
{ -1.0, -1.0 },
{ 15.0, 15.0 },
{ -15.0, -15.0 },
{ 125.0, 125.0 },
{ -125.0, -125.0 },
{ 1024.0, 1024.0 },
{ -1024.0, -1024.0 }
};
return helper_dtod("Ceil", SDL_ceil, round_cases, SDL_arraysize(round_cases));
}
/**
* Inputs: fractional values.
* Expected: the higher integral value is returned.
*/
static int
ceil_fractionCases(void *args)
{
const d_to_d frac_cases[] = {
{ 1.0 / 2.0, 1.0 },
{ -1.0 / 2.0, -0.0 },
{ 4.0 / 3.0, 2.0 },
{ -4.0 / 3.0, -1.0 },
{ 76.0 / 7.0, 11.0 },
{ -76.0 / 7.0, -10.0 },
{ 535.0 / 8.0, 67.0 },
{ -535.0 / 8.0, -66.0 },
{ 19357.0 / 53.0, 366.0 },
{ -19357.0 / 53.0, -365.0 }
};
return helper_dtod("Ceil", SDL_ceil, frac_cases, SDL_arraysize(frac_cases));
}
/**
* Inputs: values in the range [0, UINT32_MAX].
* Expected: the input value is returned as-is.
*/
static int
ceil_rangeTest(void *args)
{
return helper_range("Ceil", SDL_ceil);
}
/* SDL_trunc tests functions */
/**
* Inputs: +/-Infinity.
* Expected: Infinity is returned as-is.
*/
static int
trunc_infCases(void *args)
{
double result;
result = SDL_trunc(INFINITY);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Trunc(%f), expected %f, got %f",
INFINITY, INFINITY, result);
result = SDL_trunc(-INFINITY);
SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Trunc(%f), expected %f, got %f",
-INFINITY, -INFINITY, result);
return TEST_COMPLETED;
}
/**
* Inputs: +/-0.0.
* Expected: Zero is returned as-is.
*/
static int
trunc_zeroCases(void *args)
{
const d_to_d zero_cases[] = {
{ 0.0, 0.0 },
{ -0.0, -0.0 }
};
return helper_dtod("Trunc", SDL_trunc, zero_cases, SDL_arraysize(zero_cases));
}
/**
* Input: NAN.
* Expected: NAN is returned.
*/
static int
trunc_nanCase(void *args)
{
const double result = SDL_trunc(NAN);
SDLTest_AssertCheck(isnan(result),
"Trunc(nan), expected nan, got %f",
result);
return TEST_COMPLETED;
}
/**
* Inputs: integral values.
* Expected: the input value is returned as-is.
*/
static int
trunc_roundNumbersCases(void *args)
{
const d_to_d round_cases[] = {
{ 1.0, 1.0 },
{ -1.0, -1.0 },
{ 15.0, 15.0 },
{ -15.0, -15.0 },
{ 125.0, 125.0 },
{ -125.0, -125.0 },
{ 1024.0, 1024.0 },
{ -1024.0, -1024.0 }
};
return helper_dtod("Trunc", SDL_trunc, round_cases, SDL_arraysize(round_cases));
}
/**
* Inputs: fractional values.
* Expected: the integral part is returned.
*/
static int
trunc_fractionCases(void *args)
{
const d_to_d frac_cases[] = {
{ 1.0 / 2.0, 0.0 },
{ -1.0 / 2.0, -0.0 },
{ 4.0 / 3.0, 1.0 },
{ -4.0 / 3.0, -1.0 },
{ 76.0 / 7.0, 10.0 },
{ -76.0 / 7.0, -10.0 },
{ 535.0 / 8.0, 66.0 },
{ -535.0 / 8.0, -66.0 },
{ 19357.0 / 53.0, 365.0 },
{ -19357.0 / 53.0, -365.0 }
};
return helper_dtod("Trunc", SDL_trunc, frac_cases, SDL_arraysize(frac_cases));
}
/**
* Inputs: values in the range [0, UINT32_MAX].
* Expected: the input value is returned as-is.
*/
static int
trunc_rangeTest(void *args)
{
return helper_range("Trunc", SDL_trunc);
}
/* SDL_round tests functions */
/**
* Inputs: +/-Infinity.
* Expected: Infinity is returned as-is.
*/
static int
round_infCases(void *args)
{
double result;
result = SDL_round(INFINITY);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Round(%f), expected %f, got %f",
INFINITY, INFINITY, result);
result = SDL_round(-INFINITY);
SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Round(%f), expected %f, got %f",
-INFINITY, -INFINITY, result);
return TEST_COMPLETED;
}
/**
* Inputs: +/-0.0.
* Expected: Zero is returned as-is.
*/
static int
round_zeroCases(void *args)
{
const d_to_d zero_cases[] = {
{ 0.0, 0.0 },
{ -0.0, -0.0 }
};
return helper_dtod("Round", SDL_round, zero_cases, SDL_arraysize(zero_cases));
}
/**
* Input: NAN.
* Expected: NAN is returned.
*/
static int
round_nanCase(void *args)
{
const double result = SDL_round(NAN);
SDLTest_AssertCheck(isnan(result),
"Round(nan), expected nan, got %f",
result);
return TEST_COMPLETED;
}
/**
* Inputs: integral values.
* Expected: the input value is returned as-is.
*/
static int
round_roundNumbersCases(void *args)
{
const d_to_d round_cases[] = {
{ 1.0, 1.0 },
{ -1.0, -1.0 },
{ 15.0, 15.0 },
{ -15.0, -15.0 },
{ 125.0, 125.0 },
{ -125.0, -125.0 },
{ 1024.0, 1024.0 },
{ -1024.0, -1024.0 }
};
return helper_dtod("Round", SDL_round, round_cases, SDL_arraysize(round_cases));
}
/**
* Inputs: fractional values.
* Expected: the nearest integral value is returned.
*/
static int
round_fractionCases(void *args)
{
const d_to_d frac_cases[] = {
{ 1.0 / 2.0, 1.0 },
{ -1.0 / 2.0, -1.0 },
{ 4.0 / 3.0, 1.0 },
{ -4.0 / 3.0, -1.0 },
{ 76.0 / 7.0, 11.0 },
{ -76.0 / 7.0, -11.0 },
{ 535.0 / 8.0, 67.0 },
{ -535.0 / 8.0, -67.0 },
{ 19357.0 / 53.0, 365.0 },
{ -19357.0 / 53.0, -365.0 }
};
return helper_dtod("Round", SDL_round, frac_cases, SDL_arraysize(frac_cases));
}
/**
* Inputs: values in the range [0, UINT32_MAX].
* Expected: the input value is returned as-is.
*/
static int
round_rangeTest(void *args)
{
return helper_range("Round", SDL_round);
}
/* SDL_fabs tests functions */
/**
* Inputs: +/-Infinity.
* Expected: Positive Infinity is returned.
*/
static int
fabs_infCases(void *args)
{
double result;
result = SDL_fabs(INFINITY);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Fabs(%f), expected %f, got %f",
INFINITY, INFINITY, result);
result = SDL_fabs(-INFINITY);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Fabs(%f), expected %f, got %f",
-INFINITY, INFINITY, result);
return TEST_COMPLETED;
}
/**
* Inputs: +/-0.0.
* Expected: Positive zero is returned.
*/
static int
fabs_zeroCases(void *args)
{
const d_to_d zero_cases[] = {
{ 0.0, 0.0 },
{ -0.0, 0.0 }
};
return helper_dtod("Fabs", SDL_fabs, zero_cases, SDL_arraysize(zero_cases));
}
/**
* Input: NAN.
* Expected: NAN is returned.
*/
static int
fabs_nanCase(void *args)
{
const double result = SDL_fabs(NAN);
SDLTest_AssertCheck(isnan(result),
"Fabs(nan), expected nan, got %f",
result);
return TEST_COMPLETED;
}
/**
* Inputs: values in the range [0, UINT32_MAX].
* Expected: the input value is returned as-is.
*/
static int
fabs_rangeTest(void *args)
{
return helper_range("Fabs", SDL_fabs);
}
/* SDL_copysign tests functions */
/**
* Inputs: (+/-Infinity, +/-1.0).
* Expected: Infinity with the sign of 1.0 is returned.
*/
static int
copysign_infCases(void *args)
{
double result;
result = SDL_copysign(INFINITY, -1.0);
SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Copysign(%f,%.1f), expected %f, got %f",
INFINITY, -1.0, -INFINITY, result);
result = SDL_copysign(INFINITY, 1.0);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Copysign(%f,%.1f), expected %f, got %f",
INFINITY, 1.0, INFINITY, result);
result = SDL_copysign(-INFINITY, -1.0);
SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Copysign(%f,%.1f), expected %f, got %f",
-INFINITY, -1.0, -INFINITY, result);
result = SDL_copysign(-INFINITY, 1.0);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Copysign(%f,%.1f), expected %f, got %f",
-INFINITY, 1.0, INFINITY, result);
return TEST_COMPLETED;
}
/**
* Inputs: (+/-0.0, +/-1.0).
* Expected: 0.0 with the sign of 1.0 is returned.
*/
static int
copysign_zeroCases(void *args)
{
const dd_to_d zero_cases[] = {
{ 0.0, 1.0, 0.0 },
{ 0.0, -1.0, -0.0 },
{ -0.0, 1.0, 0.0 },
{ -0.0, -1.0, -0.0 }
};
return helper_ddtod("Copysign", SDL_copysign, zero_cases, SDL_arraysize(zero_cases));
}
/**
* Inputs: (NAN, +/-1.0).
* Expected: NAN with the sign of 1.0 is returned.
* NOTE: On some platforms signed NAN is not supported, so we only check if the result is still NAN.
*/
static int
copysign_nanCases(void *args)
{
double result;
result = SDL_copysign(NAN, 1.0);
SDLTest_AssertCheck(isnan(result),
"Copysign(nan,1.0), expected nan, got %f",
result);
result = SDL_copysign(NAN, -1.0);
SDLTest_AssertCheck(isnan(result),
"Copysign(nan,-1.0), expected nan, got %f",
result);
return TEST_COMPLETED;
}
/**
* Inputs: values in the range [0, UINT32_MAX], +/-1.0.
* Expected: the input value with the sign of 1.0 is returned.
*/
static int
copysign_rangeTest(void *args)
{
Uint32 i;
double test_value = 0.0;
SDLTest_AssertPass("Copysign: Testing a range of %u values with steps of %" SDL_PRIu32,
RANGE_TEST_ITERATIONS,
RANGE_TEST_STEP);
for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
double result;
/* These are tested elsewhere */
if (isnan(test_value) || isinf(test_value)) {
continue;
}
/* Only log failures to save performances */
result = SDL_copysign(test_value, 1.0);
if (result != test_value) {
SDLTest_AssertCheck(SDL_FALSE,
"Copysign(%.1f,%.1f), expected %.1f, got %.1f",
test_value, 1.0, test_value, result);
return TEST_ABORTED;
}
result = SDL_copysign(test_value, -1.0);
if (result != -test_value) {
SDLTest_AssertCheck(SDL_FALSE,
"Copysign(%.1f,%.1f), expected %.1f, got %.1f",
test_value, -1.0, -test_value, result);
return TEST_ABORTED;
}
}
return TEST_COMPLETED;
}
/* SDL_fmod tests functions */
/**
* Inputs: (+/-Infinity, +/-1.0).
* Expected: NAN is returned.
*/
static int
fmod_divOfInfCases(void *args)
{
double result;
result = SDL_fmod(INFINITY, -1.0);
SDLTest_AssertCheck(isnan(result),
"Fmod(%f,%.1f), expected %f, got %f",
INFINITY, -1.0, NAN, result);
result = SDL_fmod(INFINITY, 1.0);
SDLTest_AssertCheck(isnan(result),
"Fmod(%f,%.1f), expected %f, got %f",
INFINITY, 1.0, NAN, result);
result = SDL_fmod(-INFINITY, -1.0);
SDLTest_AssertCheck(isnan(result),
"Fmod(%f,%.1f), expected %f, got %f",
-INFINITY, -1.0, NAN, result);
result = SDL_fmod(-INFINITY, 1.0);
SDLTest_AssertCheck(isnan(result),
"Fmod(%f,%.1f), expected %f, got %f",
-INFINITY, 1.0, NAN, result);
return TEST_COMPLETED;
}
/**
* Inputs: (+/-1.0, +/-Infinity).
* Expected: 1.0 is returned as-is.
*/
static int
fmod_divByInfCases(void *args)
{
double result;
result = SDL_fmod(1.0, INFINITY);
SDLTest_AssertCheck(1.0 == result,
"Fmod(%.1f,%f), expected %f, got %f",
1.0, INFINITY, 1.0, result);
result = SDL_fmod(-1.0, INFINITY);
SDLTest_AssertCheck(-1.0 == result,
"Fmod(%.1f,%f), expected %f, got %f",
-1.0, INFINITY, -1.0, result);
result = SDL_fmod(1.0, -INFINITY);
SDLTest_AssertCheck(1.0 == result,
"Fmod(%.1f,%f), expected %f, got %f",
1.0, -INFINITY, 1.0, result);
result = SDL_fmod(-1.0, -INFINITY);
SDLTest_AssertCheck(-1.0 == result,
"Fmod(%.1f,%f), expected %f, got %f",
-1.0, -INFINITY, -1.0, result);
return TEST_COMPLETED;
}
/**
* Inputs: (+/-0.0, +/-1.0).
* Expected: Zero is returned as-is.
*/
static int
fmod_divOfZeroCases(void *args)
{
const dd_to_d zero_cases[] = {
{ 0.0, 1.0, 0.0 },
{ 0.0, -1.0, 0.0 },
{ -0.0, 1.0, -0.0 },
{ -0.0, -1.0, -0.0 }
};
return helper_ddtod("Fmod", SDL_fmod, zero_cases, SDL_arraysize(zero_cases));
}
/**
* Inputs: (+/-1.0, +/-0.0).
* Expected: NAN is returned.
*/
static int
fmod_divByZeroCases(void *args)
{
double result;
result = SDL_fmod(1.0, 0.0);
SDLTest_AssertCheck(isnan(result),
"Fmod(1.0,0.0), expected nan, got %f",
result);
result = SDL_fmod(-1.0, 0.0);
SDLTest_AssertCheck(isnan(result),
"Fmod(-1.0,0.0), expected nan, got %f",
result);
result = SDL_fmod(1.0, -0.0);
SDLTest_AssertCheck(isnan(result),
"Fmod(1.0,-0.0), expected nan, got %f",
result);
result = SDL_fmod(-1.0, -0.0);
SDLTest_AssertCheck(isnan(result),
"Fmod(-1.0,-0.0), expected nan, got %f",
result);
return TEST_COMPLETED;
}
/**
* Inputs: all permutation of NAN and +/-1.0.
* Expected: NAN is returned.
*/
static int
fmod_nanCases(void *args)
{
double result;
result = SDL_fmod(NAN, 1.0);
SDLTest_AssertCheck(isnan(result),
"Fmod(nan,1.0), expected nan, got %f",
result);
result = SDL_fmod(NAN, -1.0);
SDLTest_AssertCheck(isnan(result),
"Fmod(nan,-1.0), expected nan, got %f",
result);
result = SDL_fmod(1.0, NAN);
SDLTest_AssertCheck(isnan(result),
"Fmod(1.0,nan), expected nan, got %f",
result);
result = SDL_fmod(-1.0, NAN);
SDLTest_AssertCheck(isnan(result),
"Fmod(-1.0,nan), expected nan, got %f",
result);
return TEST_COMPLETED;
}
/**
* Inputs: values within the domain of the function.
* Expected: the correct result is returned.
*/
static int
fmod_regularCases(void *args)
{
const dd_to_d regular_cases[] = {
{ 3.5, 2.0, 1.5 },
{ -6.25, 3.0, -0.25 },
{ 7.5, 2.5, 0.0 },
{ 2.0 / 3.0, -1.0 / 3.0, 0.0 }
};
return helper_ddtod("Fmod", SDL_fmod, regular_cases, SDL_arraysize(regular_cases));
}
/**
* Inputs: values in the range [0, UINT32_MAX] divided by 1.0.
* Expected: Positive zero is always returned.
*/
static int
fmod_rangeTest(void *args)
{
Uint32 i;
double test_value = 0.0;
SDLTest_AssertPass("Fmod: Testing a range of %u values with steps of %" SDL_PRIu32,
RANGE_TEST_ITERATIONS,
RANGE_TEST_STEP);
for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
double result;
/* These are tested elsewhere */
if (isnan(test_value) || isinf(test_value)) {
continue;
}
/* Only log failures to save performances */
result = SDL_fmod(test_value, 1.0);
if (0.0 != result) {
SDLTest_AssertCheck(SDL_FALSE,
"Fmod(%.1f,%.1f), expected %.1f, got %.1f",
test_value, 1.0, 0.0, result);
return TEST_ABORTED;
}
}
return TEST_COMPLETED;
}
/* SDL_exp tests functions */
/**
* Inputs: +/-Infinity.
* Expected: Infinity is returned as-is.
*/
static int
exp_infCases(void *args)
{
double result;
result = SDL_exp(INFINITY);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Exp(%f), expected %f, got %f",
INFINITY, INFINITY, result);
result = SDL_exp(-INFINITY);
SDLTest_AssertCheck(0.0 == result,
"Exp(%f), expected %f, got %f",
-INFINITY, 0.0, result);
return TEST_COMPLETED;
}
/**
* Inputs: +/-0.0.
* Expected: 1.0 is returned.
*/
static int
exp_zeroCases(void *args)
{
const d_to_d zero_cases[] = {
{ 0.0, 1.0 },
{ -0.0, 1.0 }
};
return helper_dtod("Exp", SDL_exp, zero_cases, SDL_arraysize(zero_cases));
}
/**
* Input: 710.0 (overflows for 64bits double).
* Expected: Infinity is returned.
* NOTE: This test is skipped for double types larger than 64 bits.
*/
static int
exp_overflowCase(void *args)
{
double result;
if (sizeof(double) > 8) {
return TEST_SKIPPED;
}
result = SDL_exp(710.0);
SDLTest_AssertCheck(isinf(result),
"Exp(%f), expected %f, got %f",
710.0, INFINITY, result);
return TEST_COMPLETED;
}
/**
* Input: 1.0
* Expected: The euler constant.
*/
static int
exp_baseCase(void *args)
{
const double result = SDL_exp(1.0);
SDLTest_AssertCheck(result >= EULER - EPSILON &&
result <= EULER + EPSILON,
"Exp(%f), expected [%f,%f], got %f",
1.0, EULER - EPSILON, EULER + EPSILON, result);
return TEST_COMPLETED;
}
/**
* Inputs: values within the domain of the function.
* Expected: the correct result is returned.
*/
static int
exp_regularCases(void *args)
{
/* Hexadecimal floating constants are not supported on C89 compilers */
const d_to_d regular_cases[] = {
{ -101.0, 1.36853947117385291381565719268793547578002532127613087E-44 },
{ -15.73, 0.00000014741707833928422931856502906683425990763681 },
{ -1.0, 0.36787944117144233402427744294982403516769409179688 },
{ -0.5, 0.60653065971263342426311737654032185673713684082031 },
{ 0.5, 1.64872127070012819416433558217249810695648193359375 },
{ 2.25, 9.48773583635852624240669683786109089851379394531250 },
{ 34.125, 661148770968660.375 },
{ 112.89, 10653788283588960962604279261058893737879589093376.0 },
{ 539.483, 1970107755334319939701129934673541628417235942656909222826926175622435588279443011110464355295725187195188154768877850257012251677751742837992843520967922303961718983154427294786640886286983037548604937796221048661733679844353544028160.0 },
};
return helper_dtod("Exp", SDL_exp, regular_cases, SDL_arraysize(regular_cases));
}
/* SDL_log tests functions */
/**
* Inputs: Positive Infinity and +/-0.0.
* Expected: Positive and negative Infinity respectively.
*/
static int
log_limitCases(void *args)
{
double result;
result = SDL_log(INFINITY);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Log(%f), expected %f, got %f",
INFINITY, INFINITY, result);
result = SDL_log(0.0);
SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Log(%f), expected %f, got %f",
0.0, -INFINITY, result);
result = SDL_log(-0.0);
SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Log(%f), expected %f, got %f",
-0.0, -INFINITY, result);
return TEST_COMPLETED;
}
/**
* Inputs: 1.0 and the Euler constant.
* Expected: 0.0 and 1.0 respectively.
*/
static int
log_baseCases(void *args)
{
double result;
result = SDL_log(1.0);
SDLTest_AssertCheck(0.0 == result,
"Log(%f), expected %f, got %f",
1.0, 0.0, result);
result = SDL_log(EULER);
SDLTest_AssertCheck(1.0 == result,
"Log(%f), expected %f, got %f",
EULER, 1.0, result);
return TEST_COMPLETED;
}
/**
* Inputs: NAN and a negative value.
* Expected: NAN is returned.
*/
static int
log_nanCases(void *args)
{
double result;
result = SDL_log(NAN);
SDLTest_AssertCheck(isnan(result),
"Log(%f), expected %f, got %f",
NAN, NAN, result);
result = SDL_log(-1234.5678);
SDLTest_AssertCheck(isnan(result),
"Log(%f), expected %f, got %f",
-1234.5678, NAN, result);
return TEST_COMPLETED;
}
/**
* Inputs: values within the domain of the function.
* Expected: the correct result is returned.
*/
static int
log_regularCases(void *args)
{
const d_to_d regular_cases[] = {
{ 5.0, 1.60943791243410028179994242236716672778129577636718750 },
{ 10.0, 2.302585092994045901093613792909309267997741699218750 },
{ 56.32, 4.031049711849786554296315443934872746467590332031250 },
{ 789.123, 6.670922202231861497523368598194792866706848144531250 },
{ 2734.876324, 7.91384149408957959792587644187733530998229980468750 }
};
return helper_dtod("Log", SDL_log, regular_cases, SDL_arraysize(regular_cases));
}
/* SDL_log10 tests functions */
/**
* Inputs: Positive Infinity and +/-0.0.
* Expected: Positive and negative Infinity respectively.
*/
static int
log10_limitCases(void *args)
{
double result;
result = SDL_log10(INFINITY);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Log10(%f), expected %f, got %f",
INFINITY, INFINITY, result);
result = SDL_log10(0.0);
SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Log10(%f), expected %f, got %f",
0.0, -INFINITY, result);
result = SDL_log10(-0.0);
SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Log10(%f), expected %f, got %f",
-0.0, -INFINITY, result);
return TEST_COMPLETED;
}
/**
* Inputs: Powers of ten from 0 to 9.
* Expected: the exact power of ten is returned.
*/
static int
log10_baseCases(void *args)
{
const d_to_d base_cases[] = {
{ 1.0, 0.0 },
{ 10.0, 1.0 },
{ 100.0, 2.0 },
{ 1000.0, 3.0 },
{ 10000.0, 4.0 },
{ 100000.0, 5.0 },
{ 1000000.0, 6.0 },
{ 10000000.0, 7.0 },
{ 100000000.0, 8.0 },
{ 1000000000.0, 9.0 },
};
return helper_dtod("Log10", SDL_log10, base_cases, SDL_arraysize(base_cases));
}
/**
* Inputs: NAN and a negative value.
* Expected: NAN is returned.
*/
static int
log10_nanCases(void *args)
{
double result;
result = SDL_log10(NAN);
SDLTest_AssertCheck(isnan(result),
"Log10(%f), expected %f, got %f",
NAN, NAN, result);
result = SDL_log10(-1234.5678);
SDLTest_AssertCheck(isnan(result),
"Log10(%f), expected %f, got %f",
-1234.5678, NAN, result);
return TEST_COMPLETED;
}
/**
* Inputs: values within the domain of the function.
* Expected: the correct result is returned.
*/
static int
log10_regularCases(void *args)
{
const d_to_d regular_cases[] = {
{ 5.0, 0.698970004336018857493684208748163655400276184082031250 },
{ 12.5, 1.09691001300805646145875016372883692383766174316406250 },
{ 56.32, 1.750662646134055755453573510749265551567077636718750 },
{ 789.123, 2.8971447016351858927407647570362314581871032714843750 },
{ 2734.876324, 3.436937691540090433761633903486654162406921386718750 }
};
return helper_dtod_inexact("Log10", SDL_log10, regular_cases, SDL_arraysize(regular_cases));
}
/* SDL_pow tests functions */
/* Tests with positive and negative infinities as exponents */
/**
* Inputs: (-1.0, +/-Infinity).
* Expected: 1.0 is returned.
*/
static int
pow_baseNOneExpInfCases(void *args)
{
double result;
result = SDL_pow(-1.0, INFINITY);
SDLTest_AssertCheck(1.0 == result,
"Pow(%f,%f), expected %f, got %f",
-1.0, INFINITY, 1.0, result);
result = SDL_pow(-1.0, -INFINITY);
SDLTest_AssertCheck(1.0 == result,
"Pow(%f,%f), expected %f, got %f",
-1.0, -INFINITY, 1.0, result);
return TEST_COMPLETED;
}
/**
* Inputs: (+/-0.0, -Infinity).
* Expected: Infinity is returned.
*/
static int
pow_baseZeroExpNInfCases(void *args)
{
double result;
result = SDL_pow(0.0, -INFINITY);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
0.0, -INFINITY, INFINITY, result);
result = SDL_pow(-0.0, -INFINITY);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
-0.0, -INFINITY, INFINITY, result);
return TEST_COMPLETED;
}
/**
* Inputs: (x, +/-Infinity) where x is not +/-0.0.
* Expected: 0.0 when x < 1, Infinity when x > 1.
*/
static int
pow_expInfCases(void *args)
{
double result;
result = SDL_pow(0.5, INFINITY);
SDLTest_AssertCheck(0.0 == result,
"Pow(%f,%f), expected %f, got %f",
0.5, INFINITY, 0.0, result);
result = SDL_pow(1.5, INFINITY);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
1.5, INFINITY, INFINITY, result);
result = SDL_pow(0.5, -INFINITY);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
0.5, INFINITY, INFINITY, result);
result = SDL_pow(1.5, -INFINITY);
SDLTest_AssertCheck(0.0 == result,
"Pow(%f,%f), expected %f, got %f",
1.5, -INFINITY, 0.0, result);
return TEST_COMPLETED;
}
/* Tests with positive and negative infinities as base */
/**
* Inputs: (Positive Infinity, x) where x is not +/-0.0.
* Expected: 0.0 when x is < 0, positive Infinity when x > 0.
*/
static int
pow_basePInfCases(void *args)
{
double result;
result = SDL_pow(INFINITY, -3.0);
SDLTest_AssertCheck(0.0 == result,
"Pow(%f,%f), expected %f, got %f",
INFINITY, -3.0, 0.0, result);
result = SDL_pow(INFINITY, 2.0);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
INFINITY, 2.0, INFINITY, result);
result = SDL_pow(INFINITY, -2.12345);
SDLTest_AssertCheck(0.0 == result,
"Pow(%f,%f), expected %f, got %f",
INFINITY, -2.12345, 0.0, result);
result = SDL_pow(INFINITY, 3.1345);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
INFINITY, 3.12345, INFINITY, result);
return TEST_COMPLETED;
}
/**
* Inputs: (Negative Infinity, x) where x is not +/-0.0.
* Expected:
* - -0.0 when x is a negative odd integer,
* - 0.0 when x is a negative even integer or negative non-integer,
* - Negative Infinity when x is a positive odd integer,
* - Positive Infinity when x is a positive even integer or positive non-integer.
*/
static int
pow_baseNInfCases(void *args)
{
double result;
result = SDL_pow(-INFINITY, -3.0);
SDLTest_AssertCheck(-0.0 == result,
"Pow(%f,%f), expected %f, got %f",
-INFINITY, -3.0, -0.0, result);
result = SDL_pow(-INFINITY, -2.0);
SDLTest_AssertCheck(0.0 == result,
"Pow(%f,%f), expected %f, got %f",
-INFINITY, -2.0, 0.0, result);
result = SDL_pow(-INFINITY, -5.5);
SDLTest_AssertCheck(0.0 == result,
"Pow(%f,%f), expected %f, got %f",
-INFINITY, -5.5, 0.0, result);
result = SDL_pow(-INFINITY, 3.0);
SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Pow(%f,%f), expected %f, got %f",
-INFINITY, 3.0, -INFINITY, result);
result = SDL_pow(-INFINITY, 2.0);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
-INFINITY, 2.0, INFINITY, result);
result = SDL_pow(-INFINITY, 5.5);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
-INFINITY, 5.5, INFINITY, result);
return TEST_COMPLETED;
}
/* Tests related to NAN */
/**
* Inputs:
* - finite and negative base,
* - finite and non-integer exponent.
* Expected: NAN is returned.
*/
static int
pow_badOperationCase(void *args)
{
const double result = SDL_pow(-2.0, 4.2);
SDLTest_AssertCheck(isnan(result),
"Pow(%f,%f), expected %f, got %f",
-2.0, 4.2, NAN, result);
return TEST_COMPLETED;
}
/**
* Inputs: (1.0, NAN)
* Expected: 1.0 is returned.
*/
static int
pow_base1ExpNanCase(void *args)
{
const double result = SDL_pow(1.0, NAN);
SDLTest_AssertCheck(1.0 == result,
"Pow(%f,%f), expected %f, got %f",
1.0, NAN, 1.0, result);
return TEST_COMPLETED;
}
/**
* Inputs: (NAN, +/-0.0)
* Expected: 1.0 is returned.
*/
static int
pow_baseNanExp0Cases(void *args)
{
double result;
result = SDL_pow(NAN, 0.0);
SDLTest_AssertCheck(1.0 == result,
"Pow(%f,%f), expected %f, got %f",
NAN, 0.0, 1.0, result);
result = SDL_pow(NAN, -0.0);
SDLTest_AssertCheck(1.0 == result,
"Pow(%f,%f), expected %f, got %f",
NAN, -0.0, 1.0, result);
return TEST_COMPLETED;
}
/**
* Inputs: NAN as base, exponent or both.
* Expected: NAN is returned.
*/
static int
pow_nanArgsCases(void *args)
{
double result;
result = SDL_pow(7.8, NAN);
SDLTest_AssertCheck(isnan(result),
"Pow(%f,%f), expected %f, got %f",
7.8, NAN, NAN, result);
result = SDL_pow(NAN, 10.0);
SDLTest_AssertCheck(isnan(result),
"Pow(%f,%f), expected %f, got %f",
NAN, 10.0, NAN, result);
result = SDL_pow(NAN, NAN);
SDLTest_AssertCheck(isnan(result),
"Pow(%f,%f), expected %f, got %f",
NAN, NAN, NAN, result);
return TEST_COMPLETED;
}
/* Tests with positive and negative zeros as base */
/**
* Inputs: (-0.0, x) where x is an odd integer.
* Expected:
* - Negative Infinity with a negative exponent,
* - -0.0 with a positive exponent.
*/
static int
pow_baseNZeroExpOddCases(void *args)
{
double result;
result = SDL_pow(-0.0, -3.0);
SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Pow(%f,%f), expected %f, got %f",
-0.0, -3.0, -INFINITY, result);
result = SDL_pow(-0.0, 3.0);
SDLTest_AssertCheck(-0.0 == result,
"Pow(%f,%f), expected %f, got %f",
-0.0, 3.0, -0.0, result);
return TEST_COMPLETED;
}
/**
* Inputs: (0.0, x) where x is an odd integer.
* Expected:
* - 0.0 with a positive exponent,
* - Positive Infinity with a negative exponent.
*/
static int
pow_basePZeroExpOddCases(void *args)
{
double result;
result = SDL_pow(0.0, -5.0);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
0.0, -5.0, INFINITY, result);
result = SDL_pow(0.0, 5.0);
SDLTest_AssertCheck(0.0 == result,
"Pow(%f,%f), expected %f, got %f",
0.0, 5.0, 0.0, result);
return TEST_COMPLETED;
}
/**
* Inputs: (-0.0, x), with x either:
* - finite and even,
* - finite and non-integer.
* Expected:
* - Positive Infinity if the exponent is negative,
* - 0.0 if the exponent is positive.
*/
static int
pow_baseNZeroCases(void *args)
{
double result;
result = SDL_pow(-0.0, -3.5);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
-0.0, -3.5, INFINITY, result);
result = SDL_pow(-0.0, -4.0);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
-0.0, -4.0, INFINITY, result);
result = SDL_pow(-0.0, 3.5);
SDLTest_AssertCheck(0.0 == result,
"Pow(%f,%f), expected %f, got %f",
-0.0, 3.5, 0.0, result);
result = SDL_pow(-0.0, 4.0);
SDLTest_AssertCheck(0.0 == result,
"Pow(%f,%f), expected %f, got %f",
-0.0, 4.0, 0.0, result);
return TEST_COMPLETED;
}
/**
* Inputs: (0.0, x), with x either:
* - finite and even,
* - finite and non-integer.
* Expected:
* - Positive Infinity if the exponent is negative,
* - 0.0 if the exponent is positive.
*/
static int
pow_basePZeroCases(void *args)
{
double result;
result = SDL_pow(0.0, -3.5);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
0.0, -3.5, INFINITY, result);
result = SDL_pow(0.0, -4.0);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
0.0, -4.0, INFINITY, result);
result = SDL_pow(0.0, 3.5);
SDLTest_AssertCheck(0.0 == result,
"Pow(%f,%f), expected %f, got %f",
0.0, 3.5, 0.0, result);
result = SDL_pow(0.0, 4.0);
SDLTest_AssertCheck(0.0 == result,
"Pow(%f,%f), expected %f, got %f",
0.0, 4.0, 0.0, result);
return TEST_COMPLETED;
}
/* Remaining tests */
/**
* Inputs: values within the domain of the function.
* Expected: the correct result is returned.
*/
static int
pow_regularCases(void *args)
{
const dd_to_d regular_cases[] = {
{ -391.25, -2.0, 0.00000653267870448815438463212659780943170062528224661946296691894531250 },
{ -72.3, 12.0, 20401381050275984310272.0 },
{ -5.0, 3.0, -125.0 },
{ 3.0, 2.5, 15.58845726811989607085706666111946105957031250 },
{ 39.23, -1.5, 0.0040697950366865498147972424192175822099670767784118652343750 },
{ 478.972, 12.125, 315326359630449587856007411793920.0 }
};
return helper_ddtod("Pow", SDL_pow, regular_cases, SDL_arraysize(regular_cases));
}
/**
* Inputs: (2.0, x), with x in range [0, 8].
* Expected: the correct result is returned.
*/
static int
pow_powerOfTwo(void *args)
{
const dd_to_d power_of_two_cases[] = {
{ 2.0, 1.0, 2.0 },
{ 2.0, 2.0, 4.0 },
{ 2.0, 3.0, 8.0 },
{ 2.0, 4.0, 16.0 },
{ 2.0, 5.0, 32.0 },
{ 2.0, 6.0, 64.0 },
{ 2.0, 7.0, 128.0 },
{ 2.0, 8.0, 256.0 },
};
return helper_ddtod("Pow", SDL_pow, power_of_two_cases, SDL_arraysize(power_of_two_cases));
}
/**
* Inputs: values in the range [0, UINT32_MAX] to the power of +/-0.0.
* Expected: 1.0 is always returned.
*/
static int
pow_rangeTest(void *args)
{
Uint32 i;
double test_value = 0.0;
SDLTest_AssertPass("Pow: Testing a range of %u values with steps of %" SDL_PRIu32,
RANGE_TEST_ITERATIONS,
RANGE_TEST_STEP);
for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
double result;
/* These are tested elsewhere */
if (isnan(test_value) || isinf(test_value)) {
continue;
}
/* Only log failures to save performances */
result = SDL_pow(test_value, 0.0);
if (result != 1.0) {
SDLTest_AssertCheck(SDL_FALSE,
"Pow(%.1f,%.1f), expected %.1f, got %.1f",
test_value, 1.0, 1.0, result);
return TEST_ABORTED;
}
result = SDL_pow(test_value, -0.0);
if (result != 1.0) {
SDLTest_AssertCheck(SDL_FALSE,
"Pow(%.1f,%.1f), expected %.1f, got %.1f",
test_value, -0.0, 1.0, result);
return TEST_ABORTED;
}
}
return TEST_COMPLETED;
}
/* SDL_sqrt tests functions */
/**
* Input: Positive Infinity.
* Expected: Positive Infinity is returned.
*/
static int
sqrt_infCase(void *args)
{
const double result = SDL_sqrt(INFINITY);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Sqrt(%f), expected %f, got %f",
INFINITY, INFINITY, result);
return TEST_COMPLETED;
}
/**
* Input: NAN.
* Expected: NAN is returned.
*/
static int
sqrt_nanCase(void *args)
{
const double result = SDL_sqrt(NAN);
SDLTest_AssertCheck(isnan(result),
"Sqrt(%f), expected %f, got %f",
NAN, NAN, result);
return TEST_COMPLETED;
}
/**
* Inputs: values outside the domain of the function.
* Expected: NAN is returned.
*/
static int
sqrt_outOfDomainCases(void *args)
{
double result;
result = SDL_sqrt(-1.0);
SDLTest_AssertCheck(isnan(result),
"Sqrt(%f), expected %f, got %f",
-1.0, NAN, result);
result = SDL_sqrt(-12345.6789);
SDLTest_AssertCheck(isnan(result),
"Sqrt(%f), expected %f, got %f",
-12345.6789, NAN, result);
result = SDL_sqrt(-INFINITY);
SDLTest_AssertCheck(isnan(result),
"Sqrt(%f), expected %f, got %f",
-INFINITY, NAN, result);
return TEST_COMPLETED;
}
/**
* Inputs: +/-0.0 and 1.0.
* Expected: the input value is returned as-is.
*/
static int
sqrt_baseCases(void *args)
{
const d_to_d base_cases[] = {
{ -0.0, -0.0 },
{ 0.0, 0.0 },
{ 1.0, 1.0 }
};
return helper_dtod("Sqrt", SDL_sqrt, base_cases, SDL_arraysize(base_cases));
}
/**
* Inputs: values within the domain of the function.
* Expected: the correct result is returned.
*/
static int
sqrt_regularCases(void *args)
{
const d_to_d regular_cases[] = {
{ 4.0, 2.0 },
{ 9.0, 3.0 },
{ 27.2, 5.21536192416211896727418206864967942237854003906250 },
{ 240.250, 15.5 },
{ 1337.0, 36.565010597564445049556525191292166709899902343750 },
{ 2887.12782400000014604302123188972473144531250, 53.732 },
{ 65600.0156250, 256.125 }
};
return helper_dtod_inexact("Sqrt", SDL_sqrt, regular_cases, SDL_arraysize(regular_cases));
}
/* SDL_scalbn tests functions */
/**
* Input: (+/-Infinity, 1).
* Expected: Infinity is returned as-is.
*/
static int
scalbn_infCases(void *args)
{
double result;
result = SDL_scalbn(INFINITY, 1);
SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Scalbn(%f,%d), expected %f, got %f",
INFINITY, 1, INFINITY, result);
result = SDL_scalbn(-INFINITY, 1);
SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Scalbn(%f,%d), expected %f, got %f",
-INFINITY, 1, -INFINITY, result);
return TEST_COMPLETED;
}
/**
* Inputs: (+/-0.0, 1).
* Expected: Zero is returned as-is.
*/
static int
scalbn_baseZeroCases(void *args)
{
double result;
result = SDL_scalbn(0.0, 1);
SDLTest_AssertCheck(0.0 == result,
"Scalbn(%f,%d), expected %f, got %f",
0.0, 1, 0.0, result);
result = SDL_scalbn(-0.0, 1);
SDLTest_AssertCheck(-0.0 == result,
"Scalbn(%f,%d), expected %f, got %f",
-0.0, 1, -0.0, result);
return TEST_COMPLETED;
}
/**
* Input: (x, 0)
* Expected: x is returned as-is.
*/
static int
scalbn_expZeroCase(void *args)
{
const double result = SDL_scalbn(42.0, 0);
SDLTest_AssertCheck(42.0 == result,
"Scalbn(%f,%d), expected %f, got %f",
42.0, 0, 42.0, result);
return TEST_COMPLETED;
}
/**
* Input: (NAN, x).
* Expected: NAN is returned.
*/
static int
scalbn_nanCase(void *args)
{
const double result = SDL_scalbn(NAN, 2);
SDLTest_AssertCheck(isnan(result),
"Scalbn(%f,%d), expected %f, got %f",
NAN, 2, NAN, result);
return TEST_COMPLETED;
}
/**
* Inputs: values inside the domain of the function.
* Expected: the correct result is returned.
* NOTE: This test depends on SDL_pow and FLT_RADIX.
*/
static int
scalbn_regularCases(void *args)
{
double result, expected;
result = SDL_scalbn(2.0, 2);
expected = 2.0 * SDL_pow(FLT_RADIX, 2);
SDLTest_AssertCheck(result == expected,
"Scalbn(%f,%d), expected %f, got %f",
2.0, 2, expected, result);
result = SDL_scalbn(1.0, 13);
expected = 1.0 * SDL_pow(FLT_RADIX, 13);
SDLTest_AssertCheck(result == expected,
"Scalbn(%f,%d), expected %f, got %f",
1.0, 13, expected, result);
result = SDL_scalbn(2.0, -5);
expected = 2.0 * SDL_pow(FLT_RADIX, -5);
SDLTest_AssertCheck(result == expected,
"Scalbn(%f,%d), expected %f, got %f",
2.0, -5, expected, result);
result = SDL_scalbn(-1.0, -13);
expected = -1.0 * SDL_pow(FLT_RADIX, -13);
SDLTest_AssertCheck(result == expected,
"Scalbn(%f,%d), expected %f, got %f",
-1.0, -13, expected, result);
return TEST_COMPLETED;
}
/* SDL_cos tests functions */
/**
* Inputs: +/-Infinity.
* Expected: NAN is returned.
*/
static int
cos_infCases(void *args)
{
double result;
result = SDL_cos(INFINITY);
SDLTest_AssertCheck(isnan(result),
"Cos(%f), expected %f, got %f",
INFINITY, NAN, result);
result = SDL_cos(-INFINITY);
SDLTest_AssertCheck(isnan(result),
"Cos(%f), expected %f, got %f",
-INFINITY, NAN, result);
return TEST_COMPLETED;
}
/**
* Input: NAN.
* Expected: NAN is returned.
*/
static int
cos_nanCase(void *args)
{
const double result = SDL_cos(NAN);
SDLTest_AssertCheck(isnan(result),
"Cos(%f), expected %f, got %f",
NAN, NAN, result);
return TEST_COMPLETED;
}
/**
* Inputs: +/-0.0 and +/-Pi.
* Expected: +1.0 and -1.0 respectively.
*/
static int
cos_regularCases(void *args)
{
const d_to_d regular_cases[] = {
{ -M_PI, -1.0 },
{ -0.0, 1.0 },
{ 0.0, 1.0 },
{ M_PI, -1.0 }
};
return helper_dtod("Cos", SDL_cos, regular_cases, SDL_arraysize(regular_cases));
}
/**
* Inputs: Angles between 1/10 and 9/10 of Pi (positive and negative).
* Expected: The correct result is returned (+/-EPSILON).
*/
static int
cos_precisionTest(void *args)
{
const d_to_d precision_cases[] = {
{ M_PI * 1.0 / 10.0, 0.9510565162 },
{ M_PI * 2.0 / 10.0, 0.8090169943 },
{ M_PI * 3.0 / 10.0, 0.5877852522 },
{ M_PI * 4.0 / 10.0, 0.3090169943 },
{ M_PI * 5.0 / 10.0, 0.0 },
{ M_PI * 6.0 / 10.0, -0.3090169943 },
{ M_PI * 7.0 / 10.0, -0.5877852522 },
{ M_PI * 8.0 / 10.0, -0.8090169943 },
{ M_PI * 9.0 / 10.0, -0.9510565162 },
{ M_PI * -1.0 / 10.0, 0.9510565162 },
{ M_PI * -2.0 / 10.0, 0.8090169943 },
{ M_PI * -3.0 / 10.0, 0.5877852522 },
{ M_PI * -4.0 / 10.0, 0.3090169943 },
{ M_PI * -5.0 / 10.0, 0.0 },
{ M_PI * -6.0 / 10.0, -0.3090169943 },
{ M_PI * -7.0 / 10.0, -0.5877852522 },
{ M_PI * -8.0 / 10.0, -0.8090169943 },
{ M_PI * -9.0 / 10.0, -0.9510565162 }
};
return helper_dtod_inexact("Cos", SDL_cos, precision_cases, SDL_arraysize(precision_cases));
}
/**
* Inputs: Values in the range [0, UINT32_MAX].
* Expected: A value between 0 and 1 is returned.
*/
static int
cos_rangeTest(void *args)
{
Uint32 i;
double test_value = 0.0;
SDLTest_AssertPass("Cos: Testing a range of %u values with steps of %" SDL_PRIu32,
RANGE_TEST_ITERATIONS,
RANGE_TEST_STEP);
for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
double result;
/* These are tested elsewhere */
if (isnan(test_value) || isinf(test_value)) {
continue;
}
/* Only log failures to save performances */
result = SDL_cos(test_value);
if (result < -1.0 || result > 1.0) {
SDLTest_AssertCheck(SDL_FALSE,
"Cos(%.1f), expected [%.1f,%.1f], got %.1f",
test_value, -1.0, 1.0, result);
return TEST_ABORTED;
}
}
return TEST_COMPLETED;
}
/* SDL_sin tests functions */
/**
* Inputs: +/-Infinity.
* Expected: NAN is returned.
*/
static int
sin_infCases(void *args)
{
double result;
result = SDL_sin(INFINITY);
SDLTest_AssertCheck(isnan(result),
"Sin(%f), expected %f, got %f",
INFINITY, NAN, result);
result = SDL_sin(-INFINITY);
SDLTest_AssertCheck(isnan(result),
"Sin(%f), expected %f, got %f",
-INFINITY, NAN, result);
return TEST_COMPLETED;
}
/**
* Input: NAN.
* Expected: NAN is returned.
*/
static int
sin_nanCase(void *args)
{
const double result = SDL_sin(NAN);
SDLTest_AssertCheck(isnan(result),
"Sin(%f), expected %f, got %f",
NAN, NAN, result);
return TEST_COMPLETED;
}
/**
* Inputs: +/-0.0 and +/-Pi/2.
* Expected: +/-0.0 and +/-1.0 respectively.
*/
static int
sin_regularCases(void *args)
{
const d_to_d regular_cases[] = {
{ -M_PI / 2, -1.0 },
{ -0.0, -0.0 },
{ 0.0, 0.0 },
{ M_PI / 2, 1.0 }
};
return helper_dtod("Sin", SDL_sin, regular_cases, SDL_arraysize(regular_cases));
}
/**
* Inputs: Angles between 1/10 and 10/10 of Pi (positive and negative).
* Expected: The correct result is returned (+/-EPSILON).
* NOTE: +/-Pi/2 is tested in the regular cases.
*/
static int
sin_precisionTest(void *args)
{
const d_to_d precision_cases[] = {
{ M_PI * 1.0 / 10.0, 0.3090169943 },
{ M_PI * 2.0 / 10.0, 0.5877852522 },
{ M_PI * 3.0 / 10.0, 0.8090169943 },
{ M_PI * 4.0 / 10.0, 0.9510565162 },
{ M_PI * 6.0 / 10.0, 0.9510565162 },
{ M_PI * 7.0 / 10.0, 0.8090169943 },
{ M_PI * 8.0 / 10.0, 0.5877852522 },
{ M_PI * 9.0 / 10.0, 0.3090169943 },
{ M_PI, 0.0 },
{ M_PI * -1.0 / 10.0, -0.3090169943 },
{ M_PI * -2.0 / 10.0, -0.5877852522 },
{ M_PI * -3.0 / 10.0, -0.8090169943 },
{ M_PI * -4.0 / 10.0, -0.9510565162 },
{ M_PI * -6.0 / 10.0, -0.9510565162 },
{ M_PI * -7.0 / 10.0, -0.8090169943 },
{ M_PI * -8.0 / 10.0, -0.5877852522 },
{ M_PI * -9.0 / 10.0, -0.3090169943 },
{ -M_PI, 0.0 },
};
return helper_dtod_inexact("Sin", SDL_sin, precision_cases, SDL_arraysize(precision_cases));
}
/**
* Inputs: Values in the range [0, UINT32_MAX].
* Expected: A value between 0 and 1 is returned.
*/
static int
sin_rangeTest(void *args)
{
Uint32 i;
double test_value = 0.0;
SDLTest_AssertPass("Sin: Testing a range of %u values with steps of %" SDL_PRIu32,
RANGE_TEST_ITERATIONS,
RANGE_TEST_STEP);
for (i = 0; i < RANGE_TEST_ITERATIONS; i++, test_value += RANGE_TEST_STEP) {
double result;
/* These are tested elsewhere */
if (isnan(test_value) || isinf(test_value)) {
continue;
}
/* Only log failures to save performances */
result = SDL_sin(test_value);
if (result < -1.0 || result > 1.0) {
SDLTest_AssertCheck(SDL_FALSE,
"Sin(%.1f), expected [%.1f,%.1f], got %.1f",
test_value, -1.0, 1.0, result);
return TEST_ABORTED;
}
}
return TEST_COMPLETED;
}
/* SDL_tan tests functions */
/**
* Inputs: +/-Infinity.
* Expected: NAN is returned.
*/
static int
tan_infCases(void *args)
{
double result;
result = SDL_tan(INFINITY);
SDLTest_AssertCheck(isnan(result),
"Tan(%f), expected %f, got %f",
INFINITY, NAN, result);
result = SDL_tan(-INFINITY);
SDLTest_AssertCheck(isnan(result),
"Tan(%f), expected %f, got %f",
-INFINITY, NAN, result);
return TEST_COMPLETED;
}
/**
* Input: NAN.
* Expected: NAN is returned.
*/
static int
tan_nanCase(void *args)
{
const double result = SDL_tan(NAN);
SDLTest_AssertCheck(isnan(result),
"Tan(%f), expected %f, got %f",
NAN, NAN, result);
return TEST_COMPLETED;
}
/**
* Inputs: +/-0.0.
* Expected: Zero is returned as-is.
*/
static int
tan_zeroCases(void *args)
{
const d_to_d regular_cases[] = {
{ -0.0, -0.0 },
{ 0.0, 0.0 }
};
return helper_dtod("Tan", SDL_tan, regular_cases, SDL_arraysize(regular_cases));
}
/**
* Inputs: Angles between 1/11 and 10/11 of Pi (positive and negative).
* Expected: The correct result is returned (+/-EPSILON).
* NOTE: +/-Pi/2 is intentionally avoided as it returns garbage values.
*/
static int
tan_precisionTest(void *args)
{
const d_to_d precision_cases[] = {
{ M_PI * 1.0 / 11.0, 0.2936264929 },
{ M_PI * 2.0 / 11.0, 0.6426609771 },
{ M_PI * 3.0 / 11.0, 1.1540615205 },
{ M_PI * 4.0 / 11.0, 2.1896945629 },
{ M_PI * 5.0 / 11.0, 6.9551527717 },
{ M_PI * 6.0 / 11.0, -6.9551527717 },
{ M_PI * 7.0 / 11.0, -2.1896945629 },
{ M_PI * 8.0 / 11.0, -1.1540615205 },
{ M_PI * 9.0 / 11.0, -0.6426609771 },
{ M_PI * 10.0 / 11.0, -0.2936264929 },
{ M_PI * -1.0 / 11.0, -0.2936264929 },
{ M_PI * -2.0 / 11.0, -0.6426609771 },
{ M_PI * -3.0 / 11.0, -1.1540615205 },
{ M_PI * -4.0 / 11.0, -2.1896945629 },
{ M_PI * -5.0 / 11.0, -6.9551527717 },
{ M_PI * -6.0 / 11.0, 6.9551527717 },
{ M_PI * -7.0 / 11.0, 2.1896945629 },
{ M_PI * -8.0 / 11.0, 1.1540615205 },
{ M_PI * -9.0 / 11.0, 0.6426609771 },
{ M_PI * -10.0 / 11.0, 0.2936264929 }
};
return helper_dtod_inexact("Tan", SDL_tan, precision_cases, SDL_arraysize(precision_cases));
}
/* SDL_acos tests functions */
/**
* Inputs: +/-1.0.
* Expected: 0.0 and Pi respectively.
*/
static int
acos_limitCases(void *args)
{
double result;
result = SDL_acos(1.0);
SDLTest_AssertCheck(0.0 == result,
"Acos(%f), expected %f, got %f",
1.0, 0.0, result);
result = SDL_acos(-1.0);
SDLTest_AssertCheck(M_PI == result,
"Acos(%f), expected %f, got %f",
-1.0, M_PI, result);
return TEST_COMPLETED;
}
/**
* Inputs: Values outside the domain of [-1, 1].
* Expected: NAN is returned.
*/
static int
acos_outOfDomainCases(void *args)
{
double result;
result = SDL_acos(1.1);
SDLTest_AssertCheck(isnan(result),
"Acos(%f), expected %f, got %f",
1.1, NAN, result);
result = SDL_acos(-1.1);
SDLTest_AssertCheck(isnan(result),
"Acos(%f), expected %f, got %f",
-1.1, NAN, result);
return TEST_COMPLETED;
}
/**
* Input: NAN.
* Expected: NAN is returned.
*/
static int
acos_nanCase(void *args)
{
const double result = SDL_acos(NAN);
SDLTest_AssertCheck(isnan(result),
"Acos(%f), expected %f, got %f",
NAN, NAN, result);
return TEST_COMPLETED;
}
/**
* Inputs: Values between -0.9 and 0.9 with steps of 0.1.
* Expected: The correct result is returned (+/-EPSILON).
*/
static int
acos_precisionTest(void *args)
{
const d_to_d precision_cases[] = {
{ 0.9, 0.4510268117 },
{ 0.8, 0.6435011087 },
{ 0.7, 0.7953988301 },
{ 0.6, 0.9272952180 },
{ 0.5, 1.0471975511 },
{ 0.4, 1.1592794807 },
{ 0.3, 1.2661036727 },
{ 0.2, 1.3694384060 },
{ 0.1, 1.4706289056 },
{ 0.0, 1.5707963267 },
{ -0.0, 1.5707963267 },
{ -0.1, 1.6709637479 },
{ -0.2, 1.7721542475 },
{ -0.3, 1.8754889808 },
{ -0.4, 1.9823131728 },
{ -0.5, 2.0943951023 },
{ -0.6, 2.2142974355 },
{ -0.7, 2.3461938234 },
{ -0.8, 2.4980915447 },
{ -0.9, 2.6905658417 },
};
return helper_dtod_inexact("Acos", SDL_acos, precision_cases, SDL_arraysize(precision_cases));
}
/* SDL_asin tests functions */
/**
* Inputs: +/-1.0.
* Expected: +/-Pi/2 is returned.
*/
static int
asin_limitCases(void *args)
{
double result;
result = SDL_asin(1.0);
SDLTest_AssertCheck(M_PI / 2.0 == result,
"Asin(%f), expected %f, got %f",
1.0, M_PI / 2.0, result);
result = SDL_asin(-1.0);
SDLTest_AssertCheck(-M_PI / 2.0 == result,
"Asin(%f), expected %f, got %f",
-1.0, -M_PI / 2.0, result);
return TEST_COMPLETED;
}
/**
* Inputs: Values outside the domain of [-1, 1].
* Expected: NAN is returned.
*/
static int
asin_outOfDomainCases(void *args)
{
double result;
result = SDL_asin(1.1);
SDLTest_AssertCheck(isnan(result),
"Asin(%f), expected %f, got %f",
1.1, NAN, result);
result = SDL_asin(-1.1);
SDLTest_AssertCheck(isnan(result),
"Asin(%f), expected %f, got %f",
-1.1, NAN, result);
return TEST_COMPLETED;
}
/**
* Input: NAN.
* Expected: NAN is returned.
*/
static int
asin_nanCase(void *args)
{
const double result = SDL_asin(NAN);
SDLTest_AssertCheck(isnan(result),
"Asin(%f), expected %f, got %f",
NAN, NAN, result);
return TEST_COMPLETED;
}
/**
* Inputs: Values between -0.9 and 0.9 with steps of 0.1.
* Expected: The correct result is returned (+/-EPSILON).
*/
static int
asin_precisionTest(void *args)
{
const d_to_d precision_cases[] = {
{ 0.9, 1.1197695149 },
{ 0.8, 0.9272952180 },
{ 0.7, 0.7753974966 },
{ 0.6, 0.6435011087 },
{ 0.5, 0.5235987755 },
{ 0.4, 0.4115168460 },
{ 0.3, 0.3046926540 },
{ 0.2, 0.2013579207 },
{ 0.1, 0.1001674211 },
{ 0.0, 0.0 },
{ -0.0, -0.0 },
{ -0.1, -0.1001674211 },
{ -0.2, -0.2013579207 },
{ -0.3, -0.3046926540 },
{ -0.4, -0.4115168460 },
{ -0.5, -0.5235987755 },
{ -0.6, -0.6435011087 },
{ -0.7, -0.7753974966 },
{ -0.8, -0.9272952180 },
{ -0.9, -1.1197695149 }
};
return helper_dtod_inexact("Asin", SDL_asin, precision_cases, SDL_arraysize(precision_cases));
}
/* SDL_atan tests functions */
/**
* Inputs: +/-Infinity.
* Expected: +/-Pi/2 is returned.
*/
static int
atan_limitCases(void *args)
{
double result;
result = SDL_atan(INFINITY);
SDLTest_AssertCheck((M_PI / 2.0) - EPSILON <= result &&
result <= (M_PI / 2.0) + EPSILON,
"Atan(%f), expected %f, got %f",
INFINITY, M_PI / 2.0, result);
result = SDL_atan(-INFINITY);
SDLTest_AssertCheck((-M_PI / 2.0) - EPSILON <= result &&
result <= (-M_PI / 2.0) + EPSILON,
"Atan(%f), expected %f, got %f",
-INFINITY, -M_PI / 2.0, result);
return TEST_COMPLETED;
}
/**
* Inputs: +/-0.0.
* Expected: Zero is returned as-is.
*/
static int
atan_zeroCases(void *args)
{
double result;
result = SDL_atan(0.0);
SDLTest_AssertCheck(0.0 == result,
"Atan(%f), expected %f, got %f",
0.0, 0.0, result);
result = SDL_atan(-0.0);
SDLTest_AssertCheck(-0.0 == result,
"Atan(%f), expected %f, got %f",
-0.0, -0.0, result);
return TEST_COMPLETED;
}
/**
* Input: NAN.
* Expected: NAN is returned.
*/
static int
atan_nanCase(void *args)
{
const double result = SDL_atan(NAN);
SDLTest_AssertCheck(isnan(result),
"Atan(%f), expected %f, got %f",
NAN, NAN, result);
return TEST_COMPLETED;
}
/**
* Inputs: Values corresponding to angles between 9Pi/20 and -9Pi/20 with steps of Pi/20.
* Expected: The correct result is returned (+/-EPSILON).
*/
static int
atan_precisionTest(void *args)
{
const d_to_d precision_cases[] = {
{ 6.313751514675041, 1.4137166941 },
{ 3.0776835371752527, 1.2566370614 },
{ 1.9626105055051504, 1.0995574287 },
{ 1.3763819204711734, 0.9424777960 },
{ 1.0, 0.7853981633 },
{ 0.7265425280053609, 0.6283185307 },
{ 0.5095254494944288, 0.4712388980 },
{ 0.3249196962329063, 0.3141592653 },
{ 0.15838444032453627, 0.1570796326 },
{ -0.15838444032453627, -0.1570796326 },
{ -0.3249196962329063, -0.3141592653 },
{ -0.5095254494944288, -0.4712388980 },
{ -0.7265425280053609, -0.6283185307 },
{ -1.0, -0.7853981633 },
{ -1.3763819204711734, -0.9424777960 },
{ -1.9626105055051504, -1.0995574287 },
{ -3.0776835371752527, -1.2566370614 },
{ -6.313751514675041, -1.4137166941 },
};
return helper_dtod_inexact("Atan", SDL_atan, precision_cases, SDL_arraysize(precision_cases));
}
/* SDL_atan2 tests functions */
/* Zero cases */
/**
* Inputs: (+/-0.0, +/-0.0).
* Expected:
* - Zero if the second argument is positive zero.
* - Pi if the second argument is negative zero.
* - The sign is inherited from the first argument.
*/
static int
atan2_bothZeroCases(void *args)
{
const dd_to_d cases[] = {
{ 0.0, 0.0, 0.0 },
{ -0.0, 0.0, -0.0 },
{ 0.0, -0.0, M_PI },
{ -0.0, -0.0, -M_PI },
};
return helper_ddtod("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases));
}
/**
* Inputs: (+/-0.0, +/-1.0).
* Expected:
* - Zero if the second argument is positive.
* - Pi if the second argument is negative.
* - The sign is inherited from the first argument.
*/
static int
atan2_yZeroCases(void *args)
{
const dd_to_d cases[] = {
{ 0.0, 1.0, 0.0 },
{ 0.0, -1.0, M_PI },
{ -0.0, 1.0, -0.0 },
{ -0.0, -1.0, -M_PI }
};
return helper_ddtod("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases));
}
/**
* Inputs: (+/-1.0, +/-0.0).
* Expected: Pi/2 with the sign of the first argument.
*/
static int
atan2_xZeroCases(void *args)
{
const dd_to_d cases[] = {
{ 1.0, 0.0, M_PI / 2.0 },
{ -1.0, 0.0, -M_PI / 2.0 },
{ 1.0, -0.0, M_PI / 2.0 },
{ -1.0, -0.0, -M_PI / 2.0 }
};
return helper_ddtod("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases));
}
/* Infinity cases */
/**
* Inputs: (+/-Infinity, +/-Infinity).
* Expected:
* - (+int, +inf) -> Pi/4,
* - (+int, -inf) -> 3Pi/4,
* - (-int, +inf) -> -Pi/4,
* - (-int, -inf) -> Pi.
*/
static int
atan2_bothInfCases(void *args)
{
double result;
result = SDL_atan2(INFINITY, INFINITY);
SDLTest_AssertCheck(M_PI / 4.0 == result,
"Atan2(%f,%f), expected %f, got %f",
INFINITY, INFINITY, M_PI / 4.0, result);
result = SDL_atan2(INFINITY, -INFINITY);
SDLTest_AssertCheck(3.0 * M_PI / 4.0 == result,
"Atan2(%f,%f), expected %f, got %f",
INFINITY, -INFINITY, 3.0 * M_PI / 4.0, result);
result = SDL_atan2(-INFINITY, INFINITY);
SDLTest_AssertCheck(-M_PI / 4.0 == result,
"Atan2(%f,%f), expected %f, got %f",
-INFINITY, INFINITY, -M_PI / 4.0, result);
result = SDL_atan2(-INFINITY, -INFINITY);
SDLTest_AssertCheck(-3.0 * M_PI / 4.0 == result,
"Atan2(%f,%f), expected %f, got %f",
-INFINITY, -INFINITY, -3.0 * M_PI / 4.0, result);
return TEST_COMPLETED;
}
/**
* Inputs: (+/-Infinity, +/-1.0).
* Expected: Pi/2 with the sign of the first argument.
*/
static int
atan2_yInfCases(void *args)
{
double result;
result = SDL_atan2(INFINITY, 1.0);
SDLTest_AssertCheck(M_PI / 2.0 == result,
"Atan2(%f,%f), expected %f, got %f",
INFINITY, 1.0, M_PI / 2.0, result);
result = SDL_atan2(INFINITY, -1.0);
SDLTest_AssertCheck(M_PI / 2.0 == result,
"Atan2(%f,%f), expected %f, got %f",
INFINITY, -1.0, M_PI / 2.0, result);
result = SDL_atan2(-INFINITY, 1.0);
SDLTest_AssertCheck(-M_PI / 2.0 == result,
"Atan2(%f,%f), expected %f, got %f",
-INFINITY, 1.0, -M_PI / 2.0, result);
result = SDL_atan2(-INFINITY, -1.0);
SDLTest_AssertCheck(-M_PI / 2.0 == result,
"Atan2(%f,%f), expected %f, got %f",
-INFINITY, -1.0, -M_PI / 2.0, result);
return TEST_COMPLETED;
}
/**
* Inputs: (+/-1.0, +/-Infinity).
* Expected:
* - (+/-1.0, +inf) -> +/-0.0
* - (+/-1.0, -inf) -> +/-Pi.
*/
static int
atan2_xInfCases(void *args)
{
double result;
result = SDL_atan2(1.0, INFINITY);
SDLTest_AssertCheck(0.0 == result,
"Atan2(%f,%f), expected %f, got %f",
1.0, INFINITY, 0.0, result);
result = SDL_atan2(-1.0, INFINITY);
SDLTest_AssertCheck(-0.0 == result,
"Atan2(%f,%f), expected %f, got %f",
-1.0, INFINITY, -0.0, result);
result = SDL_atan2(1.0, -INFINITY);
SDLTest_AssertCheck(M_PI == result,
"Atan2(%f,%f), expected %f, got %f",
1.0, -INFINITY, M_PI, result);
result = SDL_atan2(-1.0, -INFINITY);
SDLTest_AssertCheck(-M_PI == result,
"Atan2(%f,%f), expected %f, got %f",
-1.0, -INFINITY, -M_PI, result);
return TEST_COMPLETED;
}
/* Miscelanious cases */
/**
* Inputs: NAN as either or both of the arguments.
* Expected: NAN is returned.
*/
static int
atan2_nanCases(void *args)
{
double result;
result = SDL_atan2(NAN, NAN);
SDLTest_AssertCheck(isnan(result),
"Atan2(%f,%f), expected %f, got %f",
NAN, NAN, NAN, result);
result = SDL_atan2(NAN, 1.0);
SDLTest_AssertCheck(isnan(result),
"Atan2(%f,%f), expected %f, got %f",
NAN, 1.0, NAN, result);
result = SDL_atan2(1.0, NAN);
SDLTest_AssertCheck(isnan(result),
"Atan2(%f,%f), expected %f, got %f",
1.0, NAN, NAN, result);
return TEST_COMPLETED;
}
/**
* Inputs: (y, x) with x and y positive.
* Expected: Angle in the top right quadrant.
*/
static int
atan2_topRightQuadrantTest(void *args)
{
const dd_to_d top_right_cases[] = {
{ 1.0, 1.0, M_PI / 4.0 },
{ SQRT3, 3.0, M_PI / 6.0 },
{ SQRT3, 1.0, M_PI / 3.0 }
};
return helper_ddtod_inexact("SDL_atan2", SDL_atan2, top_right_cases, SDL_arraysize(top_right_cases));
}
/**
* Inputs: (y, x) with x negative and y positive.
* Expected: Angle in the top left quadrant.
*/
static int
atan2_topLeftQuadrantTest(void *args)
{
const dd_to_d top_left_cases[] = {
{ 1.0, -1.0, 3.0 * M_PI / 4.0 },
{ SQRT3, -3.0, 5.0 * M_PI / 6.0 },
{ SQRT3, -1.0, 2.0 * M_PI / 3.0 }
};
return helper_ddtod_inexact("SDL_atan2", SDL_atan2, top_left_cases, SDL_arraysize(top_left_cases));
}
/**
* Inputs: (y, x) with x positive and y negative.
* Expected: Angle in the bottom right quadrant.
*/
static int
atan2_bottomRightQuadrantTest(void *args)
{
const dd_to_d bottom_right_cases[] = {
{ -1.0, 1.0, -M_PI / 4 },
{ -SQRT3, 3.0, -M_PI / 6.0 },
{ -SQRT3, 1.0, -M_PI / 3.0 }
};
return helper_ddtod_inexact("SDL_atan2", SDL_atan2, bottom_right_cases, SDL_arraysize(bottom_right_cases));
}
/**
* Inputs: (y, x) with x and y negative.
* Expected: Angle in the bottom left quadrant.
*/
static int
atan2_bottomLeftQuadrantTest(void *args)
{
const dd_to_d bottom_left_cases[] = {
{ -1.0, -1.0, -3.0 * M_PI / 4.0 },
{ -SQRT3, -3.0, -5.0 * M_PI / 6.0 },
{ -SQRT3, -1.0, -4.0 * M_PI / 6.0 }
};
return helper_ddtod_inexact("SDL_atan2", SDL_atan2, bottom_left_cases, SDL_arraysize(bottom_left_cases));
}
/* ================= Test References ================== */
/* SDL_floor test cases */
static const SDLTest_TestCaseReference floorTestInf = {
(SDLTest_TestCaseFp)floor_infCases, "floor_infCases",
"Checks positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference floorTestZero = {
(SDLTest_TestCaseFp)floor_zeroCases, "floor_zeroCases",
"Checks positive and negative zero", TEST_ENABLED
};
static const SDLTest_TestCaseReference floorTestNan = {
(SDLTest_TestCaseFp)floor_nanCase, "floor_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference floorTestRound = {
(SDLTest_TestCaseFp)floor_roundNumbersCases, "floor_roundNumberCases",
"Checks a set of integral values", TEST_ENABLED
};
static const SDLTest_TestCaseReference floorTestFraction = {
(SDLTest_TestCaseFp)floor_fractionCases, "floor_fractionCases",
"Checks a set of fractions", TEST_ENABLED
};
static const SDLTest_TestCaseReference floorTestRange = {
(SDLTest_TestCaseFp)floor_rangeTest, "floor_rangeTest",
"Checks a range of positive integer", TEST_ENABLED
};
/* SDL_ceil test cases */
static const SDLTest_TestCaseReference ceilTestInf = {
(SDLTest_TestCaseFp)ceil_infCases, "ceil_infCases",
"Checks positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference ceilTestZero = {
(SDLTest_TestCaseFp)ceil_zeroCases, "ceil_zeroCases",
"Checks positive and negative zero", TEST_ENABLED
};
static const SDLTest_TestCaseReference ceilTestNan = {
(SDLTest_TestCaseFp)ceil_nanCase, "ceil_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference ceilTestRound = {
(SDLTest_TestCaseFp)ceil_roundNumbersCases, "ceil_roundNumberCases",
"Checks a set of integral values", TEST_ENABLED
};
static const SDLTest_TestCaseReference ceilTestFraction = {
(SDLTest_TestCaseFp)ceil_fractionCases, "ceil_fractionCases",
"Checks a set of fractions", TEST_ENABLED
};
static const SDLTest_TestCaseReference ceilTestRange = {
(SDLTest_TestCaseFp)ceil_rangeTest, "ceil_rangeTest",
"Checks a range of positive integer", TEST_ENABLED
};
/* SDL_trunc test cases */
static const SDLTest_TestCaseReference truncTestInf = {
(SDLTest_TestCaseFp)trunc_infCases, "trunc_infCases",
"Checks positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference truncTestZero = {
(SDLTest_TestCaseFp)trunc_zeroCases, "trunc_zeroCases",
"Checks positive and negative zero", TEST_ENABLED
};
static const SDLTest_TestCaseReference truncTestNan = {
(SDLTest_TestCaseFp)trunc_nanCase, "trunc_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference truncTestRound = {
(SDLTest_TestCaseFp)trunc_roundNumbersCases, "trunc_roundNumberCases",
"Checks a set of integral values", TEST_ENABLED
};
static const SDLTest_TestCaseReference truncTestFraction = {
(SDLTest_TestCaseFp)trunc_fractionCases, "trunc_fractionCases",
"Checks a set of fractions", TEST_ENABLED
};
static const SDLTest_TestCaseReference truncTestRange = {
(SDLTest_TestCaseFp)trunc_rangeTest, "trunc_rangeTest",
"Checks a range of positive integer", TEST_ENABLED
};
/* SDL_round test cases */
static const SDLTest_TestCaseReference roundTestInf = {
(SDLTest_TestCaseFp)round_infCases, "round_infCases",
"Checks positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference roundTestZero = {
(SDLTest_TestCaseFp)round_zeroCases, "round_zeroCases",
"Checks positive and negative zero", TEST_ENABLED
};
static const SDLTest_TestCaseReference roundTestNan = {
(SDLTest_TestCaseFp)round_nanCase, "round_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference roundTestRound = {
(SDLTest_TestCaseFp)round_roundNumbersCases, "round_roundNumberCases",
"Checks a set of integral values", TEST_ENABLED
};
static const SDLTest_TestCaseReference roundTestFraction = {
(SDLTest_TestCaseFp)round_fractionCases, "round_fractionCases",
"Checks a set of fractions", TEST_ENABLED
};
static const SDLTest_TestCaseReference roundTestRange = {
(SDLTest_TestCaseFp)round_rangeTest, "round_rangeTest",
"Checks a range of positive integer", TEST_ENABLED
};
/* SDL_fabs test cases */
static const SDLTest_TestCaseReference fabsTestInf = {
(SDLTest_TestCaseFp)fabs_infCases, "fabs_infCases",
"Checks positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference fabsTestZero = {
(SDLTest_TestCaseFp)fabs_zeroCases, "fabs_zeroCases",
"Checks positive and negative zero", TEST_ENABLED
};
static const SDLTest_TestCaseReference fabsTestNan = {
(SDLTest_TestCaseFp)fabs_nanCase, "fabs_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference fabsTestRange = {
(SDLTest_TestCaseFp)fabs_rangeTest, "fabs_rangeTest",
"Checks a range of positive integer", TEST_ENABLED
};
/* SDL_copysign test cases */
static const SDLTest_TestCaseReference copysignTestInf = {
(SDLTest_TestCaseFp)copysign_infCases, "copysign_infCases",
"Checks positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference copysignTestZero = {
(SDLTest_TestCaseFp)copysign_zeroCases, "copysign_zeroCases",
"Checks positive and negative zero", TEST_ENABLED
};
static const SDLTest_TestCaseReference copysignTestNan = {
(SDLTest_TestCaseFp)copysign_nanCases, "copysign_nanCases",
"Checks NANs", TEST_ENABLED
};
static const SDLTest_TestCaseReference copysignTestRange = {
(SDLTest_TestCaseFp)copysign_rangeTest, "copysign_rangeTest",
"Checks a range of positive integer", TEST_ENABLED
};
/* SDL_fmod test cases */
static const SDLTest_TestCaseReference fmodTestDivOfInf = {
(SDLTest_TestCaseFp)fmod_divOfInfCases, "fmod_divOfInfCases",
"Checks division of positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference fmodTestDivByInf = {
(SDLTest_TestCaseFp)fmod_divByInfCases, "fmod_divByInfCases",
"Checks division by positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference fmodTestDivOfZero = {
(SDLTest_TestCaseFp)fmod_divOfZeroCases, "fmod_divOfZeroCases",
"Checks division of positive and negative zero", TEST_ENABLED
};
static const SDLTest_TestCaseReference fmodTestDivByZero = {
(SDLTest_TestCaseFp)fmod_divByZeroCases, "fmod_divByZeroCases",
"Checks division by positive and negative zero", TEST_ENABLED
};
static const SDLTest_TestCaseReference fmodTestNan = {
(SDLTest_TestCaseFp)fmod_nanCases, "fmod_nanCases",
"Checks NANs", TEST_ENABLED
};
static const SDLTest_TestCaseReference fmodTestRegular = {
(SDLTest_TestCaseFp)fmod_regularCases, "fmod_regularCases",
"Checks a set of regular values", TEST_ENABLED
};
static const SDLTest_TestCaseReference fmodTestRange = {
(SDLTest_TestCaseFp)fmod_rangeTest, "fmod_rangeTest",
"Checks a range of positive integer", TEST_ENABLED
};
/* SDL_exp test cases */
static const SDLTest_TestCaseReference expTestInf = {
(SDLTest_TestCaseFp)exp_infCases, "exp_infCases",
"Checks positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference expTestZero = {
(SDLTest_TestCaseFp)exp_zeroCases, "exp_zeroCases",
"Checks for positive and negative zero", TEST_ENABLED
};
static const SDLTest_TestCaseReference expTestOverflow = {
(SDLTest_TestCaseFp)exp_overflowCase, "exp_overflowCase",
"Checks for overflow", TEST_ENABLED
};
static const SDLTest_TestCaseReference expTestBase = {
(SDLTest_TestCaseFp)exp_baseCase, "exp_baseCase",
"Checks the base case", TEST_ENABLED
};
static const SDLTest_TestCaseReference expTestRegular = {
(SDLTest_TestCaseFp)exp_regularCases, "exp_regularCases",
"Checks a set of regular values", TEST_ENABLED
};
/* SDL_log test cases */
static const SDLTest_TestCaseReference logTestLimit = {
(SDLTest_TestCaseFp)log_limitCases, "log_limitCases",
"Checks the domain limits", TEST_ENABLED
};
static const SDLTest_TestCaseReference logTestNan = {
(SDLTest_TestCaseFp)log_nanCases, "log_nanCases",
"Checks NAN and negative values", TEST_ENABLED
};
static const SDLTest_TestCaseReference logTestBase = {
(SDLTest_TestCaseFp)log_baseCases, "log_baseCases",
"Checks the base cases", TEST_ENABLED
};
static const SDLTest_TestCaseReference logTestRegular = {
(SDLTest_TestCaseFp)log_regularCases, "log_regularCases",
"Checks a set of regular values", TEST_ENABLED
};
/* SDL_log10 test cases */
static const SDLTest_TestCaseReference log10TestLimit = {
(SDLTest_TestCaseFp)log10_limitCases, "log10_limitCases",
"Checks the domain limits", TEST_ENABLED
};
static const SDLTest_TestCaseReference log10TestNan = {
(SDLTest_TestCaseFp)log10_nanCases, "log10_nanCases",
"Checks NAN and negative values", TEST_ENABLED
};
static const SDLTest_TestCaseReference log10TestBase = {
(SDLTest_TestCaseFp)log10_baseCases, "log10_baseCases",
"Checks the base cases", TEST_ENABLED
};
static const SDLTest_TestCaseReference log10TestRegular = {
(SDLTest_TestCaseFp)log10_regularCases, "log10_regularCases",
"Checks a set of regular values", TEST_ENABLED
};
/* SDL_pow test cases */
static const SDLTest_TestCaseReference powTestExpInf1 = {
(SDLTest_TestCaseFp)pow_baseNOneExpInfCases, "pow_baseNOneExpInfCases",
"Checks for pow(-1, +/-inf)", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestExpInf2 = {
(SDLTest_TestCaseFp)pow_baseZeroExpNInfCases, "pow_baseZeroExpNInfCases",
"Checks for pow(+/-0, -inf)", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestExpInf3 = {
(SDLTest_TestCaseFp)pow_expInfCases, "pow_expInfCases",
"Checks for pow(x, +/-inf)", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestBaseInf1 = {
(SDLTest_TestCaseFp)pow_basePInfCases, "pow_basePInfCases",
"Checks for pow(inf, x)", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestBaseInf2 = {
(SDLTest_TestCaseFp)pow_baseNInfCases, "pow_baseNInfCases",
"Checks for pow(-inf, x)", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestNan1 = {
(SDLTest_TestCaseFp)pow_badOperationCase, "pow_badOperationCase",
"Checks for negative finite base and non-integer finite exponent", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestNan2 = {
(SDLTest_TestCaseFp)pow_base1ExpNanCase, "pow_base1ExpNanCase",
"Checks for pow(1.0, NAN)", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestNan3 = {
(SDLTest_TestCaseFp)pow_baseNanExp0Cases, "pow_baseNanExp0Cases",
"Checks for pow(NAN, +/-0)", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestNan4 = {
(SDLTest_TestCaseFp)pow_nanArgsCases, "pow_nanArgsCases",
"Checks for pow(x, y) with either x or y being NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestZero1 = {
(SDLTest_TestCaseFp)pow_baseNZeroExpOddCases, "pow_baseNZeroExpOddCases",
"Checks for pow(-0.0, y), with y an odd integer.", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestZero2 = {
(SDLTest_TestCaseFp)pow_basePZeroExpOddCases, "pow_basePZeroExpOddCases",
"Checks for pow(0.0, y), with y an odd integer.", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestZero3 = {
(SDLTest_TestCaseFp)pow_baseNZeroCases, "pow_baseNZeroCases",
"Checks for pow(-0.0, y), with y finite and even or non-integer number", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestZero4 = {
(SDLTest_TestCaseFp)pow_basePZeroCases, "pow_basePZeroCases",
"Checks for pow(0.0, y), with y finite and even or non-integer number", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestRegular = {
(SDLTest_TestCaseFp)pow_regularCases, "pow_regularCases",
"Checks a set of regular values", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestPowOf2 = {
(SDLTest_TestCaseFp)pow_powerOfTwo, "pow_powerOfTwo",
"Checks the powers of two from 1 to 8", TEST_ENABLED
};
static const SDLTest_TestCaseReference powTestRange = {
(SDLTest_TestCaseFp)pow_rangeTest, "pow_rangeTest",
"Checks a range of positive integer to the power of 0", TEST_ENABLED
};
/* SDL_sqrt test cases */
static const SDLTest_TestCaseReference sqrtTestInf = {
(SDLTest_TestCaseFp)sqrt_infCase, "sqrt_infCase",
"Checks positive infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference sqrtTestNan = {
(SDLTest_TestCaseFp)sqrt_nanCase, "sqrt_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference sqrtTestDomain = {
(SDLTest_TestCaseFp)sqrt_outOfDomainCases, "sqrt_outOfDomainCases",
"Checks for values out of the domain", TEST_ENABLED
};
static const SDLTest_TestCaseReference sqrtTestBase = {
(SDLTest_TestCaseFp)sqrt_baseCases, "sqrt_baseCases",
"Checks the base cases", TEST_ENABLED
};
static const SDLTest_TestCaseReference sqrtTestRegular = {
(SDLTest_TestCaseFp)sqrt_regularCases, "sqrt_regularCases",
"Checks a set of regular values", TEST_ENABLED
};
/* SDL_scalbn test cases */
static const SDLTest_TestCaseReference scalbnTestInf = {
(SDLTest_TestCaseFp)scalbn_infCases, "scalbn_infCases",
"Checks positive and negative infinity arg", TEST_ENABLED
};
static const SDLTest_TestCaseReference scalbnTestBaseZero = {
(SDLTest_TestCaseFp)scalbn_baseZeroCases, "scalbn_baseZeroCases",
"Checks for positive and negative zero arg", TEST_ENABLED
};
static const SDLTest_TestCaseReference scalbnTestExpZero = {
(SDLTest_TestCaseFp)scalbn_expZeroCase, "scalbn_expZeroCase",
"Checks for zero exp", TEST_ENABLED
};
static const SDLTest_TestCaseReference scalbnTestNan = {
(SDLTest_TestCaseFp)scalbn_nanCase, "scalbn_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference scalbnTestRegular = {
(SDLTest_TestCaseFp)scalbn_regularCases, "scalbn_regularCases",
"Checks a set of regular cases", TEST_ENABLED
};
/* SDL_cos test cases */
static const SDLTest_TestCaseReference cosTestInf = {
(SDLTest_TestCaseFp)cos_infCases, "cos_infCases",
"Checks for positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference cosTestNan = {
(SDLTest_TestCaseFp)cos_nanCase, "cos_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference cosTestRegular = {
(SDLTest_TestCaseFp)cos_regularCases, "cos_regularCases",
"Checks a set of regular cases", TEST_ENABLED
};
static const SDLTest_TestCaseReference cosTestPrecision = {
(SDLTest_TestCaseFp)cos_precisionTest, "cos_precisionTest",
"Checks cosine precision", TEST_ENABLED
};
static const SDLTest_TestCaseReference cosTestRange = {
(SDLTest_TestCaseFp)cos_rangeTest, "cos_rangeTest",
"Checks a range of positive integer", TEST_ENABLED
};
/* SDL_sin test cases */
static const SDLTest_TestCaseReference sinTestInf = {
(SDLTest_TestCaseFp)sin_infCases, "sin_infCases",
"Checks for positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference sinTestNan = {
(SDLTest_TestCaseFp)sin_nanCase, "sin_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference sinTestRegular = {
(SDLTest_TestCaseFp)sin_regularCases, "sin_regularCases",
"Checks a set of regular cases", TEST_ENABLED
};
static const SDLTest_TestCaseReference sinTestPrecision = {
(SDLTest_TestCaseFp)sin_precisionTest, "sin_precisionTest",
"Checks sine precision", TEST_ENABLED
};
static const SDLTest_TestCaseReference sinTestRange = {
(SDLTest_TestCaseFp)sin_rangeTest, "sin_rangeTest",
"Checks a range of positive integer", TEST_ENABLED
};
/* SDL_tan test cases */
static const SDLTest_TestCaseReference tanTestInf = {
(SDLTest_TestCaseFp)tan_infCases, "tan_infCases",
"Checks for positive and negative infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference tanTestNan = {
(SDLTest_TestCaseFp)tan_nanCase, "tan_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference tanTestZero = {
(SDLTest_TestCaseFp)tan_zeroCases, "tan_zeroCases",
"Checks a set of regular cases", TEST_ENABLED
};
static const SDLTest_TestCaseReference tanTestPrecision = {
(SDLTest_TestCaseFp)tan_precisionTest, "tan_precisionTest",
"Checks tangent precision", TEST_ENABLED
};
/* SDL_acos test cases */
static const SDLTest_TestCaseReference acosTestLimit = {
(SDLTest_TestCaseFp)acos_limitCases, "acos_limitCases",
"Checks the edge of the domain (+/-1)", TEST_ENABLED
};
static const SDLTest_TestCaseReference acosTestOutOfDomain = {
(SDLTest_TestCaseFp)acos_outOfDomainCases, "acos_outOfDomainCases",
"Checks values outside the domain", TEST_ENABLED
};
static const SDLTest_TestCaseReference acosTestNan = {
(SDLTest_TestCaseFp)acos_nanCase, "acos_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference acosTestPrecision = {
(SDLTest_TestCaseFp)acos_precisionTest, "acos_precisionTest",
"Checks acos precision", TEST_ENABLED
};
/* SDL_asin test cases */
static const SDLTest_TestCaseReference asinTestLimit = {
(SDLTest_TestCaseFp)asin_limitCases, "asin_limitCases",
"Checks the edge of the domain (+/-1)", TEST_ENABLED
};
static const SDLTest_TestCaseReference asinTestOutOfDomain = {
(SDLTest_TestCaseFp)asin_outOfDomainCases, "asin_outOfDomainCases",
"Checks values outside the domain", TEST_ENABLED
};
static const SDLTest_TestCaseReference asinTestNan = {
(SDLTest_TestCaseFp)asin_nanCase, "asin_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference asinTestPrecision = {
(SDLTest_TestCaseFp)asin_precisionTest, "asin_precisionTest",
"Checks asin precision", TEST_ENABLED
};
/* SDL_atan test cases */
static const SDLTest_TestCaseReference atanTestLimit = {
(SDLTest_TestCaseFp)atan_limitCases, "atan_limitCases",
"Checks the edge of the domain (+/-Infinity)", TEST_ENABLED
};
static const SDLTest_TestCaseReference atanTestZero = {
(SDLTest_TestCaseFp)atan_zeroCases, "atan_zeroCases",
"Checks for positive and negative zero", TEST_ENABLED
};
static const SDLTest_TestCaseReference atanTestNan = {
(SDLTest_TestCaseFp)atan_nanCase, "atan_nanCase",
"Checks NAN", TEST_ENABLED
};
static const SDLTest_TestCaseReference atanTestPrecision = {
(SDLTest_TestCaseFp)atan_precisionTest, "atan_precisionTest",
"Checks atan precision", TEST_ENABLED
};
/* SDL_atan2 test cases */
static const SDLTest_TestCaseReference atan2TestZero1 = {
(SDLTest_TestCaseFp)atan2_bothZeroCases, "atan2_bothZeroCases",
"Checks for both arguments being zero", TEST_ENABLED
};
static const SDLTest_TestCaseReference atan2TestZero2 = {
(SDLTest_TestCaseFp)atan2_yZeroCases, "atan2_yZeroCases",
"Checks for y=0", TEST_ENABLED
};
static const SDLTest_TestCaseReference atan2TestZero3 = {
(SDLTest_TestCaseFp)atan2_xZeroCases, "atan2_xZeroCases",
"Checks for x=0", TEST_ENABLED
};
static const SDLTest_TestCaseReference atan2TestInf1 = {
(SDLTest_TestCaseFp)atan2_bothInfCases, "atan2_bothInfCases",
"Checks for both arguments being infinity", TEST_ENABLED
};
static const SDLTest_TestCaseReference atan2TestInf2 = {
(SDLTest_TestCaseFp)atan2_yInfCases, "atan2_yInfCases",
"Checks for y=0", TEST_ENABLED
};
static const SDLTest_TestCaseReference atan2TestInf3 = {
(SDLTest_TestCaseFp)atan2_xInfCases, "atan2_xInfCases",
"Checks for x=0", TEST_ENABLED
};
static const SDLTest_TestCaseReference atan2TestNan = {
(SDLTest_TestCaseFp)atan2_nanCases, "atan2_nanCases",
"Checks NANs", TEST_ENABLED
};
static const SDLTest_TestCaseReference atan2TestQuadrantTopRight = {
(SDLTest_TestCaseFp)atan2_topRightQuadrantTest, "atan2_topRightQuadrantTest",
"Checks values in the top right quadrant", TEST_ENABLED
};
static const SDLTest_TestCaseReference atan2TestQuadrantTopLeft = {
(SDLTest_TestCaseFp)atan2_topLeftQuadrantTest, "atan2_topLeftQuadrantTest",
"Checks values in the top left quadrant", TEST_ENABLED
};
static const SDLTest_TestCaseReference atan2TestQuadrantBottomRight = {
(SDLTest_TestCaseFp)atan2_bottomRightQuadrantTest, "atan2_bottomRightQuadrantTest",
"Checks values in the bottom right quadrant", TEST_ENABLED
};
static const SDLTest_TestCaseReference atan2TestQuadrantBottomLeft = {
(SDLTest_TestCaseFp)atan2_bottomLeftQuadrantTest, "atan2_bottomLeftQuadrantTest",
"Checks values in the bottom left quadrant", TEST_ENABLED
};
static const SDLTest_TestCaseReference *mathTests[] = {
&floorTestInf, &floorTestZero, &floorTestNan,
&floorTestRound, &floorTestFraction, &floorTestRange,
&ceilTestInf, &ceilTestZero, &ceilTestNan,
&ceilTestRound, &ceilTestFraction, &ceilTestRange,
&truncTestInf, &truncTestZero, &truncTestNan,
&truncTestRound, &truncTestFraction, &truncTestRange,
&roundTestInf, &roundTestZero, &roundTestNan,
&roundTestRound, &roundTestFraction, &roundTestRange,
&fabsTestInf, &fabsTestZero, &fabsTestNan, &fabsTestRange,
&copysignTestInf, &copysignTestZero, &copysignTestNan, &copysignTestRange,
&fmodTestDivOfInf, &fmodTestDivByInf, &fmodTestDivOfZero, &fmodTestDivByZero,
&fmodTestNan, &fmodTestRegular, &fmodTestRange,
&expTestInf, &expTestZero, &expTestOverflow,
&expTestBase, &expTestRegular,
&logTestLimit, &logTestNan,
&logTestBase, &logTestRegular,
&log10TestLimit, &log10TestNan,
&log10TestBase, &log10TestRegular,
&powTestExpInf1, &powTestExpInf2, &powTestExpInf3,
&powTestBaseInf1, &powTestBaseInf2,
&powTestNan1, &powTestNan2, &powTestNan3, &powTestNan4,
&powTestZero1, &powTestZero2, &powTestZero3, &powTestZero4,
&powTestRegular, &powTestPowOf2, &powTestRange,
&sqrtTestInf, &sqrtTestNan, &sqrtTestDomain,
&sqrtTestBase, &sqrtTestRegular,
&scalbnTestInf, &scalbnTestBaseZero, &scalbnTestExpZero,
&scalbnTestNan, &scalbnTestRegular,
&cosTestInf, &cosTestNan, &cosTestRegular,
&cosTestPrecision, &cosTestRange,
&sinTestInf, &sinTestNan, &sinTestRegular,
&sinTestPrecision, &sinTestRange,
&tanTestInf, &tanTestNan, &tanTestZero, &tanTestPrecision,
&acosTestLimit, &acosTestOutOfDomain, &acosTestNan, &acosTestPrecision,
&asinTestLimit, &asinTestOutOfDomain, &asinTestNan, &asinTestPrecision,
&atanTestLimit, &atanTestZero, &atanTestNan, &atanTestPrecision,
&atan2TestZero1, &atan2TestZero2, &atan2TestZero3,
&atan2TestInf1, &atan2TestInf2, &atan2TestInf3,
&atan2TestNan, &atan2TestQuadrantTopRight, &atan2TestQuadrantTopLeft,
&atan2TestQuadrantBottomRight, &atan2TestQuadrantBottomLeft,
NULL
};
SDLTest_TestSuiteReference mathTestSuite = { "Math", NULL, mathTests, NULL };
......@@ -27,8 +27,7 @@ int _mouseStateCheck(Uint32 state)
* @brief Check call to SDL_GetMouseState
*
*/
int
mouse_getMouseState(void *arg)
int mouse_getMouseState(void *arg)
{
int x;
int y;
......@@ -41,21 +40,21 @@ mouse_getMouseState(void *arg)
/* 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);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
/* Case where x pointer is not NULL */
x = INT_MIN;
state = SDL_GetMouseState(&x, NULL);
SDLTest_AssertPass("Call to SDL_GetMouseState(&x, NULL)");
SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
/* Case where y pointer is not NULL */
y = INT_MIN;
state = SDL_GetMouseState(NULL, &y);
SDLTest_AssertPass("Call to SDL_GetMouseState(NULL, &y)");
SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
/* Case where x and y pointer is not NULL */
x = INT_MIN;
......@@ -64,7 +63,7 @@ mouse_getMouseState(void *arg)
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);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
return TEST_COMPLETED;
}
......@@ -73,8 +72,7 @@ mouse_getMouseState(void *arg)
* @brief Check call to SDL_GetRelativeMouseState
*
*/
int
mouse_getRelativeMouseState(void *arg)
int mouse_getRelativeMouseState(void *arg)
{
int x;
int y;
......@@ -87,21 +85,21 @@ mouse_getRelativeMouseState(void *arg)
/* 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);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
/* Case where x pointer is not NULL */
x = INT_MIN;
state = SDL_GetRelativeMouseState(&x, NULL);
SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(&x, NULL)");
SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
/* Case where y pointer is not NULL */
y = INT_MIN;
state = SDL_GetRelativeMouseState(NULL, &y);
SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(NULL, &y)");
SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
/* Case where x and y pointer is not NULL */
x = INT_MIN;
......@@ -110,12 +108,11 @@ mouse_getRelativeMouseState(void *arg)
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);
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
return TEST_COMPLETED;
}
/* XPM definition of mouse Cursor */
static const char *_mouseArrowData[] = {
/* pixels */
......@@ -195,8 +192,7 @@ static SDL_Cursor *_initArrowCursor(const char *image[])
* @sa http://wiki.libsdl.org/SDL_CreateCursor
* @sa http://wiki.libsdl.org/SDL_FreeCursor
*/
int
mouse_createFreeCursor(void *arg)
int mouse_createFreeCursor(void *arg)
{
SDL_Cursor *cursor;
......@@ -221,8 +217,7 @@ mouse_createFreeCursor(void *arg)
* @sa http://wiki.libsdl.org/SDL_CreateColorCursor
* @sa http://wiki.libsdl.org/SDL_FreeCursor
*/
int
mouse_createFreeColorCursor(void *arg)
int mouse_createFreeColorCursor(void *arg)
{
SDL_Surface *face;
SDL_Cursor *cursor;
......@@ -230,7 +225,9 @@ mouse_createFreeColorCursor(void *arg)
/* Get sample surface */
face = SDLTest_ImageFace();
SDLTest_AssertCheck(face != NULL, "Validate sample input image is not NULL");
if (face == NULL) return TEST_ABORTED;
if (face == NULL) {
return TEST_ABORTED;
}
/* Create a color cursor from surface */
cursor = SDL_CreateColorCursor(face, 0, 0);
......@@ -277,8 +274,7 @@ void _changeCursorVisibility(int state)
*
* @sa http://wiki.libsdl.org/SDL_ShowCursor
*/
int
mouse_showCursor(void *arg)
int mouse_showCursor(void *arg)
{
int currentState;
......@@ -307,8 +303,7 @@ mouse_showCursor(void *arg)
*
* @sa http://wiki.libsdl.org/SDL_SetCursor
*/
int
mouse_setCursor(void *arg)
int mouse_setCursor(void *arg)
{
SDL_Cursor *cursor;
......@@ -340,8 +335,7 @@ mouse_setCursor(void *arg)
*
* @sa http://wiki.libsdl.org/SDL_GetCursor
*/
int
mouse_getCursor(void *arg)
int mouse_getCursor(void *arg)
{
SDL_Cursor *cursor;
......@@ -359,8 +353,7 @@ mouse_getCursor(void *arg)
* @sa http://wiki.libsdl.org/SDL_GetRelativeMouseMode
* @sa http://wiki.libsdl.org/SDL_SetRelativeMouseMode
*/
int
mouse_getSetRelativeMouseMode(void *arg)
int mouse_getSetRelativeMouseMode(void *arg)
{
int result;
int i;
......@@ -442,8 +435,7 @@ void _destroyMouseSuiteTestWindow(SDL_Window *window)
*
* @sa http://wiki.libsdl.org/SDL_WarpMouseInWindow
*/
int
mouse_warpMouseInWindow(void *arg)
int mouse_warpMouseInWindow(void *arg)
{
const int w = MOUSE_TESTWINDOW_WIDTH, h = MOUSE_TESTWINDOW_HEIGHT;
int numPositions = 6;
......@@ -466,7 +458,9 @@ mouse_warpMouseInWindow(void *arg)
yPositions[5] = h + 1;
/* Create test window */
window = _createMouseSuiteTestWindow();
if (window == NULL) return TEST_ABORTED;
if (window == NULL) {
return TEST_ABORTED;
}
/* Mouse to random position inside window */
x = SDLTest_RandomIntegerInRange(1, w - 1);
......@@ -492,7 +486,6 @@ mouse_warpMouseInWindow(void *arg)
}
}
/* Clean up test window */
_destroyMouseSuiteTestWindow(window);
......@@ -504,8 +497,7 @@ mouse_warpMouseInWindow(void *arg)
*
* @sa http://wiki.libsdl.org/SDL_GetMouseFocus
*/
int
mouse_getMouseFocus(void *arg)
int mouse_getMouseFocus(void *arg)
{
const int w = MOUSE_TESTWINDOW_WIDTH, h = MOUSE_TESTWINDOW_HEIGHT;
int x, y;
......@@ -518,7 +510,9 @@ mouse_getMouseFocus(void *arg)
/* Create test window */
window = _createMouseSuiteTestWindow();
if (window == NULL) return TEST_ABORTED;
if (window == NULL) {
return TEST_ABORTED;
}
/* Mouse to random position inside window */
x = SDLTest_RandomIntegerInRange(1, w - 1);
......@@ -555,42 +549,51 @@ mouse_getMouseFocus(void *arg)
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 mouseTest1 = {
(SDLTest_TestCaseFp)mouse_getMouseState, "mouse_getMouseState", "Check call to SDL_GetMouseState", TEST_ENABLED
};
static const SDLTest_TestCaseReference mouseTest2 =
{ (SDLTest_TestCaseFp)mouse_getRelativeMouseState, "mouse_getRelativeMouseState", "Check call to SDL_GetRelativeMouseState", TEST_ENABLED };
static const SDLTest_TestCaseReference mouseTest2 = {
(SDLTest_TestCaseFp)mouse_getRelativeMouseState, "mouse_getRelativeMouseState", "Check call to SDL_GetRelativeMouseState", TEST_ENABLED
};
static const SDLTest_TestCaseReference mouseTest3 =
{ (SDLTest_TestCaseFp)mouse_createFreeCursor, "mouse_createFreeCursor", "Check call to SDL_CreateCursor and SDL_FreeCursor", TEST_ENABLED };
static const SDLTest_TestCaseReference mouseTest3 = {
(SDLTest_TestCaseFp)mouse_createFreeCursor, "mouse_createFreeCursor", "Check call to SDL_CreateCursor and SDL_FreeCursor", TEST_ENABLED
};
static const SDLTest_TestCaseReference mouseTest4 =
{ (SDLTest_TestCaseFp)mouse_showCursor, "mouse_showCursor", "Check call to SDL_ShowCursor", TEST_ENABLED };
static const SDLTest_TestCaseReference mouseTest4 = {
(SDLTest_TestCaseFp)mouse_showCursor, "mouse_showCursor", "Check call to SDL_ShowCursor", TEST_ENABLED
};
static const SDLTest_TestCaseReference mouseTest5 =
{ (SDLTest_TestCaseFp)mouse_setCursor, "mouse_setCursor", "Check call to SDL_SetCursor", TEST_ENABLED };
static const SDLTest_TestCaseReference mouseTest5 = {
(SDLTest_TestCaseFp)mouse_setCursor, "mouse_setCursor", "Check call to SDL_SetCursor", TEST_ENABLED
};
static const SDLTest_TestCaseReference mouseTest6 =
{ (SDLTest_TestCaseFp)mouse_getCursor, "mouse_getCursor", "Check call to SDL_GetCursor", TEST_ENABLED };
static const SDLTest_TestCaseReference mouseTest6 = {
(SDLTest_TestCaseFp)mouse_getCursor, "mouse_getCursor", "Check call to SDL_GetCursor", TEST_ENABLED
};
static const SDLTest_TestCaseReference mouseTest7 =
{ (SDLTest_TestCaseFp)mouse_warpMouseInWindow, "mouse_warpMouseInWindow", "Check call to SDL_WarpMouseInWindow", TEST_ENABLED };
static const SDLTest_TestCaseReference mouseTest7 = {
(SDLTest_TestCaseFp)mouse_warpMouseInWindow, "mouse_warpMouseInWindow", "Check call to SDL_WarpMouseInWindow", TEST_ENABLED
};
static const SDLTest_TestCaseReference mouseTest8 =
{ (SDLTest_TestCaseFp)mouse_getMouseFocus, "mouse_getMouseFocus", "Check call to SDL_getMouseFocus", TEST_ENABLED };
static const SDLTest_TestCaseReference mouseTest8 = {
(SDLTest_TestCaseFp)mouse_getMouseFocus, "mouse_getMouseFocus", "Check call to SDL_getMouseFocus", TEST_ENABLED
};
static const SDLTest_TestCaseReference mouseTest9 =
{ (SDLTest_TestCaseFp)mouse_createFreeColorCursor, "mouse_createFreeColorCursor", "Check call to SDL_CreateColorCursor and SDL_FreeCursor", TEST_ENABLED };
static const SDLTest_TestCaseReference mouseTest9 = {
(SDLTest_TestCaseFp)mouse_createFreeColorCursor, "mouse_createFreeColorCursor", "Check call to SDL_CreateColorCursor and SDL_FreeCursor", TEST_ENABLED
};
static const SDLTest_TestCaseReference mouseTest10 =
{ (SDLTest_TestCaseFp)mouse_getSetRelativeMouseMode, "mouse_getSetRelativeMouseMode", "Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode", TEST_ENABLED };
static const SDLTest_TestCaseReference mouseTest10 = {
(SDLTest_TestCaseFp)mouse_getSetRelativeMouseMode, "mouse_getSetRelativeMouseMode", "Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode", TEST_ENABLED
};
/* Sequence of Mouse test cases */
static const SDLTest_TestCaseReference *mouseTests[] = {
......
......@@ -11,8 +11,7 @@
/* Definition of all RGB formats used to test pixel conversions */
const int _numRGBPixelFormats = 31;
Uint32 _RGBPixelFormats[] =
{
Uint32 _RGBPixelFormats[] = {
SDL_PIXELFORMAT_INDEX1LSB,
SDL_PIXELFORMAT_INDEX1MSB,
SDL_PIXELFORMAT_INDEX4LSB,
......@@ -45,8 +44,7 @@ Uint32 _RGBPixelFormats[] =
SDL_PIXELFORMAT_BGRA8888,
SDL_PIXELFORMAT_ARGB2101010
};
const char* _RGBPixelFormatsVerbose[] =
{
const char *_RGBPixelFormatsVerbose[] = {
"SDL_PIXELFORMAT_INDEX1LSB",
"SDL_PIXELFORMAT_INDEX1MSB",
"SDL_PIXELFORMAT_INDEX4LSB",
......@@ -82,8 +80,7 @@ const char* _RGBPixelFormatsVerbose[] =
/* Definition of all Non-RGB formats used to test pixel conversions */
const int _numNonRGBPixelFormats = 7;
Uint32 _nonRGBPixelFormats[] =
{
Uint32 _nonRGBPixelFormats[] = {
SDL_PIXELFORMAT_YV12,
SDL_PIXELFORMAT_IYUV,
SDL_PIXELFORMAT_YUY2,
......@@ -92,8 +89,7 @@ Uint32 _nonRGBPixelFormats[] =
SDL_PIXELFORMAT_NV12,
SDL_PIXELFORMAT_NV21
};
const char* _nonRGBPixelFormatsVerbose[] =
{
const char *_nonRGBPixelFormatsVerbose[] = {
"SDL_PIXELFORMAT_YV12",
"SDL_PIXELFORMAT_IYUV",
"SDL_PIXELFORMAT_YUY2",
......@@ -105,13 +101,11 @@ const char* _nonRGBPixelFormatsVerbose[] =
/* Definition of some invalid formats for negative tests */
const int _numInvalidPixelFormats = 2;
Uint32 _invalidPixelFormats[] =
{
0xfffffffe,
0xffffffff
Uint32 _invalidPixelFormats[] = {
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ABGR, SDL_PACKEDLAYOUT_1010102 + 1, 32, 4),
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ABGR, SDL_PACKEDLAYOUT_1010102 + 2, 32, 4)
};
const char* _invalidPixelFormatsVerbose[] =
{
const char *_invalidPixelFormatsVerbose[] = {
"SDL_PIXELFORMAT_UNKNOWN",
"SDL_PIXELFORMAT_UNKNOWN"
};
......@@ -124,11 +118,9 @@ const char* _invalidPixelFormatsVerbose[] =
* @sa http://wiki.libsdl.org/SDL_AllocFormat
* @sa http://wiki.libsdl.org/SDL_FreeFormat
*/
int
pixels_allocFreeFormat(void *arg)
int pixels_allocFreeFormat(void *arg)
{
const char *unknownFormat = "SDL_PIXELFORMAT_UNKNOWN";
const char *expectedError = "Parameter 'format' is invalid";
const char *error;
int i;
Uint32 format;
......@@ -137,18 +129,18 @@ pixels_allocFreeFormat(void *arg)
/* Blank/unknown format */
format = 0;
SDLTest_Log("RGB Format: %s (%u)", unknownFormat, format);
SDLTest_Log("RGB Format: %s (%" SDL_PRIu32 ")", unknownFormat, format);
/* Allocate format */
result = SDL_AllocFormat(format);
SDLTest_AssertPass("Call to SDL_AllocFormat()");
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(result->format == format, "Verify value of result.format; expected: %u, got %u", format, result->format);
SDLTest_AssertCheck(result->format == format, "Verify value of result.format; expected: %" SDL_PRIu32 ", got %" SDL_PRIu32, format, result->format);
SDLTest_AssertCheck(result->BitsPerPixel == 0, "Verify value of result.BitsPerPixel; expected: 0, got %u", result->BitsPerPixel);
SDLTest_AssertCheck(result->BytesPerPixel == 0, "Verify value of result.BytesPerPixel; expected: 0, got %u", result->BytesPerPixel);
masks = result->Rmask | result->Gmask | result->Bmask | result->Amask;
SDLTest_AssertCheck(masks == 0, "Verify value of result.[RGBA]mask combined; expected: 0, got %u", masks);
SDLTest_AssertCheck(masks == 0, "Verify value of result.[RGBA]mask combined; expected: 0, got %" SDL_PRIu32, masks);
/* Deallocate again */
SDL_FreeFormat(result);
......@@ -158,19 +150,19 @@ pixels_allocFreeFormat(void *arg)
/* RGB formats */
for (i = 0; i < _numRGBPixelFormats; i++) {
format = _RGBPixelFormats[i];
SDLTest_Log("RGB Format: %s (%u)", _RGBPixelFormatsVerbose[i], format);
SDLTest_Log("RGB Format: %s (%" SDL_PRIu32 ")", _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->format == format, "Verify value of result.format; expected: %" SDL_PRIu32 ", got %" SDL_PRIu32, format, result->format);
SDLTest_AssertCheck(result->BitsPerPixel > 0, "Verify value of result.BitsPerPixel; expected: >0, got %u", result->BitsPerPixel);
SDLTest_AssertCheck(result->BytesPerPixel > 0, "Verify value of result.BytesPerPixel; expected: >0, got %u", result->BytesPerPixel);
if (result->palette != NULL) {
masks = result->Rmask | result->Gmask | result->Bmask | result->Amask;
SDLTest_AssertCheck(masks > 0, "Verify value of result.[RGBA]mask combined; expected: >0, got %u", masks);
SDLTest_AssertCheck(masks > 0, "Verify value of result.[RGBA]mask combined; expected: >0, got %" SDL_PRIu32, masks);
}
/* Deallocate again */
......@@ -179,16 +171,18 @@ pixels_allocFreeFormat(void *arg)
}
}
#if 0 /* This succeeds for SDL3, but we don't expect SDL2 applications to call SDL_AllocFormat() for FOURCC formats directly */
/* Non-RGB formats */
for (i = 0; i < _numNonRGBPixelFormats; i++) {
format = _nonRGBPixelFormats[i];
SDLTest_Log("non-RGB Format: %s (%u)", _nonRGBPixelFormatsVerbose[i], format);
SDLTest_Log("non-RGB Format: %s (%" SDL_PRIu32 ")", _nonRGBPixelFormatsVerbose[i], format);
/* Try to allocate format */
result = SDL_AllocFormat(format);
SDLTest_AssertPass("Call to SDL_AllocFormat()");
SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
}
#endif
/* Negative cases */
......@@ -198,28 +192,11 @@ pixels_allocFreeFormat(void *arg)
SDLTest_AssertPass("Call to SDL_ClearError()");
format = _invalidPixelFormats[i];
result = SDL_AllocFormat(format);
SDLTest_AssertPass("Call to SDL_AllocFormat(%u)", format);
SDLTest_AssertPass("Call to SDL_AllocFormat(%" SDL_PRIu32 ")", format);
SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
}
}
/* Invalid free pointer */
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
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;
......@@ -230,8 +207,7 @@ pixels_allocFreeFormat(void *arg)
*
* @sa http://wiki.libsdl.org/SDL_GetPixelFormatName
*/
int
pixels_getPixelFormatName(void *arg)
int pixels_getPixelFormatName(void *arg)
{
const char *unknownFormat = "SDL_PIXELFORMAT_UNKNOWN";
const char *error;
......@@ -241,7 +217,7 @@ pixels_getPixelFormatName(void *arg)
/* Blank/undefined format */
format = 0;
SDLTest_Log("RGB Format: %s (%u)", unknownFormat, format);
SDLTest_Log("RGB Format: %s (%" SDL_PRIu32 ")", unknownFormat, format);
/* Get name of format */
result = SDL_GetPixelFormatName(format);
......@@ -256,7 +232,7 @@ pixels_getPixelFormatName(void *arg)
/* RGB formats */
for (i = 0; i < _numRGBPixelFormats; i++) {
format = _RGBPixelFormats[i];
SDLTest_Log("RGB Format: %s (%u)", _RGBPixelFormatsVerbose[i], format);
SDLTest_Log("RGB Format: %s (%" SDL_PRIu32 ")", _RGBPixelFormatsVerbose[i], format);
/* Get name of format */
result = SDL_GetPixelFormatName(format);
......@@ -272,7 +248,7 @@ pixels_getPixelFormatName(void *arg)
/* Non-RGB formats */
for (i = 0; i < _numNonRGBPixelFormats; i++) {
format = _nonRGBPixelFormats[i];
SDLTest_Log("non-RGB Format: %s (%u)", _nonRGBPixelFormatsVerbose[i], format);
SDLTest_Log("non-RGB Format: %s (%" SDL_PRIu32 ")", _nonRGBPixelFormatsVerbose[i], format);
/* Get name of format */
result = SDL_GetPixelFormatName(format);
......@@ -293,7 +269,7 @@ pixels_getPixelFormatName(void *arg)
for (i = 0; i < _numInvalidPixelFormats; i++) {
format = _invalidPixelFormats[i];
result = SDL_GetPixelFormatName(format);
SDLTest_AssertPass("Call to SDL_GetPixelFormatName(%u)", format);
SDLTest_AssertPass("Call to SDL_GetPixelFormatName(%" SDL_PRIu32 ")", format);
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(result[0] != '\0',
......@@ -315,11 +291,9 @@ pixels_getPixelFormatName(void *arg)
* @sa http://wiki.libsdl.org/SDL_AllocPalette
* @sa http://wiki.libsdl.org/SDL_FreePalette
*/
int
pixels_allocFreePalette(void *arg)
int pixels_allocFreePalette(void *arg)
{
const char *expectedError1 = "Parameter 'ncolors' is invalid";
const char *expectedError2 = "Parameter 'palette' is invalid";
const char *error;
int variation;
int i;
......@@ -330,6 +304,7 @@ pixels_allocFreePalette(void *arg)
for (variation = 1; variation <= 3; variation++) {
switch (variation) {
/* Just one color */
default:
case 1:
ncolors = 1;
break;
......@@ -383,19 +358,6 @@ pixels_allocFreePalette(void *arg)
}
}
/* 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;
}
......@@ -426,6 +388,7 @@ pixels_calcGammaRamp(void *arg)
for (variation = 0; variation < 4; variation++) {
switch (variation) {
/* gamma = 0 all black */
default:
case 0:
gamma = 0.0f;
break;
......@@ -505,11 +468,13 @@ pixels_calcGammaRamp(void *arg)
/* ================= Test References ================== */
/* Pixels test cases */
static const SDLTest_TestCaseReference pixelsTest1 =
{ (SDLTest_TestCaseFp)pixels_allocFreeFormat, "pixels_allocFreeFormat", "Call to SDL_AllocFormat and SDL_FreeFormat", TEST_ENABLED };
static const SDLTest_TestCaseReference pixelsTest1 = {
(SDLTest_TestCaseFp)pixels_allocFreeFormat, "pixels_allocFreeFormat", "Call to SDL_AllocFormat and SDL_FreeFormat", TEST_ENABLED
};
static const SDLTest_TestCaseReference pixelsTest2 =
{ (SDLTest_TestCaseFp)pixels_allocFreePalette, "pixels_allocFreePalette", "Call to SDL_AllocPalette and SDL_FreePalette", TEST_ENABLED };
static const SDLTest_TestCaseReference pixelsTest2 = {
(SDLTest_TestCaseFp)pixels_allocFreePalette, "pixels_allocFreePalette", "Call to SDL_AllocPalette and SDL_FreePalette", TEST_ENABLED
};
static const SDLTest_TestCaseReference pixelsTest3 =
{ (SDLTest_TestCaseFp)pixels_calcGammaRamp, "pixels_calcGammaRamp", "Call to SDL_CalculateGammaRamp", TEST_ENABLED };
......
......@@ -34,16 +34,16 @@ int platform_testTypes(void *arg)
int ret;
ret = _compareSizeOfType(sizeof(Uint8), 1);
SDLTest_AssertCheck( ret == 0, "sizeof(Uint8) = %lu, expected 1", (unsigned long)sizeof(Uint8) );
SDLTest_AssertCheck(ret == 0, "sizeof(Uint8) = %u, expected 1", (unsigned int)sizeof(Uint8));
ret = _compareSizeOfType(sizeof(Uint16), 2);
SDLTest_AssertCheck( ret == 0, "sizeof(Uint16) = %lu, expected 2", (unsigned long)sizeof(Uint16) );
SDLTest_AssertCheck(ret == 0, "sizeof(Uint16) = %u, expected 2", (unsigned int)sizeof(Uint16));
ret = _compareSizeOfType(sizeof(Uint32), 4);
SDLTest_AssertCheck( ret == 0, "sizeof(Uint32) = %lu, expected 4", (unsigned long)sizeof(Uint32) );
SDLTest_AssertCheck(ret == 0, "sizeof(Uint32) = %u, expected 4", (unsigned int)sizeof(Uint32));
ret = _compareSizeOfType(sizeof(Uint64), 8);
SDLTest_AssertCheck( ret == 0, "sizeof(Uint64) = %lu, expected 8", (unsigned long)sizeof(Uint64) );
SDLTest_AssertCheck(ret == 0, "sizeof(Uint64) = %u, expected 8", (unsigned int)sizeof(Uint64));
return TEST_COMPLETED;
}
......@@ -54,12 +54,19 @@ int platform_testTypes(void *arg)
int platform_testEndianessAndSwap(void *arg)
{
int real_byteorder;
int real_floatwordorder = 0;
Uint16 value = 0x1234;
Uint16 value16 = 0xCDAB;
Uint16 swapped16 = 0xABCD;
Uint32 value32 = 0xEFBEADDE;
Uint32 swapped32 = 0xDEADBEEF;
union
{
double d;
Uint32 ui32[2];
} value_double;
Uint64 value64, swapped64;
value64 = 0xEFBEADDE;
value64 <<= 32;
......@@ -67,6 +74,7 @@ int platform_testEndianessAndSwap(void *arg)
swapped64 = 0x1234ABCD;
swapped64 <<= 32;
swapped64 |= 0xDEADBEEF;
value_double.d = 3.141593;
if ((*((char *)&value) >> 4) == 0x1) {
real_byteorder = SDL_BIG_ENDIAN;
......@@ -80,6 +88,19 @@ int platform_testEndianessAndSwap(void *arg)
(SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big",
(real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big");
if (value_double.ui32[0] == 0x82c2bd7f && value_double.ui32[1] == 0x400921fb) {
real_floatwordorder = SDL_LIL_ENDIAN;
} else if (value_double.ui32[0] == 0x400921fb && value_double.ui32[1] == 0x82c2bd7f) {
real_floatwordorder = SDL_BIG_ENDIAN;
}
/* Test endianness. */
SDLTest_AssertCheck(real_floatwordorder == SDL_FLOATWORDORDER,
"Machine detected as having %s endian float word order, appears to be %s endian.",
(SDL_FLOATWORDORDER == SDL_LIL_ENDIAN) ? "little" : "big",
(real_floatwordorder == SDL_LIL_ENDIAN) ? "little" : (real_floatwordorder == SDL_BIG_ENDIAN) ? "big"
: "unknown");
/* Test 16 swap. */
SDLTest_AssertCheck(SDL_Swap16(value16) == swapped16,
"SDL_Swap16(): 16 bit swapped: 0x%X => 0x%X",
......@@ -87,7 +108,7 @@ int platform_testEndianessAndSwap(void *arg)
/* Test 32 swap. */
SDLTest_AssertCheck(SDL_Swap32(value32) == swapped32,
"SDL_Swap32(): 32 bit swapped: 0x%X => 0x%X",
"SDL_Swap32(): 32 bit swapped: 0x%" SDL_PRIX32 " => 0x%" SDL_PRIX32,
value32, SDL_Swap32(value32));
/* Test 64 swap. */
......@@ -219,7 +240,6 @@ int platform_testGetVersion(void *arg)
return TEST_COMPLETED;
}
/* !
* \brief Tests SDL_VERSION macro
*/
......@@ -242,7 +262,6 @@ int platform_testSDLVersion(void *arg)
return TEST_COMPLETED;
}
/* !
* \brief Tests default SDL_Init
*/
......@@ -286,8 +305,7 @@ int platform_testGetSetClearError(void *arg)
SDLTest_AssertPass("SDL_GetError()");
SDLTest_AssertCheck(lastError != NULL,
"SDL_GetError() != NULL");
if (lastError != NULL)
{
if (lastError != NULL) {
len = SDL_strlen(lastError);
SDLTest_AssertCheck(len == 0,
"SDL_GetError(): no message expected, len: %i", (int)len);
......@@ -299,8 +317,7 @@ int platform_testGetSetClearError(void *arg)
lastError = (char *)SDL_GetError();
SDLTest_AssertCheck(lastError != NULL,
"SDL_GetError() != NULL");
if (lastError != NULL)
{
if (lastError != NULL) {
len = SDL_strlen(lastError);
SDLTest_AssertCheck(len == SDL_strlen(testError),
"SDL_GetError(): expected message len %i, was len: %i",
......@@ -337,8 +354,7 @@ int platform_testSetErrorEmptyInput(void *arg)
lastError = (char *)SDL_GetError();
SDLTest_AssertCheck(lastError != NULL,
"SDL_GetError() != NULL");
if (lastError != NULL)
{
if (lastError != NULL) {
len = SDL_strlen(lastError);
SDLTest_AssertCheck(len == SDL_strlen(testError),
"SDL_GetError(): expected message len %i, was len: %i",
......@@ -357,6 +373,11 @@ int platform_testSetErrorEmptyInput(void *arg)
return TEST_COMPLETED;
}
#if defined(HAVE_WFORMAT_OVERFLOW)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-overflow"
#endif
/* !
* \brief Tests SDL_SetError with invalid input
* \sa
......@@ -381,8 +402,7 @@ int platform_testSetErrorInvalidInput(void *arg)
lastError = (char *)SDL_GetError();
SDLTest_AssertCheck(lastError != NULL,
"SDL_GetError() != NULL");
if (lastError != NULL)
{
if (lastError != NULL) {
len = SDL_strlen(lastError);
SDLTest_AssertCheck(len == 0 || SDL_strcmp(lastError, "(null)") == 0,
"SDL_GetError(): expected message len 0, was len: %i",
......@@ -401,8 +421,7 @@ int platform_testSetErrorInvalidInput(void *arg)
lastError = (char *)SDL_GetError();
SDLTest_AssertCheck(lastError != NULL,
"SDL_GetError() != NULL");
if (lastError != NULL)
{
if (lastError != NULL) {
len = SDL_strlen(lastError);
SDLTest_AssertCheck(len == 0 || SDL_strcmp(lastError, "(null)") == 0,
"SDL_GetError(): expected message len 0, was len: %i",
......@@ -420,8 +439,7 @@ int platform_testSetErrorInvalidInput(void *arg)
lastError = (char *)SDL_GetError();
SDLTest_AssertCheck(lastError != NULL,
"SDL_GetError() != NULL");
if (lastError != NULL)
{
if (lastError != NULL) {
len = SDL_strlen(lastError);
SDLTest_AssertCheck(len == SDL_strlen(probeError),
"SDL_GetError(): expected message len %i, was len: %i",
......@@ -440,6 +458,10 @@ int platform_testSetErrorInvalidInput(void *arg)
return TEST_COMPLETED;
}
#if defined(HAVE_WFORMAT_OVERFLOW)
#pragma GCC diagnostic pop
#endif
/* !
* \brief Tests SDL_GetPowerInfo
* \sa
......@@ -465,8 +487,7 @@ int platform_testGetPowerInfo(void *arg)
"SDL_GetPowerInfo(): state %i is one of the expected values",
(int)state);
if (state==SDL_POWERSTATE_ON_BATTERY)
{
if (state == SDL_POWERSTATE_ON_BATTERY) {
SDLTest_AssertCheck(
secs >= 0,
"SDL_GetPowerInfo(): on battery, secs >= 0, was: %i",
......@@ -478,8 +499,7 @@ int platform_testGetPowerInfo(void *arg)
}
if (state == SDL_POWERSTATE_UNKNOWN ||
state==SDL_POWERSTATE_NO_BATTERY)
{
state == SDL_POWERSTATE_NO_BATTERY) {
SDLTest_AssertCheck(
secs == -1,
"SDL_GetPowerInfo(): no battery, secs == -1, was: %i",
......@@ -521,38 +541,49 @@ int platform_testGetPowerInfo(void *arg)
/* ================= Test References ================== */
/* Platform test cases */
static const SDLTest_TestCaseReference platformTest1 =
{ (SDLTest_TestCaseFp)platform_testTypes, "platform_testTypes", "Tests predefined types", TEST_ENABLED};
static const SDLTest_TestCaseReference platformTest1 = {
(SDLTest_TestCaseFp)platform_testTypes, "platform_testTypes", "Tests predefined types", TEST_ENABLED
};
static const SDLTest_TestCaseReference platformTest2 =
{ (SDLTest_TestCaseFp)platform_testEndianessAndSwap, "platform_testEndianessAndSwap", "Tests endianess and swap functions", TEST_ENABLED};
static const SDLTest_TestCaseReference platformTest2 = {
(SDLTest_TestCaseFp)platform_testEndianessAndSwap, "platform_testEndianessAndSwap", "Tests endianness and swap functions", TEST_ENABLED
};
static const SDLTest_TestCaseReference platformTest3 =
{ (SDLTest_TestCaseFp)platform_testGetFunctions, "platform_testGetFunctions", "Tests various SDL_GetXYZ functions", TEST_ENABLED};
static const SDLTest_TestCaseReference platformTest3 = {
(SDLTest_TestCaseFp)platform_testGetFunctions, "platform_testGetFunctions", "Tests various SDL_GetXYZ functions", TEST_ENABLED
};
static const SDLTest_TestCaseReference platformTest4 =
{ (SDLTest_TestCaseFp)platform_testHasFunctions, "platform_testHasFunctions", "Tests various SDL_HasXYZ functions", TEST_ENABLED};
static const SDLTest_TestCaseReference platformTest4 = {
(SDLTest_TestCaseFp)platform_testHasFunctions, "platform_testHasFunctions", "Tests various SDL_HasXYZ functions", TEST_ENABLED
};
static const SDLTest_TestCaseReference platformTest5 =
{ (SDLTest_TestCaseFp)platform_testGetVersion, "platform_testGetVersion", "Tests SDL_GetVersion function", TEST_ENABLED};
static const SDLTest_TestCaseReference platformTest5 = {
(SDLTest_TestCaseFp)platform_testGetVersion, "platform_testGetVersion", "Tests SDL_GetVersion function", TEST_ENABLED
};
static const SDLTest_TestCaseReference platformTest6 =
{ (SDLTest_TestCaseFp)platform_testSDLVersion, "platform_testSDLVersion", "Tests SDL_VERSION macro", TEST_ENABLED};
static const SDLTest_TestCaseReference platformTest6 = {
(SDLTest_TestCaseFp)platform_testSDLVersion, "platform_testSDLVersion", "Tests SDL_VERSION macro", TEST_ENABLED
};
static const SDLTest_TestCaseReference platformTest7 =
{ (SDLTest_TestCaseFp)platform_testDefaultInit, "platform_testDefaultInit", "Tests default SDL_Init", TEST_ENABLED};
static const SDLTest_TestCaseReference platformTest7 = {
(SDLTest_TestCaseFp)platform_testDefaultInit, "platform_testDefaultInit", "Tests default SDL_Init", TEST_ENABLED
};
static const SDLTest_TestCaseReference platformTest8 =
{ (SDLTest_TestCaseFp)platform_testGetSetClearError, "platform_testGetSetClearError", "Tests SDL_Get/Set/ClearError", TEST_ENABLED};
static const SDLTest_TestCaseReference platformTest8 = {
(SDLTest_TestCaseFp)platform_testGetSetClearError, "platform_testGetSetClearError", "Tests SDL_Get/Set/ClearError", TEST_ENABLED
};
static const SDLTest_TestCaseReference platformTest9 =
{ (SDLTest_TestCaseFp)platform_testSetErrorEmptyInput, "platform_testSetErrorEmptyInput", "Tests SDL_SetError with empty input", TEST_ENABLED};
static const SDLTest_TestCaseReference platformTest9 = {
(SDLTest_TestCaseFp)platform_testSetErrorEmptyInput, "platform_testSetErrorEmptyInput", "Tests SDL_SetError with empty input", TEST_ENABLED
};
static const SDLTest_TestCaseReference platformTest10 =
{ (SDLTest_TestCaseFp)platform_testSetErrorInvalidInput, "platform_testSetErrorInvalidInput", "Tests SDL_SetError with invalid input", TEST_ENABLED};
static const SDLTest_TestCaseReference platformTest10 = {
(SDLTest_TestCaseFp)platform_testSetErrorInvalidInput, "platform_testSetErrorInvalidInput", "Tests SDL_SetError with invalid input", TEST_ENABLED
};
static const SDLTest_TestCaseReference platformTest11 =
{ (SDLTest_TestCaseFp)platform_testGetPowerInfo, "platform_testGetPowerInfo", "Tests SDL_GetPowerInfo function", TEST_ENABLED };
static const SDLTest_TestCaseReference platformTest11 = {
(SDLTest_TestCaseFp)platform_testGetPowerInfo, "platform_testGetPowerInfo", "Tests SDL_GetPowerInfo function", TEST_ENABLED
};
/* Sequence of Platform test cases */
static const SDLTest_TestCaseReference *platformTests[] = {
......
......@@ -45,8 +45,7 @@ void _validateIntersectRectAndLineResults(
* \sa
* http://wiki.libsdl.org/SDL_IntersectRectAndLine
*/
int
rect_testIntersectRectAndLine (void *arg)
int rect_testIntersectRectAndLine(void *arg)
{
SDL_Rect refRect = { 0, 0, 32, 32 };
SDL_Rect rect;
......@@ -116,8 +115,7 @@ rect_testIntersectRectAndLine (void *arg)
* \sa
* http://wiki.libsdl.org/SDL_IntersectRectAndLine
*/
int
rect_testIntersectRectAndLineInside (void *arg)
int rect_testIntersectRectAndLineInside(void *arg)
{
SDL_Rect refRect = { 0, 0, 32, 32 };
SDL_Rect rect;
......@@ -183,8 +181,7 @@ rect_testIntersectRectAndLineInside (void *arg)
* \sa
* http://wiki.libsdl.org/SDL_IntersectRectAndLine
*/
int
rect_testIntersectRectAndLineOutside (void *arg)
int rect_testIntersectRectAndLineOutside(void *arg)
{
SDL_Rect refRect = { 0, 0, 32, 32 };
SDL_Rect rect;
......@@ -238,8 +235,7 @@ rect_testIntersectRectAndLineOutside (void *arg)
* \sa
* http://wiki.libsdl.org/SDL_IntersectRectAndLine
*/
int
rect_testIntersectRectAndLineEmpty (void *arg)
int rect_testIntersectRectAndLineEmpty(void *arg)
{
SDL_Rect refRect;
SDL_Rect rect;
......@@ -273,8 +269,7 @@ rect_testIntersectRectAndLineEmpty (void *arg)
* \sa
* http://wiki.libsdl.org/SDL_IntersectRectAndLine
*/
int
rect_testIntersectRectAndLineParam (void *arg)
int rect_testIntersectRectAndLineParam(void *arg)
{
SDL_Rect rect = { 0, 0, 32, 32 };
int x1 = rect.w / 2;
......@@ -408,6 +403,32 @@ void _validateRectEqualsResults(
refRectB->x, refRectB->y, refRectB->w, refRectB->h);
}
/* !
* \brief Private helper to check SDL_FRectEquals results
*/
void _validateFRectEqualsResults(
SDL_bool equals, SDL_bool expectedEquals,
SDL_FRect *rectA, SDL_FRect *rectB, SDL_FRect *refRectA, SDL_FRect *refRectB)
{
int cmpRes;
SDLTest_AssertCheck(equals == expectedEquals,
"Check for correct equals result: expected %s, got %s testing (%f,%f,%f,%f) and (%f,%f,%f,%f)",
(expectedEquals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
(equals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
rectA->x, rectA->y, rectA->w, rectA->h,
rectB->x, rectB->y, rectB->w, rectB->h);
cmpRes = SDL_memcmp(rectA, refRectA, sizeof(*rectA));
SDLTest_AssertCheck(cmpRes == 0,
"Check that source rectangle A was not modified: got (%f,%f,%f,%f) expected (%f,%f,%f,%f)",
rectA->x, rectA->y, rectA->w, rectA->h,
refRectA->x, refRectA->y, refRectA->w, refRectA->h);
cmpRes = SDL_memcmp(rectB, refRectB, sizeof(*rectB));
SDLTest_AssertCheck(cmpRes == 0,
"Check that source rectangle B was not modified: got (%f,%f,%f,%f) expected (%f,%f,%f,%f)",
rectB->x, rectB->y, rectB->w, rectB->h,
refRectB->x, refRectB->y, refRectB->w, refRectB->h);
}
/* !
* \brief Tests SDL_IntersectRect() with B fully inside A
*
......@@ -630,7 +651,7 @@ int rect_testIntersectRectEmpty (void *arg)
rectB = refRectB;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
empty = (SDL_bool)SDL_RectEmpty(&result);
empty = SDL_RectEmpty(&result);
SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
/* Rect B empty */
......@@ -647,7 +668,7 @@ int rect_testIntersectRectEmpty (void *arg)
rectB = refRectB;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
empty = (SDL_bool)SDL_RectEmpty(&result);
empty = SDL_RectEmpty(&result);
SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
/* Rect A and B empty */
......@@ -666,7 +687,7 @@ int rect_testIntersectRectEmpty (void *arg)
rectB = refRectB;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
empty = (SDL_bool)SDL_RectEmpty(&result);
empty = SDL_RectEmpty(&result);
SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
return TEST_COMPLETED;
......@@ -681,7 +702,7 @@ int rect_testIntersectRectEmpty (void *arg)
int rect_testIntersectRectParam(void *arg)
{
SDL_Rect rectA;
SDL_Rect rectB;
SDL_Rect rectB = { 0 };
SDL_Rect result;
SDL_bool intersection;
......@@ -936,7 +957,7 @@ int rect_testHasIntersectionEmpty (void *arg)
int rect_testHasIntersectionParam(void *arg)
{
SDL_Rect rectA;
SDL_Rect rectB;
SDL_Rect rectB = { 0 };
SDL_bool intersection;
/* invalid parameter combinations */
......@@ -983,10 +1004,18 @@ int rect_testEnclosePoints(void *arg)
miny = newy;
maxy = newy;
} else {
if (newx < minx) minx = newx;
if (newx > maxx) maxx = newx;
if (newy < miny) miny = newy;
if (newy > maxy) maxy = newy;
if (newx < minx) {
minx = newx;
}
if (newx > maxx) {
maxx = newx;
}
if (newy < miny) {
miny = newy;
}
if (newy > maxy) {
maxy = newy;
}
}
}
......@@ -1059,10 +1088,18 @@ int rect_testEnclosePointsRepeatedInput(void *arg)
miny = newy;
maxy = newy;
} else {
if (newx < minx) minx = newx;
if (newx > maxx) maxx = newx;
if (newy < miny) miny = newy;
if (newy > maxy) maxy = newy;
if (newx < minx) {
minx = newx;
}
if (newx > maxx) {
maxx = newx;
}
if (newy < miny) {
miny = newy;
}
if (newy > maxy) {
maxy = newy;
}
}
}
......@@ -1139,10 +1176,18 @@ int rect_testEnclosePointsWithClipping(void *arg)
miny = newy;
maxy = newy;
} else {
if (newx < minx) minx = newx;
if (newx > maxx) maxx = newx;
if (newy < miny) miny = newy;
if (newy > maxy) maxy = newy;
if (newx < minx) {
minx = newx;
}
if (newx > maxx) {
maxx = newx;
}
if (newy < miny) {
miny = newy;
}
if (newy > maxy) {
maxy = newy;
}
}
expectedEnclosed = SDL_TRUE;
}
......@@ -1205,7 +1250,7 @@ int rect_testEnclosePointsParam(void *arg)
{
SDL_Point points[1];
int count;
SDL_Rect clip;
SDL_Rect clip = { 0 };
SDL_Rect result;
SDL_bool anyEnclosed;
......@@ -1279,10 +1324,18 @@ int rect_testUnionRectOutside(void *arg)
refRectB.w = refRectA.w - 2;
refRectB.h = refRectA.h - 2;
expectedResult = refRectA;
if (dx == -1) expectedResult.x--;
if (dy == -1) expectedResult.y--;
if ((dx == 1) || (dx == -1)) expectedResult.w++;
if ((dy == 1) || (dy == -1)) expectedResult.h++;
if (dx == -1) {
expectedResult.x--;
}
if (dy == -1) {
expectedResult.y--;
}
if ((dx == 1) || (dx == -1)) {
expectedResult.w++;
}
if ((dy == 1) || (dy == -1)) {
expectedResult.h++;
}
rectA = refRectA;
rectB = refRectB;
SDL_UnionRect(&rectA, &rectB, &result);
......@@ -1407,10 +1460,18 @@ int rect_testUnionRectInside(void *arg)
refRectA.w = SDLTest_RandomIntegerInRange(256, 1024);
refRectA.h = SDLTest_RandomIntegerInRange(256, 1024);
refRectB = refRectA;
if (dx == -1) refRectB.x++;
if ((dx == 1) || (dx == -1)) refRectB.w--;
if (dy == -1) refRectB.y++;
if ((dy == 1) || (dy == -1)) refRectB.h--;
if (dx == -1) {
refRectB.x++;
}
if ((dx == 1) || (dx == -1)) {
refRectB.w--;
}
if (dy == -1) {
refRectB.y++;
}
if ((dy == 1) || (dy == -1)) {
refRectB.h--;
}
expectedResult = refRectA;
rectA = refRectA;
rectB = refRectB;
......@@ -1431,7 +1492,7 @@ int rect_testUnionRectInside(void *arg)
*/
int rect_testUnionRectParam(void *arg)
{
SDL_Rect rectA, rectB;
SDL_Rect rectA, rectB = { 0 };
SDL_Rect result;
/* invalid parameter combinations */
......@@ -1472,7 +1533,7 @@ int rect_testRectEmpty(void *arg)
refRect.h = SDLTest_RandomIntegerInRange(256, 1024);
expectedResult = SDL_FALSE;
rect = refRect;
result = (SDL_bool)SDL_RectEmpty((const SDL_Rect *)&rect);
result = SDL_RectEmpty(&rect);
_validateRectEmptyResults(result, expectedResult, &rect, &refRect);
/* Empty case */
......@@ -1485,7 +1546,7 @@ int rect_testRectEmpty(void *arg)
refRect.h = h;
expectedResult = SDL_TRUE;
rect = refRect;
result = (SDL_bool)SDL_RectEmpty((const SDL_Rect *)&rect);
result = SDL_RectEmpty(&rect);
_validateRectEmptyResults(result, expectedResult, &rect, &refRect);
}
}
......@@ -1505,7 +1566,7 @@ int rect_testRectEmptyParam(void *arg)
SDL_bool result;
/* invalid parameter combinations */
result = (SDL_bool)SDL_RectEmpty((const SDL_Rect *)NULL);
result = SDL_RectEmpty(NULL);
SDLTest_AssertCheck(result == SDL_TRUE, "Check that function returns TRUE when 1st parameter is NULL");
return TEST_COMPLETED;
......@@ -1535,7 +1596,7 @@ int rect_testRectEquals(void *arg)
expectedResult = SDL_TRUE;
rectA = refRectA;
rectB = refRectB;
result = (SDL_bool)SDL_RectEquals((const SDL_Rect *)&rectA, (const SDL_Rect *)&rectB);
result = SDL_RectEquals(&rectA, &rectB);
_validateRectEqualsResults(result, expectedResult, &rectA, &rectB, &refRectA, &refRectB);
return TEST_COMPLETED;
......@@ -1564,11 +1625,74 @@ int rect_testRectEqualsParam(void *arg)
rectB.h = SDLTest_RandomIntegerInRange(1, 1024);
/* invalid parameter combinations */
result = (SDL_bool)SDL_RectEquals((const SDL_Rect *)NULL, (const SDL_Rect *)&rectB);
result = SDL_RectEquals(NULL, &rectB);
SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
result = SDL_RectEquals(&rectA, NULL);
SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL");
result = SDL_RectEquals(NULL, NULL);
SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 2nd parameter are NULL");
return TEST_COMPLETED;
}
/* !
* \brief Tests SDL_FRectEquals() with various inputs
*
* \sa
* http://wiki.libsdl.org/SDL_FRectEquals
*/
int rect_testFRectEquals(void *arg)
{
SDL_FRect refRectA;
SDL_FRect refRectB;
SDL_FRect rectA;
SDL_FRect rectB;
SDL_bool expectedResult;
SDL_bool result;
/* Equals */
refRectA.x = (float)SDLTest_RandomIntegerInRange(-1024, 1024);
refRectA.y = (float)SDLTest_RandomIntegerInRange(-1024, 1024);
refRectA.w = (float)SDLTest_RandomIntegerInRange(1, 1024);
refRectA.h = (float)SDLTest_RandomIntegerInRange(1, 1024);
refRectB = refRectA;
expectedResult = SDL_TRUE;
rectA = refRectA;
rectB = refRectB;
result = SDL_FRectEquals(&rectA, &rectB);
_validateFRectEqualsResults(result, expectedResult, &rectA, &rectB, &refRectA, &refRectB);
return TEST_COMPLETED;
}
/* !
* \brief Negative tests against SDL_FRectEquals() with invalid parameters
*
* \sa
* http://wiki.libsdl.org/SDL_FRectEquals
*/
int rect_testFRectEqualsParam(void *arg)
{
SDL_FRect rectA;
SDL_FRect rectB;
SDL_bool result;
/* data setup -- For the purpose of this test, the values don't matter. */
rectA.x = SDLTest_RandomFloat();
rectA.y = SDLTest_RandomFloat();
rectA.w = SDLTest_RandomFloat();
rectA.h = SDLTest_RandomFloat();
rectB.x = SDLTest_RandomFloat();
rectB.y = SDLTest_RandomFloat();
rectB.w = SDLTest_RandomFloat();
rectB.h = SDLTest_RandomFloat();
/* invalid parameter combinations */
result = SDL_FRectEquals(NULL, &rectB);
SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
result = (SDL_bool)SDL_RectEquals((const SDL_Rect *)&rectA, (const SDL_Rect *)NULL);
result = SDL_FRectEquals(&rectA, NULL);
SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL");
result = (SDL_bool)SDL_RectEquals((const SDL_Rect *)NULL, (const SDL_Rect *)NULL);
result = SDL_FRectEquals(NULL, NULL);
SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 2nd parameter are NULL");
return TEST_COMPLETED;
......@@ -1579,100 +1703,138 @@ int rect_testRectEqualsParam(void *arg)
/* Rect test cases */
/* SDL_IntersectRectAndLine */
static const SDLTest_TestCaseReference rectTest1 =
{ (SDLTest_TestCaseFp)rect_testIntersectRectAndLine,"rect_testIntersectRectAndLine", "Tests SDL_IntersectRectAndLine clipping cases", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest1 = {
(SDLTest_TestCaseFp)rect_testIntersectRectAndLine, "rect_testIntersectRectAndLine", "Tests SDL_IntersectRectAndLine clipping cases", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest2 =
{ (SDLTest_TestCaseFp)rect_testIntersectRectAndLineInside, "rect_testIntersectRectAndLineInside", "Tests SDL_IntersectRectAndLine with line fully contained in rect", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest2 = {
(SDLTest_TestCaseFp)rect_testIntersectRectAndLineInside, "rect_testIntersectRectAndLineInside", "Tests SDL_IntersectRectAndLine with line fully contained in rect", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest3 =
{ (SDLTest_TestCaseFp)rect_testIntersectRectAndLineOutside, "rect_testIntersectRectAndLineOutside", "Tests SDL_IntersectRectAndLine with line fully outside of rect", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest3 = {
(SDLTest_TestCaseFp)rect_testIntersectRectAndLineOutside, "rect_testIntersectRectAndLineOutside", "Tests SDL_IntersectRectAndLine with line fully outside of rect", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest4 =
{ (SDLTest_TestCaseFp)rect_testIntersectRectAndLineEmpty, "rect_testIntersectRectAndLineEmpty", "Tests SDL_IntersectRectAndLine with empty rectangle ", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest4 = {
(SDLTest_TestCaseFp)rect_testIntersectRectAndLineEmpty, "rect_testIntersectRectAndLineEmpty", "Tests SDL_IntersectRectAndLine with empty rectangle ", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest5 =
{ (SDLTest_TestCaseFp)rect_testIntersectRectAndLineParam, "rect_testIntersectRectAndLineParam", "Negative tests against SDL_IntersectRectAndLine with invalid parameters", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest5 = {
(SDLTest_TestCaseFp)rect_testIntersectRectAndLineParam, "rect_testIntersectRectAndLineParam", "Negative tests against SDL_IntersectRectAndLine with invalid parameters", TEST_ENABLED
};
/* SDL_IntersectRect */
static const SDLTest_TestCaseReference rectTest6 =
{ (SDLTest_TestCaseFp)rect_testIntersectRectInside, "rect_testIntersectRectInside", "Tests SDL_IntersectRect with B fully contained in A", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest6 = {
(SDLTest_TestCaseFp)rect_testIntersectRectInside, "rect_testIntersectRectInside", "Tests SDL_IntersectRect with B fully contained in A", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest7 =
{ (SDLTest_TestCaseFp)rect_testIntersectRectOutside, "rect_testIntersectRectOutside", "Tests SDL_IntersectRect with B fully outside of A", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest7 = {
(SDLTest_TestCaseFp)rect_testIntersectRectOutside, "rect_testIntersectRectOutside", "Tests SDL_IntersectRect with B fully outside of A", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest8 =
{ (SDLTest_TestCaseFp)rect_testIntersectRectPartial, "rect_testIntersectRectPartial", "Tests SDL_IntersectRect with B partially intersecting A", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest8 = {
(SDLTest_TestCaseFp)rect_testIntersectRectPartial, "rect_testIntersectRectPartial", "Tests SDL_IntersectRect with B partially intersecting A", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest9 =
{ (SDLTest_TestCaseFp)rect_testIntersectRectPoint, "rect_testIntersectRectPoint", "Tests SDL_IntersectRect with 1x1 sized rectangles", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest9 = {
(SDLTest_TestCaseFp)rect_testIntersectRectPoint, "rect_testIntersectRectPoint", "Tests SDL_IntersectRect with 1x1 sized rectangles", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest10 =
{ (SDLTest_TestCaseFp)rect_testIntersectRectEmpty, "rect_testIntersectRectEmpty", "Tests SDL_IntersectRect with empty rectangles", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest10 = {
(SDLTest_TestCaseFp)rect_testIntersectRectEmpty, "rect_testIntersectRectEmpty", "Tests SDL_IntersectRect with empty rectangles", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest11 =
{ (SDLTest_TestCaseFp)rect_testIntersectRectParam, "rect_testIntersectRectParam", "Negative tests against SDL_IntersectRect with invalid parameters", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest11 = {
(SDLTest_TestCaseFp)rect_testIntersectRectParam, "rect_testIntersectRectParam", "Negative tests against SDL_IntersectRect with invalid parameters", TEST_ENABLED
};
/* SDL_HasIntersection */
static const SDLTest_TestCaseReference rectTest12 =
{ (SDLTest_TestCaseFp)rect_testHasIntersectionInside, "rect_testHasIntersectionInside", "Tests SDL_HasIntersection with B fully contained in A", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest12 = {
(SDLTest_TestCaseFp)rect_testHasIntersectionInside, "rect_testHasIntersectionInside", "Tests SDL_HasIntersection with B fully contained in A", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest13 =
{ (SDLTest_TestCaseFp)rect_testHasIntersectionOutside, "rect_testHasIntersectionOutside", "Tests SDL_HasIntersection with B fully outside of A", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest13 = {
(SDLTest_TestCaseFp)rect_testHasIntersectionOutside, "rect_testHasIntersectionOutside", "Tests SDL_HasIntersection with B fully outside of A", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest14 =
{ (SDLTest_TestCaseFp)rect_testHasIntersectionPartial,"rect_testHasIntersectionPartial", "Tests SDL_HasIntersection with B partially intersecting A", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest14 = {
(SDLTest_TestCaseFp)rect_testHasIntersectionPartial, "rect_testHasIntersectionPartial", "Tests SDL_HasIntersection with B partially intersecting A", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest15 =
{ (SDLTest_TestCaseFp)rect_testHasIntersectionPoint, "rect_testHasIntersectionPoint", "Tests SDL_HasIntersection with 1x1 sized rectangles", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest15 = {
(SDLTest_TestCaseFp)rect_testHasIntersectionPoint, "rect_testHasIntersectionPoint", "Tests SDL_HasIntersection with 1x1 sized rectangles", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest16 =
{ (SDLTest_TestCaseFp)rect_testHasIntersectionEmpty, "rect_testHasIntersectionEmpty", "Tests SDL_HasIntersection with empty rectangles", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest16 = {
(SDLTest_TestCaseFp)rect_testHasIntersectionEmpty, "rect_testHasIntersectionEmpty", "Tests SDL_HasIntersection with empty rectangles", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest17 =
{ (SDLTest_TestCaseFp)rect_testHasIntersectionParam, "rect_testHasIntersectionParam", "Negative tests against SDL_HasIntersection with invalid parameters", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest17 = {
(SDLTest_TestCaseFp)rect_testHasIntersectionParam, "rect_testHasIntersectionParam", "Negative tests against SDL_HasIntersection with invalid parameters", TEST_ENABLED
};
/* SDL_EnclosePoints */
static const SDLTest_TestCaseReference rectTest18 =
{ (SDLTest_TestCaseFp)rect_testEnclosePoints, "rect_testEnclosePoints", "Tests SDL_EnclosePoints without clipping", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest18 = {
(SDLTest_TestCaseFp)rect_testEnclosePoints, "rect_testEnclosePoints", "Tests SDL_EnclosePoints without clipping", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest19 =
{ (SDLTest_TestCaseFp)rect_testEnclosePointsWithClipping, "rect_testEnclosePointsWithClipping", "Tests SDL_EnclosePoints with clipping", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest19 = {
(SDLTest_TestCaseFp)rect_testEnclosePointsWithClipping, "rect_testEnclosePointsWithClipping", "Tests SDL_EnclosePoints with clipping", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest20 =
{ (SDLTest_TestCaseFp)rect_testEnclosePointsRepeatedInput, "rect_testEnclosePointsRepeatedInput", "Tests SDL_EnclosePoints with repeated input", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest20 = {
(SDLTest_TestCaseFp)rect_testEnclosePointsRepeatedInput, "rect_testEnclosePointsRepeatedInput", "Tests SDL_EnclosePoints with repeated input", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest21 =
{ (SDLTest_TestCaseFp)rect_testEnclosePointsParam, "rect_testEnclosePointsParam", "Negative tests against SDL_EnclosePoints with invalid parameters", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest21 = {
(SDLTest_TestCaseFp)rect_testEnclosePointsParam, "rect_testEnclosePointsParam", "Negative tests against SDL_EnclosePoints with invalid parameters", TEST_ENABLED
};
/* SDL_UnionRect */
static const SDLTest_TestCaseReference rectTest22 =
{ (SDLTest_TestCaseFp)rect_testUnionRectInside, "rect_testUnionRectInside", "Tests SDL_UnionRect where rect B is inside rect A", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest22 = {
(SDLTest_TestCaseFp)rect_testUnionRectInside, "rect_testUnionRectInside", "Tests SDL_UnionRect where rect B is inside rect A", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest23 =
{ (SDLTest_TestCaseFp)rect_testUnionRectOutside, "rect_testUnionRectOutside", "Tests SDL_UnionRect where rect B is outside rect A", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest23 = {
(SDLTest_TestCaseFp)rect_testUnionRectOutside, "rect_testUnionRectOutside", "Tests SDL_UnionRect where rect B is outside rect A", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest24 =
{ (SDLTest_TestCaseFp)rect_testUnionRectEmpty, "rect_testUnionRectEmpty", "Tests SDL_UnionRect where rect A or rect B are empty", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest24 = {
(SDLTest_TestCaseFp)rect_testUnionRectEmpty, "rect_testUnionRectEmpty", "Tests SDL_UnionRect where rect A or rect B are empty", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest25 =
{ (SDLTest_TestCaseFp)rect_testUnionRectParam, "rect_testUnionRectParam", "Negative tests against SDL_UnionRect with invalid parameters", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest25 = {
(SDLTest_TestCaseFp)rect_testUnionRectParam, "rect_testUnionRectParam", "Negative tests against SDL_UnionRect with invalid parameters", TEST_ENABLED
};
/* SDL_RectEmpty */
static const SDLTest_TestCaseReference rectTest26 =
{ (SDLTest_TestCaseFp)rect_testRectEmpty, "rect_testRectEmpty", "Tests SDL_RectEmpty with various inputs", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest26 = {
(SDLTest_TestCaseFp)rect_testRectEmpty, "rect_testRectEmpty", "Tests SDL_RectEmpty with various inputs", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest27 =
{ (SDLTest_TestCaseFp)rect_testRectEmptyParam, "rect_testRectEmptyParam", "Negative tests against SDL_RectEmpty with invalid parameters", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest27 = {
(SDLTest_TestCaseFp)rect_testRectEmptyParam, "rect_testRectEmptyParam", "Negative tests against SDL_RectEmpty with invalid parameters", TEST_ENABLED
};
/* SDL_RectEquals */
static const SDLTest_TestCaseReference rectTest28 =
{ (SDLTest_TestCaseFp)rect_testRectEquals, "rect_testRectEquals", "Tests SDL_RectEquals with various inputs", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest28 = {
(SDLTest_TestCaseFp)rect_testRectEquals, "rect_testRectEquals", "Tests SDL_RectEquals with various inputs", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest29 = {
(SDLTest_TestCaseFp)rect_testRectEqualsParam, "rect_testRectEqualsParam", "Negative tests against SDL_RectEquals with invalid parameters", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest29 =
{ (SDLTest_TestCaseFp)rect_testRectEqualsParam, "rect_testRectEqualsParam", "Negative tests against SDL_RectEquals with invalid parameters", TEST_ENABLED };
/* SDL_FRectEquals */
static const SDLTest_TestCaseReference rectTest30 = {
(SDLTest_TestCaseFp)rect_testFRectEquals, "rect_testFRectEquals", "Tests SDL_FRectEquals with various inputs", TEST_ENABLED
};
static const SDLTest_TestCaseReference rectTest31 = {
(SDLTest_TestCaseFp)rect_testFRectEqualsParam, "rect_testFRectEqualsParam", "Negative tests against SDL_FRectEquals with invalid parameters", TEST_ENABLED
};
/* !
* \brief Sequence of Rect test cases; functions that handle simple rectangles including overlaps and merges.
......@@ -1683,10 +1845,9 @@ static const SDLTest_TestCaseReference rectTest29 =
static const SDLTest_TestCaseReference *rectTests[] = {
&rectTest1, &rectTest2, &rectTest3, &rectTest4, &rectTest5, &rectTest6, &rectTest7, &rectTest8, &rectTest9, &rectTest10, &rectTest11, &rectTest12, &rectTest13, &rectTest14,
&rectTest15, &rectTest16, &rectTest17, &rectTest18, &rectTest19, &rectTest20, &rectTest21, &rectTest22, &rectTest23, &rectTest24, &rectTest25, &rectTest26, &rectTest27,
&rectTest28, &rectTest29, NULL
&rectTest28, &rectTest29, &rectTest30, &rectTest31, NULL
};
/* Rect test suite (global) */
SDLTest_TestSuiteReference rectTestSuite = {
"Rect",
......
......@@ -53,7 +53,7 @@ void InitCreateRenderer(void *arg)
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
SDLTest_AssertPass("SDL_CreateRenderer()");
SDLTest_AssertCheck(renderer != 0, "Check SDL_CreateRenderer result");
SDLTest_AssertCheck(renderer != NULL, "Check SDL_CreateRenderer result");
if (renderer == NULL) {
SDL_DestroyWindow(window);
return;
......@@ -78,15 +78,13 @@ void CleanupDestroyRenderer(void *arg)
}
}
/**
* @brief Tests call to SDL_GetNumRenderDrivers
*
* \sa
* http://wiki.libsdl.org/SDL_GetNumRenderDrivers
*/
int
render_testGetNumRenderDrivers(void *arg)
int render_testGetNumRenderDrivers(void *arg)
{
int n;
n = SDL_GetNumRenderDrivers();
......@@ -94,7 +92,6 @@ render_testGetNumRenderDrivers(void *arg)
return TEST_COMPLETED;
}
/**
* @brief Tests the SDL primitives for rendering.
*
......@@ -151,10 +148,14 @@ int render_testPrimitives (void *arg)
for (y = 0; y < 3; y++) {
for (x = y % 2; x < TESTRENDER_SCREEN_W; x += 2) {
ret = SDL_SetRenderDrawColor(renderer, x * y, x * y / 2, x * y / 3, SDL_ALPHA_OPAQUE);
if (ret != 0) checkFailCount1++;
if (ret != 0) {
checkFailCount1++;
}
ret = SDL_RenderDrawPoint(renderer, x, y);
if (ret != 0) checkFailCount2++;
if (ret != 0) {
checkFailCount2++;
}
}
}
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetRenderDrawColor, expected: 0, got: %i", checkFailCount1);
......@@ -188,13 +189,13 @@ int render_testPrimitives (void *arg)
ret = SDL_RenderDrawLine(renderer, 79, 59, 50, 30);
SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderDrawLine, expected: 0, got: %i", ret);
/* Make current */
SDL_RenderPresent(renderer);
/* See if it's the same. */
referenceSurface = SDLTest_ImagePrimitives();
_compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
/* Make current */
SDL_RenderPresent(renderer);
/* Clean up. */
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
......@@ -276,21 +277,26 @@ int render_testPrimitivesBlend (void *arg)
ret = SDL_RenderFillRect(renderer, &rect);
SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderFillRect, expected: 0, got: %i", ret);
/* Draw blended lines, lines for everyone. */
checkFailCount1 = 0;
checkFailCount2 = 0;
checkFailCount3 = 0;
for (i = 0; i < TESTRENDER_SCREEN_W; i += 2) {
ret = SDL_SetRenderDrawColor(renderer, 60 + 2 * i, 240 - 2 * i, 50, 3 * i);
if (ret != 0) checkFailCount1++;
if (ret != 0) {
checkFailCount1++;
}
ret = SDL_SetRenderDrawBlendMode(renderer,(((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
(((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_NONE );
if (ret != 0) checkFailCount2++;
ret = SDL_SetRenderDrawBlendMode(renderer, (((i / 2) % 3) == 0) ? SDL_BLENDMODE_BLEND : (((i / 2) % 3) == 1) ? SDL_BLENDMODE_ADD
: SDL_BLENDMODE_NONE);
if (ret != 0) {
checkFailCount2++;
}
ret = SDL_RenderDrawLine(renderer, 0, 0, i, 59);
if (ret != 0) checkFailCount3++;
if (ret != 0) {
checkFailCount3++;
}
}
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetRenderDrawColor, expected: 0, got: %i", checkFailCount1);
SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetRenderDrawBlendMode, expected: 0, got: %i", checkFailCount2);
......@@ -301,14 +307,20 @@ int render_testPrimitivesBlend (void *arg)
checkFailCount3 = 0;
for (i = 0; i < TESTRENDER_SCREEN_H; i += 2) {
ret = SDL_SetRenderDrawColor(renderer, 60 + 2 * i, 240 - 2 * i, 50, 3 * i);
if (ret != 0) checkFailCount1++;
if (ret != 0) {
checkFailCount1++;
}
ret = SDL_SetRenderDrawBlendMode(renderer,(((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
(((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_NONE );
if (ret != 0) checkFailCount2++;
ret = SDL_SetRenderDrawBlendMode(renderer, (((i / 2) % 3) == 0) ? SDL_BLENDMODE_BLEND : (((i / 2) % 3) == 1) ? SDL_BLENDMODE_ADD
: SDL_BLENDMODE_NONE);
if (ret != 0) {
checkFailCount2++;
}
ret = SDL_RenderDrawLine(renderer, 0, 0, 79, i);
if (ret != 0) checkFailCount3++;
if (ret != 0) {
checkFailCount3++;
}
}
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetRenderDrawColor, expected: 0, got: %i", checkFailCount1);
SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetRenderDrawBlendMode, expected: 0, got: %i", checkFailCount2);
......@@ -321,27 +333,33 @@ int render_testPrimitivesBlend (void *arg)
for (j = 0; j < TESTRENDER_SCREEN_H; j += 3) {
for (i = 0; i < TESTRENDER_SCREEN_W; i += 3) {
ret = SDL_SetRenderDrawColor(renderer, j * 4, i * 3, j * 4, i * 3);
if (ret != 0) checkFailCount1++;
if (ret != 0) {
checkFailCount1++;
}
ret = SDL_SetRenderDrawBlendMode(renderer, ((((i+j)/3)%3)==0) ? SDL_BLENDMODE_BLEND :
((((i+j)/3)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_NONE );
if (ret != 0) checkFailCount2++;
ret = SDL_SetRenderDrawBlendMode(renderer, ((((i + j) / 3) % 3) == 0) ? SDL_BLENDMODE_BLEND : ((((i + j) / 3) % 3) == 1) ? SDL_BLENDMODE_ADD
: SDL_BLENDMODE_NONE);
if (ret != 0) {
checkFailCount2++;
}
ret = SDL_RenderDrawPoint(renderer, i, j);
if (ret != 0) checkFailCount3++;
if (ret != 0) {
checkFailCount3++;
}
}
}
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetRenderDrawColor, expected: 0, got: %i", checkFailCount1);
SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetRenderDrawBlendMode, expected: 0, got: %i", checkFailCount2);
SDLTest_AssertCheck(checkFailCount3 == 0, "Validate results from calls to SDL_RenderDrawPoint, expected: 0, got: %i", checkFailCount3);
/* Make current */
SDL_RenderPresent(renderer);
/* See if it's the same. */
referenceSurface = SDLTest_ImagePrimitivesBlend();
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED);
/* Make current */
SDL_RenderPresent(renderer);
/* Clean up. */
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
......@@ -349,8 +367,6 @@ int render_testPrimitivesBlend (void *arg)
return TEST_COMPLETED;
}
/**
* @brief Tests some blitting routines.
*
......@@ -358,8 +374,7 @@ int render_testPrimitivesBlend (void *arg)
* http://wiki.libsdl.org/SDL_RenderCopy
* http://wiki.libsdl.org/SDL_DestroyTexture
*/
int
render_testBlit(void *arg)
int render_testBlit(void *arg)
{
int ret;
SDL_Rect rect;
......@@ -399,18 +414,20 @@ render_testBlit(void *arg)
rect.x = i;
rect.y = j;
ret = SDL_RenderCopy(renderer, tface, NULL, &rect);
if (ret != 0) checkFailCount1++;
if (ret != 0) {
checkFailCount1++;
}
}
}
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount1);
/* Make current */
SDL_RenderPresent(renderer);
/* See if it's the same */
referenceSurface = SDLTest_ImageBlit();
_compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
/* Make current */
SDL_RenderPresent(renderer);
/* Clean up. */
SDL_DestroyTexture(tface);
SDL_FreeSurface(referenceSurface);
......@@ -419,7 +436,6 @@ render_testBlit(void *arg)
return TEST_COMPLETED;
}
/**
* @brief Blits doing color tests.
*
......@@ -428,8 +444,7 @@ render_testBlit(void *arg)
* http://wiki.libsdl.org/SDL_RenderCopy
* http://wiki.libsdl.org/SDL_DestroyTexture
*/
int
render_testBlitColor (void *arg)
int render_testBlitColor(void *arg)
{
int ret;
SDL_Rect rect;
......@@ -466,25 +481,29 @@ render_testBlitColor (void *arg)
for (i = 0; i <= ni; i += 4) {
/* Set color mod. */
ret = SDL_SetTextureColorMod(tface, (255 / nj) * j, (255 / ni) * i, (255 / nj) * j);
if (ret != 0) checkFailCount1++;
if (ret != 0) {
checkFailCount1++;
}
/* Blitting. */
rect.x = i;
rect.y = j;
ret = SDL_RenderCopy(renderer, tface, NULL, &rect);
if (ret != 0) checkFailCount2++;
if (ret != 0) {
checkFailCount2++;
}
}
}
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i", checkFailCount1);
SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount2);
/* Make current */
SDL_RenderPresent(renderer);
/* See if it's the same. */
referenceSurface = SDLTest_ImageBlitColor();
_compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
/* Make current */
SDL_RenderPresent(renderer);
/* Clean up. */
SDL_DestroyTexture(tface);
SDL_FreeSurface(referenceSurface);
......@@ -493,7 +512,6 @@ render_testBlitColor (void *arg)
return TEST_COMPLETED;
}
/**
* @brief Tests blitting with alpha.
*
......@@ -502,8 +520,7 @@ render_testBlitColor (void *arg)
* http://wiki.libsdl.org/SDL_RenderCopy
* http://wiki.libsdl.org/SDL_DestroyTexture
*/
int
render_testBlitAlpha (void *arg)
int render_testBlitAlpha(void *arg)
{
int ret;
SDL_Rect rect;
......@@ -543,25 +560,29 @@ render_testBlitAlpha (void *arg)
for (i = 0; i <= ni; i += 4) {
/* Set alpha mod. */
ret = SDL_SetTextureAlphaMod(tface, (255 / ni) * i);
if (ret != 0) checkFailCount1++;
if (ret != 0) {
checkFailCount1++;
}
/* Blitting. */
rect.x = i;
rect.y = j;
ret = SDL_RenderCopy(renderer, tface, NULL, &rect);
if (ret != 0) checkFailCount2++;
if (ret != 0) {
checkFailCount2++;
}
}
}
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureAlphaMod, expected: 0, got: %i", checkFailCount1);
SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount2);
/* Make current */
SDL_RenderPresent(renderer);
/* See if it's the same. */
referenceSurface = SDLTest_ImageBlitAlpha();
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED);
/* Make current */
SDL_RenderPresent(renderer);
/* Clean up. */
SDL_DestroyTexture(tface);
SDL_FreeSurface(referenceSurface);
......@@ -608,20 +629,23 @@ _testBlitBlendMode( SDL_Texture * tface, int mode )
for (i = 0; i <= ni; i += 4) {
/* Set blend mode. */
ret = SDL_SetTextureBlendMode(tface, (SDL_BlendMode)mode);
if (ret != 0) checkFailCount1++;
if (ret != 0) {
checkFailCount1++;
}
/* Blitting. */
rect.x = i;
rect.y = j;
ret = SDL_RenderCopy(renderer, tface, NULL, &rect);
if (ret != 0) checkFailCount2++;
if (ret != 0) {
checkFailCount2++;
}
}
}
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureBlendMode, expected: 0, got: %i", checkFailCount1);
SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount2);
}
/**
* @brief Tests some more blitting routines.
*
......@@ -631,8 +655,7 @@ _testBlitBlendMode( SDL_Texture * tface, int mode )
* http://wiki.libsdl.org/SDL_SetTextureBlendMode
* http://wiki.libsdl.org/SDL_DestroyTexture
*/
int
render_testBlitBlend (void *arg)
int render_testBlitBlend(void *arg)
{
int ret;
SDL_Rect rect;
......@@ -674,9 +697,10 @@ render_testBlitBlend (void *arg)
_testBlitBlendMode(tface, SDL_BLENDMODE_NONE);
referenceSurface = SDLTest_ImageBlitBlendNone();
/* Make current and compare */
SDL_RenderPresent(renderer);
/* Compare, then Present */
_compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
SDL_RenderPresent(renderer);
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
......@@ -684,9 +708,10 @@ render_testBlitBlend (void *arg)
_testBlitBlendMode(tface, SDL_BLENDMODE_BLEND);
referenceSurface = SDLTest_ImageBlitBlend();
/* Make current and compare */
SDL_RenderPresent(renderer);
/* Compare, then Present */
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED);
SDL_RenderPresent(renderer);
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
......@@ -694,9 +719,10 @@ render_testBlitBlend (void *arg)
_testBlitBlendMode(tface, SDL_BLENDMODE_ADD);
referenceSurface = SDLTest_ImageBlitBlendAdd();
/* Make current and compare */
SDL_RenderPresent(renderer);
/* Compare, then Present */
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED);
SDL_RenderPresent(renderer);
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
......@@ -704,9 +730,10 @@ render_testBlitBlend (void *arg)
_testBlitBlendMode(tface, SDL_BLENDMODE_MOD);
referenceSurface = SDLTest_ImageBlitBlendMod();
/* Make current and compare */
SDL_RenderPresent(renderer);
/* Compare, then Present */
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED);
SDL_RenderPresent(renderer);
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
......@@ -723,26 +750,39 @@ render_testBlitBlend (void *arg)
/* Set color mod. */
ret = SDL_SetTextureColorMod(tface, (255 / nj) * j, (255 / ni) * i, (255 / nj) * j);
if (ret != 0) checkFailCount1++;
if (ret != 0) {
checkFailCount1++;
}
/* Set alpha mod. */
ret = SDL_SetTextureAlphaMod(tface, (100 / ni) * i);
if (ret != 0) checkFailCount2++;
if (ret != 0) {
checkFailCount2++;
}
/* Crazy blending mode magic. */
mode = (i / 4 * j / 4) % 4;
if (mode==0) mode = SDL_BLENDMODE_NONE;
else if (mode==1) mode = SDL_BLENDMODE_BLEND;
else if (mode==2) mode = SDL_BLENDMODE_ADD;
else if (mode==3) mode = SDL_BLENDMODE_MOD;
if (mode == 0) {
mode = SDL_BLENDMODE_NONE;
} else if (mode == 1) {
mode = SDL_BLENDMODE_BLEND;
} else if (mode == 2) {
mode = SDL_BLENDMODE_ADD;
} else if (mode == 3) {
mode = SDL_BLENDMODE_MOD;
}
ret = SDL_SetTextureBlendMode(tface, (SDL_BlendMode)mode);
if (ret != 0) checkFailCount3++;
if (ret != 0) {
checkFailCount3++;
}
/* Blitting. */
rect.x = i;
rect.y = j;
ret = SDL_RenderCopy(renderer, tface, NULL, &rect);
if (ret != 0) checkFailCount4++;
if (ret != 0) {
checkFailCount4++;
}
}
}
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i", checkFailCount1);
......@@ -753,26 +793,26 @@ render_testBlitBlend (void *arg)
/* Clean up. */
SDL_DestroyTexture(tface);
/* Make current */
SDL_RenderPresent(renderer);
/* Check to see if final image matches. */
referenceSurface = SDLTest_ImageBlitBlendAll();
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED);
/* Make current */
SDL_RenderPresent(renderer);
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
return TEST_COMPLETED;
}
/**
* @brief Checks to see if functionality is supported. Helper function.
*/
static int
_isSupported(int code)
{
return (code == 0);
return code == 0;
}
/**
......@@ -792,24 +832,28 @@ _hasDrawColor (void)
/* Set color. */
ret = SDL_SetRenderDrawColor(renderer, 100, 100, 100, 100);
if (!_isSupported(ret))
if (!_isSupported(ret)) {
fail = 1;
}
ret = SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a);
if (!_isSupported(ret))
if (!_isSupported(ret)) {
fail = 1;
}
/* Restore natural. */
ret = SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
if (!_isSupported(ret))
if (!_isSupported(ret)) {
fail = 1;
}
/* Something failed, consider not available. */
if (fail)
if (fail) {
return 0;
}
/* Not set properly, consider failed. */
else if ((r != 100) || (g != 100) || (b != 100) || (a != 100))
else if ((r != 100) || (g != 100) || (b != 100) || (a != 100)) {
return 0;
}
return 1;
}
......@@ -830,46 +874,57 @@ _hasBlendModes (void)
fail = 0;
ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
if (!_isSupported(ret))
if (!_isSupported(ret)) {
fail = 1;
}
ret = SDL_GetRenderDrawBlendMode(renderer, &mode);
if (!_isSupported(ret))
if (!_isSupported(ret)) {
fail = 1;
}
ret = (mode != SDL_BLENDMODE_BLEND);
if (!_isSupported(ret))
if (!_isSupported(ret)) {
fail = 1;
}
ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_ADD);
if (!_isSupported(ret))
if (!_isSupported(ret)) {
fail = 1;
}
ret = SDL_GetRenderDrawBlendMode(renderer, &mode);
if (!_isSupported(ret))
if (!_isSupported(ret)) {
fail = 1;
}
ret = (mode != SDL_BLENDMODE_ADD);
if (!_isSupported(ret))
if (!_isSupported(ret)) {
fail = 1;
}
ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_MOD);
if (!_isSupported(ret))
if (!_isSupported(ret)) {
fail = 1;
}
ret = SDL_GetRenderDrawBlendMode(renderer, &mode);
if (!_isSupported(ret))
if (!_isSupported(ret)) {
fail = 1;
}
ret = (mode != SDL_BLENDMODE_MOD);
if (!_isSupported(ret))
if (!_isSupported(ret)) {
fail = 1;
}
ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
if (!_isSupported(ret))
if (!_isSupported(ret)) {
fail = 1;
}
ret = SDL_GetRenderDrawBlendMode(renderer, &mode);
if (!_isSupported(ret))
if (!_isSupported(ret)) {
fail = 1;
}
ret = (mode != SDL_BLENDMODE_NONE);
if (!_isSupported(ret))
if (!_isSupported(ret)) {
fail = 1;
}
return !fail;
}
/**
* @brief Loads the test image 'Face' as texture. Helper function.
*
......@@ -897,7 +952,6 @@ _loadTestFace(void)
return tface;
}
/**
* @brief Test to see if can set texture color mode. Helper function.
*
......@@ -916,25 +970,29 @@ _hasTexColor (void)
/* Get test face. */
tface = _loadTestFace();
if (tface == NULL)
if (tface == NULL) {
return 0;
}
/* See if supported. */
fail = 0;
ret = SDL_SetTextureColorMod(tface, 100, 100, 100);
if (!_isSupported(ret))
if (!_isSupported(ret)) {
fail = 1;
}
ret = SDL_GetTextureColorMod(tface, &r, &g, &b);
if (!_isSupported(ret))
if (!_isSupported(ret)) {
fail = 1;
}
/* Clean up. */
SDL_DestroyTexture(tface);
if (fail)
if (fail) {
return 0;
else if ((r != 100) || (g != 100) || (b != 100))
} else if ((r != 100) || (g != 100) || (b != 100)) {
return 0;
}
return 1;
}
......@@ -956,25 +1014,29 @@ _hasTexAlpha(void)
/* Get test face. */
tface = _loadTestFace();
if (tface == NULL)
if (tface == NULL) {
return 0;
}
/* See if supported. */
fail = 0;
ret = SDL_SetTextureAlphaMod(tface, 100);
if (!_isSupported(ret))
if (!_isSupported(ret)) {
fail = 1;
}
ret = SDL_GetTextureAlphaMod(tface, &a);
if (!_isSupported(ret))
if (!_isSupported(ret)) {
fail = 1;
}
/* Clean up. */
SDL_DestroyTexture(tface);
if (fail)
if (fail) {
return 0;
else if (a != 100)
} else if (a != 100) {
return 0;
}
return 1;
}
......@@ -999,7 +1061,9 @@ _compare(SDL_Surface *referenceSurface, int allowable_error)
/* Read pixels. */
pixels = (Uint8 *)SDL_malloc(4 * TESTRENDER_SCREEN_W * TESTRENDER_SCREEN_H);
SDLTest_AssertCheck(pixels != NULL, "Validate allocated temp pixel buffer");
if (pixels == NULL) return;
if (pixels == NULL) {
return;
}
/* Explicitly specify the rect in case the window isn't the expected size... */
rect.x = 0;
......@@ -1061,29 +1125,36 @@ _clearScreen(void)
/* ================= Test References ================== */
/* Render test cases */
static const SDLTest_TestCaseReference renderTest1 =
{ (SDLTest_TestCaseFp)render_testGetNumRenderDrivers, "render_testGetNumRenderDrivers", "Tests call to SDL_GetNumRenderDrivers", TEST_ENABLED };
static const SDLTest_TestCaseReference renderTest1 = {
(SDLTest_TestCaseFp)render_testGetNumRenderDrivers, "render_testGetNumRenderDrivers", "Tests call to SDL_GetNumRenderDrivers", TEST_ENABLED
};
static const SDLTest_TestCaseReference renderTest2 =
{ (SDLTest_TestCaseFp)render_testPrimitives, "render_testPrimitives", "Tests rendering primitives", TEST_ENABLED };
static const SDLTest_TestCaseReference renderTest2 = {
(SDLTest_TestCaseFp)render_testPrimitives, "render_testPrimitives", "Tests rendering primitives", TEST_ENABLED
};
/* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
static const SDLTest_TestCaseReference renderTest3 =
{ (SDLTest_TestCaseFp)render_testPrimitivesBlend, "render_testPrimitivesBlend", "Tests rendering primitives with blending", TEST_DISABLED };
static const SDLTest_TestCaseReference renderTest3 = {
(SDLTest_TestCaseFp)render_testPrimitivesBlend, "render_testPrimitivesBlend", "Tests rendering primitives with blending", TEST_DISABLED
};
static const SDLTest_TestCaseReference renderTest4 =
{ (SDLTest_TestCaseFp)render_testBlit, "render_testBlit", "Tests blitting", TEST_ENABLED };
static const SDLTest_TestCaseReference renderTest4 = {
(SDLTest_TestCaseFp)render_testBlit, "render_testBlit", "Tests blitting", TEST_ENABLED
};
static const SDLTest_TestCaseReference renderTest5 =
{ (SDLTest_TestCaseFp)render_testBlitColor, "render_testBlitColor", "Tests blitting with color", TEST_ENABLED };
static const SDLTest_TestCaseReference renderTest5 = {
(SDLTest_TestCaseFp)render_testBlitColor, "render_testBlitColor", "Tests blitting with color", TEST_ENABLED
};
/* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
static const SDLTest_TestCaseReference renderTest6 =
{ (SDLTest_TestCaseFp)render_testBlitAlpha, "render_testBlitAlpha", "Tests blitting with alpha", TEST_DISABLED };
static const SDLTest_TestCaseReference renderTest6 = {
(SDLTest_TestCaseFp)render_testBlitAlpha, "render_testBlitAlpha", "Tests blitting with alpha", TEST_DISABLED
};
/* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
static const SDLTest_TestCaseReference renderTest7 =
{ (SDLTest_TestCaseFp)render_testBlitBlend, "render_testBlitBlend", "Tests blitting with blending", TEST_DISABLED };
static const SDLTest_TestCaseReference renderTest7 = {
(SDLTest_TestCaseFp)render_testBlitBlend, "render_testBlitBlend", "Tests blitting with blending", TEST_DISABLED
};
/* Sequence of Render test cases */
static const SDLTest_TestCaseReference *renderTests[] = {
......
......@@ -10,7 +10,9 @@
*/
/* quiet windows compiler warnings */
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdio.h>
......@@ -29,8 +31,7 @@ static const char RWopsAlphabetString[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/* Fixture */
void
RWopsSetUp(void *arg)
void RWopsSetUp(void *arg)
{
size_t fileLen;
FILE *handle;
......@@ -38,14 +39,16 @@ RWopsSetUp(void *arg)
int result;
/* Clean up from previous runs (if any); ignore errors */
remove(RWopsReadTestFilename);
remove(RWopsWriteTestFilename);
remove(RWopsAlphabetFilename);
(void)remove(RWopsReadTestFilename);
(void)remove(RWopsWriteTestFilename);
(void)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;
if (handle == NULL) {
return;
}
/* Write some known text into it */
fileLen = SDL_strlen(RWopsHelloWorldTestString);
......@@ -57,7 +60,9 @@ RWopsSetUp(void *arg)
/* Create a second test file */
handle = fopen(RWopsAlphabetFilename, "w");
SDLTest_AssertCheck(handle != NULL, "Verify creation of file '%s' returned non NULL handle", RWopsAlphabetFilename);
if (handle == NULL) return;
if (handle == NULL) {
return;
}
/* Write alphabet text into it */
fileLen = SDL_strlen(RWopsAlphabetString);
......@@ -69,15 +74,14 @@ RWopsSetUp(void *arg)
SDLTest_AssertPass("Creation of test file completed");
}
void
RWopsTearDown(void *arg)
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);
(void)remove(RWopsWriteTestFilename);
result = remove(RWopsAlphabetFilename);
SDLTest_AssertCheck(result == 0, "Verify result from remove(%s), expected 0, got %i", RWopsAlphabetFilename, result);
......@@ -91,8 +95,7 @@ RWopsTearDown(void *arg)
* http://wiki.libsdl.org/SDL_RWseek
* http://wiki.libsdl.org/SDL_RWread
*/
void
_testGenericRWopsValidations(SDL_RWops *rw, int write)
void _testGenericRWopsValidations(SDL_RWops *rw, int write)
{
char buf[sizeof(RWopsHelloWorldTestString)];
Sint64 i;
......@@ -112,8 +115,7 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write)
SDLTest_AssertPass("Call to SDL_RWwrite succeeded");
if (write) {
SDLTest_AssertCheck(s == (size_t)1, "Verify result of writing one byte with SDL_RWwrite, expected 1, got %i", (int)s);
}
else {
} else {
SDLTest_AssertCheck(s == (size_t)0, "Verify result of writing with SDL_RWwrite, expected: 0, got %i", (int)s);
}
......@@ -171,8 +173,7 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write)
* \sa http://wiki.libsdl.org/SDL_RWFromFile
*
*/
int
rwops_testParamNegative (void)
int rwops_testParamNegative(void)
{
SDL_RWops *rwops;
......@@ -197,7 +198,7 @@ rwops_testParamNegative (void)
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);
rwops = SDL_RWFromMem(NULL, 10);
SDLTest_AssertPass("Call to SDL_RWFromMem(NULL, 10) succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromMem(NULL, 10) returns NULL");
......@@ -218,8 +219,7 @@ rwops_testParamNegative (void)
* \sa http://wiki.libsdl.org/SDL_RWFromMem
* \sa http://wiki.libsdl.org/SDL_RWClose
*/
int
rwops_testMem (void)
int rwops_testMem(void)
{
char mem[sizeof(RWopsHelloWorldTestString)];
SDL_RWops *rw;
......@@ -234,10 +234,12 @@ rwops_testMem (void)
SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromMem does not return NULL");
/* Bail out if NULL */
if (rw == NULL) return TEST_ABORTED;
if (rw == NULL) {
return TEST_ABORTED;
}
/* Check type */
SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY, "Verify RWops type is SDL_RWOPS_MEMORY; expected: %d, got: %d", SDL_RWOPS_MEMORY, rw->type);
SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY, "Verify RWops type is SDL_RWOPS_MEMORY; expected: %d, got: %" SDL_PRIu32, SDL_RWOPS_MEMORY, rw->type);
/* Run generic tests */
_testGenericRWopsValidations(rw, 1);
......@@ -250,7 +252,6 @@ rwops_testMem (void)
return TEST_COMPLETED;
}
/**
* @brief Tests opening from memory.
*
......@@ -258,8 +259,7 @@ rwops_testMem (void)
* http://wiki.libsdl.org/SDL_RWFromConstMem
* http://wiki.libsdl.org/SDL_RWClose
*/
int
rwops_testConstMem (void)
int rwops_testConstMem(void)
{
SDL_RWops *rw;
int result;
......@@ -270,10 +270,12 @@ rwops_testConstMem (void)
SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromConstMem does not return NULL");
/* Bail out if NULL */
if (rw == NULL) return TEST_ABORTED;
if (rw == NULL) {
return TEST_ABORTED;
}
/* Check type */
SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY_RO, "Verify RWops type is SDL_RWOPS_MEMORY_RO; expected: %d, got: %d", SDL_RWOPS_MEMORY_RO, rw->type);
SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY_RO, "Verify RWops type is SDL_RWOPS_MEMORY_RO; expected: %d, got: %" SDL_PRIu32, SDL_RWOPS_MEMORY_RO, rw->type);
/* Run generic tests */
_testGenericRWopsValidations(rw, 0);
......@@ -286,7 +288,6 @@ rwops_testConstMem (void)
return TEST_COMPLETED;
}
/**
* @brief Tests reading from file.
*
......@@ -294,8 +295,7 @@ rwops_testConstMem (void)
* http://wiki.libsdl.org/SDL_RWFromFile
* http://wiki.libsdl.org/SDL_RWClose
*/
int
rwops_testFileRead(void)
int rwops_testFileRead(void)
{
SDL_RWops *rw;
int result;
......@@ -306,7 +306,9 @@ rwops_testFileRead(void)
SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in read mode does not return NULL");
/* Bail out if NULL */
if (rw == NULL) return TEST_ABORTED;
if (rw == NULL) {
return TEST_ABORTED;
}
/* Check type */
#if defined(__ANDROID__)
......@@ -320,7 +322,7 @@ rwops_testFileRead(void)
#else
SDLTest_AssertCheck(
rw->type == SDL_RWOPS_STDFILE,
"Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type);
"Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %" SDL_PRIu32, SDL_RWOPS_STDFILE, rw->type);
#endif
/* Run generic tests */
......@@ -341,8 +343,7 @@ rwops_testFileRead(void)
* http://wiki.libsdl.org/SDL_RWFromFile
* http://wiki.libsdl.org/SDL_RWClose
*/
int
rwops_testFileWrite(void)
int rwops_testFileWrite(void)
{
SDL_RWops *rw;
int result;
......@@ -353,7 +354,9 @@ rwops_testFileWrite(void)
SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in write mode does not return NULL");
/* Bail out if NULL */
if (rw == NULL) return TEST_ABORTED;
if (rw == NULL) {
return TEST_ABORTED;
}
/* Check type */
#if defined(__ANDROID__)
......@@ -367,7 +370,7 @@ rwops_testFileWrite(void)
#else
SDLTest_AssertCheck(
rw->type == SDL_RWOPS_STDFILE,
"Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type);
"Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %" SDL_PRIu32, SDL_RWOPS_STDFILE, rw->type);
#endif
/* Run generic tests */
......@@ -381,7 +384,6 @@ rwops_testFileWrite(void)
return TEST_COMPLETED;
}
/**
* @brief Tests reading from file handle
*
......@@ -393,6 +395,7 @@ rwops_testFileWrite(void)
int
rwops_testFPRead(void)
{
#ifdef HAVE_LIBC
FILE *fp;
SDL_RWops *rw;
int result;
......@@ -418,7 +421,7 @@ rwops_testFPRead(void)
/* 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);
"Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %" SDL_PRIu32, SDL_RWOPS_STDFILE, rw->type);
/* Run generic tests */
_testGenericRWopsValidations( rw, 0 );
......@@ -428,6 +431,8 @@ rwops_testFPRead(void)
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
#endif /* HAVE_LIBC */
return TEST_COMPLETED;
}
......@@ -443,6 +448,7 @@ rwops_testFPRead(void)
int
rwops_testFPWrite(void)
{
#ifdef HAVE_LIBC
FILE *fp;
SDL_RWops *rw;
int result;
......@@ -468,7 +474,7 @@ rwops_testFPWrite(void)
/* 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);
"Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %" SDL_PRIu32, SDL_RWOPS_STDFILE, rw->type);
/* Run generic tests */
_testGenericRWopsValidations( rw, 1 );
......@@ -478,6 +484,8 @@ rwops_testFPWrite(void)
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
#endif /* HAVE_LIBC */
return TEST_COMPLETED;
}
......@@ -487,19 +495,20 @@ rwops_testFPWrite(void)
* \sa http://wiki.libsdl.org/SDL_AllocRW
* \sa http://wiki.libsdl.org/SDL_FreeRW
*/
int
rwops_testAllocFree (void)
int rwops_testAllocFree(void)
{
/* Allocate context */
SDL_RWops *rw = SDL_AllocRW();
SDLTest_AssertPass("Call to SDL_AllocRW() succeeded");
SDLTest_AssertCheck(rw != NULL, "Validate result from SDL_AllocRW() is not NULL");
if (rw==NULL) return TEST_ABORTED;
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);
"Verify RWops type is SDL_RWOPS_UNKNOWN; expected: %d, got: %" SDL_PRIu32, SDL_RWOPS_UNKNOWN, rw->type);
/* Free context again */
SDL_FreeRW(rw);
......@@ -514,8 +523,7 @@ rwops_testAllocFree (void)
* \sa http://wiki.libsdl.org/SDL_RWFromMem
* \sa http://wiki.libsdl.org/SDL_RWFromFile
*/
int
rwops_testCompareRWFromMemWithRWFromFile(void)
int rwops_testCompareRWFromMemWithRWFromFile(void)
{
int slen = 26;
char buffer_file[27];
......@@ -529,9 +537,7 @@ rwops_testCompareRWFromMemWithRWFromFile(void)
int size;
int result;
for (size=5; size<10; size++)
{
for (size = 5; size < 10; size++) {
/* Terminate buffer */
buffer_file[slen] = 0;
buffer_mem[slen] = 0;
......@@ -583,8 +589,7 @@ rwops_testCompareRWFromMemWithRWFromFile(void)
* http://wiki.libsdl.org/SDL_ReadBE16
* http://wiki.libsdl.org/SDL_WriteBE16
*/
int
rwops_testFileWriteReadEndian(void)
int rwops_testFileWriteReadEndian(void)
{
SDL_RWops *rw;
Sint64 result;
......@@ -608,6 +613,7 @@ rwops_testFileWriteReadEndian(void)
/* Create test data */
switch (mode) {
default:
case 0:
SDLTest_Log("All 0 values");
BE16value = 0;
......@@ -643,7 +649,9 @@ rwops_testFileWriteReadEndian(void)
SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in write mode does not return NULL");
/* Bail out if NULL */
if (rw == NULL) return TEST_ABORTED;
if (rw == NULL) {
return TEST_ABORTED;
}
/* Write test data */
objectsWritten = SDL_WriteBE16(rw, BE16value);
......@@ -676,7 +684,7 @@ rwops_testFileWriteReadEndian(void)
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);
SDLTest_AssertCheck(BE32test == BE32value, "Validate return value from SDL_ReadBE32, expected: %" SDL_PRIu32 ", got: %" SDL_PRIu32, BE32value, BE32test);
BE64test = SDL_ReadBE64(rw);
SDLTest_AssertPass("Call to SDL_ReadBE64()");
SDLTest_AssertCheck(BE64test == BE64value, "Validate return value from SDL_ReadBE64, expected: %" SDL_PRIu64 ", got: %" SDL_PRIu64, BE64value, BE64test);
......@@ -685,7 +693,7 @@ rwops_testFileWriteReadEndian(void)
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);
SDLTest_AssertCheck(LE32test == LE32value, "Validate return value from SDL_ReadLE32, expected: %" SDL_PRIu32 ", got: %" SDL_PRIu32, LE32value, LE32test);
LE64test = SDL_ReadLE64(rw);
SDLTest_AssertPass("Call to SDL_ReadLE64()");
SDLTest_AssertCheck(LE64test == LE64value, "Validate return value from SDL_ReadLE64, expected: %" SDL_PRIu64 ", got: %" SDL_PRIu64, LE64value, LE64test);
......@@ -699,24 +707,28 @@ rwops_testFileWriteReadEndian(void)
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* RWops test cases */
static const SDLTest_TestCaseReference rwopsTest1 =
{ (SDLTest_TestCaseFp)rwops_testParamNegative, "rwops_testParamNegative", "Negative test for SDL_RWFromFile parameters", TEST_ENABLED };
static const SDLTest_TestCaseReference rwopsTest1 = {
(SDLTest_TestCaseFp)rwops_testParamNegative, "rwops_testParamNegative", "Negative test for SDL_RWFromFile parameters", TEST_ENABLED
};
static const SDLTest_TestCaseReference rwopsTest2 =
{ (SDLTest_TestCaseFp)rwops_testMem, "rwops_testMem", "Tests opening from memory", TEST_ENABLED };
static const SDLTest_TestCaseReference rwopsTest2 = {
(SDLTest_TestCaseFp)rwops_testMem, "rwops_testMem", "Tests opening from memory", TEST_ENABLED
};
static const SDLTest_TestCaseReference rwopsTest3 =
{ (SDLTest_TestCaseFp)rwops_testConstMem, "rwops_testConstMem", "Tests opening from (const) memory", TEST_ENABLED };
static const SDLTest_TestCaseReference rwopsTest3 = {
(SDLTest_TestCaseFp)rwops_testConstMem, "rwops_testConstMem", "Tests opening from (const) memory", TEST_ENABLED
};
static const SDLTest_TestCaseReference rwopsTest4 =
{ (SDLTest_TestCaseFp)rwops_testFileRead, "rwops_testFileRead", "Tests reading from a file", TEST_ENABLED };
static const SDLTest_TestCaseReference rwopsTest4 = {
(SDLTest_TestCaseFp)rwops_testFileRead, "rwops_testFileRead", "Tests reading from a file", TEST_ENABLED
};
static const SDLTest_TestCaseReference rwopsTest5 =
{ (SDLTest_TestCaseFp)rwops_testFileWrite, "rwops_testFileWrite", "Test writing to a file", TEST_ENABLED };
static const SDLTest_TestCaseReference rwopsTest5 = {
(SDLTest_TestCaseFp)rwops_testFileWrite, "rwops_testFileWrite", "Test writing to a file", TEST_ENABLED
};
static const SDLTest_TestCaseReference rwopsTest6 =
{ (SDLTest_TestCaseFp)rwops_testFPRead, "rwops_testFPRead", "Test reading from file pointer", TEST_ENABLED };
......