Expanded and updated testplatform suite.
This commit is contained in:
parent
254a81687d
commit
97ae8a553d
1 changed files with 215 additions and 16 deletions
|
@ -1,5 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* Original code: automated SDL platform test written by Edgar Simo "bobbens"
|
* Original code: automated SDL platform test written by Edgar Simo "bobbens"
|
||||||
|
* Extended and updated by aschiffler at ferzkopp dot net
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -10,20 +11,38 @@
|
||||||
|
|
||||||
/* Test cases */
|
/* Test cases */
|
||||||
static const TestCaseReference test1 =
|
static const TestCaseReference test1 =
|
||||||
(TestCaseReference){ "platform_testTypes", "description", TEST_ENABLED, 0, 0 };
|
(TestCaseReference){ "platform_testTypes", "Tests predefined types", TEST_ENABLED, 0, 0 };
|
||||||
|
|
||||||
static const TestCaseReference test2 =
|
static const TestCaseReference test2 =
|
||||||
(TestCaseReference){ "platform_testEndianessAndSwap", "description", TEST_ENABLED, 0, 0 };
|
(TestCaseReference){ "platform_testEndianessAndSwap", "Tests endianess and swap functions", TEST_ENABLED, 0, 0 };
|
||||||
|
|
||||||
static const TestCaseReference test3 =
|
static const TestCaseReference test3 =
|
||||||
(TestCaseReference){ "platform_testGetFunctions", "description", TEST_ENABLED, 0, 0 };
|
(TestCaseReference){ "platform_testGetFunctions", "Tests various SDL_GetXYZ functions", TEST_ENABLED, 0, 0 };
|
||||||
|
|
||||||
static const TestCaseReference test4 =
|
static const TestCaseReference test4 =
|
||||||
(TestCaseReference){ "platform_testHasFunctions", "description", TEST_ENABLED, 0, 0 };
|
(TestCaseReference){ "platform_testHasFunctions", "Tests various SDL_HasXYZ functions", TEST_ENABLED, 0, 0 };
|
||||||
|
|
||||||
|
static const TestCaseReference test5 =
|
||||||
|
(TestCaseReference){ "platform_testGetVersion", "Tests SDL_GetVersion function", TEST_ENABLED, 0, 0 };
|
||||||
|
|
||||||
|
static const TestCaseReference test6 =
|
||||||
|
(TestCaseReference){ "platform_testSDLVersion", "Tests SDL_VERSION macro", TEST_ENABLED, 0, 0 };
|
||||||
|
|
||||||
|
static const TestCaseReference test7 =
|
||||||
|
(TestCaseReference){ "platform_testDefaultInit", "Tests default SDL_Init", TEST_ENABLED, 0, 0 };
|
||||||
|
|
||||||
|
static const TestCaseReference test8 =
|
||||||
|
(TestCaseReference){ "platform_testGetSetClearError", "Tests SDL_Get/Set/ClearError", TEST_ENABLED, 0, 0 };
|
||||||
|
|
||||||
|
static const TestCaseReference test9 =
|
||||||
|
(TestCaseReference){ "platform_testSetErrorEmptyInput", "Tests SDL_SetError with empty input", TEST_ENABLED, 0, 0 };
|
||||||
|
|
||||||
|
static const TestCaseReference test10 =
|
||||||
|
(TestCaseReference){ "platform_testSetErrorInvalidInput", "Tests SDL_SetError with invalid input", TEST_ENABLED, 0, 0 };
|
||||||
|
|
||||||
/* Test suite */
|
/* Test suite */
|
||||||
extern const TestCaseReference *testSuite[] = {
|
extern const TestCaseReference *testSuite[] = {
|
||||||
&test1, &test2, &test3, &test4, NULL
|
&test1, &test2, &test3, &test4, &test5, &test6, &test7, &test8, &test9, &test10, NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
TestCaseReference **QueryTestSuite() {
|
TestCaseReference **QueryTestSuite() {
|
||||||
|
@ -50,16 +69,16 @@ int platform_testTypes(void *arg)
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = _compareSizeOfType( sizeof(Uint8), 1 );
|
ret = _compareSizeOfType( sizeof(Uint8), 1 );
|
||||||
AssertTrue( ret == 0, "sizeof(Uint8) = %lu instead of 1", sizeof(Uint8) );
|
AssertTrue( ret == 0, "sizeof(Uint8) = %lu, expected 1", sizeof(Uint8) );
|
||||||
|
|
||||||
ret = _compareSizeOfType( sizeof(Uint16), 2 );
|
ret = _compareSizeOfType( sizeof(Uint16), 2 );
|
||||||
AssertTrue( ret == 0, "sizeof(Uint16) = %lu instead of 2", sizeof(Uint16) );
|
AssertTrue( ret == 0, "sizeof(Uint16) = %lu, expected 2", sizeof(Uint16) );
|
||||||
|
|
||||||
ret = _compareSizeOfType( sizeof(Uint32), 4 );
|
ret = _compareSizeOfType( sizeof(Uint32), 4 );
|
||||||
AssertTrue( ret == 0, "sizeof(Uint32) = %lu instead of 4", sizeof(Uint32) );
|
AssertTrue( ret == 0, "sizeof(Uint32) = %lu, expected 4", sizeof(Uint32) );
|
||||||
|
|
||||||
ret = _compareSizeOfType( sizeof(Uint64), 8 );
|
ret = _compareSizeOfType( sizeof(Uint64), 8 );
|
||||||
AssertTrue( ret == 0, "sizeof(Uint64) = %lu instead of 8", sizeof(Uint64) );
|
AssertTrue( ret == 0, "sizeof(Uint64) = %lu, expected 8", sizeof(Uint64) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -90,42 +109,62 @@ int platform_testEndianessAndSwap(void *arg)
|
||||||
|
|
||||||
/* Test endianness. */
|
/* Test endianness. */
|
||||||
AssertTrue( real_byteorder == SDL_BYTEORDER,
|
AssertTrue( real_byteorder == SDL_BYTEORDER,
|
||||||
"Machine detected as %s endian but appears to be %s endian.",
|
"Machine detected as %s endian, appears to be %s endian.",
|
||||||
(SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big",
|
(SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big",
|
||||||
(real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big" );
|
(real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big" );
|
||||||
|
|
||||||
/* Test 16 swap. */
|
/* Test 16 swap. */
|
||||||
AssertTrue( SDL_Swap16(value16) == swapped16,
|
AssertTrue( SDL_Swap16(value16) == swapped16,
|
||||||
"SDL_Swap16(): 16 bit swapped incorrectly: 0x%X => 0x%X",
|
"SDL_Swap16(): 16 bit swapped: 0x%X => 0x%X",
|
||||||
value16, SDL_Swap16(value16) );
|
value16, SDL_Swap16(value16) );
|
||||||
|
|
||||||
/* Test 32 swap. */
|
/* Test 32 swap. */
|
||||||
AssertTrue( SDL_Swap32(value32) == swapped32,
|
AssertTrue( SDL_Swap32(value32) == swapped32,
|
||||||
"SDL_Swap32(): 32 bit swapped incorrectly: 0x%X => 0x%X",
|
"SDL_Swap32(): 32 bit swapped: 0x%X => 0x%X",
|
||||||
value32, SDL_Swap32(value32) );
|
value32, SDL_Swap32(value32) );
|
||||||
|
|
||||||
/* Test 64 swap. */
|
/* Test 64 swap. */
|
||||||
AssertTrue( SDL_Swap64(value64) == swapped64,
|
AssertTrue( SDL_Swap64(value64) == swapped64,
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
"SDL_Swap64(): 64 bit swapped incorrectly: 0x%I64X => 0x%I64X",
|
"SDL_Swap64(): 64 bit swapped: 0x%I64X => 0x%I64X",
|
||||||
#else
|
#else
|
||||||
"SDL_Swap64(): 64 bit swapped incorrectly: 0x%llX => 0x%llX",
|
"SDL_Swap64(): 64 bit swapped: 0x%llX => 0x%llX",
|
||||||
#endif
|
#endif
|
||||||
value64, SDL_Swap64(value64) );
|
value64, SDL_Swap64(value64) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Tests SDL_GetXYZ() functions
|
* \brief Tests SDL_GetXYZ() functions
|
||||||
|
* \sa
|
||||||
|
* http://wiki.libsdl.org/moin.cgi/SDL_GetPlatform
|
||||||
*/
|
*/
|
||||||
int platform_testGetFunctions (void *arg)
|
int platform_testGetFunctions (void *arg)
|
||||||
{
|
{
|
||||||
|
char *platform;
|
||||||
|
char *revision;
|
||||||
int ret;
|
int ret;
|
||||||
|
int len;
|
||||||
|
|
||||||
ret = SDL_GetPlatform();
|
platform = (char *)SDL_GetPlatform();
|
||||||
AssertPass("SDL_GetPlatform()");
|
AssertPass("SDL_GetPlatform()");
|
||||||
|
AssertTrue(platform != NULL, "SDL_GetPlatform() != NULL");
|
||||||
|
if (platform != NULL) {
|
||||||
|
len = strlen(platform);
|
||||||
|
AssertTrue(len > 0,
|
||||||
|
"SDL_GetPlatform(): expected non-empty platform, was platform: '%s', len: %i",
|
||||||
|
platform,
|
||||||
|
len);
|
||||||
|
}
|
||||||
|
|
||||||
ret = SDL_GetCPUCount();
|
ret = SDL_GetCPUCount();
|
||||||
AssertPass("SDL_GetCPUCount()");
|
AssertPass("SDL_GetCPUCount()");
|
||||||
|
|
||||||
|
revision = (char *)SDL_GetRevision();
|
||||||
|
AssertPass("SDL_GetRevision()");
|
||||||
|
AssertTrue(revision != NULL, "SDL_GetRevision() != NULL");
|
||||||
|
|
||||||
|
ret = SDL_GetRevisionNumber();
|
||||||
|
AssertPass("SDL_GetRevisionNumber()");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -164,3 +203,163 @@ int platform_testHasFunctions (void *arg)
|
||||||
ret = SDL_HasSSE42();
|
ret = SDL_HasSSE42();
|
||||||
AssertPass("SDL_HasSSE42()");
|
AssertPass("SDL_HasSSE42()");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Tests SDL_GetVersion
|
||||||
|
*/
|
||||||
|
int platform_testGetVersion(void *arg)
|
||||||
|
{
|
||||||
|
SDL_version linked;
|
||||||
|
|
||||||
|
SDL_GetVersion(&linked);
|
||||||
|
AssertTrue( linked.major >= SDL_MAJOR_VERSION,
|
||||||
|
"SDL_GetVersion(): returned major %i (>= %i)",
|
||||||
|
linked.major,
|
||||||
|
SDL_MAJOR_VERSION);
|
||||||
|
AssertTrue( linked.minor >= SDL_MINOR_VERSION,
|
||||||
|
"SDL_GetVersion(): returned minor %i (>= %i)",
|
||||||
|
linked.minor,
|
||||||
|
SDL_MINOR_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Tests SDL_VERSION macro
|
||||||
|
*/
|
||||||
|
int platform_testSDLVersion(void *arg)
|
||||||
|
{
|
||||||
|
SDL_version compiled;
|
||||||
|
|
||||||
|
SDL_VERSION(&compiled);
|
||||||
|
AssertTrue( compiled.major >= SDL_MAJOR_VERSION,
|
||||||
|
"SDL_VERSION() returned major %i (>= %i)",
|
||||||
|
compiled.major,
|
||||||
|
SDL_MAJOR_VERSION);
|
||||||
|
AssertTrue( compiled.minor >= SDL_MINOR_VERSION,
|
||||||
|
"SDL_VERSION() returned minor %i (>= %i)",
|
||||||
|
compiled.minor,
|
||||||
|
SDL_MINOR_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Tests default SDL_Init
|
||||||
|
*/
|
||||||
|
int platform_testDefaultInit(void *arg)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
int subsystem;
|
||||||
|
|
||||||
|
ret = SDL_Init(0);
|
||||||
|
AssertTrue( ret == 0,
|
||||||
|
"SDL_Init(0): returned %i, expected 0, error: %s",
|
||||||
|
ret,
|
||||||
|
SDL_GetError());
|
||||||
|
|
||||||
|
subsystem = SDL_WasInit(0);
|
||||||
|
AssertTrue( subsystem == 0,
|
||||||
|
"SDL_WasInit(0): returned %i, expected 0",
|
||||||
|
ret);
|
||||||
|
|
||||||
|
SDL_Quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \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();
|
||||||
|
AssertPass("SDL_ClearError()");
|
||||||
|
|
||||||
|
lastError = (char *)SDL_GetError();
|
||||||
|
AssertPass("SDL_GetError()");
|
||||||
|
AssertTrue(lastError != NULL,
|
||||||
|
"SDL_GetError() != NULL");
|
||||||
|
if (lastError != NULL)
|
||||||
|
{
|
||||||
|
len = strlen(lastError);
|
||||||
|
AssertTrue(len == 0,
|
||||||
|
"SDL_GetError(): no message expected, len: %i", len);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_SetError("%s", testError);
|
||||||
|
AssertPass("SDL_SetError()");
|
||||||
|
lastError = (char *)SDL_GetError();
|
||||||
|
AssertTrue(lastError != NULL,
|
||||||
|
"SDL_GetError() != NULL");
|
||||||
|
if (lastError != NULL)
|
||||||
|
{
|
||||||
|
len = strlen(lastError);
|
||||||
|
AssertTrue(len == strlen(testError),
|
||||||
|
"SDL_GetError(): expected message len %i, was len: %i",
|
||||||
|
strlen(testError),
|
||||||
|
len);
|
||||||
|
AssertTrue(strcmp(lastError, testError) == 0,
|
||||||
|
"SDL_GetError(): expected message %s, was message: %s",
|
||||||
|
testError,
|
||||||
|
lastError);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
SDL_ClearError();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \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);
|
||||||
|
AssertPass("SDL_SetError()");
|
||||||
|
lastError = (char *)SDL_GetError();
|
||||||
|
AssertTrue(lastError != NULL,
|
||||||
|
"SDL_GetError() != NULL");
|
||||||
|
if (lastError != NULL)
|
||||||
|
{
|
||||||
|
len = strlen(lastError);
|
||||||
|
AssertTrue(len == strlen(testError),
|
||||||
|
"SDL_GetError(): expected message len %i, was len: %i",
|
||||||
|
strlen(testError),
|
||||||
|
len);
|
||||||
|
AssertTrue(strcmp(lastError, testError) == 0,
|
||||||
|
"SDL_GetError(): expected message '%s', was message: '%s'",
|
||||||
|
testError,
|
||||||
|
lastError);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
SDL_ClearError();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \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;
|
||||||
|
char *lastError;
|
||||||
|
|
||||||
|
SDL_SetError(testError);
|
||||||
|
AssertPass("SDL_SetError()");
|
||||||
|
lastError = (char *)SDL_GetError();
|
||||||
|
AssertTrue(lastError == NULL,
|
||||||
|
"SDL_GetError() == NULL");
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
SDL_ClearError();
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue