Mercurial > sdl-ios-xcode
comparison test/testplatform.c @ 1895:c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 10 Jul 2006 21:04:37 +0000 |
parents | f12379c41042 |
children | c9aa6bcb26f3 |
comparison
equal
deleted
inserted
replaced
1894:c69cee13dd76 | 1895:c121d94672cb |
---|---|
8 /* | 8 /* |
9 * Watcom C flags these as Warning 201: "Unreachable code" if you just | 9 * Watcom C flags these as Warning 201: "Unreachable code" if you just |
10 * compare them directly, so we push it through a function to keep the | 10 * compare them directly, so we push it through a function to keep the |
11 * compiler quiet. --ryan. | 11 * compiler quiet. --ryan. |
12 */ | 12 */ |
13 static int badsize(size_t sizeoftype, size_t hardcodetype) | 13 static int |
14 badsize(size_t sizeoftype, size_t hardcodetype) | |
14 { | 15 { |
15 return sizeoftype != hardcodetype; | 16 return sizeoftype != hardcodetype; |
16 } | 17 } |
17 | 18 |
18 int TestTypes(SDL_bool verbose) | 19 int |
19 { | 20 TestTypes(SDL_bool verbose) |
20 int error = 0; | 21 { |
21 | 22 int error = 0; |
22 if ( badsize(sizeof(Uint8), 1) ) { | 23 |
23 if ( verbose ) | 24 if (badsize(sizeof(Uint8), 1)) { |
24 printf("sizeof(Uint8) != 1, instead = %ul\n", | 25 if (verbose) |
25 sizeof(Uint8)); | 26 printf("sizeof(Uint8) != 1, instead = %ul\n", sizeof(Uint8)); |
26 ++error; | 27 ++error; |
27 } | 28 } |
28 if ( badsize(sizeof(Uint16), 2) ) { | 29 if (badsize(sizeof(Uint16), 2)) { |
29 if ( verbose ) | 30 if (verbose) |
30 printf("sizeof(Uint16) != 2, instead = %ul\n", | 31 printf("sizeof(Uint16) != 2, instead = %ul\n", sizeof(Uint16)); |
31 sizeof(Uint16)); | 32 ++error; |
32 ++error; | 33 } |
33 } | 34 if (badsize(sizeof(Uint32), 4)) { |
34 if ( badsize(sizeof(Uint32), 4) ) { | 35 if (verbose) |
35 if ( verbose ) | 36 printf("sizeof(Uint32) != 4, instead = %ul\n", sizeof(Uint32)); |
36 printf("sizeof(Uint32) != 4, instead = %ul\n", | 37 ++error; |
37 sizeof(Uint32)); | 38 } |
38 ++error; | |
39 } | |
40 #ifdef SDL_HAS_64BIT_TYPE | 39 #ifdef SDL_HAS_64BIT_TYPE |
41 if ( badsize(sizeof(Uint64), 8) ) { | 40 if (badsize(sizeof(Uint64), 8)) { |
42 if ( verbose ) | 41 if (verbose) |
43 printf("sizeof(Uint64) != 8, instead = %ul\n", | 42 printf("sizeof(Uint64) != 8, instead = %ul\n", sizeof(Uint64)); |
44 sizeof(Uint64)); | 43 ++error; |
45 ++error; | 44 } |
46 } | 45 #else |
47 #else | 46 if (verbose) { |
48 if ( verbose ) { | 47 printf("WARNING: No 64-bit datatype on this platform\n"); |
49 printf("WARNING: No 64-bit datatype on this platform\n"); | 48 } |
50 } | 49 #endif |
51 #endif | 50 if (verbose && !error) |
52 if ( verbose && !error ) | 51 printf("All data types are the expected size.\n"); |
53 printf("All data types are the expected size.\n"); | 52 |
54 | 53 return (error ? 1 : 0); |
55 return( error ? 1 : 0 ); | 54 } |
56 } | 55 |
57 | 56 int |
58 int TestEndian(SDL_bool verbose) | 57 TestEndian(SDL_bool verbose) |
59 { | 58 { |
60 int error = 0; | 59 int error = 0; |
61 Uint16 value = 0x1234; | 60 Uint16 value = 0x1234; |
62 int real_byteorder; | 61 int real_byteorder; |
63 Uint16 value16 = 0xCDAB; | 62 Uint16 value16 = 0xCDAB; |
64 Uint16 swapped16 = 0xABCD; | 63 Uint16 swapped16 = 0xABCD; |
65 Uint32 value32 = 0xEFBEADDE; | 64 Uint32 value32 = 0xEFBEADDE; |
66 Uint32 swapped32 = 0xDEADBEEF; | 65 Uint32 swapped32 = 0xDEADBEEF; |
67 #ifdef SDL_HAS_64BIT_TYPE | 66 #ifdef SDL_HAS_64BIT_TYPE |
68 Uint64 value64, swapped64; | 67 Uint64 value64, swapped64; |
69 value64 = 0xEFBEADDE; | 68 value64 = 0xEFBEADDE; |
70 value64 <<= 32; | 69 value64 <<= 32; |
71 value64 |= 0xCDAB3412; | 70 value64 |= 0xCDAB3412; |
72 swapped64 = 0x1234ABCD; | 71 swapped64 = 0x1234ABCD; |
73 swapped64 <<= 32; | 72 swapped64 <<= 32; |
74 swapped64 |= 0xDEADBEEF; | 73 swapped64 |= 0xDEADBEEF; |
75 #endif | 74 #endif |
76 | 75 |
77 if ( verbose ) { | 76 if (verbose) { |
78 printf("Detected a %s endian machine.\n", | 77 printf("Detected a %s endian machine.\n", |
79 (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big"); | 78 (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big"); |
80 } | 79 } |
81 if ( (*((char *)&value) >> 4) == 0x1 ) { | 80 if ((*((char *) &value) >> 4) == 0x1) { |
82 real_byteorder = SDL_BIG_ENDIAN; | 81 real_byteorder = SDL_BIG_ENDIAN; |
83 } else { | 82 } else { |
84 real_byteorder = SDL_LIL_ENDIAN; | 83 real_byteorder = SDL_LIL_ENDIAN; |
85 } | 84 } |
86 if ( real_byteorder != SDL_BYTEORDER ) { | 85 if (real_byteorder != SDL_BYTEORDER) { |
87 if ( verbose ) { | 86 if (verbose) { |
88 printf("Actually a %s endian machine!\n", | 87 printf("Actually a %s endian machine!\n", |
89 (real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big"); | 88 (real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big"); |
90 } | 89 } |
91 ++error; | 90 ++error; |
92 } | 91 } |
93 if ( verbose ) { | 92 if (verbose) { |
94 printf("Value 16 = 0x%X, swapped = 0x%X\n", value16, SDL_Swap16(value16)); | 93 printf("Value 16 = 0x%X, swapped = 0x%X\n", value16, |
95 } | 94 SDL_Swap16(value16)); |
96 if ( SDL_Swap16(value16) != swapped16 ) { | 95 } |
97 if ( verbose ) { | 96 if (SDL_Swap16(value16) != swapped16) { |
98 printf("16 bit value swapped incorrectly!\n"); | 97 if (verbose) { |
99 } | 98 printf("16 bit value swapped incorrectly!\n"); |
100 ++error; | 99 } |
101 } | 100 ++error; |
102 if ( verbose ) { | 101 } |
103 printf("Value 32 = 0x%X, swapped = 0x%X\n", value32, SDL_Swap32(value32)); | 102 if (verbose) { |
104 } | 103 printf("Value 32 = 0x%X, swapped = 0x%X\n", value32, |
105 if ( SDL_Swap32(value32) != swapped32 ) { | 104 SDL_Swap32(value32)); |
106 if ( verbose ) { | 105 } |
107 printf("32 bit value swapped incorrectly!\n"); | 106 if (SDL_Swap32(value32) != swapped32) { |
108 } | 107 if (verbose) { |
109 ++error; | 108 printf("32 bit value swapped incorrectly!\n"); |
110 } | 109 } |
110 ++error; | |
111 } | |
111 #ifdef SDL_HAS_64BIT_TYPE | 112 #ifdef SDL_HAS_64BIT_TYPE |
112 if ( verbose ) { | 113 if (verbose) { |
113 #ifdef _MSC_VER | 114 #ifdef _MSC_VER |
114 printf("Value 64 = 0x%I64X, swapped = 0x%I64X\n", value64, SDL_Swap64(value64)); | 115 printf("Value 64 = 0x%I64X, swapped = 0x%I64X\n", value64, |
115 #else | 116 SDL_Swap64(value64)); |
116 printf("Value 64 = 0x%llX, swapped = 0x%llX\n", value64, SDL_Swap64(value64)); | 117 #else |
117 #endif | 118 printf("Value 64 = 0x%llX, swapped = 0x%llX\n", value64, |
118 } | 119 SDL_Swap64(value64)); |
119 if ( SDL_Swap64(value64) != swapped64 ) { | 120 #endif |
120 if ( verbose ) { | 121 } |
121 printf("64 bit value swapped incorrectly!\n"); | 122 if (SDL_Swap64(value64) != swapped64) { |
122 } | 123 if (verbose) { |
123 ++error; | 124 printf("64 bit value swapped incorrectly!\n"); |
124 } | 125 } |
125 #endif | 126 ++error; |
126 return( error ? 1 : 0 ); | 127 } |
127 } | 128 #endif |
128 | 129 return (error ? 1 : 0); |
129 | 130 } |
130 int TestCPUInfo(SDL_bool verbose) | 131 |
131 { | 132 |
132 if ( verbose ) { | 133 int |
133 printf("RDTSC %s\n", SDL_HasRDTSC() ? "detected" : "not detected"); | 134 TestCPUInfo(SDL_bool verbose) |
134 printf("MMX %s\n", SDL_HasMMX() ? "detected" : "not detected"); | 135 { |
135 printf("MMX Ext %s\n", SDL_HasMMXExt() ? "detected" : "not detected"); | 136 if (verbose) { |
136 printf("3DNow %s\n", SDL_Has3DNow() ? "detected" : "not detected"); | 137 printf("RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected"); |
137 printf("3DNow Ext %s\n", SDL_Has3DNowExt() ? "detected" : "not detected"); | 138 printf("MMX %s\n", SDL_HasMMX()? "detected" : "not detected"); |
138 printf("SSE %s\n", SDL_HasSSE() ? "detected" : "not detected"); | 139 printf("MMX Ext %s\n", SDL_HasMMXExt()? "detected" : "not detected"); |
139 printf("SSE2 %s\n", SDL_HasSSE2() ? "detected" : "not detected"); | 140 printf("3DNow %s\n", SDL_Has3DNow()? "detected" : "not detected"); |
140 printf("AltiVec %s\n", SDL_HasAltiVec() ? "detected" : "not detected"); | 141 printf("3DNow Ext %s\n", |
141 } | 142 SDL_Has3DNowExt()? "detected" : "not detected"); |
142 return(0); | 143 printf("SSE %s\n", SDL_HasSSE()? "detected" : "not detected"); |
143 } | 144 printf("SSE2 %s\n", SDL_HasSSE2()? "detected" : "not detected"); |
144 | 145 printf("AltiVec %s\n", SDL_HasAltiVec()? "detected" : "not detected"); |
145 int main(int argc, char *argv[]) | 146 } |
146 { | 147 return (0); |
147 SDL_bool verbose = SDL_TRUE; | 148 } |
148 int status = 0; | 149 |
149 | 150 int |
150 if ( argv[1] && (SDL_strcmp(argv[1], "-q") == 0) ) { | 151 main(int argc, char *argv[]) |
151 verbose = SDL_FALSE; | 152 { |
152 } | 153 SDL_bool verbose = SDL_TRUE; |
153 if ( verbose ) { | 154 int status = 0; |
154 printf("This system is running %s\n", | 155 |
156 if (argv[1] && (SDL_strcmp(argv[1], "-q") == 0)) { | |
157 verbose = SDL_FALSE; | |
158 } | |
159 if (verbose) { | |
160 printf("This system is running %s\n", | |
155 #if __AIX__ | 161 #if __AIX__ |
156 "AIX" | 162 "AIX" |
157 #elif __AMIGA__ | 163 #elif __AMIGA__ |
158 "AmigaOS" | 164 "AmigaOS" |
159 #elif __BEOS__ | 165 #elif __BEOS__ |
160 "BeOS" | 166 "BeOS" |
161 #elif __BSDI__ | 167 #elif __BSDI__ |
162 "BSDI" | 168 "BSDI" |
163 #elif __DREAMCAST__ | 169 #elif __DREAMCAST__ |
164 "Dreamcast" | 170 "Dreamcast" |
165 #elif __FREEBSD__ | 171 #elif __FREEBSD__ |
166 "FreeBSD" | 172 "FreeBSD" |
167 #elif __HPUX__ | 173 #elif __HPUX__ |
168 "HP-UX" | 174 "HP-UX" |
169 #elif __IRIX__ | 175 #elif __IRIX__ |
170 "Irix" | 176 "Irix" |
171 #elif __LINUX__ | 177 #elif __LINUX__ |
172 "Linux" | 178 "Linux" |
173 #elif __MINT__ | 179 #elif __MINT__ |
174 "Atari MiNT" | 180 "Atari MiNT" |
175 #elif __MACOS__ | 181 #elif __MACOS__ |
176 "MacOS Classic" | 182 "MacOS Classic" |
177 #elif __MACOSX__ | 183 #elif __MACOSX__ |
178 "Mac OS X" | 184 "Mac OS X" |
179 #elif __NETBSD__ | 185 #elif __NETBSD__ |
180 "NetBSD" | 186 "NetBSD" |
181 #elif __OPENBSD__ | 187 #elif __OPENBSD__ |
182 "OpenBSD" | 188 "OpenBSD" |
183 #elif __OS2__ | 189 #elif __OS2__ |
184 "OS/2" | 190 "OS/2" |
185 #elif __OSF__ | 191 #elif __OSF__ |
186 "OSF/1" | 192 "OSF/1" |
187 #elif __QNXNTO__ | 193 #elif __QNXNTO__ |
188 "QNX Neutrino" | 194 "QNX Neutrino" |
189 #elif __RISCOS__ | 195 #elif __RISCOS__ |
190 "RISC OS" | 196 "RISC OS" |
191 #elif __SOLARIS__ | 197 #elif __SOLARIS__ |
192 "Solaris" | 198 "Solaris" |
193 #elif __WIN32__ | 199 #elif __WIN32__ |
194 #ifdef _WIN32_WCE | 200 #ifdef _WIN32_WCE |
195 "Windows CE" | 201 "Windows CE" |
196 #else | 202 #else |
197 "Windows" | 203 "Windows" |
198 #endif | 204 #endif |
199 #else | 205 #else |
200 "an unknown operating system! (see SDL_platform.h)" | 206 "an unknown operating system! (see SDL_platform.h)" |
201 #endif | 207 #endif |
202 ); | 208 ); |
203 } | 209 } |
204 | 210 |
205 status += TestTypes(verbose); | 211 status += TestTypes(verbose); |
206 status += TestEndian(verbose); | 212 status += TestEndian(verbose); |
207 status += TestCPUInfo(verbose); | 213 status += TestCPUInfo(verbose); |
208 return status; | 214 return status; |
209 } | 215 } |