annotate test/automated/rwops/rwops.c @ 4447:947201caa46e

Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware. The Mac OS X project has a new target called testsdl which builds the automated test. I looked at using Xcode's native unit test support, but the impedance mismatch between the existing automated test structure and Apple's was more than I could handle. As such, the testsdl application is a full blown proper OS X application, which means it is a self-contained .app bundle. This immediately revealed some problems from the automated test. The largest problem was the assumption about the current working directory and where to find resources. (I suspect Windows may have a similar problem depending on circumstance.) To open resources, the test was looking in directories relative to the SDL source directory, but this will not work well with self-contained .app bundles and Xcode which can place its built applications almost anywhere. And for real-world situations, this is pretty useless anyway. So I modified SDL_RWFromFile to do special things on OS X. First, it will look for a file in the .app bundle. If not found, it will fallback and just call fopen as it used to do. I also had to modify the automated test itself because it had a contrieved test which called fopen directly to do read from an existing FILE pointer. In addition, there was a write test. Since a .app bundle is likely going to be read-only, I added a special case for OS X to write to NSTemporaryDirectory. I expect these changes should work for both Mac and iPhone OS (which includes iPad). I will update the iPhone Xcode project next. Finally, FYI, the X11 automated test seems to be failing. Below is my output. Pending breakpoint 4 - "-[NSException raise]" resolved Platform : All tests successful (2) SDL_RWops : All tests successful (5) Rect : All tests successful (1) SDL_Surface : All tests successful (6) Rendering with cocoa driver : All tests successful (3) Assert Failed! Blit output not the same. Test Case 'Renderer x11' Test Suite 'Rendering with x11 driver' Last SDL error '' Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetSurfaceBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged. Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetWindowBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetSurfaceBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetWindowBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetSurfaceBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetWindowBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetSurfaceBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetWindowBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetSurfaceBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetWindowBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetSurfaceBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetWindowBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetSurfaceBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Rendering with x11 driver : Failed 1 out of 4 testcases! Rendering with dummy driver : All tests successful (3) SDL_Audio : All tests successful (1) Tests run with SDL 1.3.0 revision 1095906 System is running Mac OS X and is little endian
author Eric Wing <ewing . public |-at-| gmail . com>
date Sat, 08 May 2010 00:54:22 -0700
parents 78db4f7ae2f3
children 8f73f4a3c972
rev   line source
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /**
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 * Automated SDL_RWops test.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 *
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4 * Written by Edgar Simo "bobbens"
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 *
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 * Released under Public Domain.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 #include "SDL.h"
3481
c32c53fca10d Fixed include paths for Visual C++
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
11 #include "../SDL_at.h"
4447
947201caa46e Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 3482
diff changeset
12 #if __APPLE__
947201caa46e Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 3482
diff changeset
13 #include "Test_rwopsbundlesupport.h"
947201caa46e Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 3482
diff changeset
14 #endif
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 #define RWOPS_READ "rwops/read"
4447
947201caa46e Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 3482
diff changeset
17
947201caa46e Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 3482
diff changeset
18 #if __APPLE__
947201caa46e Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 3482
diff changeset
19 #define RWOPS_WRITE "write"
947201caa46e Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 3482
diff changeset
20 #else
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 #define RWOPS_WRITE "rwops/write"
4447
947201caa46e Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 3482
diff changeset
22 #endif
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 static const char hello_world[] = "Hello World!";
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 /**
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 * @brief Makes sure parameters work properly.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 static void rwops_testParam (void)
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 SDL_RWops *rwops;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 /* Begin testcase. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 SDL_ATbegin( "RWops Parameters" );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 /* These should all fail. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 rwops = SDL_RWFromFile(NULL, NULL);
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 if (SDL_ATassert( "SDL_RWFromFile(NULL, NULL) worked", rwops == NULL ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 rwops = SDL_RWFromFile(NULL, "ab+");
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 if (SDL_ATassert( "SDL_RWFromFile(NULL, \"ab+\") worked", rwops == NULL ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 rwops = SDL_RWFromFile(NULL, "sldfkjsldkfj");
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 if (SDL_ATassert( "SDL_RWFromFile(NULL, \"sldfkjsldkfj\") worked", rwops == NULL ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 rwops = SDL_RWFromFile("something", "");
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 if (SDL_ATassert( "SDL_RWFromFile(\"something\", \"\") worked", rwops == NULL ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 rwops = SDL_RWFromFile("something", NULL);
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 if (SDL_ATassert( "SDL_RWFromFile(\"something\", NULL) worked", rwops == NULL ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 /* End testcase. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 SDL_ATend();
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 /**
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 * @brief Does a generic rwops test.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 *
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 * RWops should have "Hello World!" in it already if write is disabled.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 *
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 * @param write Test writing also.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 * @return 1 if an assert is failed.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 static int rwops_testGeneric( SDL_RWops *rw, int write )
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 char buf[sizeof(hello_world)];
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 int i;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 /* Set to start. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 i = SDL_RWseek( rw, 0, RW_SEEK_SET );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 if (SDL_ATvassert( i == 0,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 "Seeking with SDL_RWseek (RW_SEEK_SET): got %d, expected %d",
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 i, 0 ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 return 1;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 /* Test write. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 i = SDL_RWwrite( rw, hello_world, sizeof(hello_world)-1, 1 );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 if (write) {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 if (SDL_ATassert( "Writing with SDL_RWwrite (failed to write)", i == 1 ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 return 1;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 else {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 if (SDL_ATassert( "Writing with SDL_RWwrite (wrote when shouldn't have)", i <= 0 ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 return 1;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 /* Test seek. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 i = SDL_RWseek( rw, 6, RW_SEEK_SET );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 if (SDL_ATvassert( i == 6,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 "Seeking with SDL_RWseek (RW_SEEK_SET): got %d, expected %d",
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 i, 0 ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 return 1;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 /* Test seek. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 i = SDL_RWseek( rw, 0, RW_SEEK_SET );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 if (SDL_ATvassert( i == 0,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 "Seeking with SDL_RWseek (RW_SEEK_SET): got %d, expected %d",
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 i, 0 ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 return 1;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 /* Test read. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 i = SDL_RWread( rw, buf, 1, sizeof(hello_world)-1 );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 if (SDL_ATassert( "Reading with SDL_RWread", i == sizeof(hello_world)-1 ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 return 1;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 if (SDL_ATassert( "Memory read does not match memory written",
3482
78db4f7ae2f3 More fixes to compile under Visual C++
Sam Lantinga <slouken@libsdl.org>
parents: 3481
diff changeset
110 SDL_memcmp( buf, hello_world, sizeof(hello_world)-1 ) == 0 ))
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 return 1;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 /* More seek tests. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 i = SDL_RWseek( rw, -4, RW_SEEK_CUR );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 if (SDL_ATvassert( i == sizeof(hello_world)-5,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 "Seeking with SDL_RWseek (RW_SEEK_CUR): got %d, expected %d",
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 i, sizeof(hello_world)-5 ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 return 1;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 i = SDL_RWseek( rw, -1, RW_SEEK_END );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 if (SDL_ATvassert( i == sizeof(hello_world)-2,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 "Seeking with SDL_RWseek (RW_SEEK_END): got %d, expected %d",
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 i, sizeof(hello_world)-2 ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 return 1;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 return 0;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 /**
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 * @brief Tests opening from memory.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 static void rwops_testMem (void)
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 char mem[sizeof(hello_world)];
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 SDL_RWops *rw;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 /* Begin testcase. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 SDL_ATbegin( "SDL_RWFromMem" );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 /* Open. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 rw = SDL_RWFromMem( mem, sizeof(hello_world)-1 );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 if (SDL_ATassert( "Opening memory with SDL_RWFromMem", rw != NULL ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 /* Run generic tests. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 if (rwops_testGeneric( rw, 1 ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 /* Close. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 SDL_FreeRW( rw );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 /* End testcase. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 SDL_ATend();
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 static const char const_mem[] = "Hello World!";
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 /**
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 * @brief Tests opening from memory.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 static void rwops_testConstMem (void)
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 SDL_RWops *rw;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 /* Begin testcase. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 SDL_ATbegin( "SDL_RWFromConstMem" );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 /* Open. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 rw = SDL_RWFromConstMem( const_mem, sizeof(const_mem)-1 );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 if (SDL_ATassert( "Opening memory with SDL_RWFromConstMem", rw != NULL ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 /* Run generic tests. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 if (rwops_testGeneric( rw, 0 ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 /* Close. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 SDL_FreeRW( rw );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 /* End testcase. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 SDL_ATend();
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 /**
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 * @brief Tests opening from memory.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 static void rwops_testFile (void)
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 SDL_RWops *rw;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 /* Begin testcase. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 SDL_ATbegin( "SDL_RWFromFile" );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 /* Read test. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 rw = SDL_RWFromFile( RWOPS_READ, "r" );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 if (SDL_ATassert( "Opening memory with SDL_RWFromFile '"RWOPS_READ"'", rw != NULL ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 if (rwops_testGeneric( rw, 0 ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 SDL_FreeRW( rw );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 /* Write test. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 rw = SDL_RWFromFile( RWOPS_WRITE, "w+" );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 if (SDL_ATassert( "Opening memory with SDL_RWFromFile '"RWOPS_WRITE"'", rw != NULL ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 if (rwops_testGeneric( rw, 1 ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 SDL_FreeRW( rw );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 /* End testcase. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 SDL_ATend();
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 /**
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 * @brief Tests opening from memory.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 static void rwops_testFP (void)
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 #ifdef HAVE_STDIO_H
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 FILE *fp;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223 SDL_RWops *rw;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 /* Begin testcase. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 SDL_ATbegin( "SDL_RWFromFP" );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 /* Run read tests. */
4447
947201caa46e Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 3482
diff changeset
229 #if __APPLE__
947201caa46e Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 3482
diff changeset
230 /* Cheating: Using private API in SDL */
947201caa46e Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 3482
diff changeset
231 fp = Test_OpenFPFromBundleOrFallback( RWOPS_READ, "r" );
947201caa46e Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 3482
diff changeset
232 #else
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 fp = fopen( RWOPS_READ, "r" );
4447
947201caa46e Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 3482
diff changeset
234 #endif
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 if (SDL_ATassert( "Failed to open file '"RWOPS_READ"'", fp != NULL))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237 rw = SDL_RWFromFP( fp, 1 );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238 if (SDL_ATassert( "Opening memory with SDL_RWFromFP", rw != NULL ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 if (rwops_testGeneric( rw, 0 ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 SDL_FreeRW( rw );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 /* Run write tests. */
4447
947201caa46e Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 3482
diff changeset
245 #if __APPLE__
947201caa46e Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 3482
diff changeset
246 /* Cheating: Using private API in SDL */
947201caa46e Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 3482
diff changeset
247 fp = Test_OpenFPFromTemporaryDir( RWOPS_WRITE, "w+" );
947201caa46e Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 3482
diff changeset
248 #else
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 fp = fopen( RWOPS_WRITE, "w+" );
4447
947201caa46e Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 3482
diff changeset
250 #endif
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 if (SDL_ATassert( "Failed to open file '"RWOPS_WRITE"'", fp != NULL))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 rw = SDL_RWFromFP( fp, 1 );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 if (SDL_ATassert( "Opening memory with SDL_RWFromFP", rw != NULL ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 if (rwops_testGeneric( rw, 1 ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 SDL_FreeRW( rw );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260 /* End testcase. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 SDL_ATend();
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 #endif /* HAVE_STDIO_H */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 /**
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 * @brief Entry point.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 #ifdef TEST_STANDALONE
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 int main( int argc, const char *argv[] )
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 (void) argc;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 (void) argv;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
274 #else /* TEST_STANDALONE */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 int test_rwops (void)
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276 {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
277 #endif /* TEST_STANDALONE */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279 SDL_ATinit( "SDL_RWops" );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 rwops_testParam();
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282 rwops_testMem();
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283 rwops_testConstMem();
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284 rwops_testFile();
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
285 rwops_testFP();
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287 return SDL_ATfinish();
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
288 }