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

Commit

Permalink
Plain logger refined.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkauppila committed Jun 27, 2011
1 parent f2b763e commit 595566d
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 74 deletions.
8 changes: 3 additions & 5 deletions test/test-automation/SDL_test.c
Expand Up @@ -57,7 +57,6 @@ _TestCaseInit(const int enable_xml_logging)
int
_TestCaseQuit()
{
//printf("Asserts: passed %d, failed %d\n", _testAssertsPassed, _testAssertsFailed);
AssertSummary(_testAssertsFailed + _testAssertsPassed,
_testAssertsFailed, _testAssertsPassed, time(0));

Expand All @@ -78,14 +77,13 @@ AssertEquals(Uint32 expected, Uint32 actual, char* message, ...)
va_start( args, 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, time(0));
AssertWithValues("AssertEquals", 0, buf, actual, expected, time(0));

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

_testAssertsPassed++;
}
Expand Down
36 changes: 36 additions & 0 deletions test/test-automation/logger.c
Expand Up @@ -18,6 +18,7 @@ SuiteEndedFp SuiteEnded = 0;
TestStartedFp TestStarted = 0;
TestEndedFp TestEnded = 0;
AssertFp Assert = 0;
AssertWithValuesFp AssertWithValues = 0;
AssertSummaryFp AssertSummary = 0;
LogFp Log = 0;

Expand All @@ -34,6 +35,7 @@ SetupXMLLogger()
TestEnded = XMLTestEnded;

Assert = XMLAssert;
AssertWithValues = XMLAssertWithValues;
AssertSummary = XMLAssertSummary;

Log = XMLLog;
Expand All @@ -52,11 +54,45 @@ SetupPlainLogger()
TestEnded = PlainTestEnded;

Assert = PlainAssert;
AssertWithValues = PlainAssertWithValues;
AssertSummary = PlainAssertSummary;

Log = PlainLog;
}


char *IntToString(const int integer) {
static char buffer[sizeof(int) * 8 + 1]; // malloc might work better
memset(buffer, 0, sizeof(buffer));

SDL_snprintf(buffer, sizeof(buffer), "%d", integer);

return buffer;
}


char *DoubleToString(const double decimal) {
static char buffer[sizeof(double) * 8 + 1]; // malloc might work better
memset(buffer, 0, sizeof(buffer));

SDL_snprintf(buffer, sizeof(buffer), "%.5f", decimal);

return buffer;
}

char *TimestampToString(const time_t timestamp) {
static char buffer[1024];
//char *buffer = SDL_malloc(1024);
memset(buffer, 0, 1024);

time_t copy = timestamp;

struct tm *local = localtime(&copy);
strftime(buffer, 1024, "%a %Y-%m-%d %H:%M:%S %Z", local);

return buffer;
}

#if 0
/*!
* Test app for logging functionality
Expand Down
33 changes: 32 additions & 1 deletion test/test-automation/logger.h
Expand Up @@ -46,10 +46,14 @@ typedef void (*TestEndedFp)(const char *testName, const char *suiteName, int tes
*/
typedef void (*AssertFp)(const char *assertName, int assertResult,
const char *assertMessage, time_t eventTime);

typedef void (*AssertWithValuesFp)(const char *assertName, int assertResult,
const char *assertMessage, int actualValue, int excpected,
time_t eventTime);

typedef void (*AssertSummaryFp)(int numAsserts, int numAssertsFailed,
int numAssertsPass, time_t eventTime);


typedef void (*LogFp)(const char *logMessage, time_t eventTime);


Expand All @@ -60,7 +64,34 @@ extern SuiteEndedFp SuiteEnded;
extern TestStartedFp TestStarted;
extern TestEndedFp TestEnded;
extern AssertFp Assert;
extern AssertWithValuesFp AssertWithValues;
extern AssertSummaryFp AssertSummary;
extern LogFp Log;

/*!
* Helper functions. Turns the given integer in to a string
*
* \param integer The converted integer
* \returns Given integer as string
*/
char *IntToString(const int integer);

/*!
* Helper functions. Turns the given double value in to a string
*
* \param integer The converted double value
* \returns Given double value as string
*/
char *DoubleToString(const double decimal);


/*!
* Converts unix timestamp to it's ascii presentation
*
* \param timestamp Timestamp
* \return Ascii presentation
*/
char *TimestampToString(const time_t timestamp);


#endif
50 changes: 38 additions & 12 deletions test/test-automation/plain_logger.c
Expand Up @@ -10,8 +10,9 @@


/*!
* Pritns out the output of the logger
* \return Possible error value (\todo)
* Prints out the output of the logger
*
* \param message The message to be printed out
*/
int
Output(const char *message, ...)
Expand All @@ -22,22 +23,30 @@ Output(const char *message, ...)
char buffer[1024];
SDL_vsnprintf(buffer, sizeof(buffer), message, list);

fprintf(stderr, "%s\n", buffer);
fflush(stderr);
fprintf(stdout, "%s\n", buffer);
fflush(stdout);
}

void
PlainRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime)
{
Output("Test run started");
Output("Given command line options: %s", "add options");
/*
Output("Test run started with following parameters\n");
int counter = 0;
for(counter = 0; counter < parameterCount; counter++) {
char *parameter = runnerParameters[counter];
Output("\t%s", parameter);
}
*/
}

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

Output("%d tests passed", testPassCount);
Output("%d tests failed", testFailCount);
Expand All @@ -46,7 +55,7 @@ PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCoun
void
PlainSuiteStarted(const char *suiteName, time_t eventTime)
{
Output("Executing tests in %s", suiteName);
Output("Executing tests from %s", suiteName);
}

void
Expand All @@ -59,19 +68,35 @@ PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
void
PlainTestStarted(const char *testName, const char *suiteName, const char *testDescription, time_t startTime)
{
Output("test %s (in %s) started", testName, suiteName);
Output("%s (in %s) started", testName, suiteName);
}

void
PlainTestEnded(const char *testName, const char *suiteName,
int testResult, time_t endTime, double totalRuntime)
{
Output("%s: ok", testName);
if(testResult) {
if(testResult == 2) {
Output("%s: failed -> no assert");
} else {
Output("%s: failed");
}
} else {
Output("%s: ok", testName);
}
}

void
PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
time_t eventTime)
time_t eventTime)
{
const char *result = (assertResult) ? "passed" : "failed";
Output("%s: %s", assertName, assertMessage);
}

void
PlainAssertWithValues(const char *assertName, int assertResult, const char *assertMessage,
int actualValue, int excpected, time_t eventTime)
{
const char *result = (assertResult) ? "passed" : "failed";
Output("%s %d: %s", assertName, assertResult, assertMessage);
Expand All @@ -80,7 +105,8 @@ PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
void
PlainAssertSummary(int numAsserts, int numAssertsFailed, int numAssertsPass, time_t eventTime)
{
Output("Asserts:%d", numAsserts);
Output("Assert summary: %d failed, %d passed (total: %d)",
numAssertsFailed, numAssertsPass, numAsserts);
}

void
Expand Down
5 changes: 4 additions & 1 deletion test/test-automation/plain_logger.h
Expand Up @@ -21,7 +21,10 @@ void PlainTestEnded(const char *testName, const char *suiteName,


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

void PlainAssertWithValues(const char *assertName, int assertResult, const char *assertMessage,
int actualValue, int excpected, time_t eventTime);

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

Expand Down

0 comments on commit 595566d

Please sign in to comment.