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

Logging system added to harness. Logging system doesn't

yet utilize all the given parameters.
  • Loading branch information
mkauppila committed Jun 26, 2011
1 parent e280ba6 commit f7633bda545c715b128801bd05d95f2a9ef72299
@@ -3,15 +3,10 @@ ACLOCAL_AMFLAGS = -I acinclude -I build-scripts
SUBDIRS = testdummy testrect testplatform

bin_PROGRAMS = runner
runner_SOURCES = runner.c SDL_test.c
runner_SOURCES = runner.c SDL_test.c logger.c xml_logger.c plain_logger.c xml.c
runner_CLAGS = -W -Wall -Wextra -g `sdl-config --cflags` -DSDL_NO_COMPAT
runner_LDFLAGS = `sdl-config --libs`

bin_PROGRAMS = logger
logger_SOURCES = xml_logger.c xml.c plain_logger.c logger.c
logger_CLAGS = -W -Wall -Wextra -g `sdl-config --cflags` -DSDL_NO_COMPAT
logger_LDFLAGS = `sdl-config --libs`

install: install-tests
install-tests:
-mkdir tests
@@ -24,6 +24,8 @@
#include <stdio.h> /* printf/fprintf */
#include <stdarg.h> /* va_list */

#include "logger.h"

#include "SDL_test.h"

/*! \brief return value of test case. Non-zero value means that the test failed */
@@ -36,8 +38,16 @@ int _testAssertsFailed;
int _testAssertsPassed;

void
_TestCaseInit()
_TestCaseInit(const int enable_xml_logging)
{
// setup logging functions
// rather afwul way to do it, but function pointers didn't work
if(enable_xml_logging) {
SetupXMLLogger();
} else {
SetupPlainLogger();
}

_testReturnValue = 0;
_testAssertsFailed = 0;
_testAssertsPassed = 0;
@@ -46,8 +56,9 @@ _TestCaseInit()
int
_TestCaseQuit()
{
//! \todo make the test fail, if it does not contain any asserts
printf("Asserts: passed %d, failed %d\n", _testAssertsPassed, _testAssertsFailed);
//printf("Asserts: passed %d, failed %d\n", _testAssertsPassed, _testAssertsFailed);
AssertSummary(_testAssertsFailed + _testAssertsPassed,
_testAssertsFailed, _testAssertsPassed);

if(_testAssertsFailed == 0 && _testAssertsPassed == 0) {
_testReturnValue = 2;
@@ -66,11 +77,15 @@ 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);
//printf("AssertEquals failed: expected %d, got %d; %s\n", expected, actual, buf);
Assert("AssertEquals", 0, buf, 0);

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

_testAssertsPassed++;
}
}
@@ -86,12 +101,15 @@ AssertTrue(int condition, char *message, ...)
SDL_vsnprintf( buf, sizeof(buf), message, args );
va_end( args );

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

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

@@ -105,7 +123,8 @@ AssertPass(char *message, ...)
SDL_vsnprintf( buf, sizeof(buf), message, args );
va_end( args );

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

_testAssertsPassed++;
}
@@ -120,7 +139,8 @@ AssertFail(char *message, ...)
SDL_vsnprintf( buf, sizeof(buf), message, args );
va_end( args );

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

_testAssertsFailed++;
}
@@ -23,6 +23,8 @@

#include <SDL/SDL.h>

#include "logger.h"

