Commit 6d3454e1 authored by Markus Kauppila's avatar Markus Kauppila

If any assert in SetUp function fails that test will be skipped.

parent 3efe0fed
...@@ -36,7 +36,7 @@ int _testAssertsFailed; ...@@ -36,7 +36,7 @@ int _testAssertsFailed;
int _testAssertsPassed; int _testAssertsPassed;
void void
_InitTestEnvironment() // InitTestEnvironment _InitTestEnvironment()
{ {
_testReturnValue = 0; _testReturnValue = 0;
_testAssertsFailed = 0; _testAssertsFailed = 0;
...@@ -56,8 +56,13 @@ _QuitTestEnvironment() ...@@ -56,8 +56,13 @@ _QuitTestEnvironment()
return _testReturnValue; return _testReturnValue;
} }
int
_CountFailedAsserts() {
return _testAssertsFailed;
}
void void
AssertEquals(const int expected, const int actual, char *message, ...) AssertEquals(int expected, int actual, char *message, ...)
{ {
va_list args; va_list args;
char buf[256]; char buf[256];
......
...@@ -69,13 +69,19 @@ void _InitTestEnvironment(); ...@@ -69,13 +69,19 @@ void _InitTestEnvironment();
*/ */
int _QuitTestEnvironment(); 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 * Assert function. Tests if the expected value equals the actual value, then
* the test assert succeeds, otherwise it fails and warns about it. * the test assert succeeds, otherwise it fails and warns about it.
* *
* \param expected Value user expects to have * \param expected Value user expects to have
* \param actual The actual value of tested variable * \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, ...); void AssertEquals(const int expected, const int actual, char *message, ...);
...@@ -85,18 +91,22 @@ void AssertEquals(const int expected, const int actual, char *message, ...); ...@@ -85,18 +91,22 @@ void AssertEquals(const int expected, const int actual, char *message, ...);
* assert passes, otherwise it fails. * assert passes, otherwise it fails.
* *
* \param condition Condition which will be evaluated * \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, ...); 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, ...); void AssertFail(char *message, ...);
/*! /*!
\todo add markup * Assert function which will always pass
*/ *
* \param message Message that will be printed
*/
void AssertPass(char *message, ...); void AssertPass(char *message, ...);
#endif #endif
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
*/ */
typedef void (*RunStartedFp)(int parameterCount, char *runnerParameters[], time_t eventTime, void *data); typedef void (*RunStartedFp)(int parameterCount, char *runnerParameters[], time_t eventTime, void *data);
typedef void (*RunEndedFp)(int testCount, int suiteCount, int testPassCount, int testFailCount, 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 (*SuiteStartedFp)(const char *suiteName, time_t eventTime);
typedef void (*SuiteEndedFp)(int testsPassed, int testsFailed, int testsSkipped, typedef void (*SuiteEndedFp)(int testsPassed, int testsFailed, int testsSkipped,
......
...@@ -54,13 +54,14 @@ PlainRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime, ...@@ -54,13 +54,14 @@ PlainRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime,
void void
PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount, 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.", Output(indentLevel, "Ran %d tests in %0.5f seconds from %d suites.",
testCount, totalRuntime, suiteCount); testCount, totalRuntime, suiteCount);
Output(indentLevel, "%d tests passed", testPassCount); Output(indentLevel, "%d tests passed", testPassCount);
Output(indentLevel, "%d tests failed", testFailCount); Output(indentLevel, "%d tests failed", testFailCount);
Output(indentLevel, "%d tests skipped", testSkippedCount);
} }
void void
...@@ -91,6 +92,9 @@ PlainTestEnded(const char *testName, const char *suiteName, ...@@ -91,6 +92,9 @@ PlainTestEnded(const char *testName, const char *suiteName,
if(testResult) { if(testResult) {
if(testResult == 2) { if(testResult == 2) {
Output(--indentLevel, "%s: failed -> no assert", testName); Output(--indentLevel, "%s: failed -> no assert", testName);
}
else if(testResult == 3) {
Output(--indentLevel, "%s: skipped", testName);
} else { } else {
Output(--indentLevel, "%s: failed", testName); Output(--indentLevel, "%s: failed", testName);
} }
...@@ -104,7 +108,7 @@ PlainAssert(const char *assertName, int assertResult, const char *assertMessage, ...@@ -104,7 +108,7 @@ PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
time_t eventTime) time_t eventTime)
{ {
const char *result = (assertResult) ? "passed" : "failed"; const char *result = (assertResult) ? "passed" : "failed";
Output(indentLevel, "%s: %s; %s", assertName, result, assertMessage); Output(indentLevel, "%s: %s - %s", assertName, result, assertMessage);
} }
void void
...@@ -112,7 +116,7 @@ PlainAssertWithValues(const char *assertName, int assertResult, const char *asse ...@@ -112,7 +116,7 @@ PlainAssertWithValues(const char *assertName, int assertResult, const char *asse
int actualValue, int expected, time_t eventTime) int actualValue, int expected, time_t eventTime)
{ {
const char *result = (assertResult) ? "passed" : "failed"; 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); assertName, result, expected, actualValue, assertMessage);
} }
......
...@@ -26,7 +26,7 @@ void PlainRunStarted(int parameterCount, char *runnerParameters[], time_t eventT ...@@ -26,7 +26,7 @@ void PlainRunStarted(int parameterCount, char *runnerParameters[], time_t eventT
* \param totalRuntime How long the execution took * \param totalRuntime How long the execution took
*/ */
void PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount, 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 * Prints the data about the test suite that'll be executed next
......
This diff is collapsed.
...@@ -104,6 +104,7 @@ $(document).ready(function() { ...@@ -104,6 +104,7 @@ $(document).ready(function() {
/* Color the tests based on the result */ /* Color the tests based on the result */
$("span.testResult[result='passed']").addClass('passed'); $("span.testResult[result='passed']").addClass('passed');
$("span.testResult[result='failed']").addClass('failed'); $("span.testResult[result='failed']").addClass('failed');
$("span.testResult[result='skipped']").addClass('skipped');
/* Color the asserts based on the result */ /* Color the asserts based on the result */
$("span.assertResult[result='pass']").addClass('passed'); $("span.assertResult[result='pass']").addClass('passed');
...@@ -157,6 +158,10 @@ div, h1 { ...@@ -157,6 +158,10 @@ div, h1 {
color: red; color: red;
} }
.skipped {
color: gray;
}
</style> </style>
</head> </head>
......
...@@ -56,6 +56,9 @@ TestCaseReference **QueryTestSuite() { ...@@ -56,6 +56,9 @@ TestCaseReference **QueryTestSuite() {
* SetUp function can be used to create a test fixture for test cases. * SetUp function can be used to create a test fixture for test cases.
* The function will be called right before executing the test case. * The function will be called right before executing the test case.
* *
* Note: If any assert in the function fails then the test will be skipped.
* In practice, the entire suite will be skipped if assert failure happens.
*
* Note: this function is optional. * Note: this function is optional.
* *
* \param arg parameters given to test. Usually NULL * \param arg parameters given to test. Usually NULL
......
...@@ -32,11 +32,39 @@ TestCaseReference **QueryTestSuite() { ...@@ -32,11 +32,39 @@ TestCaseReference **QueryTestSuite() {
return (TestCaseReference **)testSuite; return (TestCaseReference **)testSuite;
} }
/* Function prototypes */
SDL_Surface *_CreateTestSurface();
/* Create test fixture */
static SDL_Surface *testsur = NULL;
void
SetUp(void *arg)
{
int ret = SDL_Init(SDL_INIT_VIDEO);
AssertTrue(ret == 0, "SDL_Init(SDL_INIT_VIDEO)");
testsur = _CreateTestSurface();
AssertTrue(testsur != NULL, "SDL_Init(SDL_INIT_VIDEO)");
}
void
TearDown(void *arg)
{
SDL_FreeSurface( testsur );
SDL_Quit();
}
/* Helper functions for the test cases */ /* Helper functions for the test cases */
#define TEST_SURFACE_WIDTH 80 #define TEST_SURFACE_WIDTH 80
#define TEST_SURFACE_HEIGHT 60 #define TEST_SURFACE_HEIGHT 60
/*! /*!
* Creates test surface * Creates test surface
*/ */
...@@ -66,7 +94,7 @@ _CreateTestSurface() ...@@ -66,7 +94,7 @@ _CreateTestSurface()
/** /**
* @brief Tests a blend mode. * @brief Tests a blend mode.
*/ */
int _testBlitBlendMode(SDL_Surface *testsur, SDL_Surface *face, int mode) void _testBlitBlendMode(SDL_Surface *testsur, SDL_Surface *face, int mode)
{ {
int ret; int ret;
int i, j, ni, nj; int i, j, ni, nj;
...@@ -102,8 +130,6 @@ int _testBlitBlendMode(SDL_Surface *testsur, SDL_Surface *face, int mode) ...@@ -102,8 +130,6 @@ int _testBlitBlendMode(SDL_Surface *testsur, SDL_Surface *face, int mode)
ret = SDL_BlitSurface( face, NULL, testsur, &rect ); ret = SDL_BlitSurface( face, NULL, testsur, &rect );
AssertTrue(ret != 0, "SDL_BlitSurface"); } AssertTrue(ret != 0, "SDL_BlitSurface"); }
} }
return 0;
} }
/* Test case functions */ /* Test case functions */
...@@ -115,13 +141,8 @@ void surface_testLoad(void *arg) ...@@ -115,13 +141,8 @@ void surface_testLoad(void *arg)
int ret; int ret;
SDL_Surface *face, *rface; SDL_Surface *face, *rface;
ret = SDL_Init(SDL_INIT_VIDEO); /* Clear surface. */
AssertTrue(ret == 0, "SDL_Init(SDL_INIT_VIDEO)"); ret = SDL_FillRect( testsur, NULL,
SDL_Surface *testsur = _CreateTestSurface();
/* Clear surface. */
ret = SDL_FillRect( testsur, NULL,
SDL_MapRGB( testsur->format, 0, 0, 0 ) ); SDL_MapRGB( testsur->format, 0, 0, 0 ) );
AssertTrue(ret == 0, "SDL_FillRect"); AssertTrue(ret == 0, "SDL_FillRect");
...@@ -151,10 +172,6 @@ void surface_testLoad(void *arg) ...@@ -151,10 +172,6 @@ void surface_testLoad(void *arg)
/* Clean up. */ /* Clean up. */
SDL_FreeSurface( rface ); SDL_FreeSurface( rface );
SDL_FreeSurface( face ); SDL_FreeSurface( face );
SDL_FreeSurface( testsur );
SDL_Quit();
} }
...@@ -163,14 +180,8 @@ void surface_testLoad(void *arg) ...@@ -163,14 +180,8 @@ void surface_testLoad(void *arg)
*/ */
void surface_testLoadFailure(void *arg) void surface_testLoadFailure(void *arg)
{ {
int ret = SDL_Init(SDL_INIT_VIDEO);
AssertTrue(ret == 0, "SDL_Init(SDL_INIT_VIDEO)");
SDL_Surface *face = SDL_LoadBMP("nonexistant.bmp"); SDL_Surface *face = SDL_LoadBMP("nonexistant.bmp");
AssertTrue(face == NULL, "SDL_CreateLoadBmp"); AssertTrue(face == NULL, "SDL_CreateLoadBmp");
SDL_Quit();
} }
...@@ -184,11 +195,6 @@ void surface_testBlit(void *arg) ...@@ -184,11 +195,6 @@ void surface_testBlit(void *arg)
SDL_Surface *face; SDL_Surface *face;
int i, j, ni, nj; int i, j, ni, nj;
ret = SDL_Init(SDL_INIT_VIDEO);
AssertTrue(ret == 0, "SDL_Init(SDL_INIT_VIDEO)");
SDL_Surface *testsur = _CreateTestSurface();
/* Clear surface. */ /* Clear surface. */
ret = SDL_FillRect( testsur, NULL, ret = SDL_FillRect( testsur, NULL,
SDL_MapRGB( testsur->format, 0, 0, 0 ) ); SDL_MapRGB( testsur->format, 0, 0, 0 ) );
...@@ -292,9 +298,6 @@ void surface_testBlit(void *arg) ...@@ -292,9 +298,6 @@ void surface_testBlit(void *arg)
/* Clean up. */ /* Clean up. */
SDL_FreeSurface( face ); SDL_FreeSurface( face );
SDL_FreeSurface( testsur );
SDL_Quit();
} }
/** /**
...@@ -308,11 +311,6 @@ void surface_testBlitBlend(void *arg) ...@@ -308,11 +311,6 @@ void surface_testBlitBlend(void *arg)
int i, j, ni, nj; int i, j, ni, nj;
int mode; int mode;
ret = SDL_Init(SDL_INIT_VIDEO);
AssertTrue(ret == 0, "SDL_Init(SDL_INIT_VIDEO)");
SDL_Surface *testsur = _CreateTestSurface();
/* Clear surface. */ /* Clear surface. */
ret = SDL_FillRect( testsur, NULL, ret = SDL_FillRect( testsur, NULL,
SDL_MapRGB( testsur->format, 0, 0, 0 ) ); SDL_MapRGB( testsur->format, 0, 0, 0 ) );
...@@ -415,7 +413,4 @@ void surface_testBlitBlend(void *arg) ...@@ -415,7 +413,4 @@ void surface_testBlitBlend(void *arg)
/* Clean up. */ /* Clean up. */
SDL_FreeSurface( face ); SDL_FreeSurface( face );
SDL_FreeSurface( testsur );
SDL_Quit();
} }
...@@ -38,6 +38,7 @@ const char *numSuitesElementName = "numSuites"; ...@@ -38,6 +38,7 @@ const char *numSuitesElementName = "numSuites";
const char *numTestElementName = "numTests"; const char *numTestElementName = "numTests";
const char *numPassedTestsElementName = "numPassedTests"; const char *numPassedTestsElementName = "numPassedTests";
const char *numFailedTestsElementName = "numFailedTests"; const char *numFailedTestsElementName = "numFailedTests";
const char *numSkippedTestsElementName = "numSkippedTests";
const char *endTimeElementName = "endTime"; const char *endTimeElementName = "endTime";
const char *totalRuntimeElementName = "totalRuntime"; const char *totalRuntimeElementName = "totalRuntime";
const char *suiteElementName = "suite"; const char *suiteElementName = "suite";
...@@ -145,7 +146,7 @@ XMLRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime, ...@@ -145,7 +146,7 @@ XMLRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime,
void void
XMLRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount, XMLRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
time_t endTime, double totalRuntime) int testSkippedCount, time_t endTime, double totalRuntime)
{ {
// log suite count // log suite count
char *output = XMLOpenElement(numSuitesElementName); char *output = XMLOpenElement(numSuitesElementName);
...@@ -187,7 +188,17 @@ XMLRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount, ...@@ -187,7 +188,17 @@ XMLRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
output = XMLCloseElement(numFailedTestsElementName); output = XMLCloseElement(numFailedTestsElementName);
XMLOutputter(--indentLevel, YES, output); XMLOutputter(--indentLevel, YES, output);
// log end timte // log skipped test count
output = XMLOpenElement(numSkippedTestsElementName);
XMLOutputter(indentLevel++, NO, output);
output = XMLAddContent(IntToString(testSkippedCount));
XMLOutputter(indentLevel, NO, output);
output = XMLCloseElement(numSkippedTestsElementName);
XMLOutputter(--indentLevel, YES, output);
// log end tite
output = XMLOpenElement(endTimeElementName); output = XMLOpenElement(endTimeElementName);
XMLOutputter(indentLevel++, NO, output); XMLOutputter(indentLevel++, NO, output);
...@@ -342,6 +353,9 @@ XMLTestEnded(const char *testName, const char *suiteName, ...@@ -342,6 +353,9 @@ XMLTestEnded(const char *testName, const char *suiteName,
if(testResult) { if(testResult) {
if(testResult == 2) { if(testResult == 2) {
output = XMLAddContent("failed. No assert"); output = XMLAddContent("failed. No assert");
}
else if(testResult == 3) {
output = XMLAddContent("skipped");
} else { } else {
output = XMLAddContent("failed"); output = XMLAddContent("failed");
} }
......
...@@ -24,7 +24,7 @@ void XMLRunStarted(int parameterCount, char *runnerParameters[], time_t eventTim ...@@ -24,7 +24,7 @@ void XMLRunStarted(int parameterCount, char *runnerParameters[], time_t eventTim
* \param totalRuntime How long the execution took * \param totalRuntime How long the execution took
*/ */
void XMLRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount, void XMLRunEnded(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 in XML * Prints the data about the test suite that'll be executed next in XML
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment