test/testfile.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 12 Aug 2016 19:59:00 -0400
changeset 10266 c09f06c4e8c8
parent 9998 f67cf37e9cd4
permissions -rw-r--r--
emscripten: send fake mouse events for touches, like other targets do. (This really should be handled at the higher level and not in the individual targets, but this fixes the immediate bug.)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
     1
/*
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9922
diff changeset
     2
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
     3
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
     4
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
     5
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
     6
  arising from the use of this software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
     7
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
     8
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
     9
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
    10
  freely.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
    11
*/
1453
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    13
/* sanity tests on SDL_rwops.c (usefull for alternative implementations of stdio rwops) */
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    14
7663
53fe1b64eb2d More non C89 compliant comments
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7639
diff changeset
    15
/* quiet windows compiler warnings */
4884
27ab20a36eba - added directx include path to VS2008 solution
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 2765
diff changeset
    16
#define _CRT_NONSTDC_NO_WARNINGS
27ab20a36eba - added directx include path to VS2008 solution
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 2765
diff changeset
    17
1484
b2b476a4a73c Added documentation on how to build a completely useless SDL library. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1454
diff changeset
    18
#include <stdlib.h>
2099
891ed60fcaa9 Merged r2999:3000 from branches/SDL-1.2: Visual Studio compilation fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
    19
891ed60fcaa9 Merged r2999:3000 from branches/SDL-1.2: Visual Studio compilation fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
    20
#ifndef _MSC_VER
1843
c2c327e8e781 Needed unistd.h for unlink()
Sam Lantinga <slouken@libsdl.org>
parents: 1484
diff changeset
    21
#include <unistd.h>
2099
891ed60fcaa9 Merged r2999:3000 from branches/SDL-1.2: Visual Studio compilation fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
    22
#endif
1453
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
#include "SDL.h"
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    27
#include <stdio.h>
1453
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
/* WARNING ! those 2 files will be destroyed by this test program */
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2099
diff changeset
    30
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2099
diff changeset
    31
#ifdef __IPHONEOS__
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    32
#define FBASENAME1  "../Documents/sdldata1" /* this file will be created during tests */
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2099
diff changeset
    33
#define FBASENAME2  "../Documents/sdldata2"     /* this file should not exist before starting test */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2099
diff changeset
    34
#else
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    35
#define FBASENAME1  "sdldata1"      /* this file will be created during tests */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    36
#define FBASENAME2  "sdldata2"      /* this file should not exist before starting test */
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2099
diff changeset
    37
#endif
1453
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
#ifndef NULL
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
#define NULL ((void *)0)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    41
#endif
1453
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    43
static void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    44
cleanup(void)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    45
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    46
    unlink(FBASENAME1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    47
    unlink(FBASENAME2);
1453
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
}
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    50
static void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    51
rwops_error_quit(unsigned line, SDL_RWops * rwops)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    52
{
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7538
diff changeset
    53
    SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "testfile.c(%d): failed\n", line);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    54
    if (rwops) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    55
        rwops->close(rwops);    /* This calls SDL_FreeRW(rwops); */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    56
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    57
    cleanup();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    58
    exit(1);                    /* quit with rwops error (test failed) */
1453
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
}
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    61
#define RWOP_ERR_QUIT(x)    rwops_error_quit( __LINE__, (x) )
1453
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    65
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    66
main(int argc, char *argv[])
1453
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    68
    SDL_RWops *rwops = NULL;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    69
    char test_buf[30];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    70
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7538
diff changeset
    71
    /* Enable standard application logging */
9922
b066d5fd5fa7 Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9619
diff changeset
    72
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7538
diff changeset
    73
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    74
    cleanup();
1453
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
/* test 1 : basic argument test: all those calls to SDL_RWFromFile should fail */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    77
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    78
    rwops = SDL_RWFromFile(NULL, NULL);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    79
    if (rwops)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    80
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    81
    rwops = SDL_RWFromFile(NULL, "ab+");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    82
    if (rwops)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    83
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    84
    rwops = SDL_RWFromFile(NULL, "sldfkjsldkfj");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    85
    if (rwops)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    86
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    87
    rwops = SDL_RWFromFile("something", "");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    88
    if (rwops)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    89
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    90
    rwops = SDL_RWFromFile("something", NULL);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    91
    if (rwops)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
    92
        RWOP_ERR_QUIT(rwops);
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7538
diff changeset
    93
    SDL_Log("test1 OK\n");
