Runner can execute multiple test suites consecutively.
This commit is contained in:
parent
88d6f70285
commit
8e99f21e3f
3 changed files with 91 additions and 73 deletions
|
@ -56,15 +56,6 @@ _TestCaseQuit()
|
||||||
return _testReturnValue;
|
return _testReturnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Assert function. Tests if the expected value equals the actual value, then
|
|
||||||
* the test assert succeeds, otherwise it fails and warns about it.
|
|
||||||
*
|
|
||||||
* \param expected Value user expects to have
|
|
||||||
* \param actual The actual value of tested variable
|
|
||||||
* \param message Message that will be printed if assert fails
|
|
||||||
*/
|
|
||||||
void
|
void
|
||||||
AssertEquals(Uint32 expected, Uint32 actual, char* message, ...)
|
AssertEquals(Uint32 expected, Uint32 actual, char* message, ...)
|
||||||
{
|
{
|
||||||
|
@ -83,14 +74,6 @@ AssertEquals(Uint32 expected, Uint32 actual, char* message, ...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
* Assert function. Tests if the given condition is true. True in
|
|
||||||
* this case means non-zero value. If the condition is true, the
|
|
||||||
* assert passes, otherwise it fails.
|
|
||||||
*
|
|
||||||
* \param condition Condition which will be evaluated
|
|
||||||
* \param message Message that will be printed if assert fails
|
|
||||||
*/
|
|
||||||
void
|
void
|
||||||
AssertTrue(int condition, char *message, ...)
|
AssertTrue(int condition, char *message, ...)
|
||||||
{
|
{
|
||||||
|
|
|
@ -56,12 +56,22 @@ void _TestCaseInit();
|
||||||
int _TestCaseQuit();
|
int _TestCaseQuit();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* todo add comment
|
* Assert function. Tests if the expected value equals the actual value, then
|
||||||
|
* the test assert succeeds, otherwise it fails and warns about it.
|
||||||
|
*
|
||||||
|
* \param expected Value user expects to have
|
||||||
|
* \param actual The actual value of tested variable
|
||||||
|
* \param message Message that will be printed if assert fails
|
||||||
*/
|
*/
|
||||||
void AssertEquals(Uint32 expected, Uint32 actual, char *message, ...);
|
void AssertEquals(Uint32 expected, Uint32 actual, char *message, ...);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* todo add comment
|
* Assert function. Tests if the given condition is true. True in
|
||||||
|
* this case means non-zero value. If the condition is true, the
|
||||||
|
* assert passes, otherwise it fails.
|
||||||
|
*
|
||||||
|
* \param condition Condition which will be evaluated
|
||||||
|
* \param message Message that will be printed if assert fails
|
||||||
*/
|
*/
|
||||||
void AssertTrue(int condition, char *message, ...);
|
void AssertTrue(int condition, char *message, ...);
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,15 @@ typedef int (*TestCaseQuit)(void);
|
||||||
//!< Flag for executing tests in-process
|
//!< Flag for executing tests in-process
|
||||||
static int execute_inproc = 0;
|
static int execute_inproc = 0;
|
||||||
|
|
||||||
|
|
||||||
|
//!< Temporary array to hold test suite names
|
||||||
|
#if defined(linux) || defined( __linux)
|
||||||
|
char *testSuites[] = { "tests/libtest.so", "tests/libtestrect.so", NULL};
|
||||||
|
#else
|
||||||
|
char *testSuites[] = { "tests/libtest.dylib", "tests/libtestrect.dylib", NULL};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Returns the name for the dynamic library
|
* Returns the name for the dynamic library
|
||||||
* which implements the test suite.
|
* which implements the test suite.
|
||||||
|
@ -45,16 +54,11 @@ static int execute_inproc = 0;
|
||||||
* returns the names of the dynamic libraries
|
* returns the names of the dynamic libraries
|
||||||
* implementing the test suites)
|
* implementing the test suites)
|
||||||
*
|
*
|
||||||
* \return Name of the dummy test suite
|
* \return Array of test suite names
|
||||||
*/
|
*/
|
||||||
char *
|
char **
|
||||||
ScanForTestSuites() {
|
ScanForTestSuites() {
|
||||||
#if defined(linux) || defined( __linux)
|
return testSuites;
|
||||||
char *libName = "tests/libtest.so";
|
|
||||||
#else
|
|
||||||
char *libName = "tests/libtest.dylib";
|
|
||||||
#endif
|
|
||||||
return libName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -189,6 +193,49 @@ HandleTestReturnValue(int stat_lock)
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Executes a test case. Loads the test, executes it and
|
||||||
|
* returns the tests return value to the caller.
|
||||||
|
*
|
||||||
|
* \param suite The suite from which the test will be loaded
|
||||||
|
* \param testReference TestCaseReference of the test under execution
|
||||||
|
* \return The return value of the test. Zero means success, non-zero failure.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
ExecuteTest(void *suite, TestCaseReference *testReference) {
|
||||||
|
char *testname = testReference->name;
|
||||||
|
|
||||||
|
TestCaseInit testCaseInit = LoadTestCaseInit(suite);
|
||||||
|
TestCaseQuit testCaseQuit = LoadTestCaseQuit(suite);
|
||||||
|
TestCase test = (TestCase) LoadTestCase(suite, testname);
|
||||||
|
|
||||||
|
int retVal = 1;
|
||||||
|
if(execute_inproc) {
|
||||||
|
testCaseInit();
|
||||||
|
|
||||||
|
test(0x0);
|
||||||
|
|
||||||
|
retVal = testCaseQuit();
|
||||||
|
} else {
|
||||||
|
int childpid = fork();
|
||||||
|
if(childpid == 0) {
|
||||||
|
testCaseInit();
|
||||||
|
|
||||||
|
test(0x0);
|
||||||
|
|
||||||
|
exit(testCaseQuit());
|
||||||
|
} else {
|
||||||
|
int stat_lock = -1;
|
||||||
|
int child = wait(&stat_lock);
|
||||||
|
|
||||||
|
retVal = HandleTestReturnValue(stat_lock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Prints usage information
|
* Prints usage information
|
||||||
*/
|
*/
|
||||||
|
@ -243,65 +290,43 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
const Uint32 startTicks = SDL_GetTicks();
|
const Uint32 startTicks = SDL_GetTicks();
|
||||||
|
|
||||||
char *testSuiteName = ScanForTestSuites();
|
char **testSuiteNames = ScanForTestSuites();
|
||||||
void *suite = LoadTestSuite(testSuiteName);
|
|
||||||
TestCaseReference **tests = QueryTestCases(suite);
|
|
||||||
|
|
||||||
TestCaseReference *reference = NULL;
|
char *testSuiteName = NULL;
|
||||||
int counter = 0;
|
int suiteCounter = 0;
|
||||||
|
for(testSuiteName = testSuiteNames[suiteCounter]; testSuiteName; testSuiteName = testSuiteNames[++suiteCounter]) {
|
||||||
|
void *suite = LoadTestSuite(testSuiteName);
|
||||||
|
TestCaseReference **tests = QueryTestCases(suite);
|
||||||
|
|
||||||
for(reference = tests[counter]; reference; reference = tests[++counter]) {
|
TestCaseReference *reference = NULL;
|
||||||
if(reference->enabled == TEST_DISABLED) {
|
int counter = 0;
|
||||||
printf("Test %s (in %s) disabled. Omitting...\n", reference->name, testSuiteName);
|
|
||||||
} else {
|
|
||||||
char *testname = reference->name;
|
|
||||||
|
|
||||||
printf("Running %s (in %s):\n", testname, testSuiteName);
|
for(reference = tests[counter]; reference; reference = tests[++counter]) {
|
||||||
|
if(reference->enabled == TEST_DISABLED) {
|
||||||
TestCaseInit testCaseInit = LoadTestCaseInit(suite);
|
printf("Test %s (in %s) disabled. Omitting...\n", reference->name, testSuiteName);
|
||||||
TestCaseQuit testCaseQuit = LoadTestCaseQuit(suite);
|
|
||||||
TestCase test = (TestCase) LoadTestCase(suite, testname);
|
|
||||||
|
|
||||||
int retVal = 1;
|
|
||||||
if(execute_inproc) {
|
|
||||||
testCaseInit();
|
|
||||||
|
|
||||||
test(0x0);
|
|
||||||
|
|
||||||
retVal = testCaseQuit();
|
|
||||||
} else {
|
} else {
|
||||||
int childpid = fork();
|
printf("Executing %s (in %s):\n", reference->name, testSuiteName);
|
||||||
if(childpid == 0) {
|
|
||||||
testCaseInit();
|
|
||||||
|
|
||||||
test(0x0);
|
int retVal = ExecuteTest(suite, reference);
|
||||||
|
|
||||||
return testCaseQuit();
|
if(retVal) {
|
||||||
|
failureCount++;
|
||||||
|
if(retVal == 2) {
|
||||||
|
printf("%s (in %s): FAILED -> No asserts\n", reference->name, testSuiteName);
|
||||||
|
} else {
|
||||||
|
printf("%s (in %s): FAILED\n", reference->name, testSuiteName);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
int stat_lock = -1;
|
passCount++;
|
||||||
int child = wait(&stat_lock);
|
printf("%s (in %s): ok\n", reference->name, testSuiteName);
|
||||||
|
|
||||||
retVal = HandleTestReturnValue(stat_lock);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(retVal) {
|
printf("\n");
|
||||||
failureCount++;
|
|
||||||
if(retVal == 2) {
|
|
||||||
printf("%s (in %s): FAILED -> No asserts\n", testname, testSuiteName);
|
|
||||||
} else {
|
|
||||||
printf("%s (in %s): FAILED\n", testname, testSuiteName);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
passCount++;
|
|
||||||
printf("%s (in %s): ok\n", testname, testSuiteName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\n");
|
SDL_UnloadObject(suite);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_UnloadObject(suite);
|
|
||||||
|
|
||||||
const Uint32 endTicks = SDL_GetTicks();
|
const Uint32 endTicks = SDL_GetTicks();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue