annotate test/automated/rwops/rwops.c @ 3741:808fad5fb593 gsoc2009_unit_tests

Added command line options. Added verbosity levels.
author Edgar Simo <bobbens@gmail.com>
date Sun, 02 Aug 2009 18:58:03 +0000
parents e451d5d288e9
children
rev   line source
3713
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
1 /**
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
2 * Automated SDL_RWops test.
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
3 *
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
4 * Written by Edgar Simo "bobbens"
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
5 *
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
6 * Released under Public Domain.
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
7 */
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
8
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
9
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
10 #include "SDL.h"
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
11 #include "SDL_at.h"
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
12
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
13
3737
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
14 #define RWOPS_READ "rwops/read"
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
15 #define RWOPS_WRITE "rwops/write"
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
16
3713
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
17 static const char hello_world[] = "Hello World!";
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
18
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
19
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
20 /**
3737
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
21 * @brief Makes sure parameters work properly.
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
22 */
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
23 static void rwops_testParam (void)
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
24 {
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
25 SDL_RWops *rwops;
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
26
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
27 /* Begin testcase. */
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
28 SDL_ATbegin( "RWops Parameters" );
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
29
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
30 /* These should all fail. */
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
31 rwops = SDL_RWFromFile(NULL, NULL);
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
32 if (SDL_ATassert( "SDL_RWFromFile(NULL, NULL) worked", rwops == NULL ))
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
33 return;
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
34 rwops = SDL_RWFromFile(NULL, "ab+");
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
35 if (SDL_ATassert( "SDL_RWFromFile(NULL, \"ab+\") worked", rwops == NULL ))
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
36 return;
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
37 rwops = SDL_RWFromFile(NULL, "sldfkjsldkfj");
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
38 if (SDL_ATassert( "SDL_RWFromFile(NULL, \"sldfkjsldkfj\") worked", rwops == NULL ))
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
39 return;
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
40 rwops = SDL_RWFromFile("something", "");
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
41 if (SDL_ATassert( "SDL_RWFromFile(\"something\", \"\") worked", rwops == NULL ))
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
42 return;
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
43 rwops = SDL_RWFromFile("something", NULL);
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
44 if (SDL_ATassert( "SDL_RWFromFile(\"something\", NULL) worked", rwops == NULL ))
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
45 return;
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
46
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
47
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
48 /* End testcase. */
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
49 SDL_ATend();
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
50 }
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
51
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
52
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
53 /**
3713
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
54 * @brief Does a generic rwops test.
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
55 *
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
56 * RWops should have "Hello World!" in it already if write is disabled.
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
57 *
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
58 * @param write Test writing also.
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
59 * @return 1 if an assert is failed.
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
60 */
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
61 static int rwops_testGeneric( SDL_RWops *rw, int write )
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
62 {
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
63 char buf[sizeof(hello_world)];
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
64 int i;
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
65
3737
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
66 /* Set to start. */
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
67 i = SDL_RWseek( rw, 0, RW_SEEK_SET );
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
68 if (SDL_ATvassert( i == 0,
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
69 "Seeking with SDL_RWseek (RW_SEEK_SET): got %d, expected %d",
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
70 i, 0 ))
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
71 return 1;
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
72
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
73 /* Test write. */
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
74 i = SDL_RWwrite( rw, hello_world, sizeof(hello_world)-1, 1 );
3713
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
75 if (write) {
3737
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
76 if (SDL_ATassert( "Writing with SDL_RWwrite (failed to write)", i == 1 ))
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
77 return 1;
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
78 }
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
79 else {
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
80 if (SDL_ATassert( "Writing with SDL_RWwrite (wrote when shouldn't have)", i <= 0 ))
3713
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
81 return 1;
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
82 }
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
83
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
84 /* Test seek. */
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
85 i = SDL_RWseek( rw, 6, RW_SEEK_SET );
3737
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
86 if (SDL_ATvassert( i == 6,
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
87 "Seeking with SDL_RWseek (RW_SEEK_SET): got %d, expected %d",
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
88 i, 0 ))
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
89 return 1;
3713
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
90
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
91 /* Test seek. */
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
92 i = SDL_RWseek( rw, 0, RW_SEEK_SET );
3737
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
93 if (SDL_ATvassert( i == 0,
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
94 "Seeking with SDL_RWseek (RW_SEEK_SET): got %d, expected %d",
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
95 i, 0 ))
3713
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
96 return 1;
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
97
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
98 /* Test read. */
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
99 i = SDL_RWread( rw, buf, 1, sizeof(hello_world)-1 );
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
100 if (SDL_ATassert( "Reading with SDL_RWread", i == sizeof(hello_world)-1 ))
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
101 return 1;
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
102 if (SDL_ATassert( "Memory read does not match memory written",
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
103 memcmp( buf, hello_world, sizeof(hello_world)-1 ) == 0 ))
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
104 return 1;
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
105
3737
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
106 /* More seek tests. */
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
107 i = SDL_RWseek( rw, -4, RW_SEEK_CUR );
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
108 if (SDL_ATvassert( i == sizeof(hello_world)-5,
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
109 "Seeking with SDL_RWseek (RW_SEEK_CUR): got %d, expected %d",
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
110 i, sizeof(hello_world)-5 ))
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
111 return 1;
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
112 i = SDL_RWseek( rw, -1, RW_SEEK_END );
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
113 if (SDL_ATvassert( i == sizeof(hello_world)-2,
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
114 "Seeking with SDL_RWseek (RW_SEEK_END): got %d, expected %d",
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
115 i, sizeof(hello_world)-2 ))
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
116 return 1;
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
117
3713
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
118 return 0;
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
119 }
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
120
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
121
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
122 /**
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
123 * @brief Tests opening from memory.
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
124 */
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
125 static void rwops_testMem (void)
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
126 {
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
127 char mem[sizeof(hello_world)];
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
128 SDL_RWops *rw;
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
129
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
130 /* Begin testcase. */
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
131 SDL_ATbegin( "SDL_RWFromMem" );
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
132
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
133 /* Open. */
3737
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
134 rw = SDL_RWFromMem( mem, sizeof(hello_world)-1 );
3713
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
135 if (SDL_ATassert( "Opening memory with SDL_RWFromMem", rw != NULL ))
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
136 return;
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
137
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
138 /* Run generic tests. */
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
139 if (rwops_testGeneric( rw, 1 ))
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
140 return;
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
141
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
142 /* Close. */
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
143 SDL_FreeRW( rw );
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
144
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
145 /* End testcase. */
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
146 SDL_ATend();
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
147 }
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
148
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
149
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
150 static const char const_mem[] = "Hello World!";
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
151 /**
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
152 * @brief Tests opening from memory.
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
153 */
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
154 static void rwops_testConstMem (void)
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
155 {
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
156 SDL_RWops *rw;
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
157
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
158 /* Begin testcase. */
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
159 SDL_ATbegin( "SDL_RWFromConstMem" );
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
160
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
161 /* Open. */
3737
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
162 rw = SDL_RWFromConstMem( const_mem, sizeof(const_mem)-1 );
3713
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
163 if (SDL_ATassert( "Opening memory with SDL_RWFromConstMem", rw != NULL ))
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
164 return;
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
165
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
166 /* Run generic tests. */
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
167 if (rwops_testGeneric( rw, 0 ))
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
168 return;
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
169
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
170 /* Close. */
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
171 SDL_FreeRW( rw );
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
172
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
173 /* End testcase. */
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
174 SDL_ATend();
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
175 }
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
176
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
177
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
178 /**
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
179 * @brief Tests opening from memory.
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
180 */
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
181 static void rwops_testFile (void)
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
182 {
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
183 SDL_RWops *rw;
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
184
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
185 /* Begin testcase. */
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
186 SDL_ATbegin( "SDL_RWFromFile" );
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
187
3737
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
188 /* Read test. */
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
189 rw = SDL_RWFromFile( RWOPS_READ, "r" );
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
190 if (SDL_ATassert( "Opening memory with SDL_RWFromFile '"RWOPS_READ"'", rw != NULL ))
3713
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
191 return;
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
192 if (rwops_testGeneric( rw, 0 ))
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
193 return;
3737
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
194 SDL_FreeRW( rw );
3713
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
195
3737
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
196 /* Write test. */
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
197 rw = SDL_RWFromFile( RWOPS_WRITE, "w+" );
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
198 if (SDL_ATassert( "Opening memory with SDL_RWFromFile '"RWOPS_WRITE"'", rw != NULL ))
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
199 return;
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
200 if (rwops_testGeneric( rw, 1 ))
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
201 return;
3713
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
202 SDL_FreeRW( rw );
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
203
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
204 /* End testcase. */
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
205 SDL_ATend();
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
206 }
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
207
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
208
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
209 /**
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
210 * @brief Tests opening from memory.
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
211 */
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
212 static void rwops_testFP (void)
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
213 {
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
214 #ifdef HAVE_STDIO_H
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
215 FILE *fp;
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
216 SDL_RWops *rw;
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
217
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
218 /* Begin testcase. */
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
219 SDL_ATbegin( "SDL_RWFromFP" );
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
220
3737
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
221 /* Run read tests. */
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
222 fp = fopen( RWOPS_READ, "r" );
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
223 if (SDL_ATassert( "Failed to open file '"RWOPS_READ"'", fp != NULL))
3713
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
224 return;
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
225 rw = SDL_RWFromFP( fp, 1 );
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
226 if (SDL_ATassert( "Opening memory with SDL_RWFromFP", rw != NULL ))
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
227 return;
3737
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
228 if (rwops_testGeneric( rw, 0 ))
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
229 return;
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
230 SDL_FreeRW( rw );
3713
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
231
3737
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
232 /* Run write tests. */
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
233 fp = fopen( RWOPS_WRITE, "w+" );
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
234 if (SDL_ATassert( "Failed to open file '"RWOPS_WRITE"'", fp != NULL))
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
235 return;
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
236 rw = SDL_RWFromFP( fp, 1 );
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
237 if (SDL_ATassert( "Opening memory with SDL_RWFromFP", rw != NULL ))
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
238 return;
3713
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
239 if (rwops_testGeneric( rw, 1 ))
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
240 return;
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
241 SDL_FreeRW( rw );
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
242
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
243 /* End testcase. */
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
244 SDL_ATend();
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
245 #endif /* HAVE_STDIO_H */
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
246 }
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
247
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
248
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
249 /**
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
250 * @brief Entry point.
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
251 */
3740
e451d5d288e9 Merged into one big app, while keeping modular applications also.
Edgar Simo <bobbens@gmail.com>
parents: 3737
diff changeset
252 #ifdef TEST_STANDALONE
3713
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
253 int main( int argc, const char *argv[] )
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
254 {
3722
d8772964e402 Added more strict warning flags.
Edgar Simo <bobbens@gmail.com>
parents: 3713
diff changeset
255 (void) argc;
d8772964e402 Added more strict warning flags.
Edgar Simo <bobbens@gmail.com>
parents: 3713
diff changeset
256 (void) argv;
3740
e451d5d288e9 Merged into one big app, while keeping modular applications also.
Edgar Simo <bobbens@gmail.com>
parents: 3737
diff changeset
257 #else /* TEST_STANDALONE */
e451d5d288e9 Merged into one big app, while keeping modular applications also.
Edgar Simo <bobbens@gmail.com>
parents: 3737
diff changeset
258 int test_rwops (void)
e451d5d288e9 Merged into one big app, while keeping modular applications also.
Edgar Simo <bobbens@gmail.com>
parents: 3737
diff changeset
259 {
e451d5d288e9 Merged into one big app, while keeping modular applications also.
Edgar Simo <bobbens@gmail.com>
parents: 3737
diff changeset
260 #endif /* TEST_STANDALONE */
3722
d8772964e402 Added more strict warning flags.
Edgar Simo <bobbens@gmail.com>
parents: 3713
diff changeset
261
3713
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
262 SDL_ATinit( "SDL_RWops" );
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
263
3737
9689eaa6d2e3 Made rwops tests a bit more complete.
Edgar Simo <bobbens@gmail.com>
parents: 3722
diff changeset
264 rwops_testParam();
3713
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
265 rwops_testMem();
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
266 rwops_testConstMem();
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
267 rwops_testFile();
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
268 rwops_testFP();
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
269
3741
808fad5fb593 Added command line options.
Edgar Simo <bobbens@gmail.com>
parents: 3740
diff changeset
270 return SDL_ATfinish();
3713
a34bab848c7e Better output.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
271 }