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

Latest commit

 

History

History
70 lines (53 loc) · 1.37 KB

File metadata and controls

70 lines (53 loc) · 1.37 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* Automated SDL_RWops test.
*
* Written by Edgar Simo "bobbens"
*
* Released under Public Domain.
*/
#include "SDL.h"
#include "SDL_at.h"
static const char hello_world[] = "Hello World!";
/**
* @brief Tests opening from memory.
*/
static void rwops_testMem (void)
{
SDL_RWops *rw;
char mem[sizeof(hello_world)], buf[sizeof(hello_world)];
int i;
/* Begin testcase. */
SDL_ATbegin( "SDL_RWFromMem" );
/* Open. */
rw = SDL_RWFromMem( mem, sizeof(mem) );
if (SDL_ATassert( "Opening memory with SDL_RWFromMem", rw != NULL ))
return;
/* Test write. */
i = SDL_RWwrite( rw, hello_world, sizeof(hello_world), 1 );
if (SDL_ATassert( "Writing with SDL_RWwrite", i == 1 ))
return;
/* Test seek. */
i = SDL_RWseek( rw, 0, RW_SEEK_SET );
if (SDL_ATassert( "Seeking with SDL_RWseek", i == 0 ))
return;
/* Test read. */
i = SDL_RWread( rw, buf, sizeof(hello_world), 1 );
if (SDL_ATassert( "Reading with SDL_RWread", i == 1 ))
return;
if (SDL_ATassert( "Memory read does not match memory written",
memcmp( buf, hello_world, sizeof(hello_world) ) == 0 ))
return;
/* Close. */
SDL_FreeRW( rw );
/* End testcase. */
SDL_ATend();
}
/**
* @brief Entry point.
*/
int main( int argc, const char *argv[] )
{
SDL_ATinit( "SDL_RWops" );
rwops_testMem();
return SDL_ATfinish(1);
}