Mercurial > sdl-ios-xcode
annotate test/testfile.c @ 1510:720f8bb49d7d
Win32 fixes
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 13 Mar 2006 02:06:33 +0000 |
parents | b2b476a4a73c |
children | 14717b52abc0 |
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> |
1453
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 #include "SDL.h" |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 #include "SDL_endian.h" |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 |
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 <stdio.h> |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 /* 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
|
13 #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
|
14 #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
|
15 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 #ifndef NULL |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 #define NULL ((void *)0) |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 #endif |
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 static void cleanup( void ) { |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 unlink(FBASENAME1); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 unlink(FBASENAME2); |
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 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 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
|
28 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 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
|
30 if (rwops) { |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 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
|
32 } |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 cleanup(); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 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
|
35 } |
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 #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
|
38 |
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 int main(int argc, char *argv[]) |
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 SDL_RWops *rwops = NULL; |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 char test_buf[30]; |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 cleanup(); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 /* 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
|
49 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 rwops = SDL_RWFromFile(NULL,NULL); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 if (rwops) RWOP_ERR_QUIT(rwops); |
1454 | 52 rwops = SDL_RWFromFile(NULL,"ab+"); |
1453
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 if (rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 rwops = SDL_RWFromFile(NULL,"sldfkjsldkfj"); |
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); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 rwops = SDL_RWFromFile("something",""); |
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("something",NULL); |
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 printf("test1 OK\n"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 /* 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
|
63 /* 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
|
64 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
|
65 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 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
|
68 if (rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 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
|
70 if (rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 rwops = SDL_RWFromFile(FBASENAME2,"wb"); |
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->close(rwops); unlink(FBASENAME2); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 rwops = SDL_RWFromFile(FBASENAME2,"wb+"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 if (!rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 rwops->close(rwops); unlink(FBASENAME2); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 rwops = SDL_RWFromFile(FBASENAME2,"ab"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 if (!rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 rwops->close(rwops); unlink(FBASENAME2); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 rwops = SDL_RWFromFile(FBASENAME2,"ab+"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 if (!rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 rwops->close(rwops); unlink(FBASENAME2); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 printf("test2 OK\n"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 /* test 3 : creation, writing , reading, seeking, |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 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
|
87 */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 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
|
89 if (!rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 rwops->close(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 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
|
98 if (!rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 rwops->close(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 /* test 3: same with w+ mode */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 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
|
113 if (!rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 rwops->close(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 printf("test3 OK\n"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 /* test 4: same in r+ mode */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 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
|
133 if (!rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 rwops->close(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 printf("test4 OK\n"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 /* test5 : append mode */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 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
|
153 if (!rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 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
|
155 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
|
156 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
|
157 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
|
158 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 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
|
160 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
|
161 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 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
|
169 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
170 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
|
171 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
|
172 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
|
173 RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 rwops->close(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 printf("test5 OK\n"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 cleanup(); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 return 0; /* all ok */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 } |