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

Latest commit

 

History

History
561 lines (473 loc) · 16 KB

testautomation_platform.c

File metadata and controls

561 lines (473 loc) · 16 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
* Original code: automated SDL platform test written by Edgar Simo "bobbens"
* Extended and updated by aschiffler at ferzkopp dot net
*/
#include <stdio.h>
#include "SDL.h"
#include "SDL_test.h"
/* ================= Test Case Implementation ================== */
/* Helper functions */
/**
* @brief Compare sizes of types.
*
* @note Watcom C flags these as Warning 201: "Unreachable code" if you just
* compare them directly, so we push it through a function to keep the
* compiler quiet. --ryan.
*/
static int _compareSizeOfType( size_t sizeoftype, size_t hardcodetype )
{
return sizeoftype != hardcodetype;
}
/* Test case functions */
/**
* @brief Tests type sizes.
*/
int platform_testTypes(void *arg)
{
int ret;
ret = _compareSizeOfType( sizeof(Uint8), 1 );
SDLTest_AssertCheck( ret == 0, "sizeof(Uint8) = %lu, expected 1", sizeof(Uint8) );
ret = _compareSizeOfType( sizeof(Uint16), 2 );
SDLTest_AssertCheck( ret == 0, "sizeof(Uint16) = %lu, expected 2", sizeof(Uint16) );
ret = _compareSizeOfType( sizeof(Uint32), 4 );
SDLTest_AssertCheck( ret == 0, "sizeof(Uint32) = %lu, expected 4", sizeof(Uint32) );
ret = _compareSizeOfType( sizeof(Uint64), 8 );
SDLTest_AssertCheck( ret == 0, "sizeof(Uint64) = %lu, expected 8", sizeof(Uint64) );
return TEST_COMPLETED;
}
/**
* @brief Tests platform endianness and SDL_SwapXY functions.
*/
int platform_testEndianessAndSwap(void *arg)
{
int real_byteorder;
Uint16 value = 0x1234;
Uint16 value16 = 0xCDAB;
Uint16 swapped16 = 0xABCD;
Uint32 value32 = 0xEFBEADDE;
Uint32 swapped32 = 0xDEADBEEF;
Uint64 value64, swapped64;
value64 = 0xEFBEADDE;
value64 <<= 32;
value64 |= 0xCDAB3412;
swapped64 = 0x1234ABCD;
swapped64 <<= 32;
swapped64 |= 0xDEADBEEF;
if ((*((char *) &value) >> 4) == 0x1) {
real_byteorder = SDL_BIG_ENDIAN;
} else {
real_byteorder = SDL_LIL_ENDIAN;
}
/* Test endianness. */
SDLTest_AssertCheck( real_byteorder == SDL_BYTEORDER,
"Machine detected as %s endian, appears to be %s endian.",
(SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big",
(real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big" );
/* Test 16 swap. */
SDLTest_AssertCheck( SDL_Swap16(value16) == swapped16,
"SDL_Swap16(): 16 bit swapped: 0x%X => 0x%X",
value16, SDL_Swap16(value16) );
/* Test 32 swap. */
SDLTest_AssertCheck( SDL_Swap32(value32) == swapped32,
"SDL_Swap32(): 32 bit swapped: 0x%X => 0x%X",
value32, SDL_Swap32(value32) );
/* Test 64 swap. */
SDLTest_AssertCheck( SDL_Swap64(value64) == swapped64,
#ifdef _MSC_VER
"SDL_Swap64(): 64 bit swapped: 0x%I64X => 0x%I64X",
#else
"SDL_Swap64(): 64 bit swapped: 0x%llX => 0x%llX",
#endif
value64, SDL_Swap64(value64) );
return TEST_COMPLETED;
}
/*!
* \brief Tests SDL_GetXYZ() functions
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_GetPlatform
* http://wiki.libsdl.org/moin.cgi/SDL_GetCPUCount
* http://wiki.libsdl.org/moin.cgi/SDL_GetCPUCacheLineSize
* http://wiki.libsdl.org/moin.cgi/SDL_GetRevision
* http://wiki.libsdl.org/moin.cgi/SDL_GetRevisionNumber
*/
int platform_testGetFunctions (void *arg)
{
char *platform;
char *revision;
int ret;
int len;
platform = (char *)SDL_GetPlatform();
SDLTest_AssertPass("SDL_GetPlatform()");
SDLTest_AssertCheck(platform != NULL, "SDL_GetPlatform() != NULL");
if (platform != NULL) {
Dec 30, 2012
Dec 30, 2012
125
len = SDL_strlen(platform);
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
SDLTest_AssertCheck(len > 0,
"SDL_GetPlatform(): expected non-empty platform, was platform: '%s', len: %i",
platform,
len);
}
ret = SDL_GetCPUCount();
SDLTest_AssertPass("SDL_GetCPUCount()");
SDLTest_AssertCheck(ret > 0,
"SDL_GetCPUCount(): expected count > 0, was: %i",
ret);
ret = SDL_GetCPUCacheLineSize();
SDLTest_AssertPass("SDL_GetCPUCacheLineSize()");
SDLTest_AssertCheck(ret >= 0,
"SDL_GetCPUCacheLineSize(): expected size >= 0, was: %i",
ret);
revision = (char *)SDL_GetRevision();
SDLTest_AssertPass("SDL_GetRevision()");
SDLTest_AssertCheck(revision != NULL, "SDL_GetRevision() != NULL");
ret = SDL_GetRevisionNumber();
SDLTest_AssertPass("SDL_GetRevisionNumber()");
return TEST_COMPLETED;
}
/*!
* \brief Tests SDL_HasXYZ() functions
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_Has3DNow
* http://wiki.libsdl.org/moin.cgi/SDL_HasAltiVec
* http://wiki.libsdl.org/moin.cgi/SDL_HasMMX
* http://wiki.libsdl.org/moin.cgi/SDL_HasRDTSC
* http://wiki.libsdl.org/moin.cgi/SDL_HasSSE
* http://wiki.libsdl.org/moin.cgi/SDL_HasSSE2
* http://wiki.libsdl.org/moin.cgi/SDL_HasSSE3
* http://wiki.libsdl.org/moin.cgi/SDL_HasSSE41
* http://wiki.libsdl.org/moin.cgi/SDL_HasSSE42
*/
int platform_testHasFunctions (void *arg)
{
int ret;
// TODO: independently determine and compare values as well
ret = SDL_HasRDTSC();
SDLTest_AssertPass("SDL_HasRDTSC()");
ret = SDL_HasAltiVec();
SDLTest_AssertPass("SDL_HasAltiVec()");
ret = SDL_HasMMX();
SDLTest_AssertPass("SDL_HasMMX()");
ret = SDL_Has3DNow();
SDLTest_AssertPass("SDL_Has3DNow()");
ret = SDL_HasSSE();
SDLTest_AssertPass("SDL_HasSSE()");
ret = SDL_HasSSE2();
SDLTest_AssertPass("SDL_HasSSE2()");
ret = SDL_HasSSE3();
SDLTest_AssertPass("SDL_HasSSE3()");
ret = SDL_HasSSE41();
SDLTest_AssertPass("SDL_HasSSE41()");
ret = SDL_HasSSE42();
SDLTest_AssertPass("SDL_HasSSE42()");
return TEST_COMPLETED;
}
/*!
* \brief Tests SDL_GetVersion
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_GetVersion
*/
int platform_testGetVersion(void *arg)
{
SDL_version linked;
int major = SDL_MAJOR_VERSION;
int minor = SDL_MINOR_VERSION;
SDL_GetVersion(&linked);
SDLTest_AssertCheck( linked.major >= major,
"SDL_GetVersion(): returned major %i (>= %i)",
linked.major,
major);
SDLTest_AssertCheck( linked.minor >= minor,
"SDL_GetVersion(): returned minor %i (>= %i)",
linked.minor,
minor);
return TEST_COMPLETED;
}
/*!
* \brief Tests SDL_VERSION macro
*/
int platform_testSDLVersion(void *arg)
{
SDL_version compiled;
int major = SDL_MAJOR_VERSION;
int minor = SDL_MINOR_VERSION;
SDL_VERSION(&compiled);
SDLTest_AssertCheck( compiled.major >= major,
"SDL_VERSION() returned major %i (>= %i)",
compiled.major,
major);
SDLTest_AssertCheck( compiled.minor >= minor,
"SDL_VERSION() returned minor %i (>= %i)",
compiled.minor,
minor);
return TEST_COMPLETED;
}
/*!
* \brief Tests default SDL_Init
*/
int platform_testDefaultInit(void *arg)
{
int ret;
int subsystem;
subsystem = SDL_WasInit(SDL_INIT_EVERYTHING);
SDLTest_AssertCheck( subsystem != 0,
"SDL_WasInit(0): returned %i, expected != 0",
subsystem);
ret = SDL_Init(SDL_WasInit(SDL_INIT_EVERYTHING));
SDLTest_AssertCheck( ret == 0,
"SDL_Init(0): returned %i, expected 0, error: %s",
ret,
SDL_GetError());
return TEST_COMPLETED;
}
/*!
* \brief Tests SDL_Get/Set/ClearError
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_GetError
* http://wiki.libsdl.org/moin.cgi/SDL_SetError
* http://wiki.libsdl.org/moin.cgi/SDL_ClearError
*/
int platform_testGetSetClearError(void *arg)
{
const char *testError = "Testing";
char *lastError;
int len;
SDL_ClearError();
SDLTest_AssertPass("SDL_ClearError()");
lastError = (char *)SDL_GetError();
SDLTest_AssertPass("SDL_GetError()");
SDLTest_AssertCheck(lastError != NULL,
"SDL_GetError() != NULL");
if (lastError != NULL)
{
Dec 30, 2012
Dec 30, 2012
295
len = SDL_strlen(lastError);
296
297
298
299
300
301
302
303
304
305
306
SDLTest_AssertCheck(len == 0,
"SDL_GetError(): no message expected, len: %i", len);
}
SDL_SetError("%s", testError);
SDLTest_AssertPass("SDL_SetError()");
lastError = (char *)SDL_GetError();
SDLTest_AssertCheck(lastError != NULL,
"SDL_GetError() != NULL");
if (lastError != NULL)
{
Dec 30, 2012
Dec 30, 2012
307
308
len = SDL_strlen(lastError);
SDLTest_AssertCheck(len == SDL_strlen(testError),
309
"SDL_GetError(): expected message len %i, was len: %i",
Dec 30, 2012
Dec 30, 2012
310
SDL_strlen(testError),
Dec 30, 2012
Dec 30, 2012
312
SDLTest_AssertCheck(SDL_strcmp(lastError, testError) == 0,
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
"SDL_GetError(): expected message %s, was message: %s",
testError,
lastError);
}
// Clean up
SDL_ClearError();
SDLTest_AssertPass("SDL_ClearError()");
return TEST_COMPLETED;
}
/*!
* \brief Tests SDL_SetError with empty input
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_SetError
*/
int platform_testSetErrorEmptyInput(void *arg)
{
const char *testError = "";
char *lastError;
int len;
SDL_SetError("%s", testError);
SDLTest_AssertPass("SDL_SetError()");
lastError = (char *)SDL_GetError();
SDLTest_AssertCheck(lastError != NULL,
"SDL_GetError() != NULL");
if (lastError != NULL)
{
Dec 30, 2012
Dec 30, 2012
343
344
len = SDL_strlen(lastError);
SDLTest_AssertCheck(len == SDL_strlen(testError),
345
"SDL_GetError(): expected message len %i, was len: %i",
Dec 30, 2012
Dec 30, 2012
346
SDL_strlen(testError),
Dec 30, 2012
Dec 30, 2012
348
SDLTest_AssertCheck(SDL_strcmp(lastError, testError) == 0,
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
"SDL_GetError(): expected message '%s', was message: '%s'",
testError,
lastError);
}
// Clean up
SDL_ClearError();
SDLTest_AssertPass("SDL_ClearError()");
return TEST_COMPLETED;
}
/*!
* \brief Tests SDL_SetError with invalid input
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_SetError
*/
int platform_testSetErrorInvalidInput(void *arg)
{
const char *testError = NULL;
const char *probeError = "Testing";
char *lastError;
int len;
// Reset
SDL_ClearError();
SDLTest_AssertPass("SDL_ClearError()");
// Check for no-op
SDL_SetError(testError);
SDLTest_AssertPass("SDL_SetError()");
lastError = (char *)SDL_GetError();
SDLTest_AssertCheck(lastError != NULL,
"SDL_GetError() != NULL");
if (lastError != NULL)
{
Dec 30, 2012
Dec 30, 2012
385
len = SDL_strlen(lastError);
386
387
388
389
SDLTest_AssertCheck(len == 0,
"SDL_GetError(): expected message len 0, was len: %i",
0,
len);
Dec 30, 2012
Dec 30, 2012
390
SDLTest_AssertCheck(SDL_strcmp(lastError, "") == 0,
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
"SDL_GetError(): expected message '', was message: '%s'",
lastError);
}
// Set
SDL_SetError(probeError);
SDLTest_AssertPass("SDL_SetError()");
// Check for no-op
SDL_SetError(testError);
SDLTest_AssertPass("SDL_SetError()");
lastError = (char *)SDL_GetError();
SDLTest_AssertCheck(lastError != NULL,
"SDL_GetError() != NULL");
if (lastError != NULL)
{
Dec 30, 2012
Dec 30, 2012
407
408
len = SDL_strlen(lastError);
SDLTest_AssertCheck(len == SDL_strlen(probeError),
409
"SDL_GetError(): expected message len %i, was len: %i",
Dec 30, 2012
Dec 30, 2012
410
SDL_strlen(probeError),
Dec 30, 2012
Dec 30, 2012
412
SDLTest_AssertCheck(SDL_strcmp(lastError, probeError) == 0,
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
"SDL_GetError(): expected message '%s', was message: '%s'",
probeError,
lastError);
}
// Clean up
SDL_ClearError();
SDLTest_AssertPass("SDL_ClearError()");
return TEST_COMPLETED;
}
/*!
* \brief Tests SDL_GetPowerInfo
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_GetPowerInfo
*/
int platform_testGetPowerInfo(void *arg)
{
SDL_PowerState state;
SDL_PowerState stateAgain;
int secs;
int secsAgain;
int pct;
int pctAgain;
state = SDL_GetPowerInfo(&secs, &pct);
SDLTest_AssertPass("SDL_GetPowerInfo()");
SDLTest_AssertCheck(
state==SDL_POWERSTATE_UNKNOWN ||
state==SDL_POWERSTATE_ON_BATTERY ||
state==SDL_POWERSTATE_NO_BATTERY ||
state==SDL_POWERSTATE_CHARGING ||
state==SDL_POWERSTATE_CHARGED,
"SDL_GetPowerInfo(): state %i is one of the expected values",
(int)state);
if (state==SDL_POWERSTATE_ON_BATTERY)
{
SDLTest_AssertCheck(
secs >= 0,
"SDL_GetPowerInfo(): on battery, secs >= 0, was: %i",
secs);
SDLTest_AssertCheck(
(pct >= 0) && (pct <= 100),
"SDL_GetPowerInfo(): on battery, pct=[0,100], was: %i",
pct);
}
if (state==SDL_POWERSTATE_UNKNOWN ||
state==SDL_POWERSTATE_NO_BATTERY)
{
SDLTest_AssertCheck(
secs == -1,
"SDL_GetPowerInfo(): no battery, secs == -1, was: %i",
secs);
SDLTest_AssertCheck(
pct == -1,
"SDL_GetPowerInfo(): no battery, pct == -1, was: %i",
pct);
}
// Partial return value variations
stateAgain = SDL_GetPowerInfo(&secsAgain, NULL);
SDLTest_AssertCheck(
state==stateAgain,
"State %i returned when only 'secs' requested",
stateAgain);
SDLTest_AssertCheck(
secs==secsAgain,
"Value %i matches when only 'secs' requested",
secsAgain);
stateAgain = SDL_GetPowerInfo(NULL, &pctAgain);
SDLTest_AssertCheck(
state==stateAgain,
"State %i returned when only 'pct' requested",
stateAgain);
SDLTest_AssertCheck(
pct==pctAgain,
"Value %i matches when only 'pct' requested",
pctAgain);
stateAgain = SDL_GetPowerInfo(NULL, NULL);
SDLTest_AssertCheck(
state==stateAgain,
"State %i returned when no value requested",
stateAgain);
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Platform test cases */
static const SDLTest_TestCaseReference platformTest1 =
May 18, 2013
May 18, 2013
507
{ (SDLTest_TestCaseFp)platform_testTypes, "platform_testTypes", "Tests predefined types", TEST_ENABLED};
508
509
static const SDLTest_TestCaseReference platformTest2 =
May 18, 2013
May 18, 2013
510
{ (SDLTest_TestCaseFp)platform_testEndianessAndSwap, "platform_testEndianessAndSwap", "Tests endianess and swap functions", TEST_ENABLED};
511
512
static const SDLTest_TestCaseReference platformTest3 =
May 18, 2013
May 18, 2013
513
{ (SDLTest_TestCaseFp)platform_testGetFunctions, "platform_testGetFunctions", "Tests various SDL_GetXYZ functions", TEST_ENABLED};
514
515
static const SDLTest_TestCaseReference platformTest4 =
May 18, 2013
May 18, 2013
516
{ (SDLTest_TestCaseFp)platform_testHasFunctions, "platform_testHasFunctions", "Tests various SDL_HasXYZ functions", TEST_ENABLED};
517
518
static const SDLTest_TestCaseReference platformTest5 =
May 18, 2013
May 18, 2013
519
{ (SDLTest_TestCaseFp)platform_testGetVersion, "platform_testGetVersion", "Tests SDL_GetVersion function", TEST_ENABLED};
520
521
static const SDLTest_TestCaseReference platformTest6 =
May 18, 2013
May 18, 2013
522
{ (SDLTest_TestCaseFp)platform_testSDLVersion, "platform_testSDLVersion", "Tests SDL_VERSION macro", TEST_ENABLED};
523
524
static const SDLTest_TestCaseReference platformTest7 =
May 18, 2013
May 18, 2013
525
{ (SDLTest_TestCaseFp)platform_testDefaultInit, "platform_testDefaultInit", "Tests default SDL_Init", TEST_ENABLED};
526
527
static const SDLTest_TestCaseReference platformTest8 =
May 18, 2013
May 18, 2013
528
{ (SDLTest_TestCaseFp)platform_testGetSetClearError, "platform_testGetSetClearError", "Tests SDL_Get/Set/ClearError", TEST_ENABLED};
529
530
static const SDLTest_TestCaseReference platformTest9 =
May 18, 2013
May 18, 2013
531
{ (SDLTest_TestCaseFp)platform_testSetErrorEmptyInput, "platform_testSetErrorEmptyInput", "Tests SDL_SetError with empty input", TEST_ENABLED};
532
533
static const SDLTest_TestCaseReference platformTest10 =
May 18, 2013
May 18, 2013
534
{ (SDLTest_TestCaseFp)platform_testSetErrorInvalidInput, "platform_testSetErrorInvalidInput", "Tests SDL_SetError with invalid input", TEST_ENABLED};
535
536
static const SDLTest_TestCaseReference platformTest11 =
May 18, 2013
May 18, 2013
537
{ (SDLTest_TestCaseFp)platform_testGetPowerInfo, "platform_testGetPowerInfo", "Tests SDL_GetPowerInfo function", TEST_ENABLED };
538
539
540
/* Sequence of Platform test cases */
static const SDLTest_TestCaseReference *platformTests[] = {
May 18, 2013
May 18, 2013
541
542
543
544
545
546
547
548
549
550
551
552
&platformTest1,
&platformTest2,
&platformTest3,
&platformTest4,
&platformTest5,
&platformTest6,
&platformTest7,
&platformTest8,
&platformTest9,
&platformTest10,
&platformTest11,
NULL
553
554
555
556
};
/* Platform test suite (global) */
SDLTest_TestSuiteReference platformTestSuite = {
May 18, 2013
May 18, 2013
557
558
559
560
"Platform",
NULL,
platformTests,
NULL