mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-28 07:29:09 +00:00
test: Add some common code to load test resources
As well as reducing duplication, this lets the tests load their resources from the SDL_GetBasePath() on platforms that support it, which is useful if the tests are compiled along with the rest of SDL and installed below /usr as manual tests, similar to GNOME's installed-tests convention. Thanks to Ozkan Sezer for the OS/2 build glue. Co-authored-by: Ozkan Sezer <sezeroz@gmail.com> Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
parent
ecf1e15fec
commit
76a7b629bf
31 changed files with 344 additions and 508 deletions
|
@ -25,6 +25,8 @@
|
|||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#include "testutils.h"
|
||||
|
||||
static struct
|
||||
{
|
||||
SDL_AudioSpec spec;
|
||||
|
@ -74,7 +76,7 @@ loop()
|
|||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char filename[4096];
|
||||
char *filename = NULL;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
@ -85,11 +87,13 @@ main(int argc, char *argv[])
|
|||
return (1);
|
||||
}
|
||||
|
||||
if (argc > 1) {
|
||||
SDL_strlcpy(filename, argv[1], sizeof(filename));
|
||||
} else {
|
||||
SDL_strlcpy(filename, "sample.wav", sizeof(filename));
|
||||
filename = GetResourceFilename(argc > 1 ? argv[1] : NULL, "sample.wav");
|
||||
|
||||
if (filename == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError());
|
||||
quit(1);
|
||||
}
|
||||
|
||||
/* Load the wave file into memory */
|
||||
if (SDL_LoadWAV(filename, &wave.spec, &wave.sound, &wave.soundlen) == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError());
|
||||
|
@ -142,6 +146,7 @@ main(int argc, char *argv[])
|
|||
/* Clean up on signal */
|
||||
SDL_CloseAudio();
|
||||
SDL_FreeWAV(wave.sound);
|
||||
SDL_free(filename);
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue