2015-06-21 23:33:46 +08:00
|
|
|
/*
|
2023-01-10 01:41:41 +08:00
|
|
|
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
2015-06-21 23:33:46 +08:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely.
|
|
|
|
*/
|
|
|
|
|
2023-07-03 23:29:42 +08:00
|
|
|
/* sanity tests on SDL_rwops.c (useful for alternative implementations of stdio rwops) */
|
2015-06-21 23:33:46 +08:00
|
|
|
|
|
|
|
/* quiet windows compiler warnings */
|
2022-12-05 05:35:20 +08:00
|
|
|
#if defined(_MSC_VER) && !defined(_CRT_NONSTDC_NO_WARNINGS)
|
2015-06-21 23:33:46 +08:00
|
|
|
#define _CRT_NONSTDC_NO_WARNINGS
|
2022-12-05 05:35:20 +08:00
|
|
|
#endif
|
2015-06-21 23:33:46 +08:00
|
|
|
|
2022-11-26 17:41:46 +08:00
|
|
|
#include <stdio.h>
|
2015-06-21 23:33:46 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#ifndef _MSC_VER
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2022-11-27 12:43:38 +08:00
|
|
|
#include <SDL3/SDL.h>
|
2022-12-15 12:58:20 +08:00
|
|
|
#include <SDL3/SDL_main.h>
|
2023-03-17 07:25:39 +08:00
|
|
|
#include <SDL3/SDL_test.h>
|
2015-06-21 23:33:46 +08:00
|
|
|
|
|
|
|
/* WARNING ! those 2 files will be destroyed by this test program */
|
|
|
|
|
2022-11-26 08:00:06 +08:00
|
|
|
#ifdef __IOS__
|
2022-12-01 04:51:59 +08:00
|
|
|
#define FBASENAME1 "../Documents/sdldata1" /* this file will be created during tests */
|
|
|
|
#define FBASENAME2 "../Documents/sdldata2" /* this file should not exist before starting test */
|
2015-06-21 23:33:46 +08:00
|
|
|
#else
|
2022-12-01 04:51:59 +08:00
|
|
|
#define FBASENAME1 "sdldata1" /* this file will be created during tests */
|
|
|
|
#define FBASENAME2 "sdldata2" /* this file should not exist before starting test */
|
2015-06-21 23:33:46 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef NULL
|
|
|
|
#define NULL ((void *)0)
|
|
|
|
#endif
|
|
|
|
|
2023-03-17 07:25:39 +08:00
|
|
|
static SDLTest_CommonState *state;
|
|
|
|
|
2015-06-21 23:33:46 +08:00
|
|
|
static void
|
|
|
|
cleanup(void)
|
|
|
|
{
|
|
|
|
unlink(FBASENAME1);
|
|
|
|
unlink(FBASENAME2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-12-01 04:51:59 +08:00
|
|
|
rwops_error_quit(unsigned line, SDL_RWops *rwops)
|
2015-06-21 23:33:46 +08:00
|
|
|
{
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "testfile.c(%d): failed\n", line);
|
|
|
|
if (rwops) {
|
2022-12-30 07:07:59 +08:00
|
|
|
rwops->close(rwops); /* This calls SDL_DestroyRW(rwops); */
|
2015-06-21 23:33:46 +08:00
|
|
|
}
|
|
|
|
cleanup();
|
2023-03-17 07:25:39 +08:00
|
|
|
SDLTest_CommonDestroyState(state);
|
2022-12-01 04:51:59 +08:00
|
|
|
exit(1); /* quit with rwops error (test failed) */
|
2015-06-21 23:33:46 +08:00
|
|
|
}
|
|
|
|
|
2022-12-01 04:51:59 +08:00
|
|
|
#define RWOP_ERR_QUIT(x) rwops_error_quit(__LINE__, (x))
|
2015-06-21 23:33:46 +08:00
|
|
|
|
2022-12-01 04:51:59 +08:00
|
|
|
int main(int argc, char *argv[])
|
2015-06-21 23:33:46 +08:00
|
|
|
{
|
|
|
|
SDL_RWops *rwops = NULL;
|
|
|
|
char test_buf[30];
|
|
|
|
|
2023-03-17 07:25:39 +08:00
|
|
|
/* Initialize test framework */
|
|
|
|
state = SDLTest_CommonCreateState(argv, 0);
|
|
|
|
if (state == NULL) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-06-21 23:33:46 +08:00
|
|
|
/* Enable standard application logging */
|
2015-11-26 04:39:28 +08:00
|
|
|
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
2015-06-21 23:33:46 +08:00
|
|
|
|
2023-03-17 07:25:39 +08:00
|
|
|
/* Parse commandline */
|
|
|
|
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-06-21 23:33:46 +08:00
|
|
|
cleanup();
|
|
|
|
|
2022-12-01 04:51:59 +08:00
|
|
|
/* test 1 : basic argument test: all those calls to SDL_RWFromFile should fail */
|
2015-06-21 23:33:46 +08:00
|
|
|
|
|
|
|
rwops = SDL_RWFromFile(NULL, NULL);
|
2022-11-28 00:38:43 +08:00
|
|
|
if (rwops) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
rwops = SDL_RWFromFile(NULL, "ab+");
|
2022-11-28 00:38:43 +08:00
|
|
|
if (rwops) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
rwops = SDL_RWFromFile(NULL, "sldfkjsldkfj");
|
2022-11-28 00:38:43 +08:00
|
|
|
if (rwops) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
rwops = SDL_RWFromFile("something", "");
|
2022-11-28 00:38:43 +08:00
|
|
|
if (rwops) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
rwops = SDL_RWFromFile("something", NULL);
|
2022-11-28 00:38:43 +08:00
|
|
|
if (rwops) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
SDL_Log("test1 OK\n");
|
|
|
|
|
2022-12-01 04:51:59 +08:00
|
|
|
/* 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)
|
2015-06-21 23:33:46 +08:00
|
|
|
|
2022-12-01 04:51:59 +08:00
|
|
|
*/
|
|
|
|
rwops = SDL_RWFromFile(FBASENAME2, "rb"); /* this file doesn't exist that call must fail */
|
2022-11-28 00:38:43 +08:00
|
|
|
if (rwops) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-01 04:51:59 +08:00
|
|
|
rwops = SDL_RWFromFile(FBASENAME2, "rb+"); /* this file doesn't exist that call must fail */
|
2022-11-28 00:38:43 +08:00
|
|
|
if (rwops) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
rwops = SDL_RWFromFile(FBASENAME2, "wb");
|
2022-11-28 00:38:43 +08:00
|
|
|
if (rwops == NULL) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
rwops->close(rwops);
|
|
|
|
unlink(FBASENAME2);
|
|
|
|
rwops = SDL_RWFromFile(FBASENAME2, "wb+");
|
2022-11-28 00:38:43 +08:00
|
|
|
if (rwops == NULL) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
rwops->close(rwops);
|
|
|
|
unlink(FBASENAME2);
|
|
|
|
rwops = SDL_RWFromFile(FBASENAME2, "ab");
|
2022-11-28 00:38:43 +08:00
|
|
|
if (rwops == NULL) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
rwops->close(rwops);
|
|
|
|
unlink(FBASENAME2);
|
|
|
|
rwops = SDL_RWFromFile(FBASENAME2, "ab+");
|
2022-11-28 00:38:43 +08:00
|
|
|
if (rwops == NULL) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
rwops->close(rwops);
|
|
|
|
unlink(FBASENAME2);
|
|
|
|
SDL_Log("test2 OK\n");
|
|
|
|
|
2022-12-01 04:51:59 +08:00
|
|
|
/* test 3 : creation, writing , reading, seeking,
|
|
|
|
test : w mode, r mode, w+ mode
|
|
|
|
*/
|
|
|
|
rwops = SDL_RWFromFile(FBASENAME1, "wb"); /* write only */
|
2022-11-28 00:38:43 +08:00
|
|
|
if (rwops == NULL) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (10 != rwops->write(rwops, "1234567890", 10)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (10 != rwops->write(rwops, "1234567890", 10)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (7 != rwops->write(rwops, "1234567", 7)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-23 17:16:11 +08:00
|
|
|
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2023-03-17 10:50:08 +08:00
|
|
|
if (-1 != rwops->read(rwops, test_buf, 1)) {
|
2022-11-28 00:38:43 +08:00
|
|
|
RWOP_ERR_QUIT(rwops); /* we are in write only mode */
|
2022-12-01 04:51:59 +08:00
|
|
|
}
|
2022-11-28 00:38:43 +08:00
|
|
|
|
2015-06-21 23:33:46 +08:00
|
|
|
rwops->close(rwops);
|
|
|
|
|
2023-03-17 10:50:08 +08:00
|
|
|
rwops = SDL_RWFromFile(FBASENAME1, "rb"); /* read mode, file must exist */
|
2022-11-28 00:38:43 +08:00
|
|
|
if (rwops == NULL) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-23 17:16:11 +08:00
|
|
|
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-23 17:16:11 +08:00
|
|
|
if (20 != rwops->seek(rwops, -7, SDL_RW_SEEK_END)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (7 != rwops->read(rwops, test_buf, 7)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-02 05:07:03 +08:00
|
|
|
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (0 != rwops->read(rwops, test_buf, 1)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (0 != rwops->read(rwops, test_buf, 1000)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-23 17:16:11 +08:00
|
|
|
if (0 != rwops->seek(rwops, -27, SDL_RW_SEEK_CUR)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2023-03-17 10:50:08 +08:00
|
|
|
if (27 != rwops->read(rwops, test_buf, 30)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-02 05:07:03 +08:00
|
|
|
if (SDL_memcmp(test_buf, "12345678901234567890", 20) != 0) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2023-03-17 10:50:08 +08:00
|
|
|
if (-1 != rwops->write(rwops, test_buf, 1)) {
|
2022-11-28 00:38:43 +08:00
|
|
|
RWOP_ERR_QUIT(rwops); /* readonly mode */
|
|
|
|
}
|
|
|
|
|
2015-06-21 23:33:46 +08:00
|
|
|
rwops->close(rwops);
|
|
|
|
|
2022-12-01 04:51:59 +08:00
|
|
|
/* test 3: same with w+ mode */
|
|
|
|
rwops = SDL_RWFromFile(FBASENAME1, "wb+"); /* write + read + truncation */
|
2022-11-28 00:38:43 +08:00
|
|
|
if (rwops == NULL) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (10 != rwops->write(rwops, "1234567890", 10)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (10 != rwops->write(rwops, "1234567890", 10)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (7 != rwops->write(rwops, "1234567", 7)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-23 17:16:11 +08:00
|
|
|
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (1 != rwops->read(rwops, test_buf, 1)) {
|
2022-11-28 00:38:43 +08:00
|
|
|
RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
|
|
|
|
}
|
|
|
|
|
2022-12-23 17:16:11 +08:00
|
|
|
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-23 17:16:11 +08:00
|
|
|
if (20 != rwops->seek(rwops, -7, SDL_RW_SEEK_END)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (7 != rwops->read(rwops, test_buf, 7)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-02 05:07:03 +08:00
|
|
|
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (0 != rwops->read(rwops, test_buf, 1)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (0 != rwops->read(rwops, test_buf, 1000)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-23 17:16:11 +08:00
|
|
|
if (0 != rwops->seek(rwops, -27, SDL_RW_SEEK_CUR)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2023-03-17 10:50:08 +08:00
|
|
|
if (27 != rwops->read(rwops, test_buf, 30)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-02 05:07:03 +08:00
|
|
|
if (SDL_memcmp(test_buf, "12345678901234567890", 20) != 0) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
rwops->close(rwops);
|
|
|
|
SDL_Log("test3 OK\n");
|
|
|
|
|
2022-12-01 04:51:59 +08:00
|
|
|
/* test 4: same in r+ mode */
|
|
|
|
rwops = SDL_RWFromFile(FBASENAME1, "rb+"); /* write + read + file must exists, no truncation */
|
2022-11-28 00:38:43 +08:00
|
|
|
if (rwops == NULL) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (10 != rwops->write(rwops, "1234567890", 10)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (10 != rwops->write(rwops, "1234567890", 10)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (7 != rwops->write(rwops, "1234567", 7)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-23 17:16:11 +08:00
|
|
|
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (1 != rwops->read(rwops, test_buf, 1)) {
|
2022-11-28 00:38:43 +08:00
|
|
|
RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
|
|
|
|
}
|
|
|
|
|
2022-12-23 17:16:11 +08:00
|
|
|
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-23 17:16:11 +08:00
|
|
|
if (20 != rwops->seek(rwops, -7, SDL_RW_SEEK_END)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (7 != rwops->read(rwops, test_buf, 7)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-02 05:07:03 +08:00
|
|
|
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (0 != rwops->read(rwops, test_buf, 1)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (0 != rwops->read(rwops, test_buf, 1000)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-23 17:16:11 +08:00
|
|
|
if (0 != rwops->seek(rwops, -27, SDL_RW_SEEK_CUR)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2023-03-17 10:50:08 +08:00
|
|
|
if (27 != rwops->read(rwops, test_buf, 30)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-02 05:07:03 +08:00
|
|
|
if (SDL_memcmp(test_buf, "12345678901234567890", 20) != 0) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
rwops->close(rwops);
|
|
|
|
SDL_Log("test4 OK\n");
|
|
|
|
|
2022-12-01 04:51:59 +08:00
|
|
|
/* test5 : append mode */
|
|
|
|
rwops = SDL_RWFromFile(FBASENAME1, "ab+"); /* write + read + append */
|
2022-11-28 00:38:43 +08:00
|
|
|
if (rwops == NULL) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (10 != rwops->write(rwops, "1234567890", 10)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (10 != rwops->write(rwops, "1234567890", 10)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (7 != rwops->write(rwops, "1234567", 7)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-23 17:16:11 +08:00
|
|
|
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
|
2022-12-15 12:24:56 +08:00
|
|
|
if (1 != rwops->read(rwops, test_buf, 1)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-23 17:16:11 +08:00
|
|
|
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
|
2022-12-23 17:16:11 +08:00
|
|
|
if (20 + 27 != rwops->seek(rwops, -7, SDL_RW_SEEK_END)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (7 != rwops->read(rwops, test_buf, 7)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-02 05:07:03 +08:00
|
|
|
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (0 != rwops->read(rwops, test_buf, 1)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-15 12:24:56 +08:00
|
|
|
if (0 != rwops->read(rwops, test_buf, 1000)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
|
2022-12-23 17:16:11 +08:00
|
|
|
if (27 != rwops->seek(rwops, -27, SDL_RW_SEEK_CUR)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
|
2022-12-23 17:16:11 +08:00
|
|
|
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2023-03-17 10:50:08 +08:00
|
|
|
if (30 != rwops->read(rwops, test_buf, 30)) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-02 05:07:03 +08:00
|
|
|
if (SDL_memcmp(test_buf, "123456789012345678901234567123", 30) != 0) {
|
2015-06-21 23:33:46 +08:00
|
|
|
RWOP_ERR_QUIT(rwops);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
rwops->close(rwops);
|
|
|
|
SDL_Log("test5 OK\n");
|
|
|
|
cleanup();
|
2023-03-17 07:25:39 +08:00
|
|
|
SDLTest_CommonDestroyState(state);
|
2022-12-01 04:51:59 +08:00
|
|
|
return 0; /* all ok */
|
2015-06-21 23:33:46 +08:00
|
|
|
}
|