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

Commit

Permalink
If any assert in SetUp function fails that test will be skipped.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkauppila committed Jul 11, 2011
1 parent f089d2a commit dd3d889
Show file tree
Hide file tree
Showing 11 changed files with 377 additions and 293 deletions.
9 changes: 7 additions & 2 deletions test/test-automation/SDL_test.c
Expand Up @@ -36,7 +36,7 @@ int _testAssertsFailed;
int _testAssertsPassed;

void
_InitTestEnvironment() // InitTestEnvironment
_InitTestEnvironment()
{
_testReturnValue = 0;
_testAssertsFailed = 0;
Expand All @@ -56,8 +56,13 @@ _QuitTestEnvironment()
return _testReturnValue;
}

int
_CountFailedAsserts() {
return _testAssertsFailed;
}

void
AssertEquals(const int expected, const int actual, char *message, ...)
AssertEquals(int expected, int actual, char *message, ...)
{
va_list args;
char buf[256];
Expand Down
22 changes: 16 additions & 6 deletions test/test-automation/SDL_test.h
Expand Up @@ -69,13 +69,19 @@ void _InitTestEnvironment();
*/
int _QuitTestEnvironment();

/*!
* Can be used to query the number of failed asserts
* \return Returns the failed assert count.
*/
int _CountFailedAsserts();

/*!
* 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
* \param message Message that will be printed
*/
void AssertEquals(const int expected, const int actual, char *message, ...);

Expand All @@ -85,18 +91,22 @@ void AssertEquals(const int expected, const int actual, char *message, ...);
* assert passes, otherwise it fails.
*
* \param condition Condition which will be evaluated
* \param message Message that will be printed if assert fails
* \param message Message that will be printed
*/
void AssertTrue(int condition, char *message, ...);

/*!
\todo add markup
*/
* Assert function which will always fail
*
* \param message Message that will be printed
*/
void AssertFail(char *message, ...);

/*!
\todo add markup
*/
* Assert function which will always pass
*
* \param message Message that will be printed
*/
void AssertPass(char *message, ...);

#endif
2 changes: 1 addition & 1 deletion test/test-automation/logger.h
Expand Up @@ -30,7 +30,7 @@
*/
typedef void (*RunStartedFp)(int parameterCount, char *runnerParameters[], time_t eventTime, void *data);
typedef void (*RunEndedFp)(int testCount, int suiteCount, int testPassCount, int testFailCount,
time_t endTime, double totalRuntime);
int testSkippedCount, time_t endTime, double totalRuntime);

typedef void (*SuiteStartedFp)(const char *suiteName, time_t eventTime);
typedef void (*SuiteEndedFp)(int testsPassed, int testsFailed, int testsSkipped,
Expand Down
10 changes: 7 additions & 3 deletions test/test-automation/plain_logger.c
Expand Up @@ -54,13 +54,14 @@ PlainRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime,

void
PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
time_t endTime, double totalRuntime)
int testSkippedCount, time_t endTime, double totalRuntime)
{
Output(indentLevel, "Ran %d tests in %0.5f seconds from %d suites.",
testCount, totalRuntime, suiteCount);

Output(indentLevel, "%d tests passed", testPassCount);
Output(indentLevel, "%d tests failed", testFailCount);
Output(indentLevel, "%d tests skipped", testSkippedCount);
}

void
Expand Down Expand Up @@ -91,6 +92,9 @@ PlainTestEnded(const char *testName, const char *suiteName,
if(testResult) {
if(testResult == 2) {
Output(--indentLevel, "%s: failed -> no assert", testName);
}
else if(testResult == 3) {
Output(--indentLevel, "%s: skipped", testName);
} else {
Output(--indentLevel, "%s: failed", testName);
}
Expand All @@ -104,15 +108,15 @@ PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
time_t eventTime)
{
const char *result = (assertResult) ? "passed" : "failed";
Output(indentLevel, "%s: %s; %s", assertName, result, assertMessage);
Output(indentLevel, "%s: %s - %s", assertName, result, assertMessage);
}

void
PlainAssertWithValues(const char *assertName, int assertResult, const char *assertMessage,
int actualValue, int expected, time_t eventTime)
{
const char *result = (assertResult) ? "passed" : "failed";
Output(indentLevel, "%s %s (expected %d, actualValue &d): %s",
Output(indentLevel, "%s: %s (expected %d, actualValue &d) - %s",
assertName, result, expected, actualValue, assertMessage);
}

Expand Down
2 changes: 1 addition & 1 deletion test/test-automation/plain_logger.h
Expand Up @@ -26,7 +26,7 @@ void PlainRunStarted(int parameterCount, char *runnerParameters[], time_t eventT
* \param totalRuntime How long the execution took
*/
void PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
time_t endTime, double totalRuntime);
int testSkippedCount, time_t endTime, double totalRuntime);

/*!
* Prints the data about the test suite that'll be executed next
Expand Down

0 comments on commit dd3d889

Please sign in to comment.