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:
Simon McVittie
2022-04-12 13:07:18 +01:00
committed by Sam Lantinga
parent ecf1e15fec
commit 76a7b629bf
31 changed files with 344 additions and 508 deletions

View File

@@ -16,6 +16,7 @@
#include <time.h> /* for time() */
#include "testnative.h"
#include "testutils.h"
#define WINDOW_W 640
#define WINDOW_H 480
@@ -52,37 +53,6 @@ quit(int rc)
exit(rc);
}
SDL_Texture *
LoadSprite(SDL_Renderer *renderer, const char *file)
{
SDL_Surface *temp;
SDL_Texture *sprite;
/* Load the sprite image */
temp = SDL_LoadBMP(file);
if (temp == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
return 0;
}
/* Set transparent pixel as the pixel at (0,0) */
if (temp->format->palette) {
SDL_SetColorKey(temp, 1, *(Uint8 *) temp->pixels);
}
/* Create textures from the image */
sprite = SDL_CreateTextureFromSurface(renderer, temp);
if (!sprite) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp);
return 0;
}
SDL_FreeSurface(temp);
/* We're ready to roll. :) */
return sprite;
}
void
MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
{
@@ -180,7 +150,7 @@ main(int argc, char *argv[])
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderClear(renderer);
sprite = LoadSprite(renderer, "icon.bmp");
sprite = LoadTexture(renderer, "icon.bmp", SDL_TRUE, NULL, NULL);
if (!sprite) {
quit(6);
}