Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
748 lines (624 loc) · 26 KB

testautomation_rwops.c

File metadata and controls

748 lines (624 loc) · 26 KB
 
Dec 31, 2012
Dec 31, 2012
1
2
3
4
5
6
/**
* Automated SDL_RWops test.
*
* Original code written by Edgar Simo "bobbens"
* Ported by Markus Kauppila (markus.kauppila@gmail.com)
Jan 21, 2013
Jan 21, 2013
7
* Updated and extended for SDL_test by aschiffler at ferzkopp dot net
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
*
* Released under Public Domain.
*/
/* quiet windows compiler warnings */
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include "SDL.h"
#include "SDL_test.h"
/* ================= Test Case Implementation ================== */
const char* RWopsReadTestFilename = "rwops_read";
const char* RWopsWriteTestFilename = "rwops_write";
Mar 13, 2013
Mar 13, 2013
24
const char* RWopsAlphabetFilename = "rwops_alphabet";
25
26
27
static const char RWopsHelloWorldTestString[] = "Hello World!";
static const char RWopsHelloWorldCompString[] = "Hello World!";
Mar 13, 2013
Mar 13, 2013
28
static const char RWopsAlphabetString[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
29
30
31
32
33
34
/* Fixture */
void
RWopsSetUp(void *arg)
{
May 18, 2013
May 18, 2013
35
36
37
38
39
40
41
42
43
44
45
46
47
int fileLen;
FILE *handle;
int writtenLen;
int result;
/* Clean up from previous runs (if any); ignore errors */
remove(RWopsReadTestFilename);
remove(RWopsWriteTestFilename);
remove(RWopsAlphabetFilename);
/* Create a test file */
handle = fopen(RWopsReadTestFilename, "w");
SDLTest_AssertCheck(handle != NULL, "Verify creation of file '%s' returned non NULL handle", RWopsReadTestFilename);
Jan 21, 2013
Jan 21, 2013
48
if (handle == NULL) return;
May 18, 2013
May 18, 2013
50
51
52
53
54
55
/* Write some known text into it */
fileLen = SDL_strlen(RWopsHelloWorldTestString);
writtenLen = (int)fwrite(RWopsHelloWorldTestString, 1, fileLen, handle);
SDLTest_AssertCheck(fileLen == writtenLen, "Verify number of written bytes, expected %i, got %i", fileLen, writtenLen);
result = fclose(handle);
SDLTest_AssertCheck(result == 0, "Verify result from fclose, expected 0, got %i", result);
May 18, 2013
May 18, 2013
57
58
59
/* Create a second test file */
handle = fopen(RWopsAlphabetFilename, "w");
SDLTest_AssertCheck(handle != NULL, "Verify creation of file '%s' returned non NULL handle", RWopsAlphabetFilename);
Mar 13, 2013
Mar 13, 2013
60
61
if (handle == NULL) return;
May 18, 2013
May 18, 2013
62
63
64
65
66
67
/* Write alphabet text into it */
fileLen = SDL_strlen(RWopsAlphabetString);
writtenLen = (int)fwrite(RWopsAlphabetString, 1, fileLen, handle);
SDLTest_AssertCheck(fileLen == writtenLen, "Verify number of written bytes, expected %i, got %i", fileLen, writtenLen);
result = fclose(handle);
SDLTest_AssertCheck(result == 0, "Verify result from fclose, expected 0, got %i", result);
Mar 13, 2013
Mar 13, 2013
68
May 18, 2013
May 18, 2013
69
SDLTest_AssertPass("Creation of test file completed");
70
71
72
73
74
}
void
RWopsTearDown(void *arg)
{
May 18, 2013
May 18, 2013
75
76
77
78
79
80
81
82
83
84
int result;
/* Remove the created files to clean up; ignore errors for write filename */
result = remove(RWopsReadTestFilename);
SDLTest_AssertCheck(result == 0, "Verify result from remove(%s), expected 0, got %i", RWopsReadTestFilename, result);
remove(RWopsWriteTestFilename);
result = remove(RWopsAlphabetFilename);
SDLTest_AssertCheck(result == 0, "Verify result from remove(%s), expected 0, got %i", RWopsAlphabetFilename, result);
SDLTest_AssertPass("Cleanup of test files completed");
85
86
87
88
89
90
91
92
93
}
/**
* @brief Makes sure parameters work properly. Local helper function.
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_RWseek
* http://wiki.libsdl.org/moin.cgi/SDL_RWread
*/
May 18, 2013
May 18, 2013
94
void
95
96
97
_testGenericRWopsValidations(SDL_RWops *rw, int write)
{
char buf[sizeof(RWopsHelloWorldTestString)];
Dec 30, 2012
Dec 30, 2012
98
Sint64 i;
Mar 12, 2013
Mar 12, 2013
99
size_t s;
100
101
102
103
104
105
106
107
int seekPos = SDLTest_RandomIntegerInRange(4, 8);
/* Clear buffer */
SDL_zero(buf);
/* Set to start. */
i = SDL_RWseek(rw, 0, RW_SEEK_SET );
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
Dec 30, 2012
Dec 30, 2012
108
SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %i", i);
109
110
/* Test write. */
Mar 12, 2013
Mar 12, 2013
111
s = SDL_RWwrite(rw, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1, 1);
112
113
SDLTest_AssertPass("Call to SDL_RWwrite succeeded");
if (write) {
May 18, 2013
May 18, 2013
114
SDLTest_AssertCheck(s == (size_t)1, "Verify result of writing one byte with SDL_RWwrite, expected 1, got %i", s);
May 18, 2013
May 18, 2013
117
SDLTest_AssertCheck(s == (size_t)0, "Verify result of writing with SDL_RWwrite, expected: 0, got %i", s);
118
119
120
121
122
}
/* Test seek to random position */
i = SDL_RWseek( rw, seekPos, RW_SEEK_SET );
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
Dec 30, 2012
Dec 30, 2012
123
SDLTest_AssertCheck(i == (Sint64)seekPos, "Verify seek to %i with SDL_RWseek (RW_SEEK_SET), expected %i, got %i", seekPos, seekPos, i);
124
125
126
127
/* Test seek back to start */
i = SDL_RWseek(rw, 0, RW_SEEK_SET );
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
Dec 30, 2012
Dec 30, 2012
128
SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %i", i);
Mar 12, 2013
Mar 12, 2013
131
s = SDL_RWread( rw, buf, 1, sizeof(RWopsHelloWorldTestString)-1 );
132
133
SDLTest_AssertPass("Call to SDL_RWread succeeded");
SDLTest_AssertCheck(
May 18, 2013
May 18, 2013
134
135
136
137
s == (size_t)(sizeof(RWopsHelloWorldTestString)-1),
"Verify result from SDL_RWread, expected %i, got %i",
sizeof(RWopsHelloWorldTestString)-1,
s);
138
SDLTest_AssertCheck(
May 18, 2013
May 18, 2013
139
140
SDL_memcmp(buf, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1 ) == 0,
"Verify read bytes match expected string, expected '%s', got '%s'", RWopsHelloWorldTestString, buf);
141
142
143
144
145
/* More seek tests. */
i = SDL_RWseek( rw, -4, RW_SEEK_CUR );
SDLTest_AssertPass("Call to SDL_RWseek(...,-4,RW_SEEK_CUR) succeeded");
SDLTest_AssertCheck(
May 18, 2013
May 18, 2013
146
147
148
149
i == (Sint64)(sizeof(RWopsHelloWorldTestString)-5),
"Verify seek to -4 with SDL_RWseek (RW_SEEK_CUR), expected %i, got %i",
sizeof(RWopsHelloWorldTestString)-5,
i);
150
151
152
153
i = SDL_RWseek( rw, -1, RW_SEEK_END );
SDLTest_AssertPass("Call to SDL_RWseek(...,-1,RW_SEEK_END) succeeded");
SDLTest_AssertCheck(
May 18, 2013
May 18, 2013
154
155
156
157
158
i == (Sint64)(sizeof(RWopsHelloWorldTestString)-2),
"Verify seek to -1 with SDL_RWseek (RW_SEEK_END), expected %i, got %i",
sizeof(RWopsHelloWorldTestString)-2,
i);
Mar 13, 2013
Mar 13, 2013
159
160
161
162
/* Invalid whence seek */
i = SDL_RWseek( rw, 0, 999 );
SDLTest_AssertPass("Call to SDL_RWseek(...,0,invalid_whence) succeeded");
SDLTest_AssertCheck(
May 18, 2013
May 18, 2013
163
164
165
i == (Sint64)(-1),
"Verify seek with SDL_RWseek (invalid_whence); expected: -1, got %i",
i);
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
}
/*!
* Negative test for SDL_RWFromFile parameters
*
* \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
*
*/
int
rwops_testParamNegative (void)
{
SDL_RWops *rwops;
/* These should all fail. */
rwops = SDL_RWFromFile(NULL, NULL);
SDLTest_AssertPass("Call to SDL_RWFromFile(NULL, NULL) succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(NULL, NULL) returns NULL");
rwops = SDL_RWFromFile(NULL, "ab+");
SDLTest_AssertPass("Call to SDL_RWFromFile(NULL, \"ab+\") succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(NULL, \"ab+\") returns NULL");
rwops = SDL_RWFromFile(NULL, "sldfkjsldkfj");
SDLTest_AssertPass("Call to SDL_RWFromFile(NULL, \"sldfkjsldkfj\") succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(NULL, \"sldfkjsldkfj\") returns NULL");
rwops = SDL_RWFromFile("something", "");
SDLTest_AssertPass("Call to SDL_RWFromFile(\"something\", \"\") succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(\"something\", \"\") returns NULL");
rwops = SDL_RWFromFile("something", NULL);
SDLTest_AssertPass("Call to SDL_RWFromFile(\"something\", NULL) succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(\"something\", NULL) returns NULL");
Mar 13, 2013
Mar 13, 2013
200
201
202
203
204
205
206
207
208
209
210
211
rwops = SDL_RWFromMem((void *)NULL, 10);
SDLTest_AssertPass("Call to SDL_RWFromMem(NULL, 10) succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromMem(NULL, 10) returns NULL");
rwops = SDL_RWFromMem((void *)RWopsAlphabetString, 0);
SDLTest_AssertPass("Call to SDL_RWFromMem(data, 0) succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromMem(data, 0) returns NULL");
rwops = SDL_RWFromConstMem((const void *)RWopsAlphabetString, 0);
SDLTest_AssertPass("Call to SDL_RWFromConstMem(data, 0) succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromConstMem(data, 0) returns NULL");
212
213
214
215
216
217
218
return TEST_COMPLETED;
}
/**
* @brief Tests opening from memory.
*
* \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromMem
Mar 13, 2013
Mar 13, 2013
219
* \sa http://wiki.libsdl.org/moin.cgi/SDL_RWClose
220
221
222
223
224
225
*/
int
rwops_testMem (void)
{
char mem[sizeof(RWopsHelloWorldTestString)];
SDL_RWops *rw;
Mar 13, 2013
Mar 13, 2013
226
int result;
227
228
229
230
231
232
233
234
235
236
237
238
/* Clear buffer */
SDL_zero(mem);
/* Open */
rw = SDL_RWFromMem(mem, sizeof(RWopsHelloWorldTestString)-1);
SDLTest_AssertPass("Call to SDL_RWFromMem() succeeded");
SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromMem does not return NULL");
/* Bail out if NULL */
if (rw == NULL) return TEST_ABORTED;
Mar 13, 2013
Mar 13, 2013
239
240
241
/* Check type */
SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY, "Verify RWops type is SDL_RWOPS_MEMORY; expected: %d, got: %d", SDL_RWOPS_MEMORY, rw->type);
242
243
244
245
/* Run generic tests */
_testGenericRWopsValidations(rw, 1);
/* Close */
Mar 13, 2013
Mar 13, 2013
246
result = SDL_RWclose(rw);
247
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
Mar 13, 2013
Mar 13, 2013
248
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
249
250
251
252
253
254
255
256
257
258
return TEST_COMPLETED;
}
/**
* @brief Tests opening from memory.
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_RWFromConstMem
Jan 21, 2013
Jan 21, 2013
259
* http://wiki.libsdl.org/moin.cgi/SDL_RWClose
May 18, 2013
May 18, 2013
261
int
262
263
264
rwops_testConstMem (void)
{
SDL_RWops *rw;
Mar 13, 2013
Mar 13, 2013
265
int result;
266
267
268
269
270
271
272
273
274
/* Open handle */
rw = SDL_RWFromConstMem( RWopsHelloWorldCompString, sizeof(RWopsHelloWorldCompString)-1 );
SDLTest_AssertPass("Call to SDL_RWFromConstMem() succeeded");
SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromConstMem does not return NULL");
/* Bail out if NULL */
if (rw == NULL) return TEST_ABORTED;
Mar 13, 2013
Mar 13, 2013
275
276
277
/* Check type */
SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY_RO, "Verify RWops type is SDL_RWOPS_MEMORY_RO; expected: %d, got: %d", SDL_RWOPS_MEMORY_RO, rw->type);
278
279
280
281
/* Run generic tests */
_testGenericRWopsValidations( rw, 0 );
/* Close handle */
Mar 13, 2013
Mar 13, 2013
282
result = SDL_RWclose(rw);
283
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
Mar 13, 2013
Mar 13, 2013
284
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
285
286
287
288
289
290
291
292
293
294
return TEST_COMPLETED;
}
/**
* @brief Tests reading from file.
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
Jan 21, 2013
Jan 21, 2013
295
* http://wiki.libsdl.org/moin.cgi/SDL_RWClose
296
297
298
299
300
*/
int
rwops_testFileRead(void)
{
SDL_RWops *rw;
Mar 13, 2013
Mar 13, 2013
301
int result;
302
303
304
305
306
307
308
309
310
/* Read test. */
rw = SDL_RWFromFile(RWopsReadTestFilename, "r");
SDLTest_AssertPass("Call to SDL_RWFromFile(..,\"r\") succeeded");
SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in read mode does not return NULL");
// Bail out if NULL
if (rw == NULL) return TEST_ABORTED;
Mar 13, 2013
Mar 13, 2013
311
312
313
/* Check type */
#if defined(ANDROID)
SDLTest_AssertCheck(
May 18, 2013
May 18, 2013
314
rw->type == SDL_RWOPS_STDFILE || rw->type == SDL_RWOPS_JNIFILE,
Mar 13, 2013
Mar 13, 2013
315
316
317
"Verify RWops type is SDL_RWOPS_STDFILE or SDL_RWOPS_JNIFILE; expected: %d|%d, got: %d", SDL_RWOPS_STDFILE, SDL_RWOPS_JNIFILE, rw->type);
#elif defined(__WIN32__)
SDLTest_AssertCheck(
May 18, 2013
May 18, 2013
318
rw->type == SDL_RWOPS_WINFILE,
Mar 13, 2013
Mar 13, 2013
319
320
321
"Verify RWops type is SDL_RWOPS_WINFILE; expected: %d, got: %d", SDL_RWOPS_WINFILE, rw->type);
#else
SDLTest_AssertCheck(
May 18, 2013
May 18, 2013
322
rw->type == SDL_RWOPS_STDFILE,
Mar 13, 2013
Mar 13, 2013
323
324
325
"Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type);
#endif
326
327
328
329
/* Run generic tests */
_testGenericRWopsValidations( rw, 0 );
/* Close handle */
Mar 13, 2013
Mar 13, 2013
330
result = SDL_RWclose(rw);
331
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
Mar 13, 2013
Mar 13, 2013
332
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
333
334
335
336
337
return TEST_COMPLETED;
}
/**
Jan 21, 2013
Jan 21, 2013
338
* @brief Tests writing from file.
339
340
341
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
Jan 21, 2013
Jan 21, 2013
342
* http://wiki.libsdl.org/moin.cgi/SDL_RWClose
343
344
345
346
347
*/
int
rwops_testFileWrite(void)
{
SDL_RWops *rw;
Mar 13, 2013
Mar 13, 2013
348
int result;
349
350
351
352
353
354
355
356
357
/* Write test. */
rw = SDL_RWFromFile(RWopsWriteTestFilename, "w+");
SDLTest_AssertPass("Call to SDL_RWFromFile(..,\"w+\") succeeded");
SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in write mode does not return NULL");
// Bail out if NULL
if (rw == NULL) return TEST_ABORTED;
Mar 13, 2013
Mar 13, 2013
358
359
360
/* Check type */
#if defined(ANDROID)
SDLTest_AssertCheck(
May 18, 2013
May 18, 2013
361
rw->type == SDL_RWOPS_STDFILE || rw->type == SDL_RWOPS_JNIFILE,
Mar 13, 2013
Mar 13, 2013
362
363
364
"Verify RWops type is SDL_RWOPS_STDFILE or SDL_RWOPS_JNIFILE; expected: %d|%d, got: %d", SDL_RWOPS_STDFILE, SDL_RWOPS_JNIFILE, rw->type);
#elif defined(__WIN32__)
SDLTest_AssertCheck(
May 18, 2013
May 18, 2013
365
rw->type == SDL_RWOPS_WINFILE,
Mar 13, 2013
Mar 13, 2013
366
367
368
"Verify RWops type is SDL_RWOPS_WINFILE; expected: %d, got: %d", SDL_RWOPS_WINFILE, rw->type);
#else
SDLTest_AssertCheck(
May 18, 2013
May 18, 2013
369
rw->type == SDL_RWOPS_STDFILE,
Mar 13, 2013
Mar 13, 2013
370
371
372
"Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type);
#endif
373
374
375
376
/* Run generic tests */
_testGenericRWopsValidations( rw, 1 );
/* Close handle */
Mar 13, 2013
Mar 13, 2013
377
result = SDL_RWclose(rw);
378
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
Mar 13, 2013
Mar 13, 2013
379
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
380
381
382
383
384
385
386
387
388
389
return TEST_COMPLETED;
}
/**
* @brief Tests reading from file handle
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_RWFromFP
Jan 21, 2013
Jan 21, 2013
390
* http://wiki.libsdl.org/moin.cgi/SDL_RWClose
391
392
393
394
395
396
397
*
*/
int
rwops_testFPRead(void)
{
FILE *fp;
SDL_RWops *rw;
Mar 13, 2013
Mar 13, 2013
398
int result;
399
400
401
402
403
404
405
406
407
/* Run read tests. */
fp = fopen(RWopsReadTestFilename, "r");
SDLTest_AssertCheck(fp != NULL, "Verify handle from opening file '%s' in read mode is not NULL", RWopsReadTestFilename);
/* Bail out if NULL */
if (fp == NULL) return TEST_ABORTED;
/* Open */
Dec 30, 2012
Dec 30, 2012
408
rw = SDL_RWFromFP( fp, SDL_TRUE );
409
410
411
412
SDLTest_AssertPass("Call to SDL_RWFromFP() succeeded");
SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFP in read mode does not return NULL");
/* Bail out if NULL */
Dec 31, 2012
Dec 31, 2012
413
414
415
416
if (rw == NULL) {
fclose(fp);
return TEST_ABORTED;
}
Mar 13, 2013
Mar 13, 2013
418
419
/* Check type */
SDLTest_AssertCheck(
May 18, 2013
May 18, 2013
420
rw->type == SDL_RWOPS_STDFILE,
Mar 13, 2013
Mar 13, 2013
421
422
"Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type);
423
424
425
/* Run generic tests */
_testGenericRWopsValidations( rw, 0 );
Jan 14, 2013
Jan 14, 2013
426
/* Close handle - does fclose() */
Mar 13, 2013
Mar 13, 2013
427
result = SDL_RWclose(rw);
428
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
Mar 13, 2013
Mar 13, 2013
429
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
430
431
432
433
434
435
436
437
438
439
return TEST_COMPLETED;
}
/**
* @brief Tests writing to file handle
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_RWFromFP
Jan 21, 2013
Jan 21, 2013
440
* http://wiki.libsdl.org/moin.cgi/SDL_RWClose
441
442
443
444
445
446
447
*
*/
int
rwops_testFPWrite(void)
{
FILE *fp;
SDL_RWops *rw;
Mar 13, 2013
Mar 13, 2013
448
int result;
449
450
451
452
453
454
455
456
457
/* Run write tests. */
fp = fopen(RWopsWriteTestFilename, "w+");
SDLTest_AssertCheck(fp != NULL, "Verify handle from opening file '%s' in write mode is not NULL", RWopsWriteTestFilename);
/* Bail out if NULL */
if (fp == NULL) return TEST_ABORTED;
/* Open */
Dec 30, 2012
Dec 30, 2012
458
rw = SDL_RWFromFP( fp, SDL_TRUE );
459
460
461
462
SDLTest_AssertPass("Call to SDL_RWFromFP() succeeded");
SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFP in write mode does not return NULL");
/* Bail out if NULL */
Dec 31, 2012
Dec 31, 2012
463
464
465
466
if (rw == NULL) {
fclose(fp);
return TEST_ABORTED;
}
Mar 13, 2013
Mar 13, 2013
468
469
/* Check type */
SDLTest_AssertCheck(
May 18, 2013
May 18, 2013
470
rw->type == SDL_RWOPS_STDFILE,
Mar 13, 2013
Mar 13, 2013
471
472
"Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type);
473
474
475
/* Run generic tests */
_testGenericRWopsValidations( rw, 1 );
Jan 14, 2013
Jan 14, 2013
476
/* Close handle - does fclose() */
Mar 13, 2013
Mar 13, 2013
477
result = SDL_RWclose(rw);
478
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
Mar 13, 2013
Mar 13, 2013
479
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
480
481
482
483
return TEST_COMPLETED;
}
Dec 31, 2012
Dec 31, 2012
484
485
486
487
/**
* @brief Tests alloc and free RW context.
*
* \sa http://wiki.libsdl.org/moin.cgi/SDL_AllocRW
Jan 21, 2013
Jan 21, 2013
488
* \sa http://wiki.libsdl.org/moin.cgi/SDL_FreeRW
Dec 31, 2012
Dec 31, 2012
489
490
491
492
493
494
495
496
497
*/
int
rwops_testAllocFree (void)
{
/* Allocate context */
SDL_RWops *rw = SDL_AllocRW();
SDLTest_AssertPass("Call to SDL_AllocRW() succeeded");
SDLTest_AssertCheck(rw != NULL, "Validate result from SDL_AllocRW() is not NULL");
if (rw==NULL) return TEST_ABORTED;
Mar 13, 2013
Mar 13, 2013
498
499
500
/* Check type */
SDLTest_AssertCheck(
May 18, 2013
May 18, 2013
501
rw->type == SDL_RWOPS_UNKNOWN,
Mar 13, 2013
Mar 13, 2013
502
"Verify RWops type is SDL_RWOPS_UNKNOWN; expected: %d, got: %d", SDL_RWOPS_UNKNOWN, rw->type);
May 18, 2013
May 18, 2013
503
Dec 31, 2012
Dec 31, 2012
504
505
506
507
508
509
510
/* Free context again */
SDL_FreeRW(rw);
SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
return TEST_COMPLETED;
}
Mar 13, 2013
Mar 13, 2013
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
/**
* @brief Compare memory and file reads
*
* \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromMem
* \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
*/
int
rwops_testCompareRWFromMemWithRWFromFile(void)
{
int slen = 26;
char buffer_file[27];
char buffer_mem[27];
size_t rv_file;
size_t rv_mem;
Uint64 sv_file;
Uint64 sv_mem;
SDL_RWops* rwops_file;
SDL_RWops* rwops_mem;
int size;
int result;
May 18, 2013
May 18, 2013
532
Mar 13, 2013
Mar 13, 2013
533
534
535
536
537
for (size=5; size<10; size++)
{
/* Terminate buffer */
buffer_file[slen] = 0;
buffer_mem[slen] = 0;
May 18, 2013
May 18, 2013
538
Mar 13, 2013
Mar 13, 2013
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
/* Read/seek from memory */
rwops_mem = SDL_RWFromMem((void *)RWopsAlphabetString, slen);
SDLTest_AssertPass("Call to SDL_RWFromMem()");
rv_mem = SDL_RWread(rwops_mem, buffer_mem, size, 6);
SDLTest_AssertPass("Call to SDL_RWread(mem, size=%d)", size);
sv_mem = SDL_RWseek(rwops_mem, 0, SEEK_END);
SDLTest_AssertPass("Call to SDL_RWseek(mem,SEEK_END)");
result = SDL_RWclose(rwops_mem);
SDLTest_AssertPass("Call to SDL_RWclose(mem)");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
/* Read/see from file */
rwops_file = SDL_RWFromFile(RWopsAlphabetFilename, "r");
SDLTest_AssertPass("Call to SDL_RWFromFile()");
rv_file = SDL_RWread(rwops_file, buffer_file, size, 6);
SDLTest_AssertPass("Call to SDL_RWread(file, size=%d)", size);
sv_file = SDL_RWseek(rwops_file, 0, SEEK_END);
SDLTest_AssertPass("Call to SDL_RWseek(file,SEEK_END)");
result = SDL_RWclose(rwops_file);
SDLTest_AssertPass("Call to SDL_RWclose(file)");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
May 18, 2013
May 18, 2013
560
Mar 13, 2013
Mar 13, 2013
561
562
563
564
565
566
567
568
569
570
571
572
/* Compare */
SDLTest_AssertCheck(rv_mem == rv_file, "Verify returned read blocks matches for mem and file reads; got: rv_mem=%d rv_file=%d", rv_mem, rv_file);
SDLTest_AssertCheck(sv_mem == sv_file, "Verify SEEK_END position matches for mem and file seeks; got: sv_mem=%llu sv_file=%llu", sv_mem, sv_file);
SDLTest_AssertCheck(buffer_mem[slen] == 0, "Verify mem buffer termination; expected: 0, got: %d", buffer_mem[slen]);
SDLTest_AssertCheck(buffer_file[slen] == 0, "Verify file buffer termination; expected: 0, got: %d", buffer_file[slen]);
SDLTest_AssertCheck(
SDL_strncmp(buffer_mem, RWopsAlphabetString, slen) == 0,
"Verify mem buffer contain alphabet string; expected: %s, got: %s", RWopsAlphabetString, buffer_mem);
SDLTest_AssertCheck(
SDL_strncmp(buffer_file, RWopsAlphabetString, slen) == 0,
"Verify file buffer contain alphabet string; expected: %s, got: %s", RWopsAlphabetString, buffer_file);
}
May 18, 2013
May 18, 2013
573
Mar 13, 2013
Mar 13, 2013
574
575
576
return TEST_COMPLETED;
}
Jan 21, 2013
Jan 21, 2013
577
578
579
580
581
582
583
584
585
586
587
588
589
/**
* @brief Tests writing and reading from file using endian aware functions.
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
* http://wiki.libsdl.org/moin.cgi/SDL_RWClose
* http://wiki.libsdl.org/moin.cgi/SDL_ReadBE16
* http://wiki.libsdl.org/moin.cgi/SDL_WriteBE16
*/
int
rwops_testFileWriteReadEndian(void)
{
SDL_RWops *rw;
Jan 23, 2013
Jan 23, 2013
590
Sint64 result;
Jan 21, 2013
Jan 21, 2013
591
592
593
594
595
596
597
598
599
600
601
602
603
604
int mode;
size_t objectsWritten;
Uint16 BE16value;
Uint32 BE32value;
Uint64 BE64value;
Uint16 LE16value;
Uint32 LE32value;
Uint64 LE64value;
Uint16 BE16test;
Uint32 BE32test;
Uint64 BE64test;
Uint16 LE16test;
Uint32 LE32test;
Uint64 LE64test;
Mar 13, 2013
Mar 13, 2013
605
int cresult;
Jan 21, 2013
Jan 21, 2013
606
607
for (mode = 0; mode < 3; mode++) {
May 18, 2013
May 18, 2013
608
Jan 21, 2013
Jan 21, 2013
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
/* Create test data */
switch (mode) {
case 0:
SDLTest_Log("All 0 values");
BE16value = 0;
BE32value = 0;
BE64value = 0;
LE16value = 0;
LE32value = 0;
LE64value = 0;
break;
case 1:
SDLTest_Log("All 1 values");
BE16value = 1;
BE32value = 1;
BE64value = 1;
LE16value = 1;
LE32value = 1;
LE64value = 1;
break;
case 2:
SDLTest_Log("Random values");
BE16value = SDLTest_RandomUint16();
BE32value = SDLTest_RandomUint32();
BE64value = SDLTest_RandomUint64();
LE16value = SDLTest_RandomUint16();
LE32value = SDLTest_RandomUint32();
LE64value = SDLTest_RandomUint64();
break;
}
May 18, 2013
May 18, 2013
639
Jan 21, 2013
Jan 21, 2013
640
641
642
643
644
645
646
647
648
649
650
/* Write test. */
rw = SDL_RWFromFile(RWopsWriteTestFilename, "w+");
SDLTest_AssertPass("Call to SDL_RWFromFile(..,\"w+\")");
SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in write mode does not return NULL");
// Bail out if NULL
if (rw == NULL) return TEST_ABORTED;
/* Write test data */
objectsWritten = SDL_WriteBE16(rw, BE16value);
SDLTest_AssertPass("Call to SDL_WriteBE16");
May 18, 2013
May 18, 2013
651
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);
Jan 21, 2013
Jan 21, 2013
652
653
objectsWritten = SDL_WriteBE32(rw, BE32value);
SDLTest_AssertPass("Call to SDL_WriteBE32");
May 18, 2013
May 18, 2013
654
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);
Jan 21, 2013
Jan 21, 2013
655
656
objectsWritten = SDL_WriteBE64(rw, BE64value);
SDLTest_AssertPass("Call to SDL_WriteBE64");
May 18, 2013
May 18, 2013
657
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);
Jan 21, 2013
Jan 21, 2013
658
659
objectsWritten = SDL_WriteLE16(rw, LE16value);
SDLTest_AssertPass("Call to SDL_WriteLE16");
May 18, 2013
May 18, 2013
660
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);
Jan 21, 2013
Jan 21, 2013
661
662
objectsWritten = SDL_WriteLE32(rw, LE32value);
SDLTest_AssertPass("Call to SDL_WriteLE32");
May 18, 2013
May 18, 2013
663
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);
Jan 21, 2013
Jan 21, 2013
664
665
objectsWritten = SDL_WriteLE64(rw, LE64value);
SDLTest_AssertPass("Call to SDL_WriteLE64");
May 18, 2013
May 18, 2013
666
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);
Jan 21, 2013
Jan 21, 2013
667
668
669
670
671
672
673
674
675
676
677
678
/* Test seek to start */
result = SDL_RWseek( rw, 0, RW_SEEK_SET );
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
SDLTest_AssertCheck(result == 0, "Verify result from position 0 with SDL_RWseek, expected 0, got %i", result);
/* Read test data */
BE16test = SDL_ReadBE16(rw);
SDLTest_AssertPass("Call to SDL_ReadBE16");
SDLTest_AssertCheck(BE16test == BE16value, "Validate return value from SDL_ReadBE16, expected: %hu, got: %hu", BE16value, BE16test);
BE32test = SDL_ReadBE32(rw);
SDLTest_AssertPass("Call to SDL_ReadBE32");
May 18, 2013
May 18, 2013
679
SDLTest_AssertCheck(BE32test == BE32value, "Validate return value from SDL_ReadBE32, expected: %u, got: %u", BE32value, BE32test);
Jan 21, 2013
Jan 21, 2013
680
681
BE64test = SDL_ReadBE64(rw);
SDLTest_AssertPass("Call to SDL_ReadBE64");
May 18, 2013
May 18, 2013
682
SDLTest_AssertCheck(BE64test == BE64value, "Validate return value from SDL_ReadBE64, expected: %llu, got: %llu", BE64value, BE64test);
Jan 21, 2013
Jan 21, 2013
683
684
685
686
687
LE16test = SDL_ReadLE16(rw);
SDLTest_AssertPass("Call to SDL_ReadLE16");
SDLTest_AssertCheck(LE16test == LE16value, "Validate return value from SDL_ReadLE16, expected: %hu, got: %hu", LE16value, LE16test);
LE32test = SDL_ReadLE32(rw);
SDLTest_AssertPass("Call to SDL_ReadLE32");
May 18, 2013
May 18, 2013
688
SDLTest_AssertCheck(LE32test == LE32value, "Validate return value from SDL_ReadLE32, expected: %u, got: %u", LE32value, LE32test);
Jan 21, 2013
Jan 21, 2013
689
690
691
692
693
LE64test = SDL_ReadLE64(rw);
SDLTest_AssertPass("Call to SDL_ReadLE64");
SDLTest_AssertCheck(LE64test == LE64value, "Validate return value from SDL_ReadLE64, expected: %llu, got: %llu", LE64value, LE64test);
/* Close handle */
Mar 13, 2013
Mar 13, 2013
694
cresult = SDL_RWclose(rw);
Jan 21, 2013
Jan 21, 2013
695
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
May 18, 2013
May 18, 2013
696
SDLTest_AssertCheck(cresult == 0, "Verify result value is 0; got: %d", cresult);
Jan 21, 2013
Jan 21, 2013
697
698
699
700
701
}
return TEST_COMPLETED;
}
Dec 31, 2012
Dec 31, 2012
702
703
704
705
706
/* ================= Test References ================== */
/* RWops test cases */
static const SDLTest_TestCaseReference rwopsTest1 =
May 18, 2013
May 18, 2013
707
{ (SDLTest_TestCaseFp)rwops_testParamNegative, "rwops_testParamNegative", "Negative test for SDL_RWFromFile parameters", TEST_ENABLED };
708
709
static const SDLTest_TestCaseReference rwopsTest2 =
May 18, 2013
May 18, 2013
710
{ (SDLTest_TestCaseFp)rwops_testMem, "rwops_testMem", "Tests opening from memory", TEST_ENABLED };
711
712
static const SDLTest_TestCaseReference rwopsTest3 =
May 18, 2013
May 18, 2013
713
{ (SDLTest_TestCaseFp)rwops_testConstMem, "rwops_testConstMem", "Tests opening from (const) memory", TEST_ENABLED };
714
715
static const SDLTest_TestCaseReference rwopsTest4 =
May 18, 2013
May 18, 2013
716
{ (SDLTest_TestCaseFp)rwops_testFileRead, "rwops_testFileRead", "Tests reading from a file", TEST_ENABLED };
717
718
static const SDLTest_TestCaseReference rwopsTest5 =
May 18, 2013
May 18, 2013
719
{ (SDLTest_TestCaseFp)rwops_testFileWrite, "rwops_testFileWrite", "Test writing to a file", TEST_ENABLED };
720
721
static const SDLTest_TestCaseReference rwopsTest6 =
May 18, 2013
May 18, 2013
722
{ (SDLTest_TestCaseFp)rwops_testFPRead, "rwops_testFPRead", "Test reading from file pointer", TEST_ENABLED };
723
724
static const SDLTest_TestCaseReference rwopsTest7 =
May 18, 2013
May 18, 2013
725
{ (SDLTest_TestCaseFp)rwops_testFPWrite, "rwops_testFPWrite", "Test writing to file pointer", TEST_ENABLED };
Dec 31, 2012
Dec 31, 2012
727
static const SDLTest_TestCaseReference rwopsTest8 =
May 18, 2013
May 18, 2013
728
{ (SDLTest_TestCaseFp)rwops_testAllocFree, "rwops_testAllocFree", "Test alloc and free of RW context", TEST_ENABLED };
Dec 31, 2012
Dec 31, 2012
729
Jan 21, 2013
Jan 21, 2013
730
static const SDLTest_TestCaseReference rwopsTest9 =
May 18, 2013
May 18, 2013
731
{ (SDLTest_TestCaseFp)rwops_testFileWriteReadEndian, "rwops_testFileWriteReadEndian", "Test writing and reading via the Endian aware functions", TEST_ENABLED };
Jan 21, 2013
Jan 21, 2013
732
Mar 13, 2013
Mar 13, 2013
733
static const SDLTest_TestCaseReference rwopsTest10 =
May 18, 2013
May 18, 2013
734
{ (SDLTest_TestCaseFp)rwops_testCompareRWFromMemWithRWFromFile, "rwops_testCompareRWFromMemWithRWFromFile", "Compare RWFromMem and RWFromFile RWops for read and seek", TEST_ENABLED };
Mar 13, 2013
Mar 13, 2013
735
736
737
/* Sequence of RWops test cases */
static const SDLTest_TestCaseReference *rwopsTests[] = {
May 18, 2013
May 18, 2013
738
739
&rwopsTest1, &rwopsTest2, &rwopsTest3, &rwopsTest4, &rwopsTest5, &rwopsTest6,
&rwopsTest7, &rwopsTest8, &rwopsTest9, &rwopsTest10, NULL
740
741
742
743
};
/* RWops test suite (global) */
SDLTest_TestSuiteReference rwopsTestSuite = {
May 18, 2013
May 18, 2013
744
745
746
747
"RWops",
RWopsSetUp,
rwopsTests,
RWopsTearDown