Mercurial > sdl-ios-xcode
annotate test/testfile.c @ 3899:081aecdb0911 SDL-1.2
From: Gabriel Gambetta
To: SDL Mailing List <sdl@libsdl.org>
Date: Fri, 17 Nov 2006 00:39:29 -0200
Subject: [SDL] Alpha blending bug - fixed?
It turns out mm5 never got the correct value. This failed :
[...]
"movd %1, %%mm5\n\t"
: : "m" (amask), "m" (sf->Ashift) );
mm5 got 0xFF000018 instead of 0x00000018. However I did this :
Uint32 ashift = sf->Ashift;
[...]
"movd %1, %%mm5\n\t"
: : "m" (amask), "m" (ashift) );
and everything worked fine.
The only thing I could find out was that ashift is 32-bit aligned but
sf->Ashift isn't:
printf("ashift %8X [%d]\n", &ashift, (int)(&ashift) % 4);
printf("sf->Ashift %8X [%d]\n", &sf->Ashift, (int)(&sf->Ashift) % 4);
ashift at BFF0E0C4 [0]
sf->Ashift at 08AFB9CD [1]
Could this be the problem? If it is, the fix is extremely trivial.
Should I submit a patch?
--Gabriel
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Tue, 21 Nov 2006 23:17:00 +0000 |
parents | c2c327e8e781 |
children | 782fd950bd46 c121d94672cb f86ced1837de |
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> |
1843
c2c327e8e781
Needed unistd.h for unlink()
Sam Lantinga <slouken@libsdl.org>
parents:
1484
diff
changeset
|
5 #include <unistd.h> |
1453
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 #include "SDL.h" |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 #include "SDL_endian.h" |
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 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 #include <stdio.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 /* 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
|
14 #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
|
15 #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
|
16 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 #ifndef NULL |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 #define NULL ((void *)0) |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 #endif |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 static void cleanup( void ) { |
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 unlink(FBASENAME1); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 unlink(FBASENAME2); |
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 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 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
|
29 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 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
|
31 if (rwops) { |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 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
|
33 } |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 cleanup(); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 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
|
36 } |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 #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
|
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 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 int main(int argc, char *argv[]) |
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 SDL_RWops *rwops = NULL; |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 char test_buf[30]; |
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 cleanup(); |
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 /* 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
|
50 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 rwops = SDL_RWFromFile(NULL,NULL); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 if (rwops) RWOP_ERR_QUIT(rwops); |
1454 | 53 rwops = SDL_RWFromFile(NULL,"ab+"); |
1453
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 if (rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 rwops = SDL_RWFromFile(NULL,"sldfkjsldkfj"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 if (rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 rwops = SDL_RWFromFile("something",""); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 if (rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 rwops = SDL_RWFromFile("something",NULL); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 if (rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 printf("test1 OK\n"); |
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 /* 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
|
64 /* 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
|
65 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
|
66 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 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
|
69 if (rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 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
|
71 if (rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 rwops = SDL_RWFromFile(FBASENAME2,"wb"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 if (!rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 rwops->close(rwops); unlink(FBASENAME2); |
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,"ab"); |
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 printf("test2 OK\n"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 /* test 3 : creation, writing , reading, seeking, |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 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
|
88 */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 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
|
90 if (!rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 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
|
92 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
|
93 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
|
94 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
|
95 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
|
96 rwops->close(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 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
|
99 if (!rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 rwops->close(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 /* test 3: same with w+ mode */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 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
|
114 if (!rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 rwops->close(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 printf("test3 OK\n"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 /* test 4: same in r+ mode */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 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
|
134 if (!rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 rwops->close(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 printf("test4 OK\n"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 /* test5 : append mode */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 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
|
154 if (!rwops) RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 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
|
156 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
|
157 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
|
158 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
|
159 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 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
|
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 (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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
169 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
|
170 |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
171 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
|
172 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
|
173 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
|
174 RWOP_ERR_QUIT(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 rwops->close(rwops); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 printf("test5 OK\n"); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 cleanup(); |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 return 0; /* all ok */ |
2eb75f8a32ca
Date: Mon, 27 Feb 2006 17:01:43 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
179 } |