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;
int _testAssertsPassed;
void
_InitTestEnvironment() // InitTestEnvironment
_InitTestEnvironment()
{
_testReturnValue = 0;
_testAssertsFailed = 0;
......@@ -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];
......
......@@ -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, ...);
......@@ -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
......@@ -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,
......
......@@ -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
......@@ -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);
}
......@@ -104,7 +108,7 @@ 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
......@@ -112,7 +116,7 @@ PlainAssertWithValues(const char *assertName, int assertResult, const char *asse
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);
}
......
......@@ -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
......
This diff is collapsed.
......@@ -104,6 +104,7 @@ $(document).ready(function() {
/* Color the tests based on the result */
$("span.testResult[result='passed']").addClass('passed');
$("span.testResult[result='failed']").addClass('failed');
$("span.testResult[result='skipped']").addClass('skipped');
/* Color the asserts based on the result */
$("span.assertResult[result='pass']").addClass('passed');
......@@ -157,6 +158,10 @@ div, h1 {
color: red;
}
.skipped {
color: gray;
}
</style>
</head>
......
......@@ -56,6 +56,9 @@ TestCaseReference **QueryTestSuite() {
* SetUp function can be used to create a test fixture for test cases.
* 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.
*
* \param arg parameters given to test. Usually NULL
......
......@@ -32,11 +32,39 @@ TestCaseReference **QueryTestSuite() {
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 */
#define TEST_SURFACE_WIDTH 80
#define TEST_SURFACE_HEIGHT 60
/*!
* Creates test surface
*/
......@@ -66,7 +94,7 @@ _CreateTestSurface()
/**
* @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 i, j, ni, nj;
......@@ -102,8 +130,6 @@ int _testBlitBlendMode(SDL_Surface *testsur, SDL_Surface *face, int mode)
ret = SDL_BlitSurface( face, NULL, testsur, &rect );
AssertTrue(ret != 0, "SDL_BlitSurface"); }
}
return 0;
}
/* Test case functions */
......@@ -115,11 +141,6 @@ void surface_testLoad(void *arg)
int ret;
SDL_Surface *face, *rface;
ret = SDL_Init(SDL_INIT_VIDEO);
AssertTrue(ret == 0, "SDL_Init(SDL_INIT_VIDEO)");
SDL_Surface *testsur = _CreateTestSurface();
/* Clear surface. */
ret = SDL_FillRect( testsur, NULL,
SDL_MapRGB( testsur->format, 0, 0, 0 ) );
......@@ -151,10 +172,6 @@ void surface_testLoad(void *arg)
/* Clean up. */
SDL_FreeSurface( rface );
SDL_FreeSurface( face );
SDL_FreeSurface( testsur );
SDL_Quit();
}
......@@ -163,14 +180,8 @@ void surface_testLoad(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");
AssertTrue(face == NULL, "SDL_CreateLoadBmp");
SDL_Quit();
}
......@@ -184,11 +195,6 @@ void surface_testBlit(void *arg)
SDL_Surface *face;
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. */
ret = SDL_FillRect( testsur, NULL,
SDL_MapRGB( testsur->format, 0, 0, 0 ) );
......@@ -292,9 +298,6 @@ void surface_testBlit(void *arg)
/* Clean up. */
SDL_FreeSurface( face );
SDL_FreeSurface( testsur );
SDL_Quit();
}
/**
......@@ -308,11 +311,6 @@ void surface_testBlitBlend(void *arg)
int i, j, ni, nj;
int mode;
ret = SDL_Init(SDL_INIT_VIDEO);
AssertTrue(ret == 0, "SDL_Init(SDL_INIT_VIDEO)");
SDL_Surface *testsur = _CreateTestSurface();
/* Clear surface. */
ret = SDL_FillRect( testsur, NULL,
SDL_MapRGB( testsur->format, 0, 0, 0 ) );
......@@ -415,7 +413,4 @@ void surface_testBlitBlend(void *arg)
/* Clean up. */
SDL_FreeSurface( face );
SDL_FreeSurface( testsur );
SDL_Quit();
}
......@@ -38,6 +38,7 @@ const char *numSuitesElementName = "numSuites";
const char *numTestElementName = "numTests";
const char *numPassedTestsElementName = "numPassedTests";
const char *numFailedTestsElementName = "numFailedTests";
const char *numSkippedTestsElementName = "numSkippedTests";
const char *endTimeElementName = "endTime";
const char *totalRuntimeElementName = "totalRuntime";
const char *suiteElementName = "suite";
......@@ -145,7 +146,7 @@ XMLRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime,
void
XMLRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
time_t endTime, double totalRuntime)
int testSkippedCount, time_t endTime, double totalRuntime)
{
// log suite count
char *output = XMLOpenElement(numSuitesElementName);
......@@ -187,7 +188,17 @@ XMLRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
output = XMLCloseElement(numFailedTestsElementName);
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);
XMLOutputter(indentLevel++, NO, output);
......@@ -342,6 +353,9 @@ XMLTestEnded(const char *testName, const char *suiteName,
if(testResult) {
if(testResult == 2) {
output = XMLAddContent("failed. No assert");
}
else if(testResult == 3) {
output = XMLAddContent("skipped");
} else {
output = XMLAddContent("failed");
}
......
......@@ -24,7 +24,7 @@ void XMLRunStarted(int parameterCount, char *runnerParameters[], time_t eventTim
* \param totalRuntime How long the execution took
*/
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
......
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