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

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
Show changes
Showing with 2334 additions and 1634 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
......@@ -18,23 +18,20 @@
after calling each function.
*/
static
const char *
static const char *
tf(SDL_bool _tf)
{
static const char *t = "TRUE";
static const char *f = "FALSE";
if (_tf)
{
return t;
if (_tf) {
return t;
}
return f;
}
static
void RunBasicTest()
static void RunBasicTest()
{
int value;
SDL_SpinLock lock = 0;
......@@ -96,15 +93,16 @@ void RunBasicTest()
/* Number of concurrent incrementers */
#define NThreads 2
#define CountInc 100
#define VALBITS (sizeof(atomicValue)*8)
#define VALBITS (sizeof(atomicValue) * 8)
#define atomicValue int
#define CountTo ((atomicValue)((unsigned int)(1<<(VALBITS-1))-1))
#define NInter (CountTo/CountInc/NThreads)
#define Expect (CountTo-NInter*CountInc*NThreads)
#define CountTo ((atomicValue)((unsigned int)(1 << (VALBITS - 1)) - 1))
#define NInter (CountTo / CountInc / NThreads)
#define Expect (CountTo - NInter * CountInc * NThreads)
enum {
CountTo_GreaterThanZero = CountTo > 0,
enum
{
CountTo_GreaterThanZero = CountTo > 0,
};
SDL_COMPILE_TIME_ASSERT(size, CountTo_GreaterThanZero); /* check for rollover */
......@@ -116,25 +114,23 @@ static SDL_atomic_t threadsRunning;
static SDL_sem *threadDone;
static
int SDLCALL adder(void* junk)
static int SDLCALL adder(void *junk)
{
unsigned long N=NInter;
SDL_Log("Thread subtracting %d %lu times\n",CountInc,N);
unsigned long N = NInter;
SDL_Log("Thread subtracting %d %lu times\n", CountInc, N);
while (N--) {
SDL_AtomicAdd(&good, -CountInc);
bad-=CountInc;
bad -= CountInc;
}
SDL_AtomicAdd(&threadsRunning, -1);
SDL_SemPost(threadDone);
return 0;
}
static
void runAdder(void)
static void runAdder(void)
{
Uint32 start, end;
int T=NThreads;
int T = NThreads;
start = SDL_GetTicks();
......@@ -142,11 +138,13 @@ void runAdder(void)
SDL_AtomicSet(&threadsRunning, NThreads);
while (T--)
while (T--) {
SDL_CreateThread(adder, "Adder", NULL);
}
while (SDL_AtomicGet(&threadsRunning) > 0)
while (SDL_AtomicGet(&threadsRunning) > 0) {
SDL_SemWait(threadDone);
}
SDL_DestroySemaphore(threadDone);
......@@ -155,8 +153,7 @@ void runAdder(void)
SDL_Log("Finished in %f sec\n", (end - start) / 1000.f);
}
static
void RunEpicTest()
static void RunEpicTest()
{
int b;
atomicValue v;
......@@ -164,80 +161,80 @@ void RunEpicTest()
SDL_Log("\nepic test---------------------------------------\n\n");
SDL_Log("Size asserted to be >= 32-bit\n");
SDL_assert(sizeof(atomicValue)>=4);
SDL_assert(sizeof(atomicValue) >= 4);
SDL_Log("Check static initializer\n");
v=SDL_AtomicGet(&good);
SDL_assert(v==42);
v = SDL_AtomicGet(&good);
SDL_assert(v == 42);
SDL_assert(bad==42);
SDL_assert(bad == 42);
SDL_Log("Test negative values\n");
SDL_AtomicSet(&good, -5);
v=SDL_AtomicGet(&good);
SDL_assert(v==-5);
v = SDL_AtomicGet(&good);
SDL_assert(v == -5);
SDL_Log("Verify maximum value\n");
SDL_AtomicSet(&good, CountTo);
v=SDL_AtomicGet(&good);
SDL_assert(v==CountTo);
v = SDL_AtomicGet(&good);
SDL_assert(v == CountTo);
SDL_Log("Test compare and exchange\n");
b=SDL_AtomicCAS(&good, 500, 43);
b = SDL_AtomicCAS(&good, 500, 43);
SDL_assert(!b); /* no swap since CountTo!=500 */
v=SDL_AtomicGet(&good);
SDL_assert(v==CountTo); /* ensure no swap */
v = SDL_AtomicGet(&good);
SDL_assert(v == CountTo); /* ensure no swap */
b=SDL_AtomicCAS(&good, CountTo, 44);
b = SDL_AtomicCAS(&good, CountTo, 44);
SDL_assert(!!b); /* will swap */
v=SDL_AtomicGet(&good);
SDL_assert(v==44);
v = SDL_AtomicGet(&good);
SDL_assert(v == 44);
SDL_Log("Test Add\n");
v=SDL_AtomicAdd(&good, 1);
SDL_assert(v==44);
v=SDL_AtomicGet(&good);
SDL_assert(v==45);
v = SDL_AtomicAdd(&good, 1);
SDL_assert(v == 44);
v = SDL_AtomicGet(&good);
SDL_assert(v == 45);
v=SDL_AtomicAdd(&good, 10);
SDL_assert(v==45);
v=SDL_AtomicGet(&good);
SDL_assert(v==55);
v = SDL_AtomicAdd(&good, 10);
SDL_assert(v == 45);
v = SDL_AtomicGet(&good);
SDL_assert(v == 55);
SDL_Log("Test Add (Negative values)\n");
v=SDL_AtomicAdd(&good, -20);
SDL_assert(v==55);
v=SDL_AtomicGet(&good);
SDL_assert(v==35);
v = SDL_AtomicAdd(&good, -20);
SDL_assert(v == 55);
v = SDL_AtomicGet(&good);
SDL_assert(v == 35);
v=SDL_AtomicAdd(&good, -50); /* crossing zero down */
SDL_assert(v==35);
v=SDL_AtomicGet(&good);
SDL_assert(v==-15);
v = SDL_AtomicAdd(&good, -50); /* crossing zero down */
SDL_assert(v == 35);
v = SDL_AtomicGet(&good);
SDL_assert(v == -15);
v=SDL_AtomicAdd(&good, 30); /* crossing zero up */
SDL_assert(v==-15);
v=SDL_AtomicGet(&good);
SDL_assert(v==15);
v = SDL_AtomicAdd(&good, 30); /* crossing zero up */
SDL_assert(v == -15);
v = SDL_AtomicGet(&good);
SDL_assert(v == 15);
SDL_Log("Reset before count down test\n");
SDL_AtomicSet(&good, CountTo);
v=SDL_AtomicGet(&good);
SDL_assert(v==CountTo);
v = SDL_AtomicGet(&good);
SDL_assert(v == CountTo);
bad=CountTo;
SDL_assert(bad==CountTo);
bad = CountTo;
SDL_assert(bad == CountTo);
SDL_Log("Counting down from %d, Expect %d remaining\n",CountTo,Expect);
SDL_Log("Counting down from %d, Expect %d remaining\n", CountTo, Expect);
runAdder();
v=SDL_AtomicGet(&good);
SDL_Log("Atomic %d Non-Atomic %d\n",v,bad);
SDL_assert(v==Expect);
SDL_assert(bad!=Expect);
v = SDL_AtomicGet(&good);
SDL_Log("Atomic %d Non-Atomic %d\n", v, bad);
SDL_assert(v == Expect);
SDL_assert(bad != Expect);
}
/* End atomic operation test */
......@@ -251,13 +248,13 @@ void RunEpicTest()
*/
#define TEST_SPINLOCK_FIFO
#define NUM_READERS 4
#define NUM_WRITERS 4
#define EVENTS_PER_WRITER 1000000
#define NUM_READERS 4
#define NUM_WRITERS 4
#define EVENTS_PER_WRITER 1000000
/* The number of entries must be a power of 2 */
#define MAX_ENTRIES 256
#define WRAP_MASK (MAX_ENTRIES-1)
#define WRAP_MASK (MAX_ENTRIES - 1)
typedef struct
{
......@@ -269,22 +266,22 @@ typedef struct
{
SDL_EventQueueEntry entries[MAX_ENTRIES];
char cache_pad1[SDL_CACHELINE_SIZE-((sizeof(SDL_EventQueueEntry)*MAX_ENTRIES)%SDL_CACHELINE_SIZE)];
char cache_pad1[SDL_CACHELINE_SIZE - ((sizeof(SDL_EventQueueEntry) * MAX_ENTRIES) % SDL_CACHELINE_SIZE)];
SDL_atomic_t enqueue_pos;
char cache_pad2[SDL_CACHELINE_SIZE-sizeof(SDL_atomic_t)];
char cache_pad2[SDL_CACHELINE_SIZE - sizeof(SDL_atomic_t)];
SDL_atomic_t dequeue_pos;
char cache_pad3[SDL_CACHELINE_SIZE-sizeof(SDL_atomic_t)];
char cache_pad3[SDL_CACHELINE_SIZE - sizeof(SDL_atomic_t)];
#ifdef TEST_SPINLOCK_FIFO
SDL_SpinLock lock;
SDL_atomic_t rwcount;
SDL_atomic_t watcher;
char cache_pad4[SDL_CACHELINE_SIZE-sizeof(SDL_SpinLock)-2*sizeof(SDL_atomic_t)];
char cache_pad4[SDL_CACHELINE_SIZE - sizeof(SDL_SpinLock) - 2 * sizeof(SDL_atomic_t)];
#endif
SDL_atomic_t active;
......@@ -328,14 +325,14 @@ static SDL_bool EnqueueEvent_LockFree(SDL_EventQueue *queue, const SDL_Event *ev
#endif
queue_pos = (unsigned)SDL_AtomicGet(&queue->enqueue_pos);
for ( ; ; ) {
for (;;) {
entry = &queue->entries[queue_pos & WRAP_MASK];
entry_seq = (unsigned)SDL_AtomicGet(&entry->sequence);
delta = (int)(entry_seq - queue_pos);
if (delta == 0) {
/* The entry and the queue position match, try to increment the queue position */
if (SDL_AtomicCAS(&queue->enqueue_pos, (int)queue_pos, (int)(queue_pos+1))) {
if (SDL_AtomicCAS(&queue->enqueue_pos, (int)queue_pos, (int)(queue_pos + 1))) {
/* We own the object, fill it! */
entry->event = *event;
SDL_AtomicSet(&entry->sequence, (int)(queue_pos + 1));
......@@ -353,7 +350,7 @@ static SDL_bool EnqueueEvent_LockFree(SDL_EventQueue *queue, const SDL_Event *ev
}
#ifdef TEST_SPINLOCK_FIFO
(void) SDL_AtomicDecRef(&queue->rwcount);
(void)SDL_AtomicDecRef(&queue->rwcount);
#endif
return status;
}
......@@ -375,17 +372,17 @@ static SDL_bool DequeueEvent_LockFree(SDL_EventQueue *queue, SDL_Event *event)
#endif
queue_pos = (unsigned)SDL_AtomicGet(&queue->dequeue_pos);
for ( ; ; ) {
for (;;) {
entry = &queue->entries[queue_pos & WRAP_MASK];
entry_seq = (unsigned)SDL_AtomicGet(&entry->sequence);
delta = (int)(entry_seq - (queue_pos + 1));
if (delta == 0) {
/* The entry and the queue position match, try to increment the queue position */
if (SDL_AtomicCAS(&queue->dequeue_pos, (int)queue_pos, (int)(queue_pos+1))) {
if (SDL_AtomicCAS(&queue->dequeue_pos, (int)queue_pos, (int)(queue_pos + 1))) {
/* We own the object, fill it! */
*event = entry->event;
SDL_AtomicSet(&entry->sequence, (int)(queue_pos+MAX_ENTRIES));
SDL_AtomicSet(&entry->sequence, (int)(queue_pos + MAX_ENTRIES));
status = SDL_TRUE;
break;
}
......@@ -400,7 +397,7 @@ static SDL_bool DequeueEvent_LockFree(SDL_EventQueue *queue, SDL_Event *event)
}
#ifdef TEST_SPINLOCK_FIFO
(void) SDL_AtomicDecRef(&queue->rwcount);
(void)SDL_AtomicDecRef(&queue->rwcount);
#endif
return status;
}
......@@ -471,17 +468,15 @@ static SDL_bool DequeueEvent_Mutex(SDL_EventQueue *queue, SDL_Event *event)
return status;
}
static SDL_sem *writersDone;
static SDL_sem *readersDone;
typedef struct
{
SDL_EventQueue *queue;
int index;
char padding1[SDL_CACHELINE_SIZE-(sizeof(SDL_EventQueue*)+sizeof(int))%SDL_CACHELINE_SIZE];
char padding1[SDL_CACHELINE_SIZE - (sizeof(SDL_EventQueue *) + sizeof(int)) % SDL_CACHELINE_SIZE];
int waits;
SDL_bool lock_free;
char padding2[SDL_CACHELINE_SIZE-sizeof(int)-sizeof(SDL_bool)];
char padding2[SDL_CACHELINE_SIZE - sizeof(int) - sizeof(SDL_bool)];
SDL_Thread *thread;
} WriterData;
typedef struct
......@@ -490,10 +485,11 @@ typedef struct
int counters[NUM_WRITERS];
int waits;
SDL_bool lock_free;
char padding[SDL_CACHELINE_SIZE-(sizeof(SDL_EventQueue*)+sizeof(int)*NUM_WRITERS+sizeof(int)+sizeof(SDL_bool))%SDL_CACHELINE_SIZE];
char padding[SDL_CACHELINE_SIZE - (sizeof(SDL_EventQueue *) + sizeof(int) * NUM_WRITERS + sizeof(int) + sizeof(SDL_bool)) % SDL_CACHELINE_SIZE];
SDL_Thread *thread;
} ReaderData;
static int SDLCALL FIFO_Writer(void* _data)
static int SDLCALL FIFO_Writer(void *_data)
{
WriterData *data = (WriterData *)_data;
SDL_EventQueue *queue = data->queue;
......@@ -523,20 +519,19 @@ static int SDLCALL FIFO_Writer(void* _data)
}
}
}
SDL_SemPost(writersDone);
return 0;
}
static int SDLCALL FIFO_Reader(void* _data)
static int SDLCALL FIFO_Reader(void *_data)
{
ReaderData *data = (ReaderData *)_data;
SDL_EventQueue *queue = data->queue;
SDL_Event event;
if (data->lock_free) {
for ( ; ; ) {
for (;;) {
if (DequeueEvent_LockFree(queue, &event)) {
WriterData *writer = (WriterData*)event.user.data1;
WriterData *writer = (WriterData *)event.user.data1;
++data->counters[writer->index];
} else if (SDL_AtomicGet(&queue->active)) {
++data->waits;
......@@ -547,9 +542,9 @@ static int SDLCALL FIFO_Reader(void* _data)
}
}
} else {
for ( ; ; ) {
for (;;) {
if (DequeueEvent_Mutex(queue, &event)) {
WriterData *writer = (WriterData*)event.user.data1;
WriterData *writer = (WriterData *)event.user.data1;
++data->counters[writer->index];
} else if (SDL_AtomicGet(&queue->active)) {
++data->waits;
......@@ -560,13 +555,12 @@ static int SDLCALL FIFO_Reader(void* _data)
}
}
}
SDL_SemPost(readersDone);
return 0;
}
#ifdef TEST_SPINLOCK_FIFO
/* This thread periodically locks the queue for no particular reason */
static int SDLCALL FIFO_Watcher(void* _data)
static int SDLCALL FIFO_Watcher(void *_data)
{
SDL_EventQueue *queue = (SDL_EventQueue *)_data;
......@@ -577,7 +571,7 @@ static int SDLCALL FIFO_Watcher(void* _data)
SDL_Delay(0);
}
/* Do queue manipulation here... */
(void) SDL_AtomicDecRef(&queue->watcher);
(void)SDL_AtomicDecRef(&queue->watcher);
SDL_AtomicUnlock(&queue->lock);
/* Wait a bit... */
......@@ -590,6 +584,7 @@ static int SDLCALL FIFO_Watcher(void* _data)
static void RunFIFOTest(SDL_bool lock_free)
{
SDL_EventQueue queue;
SDL_Thread *fifo_thread = NULL;
WriterData writerData[NUM_WRITERS];
ReaderData readerData[NUM_READERS];
Uint32 start, end;
......@@ -601,9 +596,6 @@ static void RunFIFOTest(SDL_bool lock_free)
SDL_Log("\nFIFO test---------------------------------------\n\n");
SDL_Log("Mode: %s\n", lock_free ? "LockFree" : "Mutex");
readersDone = SDL_CreateSemaphore(0);
writersDone = SDL_CreateSemaphore(0);
SDL_memset(&queue, 0xff, sizeof(queue));
InitEventQueue(&queue);
......@@ -616,7 +608,7 @@ static void RunFIFOTest(SDL_bool lock_free)
#ifdef TEST_SPINLOCK_FIFO
/* Start a monitoring thread */
if (lock_free) {
SDL_CreateThread(FIFO_Watcher, "FIFOWatcher", &queue);
fifo_thread = SDL_CreateThread(FIFO_Watcher, "FIFOWatcher", &queue);
}
#endif
......@@ -625,10 +617,10 @@ static void RunFIFOTest(SDL_bool lock_free)
SDL_zeroa(readerData);
for (i = 0; i < NUM_READERS; ++i) {
char name[64];
SDL_snprintf(name, sizeof (name), "FIFOReader%d", i);
(void)SDL_snprintf(name, sizeof(name), "FIFOReader%d", i);
readerData[i].queue = &queue;
readerData[i].lock_free = lock_free;
SDL_CreateThread(FIFO_Reader, name, &readerData[i]);
readerData[i].thread = SDL_CreateThread(FIFO_Reader, name, &readerData[i]);
}
/* Start up the writers */
......@@ -636,16 +628,16 @@ static void RunFIFOTest(SDL_bool lock_free)
SDL_zeroa(writerData);
for (i = 0; i < NUM_WRITERS; ++i) {
char name[64];
SDL_snprintf(name, sizeof (name), "FIFOWriter%d", i);
(void)SDL_snprintf(name, sizeof(name), "FIFOWriter%d", i);
writerData[i].queue = &queue;
writerData[i].index = i;
writerData[i].lock_free = lock_free;
SDL_CreateThread(FIFO_Writer, name, &writerData[i]);
writerData[i].thread = SDL_CreateThread(FIFO_Writer, name, &writerData[i]);
}
/* Wait for the writers */
for (i = 0; i < NUM_WRITERS; ++i) {
SDL_SemWait(writersDone);
SDL_WaitThread(writerData[i].thread, NULL);
}
/* Shut down the queue so readers exit */
......@@ -653,13 +645,15 @@ static void RunFIFOTest(SDL_bool lock_free)
/* Wait for the readers */
for (i = 0; i < NUM_READERS; ++i) {
SDL_SemWait(readersDone);
SDL_WaitThread(readerData[i].thread, NULL);
}
end = SDL_GetTicks();
SDL_DestroySemaphore(readersDone);
SDL_DestroySemaphore(writersDone);
/* Wait for the FIFO thread */
if (fifo_thread) {
SDL_WaitThread(fifo_thread, NULL);
}
if (!lock_free) {
SDL_DestroyMutex(queue.mutex);
......@@ -671,7 +665,7 @@ static void RunFIFOTest(SDL_bool lock_free)
for (i = 0; i < NUM_WRITERS; ++i) {
SDL_Log("Writer %d wrote %d events, had %d waits\n", i, EVENTS_PER_WRITER, writerData[i].waits);
}
SDL_Log("Writers wrote %d total events\n", NUM_WRITERS*EVENTS_PER_WRITER);
SDL_Log("Writers wrote %d total events\n", NUM_WRITERS * EVENTS_PER_WRITER);
/* Print a breakdown of which readers read messages from which writer */
SDL_Log("\n");
......@@ -683,17 +677,17 @@ static void RunFIFOTest(SDL_bool lock_free)
}
grand_total += total;
SDL_Log("Reader %d read %d events, had %d waits\n", i, total, readerData[i].waits);
SDL_snprintf(textBuffer, sizeof(textBuffer), " { ");
(void)SDL_snprintf(textBuffer, sizeof(textBuffer), " { ");
for (j = 0; j < NUM_WRITERS; ++j) {
if (j > 0) {
len = SDL_strlen(textBuffer);
SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, ", ");
(void)SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, ", ");
}
len = SDL_strlen(textBuffer);
SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, "%d", readerData[i].counters[j]);
(void)SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, "%d", readerData[i].counters[j]);
}
len = SDL_strlen(textBuffer);
SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, " }\n");
(void)SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, " }\n");
SDL_Log("%s", textBuffer);
}
SDL_Log("Readers read %d total events\n", grand_total);
......@@ -702,13 +696,18 @@ static void RunFIFOTest(SDL_bool lock_free)
/* End FIFO test */
/**************************************************************************/
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
RunBasicTest();
if (SDL_getenv("SDL_TESTS_QUICK") != NULL) {
SDL_Log("Not running slower tests");
return 0;
}
RunEpicTest();
/* This test is really slow, so don't run it by default */
#if 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
......@@ -67,9 +67,9 @@ loop()
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
#ifdef __EMSCRIPTEN__
#ifdef __EMSCRIPTEN__
emscripten_cancel_main_loop();
#endif
#endif
exit(0);
}
......@@ -78,16 +78,15 @@ loop()
trying to test the API, so we use SDL_DequeueAudio() here. */
while (SDL_TRUE) {
Uint8 buf[1024];
const Uint32 br = SDL_DequeueAudio(devid_in, buf, sizeof (buf));
const Uint32 br = SDL_DequeueAudio(devid_in, buf, sizeof(buf));
SDL_QueueAudio(devid_out, buf, br);
if (br < sizeof (buf)) {
if (br < sizeof(buf)) {
break;
}
}
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
/* (argv[1] == NULL means "open default device.") */
const char *devname = argv[1];
......@@ -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,10 +26,11 @@
#endif
#include "SDL.h"
#include "testutils.h"
static SDL_AudioSpec spec;
static Uint8 *sound = NULL; /* Pointer to wave data */
static Uint32 soundlen = 0; /* Length of wave data */
static Uint8 *sound = NULL; /* Pointer to wave data */
static Uint32 soundlen = 0; /* Length of wave data */
static int posindex = 0;
static Uint32 positions[64];
......@@ -43,9 +44,9 @@ quit(int rc)
}
void SDLCALL
fillerup(void *_pos, Uint8 * stream, int len)
fillerup(void *_pos, Uint8 *stream, int len)
{
Uint32 pos = *((Uint32 *) _pos);
Uint32 pos = *((Uint32 *)_pos);
Uint8 *waveptr;
int waveleft;
......@@ -64,17 +65,16 @@ fillerup(void *_pos, Uint8 * stream, int len)
}
SDL_memcpy(stream, waveptr, len);
pos += len;
*((Uint32 *) _pos) = pos;
*((Uint32 *)_pos) = pos;
}
static int done = 0;
void
poked(int sig)
void poked(int sig)
{
done = 1;
}
static const char*
static const char *
devtypestr(int iscapture)
{
return iscapture ? "capture" : "output";
......@@ -89,17 +89,18 @@ 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)
SDL_Log("New %s audio device at index %u: %s\n", devtypestr(iscapture), (unsigned int) index, name);
else {
if (name != NULL) {
SDL_Log("New %s audio device at index %u: %s\n", devtypestr(iscapture), (unsigned int)index, name);
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Got new %s device at index %u, but failed to get the name: %s\n",
devtypestr(iscapture), (unsigned int) index, SDL_GetError());
devtypestr(iscapture), (unsigned int)index, SDL_GetError());
continue;
}
if (!iscapture) {
......@@ -110,34 +111,32 @@ iteration()
if (!dev) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open '%s': %s\n", name, SDL_GetError());
} else {
SDL_Log("Opened '%s' as %u\n", name, (unsigned int) dev);
SDL_Log("Opened '%s' as %u\n", name, (unsigned int)dev);
SDL_PauseAudioDevice(dev, 0);
}
}
} else if (e.type == SDL_AUDIODEVICEREMOVED) {
dev = (SDL_AudioDeviceID) e.adevice.which;
SDL_Log("%s device %u removed.\n", devtypestr(e.adevice.iscapture), (unsigned int) dev);
dev = (SDL_AudioDeviceID)e.adevice.which;
SDL_Log("%s device %u removed.\n", devtypestr(e.adevice.iscapture), (unsigned int)dev);
SDL_CloseAudioDevice(dev);
}
}
}
#ifdef __EMSCRIPTEN__
void
loop()
void loop()
{
if(done)
if (done)
emscripten_cancel_main_loop();
else
iteration();
}
#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;
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,15 +102,15 @@ 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;
for (i=0; i<100; i++) {
while (SDL_PollEvent(&event)) {
SDLTest_CommonEvent(state, &event, &done);
}
SDL_Delay(10);
for (i = 0; i < 100; i++) {
while (SDL_PollEvent(&event)) {
SDLTest_CommonEvent(state, &event, &done);
}
SDL_Delay(10);
}
/* Clean up */
......@@ -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,44 +19,39 @@
/* Fixture */
void
_audioSetUp(void *arg)
void _audioSetUp(void *arg)
{
/* Start SDL audio subsystem */
int ret = SDL_InitSubSystem( SDL_INIT_AUDIO );
SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_AUDIO)");
SDLTest_AssertCheck(ret==0, "Check result from SDL_InitSubSystem(SDL_INIT_AUDIO)");
int ret = SDL_InitSubSystem(SDL_INIT_AUDIO);
SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_AUDIO)");
SDLTest_AssertCheck(ret == 0, "Check result from SDL_InitSubSystem(SDL_INIT_AUDIO)");
if (ret != 0) {
SDLTest_LogError("%s", SDL_GetError());
}
SDLTest_LogError("%s", SDL_GetError());
}
}
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)
{
/* track that callback was called */
_audio_testCallbackCounter++;
_audio_testCallbackLength += len;
/* track that callback was called */
_audio_testCallbackCounter++;
_audio_testCallbackLength += len;
}
/* Test case functions */
/**
......@@ -65,11 +63,11 @@ void SDLCALL _audio_testCallback(void *userdata, Uint8 *stream, int len)
int audio_quitInitAudioSubSystem()
{
/* Stop SDL audio subsystem */
SDL_QuitSubSystem( SDL_INIT_AUDIO );
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
SDL_QuitSubSystem(SDL_INIT_AUDIO);
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
/* Restart audio again */
_audioSetUp(NULL);
/* Restart audio again */
_audioSetUp(NULL);
return TEST_COMPLETED;
}
......@@ -82,32 +80,32 @@ int audio_quitInitAudioSubSystem()
*/
int audio_initQuitAudio()
{
int result;
int result;
int i, iMax;
const char* audioDriver;
const char *audioDriver;
/* Stop SDL audio subsystem */
SDL_QuitSubSystem( SDL_INIT_AUDIO );
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
/* Loop over all available audio drivers */
iMax = SDL_GetNumAudioDrivers();
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
for (i = 0; i < iMax; i++) {
audioDriver = SDL_GetAudioDriver(i);
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
SDLTest_AssertCheck(audioDriver != NULL, "Audio driver name is not NULL");
SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver);
/* Call Init */
result = SDL_AudioInit(audioDriver);
SDLTest_AssertPass("Call to SDL_AudioInit('%s')", audioDriver);
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
/* Call Quit */
SDL_AudioQuit();
SDLTest_AssertPass("Call to SDL_AudioQuit()");
SDL_QuitSubSystem(SDL_INIT_AUDIO);
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
/* Loop over all available audio drivers */
iMax = SDL_GetNumAudioDrivers();
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
for (i = 0; i < iMax; i++) {
audioDriver = SDL_GetAudioDriver(i);
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
SDLTest_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);
SDLTest_AssertPass("Call to SDL_AudioInit('%s')", audioDriver);
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
/* Call Quit */
SDL_AudioQuit();
SDLTest_AssertPass("Call to SDL_AudioQuit()");
}
/* NULL driver specification */
......@@ -122,8 +120,8 @@ int audio_initQuitAudio()
SDL_AudioQuit();
SDLTest_AssertPass("Call to SDL_AudioQuit()");
/* Restart audio again */
_audioSetUp(NULL);
/* Restart audio again */
_audioSetUp(NULL);
return TEST_COMPLETED;
}
......@@ -140,79 +138,79 @@ int audio_initOpenCloseQuitAudio()
{
int result, expectedResult;
int i, iMax, j, k;
const char* audioDriver;
const char *audioDriver;
SDL_AudioSpec desired;
/* Stop SDL audio subsystem */
SDL_QuitSubSystem( SDL_INIT_AUDIO );
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
/* Loop over all available audio drivers */
iMax = SDL_GetNumAudioDrivers();
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
for (i = 0; i < iMax; i++) {
audioDriver = SDL_GetAudioDriver(i);
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
SDLTest_AssertCheck(audioDriver != NULL, "Audio driver name is not NULL");
SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver);
/* Change specs */
for (j = 0; j < 2; j++) {
/* Call Init */
result = SDL_AudioInit(audioDriver);
SDLTest_AssertPass("Call to SDL_AudioInit('%s')", audioDriver);
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
/* Set spec */
SDL_memset(&desired, 0, sizeof(desired));
switch (j) {
case 0:
/* Set standard desired spec */
desired.freq = 22050;
desired.format = AUDIO_S16SYS;
desired.channels = 2;
desired.samples = 4096;
desired.callback = _audio_testCallback;
desired.userdata = NULL;
case 1:
/* Set custom desired spec */
desired.freq = 48000;
desired.format = AUDIO_F32SYS;
desired.channels = 2;
desired.samples = 2048;
desired.callback = _audio_testCallback;
desired.userdata = NULL;
break;
SDL_QuitSubSystem(SDL_INIT_AUDIO);
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
/* Loop over all available audio drivers */
iMax = SDL_GetNumAudioDrivers();
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
for (i = 0; i < iMax; i++) {
audioDriver = SDL_GetAudioDriver(i);
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
SDLTest_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++) {
/* Call Init */
result = SDL_AudioInit(audioDriver);
SDLTest_AssertPass("Call to SDL_AudioInit('%s')", audioDriver);
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
/* Set spec */
SDL_memset(&desired, 0, sizeof(desired));
switch (j) {
case 0:
/* Set standard desired spec */
desired.freq = 22050;
desired.format = AUDIO_S16SYS;
desired.channels = 2;
desired.samples = 4096;
desired.callback = _audio_testCallback;
desired.userdata = NULL;
break;
case 1:
/* Set custom desired spec */
desired.freq = 48000;
desired.format = AUDIO_F32SYS;
desired.channels = 2;
desired.samples = 2048;
desired.callback = _audio_testCallback;
desired.userdata = NULL;
break;
}
/* Call Open (maybe multiple times) */
for (k=0; k <= j; k++) {
for (k = 0; k <= j; k++) {
result = SDL_OpenAudio(&desired, NULL);
SDLTest_AssertPass("Call to SDL_OpenAudio(desired_spec_%d, NULL), call %d", j, k+1);
expectedResult = (k==0) ? 0 : -1;
SDLTest_AssertPass("Call to SDL_OpenAudio(desired_spec_%d, NULL), call %d", j, k + 1);
expectedResult = (k == 0) ? 0 : -1;
SDLTest_AssertCheck(result == expectedResult, "Verify return value; expected: %d, got: %d", expectedResult, result);
}
/* Call Close (maybe multiple times) */
for (k=0; k <= j; k++) {
for (k = 0; k <= j; k++) {
SDL_CloseAudio();
SDLTest_AssertPass("Call to SDL_CloseAudio(), call %d", k+1);
SDLTest_AssertPass("Call to SDL_CloseAudio(), call %d", k + 1);
}
/* Call Quit (maybe multiple times) */
for (k=0; k <= j; k++) {
for (k = 0; k <= j; k++) {
SDL_AudioQuit();
SDLTest_AssertPass("Call to SDL_AudioQuit(), call %d", k+1);
SDLTest_AssertPass("Call to SDL_AudioQuit(), call %d", k + 1);
}
} /* spec loop */
} /* driver loop */
} /* driver loop */
/* Restart audio again */
_audioSetUp(NULL);
/* Restart audio again */
_audioSetUp(NULL);
return TEST_COMPLETED;
}
......@@ -229,52 +227,52 @@ int audio_pauseUnpauseAudio()
int totalDelay;
int pause_on;
int originalCounter;
const char* audioDriver;
const char *audioDriver;
SDL_AudioSpec desired;
/* Stop SDL audio subsystem */
SDL_QuitSubSystem( SDL_INIT_AUDIO );
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
/* Loop over all available audio drivers */
iMax = SDL_GetNumAudioDrivers();
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
for (i = 0; i < iMax; i++) {
audioDriver = SDL_GetAudioDriver(i);
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
SDLTest_AssertCheck(audioDriver != NULL, "Audio driver name is not NULL");
SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver);
/* Change specs */
for (j = 0; j < 2; j++) {
/* Call Init */
result = SDL_AudioInit(audioDriver);
SDLTest_AssertPass("Call to SDL_AudioInit('%s')", audioDriver);
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
/* Set spec */
SDL_memset(&desired, 0, sizeof(desired));
switch (j) {
case 0:
/* Set standard desired spec */
desired.freq = 22050;
desired.format = AUDIO_S16SYS;
desired.channels = 2;
desired.samples = 4096;
desired.callback = _audio_testCallback;
desired.userdata = NULL;
case 1:
/* Set custom desired spec */
desired.freq = 48000;
desired.format = AUDIO_F32SYS;
desired.channels = 2;
desired.samples = 2048;
desired.callback = _audio_testCallback;
desired.userdata = NULL;
break;
SDL_QuitSubSystem(SDL_INIT_AUDIO);
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
/* Loop over all available audio drivers */
iMax = SDL_GetNumAudioDrivers();
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
for (i = 0; i < iMax; i++) {
audioDriver = SDL_GetAudioDriver(i);
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
SDLTest_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++) {
/* Call Init */
result = SDL_AudioInit(audioDriver);
SDLTest_AssertPass("Call to SDL_AudioInit('%s')", audioDriver);
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
/* Set spec */
SDL_memset(&desired, 0, sizeof(desired));
switch (j) {
case 0:
/* Set standard desired spec */
desired.freq = 22050;
desired.format = AUDIO_S16SYS;
desired.channels = 2;
desired.samples = 4096;
desired.callback = _audio_testCallback;
desired.userdata = NULL;
break;
case 1:
/* Set custom desired spec */
desired.freq = 48000;
desired.format = AUDIO_F32SYS;
desired.channels = 2;
desired.samples = 2048;
desired.callback = _audio_testCallback;
desired.userdata = NULL;
break;
}
/* Call Open */
......@@ -283,37 +281,36 @@ int audio_pauseUnpauseAudio()
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0 got: %d", result);
/* Start and stop audio multiple times */
for (l=0; l<3; l++) {
SDLTest_Log("Pause/Unpause iteration: %d", l+1);
for (l = 0; l < 3; l++) {
SDLTest_Log("Pause/Unpause iteration: %d", l + 1);
/* Reset callback counters */
_audio_testCallbackCounter = 0;
_audio_testCallbackLength = 0;
/* Un-pause audio to start playing (maybe multiple times) */
pause_on = 0;
for (k=0; k <= j; k++) {
for (k = 0; k <= j; k++) {
SDL_PauseAudio(pause_on);
SDLTest_AssertPass("Call to SDL_PauseAudio(%d), call %d", pause_on, k+1);
SDLTest_AssertPass("Call to SDL_PauseAudio(%d), call %d", pause_on, k + 1);
}
/* Wait for callback */
totalDelay = 0;
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);
/* Pause audio to stop playing (maybe multiple times) */
for (k=0; k <= j; k++) {
pause_on = (k==0) ? 1 : SDLTest_RandomIntegerInRange(99, 9999);
for (k = 0; k <= j; k++) {
pause_on = (k == 0) ? 1 : SDLTest_RandomIntegerInRange(99, 9999);
SDL_PauseAudio(pause_on);
SDLTest_AssertPass("Call to SDL_PauseAudio(%d), call %d", pause_on, k+1);
SDLTest_AssertPass("Call to SDL_PauseAudio(%d), call %d", pause_on, k + 1);
}
/* Ensure callback is not called again */
originalCounter = _audio_testCallbackCounter;
SDL_Delay(totalDelay + 10);
......@@ -329,7 +326,7 @@ int audio_pauseUnpauseAudio()
SDLTest_AssertPass("Call to SDL_AudioQuit()");
} /* spec loop */
} /* driver loop */
} /* driver loop */
/* Restart audio again */
_audioSetUp(NULL);
......@@ -345,54 +342,54 @@ int audio_pauseUnpauseAudio()
*/
int audio_enumerateAndNameAudioDevices()
{
int t, tt;
int i, n, nn;
const char *name, *nameAgain;
/* Iterate over types: t=0 output device, t=1 input/capture device */
for (t=0; t<2; t++) {
/* Get number of devices. */
n = SDL_GetNumAudioDevices(t);
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(%i)", t);
SDLTest_Log("Number of %s devices < 0, reported as %i", (t) ? "capture" : "output", n);
SDLTest_AssertCheck(n >= 0, "Validate result is >= 0, got: %i", n);
/* Variation of non-zero type */
if (t==1) {
tt = t + SDLTest_RandomIntegerInRange(1,10);
nn = SDL_GetNumAudioDevices(tt);
SDLTest_AssertCheck(n==nn, "Verify result from SDL_GetNumAudioDevices(%i), expected same number of audio devices %i, got %i", tt, n, nn);
nn = SDL_GetNumAudioDevices(-tt);
SDLTest_AssertCheck(n==nn, "Verify result from SDL_GetNumAudioDevices(%i), expected same number of audio devices %i, got %i", -tt, n, nn);
}
/* List devices. */
if (n>0) {
for (i=0; i<n; i++) {
name = SDL_GetAudioDeviceName(i, t);
SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
SDLTest_AssertCheck(name != NULL, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not NULL", i, t);
if (name != NULL) {
SDLTest_AssertCheck(name[0] != '\0', "verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, t, name);
if (t==1) {
/* Also try non-zero type */
tt = t + SDLTest_RandomIntegerInRange(1,10);
nameAgain = SDL_GetAudioDeviceName(i, tt);
SDLTest_AssertCheck(nameAgain != NULL, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not NULL", i, tt);
if (nameAgain != NULL) {
SDLTest_AssertCheck(nameAgain[0] != '\0', "Verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, tt, nameAgain);
SDLTest_AssertCheck(SDL_strcmp(name, nameAgain)==0,
"Verify SDL_GetAudioDeviceName(%i, %i) and SDL_GetAudioDeviceName(%i %i) return the same string",
i, t, i, tt);
}
}
int t, tt;
int i, n, nn;
const char *name, *nameAgain;
/* Iterate over types: t=0 output device, t=1 input/capture device */
for (t = 0; t < 2; t++) {
/* Get number of devices. */
n = SDL_GetNumAudioDevices(t);
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(%i)", t);
SDLTest_Log("Number of %s devices < 0, reported as %i", (t) ? "capture" : "output", n);
SDLTest_AssertCheck(n >= 0, "Validate result is >= 0, got: %i", n);
/* Variation of non-zero type */
if (t == 1) {
tt = t + SDLTest_RandomIntegerInRange(1, 10);
nn = SDL_GetNumAudioDevices(tt);
SDLTest_AssertCheck(n == nn, "Verify result from SDL_GetNumAudioDevices(%i), expected same number of audio devices %i, got %i", tt, n, nn);
nn = SDL_GetNumAudioDevices(-tt);
SDLTest_AssertCheck(n == nn, "Verify result from SDL_GetNumAudioDevices(%i), expected same number of audio devices %i, got %i", -tt, n, nn);
}
/* List devices. */
if (n > 0) {
for (i = 0; i < n; i++) {
name = SDL_GetAudioDeviceName(i, t);
SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
SDLTest_AssertCheck(name != NULL, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not NULL", i, t);
if (name != NULL) {
SDLTest_AssertCheck(name[0] != '\0', "verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, t, name);
if (t == 1) {
/* Also try non-zero type */
tt = t + SDLTest_RandomIntegerInRange(1, 10);
nameAgain = SDL_GetAudioDeviceName(i, tt);
SDLTest_AssertCheck(nameAgain != NULL, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not NULL", i, tt);
if (nameAgain != NULL) {
SDLTest_AssertCheck(nameAgain[0] != '\0', "Verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, tt, nameAgain);
SDLTest_AssertCheck(SDL_strcmp(name, nameAgain) == 0,
"Verify SDL_GetAudioDeviceName(%i, %i) and SDL_GetAudioDeviceName(%i %i) return the same string",
i, t, i, tt);
}
}
}
}
}
}
}
}
}
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
......@@ -403,44 +400,43 @@ int audio_enumerateAndNameAudioDevices()
*/
int audio_enumerateAndNameAudioDevicesNegativeTests()
{
int t;
int i, j, no, nc;
const char *name;
/* Get number of devices. */
no = SDL_GetNumAudioDevices(0);
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
nc = SDL_GetNumAudioDevices(1);
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(1)");
/* Invalid device index when getting name */
for (t=0; t<2; t++) {
/* Negative device index */
i = SDLTest_RandomIntegerInRange(-10,-1);
name = SDL_GetAudioDeviceName(i, t);
SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result NULL, expected NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
/* Device index past range */
for (j=0; j<3; j++) {
i = (t) ? nc+j : no+j;
name = SDL_GetAudioDeviceName(i, t);
SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result, expected: NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
}
/* Capture index past capture range but within output range */
if ((no>0) && (no>nc) && (t==1)) {
i = no-1;
name = SDL_GetAudioDeviceName(i, t);
SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result, expected: NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
}
}
return TEST_COMPLETED;
}
int t;
int i, j, no, nc;
const char *name;
/* Get number of devices. */
no = SDL_GetNumAudioDevices(0);
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
nc = SDL_GetNumAudioDevices(1);
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(1)");
/* Invalid device index when getting name */
for (t = 0; t < 2; t++) {
/* Negative device index */
i = SDLTest_RandomIntegerInRange(-10, -1);
name = SDL_GetAudioDeviceName(i, t);
SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result NULL, expected NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
/* Device index past range */
for (j = 0; j < 3; j++) {
i = (t) ? nc + j : no + j;
name = SDL_GetAudioDeviceName(i, t);
SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result, expected: NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
}
/* Capture index past capture range but within output range */
if ((no > 0) && (no > nc) && (t == 1)) {
i = no - 1;
name = SDL_GetAudioDeviceName(i, t);
SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result, expected: NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
}
}
return TEST_COMPLETED;
}
/**
* \brief Checks available audio driver names.
......@@ -450,30 +446,28 @@ int audio_enumerateAndNameAudioDevicesNegativeTests()
*/
int audio_printAudioDrivers()
{
int i, n;
const char *name;
/* Get number of drivers */
n = SDL_GetNumAudioDrivers();
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
SDLTest_AssertCheck(n>=0, "Verify number of audio drivers >= 0, got: %i", n);
/* List drivers. */
if (n>0)
{
for (i=0; i<n; i++) {
name = SDL_GetAudioDriver(i);
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%i)", i);
SDLTest_AssertCheck(name != NULL, "Verify returned name is not NULL");
if (name != NULL) {
SDLTest_AssertCheck(name[0] != '\0', "Verify returned name is not empty, got: '%s'", name);
}
}
}
return TEST_COMPLETED;
}
int i, n;
const char *name;
/* Get number of drivers */
n = SDL_GetNumAudioDrivers();
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
SDLTest_AssertCheck(n >= 0, "Verify number of audio drivers >= 0, got: %i", n);
/* List drivers. */
if (n > 0) {
for (i = 0; i < n; i++) {
name = SDL_GetAudioDriver(i);
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%i)", i);
SDLTest_AssertCheck(name != NULL, "Verify returned name is not NULL");
if (name != NULL) {
SDLTest_AssertCheck(name[0] != '\0', "Verify returned name is not empty, got: '%s'", name);
}
}
}
return TEST_COMPLETED;
}
/**
* \brief Checks current audio driver name with initialized audio.
......@@ -482,31 +476,30 @@ int audio_printAudioDrivers()
*/
int audio_printCurrentAudioDriver()
{
/* Check current audio driver */
const char *name = SDL_GetCurrentAudioDriver();
SDLTest_AssertPass("Call to SDL_GetCurrentAudioDriver()");
SDLTest_AssertCheck(name != NULL, "Verify returned name is not NULL");
if (name != NULL) {
SDLTest_AssertCheck(name[0] != '\0', "Verify returned name is not empty, got: '%s'", name);
}
return TEST_COMPLETED;
/* Check current audio driver */
const char *name = SDL_GetCurrentAudioDriver();
SDLTest_AssertPass("Call to SDL_GetCurrentAudioDriver()");
SDLTest_AssertCheck(name != NULL, "Verify returned name is not NULL");
if (name != NULL) {
SDLTest_AssertCheck(name[0] != '\0', "Verify returned name is not empty, got: '%s'", name);
}
return TEST_COMPLETED;
}
/* Definition of all formats, channels, and frequencies used to test audio conversions */
const int _numAudioFormats = 18;
SDL_AudioFormat _audioFormats[] = { AUDIO_S8, AUDIO_U8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_S16SYS, AUDIO_S16, AUDIO_U16LSB,
AUDIO_U16MSB, AUDIO_U16SYS, AUDIO_U16, AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_S32SYS, AUDIO_S32,
AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_F32SYS, AUDIO_F32 };
AUDIO_U16MSB, AUDIO_U16SYS, AUDIO_U16, AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_S32SYS, AUDIO_S32,
AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_F32SYS, AUDIO_F32 };
const char *_audioFormatsVerbose[] = { "AUDIO_S8", "AUDIO_U8", "AUDIO_S16LSB", "AUDIO_S16MSB", "AUDIO_S16SYS", "AUDIO_S16", "AUDIO_U16LSB",
"AUDIO_U16MSB", "AUDIO_U16SYS", "AUDIO_U16", "AUDIO_S32LSB", "AUDIO_S32MSB", "AUDIO_S32SYS", "AUDIO_S32",
"AUDIO_F32LSB", "AUDIO_F32MSB", "AUDIO_F32SYS", "AUDIO_F32" };
"AUDIO_U16MSB", "AUDIO_U16SYS", "AUDIO_U16", "AUDIO_S32LSB", "AUDIO_S32MSB", "AUDIO_S32SYS", "AUDIO_S32",
"AUDIO_F32LSB", "AUDIO_F32MSB", "AUDIO_F32SYS", "AUDIO_F32" };
const int _numAudioChannels = 4;
Uint8 _audioChannels[] = { 1, 2, 4, 6 };
const int _numAudioFrequencies = 4;
int _audioFrequencies[] = { 11025, 22050, 44100, 48000 };
/**
* \brief Builds various audio conversion structures
*
......@@ -514,61 +507,61 @@ int _audioFrequencies[] = { 11025, 22050, 44100, 48000 };
*/
int audio_buildAudioCVT()
{
int result;
SDL_AudioCVT cvt;
SDL_AudioSpec spec1;
SDL_AudioSpec spec2;
int i, ii, j, jj, k, kk;
/* No conversion needed */
spec1.format = AUDIO_S16LSB;
spec1.channels = 2;
spec1.freq = 22050;
result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
spec1.format, spec1.channels, spec1.freq);
SDLTest_AssertPass("Call to SDL_BuildAudioCVT(spec1 ==> spec1)");
SDLTest_AssertCheck(result == 0, "Verify result value; expected: 0, got: %i", result);
/* Typical conversion */
spec1.format = AUDIO_S8;
spec1.channels = 1;
spec1.freq = 22050;
spec2.format = AUDIO_S16LSB;
spec2.channels = 2;
spec2.freq = 44100;
result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
spec2.format, spec2.channels, spec2.freq);
SDLTest_AssertPass("Call to SDL_BuildAudioCVT(spec1 ==> spec2)");
SDLTest_AssertCheck(result == 1, "Verify result value; expected: 1, got: %i", result);
/* All source conversions with random conversion targets, allow 'null' conversions */
for (i = 0; i < _numAudioFormats; i++) {
for (j = 0; j < _numAudioChannels; j++) {
for (k = 0; k < _numAudioFrequencies; k++) {
spec1.format = _audioFormats[i];
spec1.channels = _audioChannels[j];
spec1.freq = _audioFrequencies[k];
ii = SDLTest_RandomIntegerInRange(0, _numAudioFormats - 1);
jj = SDLTest_RandomIntegerInRange(0, _numAudioChannels - 1);
kk = SDLTest_RandomIntegerInRange(0, _numAudioFrequencies - 1);
spec2.format = _audioFormats[ii];
spec2.channels = _audioChannels[jj];
spec2.freq = _audioFrequencies[kk];
result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
spec2.format, spec2.channels, spec2.freq);
SDLTest_AssertPass("Call to SDL_BuildAudioCVT(format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i ==> format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i)",
i, _audioFormatsVerbose[i], spec1.format, j, spec1.channels, k, spec1.freq, ii, _audioFormatsVerbose[ii], spec2.format, jj, spec2.channels, kk, spec2.freq);
SDLTest_AssertCheck(result == 0 || result == 1, "Verify result value; expected: 0 or 1, got: %i", result);
if (result<0) {
SDLTest_LogError("%s", SDL_GetError());
} else {
SDLTest_AssertCheck(cvt.len_mult > 0, "Verify that cvt.len_mult value; expected: >0, got: %i", cvt.len_mult);
int result;
SDL_AudioCVT cvt;
SDL_AudioSpec spec1;
SDL_AudioSpec spec2;
int i, ii, j, jj, k, kk;
/* No conversion needed */
spec1.format = AUDIO_S16LSB;
spec1.channels = 2;
spec1.freq = 22050;
result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
spec1.format, spec1.channels, spec1.freq);
SDLTest_AssertPass("Call to SDL_BuildAudioCVT(spec1 ==> spec1)");
SDLTest_AssertCheck(result == 0, "Verify result value; expected: 0, got: %i", result);
/* Typical conversion */
spec1.format = AUDIO_S8;
spec1.channels = 1;
spec1.freq = 22050;
spec2.format = AUDIO_S16LSB;
spec2.channels = 2;
spec2.freq = 44100;
result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
spec2.format, spec2.channels, spec2.freq);
SDLTest_AssertPass("Call to SDL_BuildAudioCVT(spec1 ==> spec2)");
SDLTest_AssertCheck(result == 1, "Verify result value; expected: 1, got: %i", result);
/* All source conversions with random conversion targets, allow 'null' conversions */
for (i = 0; i < _numAudioFormats; i++) {
for (j = 0; j < _numAudioChannels; j++) {
for (k = 0; k < _numAudioFrequencies; k++) {
spec1.format = _audioFormats[i];
spec1.channels = _audioChannels[j];
spec1.freq = _audioFrequencies[k];
ii = SDLTest_RandomIntegerInRange(0, _numAudioFormats - 1);
jj = SDLTest_RandomIntegerInRange(0, _numAudioChannels - 1);
kk = SDLTest_RandomIntegerInRange(0, _numAudioFrequencies - 1);
spec2.format = _audioFormats[ii];
spec2.channels = _audioChannels[jj];
spec2.freq = _audioFrequencies[kk];
result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
spec2.format, spec2.channels, spec2.freq);
SDLTest_AssertPass("Call to SDL_BuildAudioCVT(format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i ==> format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i)",
i, _audioFormatsVerbose[i], spec1.format, j, spec1.channels, k, spec1.freq, ii, _audioFormatsVerbose[ii], spec2.format, jj, spec2.channels, kk, spec2.freq);
SDLTest_AssertCheck(result == 0 || result == 1, "Verify result value; expected: 0 or 1, got: %i", result);
if (result < 0) {
SDLTest_LogError("%s", SDL_GetError());
} else {
SDLTest_AssertCheck(cvt.len_mult > 0, "Verify that cvt.len_mult value; expected: >0, got: %i", cvt.len_mult);
}
}
}
}
}
}
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
......@@ -578,42 +571,16 @@ int audio_buildAudioCVT()
*/
int audio_buildAudioCVTNegative()
{
const char *expectedError = "Parameter 'cvt' is invalid";
const char *error;
int result;
SDL_AudioCVT cvt;
SDL_AudioSpec spec1;
SDL_AudioSpec spec2;
int i;
char message[256];
/* Valid format */
spec1.format = AUDIO_S8;
spec1.channels = 1;
spec1.freq = 22050;
spec2.format = AUDIO_S16LSB;
spec2.channels = 2;
spec2.freq = 44100;
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
/* NULL input for CVT buffer */
result = SDL_BuildAudioCVT((SDL_AudioCVT *)NULL, spec1.format, spec1.channels, spec1.freq,
spec2.format, spec2.channels, spec2.freq);
SDLTest_AssertPass("Call to SDL_BuildAudioCVT(NULL,...)");
SDLTest_AssertCheck(result == -1, "Verify result value; expected: -1, got: %i", result);
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
}
const char *expectedError = "Parameter 'cvt' is invalid";
const char *error;
int result;
SDL_AudioCVT cvt;
SDL_AudioSpec spec1;
SDL_AudioSpec spec2;
int i;
char message[256];
/* Invalid conversions */
for (i = 1; i < 64; i++) {
/* Valid format to start with */
/* Valid format */
spec1.format = AUDIO_S8;
spec1.channels = 1;
spec1.freq = 22050;
......@@ -624,46 +591,72 @@ int audio_buildAudioCVTNegative()
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
/* Set various invalid format inputs */
SDL_strlcpy(message, "Invalid: ", 256);
if (i & 1) {
SDL_strlcat(message, " spec1.format", 256);
spec1.format = 0;
}
if (i & 2) {
SDL_strlcat(message, " spec1.channels", 256);
spec1.channels = 0;
}
if (i & 4) {
SDL_strlcat(message, " spec1.freq", 256);
spec1.freq = 0;
}
if (i & 8) {
SDL_strlcat(message, " spec2.format", 256);
spec2.format = 0;
}
if (i & 16) {
SDL_strlcat(message, " spec2.channels", 256);
spec2.channels = 0;
}
if (i & 32) {
SDL_strlcat(message, " spec2.freq", 256);
spec2.freq = 0;
}
SDLTest_Log("%s", message);
result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
spec2.format, spec2.channels, spec2.freq);
SDLTest_AssertPass("Call to SDL_BuildAudioCVT(spec1 ==> spec2)");
/* NULL input for CVT buffer */
result = SDL_BuildAudioCVT((SDL_AudioCVT *)NULL, spec1.format, spec1.channels, spec1.freq,
spec2.format, spec2.channels, spec2.freq);
SDLTest_AssertPass("Call to SDL_BuildAudioCVT(NULL,...)");
SDLTest_AssertCheck(result == -1, "Verify result value; expected: -1, got: %i", result);
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL && error[0] != '\0', "Validate that error message was not NULL or empty");
}
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
}
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
/* Invalid conversions */
for (i = 1; i < 64; i++) {
/* Valid format to start with */
spec1.format = AUDIO_S8;
spec1.channels = 1;
spec1.freq = 22050;
spec2.format = AUDIO_S16LSB;
spec2.channels = 2;
spec2.freq = 44100;
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
/* Set various invalid format inputs */
SDL_strlcpy(message, "Invalid: ", 256);
if (i & 1) {
SDL_strlcat(message, " spec1.format", 256);
spec1.format = 0;
}
if (i & 2) {
SDL_strlcat(message, " spec1.channels", 256);
spec1.channels = 0;
}
if (i & 4) {
SDL_strlcat(message, " spec1.freq", 256);
spec1.freq = 0;
}
if (i & 8) {
SDL_strlcat(message, " spec2.format", 256);
spec2.format = 0;
}
if (i & 16) {
SDL_strlcat(message, " spec2.channels", 256);
spec2.channels = 0;
}
if (i & 32) {
SDL_strlcat(message, " spec2.freq", 256);
spec2.freq = 0;
}
SDLTest_Log("%s", message);
result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
spec2.format, spec2.channels, spec2.freq);
SDLTest_AssertPass("Call to SDL_BuildAudioCVT(spec1 ==> spec2)");
SDLTest_AssertCheck(result == -1, "Verify result value; expected: -1, got: %i", result);
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL && error[0] != '\0', "Validate that error message was not NULL or empty");
}
return TEST_COMPLETED;
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
return TEST_COMPLETED;
}
/**
......@@ -673,20 +666,18 @@ int audio_buildAudioCVTNegative()
*/
int audio_getAudioStatus()
{
SDL_AudioStatus result;
SDL_AudioStatus result;
/* Check current audio status */
result = SDL_GetAudioStatus();
SDLTest_AssertPass("Call to SDL_GetAudioStatus()");
SDLTest_AssertCheck(result == SDL_AUDIO_STOPPED || result == SDL_AUDIO_PLAYING || result == SDL_AUDIO_PAUSED,
"Verify returned value; expected: STOPPED (%i) | PLAYING (%i) | PAUSED (%i), got: %i",
SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED, result);
/* Check current audio status */
result = SDL_GetAudioStatus();
SDLTest_AssertPass("Call to SDL_GetAudioStatus()");
SDLTest_AssertCheck(result == SDL_AUDIO_STOPPED || result == SDL_AUDIO_PLAYING || result == SDL_AUDIO_PAUSED,
"Verify returned value; expected: STOPPED (%i) | PLAYING (%i) | PAUSED (%i), got: %i",
SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED, result);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
* \brief Opens, checks current audio status, and closes a device.
*
......@@ -694,55 +685,57 @@ int audio_getAudioStatus()
*/
int audio_openCloseAndGetAudioStatus()
{
SDL_AudioStatus result;
int i;
int count;
const char *device;
SDL_AudioDeviceID id;
SDL_AudioSpec desired, obtained;
/* Get number of devices. */
count = SDL_GetNumAudioDevices(0);
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
if (count > 0) {
for (i = 0; i < count; i++) {
/* Get device name */
device = SDL_GetAudioDeviceName(i, 0);
SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
if (device == NULL) return TEST_ABORTED;
/* Set standard desired spec */
desired.freq=22050;
desired.format=AUDIO_S16SYS;
desired.channels=2;
desired.samples=4096;
desired.callback=_audio_testCallback;
desired.userdata=NULL;
/* Open device */
id = SDL_OpenAudioDevice(device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >=2, got: %i", id);
if (id > 1) {
/* Check device audio status */
result = SDL_GetAudioDeviceStatus(id);
SDLTest_AssertPass("Call to SDL_GetAudioDeviceStatus()");
SDLTest_AssertCheck(result == SDL_AUDIO_STOPPED || result == SDL_AUDIO_PLAYING || result == SDL_AUDIO_PAUSED,
"Verify returned value; expected: STOPPED (%i) | PLAYING (%i) | PAUSED (%i), got: %i",
SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED, result);
/* Close device again */
SDL_CloseAudioDevice(id);
SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
}
}
} else {
SDLTest_Log("No devices to test with");
}
return TEST_COMPLETED;
SDL_AudioStatus result;
int i;
int count;
const char *device;
SDL_AudioDeviceID id;
SDL_AudioSpec desired, obtained;
/* Get number of devices. */
count = SDL_GetNumAudioDevices(0);
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
if (count > 0) {
for (i = 0; i < count; i++) {
/* Get device name */
device = SDL_GetAudioDeviceName(i, 0);
SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
if (device == NULL) {
return TEST_ABORTED;
}
/* Set standard desired spec */
desired.freq = 22050;
desired.format = AUDIO_S16SYS;
desired.channels = 2;
desired.samples = 4096;
desired.callback = _audio_testCallback;
desired.userdata = NULL;
/* Open device */
id = SDL_OpenAudioDevice(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: %" SDL_PRIu32, id);
if (id > 1) {
/* Check device audio status */
result = SDL_GetAudioDeviceStatus(id);
SDLTest_AssertPass("Call to SDL_GetAudioDeviceStatus()");
SDLTest_AssertCheck(result == SDL_AUDIO_STOPPED || result == SDL_AUDIO_PLAYING || result == SDL_AUDIO_PAUSED,
"Verify returned value; expected: STOPPED (%i) | PLAYING (%i) | PAUSED (%i), got: %i",
SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED, result);
/* Close device again */
SDL_CloseAudioDevice(id);
SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
}
}
} else {
SDLTest_Log("No devices to test with");
}
return TEST_COMPLETED;
}
/**
......@@ -753,60 +746,61 @@ int audio_openCloseAndGetAudioStatus()
*/
int audio_lockUnlockOpenAudioDevice()
{
int i;
int count;
const char *device;
SDL_AudioDeviceID id;
SDL_AudioSpec desired, obtained;
/* Get number of devices. */
count = SDL_GetNumAudioDevices(0);
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
if (count > 0) {
for (i = 0; i < count; i++) {
/* Get device name */
device = SDL_GetAudioDeviceName(i, 0);
SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
if (device == NULL) return TEST_ABORTED;
/* Set standard desired spec */
desired.freq=22050;
desired.format=AUDIO_S16SYS;
desired.channels=2;
desired.samples=4096;
desired.callback=_audio_testCallback;
desired.userdata=NULL;
/* Open device */
id = SDL_OpenAudioDevice(device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >=2, got: %i", id);
if (id > 1) {
/* Lock to protect callback */
SDL_LockAudioDevice(id);
SDLTest_AssertPass("SDL_LockAudioDevice(%i)", id);
/* Simulate callback processing */
SDL_Delay(10);
SDLTest_Log("Simulate callback processing - delay");
/* Unlock again */
SDL_UnlockAudioDevice(id);
SDLTest_AssertPass("SDL_UnlockAudioDevice(%i)", id);
/* Close device again */
SDL_CloseAudioDevice(id);
SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
}
}
} else {
SDLTest_Log("No devices to test with");
}
return TEST_COMPLETED;
}
int i;
int count;
const char *device;
SDL_AudioDeviceID id;
SDL_AudioSpec desired, obtained;
/* Get number of devices. */
count = SDL_GetNumAudioDevices(0);
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
if (count > 0) {
for (i = 0; i < count; i++) {
/* Get device name */
device = SDL_GetAudioDeviceName(i, 0);
SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
if (device == NULL) {
return TEST_ABORTED;
}
/* Set standard desired spec */
desired.freq = 22050;
desired.format = AUDIO_S16SYS;
desired.channels = 2;
desired.samples = 4096;
desired.callback = _audio_testCallback;
desired.userdata = NULL;
/* Open device */
id = SDL_OpenAudioDevice(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: %" SDL_PRIu32, id);
if (id > 1) {
/* Lock to protect callback */
SDL_LockAudioDevice(id);
SDLTest_AssertPass("SDL_LockAudioDevice(%" SDL_PRIu32 ")", id);
/* Simulate callback processing */
SDL_Delay(10);
SDLTest_Log("Simulate callback processing - delay");
/* Unlock again */
SDL_UnlockAudioDevice(id);
SDLTest_AssertPass("SDL_UnlockAudioDevice(%" SDL_PRIu32 ")", id);
/* Close device again */
SDL_CloseAudioDevice(id);
SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
}
}
} else {
SDLTest_Log("No devices to test with");
}
return TEST_COMPLETED;
}
/**
* \brief Convert audio using various conversion structures
......@@ -816,97 +810,100 @@ int audio_lockUnlockOpenAudioDevice()
*/
int audio_convertAudio()
{
int result;
SDL_AudioCVT cvt;
SDL_AudioSpec spec1;
SDL_AudioSpec spec2;
int c;
char message[128];
int i, ii, j, jj, k, kk, l, ll;
/* Iterate over bitmask that determines which parameters are modified in the conversion */
for (c = 1; c < 8; c++) {
SDL_strlcpy(message, "Changing:", 128);
if (c & 1) {
SDL_strlcat(message, " Format", 128);
}
if (c & 2) {
SDL_strlcat(message, " Channels", 128);
}
if (c & 4) {
SDL_strlcat(message, " Frequencies", 128);
}
SDLTest_Log("%s", message);
/* All source conversions with random conversion targets */
for (i = 0; i < _numAudioFormats; i++) {
for (j = 0; j < _numAudioChannels; j++) {
for (k = 0; k < _numAudioFrequencies; k++) {
spec1.format = _audioFormats[i];
spec1.channels = _audioChannels[j];
spec1.freq = _audioFrequencies[k];
/* Ensure we have a different target format */
do {
if (c & 1) {
ii = SDLTest_RandomIntegerInRange(0, _numAudioFormats - 1);
} else {
ii = 1;
}
if (c & 2) {
jj = SDLTest_RandomIntegerInRange(0, _numAudioChannels - 1);
} else {
jj= j;
}
if (c & 4) {
kk = SDLTest_RandomIntegerInRange(0, _numAudioFrequencies - 1);
} else {
kk = k;
int result;
SDL_AudioCVT cvt;
SDL_AudioSpec spec1;
SDL_AudioSpec spec2;
int c;
char message[128];
int i, ii, j, jj, k, kk, l, ll;
/* Iterate over bitmask that determines which parameters are modified in the conversion */
for (c = 1; c < 8; c++) {
SDL_strlcpy(message, "Changing:", 128);
if (c & 1) {
SDL_strlcat(message, " Format", 128);
}
if (c & 2) {
SDL_strlcat(message, " Channels", 128);
}
if (c & 4) {
SDL_strlcat(message, " Frequencies", 128);
}
SDLTest_Log("%s", message);
/* All source conversions with random conversion targets */
for (i = 0; i < _numAudioFormats; i++) {
for (j = 0; j < _numAudioChannels; j++) {
for (k = 0; k < _numAudioFrequencies; k++) {
spec1.format = _audioFormats[i];
spec1.channels = _audioChannels[j];
spec1.freq = _audioFrequencies[k];
/* Ensure we have a different target format */
do {
if (c & 1) {
ii = SDLTest_RandomIntegerInRange(0, _numAudioFormats - 1);
} else {
ii = 1;
}
if (c & 2) {
jj = SDLTest_RandomIntegerInRange(0, _numAudioChannels - 1);
} else {
jj = j;
}
if (c & 4) {
kk = SDLTest_RandomIntegerInRange(0, _numAudioFrequencies - 1);
} else {
kk = k;
}
} while ((i == ii) && (j == jj) && (k == kk));
spec2.format = _audioFormats[ii];
spec2.channels = _audioChannels[jj];
spec2.freq = _audioFrequencies[kk];
result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
spec2.format, spec2.channels, spec2.freq);
SDLTest_AssertPass("Call to SDL_BuildAudioCVT(format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i ==> format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i)",
i, _audioFormatsVerbose[i], spec1.format, j, spec1.channels, k, spec1.freq, ii, _audioFormatsVerbose[ii], spec2.format, jj, spec2.channels, kk, spec2.freq);
SDLTest_AssertCheck(result == 1, "Verify result value; expected: 1, got: %i", result);
if (result != 1) {
SDLTest_LogError("%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;
}
/* Create some random data to convert */
l = 64;
ll = l * cvt.len_mult;
SDLTest_Log("Creating dummy sample buffer of %i length (%i bytes)", l, ll);
cvt.len = l;
cvt.buf = (Uint8 *)SDL_malloc(ll);
SDLTest_AssertCheck(cvt.buf != NULL, "Check data buffer to convert is not NULL");
if (cvt.buf == NULL) {
return TEST_ABORTED;
}
/* Convert the data */
result = SDL_ConvertAudio(&cvt);
SDLTest_AssertPass("Call to SDL_ConvertAudio()");
SDLTest_AssertCheck(result == 0, "Verify result value; expected: 0; got: %i", result);
SDLTest_AssertCheck(cvt.buf != NULL, "Verify conversion buffer is not NULL");
SDLTest_AssertCheck(cvt.len_ratio > 0.0, "Verify conversion length ratio; expected: >0; got: %f", cvt.len_ratio);
/* Free converted buffer */
SDL_free(cvt.buf);
cvt.buf = NULL;
}
}
}
} while ((i == ii) && (j == jj) && (k == kk));
spec2.format = _audioFormats[ii];
spec2.channels = _audioChannels[jj];
spec2.freq = _audioFrequencies[kk];
result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
spec2.format, spec2.channels, spec2.freq);
SDLTest_AssertPass("Call to SDL_BuildAudioCVT(format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i ==> format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i)",
i, _audioFormatsVerbose[i], spec1.format, j, spec1.channels, k, spec1.freq, ii, _audioFormatsVerbose[ii], spec2.format, jj, spec2.channels, kk, spec2.freq);
SDLTest_AssertCheck(result == 1, "Verify result value; expected: 1, got: %i", result);
if (result != 1) {
SDLTest_LogError("%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;
/* Create some random data to convert */
l = 64;
ll = l * cvt.len_mult;
SDLTest_Log("Creating dummy sample buffer of %i length (%i bytes)", l, ll);
cvt.len = l;
cvt.buf = (Uint8 *)SDL_malloc(ll);
SDLTest_AssertCheck(cvt.buf != NULL, "Check data buffer to convert is not NULL");
if (cvt.buf == NULL) return TEST_ABORTED;
/* Convert the data */
result = SDL_ConvertAudio(&cvt);
SDLTest_AssertPass("Call to SDL_ConvertAudio()");
SDLTest_AssertCheck(result == 0, "Verify result value; expected: 0; got: %i", result);
SDLTest_AssertCheck(cvt.buf != NULL, "Verify conversion buffer is not NULL");
SDLTest_AssertCheck(cvt.len_ratio > 0.0, "Verify conversion length ratio; expected: >0; got: %f", cvt.len_ratio);
/* Free converted buffer */
SDL_free(cvt.buf);
cvt.buf = NULL;
}
}
}
}
}
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
* \brief Opens, checks current connected status, and closes a device.
*
......@@ -914,119 +911,251 @@ int audio_convertAudio()
*/
int audio_openCloseAudioDeviceConnected()
{
int result = -1;
int i;
int count;
const char *device;
SDL_AudioDeviceID id;
SDL_AudioSpec desired, obtained;
/* Get number of devices. */
count = SDL_GetNumAudioDevices(0);
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
if (count > 0) {
for (i = 0; i < count; i++) {
/* Get device name */
device = SDL_GetAudioDeviceName(i, 0);
SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
if (device == NULL) return TEST_ABORTED;
/* Set standard desired spec */
desired.freq=22050;
desired.format=AUDIO_S16SYS;
desired.channels=2;
desired.samples=4096;
desired.callback=_audio_testCallback;
desired.userdata=NULL;
/* Open device */
id = SDL_OpenAudioDevice(device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >1, got: %i", id);
if (id > 1) {
int result = -1;
int i;
int count;
const char *device;
SDL_AudioDeviceID id;
SDL_AudioSpec desired, obtained;
/* Get number of devices. */
count = SDL_GetNumAudioDevices(0);
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
if (count > 0) {
for (i = 0; i < count; i++) {
/* Get device name */
device = SDL_GetAudioDeviceName(i, 0);
SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
if (device == NULL) {
return TEST_ABORTED;
}
/* Set standard desired spec */
desired.freq = 22050;
desired.format = AUDIO_S16SYS;
desired.channels = 2;
desired.samples = 4096;
desired.callback = _audio_testCallback;
desired.userdata = NULL;
/* Open device */
id = SDL_OpenAudioDevice(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: %" SDL_PRIu32, id);
if (id > 1) {
/* TODO: enable test code when function is available in SDL2 */
#ifdef AUDIODEVICECONNECTED_DEFINED
/* Get connected status */
result = SDL_AudioDeviceConnected(id);
SDLTest_AssertPass("Call to SDL_AudioDeviceConnected()");
/* Get connected status */
result = SDL_AudioDeviceConnected(id);
SDLTest_AssertPass("Call to SDL_AudioDeviceConnected()");
#endif
SDLTest_AssertCheck(result == 1, "Verify returned value; expected: 1; got: %i", result);
/* Close device again */
SDL_CloseAudioDevice(id);
SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
}
}
} else {
SDLTest_Log("No devices to test with");
}
return TEST_COMPLETED;
SDLTest_AssertCheck(result == 1, "Verify returned value; expected: 1; got: %i", result);
/* Close device again */
SDL_CloseAudioDevice(id);
SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
}
}
} else {
SDLTest_Log("No devices to test with");
}
return TEST_COMPLETED;
}
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[] = {
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);
......@@ -71,7 +99,35 @@ clipboard_testSetClipboardText(void *arg)
SDL_free(textRef);
SDL_free(text);
return TEST_COMPLETED;
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;
}
/**
......@@ -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,13 +169,13 @@ 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));
(int)SDL_strlen(charResult));
intResult = SDL_SetClipboardText((const char *)text);
SDLTest_AssertPass("Call to SDL_SetClipboardText succeeded");
SDLTest_AssertCheck(
......@@ -150,28 +205,125 @@ clipboard_testClipboardTextFunctions(void *arg)
SDL_free(text);
SDL_free(charResult);
return TEST_COMPLETED;
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
static const SDLTest_TestCaseReference *clipboardTests[] = {
&clipboardTest1, &clipboardTest2, &clipboardTest3, &clipboardTest4, &clipboardTest5, &clipboardTest6, &clipboardTest7, &clipboardTest8, NULL
};
/* Clipboard test suite (global) */
......
......@@ -27,16 +27,16 @@ int _userdataValue2 = 2;
/* Event filter that sets some flags and optionally checks userdata */
int SDLCALL _events_sampleNullEventFilter(void *userdata, SDL_Event *event)
{
_eventFilterCalled = 1;
_eventFilterCalled = 1;
if (_userdataCheck != 0) {
SDLTest_AssertCheck(userdata != NULL, "Check userdata pointer, expected: non-NULL, got: %s", (userdata != NULL) ? "non-NULL" : "NULL");
if (userdata != NULL) {
SDLTest_AssertCheck(*(int *)userdata == _userdataValue, "Check userdata value, expected: %i, got: %i", _userdataValue, *(int *)userdata);
}
}
if (_userdataCheck != 0) {
SDLTest_AssertCheck(userdata != NULL, "Check userdata pointer, expected: non-NULL, got: %s", (userdata != NULL) ? "non-NULL" : "NULL");
if (userdata != NULL) {
SDLTest_AssertCheck(*(int *)userdata == _userdataValue, "Check userdata value, expected: %i, got: %i", _userdataValue, *(int *)userdata);
}
}
return 0;
return 0;
}
/**
......@@ -45,34 +45,32 @@ int SDLCALL _events_sampleNullEventFilter(void *userdata, SDL_Event *event)
* @sa http://wiki.libsdl.org/SDL_PumpEvents
* @sa http://wiki.libsdl.org/SDL_PollEvent
*/
int
events_pushPumpAndPollUserevent(void *arg)
int events_pushPumpAndPollUserevent(void *arg)
{
SDL_Event event1;
SDL_Event event2;
int result;
/* Create user event */
event1.type = SDL_USEREVENT;
event1.user.code = SDLTest_RandomSint32();
event1.user.data1 = (void *)&_userdataValue1;
event1.user.data2 = (void *)&_userdataValue2;
/* Push a user event onto the queue and force queue update */
SDL_PushEvent(&event1);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
/* Poll for user event */
result = SDL_PollEvent(&event2);
SDLTest_AssertPass("Call to SDL_PollEvent()");
SDLTest_AssertCheck(result == 1, "Check result from SDL_PollEvent, expected: 1, got: %d", result);
return TEST_COMPLETED;
SDL_Event event1;
SDL_Event event2;
int result;
/* Create user event */
event1.type = SDL_USEREVENT;
event1.user.code = SDLTest_RandomSint32();
event1.user.data1 = (void *)&_userdataValue1;
event1.user.data2 = (void *)&_userdataValue2;
/* Push a user event onto the queue and force queue update */
SDL_PushEvent(&event1);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
/* Poll for user event */
result = SDL_PollEvent(&event2);
SDLTest_AssertPass("Call to SDL_PollEvent()");
SDLTest_AssertCheck(result == 1, "Check result from SDL_PollEvent, expected: 1, got: %d", result);
return TEST_COMPLETED;
}
/**
* @brief Adds and deletes an event watch function with NULL userdata
*
......@@ -80,47 +78,46 @@ events_pushPumpAndPollUserevent(void *arg)
* @sa http://wiki.libsdl.org/SDL_DelEventWatch
*
*/
int
events_addDelEventWatch(void *arg)
int events_addDelEventWatch(void *arg)
{
SDL_Event event;
/* Create user event */
event.type = SDL_USEREVENT;
event.user.code = SDLTest_RandomSint32();
event.user.data1 = (void *)&_userdataValue1;
event.user.data2 = (void *)&_userdataValue2;
/* Disable userdata check */
_userdataCheck = 0;
/* Reset event filter call tracker */
_eventFilterCalled = 0;
/* Add watch */
SDL_AddEventWatch(_events_sampleNullEventFilter, NULL);
SDLTest_AssertPass("Call to SDL_AddEventWatch()");
/* Push a user event onto the queue and force queue update */
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
/* Delete watch */
SDL_DelEventWatch(_events_sampleNullEventFilter, NULL);
SDLTest_AssertPass("Call to SDL_DelEventWatch()");
/* Push a user event onto the queue and force queue update */
_eventFilterCalled = 0;
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
return TEST_COMPLETED;
SDL_Event event;
/* Create user event */
event.type = SDL_USEREVENT;
event.user.code = SDLTest_RandomSint32();
event.user.data1 = (void *)&_userdataValue1;
event.user.data2 = (void *)&_userdataValue2;
/* Disable userdata check */
_userdataCheck = 0;
/* Reset event filter call tracker */
_eventFilterCalled = 0;
/* Add watch */
SDL_AddEventWatch(_events_sampleNullEventFilter, NULL);
SDLTest_AssertPass("Call to SDL_AddEventWatch()");
/* Push a user event onto the queue and force queue update */
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
/* Delete watch */
SDL_DelEventWatch(_events_sampleNullEventFilter, NULL);
SDLTest_AssertPass("Call to SDL_DelEventWatch()");
/* Push a user event onto the queue and force queue update */
_eventFilterCalled = 0;
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
return TEST_COMPLETED;
}
/**
......@@ -130,65 +127,66 @@ events_addDelEventWatch(void *arg)
* @sa http://wiki.libsdl.org/SDL_DelEventWatch
*
*/
int
events_addDelEventWatchWithUserdata(void *arg)
int events_addDelEventWatchWithUserdata(void *arg)
{
SDL_Event event;
/* Create user event */
event.type = SDL_USEREVENT;
event.user.code = SDLTest_RandomSint32();
event.user.data1 = (void *)&_userdataValue1;
event.user.data2 = (void *)&_userdataValue2;
/* Enable userdata check and set a value to check */
_userdataCheck = 1;
_userdataValue = SDLTest_RandomIntegerInRange(-1024, 1024);
/* Reset event filter call tracker */
_eventFilterCalled = 0;
/* Add watch */
SDL_AddEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
SDLTest_AssertPass("Call to SDL_AddEventWatch()");
/* Push a user event onto the queue and force queue update */
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
/* Delete watch */
SDL_DelEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
SDLTest_AssertPass("Call to SDL_DelEventWatch()");
/* Push a user event onto the queue and force queue update */
_eventFilterCalled = 0;
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
return TEST_COMPLETED;
SDL_Event event;
/* Create user event */
event.type = SDL_USEREVENT;
event.user.code = SDLTest_RandomSint32();
event.user.data1 = (void *)&_userdataValue1;
event.user.data2 = (void *)&_userdataValue2;
/* Enable userdata check and set a value to check */
_userdataCheck = 1;
_userdataValue = SDLTest_RandomIntegerInRange(-1024, 1024);
/* Reset event filter call tracker */
_eventFilterCalled = 0;
/* Add watch */
SDL_AddEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
SDLTest_AssertPass("Call to SDL_AddEventWatch()");
/* Push a user event onto the queue and force queue update */
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
/* Delete watch */
SDL_DelEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
SDLTest_AssertPass("Call to SDL_DelEventWatch()");
/* Push a user event onto the queue and force queue update */
_eventFilterCalled = 0;
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Events test cases */
static const SDLTest_TestCaseReference eventsTest1 =
{ (SDLTest_TestCaseFp)events_pushPumpAndPollUserevent, "events_pushPumpAndPollUserevent", "Pushes, pumps and polls a user event", TEST_ENABLED };
static const SDLTest_TestCaseReference eventsTest1 = {
(SDLTest_TestCaseFp)events_pushPumpAndPollUserevent, "events_pushPumpAndPollUserevent", "Pushes, pumps and polls a user event", TEST_ENABLED
};
static const SDLTest_TestCaseReference eventsTest2 =
{ (SDLTest_TestCaseFp)events_addDelEventWatch, "events_addDelEventWatch", "Adds and deletes an event watch function with NULL userdata", TEST_ENABLED };
static const SDLTest_TestCaseReference eventsTest2 = {
(SDLTest_TestCaseFp)events_addDelEventWatch, "events_addDelEventWatch", "Adds and deletes an event watch function with NULL userdata", TEST_ENABLED
};
static const SDLTest_TestCaseReference eventsTest3 =
{ (SDLTest_TestCaseFp)events_addDelEventWatchWithUserdata, "events_addDelEventWatchWithUserdata", "Adds and deletes an event watch function with userdata", TEST_ENABLED };
static const SDLTest_TestCaseReference eventsTest3 = {
(SDLTest_TestCaseFp)events_addDelEventWatchWithUserdata, "events_addDelEventWatchWithUserdata", "Adds and deletes an event watch function with userdata", TEST_ENABLED
};
/* Sequence of Events test cases */
static const SDLTest_TestCaseReference *eventsTests[] = {
static const SDLTest_TestCaseReference *eventsTests[] = {
&eventsTest1, &eventsTest2, &eventsTest3, NULL
};
......
/**
* 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,106 +54,206 @@ 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;
int i;
for (i=0; i<_numHintsEnum; i++) {
result1 = SDL_GetHint(_HintsEnum[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using define definition", (char*)_HintsEnum[i]);
result2 = SDL_GetHint(_HintsVerbose[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char*)_HintsVerbose[i]);
SDLTest_AssertCheck(
(result1 == NULL && result2 == NULL) || (SDL_strcmp(result1, result2) == 0),
"Verify returned values are equal; got: result1='%s' result2='%s",
(result1 == NULL) ? "null" : result1,
(result2 == NULL) ? "null" : result2);
}
const char *result1;
const char *result2;
int i;
for (i = 0; i < _numHintsEnum; i++) {
result1 = SDL_GetHint(_HintsEnum[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using define definition", (char *)_HintsEnum[i]);
result2 = SDL_GetHint(_HintsVerbose[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char *)_HintsVerbose[i]);
SDLTest_AssertCheck(
(result1 == NULL && result2 == NULL) || (SDL_strcmp(result1, result2) == 0),
"Verify returned values are equal; got: result1='%s' result2='%s",
(result1 == NULL) ? "null" : result1,
(result2 == NULL) ? "null" : result2);
}
return TEST_COMPLETED;
}
return TEST_COMPLETED;
static void SDLCALL hints_testHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
*(char **)userdata = hint ? SDL_strdup(hint) : NULL;
}
/**
* @brief Call to SDL_SetHint
*/
int
hints_setHint(void *arg)
int hints_setHint(void *arg)
{
const char *originalValue;
const char *value;
const char *testValue;
SDL_bool result;
int i, j;
/* Create random values to set */
value = SDLTest_RandomAsciiStringOfSize(10);
for (i=0; i<_numHintsEnum; i++) {
/* Capture current value */
originalValue = SDL_GetHint(_HintsEnum[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s)", _HintsEnum[i]);
/* Copy the original value, since it will be freed when we set it again */
originalValue = originalValue ? SDL_strdup(originalValue) : NULL;
/* Set value (twice) */
for (j=1; j<=2; j++) {
result = SDL_SetHint(_HintsEnum[i], value);
SDLTest_AssertPass("Call to SDL_SetHint(%s, %s) (iteration %i)", _HintsEnum[i], value, j);
SDLTest_AssertCheck(
result == SDL_TRUE || result == SDL_FALSE,
"Verify valid result was returned, got: %i",
(int)result);
testValue = SDL_GetHint(_HintsEnum[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", _HintsVerbose[i]);
SDLTest_AssertCheck(
(SDL_strcmp(value, testValue) == 0),
"Verify returned value equals set value; got: testValue='%s' value='%s",
(testValue == NULL) ? "null" : testValue,
value);
const char *testHint = "SDL_AUTOMATED_TEST_HINT";
const char *originalValue;
char *value;
const char *testValue;
char *callbackValue;
SDL_bool result;
int i, j;
/* Create random values to set */
value = SDLTest_RandomAsciiStringOfSize(10);
for (i = 0; i < _numHintsEnum; i++) {
/* Capture current value */
originalValue = SDL_GetHint(_HintsEnum[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s)", _HintsEnum[i]);
/* Copy the original value, since it will be freed when we set it again */
originalValue = originalValue ? SDL_strdup(originalValue) : NULL;
/* Set value (twice) */
for (j = 1; j <= 2; j++) {
result = SDL_SetHint(_HintsEnum[i], value);
SDLTest_AssertPass("Call to SDL_SetHint(%s, %s) (iteration %i)", _HintsEnum[i], value, j);
SDLTest_AssertCheck(
result == SDL_TRUE || result == SDL_FALSE,
"Verify valid result was returned, got: %i",
(int)result);
testValue = SDL_GetHint(_HintsEnum[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", _HintsVerbose[i]);
SDLTest_AssertCheck(
(SDL_strcmp(value, testValue) == 0),
"Verify returned value equals set value; got: testValue='%s' value='%s",
(testValue == NULL) ? "null" : testValue,
value);
}
/* Reset original value */
result = SDL_SetHint(_HintsEnum[i], originalValue);
SDLTest_AssertPass("Call to SDL_SetHint(%s, originalValue)", _HintsEnum[i]);
SDLTest_AssertCheck(
result == SDL_TRUE || result == SDL_FALSE,
"Verify valid result was returned, got: %i",
(int)result);
SDL_free((void *)originalValue);
}
/* Reset original value */
result = SDL_SetHint(_HintsEnum[i], originalValue);
SDLTest_AssertPass("Call to SDL_SetHint(%s, originalValue)", _HintsEnum[i]);
SDL_free(value);
/* Set default value in environment */
SDL_setenv(testHint, "original", 1);
SDLTest_AssertPass("Call to SDL_GetHint() after saving and restoring hint");
originalValue = SDL_GetHint(testHint);
value = (originalValue == NULL) ? NULL : SDL_strdup(originalValue);
SDL_SetHint(testHint, "temp");
SDL_SetHint(testHint, value);
SDL_free(value);
testValue = SDL_GetHint(testHint);
SDLTest_AssertCheck(
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(
result == SDL_TRUE || result == SDL_FALSE,
"Verify valid result was returned, got: %i",
(int)result);
SDL_free((void *)originalValue);
}
callbackValue && SDL_strcmp(callbackValue, "original") == 0,
"callbackValue = %s, expected \"original\"",
callbackValue);
SDL_free(callbackValue);
SDL_free((void *)value);
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);
return TEST_COMPLETED;
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;
}
/* ================= Test References ================== */
/* Hints test cases */
static const SDLTest_TestCaseReference hintsTest1 =
{ (SDLTest_TestCaseFp)hints_getHint, "hints_getHint", "Call to SDL_GetHint", TEST_ENABLED };
static const SDLTest_TestCaseReference hintsTest1 = {
(SDLTest_TestCaseFp)hints_getHint, "hints_getHint", "Call to SDL_GetHint", TEST_ENABLED
};
static const SDLTest_TestCaseReference hintsTest2 =
{ (SDLTest_TestCaseFp)hints_setHint, "hints_setHint", "Call to SDL_SetHint", TEST_ENABLED };
static const SDLTest_TestCaseReference hintsTest2 = {
(SDLTest_TestCaseFp)hints_setHint, "hints_setHint", "Call to SDL_SetHint", TEST_ENABLED
};
/* Sequence of Hints test cases */
static const SDLTest_TestCaseReference *hintsTests[] = {
static const SDLTest_TestCaseReference *hintsTests[] = {
&hintsTest1, &hintsTest2, NULL
};
......
/**
* 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,25 +18,24 @@
*
* @sa http://wiki.libsdl.org/SDL_GetKeyboardState
*/
int
keyboard_getKeyboardState(void *arg)
int keyboard_getKeyboardState(void *arg)
{
int numkeys;
Uint8 *state;
/* Case where numkeys pointer is NULL */
state = (Uint8 *)SDL_GetKeyboardState(NULL);
SDLTest_AssertPass("Call to SDL_GetKeyboardState(NULL)");
SDLTest_AssertCheck(state != NULL, "Validate that return value from SDL_GetKeyboardState is not NULL");
/* Case where numkeys pointer is not NULL */
numkeys = -1;
state = (Uint8 *)SDL_GetKeyboardState(&numkeys);
SDLTest_AssertPass("Call to SDL_GetKeyboardState(&numkeys)");
SDLTest_AssertCheck(state != NULL, "Validate that return value from SDL_GetKeyboardState is not NULL");
SDLTest_AssertCheck(numkeys >= 0, "Validate that value of numkeys is >= 0, got: %i", numkeys);
return TEST_COMPLETED;
int numkeys;
Uint8 *state;
/* Case where numkeys pointer is NULL */
state = (Uint8 *)SDL_GetKeyboardState(NULL);
SDLTest_AssertPass("Call to SDL_GetKeyboardState(NULL)");
SDLTest_AssertCheck(state != NULL, "Validate that return value from SDL_GetKeyboardState is not NULL");
/* Case where numkeys pointer is not NULL */
numkeys = -1;
state = (Uint8 *)SDL_GetKeyboardState(&numkeys);
SDLTest_AssertPass("Call to SDL_GetKeyboardState(&numkeys)");
SDLTest_AssertCheck(state != NULL, "Validate that return value from SDL_GetKeyboardState is not NULL");
SDLTest_AssertCheck(numkeys >= 0, "Validate that value of numkeys is >= 0, got: %i", numkeys);
return TEST_COMPLETED;
}
/**
......@@ -44,14 +43,13 @@ 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();
SDLTest_AssertPass("Call to SDL_GetKeyboardFocus()");
/* Call, but ignore return value */
SDL_GetKeyboardFocus();
SDLTest_AssertPass("Call to SDL_GetKeyboardFocus()");
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
......@@ -59,66 +57,64 @@ 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);
/* Case where Key is known, 2 character input */
result = SDL_GetKeyFromName("F1");
SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/double)");
SDLTest_AssertCheck(result == SDLK_F1, "Verify result from call, expected: %i, got: %i", SDLK_F1, result);
/* Case where Key is known, 3 character input */
result = SDL_GetKeyFromName("End");
SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/triple)");
SDLTest_AssertCheck(result == SDLK_END, "Verify result from call, expected: %i, got: %i", SDLK_END, result);
/* Case where Key is known, 4 character input */
result = SDL_GetKeyFromName("Find");
SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/quad)");
SDLTest_AssertCheck(result == SDLK_FIND, "Verify result from call, expected: %i, got: %i", SDLK_FIND, result);
/* Case where Key is known, multiple character input */
result = SDL_GetKeyFromName("AudioStop");
SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/multi)");
SDLTest_AssertCheck(result == SDLK_AUDIOSTOP, "Verify result from call, expected: %i, got: %i", SDLK_AUDIOSTOP, result);
/* Case where Key is unknown */
result = SDL_GetKeyFromName("NotThere");
SDLTest_AssertPass("Call to SDL_GetKeyFromName(unknown)");
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
/* Case where input is NULL/invalid */
result = SDL_GetKeyFromName(NULL);
SDLTest_AssertPass("Call to SDL_GetKeyFromName(NULL)");
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
return TEST_COMPLETED;
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: %" 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: %" 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: %" 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: %" 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: %" 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: %" 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: %" SDL_PRIs32, SDLK_UNKNOWN, result);
return TEST_COMPLETED;
}
/*
* Local helper to check for the invalid scancode error message
*/
void
_checkInvalidScancodeError()
void _checkInvalidScancodeError()
{
const char *expectedError = "Parameter 'scancode' is invalid";
const char *error;
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
}
const char *expectedError = "Parameter 'scancode' is invalid";
const char *error;
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
}
}
/**
......@@ -126,38 +122,37 @@ _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);
/* Case where input is zero */
result = SDL_GetKeyFromScancode(0);
SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(0)");
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
/* Clear error message */
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
/* Case where input is invalid (too small) */
result = SDL_GetKeyFromScancode(-999);
SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(-999)");
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
_checkInvalidScancodeError();
/* Case where input is invalid (too big) */
result = SDL_GetKeyFromScancode(999);
SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(999)");
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
_checkInvalidScancodeError();
return TEST_COMPLETED;
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: %" 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: %" SDL_PRIs32, SDLK_UNKNOWN, result);
/* Clear error message */
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
/* Case where input is invalid (too small) */
result = SDL_GetKeyFromScancode(-999);
SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(-999)");
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %" 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: %" SDL_PRIs32, SDLK_UNKNOWN, result);
_checkInvalidScancodeError();
return TEST_COMPLETED;
}
/**
......@@ -165,55 +160,54 @@ 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;
/* Case where key has a 1 character name */
expected = "3";
result = (char *)SDL_GetKeyName(SDLK_3);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
/* Case where key has a 2 character name */
expected = "F1";
result = (char *)SDL_GetKeyName(SDLK_F1);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
/* Case where key has a 3 character name */
expected = "Cut";
result = (char *)SDL_GetKeyName(SDLK_CUT);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
/* Case where key has a 4 character name */
expected = "Down";
result = (char *)SDL_GetKeyName(SDLK_DOWN);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
/* Case where key has a N character name */
expected = "BrightnessUp";
result = (char *)SDL_GetKeyName(SDLK_BRIGHTNESSUP);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
/* Case where key has a N character name with space */
expected = "Keypad MemStore";
result = (char *)SDL_GetKeyName(SDLK_KP_MEMSTORE);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
return TEST_COMPLETED;
const char *result;
const char *expected;
/* Case where key has a 1 character name */
expected = "3";
result = (char *)SDL_GetKeyName(SDLK_3);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
/* Case where key has a 2 character name */
expected = "F1";
result = (char *)SDL_GetKeyName(SDLK_F1);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
/* Case where key has a 3 character name */
expected = "Cut";
result = (char *)SDL_GetKeyName(SDLK_CUT);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
/* Case where key has a 4 character name */
expected = "Down";
result = (char *)SDL_GetKeyName(SDLK_DOWN);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
/* Case where key has a N character name */
expected = "BrightnessUp";
result = (char *)SDL_GetKeyName(SDLK_BRIGHTNESSUP);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
/* Case where key has a N character name with space */
expected = "Keypad MemStore";
result = (char *)SDL_GetKeyName(SDLK_KP_MEMSTORE);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
return TEST_COMPLETED;
}
/**
......@@ -221,26 +215,25 @@ 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;
const char *expected = "";
/* Clear error message */
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
/* Out-of-bounds scancode */
scancode = (SDL_Scancode)SDL_NUM_SCANCODES;
result = (char *)SDL_GetScancodeName(scancode);
SDLTest_AssertPass("Call to SDL_GetScancodeName(%d/large)", scancode);
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result);
_checkInvalidScancodeError();
return TEST_COMPLETED;
SDL_Scancode scancode;
const char *result;
const char *expected = "";
/* Clear error message */
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
/* Out-of-bounds scancode */
scancode = (SDL_Scancode)SDL_NUM_SCANCODES;
result = (char *)SDL_GetScancodeName(scancode);
SDLTest_AssertPass("Call to SDL_GetScancodeName(%d/large)", scancode);
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result);
_checkInvalidScancodeError();
return TEST_COMPLETED;
}
/**
......@@ -248,36 +241,35 @@ 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;
const char *expected = "";
/* Unknown keycode */
keycode = SDLK_UNKNOWN;
result = (char *)SDL_GetKeyName(keycode);
SDLTest_AssertPass("Call to SDL_GetKeyName(%d/unknown)", keycode);
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result);
/* Clear error message */
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
/* Negative keycode */
keycode = (SDL_Keycode)SDLTest_RandomIntegerInRange(-255, -1);
result = (char *)SDL_GetKeyName(keycode);
SDLTest_AssertPass("Call to SDL_GetKeyName(%d/negative)", keycode);
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result);
_checkInvalidScancodeError();
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
return TEST_COMPLETED;
SDL_Keycode keycode;
const char *result;
const char *expected = "";
/* Unknown keycode */
keycode = SDLK_UNKNOWN;
result = (char *)SDL_GetKeyName(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);
/* Clear error message */
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
/* Negative keycode */
keycode = (SDL_Keycode)SDLTest_RandomIntegerInRange(-255, -1);
result = (char *)SDL_GetKeyName(keycode);
SDLTest_AssertPass("Call to SDL_GetKeyName(%" 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();
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
return TEST_COMPLETED;
}
/**
......@@ -286,106 +278,103 @@ 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;
SDL_Keymod newState;
SDL_Keymod allStates =
KMOD_NONE |
KMOD_LSHIFT |
KMOD_RSHIFT |
KMOD_LCTRL |
KMOD_RCTRL |
KMOD_LALT |
KMOD_RALT |
KMOD_LGUI |
KMOD_RGUI |
KMOD_NUM |
KMOD_CAPS |
KMOD_MODE |
KMOD_SCROLL;
/* Get state, cache for later reset */
result = SDL_GetModState();
SDLTest_AssertPass("Call to SDL_GetModState()");
SDLTest_AssertCheck(/*result >= 0 &&*/ result <= allStates, "Verify result from call is valid, expected: 0 <= result <= %i, got: %i", allStates, result);
currentState = result;
/* Set random state */
newState = SDLTest_RandomIntegerInRange(0, allStates);
SDL_SetModState(newState);
SDLTest_AssertPass("Call to SDL_SetModState(%i)", newState);
result = SDL_GetModState();
SDLTest_AssertPass("Call to SDL_GetModState()");
SDLTest_AssertCheck(result == newState, "Verify result from call is valid, expected: %i, got: %i", newState, result);
/* Set zero state */
SDL_SetModState(0);
SDLTest_AssertPass("Call to SDL_SetModState(0)");
result = SDL_GetModState();
SDLTest_AssertPass("Call to SDL_GetModState()");
SDLTest_AssertCheck(result == 0, "Verify result from call is valid, expected: 0, got: %i", result);
/* Revert back to cached current state if needed */
if (currentState != 0) {
SDL_SetModState(currentState);
SDLTest_AssertPass("Call to SDL_SetModState(%i)", currentState);
result = SDL_GetModState();
SDLTest_AssertPass("Call to SDL_GetModState()");
SDLTest_AssertCheck(result == currentState, "Verify result from call is valid, expected: %i, got: %i", currentState, result);
}
return TEST_COMPLETED;
SDL_Keymod result;
SDL_Keymod currentState;
SDL_Keymod newState;
SDL_Keymod allStates =
KMOD_NONE |
KMOD_LSHIFT |
KMOD_RSHIFT |
KMOD_LCTRL |
KMOD_RCTRL |
KMOD_LALT |
KMOD_RALT |
KMOD_LGUI |
KMOD_RGUI |
KMOD_NUM |
KMOD_CAPS |
KMOD_MODE |
KMOD_SCROLL;
/* Get state, cache for later reset */
result = SDL_GetModState();
SDLTest_AssertPass("Call to SDL_GetModState()");
SDLTest_AssertCheck(/*result >= 0 &&*/ result <= allStates, "Verify result from call is valid, expected: 0 <= result <= %i, got: %i", allStates, result);
currentState = result;
/* Set random state */
newState = SDLTest_RandomIntegerInRange(0, allStates);
SDL_SetModState(newState);
SDLTest_AssertPass("Call to SDL_SetModState(%i)", newState);
result = SDL_GetModState();
SDLTest_AssertPass("Call to SDL_GetModState()");
SDLTest_AssertCheck(result == newState, "Verify result from call is valid, expected: %i, got: %i", newState, result);
/* Set zero state */
SDL_SetModState(0);
SDLTest_AssertPass("Call to SDL_SetModState(0)");
result = SDL_GetModState();
SDLTest_AssertPass("Call to SDL_GetModState()");
SDLTest_AssertCheck(result == 0, "Verify result from call is valid, expected: 0, got: %i", result);
/* Revert back to cached current state if needed */
if (currentState != 0) {
SDL_SetModState(currentState);
SDLTest_AssertPass("Call to SDL_SetModState(%i)", currentState);
result = SDL_GetModState();
SDLTest_AssertPass("Call to SDL_GetModState()");
SDLTest_AssertCheck(result == currentState, "Verify result from call is valid, expected: %i, got: %i", currentState, result);
}
return TEST_COMPLETED;
}
/**
* @brief Check call to SDL_StartTextInput and SDL_StopTextInput
*
* @sa http://wiki.libsdl.org/SDL_StartTextInput
* @sa http://wiki.libsdl.org/SDL_StopTextInput
*/
int
keyboard_startStopTextInput(void *arg)
int keyboard_startStopTextInput(void *arg)
{
/* Start-Stop */
SDL_StartTextInput();
SDLTest_AssertPass("Call to SDL_StartTextInput()");
SDL_StopTextInput();
SDLTest_AssertPass("Call to SDL_StopTextInput()");
/* Stop-Start */
SDL_StartTextInput();
SDLTest_AssertPass("Call to SDL_StartTextInput()");
/* Start-Start */
SDL_StartTextInput();
SDLTest_AssertPass("Call to SDL_StartTextInput()");
/* Stop-Stop */
SDL_StopTextInput();
SDLTest_AssertPass("Call to SDL_StopTextInput()");
SDL_StopTextInput();
SDLTest_AssertPass("Call to SDL_StopTextInput()");
return TEST_COMPLETED;
/* Start-Stop */
SDL_StartTextInput();
SDLTest_AssertPass("Call to SDL_StartTextInput()");
SDL_StopTextInput();
SDLTest_AssertPass("Call to SDL_StopTextInput()");
/* Stop-Start */
SDL_StartTextInput();
SDLTest_AssertPass("Call to SDL_StartTextInput()");
/* Start-Start */
SDL_StartTextInput();
SDLTest_AssertPass("Call to SDL_StartTextInput()");
/* Stop-Stop */
SDL_StopTextInput();
SDLTest_AssertPass("Call to SDL_StopTextInput()");
SDL_StopTextInput();
SDLTest_AssertPass("Call to SDL_StopTextInput()");
return TEST_COMPLETED;
}
/* Internal function to test SDL_SetTextInputRect */
void _testSetTextInputRect(SDL_Rect refRect)
{
SDL_Rect testRect;
testRect = refRect;
SDL_SetTextInputRect(&testRect);
SDLTest_AssertPass("Call to SDL_SetTextInputRect with refRect(x:%i,y:%i,w:%i,h:%i)", refRect.x, refRect.y, refRect.w, refRect.h);
SDLTest_AssertCheck(
(refRect.x == testRect.x) && (refRect.y == testRect.y) && (refRect.w == testRect.w) && (refRect.h == testRect.h),
"Check that input data was not modified, expected: x:%i,y:%i,w:%i,h:%i, got: x:%i,y:%i,w:%i,h:%i",
refRect.x, refRect.y, refRect.w, refRect.h,
testRect.x, testRect.y, testRect.w, testRect.h);
SDL_Rect testRect;
testRect = refRect;
SDL_SetTextInputRect(&testRect);
SDLTest_AssertPass("Call to SDL_SetTextInputRect with refRect(x:%i,y:%i,w:%i,h:%i)", refRect.x, refRect.y, refRect.w, refRect.h);
SDLTest_AssertCheck(
(refRect.x == testRect.x) && (refRect.y == testRect.y) && (refRect.w == testRect.w) && (refRect.h == testRect.h),
"Check that input data was not modified, expected: x:%i,y:%i,w:%i,h:%i, got: x:%i,y:%i,w:%i,h:%i",
refRect.x, refRect.y, refRect.w, refRect.h,
testRect.x, testRect.y, testRect.w, testRect.h);
}
/**
......@@ -393,79 +382,78 @@ 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;
/* Normal visible refRect, origin inside */
refRect.x = SDLTest_RandomIntegerInRange(1, 50);
refRect.y = SDLTest_RandomIntegerInRange(1, 50);
refRect.w = SDLTest_RandomIntegerInRange(10, 50);
refRect.h = SDLTest_RandomIntegerInRange(10, 50);
_testSetTextInputRect(refRect);
/* Normal visible refRect, origin 0,0 */
refRect.x = 0;
refRect.y = 0;
refRect.w = SDLTest_RandomIntegerInRange(10, 50);
refRect.h = SDLTest_RandomIntegerInRange(10, 50);
_testSetTextInputRect(refRect);
/* 1Pixel refRect */
refRect.x = SDLTest_RandomIntegerInRange(10, 50);
refRect.y = SDLTest_RandomIntegerInRange(10, 50);
refRect.w = 1;
refRect.h = 1;
_testSetTextInputRect(refRect);
/* 0pixel refRect */
refRect.x = 1;
refRect.y = 1;
refRect.w = 1;
refRect.h = 0;
_testSetTextInputRect(refRect);
/* 0pixel refRect */
refRect.x = 1;
refRect.y = 1;
refRect.w = 0;
refRect.h = 1;
_testSetTextInputRect(refRect);
/* 0pixel refRect */
refRect.x = 1;
refRect.y = 1;
refRect.w = 0;
refRect.h = 0;
_testSetTextInputRect(refRect);
/* 0pixel refRect */
refRect.x = 0;
refRect.y = 0;
refRect.w = 0;
refRect.h = 0;
_testSetTextInputRect(refRect);
/* negative refRect */
refRect.x = SDLTest_RandomIntegerInRange(-200, -100);
refRect.y = SDLTest_RandomIntegerInRange(-200, -100);
refRect.w = 50;
refRect.h = 50;
_testSetTextInputRect(refRect);
/* oversized refRect */
refRect.x = SDLTest_RandomIntegerInRange(1, 50);
refRect.y = SDLTest_RandomIntegerInRange(1, 50);
refRect.w = 5000;
refRect.h = 5000;
_testSetTextInputRect(refRect);
/* NULL refRect */
SDL_SetTextInputRect(NULL);
SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");
return TEST_COMPLETED;
SDL_Rect refRect;
/* Normal visible refRect, origin inside */
refRect.x = SDLTest_RandomIntegerInRange(1, 50);
refRect.y = SDLTest_RandomIntegerInRange(1, 50);
refRect.w = SDLTest_RandomIntegerInRange(10, 50);
refRect.h = SDLTest_RandomIntegerInRange(10, 50);
_testSetTextInputRect(refRect);
/* Normal visible refRect, origin 0,0 */
refRect.x = 0;
refRect.y = 0;
refRect.w = SDLTest_RandomIntegerInRange(10, 50);
refRect.h = SDLTest_RandomIntegerInRange(10, 50);
_testSetTextInputRect(refRect);
/* 1Pixel refRect */
refRect.x = SDLTest_RandomIntegerInRange(10, 50);
refRect.y = SDLTest_RandomIntegerInRange(10, 50);
refRect.w = 1;
refRect.h = 1;
_testSetTextInputRect(refRect);
/* 0pixel refRect */
refRect.x = 1;
refRect.y = 1;
refRect.w = 1;
refRect.h = 0;
_testSetTextInputRect(refRect);
/* 0pixel refRect */
refRect.x = 1;
refRect.y = 1;
refRect.w = 0;
refRect.h = 1;
_testSetTextInputRect(refRect);
/* 0pixel refRect */
refRect.x = 1;
refRect.y = 1;
refRect.w = 0;
refRect.h = 0;
_testSetTextInputRect(refRect);
/* 0pixel refRect */
refRect.x = 0;
refRect.y = 0;
refRect.w = 0;
refRect.h = 0;
_testSetTextInputRect(refRect);
/* negative refRect */
refRect.x = SDLTest_RandomIntegerInRange(-200, -100);
refRect.y = SDLTest_RandomIntegerInRange(-200, -100);
refRect.w = 50;
refRect.h = 50;
_testSetTextInputRect(refRect);
/* oversized refRect */
refRect.x = SDLTest_RandomIntegerInRange(1, 50);
refRect.y = SDLTest_RandomIntegerInRange(1, 50);
refRect.w = 5000;
refRect.h = 5000;
_testSetTextInputRect(refRect);
/* NULL refRect */
SDL_SetTextInputRect(NULL);
SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");
return TEST_COMPLETED;
}
/**
......@@ -473,37 +461,36 @@ 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 */
/* Some platforms set also an error message; prepare for checking it */
#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_COCOA
const char *expectedError = "Parameter 'rect' is invalid";
const char *error;
const char *expectedError = "Parameter 'rect' is invalid";
const char *error;
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
#endif
/* NULL refRect */
SDL_SetTextInputRect(NULL);
SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");
/* NULL refRect */
SDL_SetTextInputRect(NULL);
SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");
/* Some platforms set also an error message; so check it */
/* Some platforms set also an error message; so check it */
#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_COCOA
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
}
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
}
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
#endif
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
......@@ -512,22 +499,21 @@ 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;
SDL_Scancode scancode;
/* Regular key */
scancode = SDL_GetScancodeFromKey(SDLK_4);
SDLTest_AssertPass("Call to SDL_GetScancodeFromKey(SDLK_4)");
SDLTest_AssertCheck(scancode == SDL_SCANCODE_4, "Validate return value from SDL_GetScancodeFromKey, expected: %i, got: %i", SDL_SCANCODE_4, scancode);
/* Regular key */
scancode = SDL_GetScancodeFromKey(SDLK_4);
SDLTest_AssertPass("Call to SDL_GetScancodeFromKey(SDLK_4)");
SDLTest_AssertCheck(scancode == SDL_SCANCODE_4, "Validate return value from SDL_GetScancodeFromKey, expected: %i, got: %i", SDL_SCANCODE_4, scancode);
/* Virtual key */
scancode = SDL_GetScancodeFromKey(SDLK_PLUS);
SDLTest_AssertPass("Call to SDL_GetScancodeFromKey(SDLK_PLUS)");
SDLTest_AssertCheck(scancode == 0, "Validate return value from SDL_GetScancodeFromKey, expected: 0, got: %i", scancode);
/* Virtual key */
scancode = SDL_GetScancodeFromKey(SDLK_PLUS);
SDLTest_AssertPass("Call to SDL_GetScancodeFromKey(SDLK_PLUS)");
SDLTest_AssertCheck(scancode == 0, "Validate return value from SDL_GetScancodeFromKey, expected: 0, got: %i", scancode);
return TEST_COMPLETED;
return TEST_COMPLETED;
}
/**
......@@ -536,71 +522,69 @@ 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;
/* Regular key, 1 character, first name in list */
scancode = SDL_GetScancodeFromName("A");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('A')");
SDLTest_AssertCheck(scancode == SDL_SCANCODE_A, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_A, scancode);
/* Regular key, 1 character */
scancode = SDL_GetScancodeFromName("4");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('4')");
SDLTest_AssertCheck(scancode == SDL_SCANCODE_4, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_4, scancode);
/* Regular key, 2 characters */
scancode = SDL_GetScancodeFromName("F1");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('F1')");
SDLTest_AssertCheck(scancode == SDL_SCANCODE_F1, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_F1, scancode);
/* Regular key, 3 characters */
scancode = SDL_GetScancodeFromName("End");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('End')");
SDLTest_AssertCheck(scancode == SDL_SCANCODE_END, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_END, scancode);
/* Regular key, 4 characters */
scancode = SDL_GetScancodeFromName("Find");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Find')");
SDLTest_AssertCheck(scancode == SDL_SCANCODE_FIND, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_FIND, scancode);
/* Regular key, several characters */
scancode = SDL_GetScancodeFromName("Backspace");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Backspace')");
SDLTest_AssertCheck(scancode == SDL_SCANCODE_BACKSPACE, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_BACKSPACE, scancode);
/* Regular key, several characters with space */
scancode = SDL_GetScancodeFromName("Keypad Enter");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Keypad Enter')");
SDLTest_AssertCheck(scancode == SDL_SCANCODE_KP_ENTER, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_KP_ENTER, scancode);
/* Regular key, last name in list */
scancode = SDL_GetScancodeFromName("Sleep");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Sleep')");
SDLTest_AssertCheck(scancode == SDL_SCANCODE_SLEEP, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_SLEEP, scancode);
return TEST_COMPLETED;
SDL_Scancode scancode;
/* Regular key, 1 character, first name in list */
scancode = SDL_GetScancodeFromName("A");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('A')");
SDLTest_AssertCheck(scancode == SDL_SCANCODE_A, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_A, scancode);
/* Regular key, 1 character */
scancode = SDL_GetScancodeFromName("4");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('4')");
SDLTest_AssertCheck(scancode == SDL_SCANCODE_4, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_4, scancode);
/* Regular key, 2 characters */
scancode = SDL_GetScancodeFromName("F1");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('F1')");
SDLTest_AssertCheck(scancode == SDL_SCANCODE_F1, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_F1, scancode);
/* Regular key, 3 characters */
scancode = SDL_GetScancodeFromName("End");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('End')");
SDLTest_AssertCheck(scancode == SDL_SCANCODE_END, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_END, scancode);
/* Regular key, 4 characters */
scancode = SDL_GetScancodeFromName("Find");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Find')");
SDLTest_AssertCheck(scancode == SDL_SCANCODE_FIND, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_FIND, scancode);
/* Regular key, several characters */
scancode = SDL_GetScancodeFromName("Backspace");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Backspace')");
SDLTest_AssertCheck(scancode == SDL_SCANCODE_BACKSPACE, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_BACKSPACE, scancode);
/* Regular key, several characters with space */
scancode = SDL_GetScancodeFromName("Keypad Enter");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Keypad Enter')");
SDLTest_AssertCheck(scancode == SDL_SCANCODE_KP_ENTER, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_KP_ENTER, scancode);
/* Regular key, last name in list */
scancode = SDL_GetScancodeFromName("Sleep");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Sleep')");
SDLTest_AssertCheck(scancode == SDL_SCANCODE_SLEEP, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_SLEEP, scancode);
return TEST_COMPLETED;
}
/*
* Local helper to check for the invalid scancode error message
*/
void
_checkInvalidNameError()
void _checkInvalidNameError()
{
const char *expectedError = "Parameter 'name' is invalid";
const char *error;
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
}
const char *expectedError = "Parameter 'name' is invalid";
const char *error;
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
}
}
/**
......@@ -609,94 +593,105 @@ _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;
/* Clear error message */
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
/* Random string input */
name = SDLTest_RandomAsciiStringOfSize(32);
SDLTest_Assert(name != NULL, "Check that random name is not NULL");
if (name == NULL) {
return TEST_ABORTED;
}
scancode = SDL_GetScancodeFromName(name);
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('%s')", name);
SDL_free((void *)name);
SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
_checkInvalidNameError();
/* Zero length string input */
name = "";
scancode = SDL_GetScancodeFromName((const char *)name);
SDLTest_AssertPass("Call to SDL_GetScancodeFromName(NULL)");
SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
_checkInvalidNameError();
/* NULL input */
name = NULL;
scancode = SDL_GetScancodeFromName((const char *)name);
SDLTest_AssertPass("Call to SDL_GetScancodeFromName(NULL)");
SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
_checkInvalidNameError();
return TEST_COMPLETED;
const char *name;
SDL_Scancode scancode;
/* Clear error message */
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
/* Random string input */
name = SDLTest_RandomAsciiStringOfSize(32);
SDLTest_Assert(name != NULL, "Check that random name is not NULL");
if (name == NULL) {
return TEST_ABORTED;
}
scancode = SDL_GetScancodeFromName(name);
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('%s')", name);
SDL_free((void *)name);
SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
_checkInvalidNameError();
/* Zero length string input */
name = "";
scancode = SDL_GetScancodeFromName(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(name);
SDLTest_AssertPass("Call to SDL_GetScancodeFromName(NULL)");
SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
_checkInvalidNameError();
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Keyboard test cases */
static const SDLTest_TestCaseReference keyboardTest1 =
{ (SDLTest_TestCaseFp)keyboard_getKeyboardState, "keyboard_getKeyboardState", "Check call to SDL_GetKeyboardState with and without numkeys reference", TEST_ENABLED };
static const SDLTest_TestCaseReference 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[] = {
static const SDLTest_TestCaseReference *keyboardTests[] = {
&keyboardTest1, &keyboardTest2, &keyboardTest3, &keyboardTest4, &keyboardTest5, &keyboardTest6,
&keyboardTest7, &keyboardTest8, &keyboardTest9, &keyboardTest10, &keyboardTest11, &keyboardTest12,
&keyboardTest13, &keyboardTest14, NULL
......
......@@ -9,14 +9,13 @@
#include "SDL.h"
#include "SDL_test.h"
/* !
* \brief Tests SDL_Init() and SDL_Quit() of Joystick and Haptic subsystems
* \sa
* http://wiki.libsdl.org/SDL_Init
* http://wiki.libsdl.org/SDL_Quit
*/
static int main_testInitQuitJoystickHaptic (void *arg)
static int main_testInitQuitJoystickHaptic(void *arg)
{
#if defined SDL_JOYSTICK_DISABLED || defined SDL_HAPTIC_DISABLED
return TEST_SKIPPED;
......@@ -24,15 +23,15 @@ static int main_testInitQuitJoystickHaptic (void *arg)
int enabled_subsystems;
int initialized_subsystems = SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC;
SDLTest_AssertCheck( SDL_Init(initialized_subsystems) == 0, "SDL_Init multiple systems." );
SDLTest_AssertCheck(SDL_Init(initialized_subsystems) == 0, "SDL_Init multiple systems.");
enabled_subsystems = SDL_WasInit(initialized_subsystems);
SDLTest_AssertCheck( enabled_subsystems == initialized_subsystems, "SDL_WasInit(SDL_INIT_EVERYTHING) contains all systems (%i)", enabled_subsystems );
SDLTest_AssertCheck(enabled_subsystems == initialized_subsystems, "SDL_WasInit(SDL_INIT_EVERYTHING) contains all systems (%i)", enabled_subsystems);
SDL_Quit();
enabled_subsystems = SDL_WasInit(initialized_subsystems);
SDLTest_AssertCheck( enabled_subsystems == 0, "SDL_Quit should shut down everything (%i)", enabled_subsystems );
SDLTest_AssertCheck(enabled_subsystems == 0, "SDL_Quit should shut down everything (%i)", enabled_subsystems);
return TEST_COMPLETED;
#endif
......@@ -44,7 +43,7 @@ static int main_testInitQuitJoystickHaptic (void *arg)
* http://wiki.libsdl.org/SDL_Init
* http://wiki.libsdl.org/SDL_Quit
*/
static int main_testInitQuitSubSystem (void *arg)
static int main_testInitQuitSubSystem(void *arg)
{
#if defined SDL_JOYSTICK_DISABLED || defined SDL_HAPTIC_DISABLED || defined SDL_GAMECONTROLLER_DISABLED
return TEST_SKIPPED;
......@@ -56,15 +55,15 @@ static int main_testInitQuitSubSystem (void *arg)
int initialized_system;
int subsystem = subsystems[i];
SDLTest_AssertCheck( (SDL_WasInit(subsystem) & subsystem) == 0, "SDL_WasInit(%x) before init should be false", subsystem );
SDLTest_AssertCheck( SDL_InitSubSystem(subsystem) == 0, "SDL_InitSubSystem(%x)", subsystem );
SDLTest_AssertCheck((SDL_WasInit(subsystem) & subsystem) == 0, "SDL_WasInit(%x) before init should be false", subsystem);
SDLTest_AssertCheck(SDL_InitSubSystem(subsystem) == 0, "SDL_InitSubSystem(%x)", subsystem);
initialized_system = SDL_WasInit(subsystem);
SDLTest_AssertCheck( (initialized_system & subsystem) != 0, "SDL_WasInit(%x) should be true (%x)", subsystem, initialized_system );
SDLTest_AssertCheck((initialized_system & subsystem) != 0, "SDL_WasInit(%x) should be true (%x)", subsystem, initialized_system);
SDL_QuitSubSystem(subsystem);
SDLTest_AssertCheck( (SDL_WasInit(subsystem) & subsystem) == 0, "SDL_WasInit(%x) after shutdown should be false", subsystem );
SDLTest_AssertCheck((SDL_WasInit(subsystem) & subsystem) == 0, "SDL_WasInit(%x) after shutdown should be false", subsystem);
}
return TEST_COMPLETED;
......@@ -72,7 +71,7 @@ static int main_testInitQuitSubSystem (void *arg)
}
const int joy_and_controller = SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER;
static int main_testImpliedJoystickInit (void *arg)
static int main_testImpliedJoystickInit(void *arg)
{
#if defined SDL_JOYSTICK_DISABLED || defined SDL_GAMECONTROLLER_DISABLED
return TEST_SKIPPED;
......@@ -80,24 +79,24 @@ static int main_testImpliedJoystickInit (void *arg)
int initialized_system;
/* First initialize the controller */
SDLTest_AssertCheck( (SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller" );
SDLTest_AssertCheck( SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)" );
SDLTest_AssertCheck((SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller");
SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)");
/* Then make sure this implicitly initialized the joystick subsystem */
initialized_system = SDL_WasInit(joy_and_controller);
SDLTest_AssertCheck( (initialized_system & joy_and_controller) == joy_and_controller, "SDL_WasInit() should be true for joystick & controller (%x)", initialized_system );
SDLTest_AssertCheck((initialized_system & joy_and_controller) == joy_and_controller, "SDL_WasInit() should be true for joystick & controller (%x)", initialized_system);
/* Then quit the controller, and make sure that implicitly also quits the */
/* joystick subsystem */
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
initialized_system = SDL_WasInit(joy_and_controller);
SDLTest_AssertCheck( (initialized_system & joy_and_controller) == 0, "SDL_WasInit() should be false for joystick & controller (%x)", initialized_system );
SDLTest_AssertCheck((initialized_system & joy_and_controller) == 0, "SDL_WasInit() should be false for joystick & controller (%x)", initialized_system);
return TEST_COMPLETED;
#endif
}
static int main_testImpliedJoystickQuit (void *arg)
static int main_testImpliedJoystickQuit(void *arg)
{
#if defined SDL_JOYSTICK_DISABLED || defined SDL_GAMECONTROLLER_DISABLED
return TEST_SKIPPED;
......@@ -105,19 +104,19 @@ static int main_testImpliedJoystickQuit (void *arg)
int initialized_system;
/* First initialize the controller and the joystick (explicitly) */
SDLTest_AssertCheck( (SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller" );
SDLTest_AssertCheck( SDL_InitSubSystem(SDL_INIT_JOYSTICK) == 0, "SDL_InitSubSystem(SDL_INIT_JOYSTICK)" );
SDLTest_AssertCheck( SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)" );
SDLTest_AssertCheck((SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller");
SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_JOYSTICK) == 0, "SDL_InitSubSystem(SDL_INIT_JOYSTICK)");
SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)");
/* Then make sure they're both initialized properly */
initialized_system = SDL_WasInit(joy_and_controller);
SDLTest_AssertCheck( (initialized_system & joy_and_controller) == joy_and_controller, "SDL_WasInit() should be true for joystick & controller (%x)", initialized_system );
SDLTest_AssertCheck((initialized_system & joy_and_controller) == joy_and_controller, "SDL_WasInit() should be true for joystick & controller (%x)", initialized_system);
/* Then quit the controller, and make sure that it does NOT quit the */
/* explicitly initialized joystick subsystem. */
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
initialized_system = SDL_WasInit(joy_and_controller);
SDLTest_AssertCheck( (initialized_system & joy_and_controller) == SDL_INIT_JOYSTICK, "SDL_WasInit() should be false for joystick & controller (%x)", initialized_system );
SDLTest_AssertCheck((initialized_system & joy_and_controller) == SDL_INIT_JOYSTICK, "SDL_WasInit() should be false for joystick & controller (%x)", initialized_system);
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
......@@ -125,24 +124,62 @@ 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[] = {
static const SDLTest_TestCaseReference *mainTests[] = {
&mainTest1,
&mainTest2,
&mainTest3,
&mainTest4,
&mainTest5,
NULL
};
......