Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Added time, date and total runtime information to the output by

logging system.
  • Loading branch information
mkauppila committed Jun 27, 2011
1 parent 23f8d07 commit f2b763e132ec060f155c15a22ad48bd1b0e51c7a
@@ -23,6 +23,7 @@

#include <stdio.h> /* printf/fprintf */
#include <stdarg.h> /* va_list */
#include <time.h>

#include "logger.h"

@@ -58,7 +59,7 @@ _TestCaseQuit()
{
//printf("Asserts: passed %d, failed %d\n", _testAssertsPassed, _testAssertsFailed);
AssertSummary(_testAssertsFailed + _testAssertsPassed,
_testAssertsFailed, _testAssertsPassed);
_testAssertsFailed, _testAssertsPassed, time(0));

if(_testAssertsFailed == 0 && _testAssertsPassed == 0) {
_testReturnValue = 2;
@@ -78,13 +79,13 @@ AssertEquals(Uint32 expected, Uint32 actual, char* message, ...)
SDL_vsnprintf( buf, sizeof(buf), message, args );
va_end( args );
//printf("AssertEquals failed: expected %d, got %d; %s\n", expected, actual, buf);
Assert("AssertEquals", 0, buf, 0);
Assert("AssertEquals", 0, buf, time(0));

_testReturnValue = 1;
_testAssertsFailed++;
} else {
//printf("AssertEquals passed\n");
Assert("AssertEquals", 1, "AssertEquals passed", 0);
Assert("AssertEquals", 1, "AssertEquals passed", time(0));

_testAssertsPassed++;
}
@@ -102,13 +103,13 @@ AssertTrue(int condition, char *message, ...)
va_end( args );

//printf("AssertTrue failed: %s\n", buf);
Assert("AssertTrue", 0, buf, 0);
Assert("AssertTrue", 0, buf, time(0));

_testReturnValue = 1;
_testAssertsFailed++;
} else {
//printf("AssertTrue passed\n");
Assert("AssertTrue", 1, "AssertTrue passed", 0);
Assert("AssertTrue", 1, "AssertTrue passed", time(0));
_testAssertsPassed++;
}
}
@@ -124,7 +125,7 @@ AssertPass(char *message, ...)
va_end( args );

//printf("AssertPass: %s\n", buf);
Assert("AssertPass", 1, buf, 0);
Assert("AssertPass", 1, buf, time(0));

_testAssertsPassed++;
}
@@ -140,7 +141,7 @@ AssertFail(char *message, ...)
va_end( args );

//printf("AssertFail: %s\n", buf);
Assert("AssertFail", 0, buf, 0);
Assert("AssertFail", 0, buf, time(0));

_testAssertsFailed++;
}
@@ -29,24 +29,25 @@
*/
typedef void (*RunStartedFp)(int parameterCount, char *runnerParameters[], time_t eventTime);
typedef void (*RunEndedFp)(int testCount, int suiteCount, int testPassCount, int testFailCount,
time_t endTime, time_t totalRuntime);
time_t endTime, double totalRuntime);

typedef void (*SuiteStartedFp)(const char *suiteName, time_t eventTime);
typedef void (*SuiteEndedFp)(int testsPassed, int testsFailed, int testsSkipped,
double endTime, time_t totalRuntime);
time_t endTime, double totalRuntime);

typedef void (*TestStartedFp)(const char *testName, const char *suiteName,
const char *testDescription, time_t startTime);
typedef void (*TestEndedFp)(const char *testName, const char *suiteName, int testResult,
time_t endTime, time_t totalRuntime);
time_t endTime, double totalRuntime);

/*!
* Note: for assertResult, non-zero == pass, zero == failure
*
*/
typedef void (*AssertFp)(const char *assertName, int assertResult, const char *assertMessage,
time_t eventTime);
typedef void (*AssertSummaryFp)(int numAsserts, int numAssertsFailed, int numAssertsPass);
typedef void (*AssertFp)(const char *assertName, int assertResult,
const char *assertMessage, time_t eventTime);
typedef void (*AssertSummaryFp)(int numAsserts, int numAssertsFailed,
int numAssertsPass, time_t eventTime);


typedef void (*LogFp)(const char *logMessage, time_t eventTime);
@@ -35,7 +35,7 @@ PlainRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime)

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

@@ -51,7 +51,7 @@ PlainSuiteStarted(const char *suiteName, time_t eventTime)

