Update SDL2 to version 2.28.1.

This commit is contained in:
Sasha Szpakowski
2023-08-31 22:21:03 -03:00
parent 99b2757fc5
commit a82fcdd079
1394 changed files with 313046 additions and 190617 deletions
+186 -112
View File
@@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -13,27 +13,26 @@
/* sanity tests on SDL_rwops.c (usefull for alternative implementations of stdio rwops) */
/* quiet windows compiler warnings */
#if defined(_MSC_VER) && !defined(_CRT_NONSTDC_NO_WARNINGS)
#define _CRT_NONSTDC_NO_WARNINGS
#endif
#include <stdio.h>
#include <stdlib.h>
#ifndef _MSC_VER
#include <unistd.h>
#endif
#include "SDL.h"
#include <stdio.h>
/* WARNING ! those 2 files will be destroyed by this test program */
#ifdef __IPHONEOS__
#define FBASENAME1 "../Documents/sdldata1" /* this file will be created during tests */
#define FBASENAME2 "../Documents/sdldata2" /* this file should not exist before starting test */
#else
#define FBASENAME1 "sdldata1" /* this file will be created during tests */
#define FBASENAME2 "sdldata2" /* this file should not exist before starting test */
#define FBASENAME1 "sdldata1" /* this file will be created during tests */
#define FBASENAME2 "sdldata2" /* this file should not exist before starting test */
#endif
#ifndef NULL
@@ -48,22 +47,19 @@ cleanup(void)
}
static void
rwops_error_quit(unsigned line, SDL_RWops * rwops)
rwops_error_quit(unsigned line, SDL_RWops *rwops)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "testfile.c(%d): failed\n", line);
if (rwops) {
rwops->close(rwops); /* This calls SDL_FreeRW(rwops); */
rwops->close(rwops); /* This calls SDL_FreeRW(rwops); */
}
cleanup();
exit(1); /* quit with rwops error (test failed) */
exit(1); /* quit with rwops error (test failed) */
}
#define RWOP_ERR_QUIT(x) rwops_error_quit( __LINE__, (x) )
#define RWOP_ERR_QUIT(x) rwops_error_quit(__LINE__, (x))
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
SDL_RWops *rwops = NULL;
char test_buf[30];
@@ -73,211 +69,289 @@ main(int argc, char *argv[])
cleanup();
/* test 1 : basic argument test: all those calls to SDL_RWFromFile should fail */
/* test 1 : basic argument test: all those calls to SDL_RWFromFile should fail */
rwops = SDL_RWFromFile(NULL, NULL);
if (rwops)
if (rwops) {
RWOP_ERR_QUIT(rwops);
}
rwops = SDL_RWFromFile(NULL, "ab+");
if (rwops)
if (rwops) {
RWOP_ERR_QUIT(rwops);
}
rwops = SDL_RWFromFile(NULL, "sldfkjsldkfj");
if (rwops)
if (rwops) {
RWOP_ERR_QUIT(rwops);
}
rwops = SDL_RWFromFile("something", "");
if (rwops)
if (rwops) {
RWOP_ERR_QUIT(rwops);
}
rwops = SDL_RWFromFile("something", NULL);
if (rwops)
if (rwops) {
RWOP_ERR_QUIT(rwops);
}
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
modes : a, a+, w, w+ checks that it succeeds (file may not exists)
/* test 2 : check that inexistent file is not successfully opened/created when required */
/* modes : r, r+ imply that file MUST exist
modes : a, a+, w, w+ checks that it succeeds (file may not exists)
*/
rwops = SDL_RWFromFile(FBASENAME2, "rb"); /* this file doesn't exist that call must fail */
if (rwops)
*/
rwops = SDL_RWFromFile(FBASENAME2, "rb"); /* this file doesn't exist that call must fail */
if (rwops) {
RWOP_ERR_QUIT(rwops);
rwops = SDL_RWFromFile(FBASENAME2, "rb+"); /* this file doesn't exist that call must fail */
if (rwops)
}
rwops = SDL_RWFromFile(FBASENAME2, "rb+"); /* this file doesn't exist that call must fail */
if (rwops) {
RWOP_ERR_QUIT(rwops);
}
rwops = SDL_RWFromFile(FBASENAME2, "wb");
if (!rwops)
if (rwops == NULL) {
RWOP_ERR_QUIT(rwops);
}
rwops->close(rwops);
unlink(FBASENAME2);
rwops = SDL_RWFromFile(FBASENAME2, "wb+");
if (!rwops)
if (rwops == NULL) {
RWOP_ERR_QUIT(rwops);
}
rwops->close(rwops);
unlink(FBASENAME2);
rwops = SDL_RWFromFile(FBASENAME2, "ab");
if (!rwops)
if (rwops == NULL) {
RWOP_ERR_QUIT(rwops);
}
rwops->close(rwops);
unlink(FBASENAME2);
rwops = SDL_RWFromFile(FBASENAME2, "ab+");
if (!rwops)
if (rwops == NULL) {
RWOP_ERR_QUIT(rwops);
}
rwops->close(rwops);
unlink(FBASENAME2);
SDL_Log("test2 OK\n");
/* test 3 : creation, writing , reading, seeking,
test : w mode, r mode, w+ mode
*/
rwops = SDL_RWFromFile(FBASENAME1, "wb"); /* write only */
if (!rwops)
/* test 3 : creation, writing , reading, seeking,
test : w mode, r mode, w+ mode
*/
rwops = SDL_RWFromFile(FBASENAME1, "wb"); /* write only */
if (rwops == NULL) {
RWOP_ERR_QUIT(rwops);
if (1 != rwops->write(rwops, "1234567890", 10, 1))
}
if (1 != rwops->write(rwops, "1234567890", 10, 1)) {
RWOP_ERR_QUIT(rwops);
if (10 != rwops->write(rwops, "1234567890", 1, 10))
}
if (10 != rwops->write(rwops, "1234567890", 1, 10)) {
RWOP_ERR_QUIT(rwops);
if (7 != rwops->write(rwops, "1234567", 1, 7))
}
if (7 != rwops->write(rwops, "1234567", 1, 7)) {
RWOP_ERR_QUIT(rwops);
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
}
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
RWOP_ERR_QUIT(rwops);
if (0 != rwops->read(rwops, test_buf, 1, 1))
RWOP_ERR_QUIT(rwops); /* we are in write only mode */
}
if (0 != rwops->read(rwops, test_buf, 1, 1)) {
RWOP_ERR_QUIT(rwops); /* we are in write only mode */
}
rwops->close(rwops);
rwops = SDL_RWFromFile(FBASENAME1, "rb"); /* read mode, file must exists */
if (!rwops)
rwops = SDL_RWFromFile(FBASENAME1, "rb"); /* read mode, file must exists */
if (rwops == NULL) {
RWOP_ERR_QUIT(rwops);
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
}
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
RWOP_ERR_QUIT(rwops);
if (20 != rwops->seek(rwops, -7, RW_SEEK_END))
}
if (20 != rwops->seek(rwops, -7, RW_SEEK_END)) {
RWOP_ERR_QUIT(rwops);
if (7 != rwops->read(rwops, test_buf, 1, 7))
}
if (7 != rwops->read(rwops, test_buf, 1, 7)) {
RWOP_ERR_QUIT(rwops);
if (SDL_memcmp(test_buf, "1234567", 7))
}
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
RWOP_ERR_QUIT(rwops);
if (0 != rwops->read(rwops, test_buf, 1, 1))
}
if (0 != rwops->read(rwops, test_buf, 1, 1)) {
RWOP_ERR_QUIT(rwops);
if (0 != rwops->read(rwops, test_buf, 10, 100))
}
if (0 != rwops->read(rwops, test_buf, 10, 100)) {
RWOP_ERR_QUIT(rwops);
if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR))
}
if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR)) {
RWOP_ERR_QUIT(rwops);
if (2 != rwops->read(rwops, test_buf, 10, 3))
}
if (2 != rwops->read(rwops, test_buf, 10, 3)) {
RWOP_ERR_QUIT(rwops);
if (SDL_memcmp(test_buf, "12345678901234567890", 20))
}
if (SDL_memcmp(test_buf, "12345678901234567890", 20) != 0) {
RWOP_ERR_QUIT(rwops);
if (0 != rwops->write(rwops, test_buf, 1, 1))
RWOP_ERR_QUIT(rwops); /* readonly mode */
}
if (0 != rwops->write(rwops, test_buf, 1, 1)) {
RWOP_ERR_QUIT(rwops); /* readonly mode */
}
rwops->close(rwops);
/* test 3: same with w+ mode */
rwops = SDL_RWFromFile(FBASENAME1, "wb+"); /* write + read + truncation */
if (!rwops)
/* test 3: same with w+ mode */
rwops = SDL_RWFromFile(FBASENAME1, "wb+"); /* write + read + truncation */
if (rwops == NULL) {
RWOP_ERR_QUIT(rwops);
if (1 != rwops->write(rwops, "1234567890", 10, 1))
}
if (1 != rwops->write(rwops, "1234567890", 10, 1)) {
RWOP_ERR_QUIT(rwops);
if (10 != rwops->write(rwops, "1234567890", 1, 10))
}
if (10 != rwops->write(rwops, "1234567890", 1, 10)) {
RWOP_ERR_QUIT(rwops);
if (7 != rwops->write(rwops, "1234567", 1, 7))
}
if (7 != rwops->write(rwops, "1234567", 1, 7)) {
RWOP_ERR_QUIT(rwops);
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
}
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
RWOP_ERR_QUIT(rwops);
if (1 != rwops->read(rwops, test_buf, 1, 1))
RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
}
if (1 != rwops->read(rwops, test_buf, 1, 1)) {
RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
}
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
RWOP_ERR_QUIT(rwops);
if (20 != rwops->seek(rwops, -7, RW_SEEK_END))
}
if (20 != rwops->seek(rwops, -7, RW_SEEK_END)) {
RWOP_ERR_QUIT(rwops);
if (7 != rwops->read(rwops, test_buf, 1, 7))
}
if (7 != rwops->read(rwops, test_buf, 1, 7)) {
RWOP_ERR_QUIT(rwops);
if (SDL_memcmp(test_buf, "1234567", 7))
}
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
RWOP_ERR_QUIT(rwops);
if (0 != rwops->read(rwops, test_buf, 1, 1))
}
if (0 != rwops->read(rwops, test_buf, 1, 1)) {
RWOP_ERR_QUIT(rwops);
if (0 != rwops->read(rwops, test_buf, 10, 100))
}
if (0 != rwops->read(rwops, test_buf, 10, 100)) {
RWOP_ERR_QUIT(rwops);
if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR))
}
if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR)) {
RWOP_ERR_QUIT(rwops);
if (2 != rwops->read(rwops, test_buf, 10, 3))
}
if (2 != rwops->read(rwops, test_buf, 10, 3)) {
RWOP_ERR_QUIT(rwops);
if (SDL_memcmp(test_buf, "12345678901234567890", 20))
}
if (SDL_memcmp(test_buf, "12345678901234567890", 20) != 0) {
RWOP_ERR_QUIT(rwops);
}
rwops->close(rwops);
SDL_Log("test3 OK\n");
/* test 4: same in r+ mode */
rwops = SDL_RWFromFile(FBASENAME1, "rb+"); /* write + read + file must exists, no truncation */
if (!rwops)
/* test 4: same in r+ mode */
rwops = SDL_RWFromFile(FBASENAME1, "rb+"); /* write + read + file must exists, no truncation */
if (rwops == NULL) {
RWOP_ERR_QUIT(rwops);
if (1 != rwops->write(rwops, "1234567890", 10, 1))
}
if (1 != rwops->write(rwops, "1234567890", 10, 1)) {
RWOP_ERR_QUIT(rwops);
if (10 != rwops->write(rwops, "1234567890", 1, 10))
}
if (10 != rwops->write(rwops, "1234567890", 1, 10)) {
RWOP_ERR_QUIT(rwops);
if (7 != rwops->write(rwops, "1234567", 1, 7))
}
if (7 != rwops->write(rwops, "1234567", 1, 7)) {
RWOP_ERR_QUIT(rwops);
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
}
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
RWOP_ERR_QUIT(rwops);
if (1 != rwops->read(rwops, test_buf, 1, 1))
RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
}
if (1 != rwops->read(rwops, test_buf, 1, 1)) {
RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
}
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
RWOP_ERR_QUIT(rwops);
if (20 != rwops->seek(rwops, -7, RW_SEEK_END))
}
if (20 != rwops->seek(rwops, -7, RW_SEEK_END)) {
RWOP_ERR_QUIT(rwops);
if (7 != rwops->read(rwops, test_buf, 1, 7))
}
if (7 != rwops->read(rwops, test_buf, 1, 7)) {
RWOP_ERR_QUIT(rwops);
if (SDL_memcmp(test_buf, "1234567", 7))
}
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
RWOP_ERR_QUIT(rwops);
if (0 != rwops->read(rwops, test_buf, 1, 1))
}
if (0 != rwops->read(rwops, test_buf, 1, 1)) {
RWOP_ERR_QUIT(rwops);
if (0 != rwops->read(rwops, test_buf, 10, 100))
}
if (0 != rwops->read(rwops, test_buf, 10, 100)) {
RWOP_ERR_QUIT(rwops);
if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR))
}
if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR)) {
RWOP_ERR_QUIT(rwops);
if (2 != rwops->read(rwops, test_buf, 10, 3))
}
if (2 != rwops->read(rwops, test_buf, 10, 3)) {
RWOP_ERR_QUIT(rwops);
if (SDL_memcmp(test_buf, "12345678901234567890", 20))
}
if (SDL_memcmp(test_buf, "12345678901234567890", 20) != 0) {
RWOP_ERR_QUIT(rwops);
}
rwops->close(rwops);
SDL_Log("test4 OK\n");
/* test5 : append mode */
rwops = SDL_RWFromFile(FBASENAME1, "ab+"); /* write + read + append */
if (!rwops)
/* test5 : append mode */
rwops = SDL_RWFromFile(FBASENAME1, "ab+"); /* write + read + append */
if (rwops == NULL) {
RWOP_ERR_QUIT(rwops);
if (1 != rwops->write(rwops, "1234567890", 10, 1))
}
if (1 != rwops->write(rwops, "1234567890", 10, 1)) {
RWOP_ERR_QUIT(rwops);
if (10 != rwops->write(rwops, "1234567890", 1, 10))
}
if (10 != rwops->write(rwops, "1234567890", 1, 10)) {
RWOP_ERR_QUIT(rwops);
if (7 != rwops->write(rwops, "1234567", 1, 7))
}
if (7 != rwops->write(rwops, "1234567", 1, 7)) {
RWOP_ERR_QUIT(rwops);
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
}
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
RWOP_ERR_QUIT(rwops);
}
if (1 != rwops->read(rwops, test_buf, 1, 1))
if (1 != rwops->read(rwops, test_buf, 1, 1)) {
RWOP_ERR_QUIT(rwops);
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
}
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
RWOP_ERR_QUIT(rwops);
}
if (20 + 27 != rwops->seek(rwops, -7, RW_SEEK_END))
if (20 + 27 != rwops->seek(rwops, -7, RW_SEEK_END)) {
RWOP_ERR_QUIT(rwops);
if (7 != rwops->read(rwops, test_buf, 1, 7))
}
if (7 != rwops->read(rwops, test_buf, 1, 7)) {
RWOP_ERR_QUIT(rwops);
if (SDL_memcmp(test_buf, "1234567", 7))
}
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
RWOP_ERR_QUIT(rwops);
if (0 != rwops->read(rwops, test_buf, 1, 1))
}
if (0 != rwops->read(rwops, test_buf, 1, 1)) {
RWOP_ERR_QUIT(rwops);
if (0 != rwops->read(rwops, test_buf, 10, 100))
}
if (0 != rwops->read(rwops, test_buf, 10, 100)) {
RWOP_ERR_QUIT(rwops);
}
if (27 != rwops->seek(rwops, -27, RW_SEEK_CUR))
if (27 != rwops->seek(rwops, -27, RW_SEEK_CUR)) {
RWOP_ERR_QUIT(rwops);
}
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
RWOP_ERR_QUIT(rwops);
if (3 != rwops->read(rwops, test_buf, 10, 3))
}
if (3 != rwops->read(rwops, test_buf, 10, 3)) {
RWOP_ERR_QUIT(rwops);
if (SDL_memcmp(test_buf, "123456789012345678901234567123", 30))
}
if (SDL_memcmp(test_buf, "123456789012345678901234567123", 30) != 0) {
RWOP_ERR_QUIT(rwops);
}
rwops->close(rwops);
SDL_Log("test5 OK\n");
cleanup();
return 0; /* all ok */
return 0; /* all ok */
}