Mercurial > sdl-ios-xcode
comparison test/automated/platform/platform.c @ 3736:78f544eded7b gsoc2009_unit_tests
Added platform test based ot testplatform.c.
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Mon, 20 Jul 2009 18:42:55 +0000 |
parents | |
children | e451d5d288e9 |
comparison
equal
deleted
inserted
replaced
3735:27b4b4d71011 | 3736:78f544eded7b |
---|---|
1 /** | |
2 * Automated SDL platform test. | |
3 * | |
4 * Based off of testplatform.c. | |
5 * | |
6 * Written by Edgar Simo "bobbens" | |
7 * | |
8 * Released under Public Domain. | |
9 */ | |
10 | |
11 | |
12 | |
13 | |
14 #include "SDL.h" | |
15 #include "SDL_at.h" | |
16 #include "SDL_endian.h" | |
17 #include "SDL_cpuinfo.h" | |
18 | |
19 | |
20 /* | |
21 * Prototypes. | |
22 */ | |
23 static int plat_testSize( size_t sizeoftype, size_t hardcodetype ); | |
24 static void plat_testTypes (void); | |
25 | |
26 | |
27 /** | |
28 * @brief Test size. | |
29 * | |
30 * @note Watcom C flags these as Warning 201: "Unreachable code" if you just | |
31 * compare them directly, so we push it through a function to keep the | |
32 * compiler quiet. --ryan. | |
33 */ | |
34 static int plat_testSize( size_t sizeoftype, size_t hardcodetype ) | |
35 { | |
36 return sizeoftype != hardcodetype; | |
37 } | |
38 | |
39 | |
40 /** | |
41 * @brief Tests type size. | |
42 */ | |
43 static void plat_testTypes (void) | |
44 { | |
45 int ret; | |
46 | |
47 SDL_ATbegin( "Type size" ); | |
48 | |
49 ret = plat_testSize( sizeof(Uint8), 1 ); | |
50 if (SDL_ATvassert( ret == 0, "sizeof(Uint8) = %ul instead of 1", sizeof(Uint8) )) | |
51 return; | |
52 | |
53 ret = plat_testSize( sizeof(Uint16), 2 ); | |
54 if (SDL_ATvassert( ret == 0, "sizeof(Uint16) = %ul instead of 2", sizeof(Uint16) )) | |
55 return; | |
56 | |
57 ret = plat_testSize( sizeof(Uint32), 4 ); | |
58 if (SDL_ATvassert( ret == 0, "sizeof(Uint32) = %ul instead of 4", sizeof(Uint32) )) | |
59 return; | |
60 | |
61 #ifdef SDL_HAS_64BIT_TYPE | |
62 ret = plat_testSize( sizeof(Uint64), 8 ); | |
63 if (SDL_ATvassert( ret == 0, "sizeof(Uint64) = %ul instead of 8", sizeof(Uint64) )) | |
64 return; | |
65 #endif /* SDL_HAS_64BIT_TYPE */ | |
66 | |
67 SDL_ATend(); | |
68 } | |
69 | |
70 | |
71 /** | |
72 * @brief Tests platform endianness. | |
73 */ | |
74 static void plat_testEndian (void) | |
75 { | |
76 Uint16 value = 0x1234; | |
77 int real_byteorder; | |
78 Uint16 value16 = 0xCDAB; | |
79 Uint16 swapped16 = 0xABCD; | |
80 Uint32 value32 = 0xEFBEADDE; | |
81 Uint32 swapped32 = 0xDEADBEEF; | |
82 #ifdef SDL_HAS_64BIT_TYPE | |
83 Uint64 value64, swapped64; | |
84 value64 = 0xEFBEADDE; | |
85 value64 <<= 32; | |
86 value64 |= 0xCDAB3412; | |
87 swapped64 = 0x1234ABCD; | |
88 swapped64 <<= 32; | |
89 swapped64 |= 0xDEADBEEF; | |
90 #endif | |
91 | |
92 SDL_ATbegin( "Endianness" ); | |
93 | |
94 /* Test endianness. */ | |
95 if ((*((char *) &value) >> 4) == 0x1) { | |
96 real_byteorder = SDL_BIG_ENDIAN; | |
97 } else { | |
98 real_byteorder = SDL_LIL_ENDIAN; | |
99 } | |
100 if (SDL_ATvassert( real_byteorder == SDL_BYTEORDER, | |
101 "Machine detected as %s endian but appears to be %s endian.", | |
102 (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big", | |
103 (real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big" )) | |
104 return; | |
105 | |
106 /* Test 16 swap. */ | |
107 if (SDL_ATvassert( SDL_Swap16(value16) == swapped16, | |
108 "16 bit swapped incorrectly: 0x%X => 0x%X", | |
109 value16, SDL_Swap16(value16) )) | |
110 return; | |
111 | |
112 /* Test 32 swap. */ | |
113 if (SDL_ATvassert( SDL_Swap32(value32) == swapped32, | |
114 "32 bit swapped incorrectly: 0x%X => 0x%X", | |
115 value32, SDL_Swap32(value32) )) | |
116 return; | |
117 | |
118 #ifdef SDL_HAS_64BIT_TYPE | |
119 /* Test 64 swap. */ | |
120 if (SDL_ATvassert( SDL_Swap64(value64) == swapped64, | |
121 #ifdef _MSC_VER | |
122 "64 bit swapped incorrectly: 0x%I64X => 0x%I64X", | |
123 #else | |
124 "64 bit swapped incorrectly: 0x%llX => 0x%llX", | |
125 #endif | |
126 value64, SDL_Swap64(value64) )) | |
127 return; | |
128 #endif | |
129 | |
130 SDL_ATend(); | |
131 } | |
132 | |
133 | |
134 int main(int argc, char *argv[]) | |
135 { | |
136 (void) argc; | |
137 (void) argv; | |
138 | |
139 SDL_ATinit( "Platform" ); | |
140 | |
141 plat_testTypes(); | |
142 plat_testEndian(); | |
143 | |
144 return SDL_ATfinish(1); | |
145 } |