Mercurial > sdl-ios-xcode
annotate test/testfile.c @ 4120:d07c60f5e460 SDL-1.2
Fixed bug #478
Take the min and max values into account.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 29 Dec 2007 19:44:02 +0000 |
parents | f86ced1837de |
children |
rev | line source |
---|---|
1453
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 /* 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
|
3 |
1484
b2b476a4a73c
Added documentation on how to build a completely useless SDL library. :)
Sam Lantinga <slouken@libsdl.org>
parents:
1454
diff
changeset
|
4 #include <stdlib.h> |
3927
f86ced1837de
Patched to compile on Visual Studio.
Ryan C. Gordon <icculus@icculus.org>
parents:
1843
diff
changeset
|
5 |
f86ced1837de
Patched to compile on Visual Studio.
Ryan C. Gordon <icculus@icculus.org>
parents:
1843
diff
changeset
|
6 #ifndef _MSC_VER |
1843
c2c327e8e781
Needed unistd.h for unlink()
Sam Lantinga <slouken@libsdl.org>
parents:
1484
diff
changeset
|
7 #include <unistd.h> |
3927
f86ced1837de
Patched to compile on Visual Studio.
Ryan C. Gordon <icculus@icculus.org>
parents:
1843
diff
changeset
|
8 #endif |
1453
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 #include "SDL.h" |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 #include "SDL_endian.h" |
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 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 #include <stdio.h> |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 /* WARNING ! those 2 files will be destroyed by this test program */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 #define FBASENAME1 "sdldata1" /* this file will be created during tests */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 #define FBASENAME2 "sdldata2" /* this file should not exists before starting test */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 #ifndef NULL |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 #define NULL ((void *)0) |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 #endif |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 static void cleanup( void ) { |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 unlink(FBASENAME1); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 unlink(FBASENAME2); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 } |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 static void rwops_error_quit( unsigned line, SDL_RWops *rwops) { |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 printf("testfile.c(%d): failed\n",line); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 if (rwops) { |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 rwops->close(rwops); /* This calls SDL_FreeRW(rwops); */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 } |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 cleanup(); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 exit(1); /* quit with rwops error (test failed) */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 } |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 #define RWOP_ERR_QUIT(x) rwops_error_quit( __LINE__, (x) ) |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 int main(int argc, char *argv[]) |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 { |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 SDL_RWops *rwops = NULL; |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 char test_buf[30]; |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 cleanup(); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 /* test 1 : basic argument test: all those calls to SDL_RWFromFile should fail */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 rwops = SDL_RWFromFile(NULL,NULL); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 if (rwops) RWOP_ERR_QUIT(rwops); |
1454 | 56 rwops = SDL_RWFromFile(NULL,"ab+"); |
1453
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 if (rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 rwops = SDL_RWFromFile(NULL,"sldfkjsldkfj"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 if (rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 rwops = SDL_RWFromFile("something",""); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 if (rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 rwops = SDL_RWFromFile("something",NULL); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 if (rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 printf("test1 OK\n"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 /* test 2 : check that inexistant file is not successfully opened/created when required */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 /* modes : r, r+ implie that file MUST exist |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 modes : a, a+, w, w+ checks that it succeeds (file may not exists) |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 rwops = SDL_RWFromFile(FBASENAME2,"rb"); /* this file doesn't exist that call must fail */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 if (rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 rwops = SDL_RWFromFile(FBASENAME2,"rb+"); /* this file doesn't exist that call must fail */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 if (rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 rwops = SDL_RWFromFile(FBASENAME2,"wb"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 if (!rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 rwops->close(rwops); unlink(FBASENAME2); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 rwops = SDL_RWFromFile(FBASENAME2,"wb+"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 if (!rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 rwops->close(rwops); unlink(FBASENAME2); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 rwops = SDL_RWFromFile(FBASENAME2,"ab"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 if (!rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 rwops->close(rwops); unlink(FBASENAME2); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 rwops = SDL_RWFromFile(FBASENAME2,"ab+"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 if (!rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 rwops->close(rwops); unlink(FBASENAME2); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 printf("test2 OK\n"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 /* test 3 : creation, writing , reading, seeking, |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 test : w mode, r mode, w+ mode |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 rwops = SDL_RWFromFile(FBASENAME1,"wb"); /* write only */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 if (!rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 if (1 != rwops->write(rwops,"1234567890",10,1) ) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 if (10 != rwops->write(rwops,"1234567890",1,10) ) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 if (7 != rwops->write(rwops,"1234567",1,7) ) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 if (0!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); /* we are in write only mode */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 rwops->close(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 rwops = SDL_RWFromFile(FBASENAME1,"rb"); /* read mode, file must exists */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 if (!rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 if (20!=rwops->seek(rwops,-7,RW_SEEK_END)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 if (7!=rwops->read(rwops,test_buf,1,7)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 if (SDL_memcmp(test_buf,"1234567",7)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 if (0!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 if (0!=rwops->read(rwops,test_buf,10,100)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 if (0!=rwops->seek(rwops,-27,RW_SEEK_CUR)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 if (2!=rwops->read(rwops,test_buf,10,3)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 if (SDL_memcmp(test_buf,"12345678901234567890",20)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 if (0!=rwops->write(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); /* readonly mode */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 rwops->close(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 /* test 3: same with w+ mode */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 rwops = SDL_RWFromFile(FBASENAME1,"wb+"); /* write + read + truncation */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 if (!rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 if (1 != rwops->write(rwops,"1234567890",10,1) ) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 if (10 != rwops->write(rwops,"1234567890",1,10) ) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 if (7 != rwops->write(rwops,"1234567",1,7) ) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 if (1!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); /* we are in read/write mode */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 if (20!=rwops->seek(rwops,-7,RW_SEEK_END)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 if (7!=rwops->read(rwops,test_buf,1,7)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
126 if (SDL_memcmp(test_buf,"1234567",7)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 if (0!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 if (0!=rwops->read(rwops,test_buf,10,100)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 if (0!=rwops->seek(rwops,-27,RW_SEEK_CUR)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 if (2!=rwops->read(rwops,test_buf,10,3)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 if (SDL_memcmp(test_buf,"12345678901234567890",20)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 rwops->close(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 printf("test3 OK\n"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 /* test 4: same in r+ mode */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 rwops = SDL_RWFromFile(FBASENAME1,"rb+"); /* write + read + file must exists, no truncation */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 if (!rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 if (1 != rwops->write(rwops,"1234567890",10,1) ) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 if (10 != rwops->write(rwops,"1234567890",1,10) ) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 if (7 != rwops->write(rwops,"1234567",1,7) ) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 if (1!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); /* we are in read/write mode */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 if (20!=rwops->seek(rwops,-7,RW_SEEK_END)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 if (7!=rwops->read(rwops,test_buf,1,7)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 if (SDL_memcmp(test_buf,"1234567",7)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 if (0!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 if (0!=rwops->read(rwops,test_buf,10,100)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 if (0!=rwops->seek(rwops,-27,RW_SEEK_CUR)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 if (2!=rwops->read(rwops,test_buf,10,3)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 if (SDL_memcmp(test_buf,"12345678901234567890",20)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 rwops->close(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 printf("test4 OK\n"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 /* test5 : append mode */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 rwops = SDL_RWFromFile(FBASENAME1,"ab+"); /* write + read + append */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 if (!rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 if (1 != rwops->write(rwops,"1234567890",10,1) ) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 if (10 != rwops->write(rwops,"1234567890",1,10) ) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 if (7 != rwops->write(rwops,"1234567",1,7) ) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 if (1!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
165 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
166 if (20+27!=rwops->seek(rwops,-7,RW_SEEK_END)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 if (7!=rwops->read(rwops,test_buf,1,7)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 if (SDL_memcmp(test_buf,"1234567",7)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
169 if (0!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
170 if (0!=rwops->read(rwops,test_buf,10,100)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
171 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 if (27!=rwops->seek(rwops,-27,RW_SEEK_CUR)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
173 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 if (3!=rwops->read(rwops,test_buf,10,3)) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 if (SDL_memcmp(test_buf,"123456789012345678901234567123",30)) |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 rwops->close(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
179 printf("test5 OK\n"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 cleanup(); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
181 return 0; /* all ok */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
182 } |