void
PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
double endTime, time_t totalRuntime)
time_t endTime, double totalRuntime)
{
Output("Suite executed. %d passed, %d failed and %d skipped", testsPassed, testsFailed, testsSkipped);
}
@@ -64,7 +64,7 @@ PlainTestStarted(const char *testName, const char *suiteName, const char *testDe

void
PlainTestEnded(const char *testName, const char *suiteName,
int testResult, time_t endTime, time_t totalRuntime)
int testResult, time_t endTime, double totalRuntime)
{
Output("%s: ok", testName);
}
@@ -78,7 +78,7 @@ PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
}

void
PlainAssertSummary(int numAsserts, int numAssertsFailed, int numAssertsPass)
PlainAssertSummary(int numAsserts, int numAssertsFailed, int numAssertsPass, time_t eventTime)
{
Output("Asserts:%d", numAsserts);
}
@@ -6,24 +6,24 @@
void PlainRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime);

void PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
time_t endTime, time_t totalRuntime);
time_t endTime, double totalRuntime);

void PlainSuiteStarted(const char *suiteName, time_t eventTime);

void PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
double endTime, time_t totalRuntime);
time_t endTime, double totalRuntime);

void PlainTestStarted(const char *testName, const char *suiteName,
const char *testDescription, time_t startTime);

void PlainTestEnded(const char *testName, const char *suiteName,
int testResult, time_t endTime, time_t totalRuntime);
int testResult, time_t endTime, double totalRuntime);


void PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
time_t eventTime);

void PlainAssertSummary(int numAsserts, int numAssertsFailed, int numAssertsPass);
void PlainAssertSummary(int numAsserts, int numAssertsFailed, int numAssertsPass, time_t eventTime);


void PlainLog(const char *logMessage, time_t eventTime);
@@ -671,33 +671,44 @@ main(int argc, char *argv[])
return 0;
}

RunStarted(argc, argv, 0);
RunStarted(argc, argv, time(0));

char *currentSuiteName = NULL;

int suiteStartTime = SDL_GetTicks();

TestCase *testItem = NULL;
for(testItem = testCases; testItem; testItem = testItem->next) {
if(currentSuiteName == NULL) {
currentSuiteName = testItem->suiteName;
SuiteStarted(currentSuiteName, 0);
SuiteStarted(currentSuiteName, time(0));

testFailureCount = testPassCount = 0;

//suiteStartTime = SDL_GetTicks();

suiteCounter++;
}
else if(strncmp(currentSuiteName, testItem->suiteName, NAME_BUFFER_SIZE) != 0) {
SuiteEnded(testPassCount, testFailureCount, testSkipCount, 0.0f, 0);
const double suiteRuntime = (SDL_GetTicks() - suiteStartTime) / 1000.0f;

SuiteEnded(testPassCount, testFailureCount, testSkipCount, time(0),
suiteRuntime);

currentSuiteName = testItem->suiteName;
SuiteStarted(currentSuiteName, 0);

testFailureCount = testPassCount = 0;

//suiteStartTime = SDL_GetTicks();

suiteCounter++;
}

TestStarted(testItem->testName, testItem->suiteName,
testItem->description, 0);
testItem->description, time(0));

const Uint32 testTimeStart = SDL_GetTicks();

int retVal = ExecuteTest(testItem);
if(retVal) {
@@ -708,22 +719,26 @@ main(int argc, char *argv[])
testPassCount++;
}

TestEnded(testItem->testName, testItem->suiteName, retVal, 0, 0);
const double testTotalRuntime = (SDL_GetTicks() - testTimeStart) / 1000.0f;

TestEnded(testItem->testName, testItem->suiteName, retVal, time(0), testTotalRuntime);
}

if(currentSuiteName) {
// \todo if no test are run, this will case incorrect nesting with
// xml output
SuiteEnded(testPassCount, testFailureCount, testSkipCount, 0.0f, 0);
SuiteEnded(testPassCount, testFailureCount, testSkipCount, time(0),
(SDL_GetTicks() - suiteStartTime) / 1000.0f);
}

UnloadTestCases(testCases);
UnloadTestSuites(suites);

const Uint32 endTicks = SDL_GetTicks();
const double totalRunTime = (endTicks - startTicks) / 1000.0f;

RunEnded(totalTestPassCount + totalTestfailureCount, suiteCounter,
totalTestPassCount, totalTestfailureCount, 0, 0);
totalTestPassCount, totalTestfailureCount, time(0), totalRunTime);

return 0;
}

0 comments on commit f2b763e

Please sign in to comment.