extern int _testReturnValue;
extern int _testAssertsFailed;
extern int _testAssertsPassed;
@@ -52,7 +54,7 @@ typedef struct TestCaseReference {
* the beginning of every test case, before doing
* anything else.
*/
void _TestCaseInit();
void _TestCaseInit(const int enable_xml_logging);

/*! \fn _TestCaseQuit
* Deinitializes and exits the test case
@@ -18,8 +18,45 @@ SuiteEndedFp SuiteEnded = 0;
TestStartedFp TestStarted = 0;
TestEndedFp TestEnded = 0;
AssertFp Assert = 0;
AssertSummaryFp AssertSummary = 0;
LogFp Log = 0;

int
SetupXMLLogger()
{
RunStarted = XMLRunStarted;
RunEnded = XMLRunEnded;

SuiteStarted = XMLSuiteStarted;
SuiteEnded = XMLSuiteEnded;

TestStarted = XMLTestStarted;
TestEnded = XMLTestEnded;

Assert = XMLAssert;
AssertSummary = XMLAssertSummary;

Log = XMLLog;
}

int
SetupPlainLogger()
{
RunStarted = PlainRunStarted;
RunEnded = PlainRunEnded;

SuiteStarted = PlainSuiteStarted;
SuiteEnded = PlainSuiteEnded;

TestStarted = PlainTestStarted;
TestEnded = PlainTestEnded;

Assert = PlainAssert;
AssertSummary = PlainAssertSummary;

Log = PlainLog;
}

/*!
* Prints the given message to stderr. Function adds nesting
* to the output.
@@ -39,6 +76,7 @@ LogGenericOutput(const char *message, ...)
fflush(stderr);
}

#if 0
/*!
* Test app for logging functionality
*/
@@ -48,29 +86,9 @@ main(int argc, char *argv[])
int xml_enabled = 1;

if(xml_enabled) {
RunStarted = XMLRunStarted;
RunEnded = XMLRunEnded;

SuiteStarted = XMLSuiteStarted;
SuiteEnded = XMLSuiteEnded;

TestStarted = XMLTestStarted;
TestEnded = XMLTestEnded;

Assert = XMLAssert;
Log = XMLLog;
SetupXMLLogger();
} else {
RunStarted = PlainRunStarted;
RunEnded = PlainRunEnded;

SuiteStarted = PlainSuiteStarted;
SuiteEnded = PlainSuiteEnded;

TestStarted = PlainTestStarted;
TestEnded = PlainTestEnded;

Assert = PlainAssert;
Log = PlainLog;
SetupPlainLogger();
}

RunStarted(LogGenericOutput, "some_<data_>here&here", 0);
@@ -84,3 +102,4 @@ main(int argc, char *argv[])

return 0;
}
#endif
@@ -26,7 +26,6 @@
// Function pointer to function which handles to output
typedef int (*LogOutputFp)(const char *, ...);


/*!
* Generic logger interface
*
@@ -42,12 +41,29 @@ typedef void (*SuiteEndedFp)(int testsPassed, int testsFailed, int testsSkipped,
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,
int numAsserts, time_t endTime, time_t totalRuntime);
time_t endTime, time_t 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 (*LogFp)(const char *logMessage, time_t eventTime);

int LogGenericOutput(const char *message, ...);

extern RunStartedFp RunStarted;
extern RunEndedFp RunEnded;
extern SuiteStartedFp SuiteStarted;
extern SuiteEndedFp SuiteEnded;
extern TestStartedFp TestStarted;
extern TestEndedFp TestEnded;
extern AssertFp Assert;
extern AssertSummaryFp AssertSummary;
extern LogFp Log;

#endif
@@ -13,52 +13,64 @@ void
PlainRunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTime)
{
logger = outputFn;
logger("Test run started");
logger("Given command line options: %s", "add options");
}

void
PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
time_t endTime, time_t totalRuntime)
{
// \todo add total number of tests, suites, pass/failure test count
logger("Ran %d tests in %0.5f seconds.", testCount, totalRuntime);

logger("%d tests passed", testPassCount);
logger("%d tests failed", testFailCount);
}

void
PlainSuiteStarted(const char *suiteName, time_t eventTime)
{
logger("Executing tests in %s\n", suiteName);
logger("Executing tests in %s", suiteName);
}

void
PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
double endTime, time_t totalRuntime)
{
logger("Suite executed. %d passed, %d failed and %d skipped\n", testsPassed, testsFailed, testsSkipped);
logger("Suite executed. %d passed, %d failed and %d skipped", testsPassed, testsFailed, testsSkipped);
}

void
PlainTestStarted(const char *testName, const char *suiteName, const char *testDescription, time_t startTime)
{
logger("test %s (in %s) started", testName, suiteName);
}

void
PlainTestEnded(const char *testName, const char *suiteName,
int testResult, int numAsserts, time_t endTime, time_t totalRuntime)
int testResult, time_t endTime, time_t totalRuntime)
{
logger("Asserts:%d\n", numAsserts);
logger("%s: ok\n", testName);
logger("%s: ok", testName);
}

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

void
PlainAssertSummary(int numAsserts, int numAssertsFailed, int numAssertsPass)
{
logger("Asserts:%d", numAsserts);
}

void
PlainLog(const char *logMessage, time_t eventTime)
{
logger("%s %d", logMessage, eventTime);
}

#endif
@@ -17,11 +17,15 @@ void PlainTestStarted(const char *testName, const char *suiteName,
const char *testDescription, time_t startTime);

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


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

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


void PlainLog(const char *logMessage, time_t eventTime);

#endif

0 comments on commit f7633bd

Please sign in to comment.