2015-06-21 23:33:46 +08:00
|
|
|
/*
|
2024-01-02 05:15:26 +08:00
|
|
|
Copyright (C) 1997-2024 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.
|
|
|
|
*/
|
|
|
|
|
2024-03-15 11:30:59 +08:00
|
|
|
/* sanity tests on SDL_iostream.c (useful for alternative implementations of stdio iostream) */
|
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 */
|
|
|
|
|
2024-01-24 09:40:51 +08:00
|
|
|
#ifdef SDL_PLATFORM_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
|
2024-03-15 07:32:50 +08:00
|
|
|
iostrm_error_quit(unsigned line, SDL_IOStream *iostrm)
|
2015-06-21 23:33:46 +08:00
|
|
|
{
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "testfile.c(%d): failed\n", line);
|
2024-03-15 07:32:50 +08:00
|
|
|
if (iostrm) {
|
|
|
|
SDL_CloseIO(iostrm);
|
2015-06-21 23:33:46 +08:00
|
|
|
}
|
|
|
|
cleanup();
|
2023-03-17 07:25:39 +08:00
|
|
|
SDLTest_CommonDestroyState(state);
|
2024-03-15 07:32:50 +08:00
|
|
|
exit(1); /* quit with iostrm error (test failed) */
|
2015-06-21 23:33:46 +08:00
|
|
|
}
|
|
|
|
|
2024-03-15 07:32:50 +08:00
|
|
|
#define RWOP_ERR_QUIT(x) iostrm_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
|
|
|
{
|
2024-03-15 07:32:50 +08:00
|
|
|
SDL_IOStream *iostrm = NULL;
|
2015-06-21 23:33:46 +08:00
|
|
|
char test_buf[30];
|
|
|
|
|
2023-03-17 07:25:39 +08:00
|
|
|
/* Initialize test framework */
|
|
|
|
state = SDLTest_CommonCreateState(argv, 0);
|
2023-11-10 05:29:15 +08:00
|
|
|
if (!state) {
|
2023-03-17 07:25:39 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-06-21 23:33:46 +08:00
|
|
|
/* Enable standard application logging */
|
2024-05-17 01:00:50 +08:00
|
|
|
SDL_SetLogPriority(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();
|
|
|
|
|
2024-03-15 07:32:50 +08:00
|
|
|
/* test 1 : basic argument test: all those calls to SDL_IOFromFile should fail */
|
2015-06-21 23:33:46 +08:00
|
|
|
|
2024-03-15 07:32:50 +08:00
|
|
|
iostrm = SDL_IOFromFile(NULL, NULL);
|
|
|
|
if (iostrm) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
iostrm = SDL_IOFromFile(NULL, "ab+");
|
|
|
|
if (iostrm) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
iostrm = SDL_IOFromFile(NULL, "sldfkjsldkfj");
|
|
|
|
if (iostrm) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
iostrm = SDL_IOFromFile("something", "");
|
|
|
|
if (iostrm) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
iostrm = SDL_IOFromFile("something", NULL);
|
|
|
|
if (iostrm) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
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
|
|
|
*/
|
2024-03-15 07:32:50 +08:00
|
|
|
iostrm = SDL_IOFromFile(FBASENAME2, "rb"); /* this file doesn't exist that call must fail */
|
|
|
|
if (iostrm) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
iostrm = SDL_IOFromFile(FBASENAME2, "rb+"); /* this file doesn't exist that call must fail */
|
|
|
|
if (iostrm) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
iostrm = SDL_IOFromFile(FBASENAME2, "wb");
|
|
|
|
if (!iostrm) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
SDL_CloseIO(iostrm);
|
2015-06-21 23:33:46 +08:00
|
|
|
unlink(FBASENAME2);
|
2024-03-15 07:32:50 +08:00
|
|
|
iostrm = SDL_IOFromFile(FBASENAME2, "wb+");
|
|
|
|
if (!iostrm) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
SDL_CloseIO(iostrm);
|
2015-06-21 23:33:46 +08:00
|
|
|
unlink(FBASENAME2);
|
2024-03-15 07:32:50 +08:00
|
|
|
iostrm = SDL_IOFromFile(FBASENAME2, "ab");
|
|
|
|
if (!iostrm) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
SDL_CloseIO(iostrm);
|
2015-06-21 23:33:46 +08:00
|
|
|
unlink(FBASENAME2);
|
2024-03-15 07:32:50 +08:00
|
|
|
iostrm = SDL_IOFromFile(FBASENAME2, "ab+");
|
|
|
|
if (!iostrm) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
SDL_CloseIO(iostrm);
|
2015-06-21 23:33:46 +08:00
|
|
|
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
|
|
|
|
*/
|
2024-03-15 07:32:50 +08:00
|
|
|
iostrm = SDL_IOFromFile(FBASENAME1, "wb"); /* write only */
|
|
|
|
if (!iostrm) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (10 != SDL_WriteIO(iostrm, "1234567890", 10)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (10 != SDL_WriteIO(iostrm, "1234567890", 10)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (7 != SDL_WriteIO(iostrm, "1234567", 7)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (0 != SDL_SeekIO(iostrm, 0L, SDL_IO_SEEK_SET)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (0 != SDL_ReadIO(iostrm, test_buf, 1)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm); /* we are in write only mode */
|
2022-12-01 04:51:59 +08:00
|
|
|
}
|
2022-11-28 00:38:43 +08:00
|
|
|
|
2024-03-15 07:32:50 +08:00
|
|
|
SDL_CloseIO(iostrm);
|
2015-06-21 23:33:46 +08:00
|
|
|
|
2024-03-15 07:32:50 +08:00
|
|
|
iostrm = SDL_IOFromFile(FBASENAME1, "rb"); /* read mode, file must exist */
|
|
|
|
if (!iostrm) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (0 != SDL_SeekIO(iostrm, 0L, SDL_IO_SEEK_SET)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (20 != SDL_SeekIO(iostrm, -7, SDL_IO_SEEK_END)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (7 != SDL_ReadIO(iostrm, test_buf, 7)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-02 05:07:03 +08:00
|
|
|
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
|
2024-03-15 07:32:50 +08:00
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (0 != SDL_ReadIO(iostrm, test_buf, 1)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (0 != SDL_ReadIO(iostrm, test_buf, 1000)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (0 != SDL_SeekIO(iostrm, -27, SDL_IO_SEEK_CUR)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (27 != SDL_ReadIO(iostrm, test_buf, 30)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-02 05:07:03 +08:00
|
|
|
if (SDL_memcmp(test_buf, "12345678901234567890", 20) != 0) {
|
2024-03-15 07:32:50 +08:00
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (0 != SDL_WriteIO(iostrm, test_buf, 1)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm); /* readonly mode */
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
|
|
|
|
2024-03-15 07:32:50 +08:00
|
|
|
SDL_CloseIO(iostrm);
|
2015-06-21 23:33:46 +08:00
|
|
|
|
2022-12-01 04:51:59 +08:00
|
|
|
/* test 3: same with w+ mode */
|
2024-03-15 07:32:50 +08:00
|
|
|
iostrm = SDL_IOFromFile(FBASENAME1, "wb+"); /* write + read + truncation */
|
|
|
|
if (!iostrm) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (10 != SDL_WriteIO(iostrm, "1234567890", 10)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (10 != SDL_WriteIO(iostrm, "1234567890", 10)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (7 != SDL_WriteIO(iostrm, "1234567", 7)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (0 != SDL_SeekIO(iostrm, 0L, SDL_IO_SEEK_SET)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (1 != SDL_ReadIO(iostrm, test_buf, 1)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm); /* we are in read/write mode */
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
|
|
|
|
2024-03-15 07:32:50 +08:00
|
|
|
if (0 != SDL_SeekIO(iostrm, 0L, SDL_IO_SEEK_SET)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (20 != SDL_SeekIO(iostrm, -7, SDL_IO_SEEK_END)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (7 != SDL_ReadIO(iostrm, test_buf, 7)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-02 05:07:03 +08:00
|
|
|
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
|
2024-03-15 07:32:50 +08:00
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (0 != SDL_ReadIO(iostrm, test_buf, 1)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (0 != SDL_ReadIO(iostrm, test_buf, 1000)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (0 != SDL_SeekIO(iostrm, -27, SDL_IO_SEEK_CUR)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (27 != SDL_ReadIO(iostrm, test_buf, 30)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-02 05:07:03 +08:00
|
|
|
if (SDL_memcmp(test_buf, "12345678901234567890", 20) != 0) {
|
2024-03-15 07:32:50 +08:00
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
SDL_CloseIO(iostrm);
|
2015-06-21 23:33:46 +08:00
|
|
|
SDL_Log("test3 OK\n");
|
|
|
|
|
2022-12-01 04:51:59 +08:00
|
|
|
/* test 4: same in r+ mode */
|
2024-03-15 07:32:50 +08:00
|
|
|
iostrm = SDL_IOFromFile(FBASENAME1, "rb+"); /* write + read + file must exists, no truncation */
|
|
|
|
if (!iostrm) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (10 != SDL_WriteIO(iostrm, "1234567890", 10)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (10 != SDL_WriteIO(iostrm, "1234567890", 10)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (7 != SDL_WriteIO(iostrm, "1234567", 7)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (0 != SDL_SeekIO(iostrm, 0L, SDL_IO_SEEK_SET)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (1 != SDL_ReadIO(iostrm, test_buf, 1)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm); /* we are in read/write mode */
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
|
|
|
|
2024-03-15 07:32:50 +08:00
|
|
|
if (0 != SDL_SeekIO(iostrm, 0L, SDL_IO_SEEK_SET)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (20 != SDL_SeekIO(iostrm, -7, SDL_IO_SEEK_END)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (7 != SDL_ReadIO(iostrm, test_buf, 7)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-02 05:07:03 +08:00
|
|
|
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
|
2024-03-15 07:32:50 +08:00
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (0 != SDL_ReadIO(iostrm, test_buf, 1)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (0 != SDL_ReadIO(iostrm, test_buf, 1000)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (0 != SDL_SeekIO(iostrm, -27, SDL_IO_SEEK_CUR)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (27 != SDL_ReadIO(iostrm, test_buf, 30)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-02 05:07:03 +08:00
|
|
|
if (SDL_memcmp(test_buf, "12345678901234567890", 20) != 0) {
|
2024-03-15 07:32:50 +08:00
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
SDL_CloseIO(iostrm);
|
2015-06-21 23:33:46 +08:00
|
|
|
SDL_Log("test4 OK\n");
|
|
|
|
|
2022-12-01 04:51:59 +08:00
|
|
|
/* test5 : append mode */
|
2024-03-15 07:32:50 +08:00
|
|
|
iostrm = SDL_IOFromFile(FBASENAME1, "ab+"); /* write + read + append */
|
|
|
|
if (!iostrm) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (10 != SDL_WriteIO(iostrm, "1234567890", 10)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (10 != SDL_WriteIO(iostrm, "1234567890", 10)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (7 != SDL_WriteIO(iostrm, "1234567", 7)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (0 != SDL_SeekIO(iostrm, 0L, SDL_IO_SEEK_SET)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
|
2024-03-15 07:32:50 +08:00
|
|
|
if (1 != SDL_ReadIO(iostrm, test_buf, 1)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (0 != SDL_SeekIO(iostrm, 0L, SDL_IO_SEEK_SET)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
|
2024-03-15 07:32:50 +08:00
|
|
|
if (20 + 27 != SDL_SeekIO(iostrm, -7, SDL_IO_SEEK_END)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (7 != SDL_ReadIO(iostrm, test_buf, 7)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-02 05:07:03 +08:00
|
|
|
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
|
2024-03-15 07:32:50 +08:00
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (0 != SDL_ReadIO(iostrm, test_buf, 1)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (0 != SDL_ReadIO(iostrm, test_buf, 1000)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
|
2024-03-15 07:32:50 +08:00
|
|
|
if (27 != SDL_SeekIO(iostrm, -27, SDL_IO_SEEK_CUR)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
|
2024-03-15 07:32:50 +08:00
|
|
|
if (0 != SDL_SeekIO(iostrm, 0L, SDL_IO_SEEK_SET)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
if (30 != SDL_ReadIO(iostrm, test_buf, 30)) {
|
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2022-12-02 05:07:03 +08:00
|
|
|
if (SDL_memcmp(test_buf, "123456789012345678901234567123", 30) != 0) {
|
2024-03-15 07:32:50 +08:00
|
|
|
RWOP_ERR_QUIT(iostrm);
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2024-03-15 07:32:50 +08:00
|
|
|
SDL_CloseIO(iostrm);
|
2015-06-21 23:33:46 +08:00
|
|
|
SDL_Log("test5 OK\n");
|
|
|
|
cleanup();
|
2023-08-23 00:44:28 +08:00
|
|
|
SDL_Quit();
|
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
|
|
|
}
|