1453
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
7538
1d187795e103 Corrected words in comments of test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7517
diff changeset
    95
/* test 2 : check that inexistent file is not successfully opened/created when required */
1d187795e103 Corrected words in comments of test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7517
diff changeset
    96
/* modes : r, r+ imply that file MUST exist
1453
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
   modes : a, a+, w, w+ checks that it succeeds (file may not exists)
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    98
1453
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   100
    rwops = SDL_RWFromFile(FBASENAME2, "rb");   /* this file doesn't exist that call must fail */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   101
    if (rwops)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   102
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   103
    rwops = SDL_RWFromFile(FBASENAME2, "rb+");  /* this file doesn't exist that call must fail */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   104
    if (rwops)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   105
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   106
    rwops = SDL_RWFromFile(FBASENAME2, "wb");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   107
    if (!rwops)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   108
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   109
    rwops->close(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   110
    unlink(FBASENAME2);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   111
    rwops = SDL_RWFromFile(FBASENAME2, "wb+");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   112
    if (!rwops)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   113
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   114
    rwops->close(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   115
    unlink(FBASENAME2);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   116
    rwops = SDL_RWFromFile(FBASENAME2, "ab");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   117
    if (!rwops)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   118
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   119
    rwops->close(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   120
    unlink(FBASENAME2);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   121
    rwops = SDL_RWFromFile(FBASENAME2, "ab+");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   122
    if (!rwops)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   123
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   124
    rwops->close(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   125
    unlink(FBASENAME2);
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7538
diff changeset
   126
    SDL_Log("test2 OK\n");
1453
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   128
/* test 3 : creation, writing , reading, seeking,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   129
            test : w mode, r mode, w+ mode
1453
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   131
    rwops = SDL_RWFromFile(FBASENAME1, "wb");   /* write only */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   132
    if (!rwops)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   133
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   134
    if (1 != rwops->write(rwops, "1234567890", 10, 1))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   135
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   136
    if (10 != rwops->write(rwops, "1234567890", 1, 10))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   137
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   138
    if (7 != rwops->write(rwops, "1234567", 1, 7))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   139
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   140
    if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   141
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   142
    if (0 != rwops->read(rwops, test_buf, 1, 1))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   143
        RWOP_ERR_QUIT(rwops);   /* we are in write only mode */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   144
    rwops->close(rwops);
1453
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   146
    rwops = SDL_RWFromFile(FBASENAME1, "rb");   /* read mode, file must exists */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   147
    if (!rwops)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   148
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   149
    if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   150
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   151
    if (20 != rwops->seek(rwops, -7, RW_SEEK_END))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   152
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   153
    if (7 != rwops->read(rwops, test_buf, 1, 7))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   154
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   155
    if (SDL_memcmp(test_buf, "1234567", 7))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   156
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   157
    if (0 != rwops->read(rwops, test_buf, 1, 1))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   158
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   159
    if (0 != rwops->read(rwops, test_buf, 10, 100))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   160
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   161
    if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   162
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   163
    if (2 != rwops->read(rwops, test_buf, 10, 3))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   164
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   165
    if (SDL_memcmp(test_buf, "12345678901234567890", 20))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   166
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   167
    if (0 != rwops->write(rwops, test_buf, 1, 1))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   168
        RWOP_ERR_QUIT(rwops);   /* readonly mode */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   169
    rwops->close(rwops);
1453
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   170
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
/* test 3: same with w+ mode */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   172
    rwops = SDL_RWFromFile(FBASENAME1, "wb+");  /* write + read + truncation */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   173
    if (!rwops)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   174
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   175
    if (1 != rwops->write(rwops, "1234567890", 10, 1))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   176
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   177
    if (10 != rwops->write(rwops, "1234567890", 1, 10))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   178
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   179
    if (7 != rwops->write(rwops, "1234567", 1, 7))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   180
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   181
    if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   182
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   183
    if (1 != rwops->read(rwops, test_buf, 1, 1))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   184
        RWOP_ERR_QUIT(rwops);   /* we are in read/write mode */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   185
    if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   186
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   187
    if (20 != rwops->seek(rwops, -7, RW_SEEK_END))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   188
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   189
    if (7 != rwops->read(rwops, test_buf, 1, 7))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   190
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   191
    if (SDL_memcmp(test_buf, "1234567", 7))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   192
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   193
    if (0 != rwops->read(rwops, test_buf, 1, 1))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   194
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   195
    if (0 != rwops->read(rwops, test_buf, 10, 100))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   196
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   197
    if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   198
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   199
    if (2 != rwops->read(rwops, test_buf, 10, 3))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   200
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   201
    if (SDL_memcmp(test_buf, "12345678901234567890", 20))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   202
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   203
    rwops->close(rwops);
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7538
diff changeset
   204
    SDL_Log("test3 OK\n");
1453
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   205
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   206
/* test 4: same in r+ mode */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   207
    rwops = SDL_RWFromFile(FBASENAME1, "rb+");  /* write + read + file must exists, no truncation */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   208
    if (!rwops)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   209
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   210
    if (1 != rwops->write(rwops, "1234567890", 10, 1))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   211
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   212
    if (10 != rwops->write(rwops, "1234567890", 1, 10))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   213
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   214
    if (7 != rwops->write(rwops, "1234567", 1, 7))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   215
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   216
    if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   217
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   218
    if (1 != rwops->read(rwops, test_buf, 1, 1))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   219
        RWOP_ERR_QUIT(rwops);   /* we are in read/write mode */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   220
    if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   221
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   222
    if (20 != rwops->seek(rwops, -7, RW_SEEK_END))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   223
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   224
    if (7 != rwops->read(rwops, test_buf, 1, 7))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   225
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   226
    if (SDL_memcmp(test_buf, "1234567", 7))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   227
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   228
    if (0 != rwops->read(rwops, test_buf, 1, 1))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   229
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   230
    if (0 != rwops->read(rwops, test_buf, 10, 100))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   231
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   232
    if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   233
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   234
    if (2 != rwops->read(rwops, test_buf, 10, 3))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   235
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   236
    if (SDL_memcmp(test_buf, "12345678901234567890", 20))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   237
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   238
    rwops->close(rwops);
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7538
diff changeset
   239
    SDL_Log("test4 OK\n");
1453
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   240
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   241
/* test5 : append mode */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   242
    rwops = SDL_RWFromFile(FBASENAME1, "ab+");  /* write + read + append */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   243
    if (!rwops)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   244
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   245
    if (1 != rwops->write(rwops, "1234567890", 10, 1))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   246
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   247
    if (10 != rwops->write(rwops, "1234567890", 1, 10))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   248
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   249
    if (7 != rwops->write(rwops, "1234567", 1, 7))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   250
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   251
    if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   252
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   253
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   254
    if (1 != rwops->read(rwops, test_buf, 1, 1))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   255
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   256
    if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   257
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   258
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   259
    if (20 + 27 != rwops->seek(rwops, -7, RW_SEEK_END))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   260
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   261
    if (7 != rwops->read(rwops, test_buf, 1, 7))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   262
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   263
    if (SDL_memcmp(test_buf, "1234567", 7))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   264
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   265
    if (0 != rwops->read(rwops, test_buf, 1, 1))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   266
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   267
    if (0 != rwops->read(rwops, test_buf, 10, 100))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   268
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   269
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   270
    if (27 != rwops->seek(rwops, -27, RW_SEEK_CUR))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   271
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   272
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   273
    if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   274
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   275
    if (3 != rwops->read(rwops, test_buf, 10, 3))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   276
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   277
    if (SDL_memcmp(test_buf, "123456789012345678901234567123", 30))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   278
        RWOP_ERR_QUIT(rwops);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   279
    rwops->close(rwops);
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7538
diff changeset
   280
    SDL_Log("test5 OK\n");
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   281
    cleanup();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1843
diff changeset
   282
    return 0;                   /* all ok */
1453
2eb75f8a32ca Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   283
}