From 65728477afc7883959afe23c7651b0fdc3e67763 Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Wed, 14 Aug 2013 23:30:10 -0700 Subject: [PATCH] Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency --- .../tests/loopwave/loopwave_VS2010.vcxproj | 14 ++- .../tests/loopwave/loopwave_VS2012.vcxproj | 12 +- test/checkkeys.c | 13 ++- test/loopwave.c | 20 ++-- test/testatomic.c | 109 ++++++++++-------- test/testaudioinfo.c | 25 ++-- test/testautomation.c | 3 +- test/testautomation_surface.c | 2 - test/testdraw2.c | 8 +- test/testdrawchessboard.c | 9 +- test/testerror.c | 15 ++- test/testfile.c | 17 +-- test/testgamecontroller.c | 43 +++---- test/testgesture.c | 3 + test/testgl2.c | 55 ++++----- test/testgles.c | 61 +++++----- test/testhaptic.c | 86 +++++++------- test/testiconv.c | 7 +- test/testime.c | 18 +-- test/testintersections.c | 12 +- test/testjoystick.c | 59 +++++----- test/testkeys.c | 7 +- test/testloadso.c | 18 +-- test/testlock.c | 27 +++-- test/testmessage.c | 21 ++-- test/testmultiaudio.c | 26 +++-- test/testnative.c | 21 ++-- test/testoverlay2.c | 54 ++++----- test/testplatform.c | 57 ++++----- test/testpower.c | 17 +-- test/testrelative.c | 4 +- test/testrendercopyex.c | 11 +- test/testrendertarget.c | 14 ++- test/testresample.c | 21 ++-- test/testrumble.c | 32 ++--- test/testscale.c | 11 +- test/testsem.c | 29 ++--- test/testshader.c | 22 ++-- test/testshape.c | 15 ++- test/testsprite2.c | 13 +-- test/testspriteminimal.c | 7 +- test/teststreaming.c | 15 ++- test/testthread.c | 23 ++-- test/testtimer.c | 30 ++--- test/testver.c | 11 +- test/testwm2.c | 9 +- test/torturethread.c | 15 ++- 47 files changed, 616 insertions(+), 505 deletions(-) diff --git a/VisualC/tests/loopwave/loopwave_VS2010.vcxproj b/VisualC/tests/loopwave/loopwave_VS2010.vcxproj index 4ef300ad0c271..1fd5189822072 100644 --- a/VisualC/tests/loopwave/loopwave_VS2010.vcxproj +++ b/VisualC/tests/loopwave/loopwave_VS2010.vcxproj @@ -1,4 +1,4 @@ - + @@ -105,7 +105,8 @@ Windows - copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll" + copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll" +copy "$(SolutionDir)\..\test\sample.wav" "$(TargetDir)\sample.wav" Copy SDL @@ -139,7 +140,8 @@ Windows - copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll" + copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll" +copy "$(SolutionDir)\..\test\sample.wav" "$(TargetDir)\sample.wav" Copy SDL @@ -174,7 +176,8 @@ Windows - copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll" + copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll" +copy "$(SolutionDir)\..\test\sample.wav" "$(TargetDir)\sample.wav" Copy SDL @@ -208,7 +211,8 @@ Windows - copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll" + copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll" +copy "$(SolutionDir)\..\test\sample.wav" "$(TargetDir)\sample.wav" Copy SDL diff --git a/VisualC/tests/loopwave/loopwave_VS2012.vcxproj b/VisualC/tests/loopwave/loopwave_VS2012.vcxproj index 0a648593eb066..ea983c5d83b72 100644 --- a/VisualC/tests/loopwave/loopwave_VS2012.vcxproj +++ b/VisualC/tests/loopwave/loopwave_VS2012.vcxproj @@ -109,7 +109,8 @@ Windows - copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll" + copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll" +copy "$(SolutionDir)\..\test\sample.wav" "$(TargetDir)\sample.wav" Copy SDL @@ -143,7 +144,8 @@ Windows - copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll" + copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll" +copy "$(SolutionDir)\..\test\sample.wav" "$(TargetDir)\sample.wav" Copy SDL @@ -178,7 +180,8 @@ Windows - copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll" + copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll" +copy "$(SolutionDir)\..\test\sample.wav" "$(TargetDir)\sample.wav" Copy SDL @@ -212,7 +215,8 @@ Windows - copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll" + copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll" +copy "$(SolutionDir)\..\test\sample.wav" "$(TargetDir)\sample.wav" Copy SDL diff --git a/test/checkkeys.c b/test/checkkeys.c index 61e8be04350f6..5f2d1484764ca 100644 --- a/test/checkkeys.c +++ b/test/checkkeys.c @@ -117,13 +117,13 @@ PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat) static void PrintText(char *text) { - unsigned char *spot, expanded[1024]; + char *spot, expanded[1024]; expanded[0] = '\0'; for ( spot = text; *spot; ++spot ) { size_t length = SDL_strlen(expanded); - SDL_snprintf(expanded + length, sizeof(expanded) - length, "\\x%.2x", *spot); + SDL_snprintf(expanded + length, sizeof(expanded) - length, "\\x%.2x", (unsigned char)*spot); } SDL_Log("Text (%s): \"%s%s\"\n", expanded, *text == '"' ? "\\" : "", text); } @@ -134,10 +134,13 @@ main(int argc, char *argv[]) SDL_Window *window; SDL_Event event; int done; + + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); /* Initialize SDL */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return (1); } @@ -146,7 +149,7 @@ main(int argc, char *argv[]) SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, 0); if (!window) { - fprintf(stderr, "Couldn't create 640x480 window: %s\n", + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create 640x480 window: %s\n", SDL_GetError()); quit(2); } @@ -166,7 +169,7 @@ main(int argc, char *argv[]) switch (event.type) { case SDL_KEYDOWN: case SDL_KEYUP: - PrintKey(&event.key.keysym, event.key.state, event.key.repeat); + PrintKey(&event.key.keysym, (event.key.state == SDL_PRESSED) ? SDL_TRUE : SDL_FALSE, (event.key.repeat) ? SDL_TRUE : SDL_FALSE); break; case SDL_TEXTINPUT: PrintText(event.text.text); diff --git a/test/loopwave.c b/test/loopwave.c index 22b0559de7d6b..34d07c2b21ce5 100644 --- a/test/loopwave.c +++ b/test/loopwave.c @@ -80,9 +80,12 @@ main(int argc, char *argv[]) { int i; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + /* Load the SDL library */ if (SDL_Init(SDL_INIT_AUDIO) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return (1); } @@ -91,7 +94,7 @@ main(int argc, char *argv[]) } /* Load the wave file into memory */ if (SDL_LoadWAV(argv[1], &wave.spec, &wave.sound, &wave.soundlen) == NULL) { - fprintf(stderr, "Couldn't load %s: %s\n", argv[1], SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", argv[1], SDL_GetError()); quit(1); } @@ -109,24 +112,19 @@ main(int argc, char *argv[]) #endif /* HAVE_SIGNAL_H */ /* Show the list of available drivers */ - printf("Available audio drivers: "); + SDL_Log("Available audio drivers:"); for (i = 0; i < SDL_GetNumAudioDrivers(); ++i) { - if (i == 0) { - printf("%s", SDL_GetAudioDriver(i)); - } else { - printf(", %s", SDL_GetAudioDriver(i)); - } + SDL_Log("%i: %s", i, SDL_GetAudioDriver(i)); } - printf("\n"); /* Initialize fillerup() variables */ if (SDL_OpenAudio(&wave.spec, NULL) < 0) { - fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open audio: %s\n", SDL_GetError()); SDL_FreeWAV(wave.sound); quit(2); } - printf("Using audio driver: %s\n", SDL_GetCurrentAudioDriver()); + SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver()); /* Let the audio run */ SDL_PauseAudio(0); diff --git a/test/testatomic.c b/test/testatomic.c index be60a611be226..b360616d2350f 100644 --- a/test/testatomic.c +++ b/test/testatomic.c @@ -45,39 +45,39 @@ void RunBasicTest() SDL_atomic_t v; SDL_bool tfret = SDL_FALSE; - printf("\nspin lock---------------------------------------\n\n"); + SDL_Log("\nspin lock---------------------------------------\n\n"); SDL_AtomicLock(&lock); - printf("AtomicLock lock=%d\n", lock); + SDL_Log("AtomicLock lock=%d\n", lock); SDL_AtomicUnlock(&lock); - printf("AtomicUnlock lock=%d\n", lock); + SDL_Log("AtomicUnlock lock=%d\n", lock); - printf("\natomic -----------------------------------------\n\n"); + SDL_Log("\natomic -----------------------------------------\n\n"); SDL_AtomicSet(&v, 0); - tfret = SDL_AtomicSet(&v, 10) == 0; - printf("AtomicSet(10) tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); - tfret = SDL_AtomicAdd(&v, 10) == 10; - printf("AtomicAdd(10) tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); + tfret = SDL_AtomicSet(&v, 10) == 0 ? SDL_TRUE : SDL_FALSE; + SDL_Log("AtomicSet(10) tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); + tfret = SDL_AtomicAdd(&v, 10) == 10 ? SDL_TRUE : SDL_FALSE; + SDL_Log("AtomicAdd(10) tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); SDL_AtomicSet(&v, 0); SDL_AtomicIncRef(&v); - tfret = (SDL_AtomicGet(&v) == 1); - printf("AtomicIncRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); + tfret = (SDL_AtomicGet(&v) == 1) ? SDL_TRUE : SDL_FALSE; + SDL_Log("AtomicIncRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); SDL_AtomicIncRef(&v); - tfret = (SDL_AtomicGet(&v) == 2); - printf("AtomicIncRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); - tfret = (SDL_AtomicDecRef(&v) == SDL_FALSE); - printf("AtomicDecRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); - tfret = (SDL_AtomicDecRef(&v) == SDL_TRUE); - printf("AtomicDecRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); + tfret = (SDL_AtomicGet(&v) == 2) ? SDL_TRUE : SDL_FALSE; + SDL_Log("AtomicIncRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); + tfret = (SDL_AtomicDecRef(&v) == SDL_FALSE) ? SDL_TRUE : SDL_FALSE; + SDL_Log("AtomicDecRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); + tfret = (SDL_AtomicDecRef(&v) == SDL_TRUE) ? SDL_TRUE : SDL_FALSE; + SDL_Log("AtomicDecRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); SDL_AtomicSet(&v, 10); - tfret = (SDL_AtomicCAS(&v, 0, 20) == SDL_FALSE); - printf("AtomicCAS() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); + tfret = (SDL_AtomicCAS(&v, 0, 20) == SDL_FALSE) ? SDL_TRUE : SDL_FALSE; + SDL_Log("AtomicCAS() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); value = SDL_AtomicGet(&v); - tfret = (SDL_AtomicCAS(&v, value, 20) == SDL_TRUE); - printf("AtomicCAS() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); + tfret = (SDL_AtomicCAS(&v, value, 20) == SDL_TRUE) ? SDL_TRUE : SDL_FALSE; + SDL_Log("AtomicCAS() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); } /**************************************************************************/ @@ -120,7 +120,7 @@ static int adder(void* junk) { unsigned long N=NInter; - printf("Thread subtracting %d %lu times\n",CountInc,N); + SDL_Log("Thread subtracting %d %lu times\n",CountInc,N); while (N--) { SDL_AtomicAdd(&good, -CountInc); bad-=CountInc; @@ -152,7 +152,7 @@ void runAdder(void) end = SDL_GetTicks(); - printf("Finished in %f sec\n", (end - start) / 1000.f); + SDL_Log("Finished in %f sec\n", (end - start) / 1000.f); } static @@ -161,28 +161,28 @@ void RunEpicTest() int b; atomicValue v; - printf("\nepic test---------------------------------------\n\n"); + SDL_Log("\nepic test---------------------------------------\n\n"); - printf("Size asserted to be >= 32-bit\n"); + SDL_Log("Size asserted to be >= 32-bit\n"); SDL_assert(sizeof(atomicValue)>=4); - printf("Check static initializer\n"); + SDL_Log("Check static initializer\n"); v=SDL_AtomicGet(&good); SDL_assert(v==42); SDL_assert(bad==42); - printf("Test negative values\n"); + SDL_Log("Test negative values\n"); SDL_AtomicSet(&good, -5); v=SDL_AtomicGet(&good); SDL_assert(v==-5); - printf("Verify maximum value\n"); + SDL_Log("Verify maximum value\n"); SDL_AtomicSet(&good, CountTo); v=SDL_AtomicGet(&good); SDL_assert(v==CountTo); - printf("Test compare and exchange\n"); + SDL_Log("Test compare and exchange\n"); b=SDL_AtomicCAS(&good, 500, 43); SDL_assert(!b); /* no swap since CountTo!=500 */ @@ -194,7 +194,7 @@ void RunEpicTest() v=SDL_AtomicGet(&good); SDL_assert(v==44); - printf("Test Add\n"); + SDL_Log("Test Add\n"); v=SDL_AtomicAdd(&good, 1); SDL_assert(v==44); @@ -206,7 +206,7 @@ void RunEpicTest() v=SDL_AtomicGet(&good); SDL_assert(v==55); - printf("Test Add (Negative values)\n"); + SDL_Log("Test Add (Negative values)\n"); v=SDL_AtomicAdd(&good, -20); SDL_assert(v==55); @@ -223,7 +223,7 @@ void RunEpicTest() v=SDL_AtomicGet(&good); SDL_assert(v==15); - printf("Reset before count down test\n"); + SDL_Log("Reset before count down test\n"); SDL_AtomicSet(&good, CountTo); v=SDL_AtomicGet(&good); SDL_assert(v==CountTo); @@ -231,11 +231,11 @@ void RunEpicTest() bad=CountTo; SDL_assert(bad==CountTo); - printf("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); - printf("Atomic %d Non-Atomic %d\n",v,bad); + SDL_Log("Atomic %d Non-Atomic %d\n",v,bad); SDL_assert(v==Expect); SDL_assert(bad!=Expect); } @@ -429,7 +429,7 @@ static SDL_bool EnqueueEvent_Mutex(SDL_EventQueue *queue, const SDL_Event *event } else if (delta < 0) { /* We ran into an old queue entry, which means it still needs to be dequeued */ } else { - printf("ERROR: mutex failed!\n"); + SDL_Log("ERROR: mutex failed!\n"); } SDL_UnlockMutex(queue->mutex); @@ -462,7 +462,7 @@ static SDL_bool DequeueEvent_Mutex(SDL_EventQueue *queue, SDL_Event *event) } else if (delta < 0) { /* We ran into an old queue entry, which means we've hit empty */ } else { - printf("ERROR: mutex failed!\n"); + SDL_Log("ERROR: mutex failed!\n"); } SDL_UnlockMutex(queue->mutex); @@ -598,9 +598,11 @@ static void RunFIFOTest(SDL_bool lock_free) Uint32 start, end; int i, j; int grand_total; + char textBuffer[1024]; + int len; - printf("\nFIFO test---------------------------------------\n\n"); - printf("Mode: %s\n", lock_free ? "LockFree" : "Mutex"); + SDL_Log("\nFIFO test---------------------------------------\n\n"); + SDL_Log("Mode: %s\n", lock_free ? "LockFree" : "Mutex"); readersDone = SDL_CreateSemaphore(0); writersDone = SDL_CreateSemaphore(0); @@ -622,7 +624,7 @@ static void RunFIFOTest(SDL_bool lock_free) #endif /* Start the readers first */ - printf("Starting %d readers\n", NUM_READERS); + SDL_Log("Starting %d readers\n", NUM_READERS); SDL_zero(readerData); SDL_AtomicSet(&readersRunning, NUM_READERS); for (i = 0; i < NUM_READERS; ++i) { @@ -634,7 +636,7 @@ static void RunFIFOTest(SDL_bool lock_free) } /* Start up the writers */ - printf("Starting %d writers\n", NUM_WRITERS); + SDL_Log("Starting %d writers\n", NUM_WRITERS); SDL_zero(writerData); SDL_AtomicSet(&writersRunning, NUM_WRITERS); for (i = 0; i < NUM_WRITERS; ++i) { @@ -668,16 +670,16 @@ static void RunFIFOTest(SDL_bool lock_free) SDL_DestroyMutex(queue.mutex); } - printf("Finished in %f sec\n", (end - start) / 1000.f); + SDL_Log("Finished in %f sec\n", (end - start) / 1000.f); - printf("\n"); + SDL_Log("\n"); for (i = 0; i < NUM_WRITERS; ++i) { - printf("Writer %d wrote %d events, had %d waits\n", i, EVENTS_PER_WRITER, writerData[i].waits); + SDL_Log("Writer %d wrote %d events, had %d waits\n", i, EVENTS_PER_WRITER, writerData[i].waits); } - printf("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 */ - printf("\n"); + SDL_Log("\n"); grand_total = 0; for (i = 0; i < NUM_READERS; ++i) { int total = 0; @@ -685,17 +687,21 @@ static void RunFIFOTest(SDL_bool lock_free) total += readerData[i].counters[j]; } grand_total += total; - printf("Reader %d read %d events, had %d waits\n", i, total, readerData[i].waits); - printf(" { "); + SDL_Log("Reader %d read %d events, had %d waits\n", i, total, readerData[i].waits); + SDL_snprintf(textBuffer, sizeof(textBuffer), " { "); for (j = 0; j < NUM_WRITERS; ++j) { if (j > 0) { - printf(", "); + len = SDL_strlen(textBuffer); + SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, ", "); } - printf("%d", readerData[i].counters[j]); + len = SDL_strlen(textBuffer); + SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, "%d", readerData[i].counters[j]); } - printf(" }\n"); + len = SDL_strlen(textBuffer); + SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, " }\n"); + SDL_Log(textBuffer); } - printf("Readers read %d total events\n", grand_total); + SDL_Log("Readers read %d total events\n", grand_total); } /* End FIFO test */ @@ -704,6 +710,9 @@ static void RunFIFOTest(SDL_bool lock_free) int main(int argc, char *argv[]) { + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + RunBasicTest(); RunEpicTest(); /* This test is really slow, so don't run it by default */ diff --git a/test/testaudioinfo.c b/test/testaudioinfo.c index c1d7fa389ac2f..a65db5fa13856 100644 --- a/test/testaudioinfo.c +++ b/test/testaudioinfo.c @@ -18,18 +18,18 @@ print_devices(int iscapture) const char *typestr = ((iscapture) ? "capture" : "output"); int n = SDL_GetNumAudioDevices(iscapture); - printf("%s devices:\n", typestr); + SDL_Log("%s devices:\n", typestr); if (n == -1) - printf(" Driver can't detect specific %s devices.\n\n", typestr); + SDL_Log(" Driver can't detect specific %s devices.\n\n", typestr); else if (n == 0) - printf(" No %s devices found.\n\n", typestr); + SDL_Log(" No %s devices found.\n\n", typestr); else { int i; for (i = 0; i < n; i++) { - printf(" %s\n", SDL_GetAudioDeviceName(i, iscapture)); + SDL_Log(" %s\n", SDL_GetAudioDeviceName(i, iscapture)); } - printf("\n"); + SDL_Log("\n"); } } @@ -38,26 +38,29 @@ main(int argc, char **argv) { int n; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + /* Load the SDL library */ if (SDL_Init(SDL_INIT_AUDIO) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return (1); } /* Print available audio drivers */ n = SDL_GetNumAudioDrivers(); if (n == 0) { - printf("No built-in audio drivers\n\n"); + SDL_Log("No built-in audio drivers\n\n"); } else { int i; - printf("Built-in audio drivers:\n"); + SDL_Log("Built-in audio drivers:\n"); for (i = 0; i < n; ++i) { - printf(" %s\n", SDL_GetAudioDriver(i)); + SDL_Log(" %s\n", SDL_GetAudioDriver(i)); } - printf("\n"); + SDL_Log("\n"); } - printf("Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver()); + SDL_Log("Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver()); print_devices(0); print_devices(1); diff --git a/test/testautomation.c b/test/testautomation.c index 5eea7ec6f4bcc..6610d8a4f6ca9 100644 --- a/test/testautomation.c +++ b/test/testautomation.c @@ -80,8 +80,7 @@ main(int argc, char *argv[]) } } if (consumed < 0) { - fprintf(stderr, - "Usage: %s %s [--iterations #] [--execKey #] [--seed string] [--filter suite_name|test_name]\n", + SDL_Log("Usage: %s %s [--iterations #] [--execKey #] [--seed string] [--filter suite_name|test_name]\n", argv[0], SDLTest_CommonUsage(state)); quit(1); } diff --git a/test/testautomation_surface.c b/test/testautomation_surface.c index 3f6c56c9aff0b..863a5bd6e1a0f 100644 --- a/test/testautomation_surface.c +++ b/test/testautomation_surface.c @@ -360,8 +360,6 @@ surface_testCompleteSurfaceConversion(void *arg) for ( i = 0; i < SDL_arraysize(pixel_formats); ++i ) { for ( j = 0; j < SDL_arraysize(pixel_formats); ++j ) { - /*printf("Converting %s -> %s\n", SDL_GetPixelFormatName(pixel_formats[i]), SDL_GetPixelFormatName(pixel_formats[j]));*/ - fmt1 = SDL_AllocFormat(pixel_formats[i]); SDL_assert(fmt1 != NULL); cvt1 = SDL_ConvertSurface(face, fmt1, 0); diff --git a/test/testdraw2.c b/test/testdraw2.c index a4509fe749037..926294bfec876 100644 --- a/test/testdraw2.c +++ b/test/testdraw2.c @@ -176,6 +176,9 @@ main(int argc, char *argv[]) SDL_Event event; Uint32 then, now, frames; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + /* Initialize parameters */ num_objects = NUM_OBJECTS; @@ -218,8 +221,7 @@ main(int argc, char *argv[]) } } if (consumed < 0) { - fprintf(stderr, - "Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha]\n", + SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha]\n", argv[0], SDLTest_CommonUsage(state)); return 1; } @@ -268,7 +270,7 @@ main(int argc, char *argv[]) now = SDL_GetTicks(); if (now > then) { double fps = ((double) frames * 1000) / (now - then); - printf("%2.2f frames per second\n", fps); + SDL_Log("%2.2f frames per second\n", fps); } return 0; } diff --git a/test/testdrawchessboard.c b/test/testdrawchessboard.c index 002d8d717f29c..567d3fb85d268 100644 --- a/test/testdrawchessboard.c +++ b/test/testdrawchessboard.c @@ -54,10 +54,13 @@ main(int argc, char *argv[]) SDL_Surface *surface; SDL_Renderer *renderer; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + /* Initialize SDL */ if(SDL_Init(SDL_INIT_VIDEO) != 0) { - fprintf(stderr,"SDL_Init fail : %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init fail : %s\n", SDL_GetError()); return 1; } @@ -66,14 +69,14 @@ main(int argc, char *argv[]) window = SDL_CreateWindow("Chess Board", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN); if(!window) { - fprintf(stderr,"Window creation fail : %s\n",SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n",SDL_GetError()); return 1; } surface = SDL_GetWindowSurface(window); renderer = SDL_CreateSoftwareRenderer(surface); if(!renderer) { - fprintf(stderr,"Render creation for surface fail : %s\n",SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n",SDL_GetError()); return 1; } diff --git a/test/testerror.c b/test/testerror.c index e7356c06b19b8..e9c76ff1f603d 100644 --- a/test/testerror.c +++ b/test/testerror.c @@ -36,10 +36,10 @@ ThreadFunc(void *data) SDL_SetError("Thread %s (%lu) had a problem: %s", (char *) data, SDL_ThreadID(), "nevermind"); while (alive) { - printf("Thread '%s' is alive!\n", (char *) data); + SDL_Log("Thread '%s' is alive!\n", (char *) data); SDL_Delay(1 * 1000); } - printf("Child thread error string: %s\n", SDL_GetError()); + SDL_Log("Child thread error string: %s\n", SDL_GetError()); return (0); } @@ -48,9 +48,12 @@ main(int argc, char *argv[]) { SDL_Thread *thread; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + /* Load the SDL library */ if (SDL_Init(0) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return (1); } @@ -60,15 +63,15 @@ main(int argc, char *argv[]) alive = 1; thread = SDL_CreateThread(ThreadFunc, NULL, "#1"); if (thread == NULL) { - fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError()); quit(1); } SDL_Delay(5 * 1000); - printf("Waiting for thread #1\n"); + SDL_Log("Waiting for thread #1\n"); alive = 0; SDL_WaitThread(thread, NULL); - printf("Main thread error string: %s\n", SDL_GetError()); + SDL_Log("Main thread error string: %s\n", SDL_GetError()); SDL_Quit(); return (0); diff --git a/test/testfile.c b/test/testfile.c index d82d0eb7c49a5..efdc4155f1e2e 100644 --- a/test/testfile.c +++ b/test/testfile.c @@ -44,7 +44,6 @@ static void cleanup(void) { - unlink(FBASENAME1); unlink(FBASENAME2); } @@ -52,8 +51,7 @@ cleanup(void) static void rwops_error_quit(unsigned line, SDL_RWops * rwops) { - - printf("testfile.c(%d): failed\n", line); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "testfile.c(%d): failed\n", line); if (rwops) { rwops->close(rwops); /* This calls SDL_FreeRW(rwops); */ } @@ -71,6 +69,9 @@ main(int argc, char *argv[]) SDL_RWops *rwops = NULL; char test_buf[30]; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + cleanup(); /* test 1 : basic argument test: all those calls to SDL_RWFromFile should fail */ @@ -90,7 +91,7 @@ main(int argc, char *argv[]) rwops = SDL_RWFromFile("something", NULL); if (rwops) RWOP_ERR_QUIT(rwops); - printf("test1 OK\n"); + SDL_Log("test1 OK\n"); /* test 2 : check that inexistent file is not successfully opened/created when required */ /* modes : r, r+ imply that file MUST exist @@ -123,7 +124,7 @@ main(int argc, char *argv[]) RWOP_ERR_QUIT(rwops); rwops->close(rwops); unlink(FBASENAME2); - printf("test2 OK\n"); + SDL_Log("test2 OK\n"); /* test 3 : creation, writing , reading, seeking, test : w mode, r mode, w+ mode @@ -201,7 +202,7 @@ main(int argc, char *argv[]) if (SDL_memcmp(test_buf, "12345678901234567890", 20)) RWOP_ERR_QUIT(rwops); rwops->close(rwops); - printf("test3 OK\n"); + SDL_Log("test3 OK\n"); /* test 4: same in r+ mode */ rwops = SDL_RWFromFile(FBASENAME1, "rb+"); /* write + read + file must exists, no truncation */ @@ -236,7 +237,7 @@ main(int argc, char *argv[]) if (SDL_memcmp(test_buf, "12345678901234567890", 20)) RWOP_ERR_QUIT(rwops); rwops->close(rwops); - printf("test4 OK\n"); + SDL_Log("test4 OK\n"); /* test5 : append mode */ rwops = SDL_RWFromFile(FBASENAME1, "ab+"); /* write + read + append */ @@ -277,7 +278,7 @@ main(int argc, char *argv[]) if (SDL_memcmp(test_buf, "123456789012345678901234567123", 30)) RWOP_ERR_QUIT(rwops); rwops->close(rwops); - printf("test5 OK\n"); + SDL_Log("test5 OK\n"); cleanup(); return 0; /* all ok */ } diff --git a/test/testgamecontroller.c b/test/testgamecontroller.c index cd18aa5cc71ed..419593dc4c46d 100644 --- a/test/testgamecontroller.c +++ b/test/testgamecontroller.c @@ -91,7 +91,7 @@ WatchGameController(SDL_GameController * gamecontroller) const char *name = SDL_GameControllerName(gamecontroller); const char *basetitle = "Game Controller Test: "; const size_t titlelen = SDL_strlen(basetitle) + SDL_strlen(name) + 1; - char *title = SDL_malloc(titlelen); + char *title = (char *)SDL_malloc(titlelen); SDL_Window *window = NULL; SDL_Renderer *screen = NULL; int done = 0; @@ -107,13 +107,13 @@ WatchGameController(SDL_GameController * gamecontroller) SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, 0); if (window == NULL) { - fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError()); return; } screen = SDL_CreateRenderer(window, -1, 0); if (screen == NULL) { - fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError()); SDL_DestroyWindow(window); return; } @@ -124,7 +124,7 @@ WatchGameController(SDL_GameController * gamecontroller) SDL_RaiseWindow(window); /* Print info about the controller we are watching */ - printf("Watching controller %s\n", name ? name : "Unknown Controller"); + SDL_Log("Watching controller %s\n", name ? name : "Unknown Controller"); /* Loop, getting controller events! */ while (!done) { @@ -135,21 +135,21 @@ WatchGameController(SDL_GameController * gamecontroller) while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_CONTROLLERAXISMOTION: - printf("Controller %d axis %d ('%s') value: %d\n", + SDL_Log("Controller %d axis %d ('%s') value: %d\n", event.caxis.which, event.caxis.axis, - ControllerAxisName(event.caxis.axis), + ControllerAxisName((SDL_GameControllerAxis)event.caxis.axis), event.caxis.value); break; case SDL_CONTROLLERBUTTONDOWN: - printf("Controller %d button %d ('%s') down\n", + SDL_Log("Controller %d button %d ('%s') down\n", event.cbutton.which, event.cbutton.button, - ControllerButtonName(event.cbutton.button)); + ControllerButtonName((SDL_GameControllerButton)event.cbutton.button)); break; case SDL_CONTROLLERBUTTONUP: - printf("Controller %d button %d ('%s') up\n", + SDL_Log("Controller %d button %d ('%s') up\n", event.cbutton.which, event.cbutton.button, - ControllerButtonName(event.cbutton.button)); + ControllerButtonName((SDL_GameControllerButton)event.cbutton.button)); break; case SDL_KEYDOWN: if (event.key.keysym.sym != SDLK_ESCAPE) { @@ -167,7 +167,7 @@ WatchGameController(SDL_GameController * gamecontroller) /* Update visual controller state */ SDL_SetRenderDrawColor(screen, 0x00, 0xFF, 0x00, SDL_ALPHA_OPAQUE); for (i = 0; i (SCREEN_WIDTH - 16)) { x = SCREEN_WIDTH - 16; } - y = (((int) SDL_GameControllerGetAxis(gamecontroller, i * 2 + 1)) + 32768); + y = (((int) SDL_GameControllerGetAxis(gamecontroller, (SDL_GameControllerAxis)(i * 2 + 1))) + 32768); y *= SCREEN_HEIGHT; y /= 65535; if (y < 0) { @@ -217,9 +217,12 @@ main(int argc, char *argv[]) char guid[64]; SDL_GameController *gamecontroller; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + /* Initialize SDL (Note: video is required to start event loop) */ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER ) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return 1; } @@ -238,22 +241,22 @@ main(int argc, char *argv[]) } else { name = SDL_JoystickNameForIndex(i); } - printf("%s %d: %s (guid %s)\n", description, i, name ? name : "Unknown", guid); + SDL_Log("%s %d: %s (guid %s)\n", description, i, name ? name : "Unknown", guid); } - printf("There are %d game controller(s) attached (%d joystick(s))\n", nController, SDL_NumJoysticks()); + SDL_Log("There are %d game controller(s) attached (%d joystick(s))\n", nController, SDL_NumJoysticks()); if (argv[1]) { int device = atoi(argv[1]); if (device >= SDL_NumJoysticks()) { - printf("%i is an invalid joystick index.\n", device); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%i is an invalid joystick index.\n", device); retcode = 1; } else { SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(device), guid, sizeof (guid)); - printf("Attempting to open device %i, guid %s\n", device, guid); + SDL_Log("Attempting to open device %i, guid %s\n", device, guid); gamecontroller = SDL_GameControllerOpen(device); if (gamecontroller == NULL) { - printf("Couldn't open joystick %d: %s\n", device, SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open joystick %d: %s\n", device, SDL_GetError()); retcode = 1; } else { WatchGameController(gamecontroller); @@ -272,7 +275,7 @@ main(int argc, char *argv[]) int main(int argc, char *argv[]) { - fprintf(stderr, "SDL compiled without Joystick support.\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Joystick support.\n"); exit(1); } diff --git a/test/testgesture.c b/test/testgesture.c index e2a9694ae7385..7d4fe78cce267 100644 --- a/test/testgesture.c +++ b/test/testgesture.c @@ -207,6 +207,9 @@ int main(int argc, char* argv[]) SDL_bool quitting = SDL_FALSE; SDL_RWops *src; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + //gesture variables knob.r = .1f; knob.ang = 0; diff --git a/test/testgl2.c b/test/testgl2.c index eb1a245e3e7cd..571a69d9a712d 100644 --- a/test/testgl2.c +++ b/test/testgl2.c @@ -181,6 +181,9 @@ main(int argc, char *argv[]) Uint32 then, now, frames; int status; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + /* Initialize parameters */ fsaa = 0; accel = -1; @@ -206,7 +209,7 @@ main(int argc, char *argv[]) } } if (consumed < 0) { - fprintf(stderr, "Usage: %s %s [--fsaa n] [--accel n]\n", argv[0], + SDL_Log("Usage: %s %s [--fsaa n] [--accel n]\n", argv[0], SDLTest_CommonUsage(state)); quit(1); } @@ -235,7 +238,7 @@ main(int argc, char *argv[]) /* Create OpenGL context */ context = SDL_GL_CreateContext(state->windows[0]); if (!context) { - fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GL_CreateContext(): %s\n", SDL_GetError()); quit(2); } @@ -249,63 +252,63 @@ main(int argc, char *argv[]) } SDL_GetCurrentDisplayMode(0, &mode); - printf("Screen BPP : %d\n", SDL_BITSPERPIXEL(mode.format)); - printf("Swap Interval : %d\n", SDL_GL_GetSwapInterval()); - printf("\n"); - printf("Vendor : %s\n", glGetString(GL_VENDOR)); - printf("Renderer : %s\n", glGetString(GL_RENDERER)); - printf("Version : %s\n", glGetString(GL_VERSION)); - printf("Extensions : %s\n", glGetString(GL_EXTENSIONS)); - printf("\n"); + SDL_Log("Screen BPP : %d\n", SDL_BITSPERPIXEL(mode.format)); + SDL_Log("Swap Interval : %d\n", SDL_GL_GetSwapInterval()); + SDL_Log("\n"); + SDL_Log("Vendor : %s\n", glGetString(GL_VENDOR)); + SDL_Log("Renderer : %s\n", glGetString(GL_RENDERER)); + SDL_Log("Version : %s\n", glGetString(GL_VERSION)); + SDL_Log("Extensions : %s\n", glGetString(GL_EXTENSIONS)); + SDL_Log("\n"); status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value); if (!status) { - printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value); + SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value); } else { - printf("Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError()); } status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value); if (!status) { - printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value); + SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value); } else { - printf("Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError()); } status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value); if (!status) { - printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value); + SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value); } else { - printf("Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError()); } status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value); if (!status) { - printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value); + SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value); } else { - printf("Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError()); } if (fsaa) { status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value); if (!status) { - printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); + SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); } else { - printf("Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", SDL_GetError()); } status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value); if (!status) { - printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, + SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value); } else { - printf("Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n", + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n", SDL_GetError()); } } if (accel >= 0) { status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value); if (!status) { - printf("SDL_GL_ACCELERATED_VISUAL: requested %d, got %d\n", accel, + SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested %d, got %d\n", accel, value); } else { - printf("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", SDL_GetError()); } } @@ -343,7 +346,7 @@ main(int argc, char *argv[]) /* Print out some timing information */ now = SDL_GetTicks(); if (now > then) { - printf("%2.2f frames per second\n", + SDL_Log("%2.2f frames per second\n", ((double) frames * 1000) / (now - then)); } quit(0); @@ -355,7 +358,7 @@ main(int argc, char *argv[]) int main(int argc, char *argv[]) { - printf("No OpenGL support on this system\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No OpenGL support on this system\n"); return 1; } diff --git a/test/testgles.c b/test/testgles.c index 41312a8bba2f3..7a790bd9d7e0a 100644 --- a/test/testgles.c +++ b/test/testgles.c @@ -110,6 +110,9 @@ main(int argc, char *argv[]) Uint32 then, now, frames; int status; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + /* Initialize parameters */ fsaa = 0; accel = 0; @@ -143,7 +146,7 @@ main(int argc, char *argv[]) } } if (consumed < 0) { - fprintf(stderr, "Usage: %s %s [--fsaa] [--accel] [--zdepth %%d]\n", argv[0], + SDL_Log("Usage: %s %s [--fsaa] [--accel] [--zdepth %%d]\n", argv[0], SDLTest_CommonUsage(state)); quit(1); } @@ -169,7 +172,7 @@ main(int argc, char *argv[]) context = SDL_calloc(state->num_windows, sizeof(context)); if (context == NULL) { - fprintf(stderr, "Out of memory!\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n"); quit(2); } @@ -177,7 +180,7 @@ main(int argc, char *argv[]) for (i = 0; i < state->num_windows; i++) { context[i] = SDL_GL_CreateContext(state->windows[i]); if (!context[i]) { - fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GL_CreateContext(): %s\n", SDL_GetError()); quit(2); } } @@ -189,65 +192,65 @@ main(int argc, char *argv[]) } SDL_GetCurrentDisplayMode(0, &mode); - printf("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format)); - printf("\n"); - printf("Vendor : %s\n", glGetString(GL_VENDOR)); - printf("Renderer : %s\n", glGetString(GL_RENDERER)); - printf("Version : %s\n", glGetString(GL_VERSION)); - printf("Extensions : %s\n", glGetString(GL_EXTENSIONS)); - printf("\n"); + SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format)); + SDL_Log("\n"); + SDL_Log("Vendor : %s\n", glGetString(GL_VENDOR)); + SDL_Log("Renderer : %s\n", glGetString(GL_RENDERER)); + SDL_Log("Version : %s\n", glGetString(GL_VERSION)); + SDL_Log("Extensions : %s\n", glGetString(GL_EXTENSIONS)); + SDL_Log("\n"); status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value); if (!status) { - printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value); + SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value); } else { - fprintf(stderr, "Failed to get SDL_GL_RED_SIZE: %s\n", + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError()); } status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value); if (!status) { - printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value); + SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value); } else { - fprintf(stderr, "Failed to get SDL_GL_GREEN_SIZE: %s\n", + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError()); } status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value); if (!status) { - printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value); + SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value); } else { - fprintf(stderr, "Failed to get SDL_GL_BLUE_SIZE: %s\n", + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError()); } status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value); if (!status) { - printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value); + SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value); } else { - fprintf(stderr, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError()); } if (fsaa) { status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value); if (!status) { - printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); + SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); } else { - fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", SDL_GetError()); } status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value); if (!status) { - printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, + SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value); } else { - fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n", + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n", SDL_GetError()); } } if (accel) { status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value); if (!status) { - printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value); + SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value); } else { - fprintf(stderr, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", SDL_GetError()); } } @@ -258,7 +261,7 @@ main(int argc, char *argv[]) status = SDL_GL_MakeCurrent(state->windows[i], context[i]); if (status) { - printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); + SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); /* Continue for next window */ continue; @@ -292,7 +295,7 @@ main(int argc, char *argv[]) if (event.window.windowID == SDL_GetWindowID(state->windows[i])) { status = SDL_GL_MakeCurrent(state->windows[i], context[i]); if (status) { - printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); + SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); break; } /* Change view port to the new window dimensions */ @@ -311,7 +314,7 @@ main(int argc, char *argv[]) for (i = 0; i < state->num_windows; ++i) { status = SDL_GL_MakeCurrent(state->windows[i], context[i]); if (status) { - printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); + SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); /* Continue for next window */ continue; @@ -324,7 +327,7 @@ main(int argc, char *argv[]) /* Print out some timing information */ now = SDL_GetTicks(); if (now > then) { - printf("%2.2f frames per second\n", + SDL_Log("%2.2f frames per second\n", ((double) frames * 1000) / (now - then)); } quit(0); @@ -336,7 +339,7 @@ main(int argc, char *argv[]) int main(int argc, char *argv[]) { - printf("No OpenGL ES support on this system\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No OpenGL ES support on this system\n"); return 1; } diff --git a/test/testhaptic.c b/test/testhaptic.c index 13dd19d671913..c28d0df34a05c 100644 --- a/test/testhaptic.c +++ b/test/testhaptic.c @@ -26,7 +26,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * includes */ #include -#include /* printf */ #include /* strstr */ #include /* isdigit */ @@ -62,12 +61,15 @@ main(int argc, char **argv) int nefx; unsigned int supported; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + name = NULL; index = -1; if (argc > 1) { name = argv[1]; if ((strcmp(name, "--help") == 0) || (strcmp(name, "-h") == 0)) { - printf("USAGE: %s [device]\n" + SDL_Log("USAGE: %s [device]\n" "If device is a two-digit number it'll use it as an index, otherwise\n" "it'll use it as if it were part of the device's name.\n", argv[0]); @@ -84,7 +86,7 @@ main(int argc, char **argv) /* Initialize the force feedbackness */ SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC); - printf("%d Haptic devices detected.\n", SDL_NumHaptics()); + SDL_Log("%d Haptic devices detected.\n", SDL_NumHaptics()); if (SDL_NumHaptics() > 0) { /* We'll just use index or the first force feedback device found */ if (name == NULL) { @@ -98,7 +100,7 @@ main(int argc, char **argv) } if (i >= SDL_NumHaptics()) { - printf("Unable to find device matching '%s', aborting.\n", + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n", name); return 1; } @@ -106,14 +108,14 @@ main(int argc, char **argv) haptic = SDL_HapticOpen(i); if (haptic == NULL) { - printf("Unable to create the haptic device: %s\n", + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n", SDL_GetError()); return 1; } - printf("Device: %s\n", SDL_HapticName(i)); + SDL_Log("Device: %s\n", SDL_HapticName(i)); HapticPrintSupported(haptic); } else { - printf("No Haptic devices found!\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n"); return 1; } @@ -125,10 +127,10 @@ main(int argc, char **argv) nefx = 0; supported = SDL_HapticQuery(haptic); - printf("\nUploading effects\n"); + SDL_Log("\nUploading effects\n"); /* First we'll try a SINE effect. */ if (supported & SDL_HAPTIC_SINE) { - printf(" effect %d: Sine Wave\n", nefx); + SDL_Log(" effect %d: Sine Wave\n", nefx); efx[nefx].type = SDL_HAPTIC_SINE; efx[nefx].periodic.period = 1000; efx[nefx].periodic.magnitude = 0x4000; @@ -137,14 +139,14 @@ main(int argc, char **argv) efx[nefx].periodic.fade_length = 1000; id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]); if (id[nefx] < 0) { - printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError()); abort_execution(); } nefx++; } /* Now we'll try a SAWTOOTHUP */ if (supported & SDL_HAPTIC_SAWTOOTHUP) { - printf(" effect %d: Sawtooth Up\n", nefx); + SDL_Log(" effect %d: Sawtooth Up\n", nefx); efx[nefx].type = SDL_HAPTIC_SAWTOOTHUP; efx[nefx].periodic.period = 500; efx[nefx].periodic.magnitude = 0x5000; @@ -153,14 +155,14 @@ main(int argc, char **argv) efx[nefx].periodic.fade_length = 1000; id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]); if (id[nefx] < 0) { - printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError()); abort_execution(); } nefx++; } /* Now the classical constant effect. */ if (supported & SDL_HAPTIC_CONSTANT) { - printf(" effect %d: Constant Force\n", nefx); + SDL_Log(" effect %d: Constant Force\n", nefx); efx[nefx].type = SDL_HAPTIC_CONSTANT; efx[nefx].constant.direction.type = SDL_HAPTIC_POLAR; efx[nefx].constant.direction.dir[0] = 20000; /* Force comes from the south-west. */ @@ -170,14 +172,14 @@ main(int argc, char **argv) efx[nefx].constant.fade_length = 1000; id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]); if (id[nefx] < 0) { - printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError()); abort_execution(); } nefx++; } /* The cute spring effect. */ if (supported & SDL_HAPTIC_SPRING) { - printf(" effect %d: Condition Spring\n", nefx); + SDL_Log(" effect %d: Condition Spring\n", nefx); efx[nefx].type = SDL_HAPTIC_SPRING; efx[nefx].condition.length = 5000; for (i = 0; i < SDL_HapticNumAxes(haptic); i++) { @@ -189,14 +191,14 @@ main(int argc, char **argv) } id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]); if (id[nefx] < 0) { - printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError()); abort_execution(); } nefx++; } /* The pretty awesome inertia effect. */ if (supported & SDL_HAPTIC_INERTIA) { - printf(" effect %d: Condition Inertia\n", nefx); + SDL_Log(" effect %d: Condition Inertia\n", nefx); efx[nefx].type = SDL_HAPTIC_SPRING; efx[nefx].condition.length = 5000; for (i = 0; i < SDL_HapticNumAxes(haptic); i++) { @@ -207,7 +209,7 @@ main(int argc, char **argv) } id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]); if (id[nefx] < 0) { - printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError()); abort_execution(); } nefx++; @@ -215,24 +217,24 @@ main(int argc, char **argv) /* Finally we'll try a left/right effect. */ if (supported & SDL_HAPTIC_LEFTRIGHT) { - printf(" effect %d: Left/Right\n", nefx); + SDL_Log(" effect %d: Left/Right\n", nefx); efx[nefx].type = SDL_HAPTIC_LEFTRIGHT; efx[nefx].leftright.length = 5000; efx[nefx].leftright.large_magnitude = 0x3000; efx[nefx].leftright.small_magnitude = 0xFFFF; id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]); if (id[nefx] < 0) { - printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError()); abort_execution(); } nefx++; } - printf + SDL_Log ("\nNow playing effects for 5 seconds each with 1 second delay between\n"); for (i = 0; i < nefx; i++) { - printf(" Playing effect %d\n", i); + SDL_Log(" Playing effect %d\n", i); SDL_HapticRunEffect(haptic, id[i], 1); SDL_Delay(6000); /* Effects only have length 5000 */ } @@ -252,7 +254,7 @@ main(int argc, char **argv) static void abort_execution(void) { - printf("\nAborting program execution.\n"); + SDL_Log("\nAborting program execution.\n"); SDL_HapticClose(haptic); SDL_Quit(); @@ -270,42 +272,42 @@ HapticPrintSupported(SDL_Haptic * haptic) unsigned int supported; supported = SDL_HapticQuery(haptic); - printf(" Supported effects [%d effects, %d playing]:\n", + SDL_Log(" Supported effects [%d effects, %d playing]:\n", SDL_HapticNumEffects(haptic), SDL_HapticNumEffectsPlaying(haptic)); if (supported & SDL_HAPTIC_CONSTANT) - printf(" constant\n"); + SDL_Log(" constant\n"); if (supported & SDL_HAPTIC_SINE) - printf(" sine\n"); + SDL_Log(" sine\n"); /* !!! FIXME: put this back when we have more bits in 2.1 */ /*if (supported & SDL_HAPTIC_SQUARE) - printf(" square\n");*/ + SDL_Log(" square\n");*/ if (supported & SDL_HAPTIC_TRIANGLE) - printf(" triangle\n"); + SDL_Log(" triangle\n"); if (supported & SDL_HAPTIC_SAWTOOTHUP) - printf(" sawtoothup\n"); + SDL_Log(" sawtoothup\n"); if (supported & SDL_HAPTIC_SAWTOOTHDOWN) - printf(" sawtoothdown\n"); + SDL_Log(" sawtoothdown\n"); if (supported & SDL_HAPTIC_RAMP) - printf(" ramp\n"); + SDL_Log(" ramp\n"); if (supported & SDL_HAPTIC_FRICTION) - printf(" friction\n"); + SDL_Log(" friction\n"); if (supported & SDL_HAPTIC_SPRING) - printf(" spring\n"); + SDL_Log(" spring\n"); if (supported & SDL_HAPTIC_DAMPER) - printf(" damper\n"); + SDL_Log(" damper\n"); if (supported & SDL_HAPTIC_INERTIA) - printf(" intertia\n"); + SDL_Log(" inertia\n"); if (supported & SDL_HAPTIC_CUSTOM) - printf(" custom\n"); + SDL_Log(" custom\n"); if (supported & SDL_HAPTIC_LEFTRIGHT) - printf(" left/right\n"); - printf(" Supported capabilities:\n"); + SDL_Log(" left/right\n"); + SDL_Log(" Supported capabilities:\n"); if (supported & SDL_HAPTIC_GAIN) - printf(" gain\n"); + SDL_Log(" gain\n"); if (supported & SDL_HAPTIC_AUTOCENTER) - printf(" autocenter\n"); + SDL_Log(" autocenter\n"); if (supported & SDL_HAPTIC_STATUS) - printf(" status\n"); + SDL_Log(" status\n"); } #else @@ -313,7 +315,7 @@ HapticPrintSupported(SDL_Haptic * haptic) int main(int argc, char *argv[]) { - fprintf(stderr, "SDL compiled without Haptic support.\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Haptic support.\n"); exit(1); } diff --git a/test/testiconv.c b/test/testiconv.c index d2081995d59a1..435e2392fdd83 100644 --- a/test/testiconv.c +++ b/test/testiconv.c @@ -49,12 +49,15 @@ main(int argc, char *argv[]) FILE *file; int errors = 0; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + if (!argv[1]) { argv[1] = "utf8.txt"; } file = fopen(argv[1], "rb"); if (!file) { - fprintf(stderr, "Unable to open %s\n", argv[1]); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to open %s\n", argv[1]); return (1); } @@ -69,7 +72,7 @@ main(int argc, char *argv[]) test[0] = SDL_iconv_string(formats[i], "UCS-4", ucs4, len); test[1] = SDL_iconv_string("UCS-4", formats[i], test[0], len); if (!test[1] || SDL_memcmp(test[1], ucs4, len) != 0) { - fprintf(stderr, "FAIL: %s\n", formats[i]); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "FAIL: %s\n", formats[i]); ++errors; } if (test[0]) { diff --git a/test/testime.c b/test/testime.c index ce9f02b1f5ad9..44f1b19033205 100644 --- a/test/testime.c +++ b/test/testime.c @@ -80,7 +80,7 @@ char *utf8_advance(char *p, size_t distance) void usage() { - printf("usage: testime [--font fontfile]\n"); + SDL_Log("usage: testime [--font fontfile]\n"); exit(0); } @@ -210,6 +210,9 @@ int main(int argc, char *argv[]) { SDL_Event event; const char *fontname = DEFAULT_FONT; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); if (!state) { @@ -251,12 +254,12 @@ int main(int argc, char *argv[]) { font = TTF_OpenFont(fontname, DEFAULT_PTSIZE); if (! font) { - fprintf(stderr, "Failed to find font: %s\n", TTF_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to find font: %s\n", TTF_GetError()); exit(-1); } #endif - printf("Using font: %s\n", fontname); + SDL_Log("Using font: %s\n", fontname); atexit(SDL_Quit); InitInput(); @@ -321,8 +324,7 @@ int main(int argc, char *argv[]) { break; } - fprintf(stderr, - "Keyboard: scancode 0x%08X = %s, keycode 0x%08X = %s\n", + SDL_Log("Keyboard: scancode 0x%08X = %s, keycode 0x%08X = %s\n", event.key.keysym.scancode, SDL_GetScancodeName(event.key.keysym.scancode), event.key.keysym.sym, SDL_GetKeyName(event.key.keysym.sym)); @@ -333,12 +335,12 @@ int main(int argc, char *argv[]) { markedRect.w < 0) break; - fprintf(stderr, "Keyboard: text input \"%s\"\n", event.text.text); + SDL_Log("Keyboard: text input \"%s\"\n", event.text.text); if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text)) SDL_strlcat(text, event.text.text, sizeof(text)); - fprintf(stderr, "text inputed: %s\n", text); + SDL_Log("text inputed: %s\n", text); // After text inputed, we can clear up markedText because it // is committed @@ -347,7 +349,7 @@ int main(int argc, char *argv[]) { break; case SDL_TEXTEDITING: - fprintf(stderr, "text editing \"%s\", selected range (%d, %d)\n", + SDL_Log("text editing \"%s\", selected range (%d, %d)\n", event.edit.text, event.edit.start, event.edit.length); strcpy(markedText, event.edit.text); diff --git a/test/testintersections.c b/test/testintersections.c index d858717e589a8..237bd3511ec9b 100644 --- a/test/testintersections.c +++ b/test/testintersections.c @@ -84,7 +84,7 @@ add_line(int x1, int y1, int x2, int y2) if ((x1 == x2) && (y1 == y2)) return 0; - printf("adding line (%d, %d), (%d, %d)\n", x1, y1, x2, y2); + SDL_Log("adding line (%d, %d), (%d, %d)\n", x1, y1, x2, y2); lines[num_lines].x = x1; lines[num_lines].y = y1; lines[num_lines].w = x2; @@ -133,7 +133,7 @@ add_rect(int x1, int y1, int x2, int y2) if (y1 > y2) SWAP(int, y1, y2); - printf("adding rect (%d, %d), (%d, %d) [%dx%d]\n", x1, y1, x2, y2, + SDL_Log("adding rect (%d, %d), (%d, %d) [%dx%d]\n", x1, y1, x2, y2, x2 - x1, y2 - y1); rects[num_rects].x = x1; @@ -199,6 +199,9 @@ main(int argc, char *argv[]) SDL_Event event; Uint32 then, now, frames; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + /* Initialize parameters */ num_objects = NUM_OBJECTS; @@ -241,8 +244,7 @@ main(int argc, char *argv[]) } } if (consumed < 0) { - fprintf(stderr, - "Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha]\n", + SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha]\n", argv[0], SDLTest_CommonUsage(state)); return 1; } @@ -327,7 +329,7 @@ main(int argc, char *argv[]) now = SDL_GetTicks(); if (now > then) { double fps = ((double) frames * 1000) / (now - then); - printf("%2.2f frames per second\n", fps); + SDL_Log("%2.2f frames per second\n", fps); } return 0; } diff --git a/test/testjoystick.c b/test/testjoystick.c index da307ed297e40..7d3c573df9ae7 100644 --- a/test/testjoystick.c +++ b/test/testjoystick.c @@ -52,13 +52,13 @@ WatchJoystick(SDL_Joystick * joystick) SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, 0); if (window == NULL) { - fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError()); return SDL_FALSE; } screen = SDL_CreateRenderer(window, -1, 0); if (screen == NULL) { - fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError()); SDL_DestroyWindow(window); return SDL_FALSE; } @@ -70,9 +70,9 @@ WatchJoystick(SDL_Joystick * joystick) /* Print info about the joystick we are watching */ name = SDL_JoystickName(joystick); - printf("Watching joystick %d: (%s)\n", SDL_JoystickInstanceID(joystick), + SDL_Log("Watching joystick %d: (%s)\n", SDL_JoystickInstanceID(joystick), name ? name : "Unknown Joystick"); - printf("Joystick has %d axes, %d hats, %d balls, and %d buttons\n", + SDL_Log("Joystick has %d axes, %d hats, %d balls, and %d buttons\n", SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick), SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick)); @@ -85,36 +85,36 @@ WatchJoystick(SDL_Joystick * joystick) while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_JOYAXISMOTION: - printf("Joystick %d axis %d value: %d\n", + SDL_Log("Joystick %d axis %d value: %d\n", event.jaxis.which, event.jaxis.axis, event.jaxis.value); break; case SDL_JOYHATMOTION: - printf("Joystick %d hat %d value:", + SDL_Log("Joystick %d hat %d value:", event.jhat.which, event.jhat.hat); if (event.jhat.value == SDL_HAT_CENTERED) - printf(" centered"); + SDL_Log(" centered"); if (event.jhat.value & SDL_HAT_UP) - printf(" up"); + SDL_Log(" up"); if (event.jhat.value & SDL_HAT_RIGHT) - printf(" right"); + SDL_Log(" right"); if (event.jhat.value & SDL_HAT_DOWN) - printf(" down"); + SDL_Log(" down"); if (event.jhat.value & SDL_HAT_LEFT) - printf(" left"); - printf("\n"); + SDL_Log(" left"); + SDL_Log("\n"); break; case SDL_JOYBALLMOTION: - printf("Joystick %d ball %d delta: (%d,%d)\n", + SDL_Log("Joystick %d ball %d delta: (%d,%d)\n", event.jball.which, event.jball.ball, event.jball.xrel, event.jball.yrel); break; case SDL_JOYBUTTONDOWN: - printf("Joystick %d button %d down\n", + SDL_Log("Joystick %d button %d down\n", event.jbutton.which, event.jbutton.button); break; case SDL_JOYBUTTONUP: - printf("Joystick %d button %d up\n", + SDL_Log("Joystick %d button %d up\n", event.jbutton.which, event.jbutton.button); break; case SDL_KEYDOWN: @@ -211,31 +211,34 @@ main(int argc, char *argv[]) int i; SDL_Joystick *joystick; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + /* Initialize SDL (Note: video is required to start event loop) */ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); exit(1); } /* Print information about the joysticks */ - printf("There are %d joysticks attached\n", SDL_NumJoysticks()); + SDL_Log("There are %d joysticks attached\n", SDL_NumJoysticks()); for (i = 0; i < SDL_NumJoysticks(); ++i) { name = SDL_JoystickNameForIndex(i); - printf("Joystick %d: %s\n", i, name ? name : "Unknown Joystick"); + SDL_Log("Joystick %d: %s\n", i, name ? name : "Unknown Joystick"); joystick = SDL_JoystickOpen(i); if (joystick == NULL) { - fprintf(stderr, "SDL_JoystickOpen(%d) failed: %s\n", i, + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_JoystickOpen(%d) failed: %s\n", i, SDL_GetError()); } else { char guid[64]; SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), guid, sizeof (guid)); - printf(" axes: %d\n", SDL_JoystickNumAxes(joystick)); - printf(" balls: %d\n", SDL_JoystickNumBalls(joystick)); - printf(" hats: %d\n", SDL_JoystickNumHats(joystick)); - printf(" buttons: %d\n", SDL_JoystickNumButtons(joystick)); - printf("instance id: %d\n", SDL_JoystickInstanceID(joystick)); - printf(" guid: %s\n", guid); + SDL_Log(" axes: %d\n", SDL_JoystickNumAxes(joystick)); + SDL_Log(" balls: %d\n", SDL_JoystickNumBalls(joystick)); + SDL_Log(" hats: %d\n", SDL_JoystickNumHats(joystick)); + SDL_Log(" buttons: %d\n", SDL_JoystickNumButtons(joystick)); + SDL_Log("instance id: %d\n", SDL_JoystickInstanceID(joystick)); + SDL_Log(" guid: %s\n", guid); SDL_JoystickClose(joystick); } } @@ -256,7 +259,7 @@ main(int argc, char *argv[]) while ( keepGoing ) { if (joystick == NULL) { if ( !reportederror ) { - printf("Couldn't open joystick %d: %s\n", atoi(argv[1]), SDL_GetError()); + SDL_Log("Couldn't open joystick %d: %s\n", atoi(argv[1]), SDL_GetError()); keepGoing = SDL_FALSE; reportederror = SDL_TRUE; } @@ -268,7 +271,7 @@ main(int argc, char *argv[]) joystick = NULL; if (keepGoing) { - printf("Waiting for attach\n"); + SDL_Log("Waiting for attach\n"); } while (keepGoing) { SDL_WaitEvent(&event); @@ -296,7 +299,7 @@ main(int argc, char *argv[]) int main(int argc, char *argv[]) { - fprintf(stderr, "SDL compiled without Joystick support.\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Joystick support.\n"); exit(1); } diff --git a/test/testkeys.c b/test/testkeys.c index 71f8956024e6f..f4a35aba69548 100644 --- a/test/testkeys.c +++ b/test/testkeys.c @@ -24,12 +24,15 @@ main(int argc, char *argv[]) { SDL_Scancode scancode; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + if (SDL_Init(SDL_INIT_VIDEO) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); exit(1); } for (scancode = 0; scancode < SDL_NUM_SCANCODES; ++scancode) { - printf("Scancode #%d, \"%s\"\n", scancode, + SDL_Log("Scancode #%d, \"%s\"\n", scancode, SDL_GetScancodeName(scancode)); } SDL_Quit(); diff --git a/test/testloadso.c b/test/testloadso.c index 4bf7bf65439ac..946aafd20c256 100644 --- a/test/testloadso.c +++ b/test/testloadso.c @@ -33,14 +33,14 @@ main(int argc, char *argv[]) if (argc != 3) { const char *app = argv[0]; - fprintf(stderr, "USAGE: %s \n", app); - fprintf(stderr, " %s --hello \n", app); + SDL_Log("USAGE: %s \n", app); + SDL_Log(" %s --hello \n", app); return 1; } /* Initialize SDL */ if (SDL_Init(0) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return 2; } @@ -55,23 +55,23 @@ main(int argc, char *argv[]) lib = SDL_LoadObject(libname); if (lib == NULL) { - fprintf(stderr, "SDL_LoadObject('%s') failed: %s\n", + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_LoadObject('%s') failed: %s\n", libname, SDL_GetError()); retval = 3; } else { fn = (fntype) SDL_LoadFunction(lib, symname); if (fn == NULL) { - fprintf(stderr, "SDL_LoadFunction('%s') failed: %s\n", + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_LoadFunction('%s') failed: %s\n", symname, SDL_GetError()); retval = 4; } else { - printf("Found %s in %s at %p\n", symname, libname, fn); + SDL_Log("Found %s in %s at %p\n", symname, libname, fn); if (hello) { - printf("Calling function...\n"); + SDL_Log("Calling function...\n"); fflush(stdout); fn(" HELLO, WORLD!\n"); - printf("...apparently, we survived. :)\n"); - printf("Unloading library...\n"); + SDL_Log("...apparently, we survived. :)\n"); + SDL_Log("Unloading library...\n"); fflush(stdout); } } diff --git a/test/testlock.c b/test/testlock.c index fcfeb8bc86dd2..0414fe3168702 100644 --- a/test/testlock.c +++ b/test/testlock.c @@ -40,7 +40,7 @@ SDL_Quit_Wrapper(void) void printid(void) { - printf("Process %lu: exiting\n", SDL_ThreadID()); + SDL_Log("Process %lu: exiting\n", SDL_ThreadID()); } void @@ -55,7 +55,7 @@ closemutex(int sig) { SDL_threadID id = SDL_ThreadID(); int i; - printf("Process %lu: Cleaning up...\n", id == mainthread ? 0 : id); + SDL_Log("Process %lu: Cleaning up...\n", id == mainthread ? 0 : id); doterminate = 1; for (i = 0; i < 6; ++i) SDL_WaitThread(threads[i], NULL); @@ -69,23 +69,23 @@ Run(void *data) if (SDL_ThreadID() == mainthread) signal(SIGTERM, closemutex); while (!doterminate) { - printf("Process %lu ready to work\n", SDL_ThreadID()); + SDL_Log("Process %lu ready to work\n", SDL_ThreadID()); if (SDL_LockMutex(mutex) < 0) { - fprintf(stderr, "Couldn't lock mutex: %s", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't lock mutex: %s", SDL_GetError()); exit(1); } - printf("Process %lu, working!\n", SDL_ThreadID()); + SDL_Log("Process %lu, working!\n", SDL_ThreadID()); SDL_Delay(1 * 1000); - printf("Process %lu, done!\n", SDL_ThreadID()); + SDL_Log("Process %lu, done!\n", SDL_ThreadID()); if (SDL_UnlockMutex(mutex) < 0) { - fprintf(stderr, "Couldn't unlock mutex: %s", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't unlock mutex: %s", SDL_GetError()); exit(1); } /* If this sleep isn't done, then threads may starve */ SDL_Delay(10); } if (SDL_ThreadID() == mainthread && doterminate) { - printf("Process %lu: raising SIGTERM\n", SDL_ThreadID()); + SDL_Log("Process %lu: raising SIGTERM\n", SDL_ThreadID()); raise(SIGTERM); } return (0); @@ -97,26 +97,29 @@ main(int argc, char *argv[]) int i; int maxproc = 6; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + /* Load the SDL library */ if (SDL_Init(0) < 0) { - fprintf(stderr, "%s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError()); exit(1); } atexit(SDL_Quit_Wrapper); if ((mutex = SDL_CreateMutex()) == NULL) { - fprintf(stderr, "Couldn't create mutex: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create mutex: %s\n", SDL_GetError()); exit(1); } mainthread = SDL_ThreadID(); - printf("Main thread: %lu\n", mainthread); + SDL_Log("Main thread: %lu\n", mainthread); atexit(printid); for (i = 0; i < maxproc; ++i) { char name[64]; SDL_snprintf(name, sizeof (name), "Worker%d", i); if ((threads[i] = SDL_CreateThread(Run, name, NULL)) == NULL) - fprintf(stderr, "Couldn't create thread!\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread!\n"); } signal(SIGINT, terminate); Run(NULL); diff --git a/test/testmessage.c b/test/testmessage.c index f76b7ebacf09b..33046236263cb 100644 --- a/test/testmessage.c +++ b/test/testmessage.c @@ -62,7 +62,7 @@ button_messagebox(void *eventNumber) success = SDL_ShowMessageBox(&data, &button); if (success == -1) { - printf("Error Presenting MessageBox: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError()); if (eventNumber) { SDL_UserEvent event; event.type = (intptr_t)eventNumber; @@ -72,7 +72,7 @@ button_messagebox(void *eventNumber) quit(2); } } - printf("Pressed button: %d, %s\n", button, button == 1 ? "Cancel" : "OK"); + SDL_Log("Pressed button: %d, %s\n", button, button == 1 ? "Cancel" : "OK"); if (eventNumber) { SDL_UserEvent event; @@ -88,12 +88,15 @@ main(int argc, char *argv[]) { int success; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Simple MessageBox", "This is a simple error MessageBox", NULL); if (success == -1) { - printf("Error Presenting MessageBox: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError()); quit(1); } @@ -102,7 +105,7 @@ main(int argc, char *argv[]) "This is a simple MessageBox with a newline:\r\nHello world!", NULL); if (success == -1) { - printf("Error Presenting MessageBox: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError()); quit(1); } @@ -112,7 +115,7 @@ main(int argc, char *argv[]) "Unicode text: '牛肉西蘭花' ...", NULL); if (success == -1) { - printf("Error Presenting MessageBox: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError()); quit(1); } @@ -122,7 +125,7 @@ main(int argc, char *argv[]) "Unicode text and newline:\r\n'牛肉西蘭花'\n'牛肉西蘭花'", NULL); if (success == -1) { - printf("Error Presenting MessageBox: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError()); quit(1); } @@ -135,7 +138,7 @@ main(int argc, char *argv[]) subsystem on the main thread. */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { - fprintf(stderr, "Couldn't initialize SDL video subsystem: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL video subsystem: %s\n", SDL_GetError()); return (1); } { @@ -153,7 +156,7 @@ main(int argc, char *argv[]) SDL_WaitThread(thread, &status); - printf("Message box thread return %i\n", status); + SDL_Log("Message box thread return %i\n", status); } /* Test showing a message box with a parent window */ @@ -166,7 +169,7 @@ main(int argc, char *argv[]) "This is a simple error MessageBox with a parent window", window); if (success == -1) { - printf("Error Presenting MessageBox: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError()); quit(1); } diff --git a/test/testmultiaudio.c b/test/testmultiaudio.c index 47a95e3447d6c..48d628ae35a62 100644 --- a/test/testmultiaudio.c +++ b/test/testmultiaudio.c @@ -10,7 +10,6 @@ freely. */ #include "SDL.h" -#include static SDL_AudioSpec spec; static Uint8 *sound = NULL; /* Pointer to wave data */ @@ -51,7 +50,7 @@ test_multi_audio(int devcount) int i; if (devcount > 64) { - fprintf(stderr, "Too many devices (%d), clamping to 64...\n", + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Too many devices (%d), clamping to 64...\n", devcount); devcount = 64; } @@ -60,33 +59,33 @@ test_multi_audio(int devcount) for (i = 0; i < devcount; i++) { const char *devname = SDL_GetAudioDeviceName(i, 0); - printf("playing on device #%d: ('%s')...", i, devname); + SDL_Log("playing on device #%d: ('%s')...", i, devname); fflush(stdout); SDL_memset(&cbd[0], '\0', sizeof(callback_data)); spec.userdata = &cbd[0]; cbd[0].dev = SDL_OpenAudioDevice(devname, 0, &spec, NULL, 0); if (cbd[0].dev == 0) { - printf("\nOpen device failed: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Open device failed: %s\n", SDL_GetError()); } else { SDL_PauseAudioDevice(cbd[0].dev, 0); while (!cbd[0].done) SDL_Delay(100); SDL_PauseAudioDevice(cbd[0].dev, 1); - printf("done.\n"); + SDL_Log("done.\n"); SDL_CloseAudioDevice(cbd[0].dev); } } SDL_memset(cbd, '\0', sizeof(cbd)); - printf("playing on all devices...\n"); + SDL_Log("playing on all devices...\n"); for (i = 0; i < devcount; i++) { const char *devname = SDL_GetAudioDeviceName(i, 0); spec.userdata = &cbd[i]; cbd[i].dev = SDL_OpenAudioDevice(devname, 0, &spec, NULL, 0); if (cbd[i].dev == 0) { - printf("Open device %d failed: %s\n", i, SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Open device %d failed: %s\n", i, SDL_GetError()); } } @@ -113,7 +112,7 @@ test_multi_audio(int devcount) } } - printf("All done!\n"); + SDL_Log("All done!\n"); } @@ -122,17 +121,20 @@ main(int argc, char **argv) { int devcount = 0; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + /* Load the SDL library */ if (SDL_Init(SDL_INIT_AUDIO) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return (1); } - printf("Using audio driver: %s\n", SDL_GetCurrentAudioDriver()); + SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver()); devcount = SDL_GetNumAudioDevices(0); if (devcount < 1) { - fprintf(stderr, "Don't see any specific audio devices!\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Don't see any specific audio devices!\n"); } else { if (argv[1] == NULL) { argv[1] = "sample.wav"; @@ -140,7 +142,7 @@ main(int argc, char **argv) /* Load the wave file into memory */ if (SDL_LoadWAV(argv[1], &spec, &sound, &soundlen) == NULL) { - fprintf(stderr, "Couldn't load %s: %s\n", argv[1], + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", argv[1], SDL_GetError()); } else { test_multi_audio(devcount); diff --git a/test/testnative.c b/test/testnative.c index 63cba29c3ac71..0ac99b2a3e4c7 100644 --- a/test/testnative.c +++ b/test/testnative.c @@ -58,7 +58,7 @@ LoadSprite(SDL_Renderer *renderer, char *file) /* Load the sprite image */ temp = SDL_LoadBMP(file); if (temp == NULL) { - fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError()); return 0; } @@ -70,7 +70,7 @@ LoadSprite(SDL_Renderer *renderer, char *file) /* Create textures from the image */ sprite = SDL_CreateTextureFromSurface(renderer, temp); if (!sprite) { - fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError()); SDL_FreeSurface(temp); return 0; } @@ -131,8 +131,11 @@ main(int argc, char *argv[]) int sprite_w, sprite_h; SDL_Event event; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + if (SDL_VideoInit(NULL) < 0) { - fprintf(stderr, "Couldn't initialize SDL video: %s\n", + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL video: %s\n", SDL_GetError()); exit(1); } @@ -146,19 +149,19 @@ main(int argc, char *argv[]) } } if (!factory) { - fprintf(stderr, "Couldn't find native window code for %s driver\n", + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find native window code for %s driver\n", driver); quit(2); } - printf("Creating native window for %s driver\n", driver); + SDL_Log("Creating native window for %s driver\n", driver); native_window = factory->CreateNativeWindow(WINDOW_W, WINDOW_H); if (!native_window) { - fprintf(stderr, "Couldn't create native window\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create native window\n"); quit(3); } window = SDL_CreateWindowFrom(native_window); if (!window) { - fprintf(stderr, "Couldn't create SDL window: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create SDL window: %s\n", SDL_GetError()); quit(4); } SDL_SetWindowTitle(window, "SDL Native Window Test"); @@ -166,7 +169,7 @@ main(int argc, char *argv[]) /* Create the renderer */ renderer = SDL_CreateRenderer(window, -1, 0); if (!renderer) { - fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError()); quit(5); } @@ -185,7 +188,7 @@ main(int argc, char *argv[]) positions = (SDL_Rect *) SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect)); velocities = (SDL_Rect *) SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect)); if (!positions || !velocities) { - fprintf(stderr, "Out of memory!\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n"); quit(2); } srand(time(NULL)); diff --git a/test/testoverlay2.c b/test/testoverlay2.c index e071614ad1456..23e1e1f174e9d 100644 --- a/test/testoverlay2.c +++ b/test/testoverlay2.c @@ -209,19 +209,18 @@ ConvertRGBtoYV12(Uint8 *rgb, Uint8 *out, int w, int h, static void PrintUsage(char *argv0) { - fprintf(stderr, "Usage: %s [arg] [arg] [arg] ...\n", argv0); - fprintf(stderr, "\n"); - fprintf(stderr, "Where 'arg' is any of the following options:\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " -fps \n"); - fprintf(stderr, " -nodelay\n"); - fprintf(stderr, " -format (one of the: YV12, IYUV, YUY2, UYVY, YVYU)\n"); - fprintf(stderr, " -scale (initial scale of the overlay)\n"); - fprintf(stderr, " -help (shows this help)\n"); - fprintf(stderr, "\n"); - fprintf(stderr, - "Press ESC to exit, or SPACE to freeze the movie while application running.\n"); - fprintf(stderr, "\n"); + SDL_Log("Usage: %s [arg] [arg] [arg] ...\n", argv0); + SDL_Log("\n"); + SDL_Log("Where 'arg' is any of the following options:\n"); + SDL_Log("\n"); + SDL_Log(" -fps \n"); + SDL_Log(" -nodelay\n"); + SDL_Log(" -format (one of the: YV12, IYUV, YUY2, UYVY, YVYU)\n"); + SDL_Log(" -scale (initial scale of the overlay)\n"); + SDL_Log(" -help (shows this help)\n"); + SDL_Log("\n"); + SDL_Log("Press ESC to exit, or SPACE to freeze the movie while application running.\n"); + SDL_Log("\n"); } int @@ -246,8 +245,11 @@ main(int argc, char **argv) int scale = 5; SDL_bool done = SDL_FALSE; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + if (SDL_Init(SDL_INIT_VIDEO) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return 3; } @@ -256,19 +258,19 @@ main(int argc, char **argv) if (argv[2]) { fps = atoi(argv[2]); if (fps == 0) { - fprintf(stderr, + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "The -fps option requires an argument [from 1 to 1000], default is 12.\n"); quit(10); } if ((fps < 0) || (fps > 1000)) { - fprintf(stderr, + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "The -fps option must be in range from 1 to 1000, default is 12.\n"); quit(10); } argv += 2; argc -= 2; } else { - fprintf(stderr, + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "The -fps option requires an argument [from 1 to 1000], default is 12.\n"); quit(10); } @@ -280,19 +282,19 @@ main(int argc, char **argv) if (argv[2]) { scale = atoi(argv[2]); if (scale == 0) { - fprintf(stderr, + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "The -scale option requires an argument [from 1 to 50], default is 5.\n"); quit(10); } if ((scale < 0) || (scale > 50)) { - fprintf(stderr, + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "The -scale option must be in range from 1 to 50, default is 5.\n"); quit(10); } argv += 2; argc -= 2; } else { - fprintf(stderr, + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "The -fps option requires an argument [from 1 to 1000], default is 12.\n"); quit(10); } @@ -301,7 +303,7 @@ main(int argc, char **argv) PrintUsage(argv[0]); quit(0); } else { - fprintf(stderr, "Unrecognized option: %s.\n", argv[1]); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unrecognized option: %s.\n", argv[1]); quit(10); } break; @@ -309,7 +311,7 @@ main(int argc, char **argv) RawMooseData = (Uint8 *) malloc(MOOSEFRAME_SIZE * MOOSEFRAMES_COUNT); if (RawMooseData == NULL) { - fprintf(stderr, "Can't allocate memory for movie !\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't allocate memory for movie !\n"); free(RawMooseData); quit(1); } @@ -317,7 +319,7 @@ main(int argc, char **argv) /* load the trojan moose images */ handle = SDL_RWFromFile("moose.dat", "rb"); if (handle == NULL) { - fprintf(stderr, "Can't find the file moose.dat !\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't find the file moose.dat !\n"); free(RawMooseData); quit(2); } @@ -335,21 +337,21 @@ main(int argc, char **argv) window_w, window_h, SDL_WINDOW_RESIZABLE); if (!window) { - fprintf(stderr, "Couldn't set create window: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create window: %s\n", SDL_GetError()); free(RawMooseData); quit(4); } renderer = SDL_CreateRenderer(window, -1, 0); if (!renderer) { - fprintf(stderr, "Couldn't set create renderer: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create renderer: %s\n", SDL_GetError()); free(RawMooseData); quit(4); } MooseTexture = SDL_CreateTexture(renderer, pixel_format, SDL_TEXTUREACCESS_STREAMING, MOOSEPIC_W, MOOSEPIC_H); if (!MooseTexture) { - fprintf(stderr, "Couldn't set create texture: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError()); free(RawMooseData); quit(5); } diff --git a/test/testplatform.c b/test/testplatform.c index 326b6f7e4931e..2f32e1f4e9c5e 100644 --- a/test/testplatform.c +++ b/test/testplatform.c @@ -35,30 +35,30 @@ TestTypes(SDL_bool verbose) if (badsize(sizeof(Uint8), 1)) { if (verbose) - printf("sizeof(Uint8) != 1, instead = %u\n", + SDL_Log("sizeof(Uint8) != 1, instead = %u\n", (unsigned int)sizeof(Uint8)); ++error; } if (badsize(sizeof(Uint16), 2)) { if (verbose) - printf("sizeof(Uint16) != 2, instead = %u\n", + SDL_Log("sizeof(Uint16) != 2, instead = %u\n", (unsigned int)sizeof(Uint16)); ++error; } if (badsize(sizeof(Uint32), 4)) { if (verbose) - printf("sizeof(Uint32) != 4, instead = %u\n", + SDL_Log("sizeof(Uint32) != 4, instead = %u\n", (unsigned int)sizeof(Uint32)); ++error; } if (badsize(sizeof(Uint64), 8)) { if (verbose) - printf("sizeof(Uint64) != 8, instead = %u\n", + SDL_Log("sizeof(Uint64) != 8, instead = %u\n", (unsigned int)sizeof(Uint64)); ++error; } if (verbose && !error) - printf("All data types are the expected size.\n"); + SDL_Log("All data types are the expected size.\n"); return (error ? 1 : 0); } @@ -83,7 +83,7 @@ TestEndian(SDL_bool verbose) swapped64 |= 0xDEADBEEF; if (verbose) { - printf("Detected a %s endian machine.\n", + SDL_Log("Detected a %s endian machine.\n", (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big"); } if ((*((char *) &value) >> 4) == 0x1) { @@ -93,44 +93,44 @@ TestEndian(SDL_bool verbose) } if (real_byteorder != SDL_BYTEORDER) { if (verbose) { - printf("Actually a %s endian machine!\n", + SDL_Log("Actually a %s endian machine!\n", (real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big"); } ++error; } if (verbose) { - printf("Value 16 = 0x%X, swapped = 0x%X\n", value16, + SDL_Log("Value 16 = 0x%X, swapped = 0x%X\n", value16, SDL_Swap16(value16)); } if (SDL_Swap16(value16) != swapped16) { if (verbose) { - printf("16 bit value swapped incorrectly!\n"); + SDL_Log("16 bit value swapped incorrectly!\n"); } ++error; } if (verbose) { - printf("Value 32 = 0x%X, swapped = 0x%X\n", value32, + SDL_Log("Value 32 = 0x%X, swapped = 0x%X\n", value32, SDL_Swap32(value32)); } if (SDL_Swap32(value32) != swapped32) { if (verbose) { - printf("32 bit value swapped incorrectly!\n"); + SDL_Log("32 bit value swapped incorrectly!\n"); } ++error; } if (verbose) { #ifdef _MSC_VER - printf("Value 64 = 0x%I64X, swapped = 0x%I64X\n", value64, + SDL_Log("Value 64 = 0x%I64X, swapped = 0x%I64X\n", value64, SDL_Swap64(value64)); #else - printf("Value 64 = 0x%llX, swapped = 0x%llX\n", + SDL_Log("Value 64 = 0x%llX, swapped = 0x%llX\n", (unsigned long long) value64, (unsigned long long) SDL_Swap64(value64)); #endif } if (SDL_Swap64(value64) != swapped64) { if (verbose) { - printf("64 bit value swapped incorrectly!\n"); + SDL_Log("64 bit value swapped incorrectly!\n"); } ++error; } @@ -142,17 +142,17 @@ int TestCPUInfo(SDL_bool verbose) { if (verbose) { - printf("CPU count: %d\n", SDL_GetCPUCount()); - printf("CPU cache line size: %d\n", SDL_GetCPUCacheLineSize()); - printf("RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected"); - printf("AltiVec %s\n", SDL_HasAltiVec()? "detected" : "not detected"); - printf("MMX %s\n", SDL_HasMMX()? "detected" : "not detected"); - printf("3DNow! %s\n", SDL_Has3DNow()? "detected" : "not detected"); - printf("SSE %s\n", SDL_HasSSE()? "detected" : "not detected"); - printf("SSE2 %s\n", SDL_HasSSE2()? "detected" : "not detected"); - printf("SSE3 %s\n", SDL_HasSSE3()? "detected" : "not detected"); - printf("SSE4.1 %s\n", SDL_HasSSE41()? "detected" : "not detected"); - printf("SSE4.2 %s\n", SDL_HasSSE42()? "detected" : "not detected"); + SDL_Log("CPU count: %d\n", SDL_GetCPUCount()); + SDL_Log("CPU cache line size: %d\n", SDL_GetCPUCacheLineSize()); + SDL_Log("RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected"); + SDL_Log("AltiVec %s\n", SDL_HasAltiVec()? "detected" : "not detected"); + SDL_Log("MMX %s\n", SDL_HasMMX()? "detected" : "not detected"); + SDL_Log("3DNow! %s\n", SDL_Has3DNow()? "detected" : "not detected"); + SDL_Log("SSE %s\n", SDL_HasSSE()? "detected" : "not detected"); + SDL_Log("SSE2 %s\n", SDL_HasSSE2()? "detected" : "not detected"); + SDL_Log("SSE3 %s\n", SDL_HasSSE3()? "detected" : "not detected"); + SDL_Log("SSE4.1 %s\n", SDL_HasSSE41()? "detected" : "not detected"); + SDL_Log("SSE4.2 %s\n", SDL_HasSSE42()? "detected" : "not detected"); } return (0); } @@ -176,7 +176,7 @@ TestAssertions(SDL_bool verbose) { const SDL_assert_data *item = SDL_GetAssertionReport(); while (item) { - printf("'%s', %s (%s:%d), triggered %u times, always ignore: %s.\n", + SDL_Log("'%s', %s (%s:%d), triggered %u times, always ignore: %s.\n", item->condition, item->function, item->filename, item->linenum, item->trigger_count, item->always_ignore ? "yes" : "no"); @@ -192,11 +192,14 @@ main(int argc, char *argv[]) SDL_bool verbose = SDL_TRUE; int status = 0; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + if (argv[1] && (SDL_strcmp(argv[1], "-q") == 0)) { verbose = SDL_FALSE; } if (verbose) { - printf("This system is running %s\n", SDL_GetPlatform()); + SDL_Log("This system is running %s\n", SDL_GetPlatform()); } status += TestTypes(verbose); diff --git a/test/testpower.c b/test/testpower.c index 3e13d0ac1dd52..1b321439367f9 100644 --- a/test/testpower.c +++ b/test/testpower.c @@ -21,7 +21,7 @@ report_power(void) const SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent); char *statestr = NULL; - printf("SDL-reported power info...\n"); + SDL_Log("SDL-reported power info...\n"); switch (state) { case SDL_POWERSTATE_UNKNOWN: statestr = "Unknown"; @@ -43,18 +43,18 @@ report_power(void) break; } - printf("State: %s\n", statestr); + SDL_Log("State: %s\n", statestr); if (percent == -1) { - printf("Percent left: unknown\n"); + SDL_Log("Percent left: unknown\n"); } else { - printf("Percent left: %d%%\n", percent); + SDL_Log("Percent left: %d%%\n", percent); } if (seconds == -1) { - printf("Time left: unknown\n"); + SDL_Log("Time left: unknown\n"); } else { - printf("Time left: %d minutes, %d seconds\n", (int) (seconds / 60), + SDL_Log("Time left: %d minutes, %d seconds\n", (int) (seconds / 60), (int) (seconds % 60)); } } @@ -63,8 +63,11 @@ report_power(void) int main(int argc, char *argv[]) { + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + if (SDL_Init(0) == -1) { - fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError()); return 1; } diff --git a/test/testrelative.c b/test/testrelative.c index fa5bda660b818..478d3bf77ca7d 100644 --- a/test/testrelative.c +++ b/test/testrelative.c @@ -35,6 +35,8 @@ main(int argc, char *argv[]) int i, done; SDL_Event event; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); @@ -74,10 +76,8 @@ main(int argc, char *argv[]) switch(event.type) { case SDL_MOUSEMOTION: { - /*printf("mouse motion ABS x %d y %d REL x %d y %d\n",event.motion.x,event.motion.y,event.motion.xrel,event.motion.yrel);*/ rect.x += event.motion.xrel; rect.y += event.motion.yrel; - } break; } diff --git a/test/testrendercopyex.c b/test/testrendercopyex.c index 6dd59c0ac24cc..a0221fe0fec55 100644 --- a/test/testrendercopyex.c +++ b/test/testrendercopyex.c @@ -46,7 +46,7 @@ LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent) /* Load the sprite image */ temp = SDL_LoadBMP(file); if (temp == NULL) { - fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError()); return NULL; } @@ -77,7 +77,7 @@ LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent) /* Create textures from the image */ texture = SDL_CreateTextureFromSurface(renderer, temp); if (!texture) { - fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError()); SDL_FreeSurface(temp); return NULL; } @@ -139,6 +139,9 @@ main(int argc, char *argv[]) int frames; Uint32 then, now; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); if (!state) { @@ -149,7 +152,7 @@ main(int argc, char *argv[]) consumed = SDLTest_CommonArg(state, i); if (consumed == 0) { - fprintf(stderr, "Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state)); + SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state)); return 1; } i += consumed; @@ -193,7 +196,7 @@ main(int argc, char *argv[]) now = SDL_GetTicks(); if (now > then) { double fps = ((double) frames * 1000) / (now - then); - printf("%2.2f frames per second\n", fps); + SDL_Log("%2.2f frames per second\n", fps); } SDL_stack_free(drawstates); diff --git a/test/testrendertarget.c b/test/testrendertarget.c index bc31048251983..03e8df19e13de 100644 --- a/test/testrendertarget.c +++ b/test/testrendertarget.c @@ -46,7 +46,7 @@ LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent) /* Load the sprite image */ temp = SDL_LoadBMP(file); if (temp == NULL) { - fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError()); return NULL; } @@ -77,7 +77,7 @@ LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent) /* Create textures from the image */ texture = SDL_CreateTextureFromSurface(renderer, temp); if (!texture) { - fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError()); SDL_FreeSurface(temp); return NULL; } @@ -114,7 +114,7 @@ DrawComposite(DrawState *s) SDL_RenderCopy(s->renderer, A, NULL, NULL); SDL_RenderReadPixels(s->renderer, NULL, SDL_PIXELFORMAT_ARGB8888, &P, sizeof(P)); - printf("Blended pixel: 0x%8.8X\n", P); + SDL_Log("Blended pixel: 0x%8.8X\n", P); SDL_DestroyTexture(A); SDL_DestroyTexture(B); @@ -218,6 +218,9 @@ main(int argc, char *argv[]) Uint32 then, now; SDL_bool test_composite = SDL_FALSE; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); if (!state) { @@ -235,8 +238,7 @@ main(int argc, char *argv[]) } } if (consumed < 0) { - fprintf(stderr, - "Usage: %s %s [--composite]\n", + SDL_Log("Usage: %s %s [--composite]\n", argv[0], SDLTest_CommonUsage(state)); quit(1); } @@ -289,7 +291,7 @@ main(int argc, char *argv[]) now = SDL_GetTicks(); if (now > then) { double fps = ((double) frames * 1000) / (now - then); - printf("%2.2f frames per second\n", fps); + SDL_Log("%2.2f frames per second\n", fps); } SDL_stack_free(drawstates); diff --git a/test/testresample.c b/test/testresample.c index d79f1ac8ace2e..177bd84139cac 100644 --- a/test/testresample.c +++ b/test/testresample.c @@ -9,7 +9,7 @@ including commercial applications, and to alter it and redistribute it freely. */ -#include + #include "SDL.h" int @@ -25,27 +25,30 @@ main(int argc, char **argv) int avgbytes = 0; SDL_RWops *io = NULL; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + if (argc != 4) { - fprintf(stderr, "USAGE: %s in.wav out.wav newfreq\n", argv[0]); + SDL_Log("USAGE: %s in.wav out.wav newfreq\n", argv[0]); return 1; } cvtfreq = SDL_atoi(argv[3]); if (SDL_Init(SDL_INIT_AUDIO) == -1) { - fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError()); return 2; } if (SDL_LoadWAV(argv[1], &spec, &data, &len) == NULL) { - fprintf(stderr, "failed to load %s: %s\n", argv[1], SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "failed to load %s: %s\n", argv[1], SDL_GetError()); SDL_Quit(); return 3; } if (SDL_BuildAudioCVT(&cvt, spec.format, spec.channels, spec.freq, spec.format, spec.channels, cvtfreq) == -1) { - fprintf(stderr, "failed to build CVT: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "failed to build CVT: %s\n", SDL_GetError()); SDL_FreeWAV(data); SDL_Quit(); return 4; @@ -54,7 +57,7 @@ main(int argc, char **argv) cvt.len = len; cvt.buf = (Uint8 *) SDL_malloc(len * cvt.len_mult); if (cvt.buf == NULL) { - fprintf(stderr, "Out of memory.\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory.\n"); SDL_FreeWAV(data); SDL_Quit(); return 5; @@ -62,7 +65,7 @@ main(int argc, char **argv) SDL_memcpy(cvt.buf, data, len); if (SDL_ConvertAudio(&cvt) == -1) { - fprintf(stderr, "Conversion failed: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Conversion failed: %s\n", SDL_GetError()); SDL_free(cvt.buf); SDL_FreeWAV(data); SDL_Quit(); @@ -72,7 +75,7 @@ main(int argc, char **argv) /* write out a WAV header... */ io = SDL_RWFromFile(argv[2], "wb"); if (io == NULL) { - fprintf(stderr, "fopen('%s') failed: %s\n", argv[2], SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "fopen('%s') failed: %s\n", argv[2], SDL_GetError()); SDL_free(cvt.buf); SDL_FreeWAV(data); SDL_Quit(); @@ -99,7 +102,7 @@ main(int argc, char **argv) SDL_RWwrite(io, cvt.buf, cvt.len_cvt, 1); if (SDL_RWclose(io) == -1) { - fprintf(stderr, "fclose('%s') failed: %s\n", argv[2], SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "fclose('%s') failed: %s\n", argv[2], SDL_GetError()); SDL_free(cvt.buf); SDL_FreeWAV(data); SDL_Quit(); diff --git a/test/testrumble.c b/test/testrumble.c index e5b5424d46f77..ffcaae4a84e92 100644 --- a/test/testrumble.c +++ b/test/testrumble.c @@ -26,7 +26,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * includes */ #include -#include /* printf */ #include /* strstr */ #include /* isdigit */ @@ -51,12 +50,15 @@ main(int argc, char **argv) char *name; int index; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + name = NULL; index = -1; if (argc > 1) { name = argv[1]; if ((strcmp(name, "--help") == 0) || (strcmp(name, "-h") == 0)) { - printf("USAGE: %s [device]\n" + SDL_Log("USAGE: %s [device]\n" "If device is a two-digit number it'll use it as an index, otherwise\n" "it'll use it as if it were part of the device's name.\n", argv[0]); @@ -73,7 +75,7 @@ main(int argc, char **argv) /* Initialize the force feedbackness */ SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC); - printf("%d Haptic devices detected.\n", SDL_NumHaptics()); + SDL_Log("%d Haptic devices detected.\n", SDL_NumHaptics()); if (SDL_NumHaptics() > 0) { /* We'll just use index or the first force feedback device found */ if (name == NULL) { @@ -87,7 +89,7 @@ main(int argc, char **argv) } if (i >= SDL_NumHaptics()) { - printf("Unable to find device matching '%s', aborting.\n", + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n", name); return 1; } @@ -95,13 +97,13 @@ main(int argc, char **argv) haptic = SDL_HapticOpen(i); if (haptic == NULL) { - printf("Unable to create the haptic device: %s\n", + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n", SDL_GetError()); return 1; } - printf("Device: %s\n", SDL_HapticName(i)); + SDL_Log("Device: %s\n", SDL_HapticName(i)); } else { - printf("No Haptic devices found!\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n"); return 1; } @@ -109,25 +111,25 @@ main(int argc, char **argv) SDL_ClearError(); if (SDL_HapticRumbleSupported(haptic) == SDL_FALSE) { - printf("\nRumble not supported!\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Rumble not supported!\n"); return 1; } if (SDL_HapticRumbleInit(haptic) != 0) { - printf("\nFailed to initialize rumble: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to initialize rumble: %s\n", SDL_GetError()); return 1; } - printf("Playing 2 second rumble at 0.5 magnitude.\n"); + SDL_Log("Playing 2 second rumble at 0.5 magnitude.\n"); if (SDL_HapticRumblePlay(haptic, 0.5, 5000) != 0) { - printf("\nFailed to play rumble: %s\n", SDL_GetError() ); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError() ); return 1; } SDL_Delay(2000); - printf("Stopping rumble.\n"); + SDL_Log("Stopping rumble.\n"); SDL_HapticRumbleStop(haptic); SDL_Delay(2000); - printf("Playing 2 second rumble at 0.3 magnitude.\n"); + SDL_Log("Playing 2 second rumble at 0.3 magnitude.\n"); if (SDL_HapticRumblePlay(haptic, 0.3f, 5000) != 0) { - printf("\nFailed to play rumble: %s\n", SDL_GetError() ); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError() ); return 1; } SDL_Delay(2000); @@ -145,7 +147,7 @@ main(int argc, char **argv) int main(int argc, char *argv[]) { - fprintf(stderr, "SDL compiled without Haptic support.\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Haptic support.\n"); exit(1); } diff --git a/test/testscale.c b/test/testscale.c index 0f0096c6e20e0..f81ccdc243d9a 100644 --- a/test/testscale.c +++ b/test/testscale.c @@ -48,7 +48,7 @@ LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent) /* Load the sprite image */ temp = SDL_LoadBMP(file); if (temp == NULL) { - fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError()); return NULL; } @@ -79,7 +79,7 @@ LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent) /* Create textures from the image */ texture = SDL_CreateTextureFromSurface(renderer, temp); if (!texture) { - fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError()); SDL_FreeSurface(temp); return NULL; } @@ -129,6 +129,9 @@ main(int argc, char *argv[]) int frames; Uint32 then, now; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); if (!state) { @@ -139,7 +142,7 @@ main(int argc, char *argv[]) consumed = SDLTest_CommonArg(state, i); if (consumed == 0) { - fprintf(stderr, "Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state)); + SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state)); return 1; } i += consumed; @@ -183,7 +186,7 @@ main(int argc, char *argv[]) now = SDL_GetTicks(); if (now > then) { double fps = ((double) frames * 1000) / (now - then); - printf("%2.2f frames per second\n", fps); + SDL_Log("%2.2f frames per second\n", fps); } SDL_stack_free(drawstates); diff --git a/test/testsem.c b/test/testsem.c index eab280e1d9083..6a2a59e675907 100644 --- a/test/testsem.c +++ b/test/testsem.c @@ -30,17 +30,15 @@ ThreadFunc(void *data) int threadnum = (int) (uintptr_t) data; while (alive) { SDL_SemWait(sem); - fprintf(stderr, - "Thread number %d has got the semaphore (value = %d)!\n", + SDL_Log("Thread number %d has got the semaphore (value = %d)!\n", threadnum, SDL_SemValue(sem)); SDL_Delay(200); SDL_SemPost(sem); - fprintf(stderr, - "Thread number %d has released the semaphore (value = %d)!\n", + SDL_Log("Thread number %d has released the semaphore (value = %d)!\n", threadnum, SDL_SemValue(sem)); SDL_Delay(1); /* For the scheduler */ } - printf("Thread number %d exiting.\n", threadnum); + SDL_Log("Thread number %d exiting.\n", threadnum); return 0; } @@ -59,7 +57,7 @@ TestWaitTimeout(void) int retval; sem = SDL_CreateSemaphore(0); - printf("Waiting 2 seconds on semaphore\n"); + SDL_Log("Waiting 2 seconds on semaphore\n"); start_ticks = SDL_GetTicks(); retval = SDL_SemWaitTimeout(sem, 2000); @@ -69,13 +67,13 @@ TestWaitTimeout(void) /* Accept a little offset in the effective wait */ if (duration > 1900 && duration < 2050) - printf("Wait done.\n"); + SDL_Log("Wait done.\n"); else - fprintf(stderr, "Wait took %d milliseconds\n", duration); + SDL_Log("Wait took %d milliseconds\n", duration); /* Check to make sure the return value indicates timed out */ if (retval != SDL_MUTEX_TIMEDOUT) - fprintf(stderr, "SDL_SemWaitTimeout returned: %d; expected: %d\n", retval, SDL_MUTEX_TIMEDOUT); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_SemWaitTimeout returned: %d; expected: %d\n", retval, SDL_MUTEX_TIMEDOUT); } int @@ -85,14 +83,17 @@ main(int argc, char **argv) uintptr_t i; int init_sem; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + if (argc < 2) { - fprintf(stderr, "Usage: %s init_value\n", argv[0]); + SDL_Log("Usage: %s init_value\n", argv[0]); return (1); } /* Load the SDL library */ if (SDL_Init(0) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return (1); } signal(SIGTERM, killed); @@ -101,7 +102,7 @@ main(int argc, char **argv) init_sem = atoi(argv[1]); sem = SDL_CreateSemaphore(init_sem); - printf("Running %d threads, semaphore value = %d\n", NUM_THREADS, + SDL_Log("Running %d threads, semaphore value = %d\n", NUM_THREADS, init_sem); /* Create all the threads */ for (i = 0; i < NUM_THREADS; ++i) { @@ -114,12 +115,12 @@ main(int argc, char **argv) SDL_Delay(10 * 1000); /* Wait for all threads to finish */ - printf("Waiting for threads to finish\n"); + SDL_Log("Waiting for threads to finish\n"); alive = 0; for (i = 0; i < NUM_THREADS; ++i) { SDL_WaitThread(threads[i], NULL); } - printf("Finished waiting for threads\n"); + SDL_Log("Finished waiting for threads\n"); SDL_DestroySemaphore(sem); diff --git a/test/testshader.c b/test/testshader.c index 376b445e79929..138dd45f83b93 100644 --- a/test/testshader.c +++ b/test/testshader.c @@ -11,7 +11,6 @@ */ /* This is a simple example of using GLSL shaders with SDL */ -#include /* for printf() */ #include "SDL.h" #ifdef HAVE_OPENGL @@ -139,7 +138,7 @@ static SDL_bool CompileShader(GLhandleARB shader, const char *source) glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length); info = SDL_stack_alloc(char, length+1); glGetInfoLogARB(shader, length, NULL, info); - fprintf(stderr, "Failed to compile shader:\n%s\n%s", source, info); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile shader:\n%s\n%s", source, info); SDL_stack_free(info); return SDL_FALSE; @@ -245,7 +244,7 @@ static SDL_bool InitShaders() /* Compile all the shaders */ for (i = 0; i < NUM_SHADERS; ++i) { if (!CompileShaderProgram(&shaders[i])) { - fprintf(stderr, "Unable to compile shader!\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to compile shader!\n"); return SDL_FALSE; } } @@ -422,29 +421,32 @@ int main(int argc, char **argv) GLuint texture; GLfloat texcoords[4]; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + /* Initialize SDL for video output */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { - fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to initialize SDL: %s\n", SDL_GetError()); exit(1); } /* Create a 640x480 OpenGL screen */ window = SDL_CreateWindow( "Shader Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL ); if ( !window ) { - fprintf(stderr, "Unable to create OpenGL window: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create OpenGL window: %s\n", SDL_GetError()); SDL_Quit(); exit(2); } if ( !SDL_GL_CreateContext(window)) { - fprintf(stderr, "Unable to create OpenGL context: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create OpenGL context: %s\n", SDL_GetError()); SDL_Quit(); exit(2); } surface = SDL_LoadBMP("icon.bmp"); if ( ! surface ) { - fprintf(stderr, "Unable to load icon.bmp: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to load icon.bmp: %s\n", SDL_GetError()); SDL_Quit(); exit(3); } @@ -454,9 +456,9 @@ int main(int argc, char **argv) /* Loop, drawing and checking events */ InitGL(640, 480); if (InitShaders()) { - printf("Shaders supported, press SPACE to cycle them.\n"); + SDL_Log("Shaders supported, press SPACE to cycle them.\n"); } else { - printf("Shaders not supported!\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Shaders not supported!\n"); } done = 0; while ( ! done ) { @@ -489,7 +491,7 @@ int main(int argc, char **argv) int main(int argc, char *argv[]) { - printf("No OpenGL support on this system\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No OpenGL support on this system\n"); return 1; } diff --git a/test/testshape.c b/test/testshape.c index 59dfb9fc281d5..5c969b30e697c 100644 --- a/test/testshape.c +++ b/test/testshape.c @@ -68,13 +68,16 @@ int main(int argc,char** argv) int access = 0; SDL_Rect texture_dimensions;; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + if(argc < 2) { - printf("SDL_Shape requires at least one bitmap file as argument.\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Shape requires at least one bitmap file as argument."); exit(-1); } if(SDL_VideoInit(NULL) == -1) { - printf("Could not initialize SDL video.\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not initialize SDL video."); exit(-2); } @@ -91,7 +94,7 @@ int main(int argc,char** argv) SDL_FreeSurface(pictures[j].surface); SDL_free(pictures); SDL_VideoQuit(); - printf("Could not load surface from named bitmap file.\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not load surface from named bitmap file."); exit(-3); } @@ -112,7 +115,7 @@ int main(int argc,char** argv) SDL_FreeSurface(pictures[i].surface); SDL_free(pictures); SDL_VideoQuit(); - printf("Could not create shaped window for SDL_Shape.\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create shaped window for SDL_Shape."); exit(-4); } renderer = SDL_CreateRenderer(window,-1,0); @@ -122,7 +125,7 @@ int main(int argc,char** argv) SDL_FreeSurface(pictures[i].surface); SDL_free(pictures); SDL_VideoQuit(); - printf("Could not create rendering context for SDL_Shape window.\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create rendering context for SDL_Shape window."); exit(-5); } @@ -141,7 +144,7 @@ int main(int argc,char** argv) SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); SDL_VideoQuit(); - printf("Could not create texture for SDL_shape.\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create texture for SDL_shape."); exit(-6); } } diff --git a/test/testsprite2.c b/test/testsprite2.c index f77296960087b..26cc29f663da2 100644 --- a/test/testsprite2.c +++ b/test/testsprite2.c @@ -64,7 +64,7 @@ LoadSprite(const char *file) /* Load the sprite image */ temp = SDL_LoadBMP(file); if (temp == NULL) { - fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError()); return (-1); } sprite_w = temp->w; @@ -95,7 +95,7 @@ LoadSprite(const char *file) SDL_Renderer *renderer = state->renderers[i]; sprites[i] = SDL_CreateTextureFromSurface(renderer, temp); if (!sprites[i]) { - fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError()); SDL_FreeSurface(temp); return (-1); } @@ -299,8 +299,7 @@ main(int argc, char *argv[]) } } if (consumed < 0) { - fprintf(stderr, - "Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha] [--iterations N] [num_sprites] [icon.bmp]\n", + SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha] [--iterations N] [num_sprites] [icon.bmp]\n", argv[0], SDLTest_CommonUsage(state)); quit(1); } @@ -314,7 +313,7 @@ main(int argc, char *argv[]) sprites = (SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites)); if (!sprites) { - fprintf(stderr, "Out of memory!\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n"); quit(2); } for (i = 0; i < state->num_windows; ++i) { @@ -330,7 +329,7 @@ main(int argc, char *argv[]) positions = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect)); velocities = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect)); if (!positions || !velocities) { - fprintf(stderr, "Out of memory!\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n"); quit(2); } @@ -375,7 +374,7 @@ main(int argc, char *argv[]) now = SDL_GetTicks(); if (now > then) { double fps = ((double) frames * 1000) / (now - then); - printf("%2.2f frames per second\n", fps); + SDL_Log("%2.2f frames per second\n", fps); } quit(0); return 0; diff --git a/test/testspriteminimal.c b/test/testspriteminimal.c index 6f3ac25c04e91..157293f306836 100644 --- a/test/testspriteminimal.c +++ b/test/testspriteminimal.c @@ -42,7 +42,7 @@ LoadSprite(char *file, SDL_Renderer *renderer) /* Load the sprite image */ temp = SDL_LoadBMP(file); if (temp == NULL) { - fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", file, SDL_GetError()); return (-1); } sprite_w = temp->w; @@ -73,7 +73,7 @@ LoadSprite(char *file, SDL_Renderer *renderer) /* Create textures from the image */ sprite = SDL_CreateTextureFromSurface(renderer, temp); if (!sprite) { - fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError()); SDL_FreeSurface(temp); return (-1); } @@ -126,6 +126,9 @@ main(int argc, char *argv[]) int i, done; SDL_Event event; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + if (SDL_CreateWindowAndRenderer(WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer) < 0) { quit(2); } diff --git a/test/teststreaming.c b/test/teststreaming.c index ea3ac2d619325..1d3f68250f092 100644 --- a/test/teststreaming.c +++ b/test/teststreaming.c @@ -68,7 +68,7 @@ void UpdateTexture(SDL_Texture *texture, int frame) int pitch; if (SDL_LockTexture(texture, NULL, &pixels, &pitch) < 0) { - fprintf(stderr, "Couldn't lock texture: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't lock texture: %s\n", SDL_GetError()); quit(5); } src = MooseFrames[frame]; @@ -93,15 +93,18 @@ main(int argc, char **argv) SDL_bool done = SDL_FALSE; int frame; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + if (SDL_Init(SDL_INIT_VIDEO) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return 1; } /* load the moose images */ handle = SDL_RWFromFile("moose.dat", "rb"); if (handle == NULL) { - fprintf(stderr, "Can't find the file moose.dat !\n"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't find the file moose.dat !\n"); quit(2); } SDL_RWread(handle, MooseFrames, MOOSEFRAME_SIZE, MOOSEFRAMES_COUNT); @@ -115,19 +118,19 @@ main(int argc, char **argv) MOOSEPIC_W*4, MOOSEPIC_H*4, SDL_WINDOW_RESIZABLE); if (!window) { - fprintf(stderr, "Couldn't set create window: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create window: %s\n", SDL_GetError()); quit(3); } renderer = SDL_CreateRenderer(window, -1, 0); if (!renderer) { - fprintf(stderr, "Couldn't set create renderer: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create renderer: %s\n", SDL_GetError()); quit(4); } MooseTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, MOOSEPIC_W, MOOSEPIC_H); if (!MooseTexture) { - fprintf(stderr, "Couldn't set create texture: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError()); quit(5); } diff --git a/test/testthread.c b/test/testthread.c index 949e44e3a4f2c..ed9f1f182f42b 100644 --- a/test/testthread.c +++ b/test/testthread.c @@ -34,20 +34,20 @@ int SDLCALL ThreadFunc(void *data) { SDL_TLSSet(tls, "baby thread", NULL); - printf("Started thread %s: My thread id is %lu, thread data = %s\n", + SDL_Log("Started thread %s: My thread id is %lu, thread data = %s\n", (char *) data, SDL_ThreadID(), (const char *)SDL_TLSGet(tls)); while (alive) { - printf("Thread '%s' is alive!\n", (char *) data); + SDL_Log("Thread '%s' is alive!\n", (char *) data); SDL_Delay(1 * 1000); } - printf("Thread '%s' exiting!\n", (char *) data); + SDL_Log("Thread '%s' exiting!\n", (char *) data); return (0); } static void killed(int sig) { - printf("Killed with SIGTERM, waiting 5 seconds to exit\n"); + SDL_Log("Killed with SIGTERM, waiting 5 seconds to exit\n"); SDL_Delay(5 * 1000); alive = 0; quit(0); @@ -58,35 +58,38 @@ main(int argc, char *argv[]) { SDL_Thread *thread; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + /* Load the SDL library */ if (SDL_Init(0) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return (1); } tls = SDL_TLSCreate(); SDL_assert(tls); SDL_TLSSet(tls, "main thread", NULL); - printf("Main thread data initially: %s\n", (const char *)SDL_TLSGet(tls)); + SDL_Log("Main thread data initially: %s\n", (const char *)SDL_TLSGet(tls)); alive = 1; thread = SDL_CreateThread(ThreadFunc, "One", "#1"); if (thread == NULL) { - fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError()); quit(1); } SDL_Delay(5 * 1000); - printf("Waiting for thread #1\n"); + SDL_Log("Waiting for thread #1\n"); alive = 0; SDL_WaitThread(thread, NULL); - printf("Main thread data finally: %s\n", (const char *)SDL_TLSGet(tls)); + SDL_Log("Main thread data finally: %s\n", (const char *)SDL_TLSGet(tls)); alive = 1; signal(SIGTERM, killed); thread = SDL_CreateThread(ThreadFunc, "Two", "#2"); if (thread == NULL) { - fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError()); quit(1); } raise(SIGTERM); diff --git a/test/testtimer.c b/test/testtimer.c index ebc655d10ae9c..ea985e26456d0 100644 --- a/test/testtimer.c +++ b/test/testtimer.c @@ -33,7 +33,7 @@ ticktock(Uint32 interval, void *param) static Uint32 SDLCALL callback(Uint32 interval, void *param) { - printf("Timer %d : param = %d\n", interval, (int) (uintptr_t) param); + SDL_Log("Timer %d : param = %d\n", interval, (int) (uintptr_t) param); return interval; } @@ -45,8 +45,11 @@ main(int argc, char *argv[]) Uint32 start32, now32; Uint64 start, now; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + if (SDL_Init(SDL_INIT_TIMER) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return (1); } @@ -61,7 +64,7 @@ main(int argc, char *argv[]) t1 = SDL_AddTimer(desired, ticktock, NULL); /* Wait 10 seconds */ - printf("Waiting 10 seconds\n"); + SDL_Log("Waiting 10 seconds\n"); SDL_Delay(10 * 1000); /* Stop the timer */ @@ -69,28 +72,27 @@ main(int argc, char *argv[]) /* Print the results */ if (ticks) { - fprintf(stderr, - "Timer resolution: desired = %d ms, actual = %f ms\n", + SDL_Log("Timer resolution: desired = %d ms, actual = %f ms\n", desired, (double) (10 * 1000) / ticks); } /* Test multiple timers */ - printf("Testing multiple timers...\n"); + SDL_Log("Testing multiple timers...\n"); t1 = SDL_AddTimer(100, callback, (void *) 1); if (!t1) - fprintf(stderr, "Could not create timer 1: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Could not create timer 1: %s\n", SDL_GetError()); t2 = SDL_AddTimer(50, callback, (void *) 2); if (!t2) - fprintf(stderr, "Could not create timer 2: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Could not create timer 2: %s\n", SDL_GetError()); t3 = SDL_AddTimer(233, callback, (void *) 3); if (!t3) - fprintf(stderr, "Could not create timer 3: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Could not create timer 3: %s\n", SDL_GetError()); /* Wait 10 seconds */ - printf("Waiting 10 seconds\n"); + SDL_Log("Waiting 10 seconds\n"); SDL_Delay(10 * 1000); - printf("Removing timer 1 and waiting 5 more seconds\n"); + SDL_Log("Removing timer 1 and waiting 5 more seconds\n"); SDL_RemoveTimer(t1); SDL_Delay(5 * 1000); @@ -103,15 +105,15 @@ main(int argc, char *argv[]) ticktock(0, NULL); } now = SDL_GetPerformanceCounter(); - printf("1 million iterations of ticktock took %f ms\n", (double)((now - start)*1000) / SDL_GetPerformanceFrequency()); + SDL_Log("1 million iterations of ticktock took %f ms\n", (double)((now - start)*1000) / SDL_GetPerformanceFrequency()); - printf("Performance counter frequency: %llu\n", (unsigned long long) SDL_GetPerformanceFrequency()); + SDL_Log("Performance counter frequency: %llu\n", (unsigned long long) SDL_GetPerformanceFrequency()); start32 = SDL_GetTicks(); start = SDL_GetPerformanceCounter(); SDL_Delay(1000); now = SDL_GetPerformanceCounter(); now32 = SDL_GetTicks(); - printf("Delay 1 second = %d ms in ticks, %f ms according to performance counter\n", (now32-start32), (double)((now - start)*1000) / SDL_GetPerformanceFrequency()); + SDL_Log("Delay 1 second = %d ms in ticks, %f ms according to performance counter\n", (now32-start32), (double)((now - start)*1000) / SDL_GetPerformanceFrequency()); SDL_Quit(); return (0); diff --git a/test/testver.c b/test/testver.c index ecfcdf35e3a60..cf3a545985167 100644 --- a/test/testver.c +++ b/test/testver.c @@ -26,17 +26,20 @@ main(int argc, char *argv[]) SDL_version compiled; SDL_version linked; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + #if SDL_VERSION_ATLEAST(2, 0, 0) - printf("Compiled with SDL 2.0 or newer\n"); + SDL_Log("Compiled with SDL 2.0 or newer\n"); #else - printf("Compiled with SDL older than 2.0\n"); + SDL_Log("Compiled with SDL older than 2.0\n"); #endif SDL_VERSION(&compiled); - printf("Compiled version: %d.%d.%d.%d (%s)\n", + SDL_Log("Compiled version: %d.%d.%d.%d (%s)\n", compiled.major, compiled.minor, compiled.patch, SDL_REVISION_NUMBER, SDL_REVISION); SDL_GetVersion(&linked); - printf("Linked version: %d.%d.%d.%d (%s)\n", + SDL_Log("Linked version: %d.%d.%d.%d (%s)\n", linked.major, linked.minor, linked.patch, SDL_GetRevisionNumber(), SDL_GetRevision()); SDL_Quit(); diff --git a/test/testwm2.c b/test/testwm2.c index efe6ea4dd12fa..241f826f83006 100644 --- a/test/testwm2.c +++ b/test/testwm2.c @@ -48,6 +48,9 @@ main(int argc, char *argv[]) int system_cursor = -1; SDL_Cursor *cursor = NULL; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + SDL_assert(SDL_arraysize(cursorNames) == SDL_NUM_SYSTEM_CURSORS); /* Initialize test framework */ @@ -64,7 +67,7 @@ main(int argc, char *argv[]) consumed = -1; } if (consumed < 0) { - fprintf(stderr, "Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state)); + SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state)); quit(1); } i += consumed; @@ -84,7 +87,7 @@ main(int argc, char *argv[]) if (event.window.event == SDL_WINDOWEVENT_RESIZED) { SDL_Window *window = SDL_GetWindowFromID(event.window.windowID); if (window) { - printf("Window %d resized to %dx%d\n", + SDL_Log("Window %d resized to %dx%d\n", event.window.windowID, event.window.data1, event.window.data2); @@ -93,7 +96,7 @@ main(int argc, char *argv[]) if (event.window.event == SDL_WINDOWEVENT_MOVED) { SDL_Window *window = SDL_GetWindowFromID(event.window.windowID); if (window) { - printf("Window %d moved to %d,%d (display %s)\n", + SDL_Log("Window %d moved to %d,%d (display %s)\n", event.window.windowID, event.window.data1, event.window.data2, diff --git a/test/torturethread.c b/test/torturethread.c index 795b60b935855..53a57a9b0dc33 100644 --- a/test/torturethread.c +++ b/test/torturethread.c @@ -49,7 +49,7 @@ ThreadFunc(void *data) int i; int tid = (int) (uintptr_t) data; - fprintf(stderr, "Creating Thread %d\n", tid); + SDL_Log("Creating Thread %d\n", tid); for (i = 0; i < NUMTHREADS; i++) { char name[64]; @@ -58,18 +58,18 @@ ThreadFunc(void *data) sub_threads[i] = SDL_CreateThread(SubThreadFunc, name, &flags[i]); } - printf("Thread '%d' waiting for signal\n", tid); + SDL_Log("Thread '%d' waiting for signal\n", tid); while (time_for_threads_to_die[tid] != 1) { ; /* do nothing */ } - printf("Thread '%d' sending signals to subthreads\n", tid); + SDL_Log("Thread '%d' sending signals to subthreads\n", tid); for (i = 0; i < NUMTHREADS; i++) { flags[i] = 1; SDL_WaitThread(sub_threads[i], NULL); } - printf("Thread '%d' exiting!\n", tid); + SDL_Log("Thread '%d' exiting!\n", tid); return 0; } @@ -80,9 +80,12 @@ main(int argc, char *argv[]) SDL_Thread *threads[NUMTHREADS]; int i; + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + /* Load the SDL library */ if (SDL_Init(0) < 0) { - fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return (1); } @@ -94,7 +97,7 @@ main(int argc, char *argv[]) threads[i] = SDL_CreateThread(ThreadFunc, name, (void*) (uintptr_t) i); if (threads[i] == NULL) { - fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError()); quit(1); } }