Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
94c6ae4e
Commit
94c6ae4e
authored
Jun 21, 2011
by
Markus Kauppila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Various fixes and additions to logger system.
parent
ac07ad67
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
266 additions
and
104 deletions
+266
-104
Makefile.am
test/test-automation/Makefile.am
+1
-1
logger.c
test/test-automation/logger.c
+89
-0
logger.h
test/test-automation/logger.h
+12
-11
plain_logger.c
test/test-automation/plain_logger.c
+63
-0
plain_logger.h
test/test-automation/plain_logger.h
+25
-0
xml.c
test/test-automation/xml.c
+11
-35
xml.h
test/test-automation/xml.h
+3
-2
xml_logger.c
test/test-automation/xml_logger.c
+37
-55
xml_logger.h
test/test-automation/xml_logger.h
+25
-0
No files found.
test/test-automation/Makefile.am
View file @
94c6ae4e
...
@@ -8,7 +8,7 @@ runner_CLAGS = -W -Wall -Wextra -g `sdl-config --cflags` -DSDL_NO_COMPAT
...
@@ -8,7 +8,7 @@ runner_CLAGS = -W -Wall -Wextra -g `sdl-config --cflags` -DSDL_NO_COMPAT
runner_LDFLAGS
=
`
sdl-config
--libs
`
runner_LDFLAGS
=
`
sdl-config
--libs
`
bin_PROGRAMS
=
logger
bin_PROGRAMS
=
logger
logger_SOURCES
=
xml_logger.c xml.c
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_CLAGS
=
-W
-Wall
-Wextra
-g
`
sdl-config
--cflags
`
-DSDL_NO_COMPAT
logger_LDFLAGS
=
`
sdl-config
--libs
`
logger_LDFLAGS
=
`
sdl-config
--libs
`
...
...
test/test-automation/logger.c
0 → 100644
View file @
94c6ae4e
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "logger.h"
#include "xml_logger.h"
#include "plain_logger.h"
// Pointers to selected logger implementation
RunStartedFp
RunStarted
=
0
;
RunEndedFp
RunEnded
=
0
;
SuiteStartedFp
SuiteStarted
=
0
;
SuiteEndedFp
SuiteEnded
=
0
;
TestStartedFp
TestStarted
=
0
;
TestEndedFp
TestEnded
=
0
;
AssertFp
Assert
=
0
;
LogFp
Log
=
0
;
/*!
* Prints the given message to stderr. Function adds nesting
* to the output.
*
* \return Possible error value (\todo)
*/
int
LogGenericOutput
(
const
char
*
message
)
{
/*
int depth = indentDepth;
while(depth--) {
fprintf(stderr, " ");
}
*/
fprintf
(
stderr
,
"%s
\n
"
,
message
);
fflush
(
stderr
);
}
/*!
* Test app for logging functionality
*/
int
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
;
}
else
{
RunStarted
=
PlainRunStarted
;
RunEnded
=
PlainRunEnded
;
SuiteStarted
=
PlainSuiteStarted
;
SuiteEnded
=
PlainSuiteEnded
;
TestStarted
=
PlainTestStarted
;
TestEnded
=
PlainTestEnded
;
Assert
=
PlainAssert
;
Log
=
PlainLog
;
}
RunStarted
(
LogGenericOutput
,
"All the data from harness"
,
0
);
SuiteStarted
(
"Suite data here"
,
0
);
TestStarted
(
"test1"
,
"desc"
,
0
);
TestEnded
(
"test1"
,
"desc"
,
0
,
0
,
0
,
0
);
//XMLTestStarted("test2", "desc", 0);
//XMLTestEnded("test2", "desc", 0, 0, 0, 0);
SuiteEnded
(
0
,
0
,
0
,
0
.
0
f
,
0
);
RunEnded
(
0
,
0
);
return
0
;
}
test/test-automation/logger.h
View file @
94c6ae4e
...
@@ -26,25 +26,26 @@
...
@@ -26,25 +26,26 @@
// Function pointer to function which handles to output
// Function pointer to function which handles to output
typedef
int
(
*
LogOutputFp
)(
const
char
*
);
typedef
int
(
*
LogOutputFp
)(
const
char
*
);
/*!
/*!
* Generic logger interface
* Generic logger interface
*
*
*/
*/
void
RunStarted
(
LogOutputFp
outputFn
,
const
char
*
runnerParameters
,
time_t
eventTime
);
typedef
void
(
*
RunStartedFp
)
(
LogOutputFp
outputFn
,
const
char
*
runnerParameters
,
time_t
eventTime
);
void
RunEnded
(
time_t
endTime
,
time_t
totalRuntime
);
typedef
void
(
*
RunEndedFp
)
(
time_t
endTime
,
time_t
totalRuntime
);
void
SuiteStarted
(
const
char
*
suiteName
,
time_t
eventTime
);
typedef
void
(
*
SuiteStartedFp
)
(
const
char
*
suiteName
,
time_t
eventTime
);
void
SuiteEnded
(
int
testsPassed
,
int
testsFailed
,
int
testsSkipped
,
typedef
void
(
*
SuiteEndedFp
)
(
int
testsPassed
,
int
testsFailed
,
int
testsSkipped
,
double
endTime
,
time_t
totalRuntime
);
double
endTime
,
time_t
totalRuntime
);
void
TestStarted
(
const
char
*
testName
,
const
char
*
testDescription
,
time_t
startTime
);
typedef
void
(
*
TestStartedFp
)
(
const
char
*
testName
,
const
char
*
testDescription
,
time_t
startTime
);
void
TestEnded
(
const
char
*
testName
,
const
char
*
testDescription
,
int
testResult
,
typedef
void
(
*
TestEndedFp
)
(
const
char
*
testName
,
const
char
*
testDescription
,
int
testResult
,
int
numAsserts
,
time_t
endTime
,
time_t
totalRuntime
);
int
numAsserts
,
time_t
endTime
,
time_t
totalRuntime
);
void
Assert
(
const
char
*
assertName
,
int
assertResult
,
const
char
*
assertMessage
,
typedef
void
(
*
AssertFp
)
(
const
char
*
assertName
,
int
assertResult
,
const
char
*
assertMessage
,
time_t
eventTime
);
time_t
eventTime
);
void
Log
(
const
char
*
logMessage
,
time_t
eventTime
);
typedef
void
(
*
LogFp
)
(
const
char
*
logMessage
,
time_t
eventTime
);
#endif
#endif
test/test-automation/plain_logger.c
0 → 100644
View file @
94c6ae4e
#ifndef _PLAIN_LOGGER
#define _PLAIN_LOGGER
#include <stdio.h>
#include "plain_logger.h"
LogOutputFp
logger
=
0
;
void
PlainRunStarted
(
LogOutputFp
outputFn
,
const
char
*
runnerParameters
,
time_t
eventTime
)
{
logger
=
outputFn
;
}
void
PlainRunEnded
(
time_t
endTime
,
time_t
totalRuntime
)
{
// \todo add total number of tests, suites, pass/failure test count
}
void
PlainSuiteStarted
(
const
char
*
suiteName
,
time_t
eventTime
)
{
printf
(
"Executing tests in %s
\n
"
,
suiteName
);
}
void
PlainSuiteEnded
(
int
testsPassed
,
int
testsFailed
,
int
testsSkipped
,
double
endTime
,
time_t
totalRuntime
)
{
printf
(
"Suite executed. %d passed, %d failed and %d skipped
\n
"
,
testsPassed
,
testsFailed
,
testsSkipped
);
}
void
PlainTestStarted
(
const
char
*
testName
,
const
char
*
testDescription
,
time_t
startTime
)
{
}
void
PlainTestEnded
(
const
char
*
testName
,
const
char
*
testDescription
,
int
testResult
,
int
numAsserts
,
time_t
endTime
,
time_t
totalRuntime
)
{
printf
(
"Asserts:%d
\n
"
,
numAsserts
);
printf
(
"%s: ok
\n
"
,
testName
);
}
void
PlainAssert
(
const
char
*
assertName
,
int
assertResult
,
const
char
*
assertMessage
,
time_t
eventTime
)
{
const
char
*
result
=
(
assertResult
)
?
"passed"
:
"failed"
;
printf
(
"%s %s: %s
\n
"
,
assertName
,
assertResult
,
assertMessage
);
}
void
PlainLog
(
const
char
*
logMessage
,
time_t
eventTime
)
{
}
#endif
test/test-automation/plain_logger.h
0 → 100644
View file @
94c6ae4e
#ifndef _PLAIN_LOGGER_H
#define _PLAIN_LOGGER_H
#include "logger.h"
void
PlainRunStarted
(
LogOutputFp
outputFn
,
const
char
*
runnerParameters
,
time_t
eventTime
);
void
PlainRunEnded
(
time_t
endTime
,
time_t
totalRuntime
);
void
PlainSuiteStarted
(
const
char
*
suiteName
,
time_t
eventTime
);
void
PlainSuiteEnded
(
int
testsPassed
,
int
testsFailed
,
int
testsSkipped
,
double
endTime
,
time_t
totalRuntime
);
void
PlainTestStarted
(
const
char
*
testName
,
const
char
*
testDescription
,
time_t
startTime
);
void
PlainTestEnded
(
const
char
*
testName
,
const
char
*
testDescription
,
int
testResult
,
int
numAsserts
,
time_t
endTime
,
time_t
totalRuntime
);
void
PlainAssert
(
const
char
*
assertName
,
int
assertResult
,
const
char
*
assertMessage
,
time_t
eventTime
);
void
PlainLog
(
const
char
*
logMessage
,
time_t
eventTime
);
#endif
test/test-automation/xml.c
View file @
94c6ae4e
...
@@ -19,10 +19,11 @@
...
@@ -19,10 +19,11 @@
*/
*/
#ifndef _XML_C
#define _XML_C
#include <stdio.h>
#include <stdio.h>
//#include <stdlib.h>
#include <string.h>
#include <string.h>
//#include <stdarg.h>
#include <assert.h>
#include <assert.h>
#include <SDL/SDL.h>
#include <SDL/SDL.h>
...
@@ -110,12 +111,12 @@ PrintOpenTags()
...
@@ -110,12 +111,12 @@ PrintOpenTags()
/*
/*
===================
===================
XML
Functions to handle XML creation
===================
===================
*/
*/
static
int
has_open_element
=
0
;
static
const
char
*
root
;
void
void
XMLOpenDocument
(
const
char
*
rootTag
,
LogOutputFp
log
)
XMLOpenDocument
(
const
char
*
rootTag
,
LogOutputFp
log
)
...
@@ -133,29 +134,15 @@ XMLOpenDocument(const char *rootTag, LogOutputFp log)
...
@@ -133,29 +134,15 @@ XMLOpenDocument(const char *rootTag, LogOutputFp log)
// add open tag
// add open tag
AddOpenTag
(
rootTag
);
AddOpenTag
(
rootTag
);
root
=
rootTag
;
// it's fine, as long as rootTag points to static memory?
}
}
void
void
XMLCloseDocument
()
{
XMLCloseDocument
()
{
// Close the open tags with proper nesting
XMLCloseElement
(
root
);
TagList
*
openTag
=
openTags
;
while
(
openTag
)
{
TagList
*
temp
=
openTag
->
next
;
size_t
size
=
SDL_strlen
(
openTag
->
tag
)
+
4
+
1
;
/* one extra for '\0', '<', '/' and '>' */
char
*
buffer
=
SDL_malloc
(
size
);
snprintf
(
buffer
,
size
,
"%s%s%s"
,
"</"
,
openTag
->
tag
,
">"
);
logger
(
buffer
);
SDL_free
(
buffer
);
RemoveOpenTag
(
openTag
->
tag
);
openTag
=
temp
;
}
}
}
static
const
char
*
currentTag
=
NULL
;
void
void
XMLOpenElement
(
const
char
*
tag
)
XMLOpenElement
(
const
char
*
tag
)
{
{
...
@@ -165,10 +152,6 @@ XMLOpenElement(const char *tag)
...
@@ -165,10 +152,6 @@ XMLOpenElement(const char *tag)
logger
(
buffer
);
logger
(
buffer
);
SDL_free
(
buffer
);
SDL_free
(
buffer
);
currentTag
=
tag
;
has_open_element
=
1
;
AddOpenTag
(
tag
);
AddOpenTag
(
tag
);
}
}
...
@@ -183,10 +166,6 @@ XMLOpenElementWithAttribute(const char *tag, Attribute attribute)
...
@@ -183,10 +166,6 @@ XMLOpenElementWithAttribute(const char *tag, Attribute attribute)
logger
(
buffer
);
logger
(
buffer
);
SDL_free
(
buffer
);
SDL_free
(
buffer
);
currentTag
=
tag
;
has_open_element
=
1
;
AddOpenTag
(
tag
);
AddOpenTag
(
tag
);
}
}
...
@@ -194,10 +173,6 @@ XMLOpenElementWithAttribute(const char *tag, Attribute attribute)
...
@@ -194,10 +173,6 @@ XMLOpenElementWithAttribute(const char *tag, Attribute attribute)
void
void
XMLAddAttribute
(
const
char
*
attribute
,
const
char
*
value
)
XMLAddAttribute
(
const
char
*
attribute
,
const
char
*
value
)
{
{
// Requires open element
if
(
has_open_element
==
0
)
{
return
;
}
size_t
attributeSize
=
SDL_strlen
(
attribute
);
size_t
attributeSize
=
SDL_strlen
(
attribute
);
size_t
valueSize
=
SDL_strlen
(
value
);
size_t
valueSize
=
SDL_strlen
(
value
);
...
@@ -249,6 +224,7 @@ XMLCloseElement(const char *tag)
...
@@ -249,6 +224,7 @@ XMLCloseElement(const char *tag)
break
;
break
;
}
}
}
}
has_open_element
=
0
;
}
}
#endif
test/test-automation/xml.h
View file @
94c6ae4e
...
@@ -67,10 +67,11 @@ void XMLAddAttribute(const char *attribute, const char *value);
...
@@ -67,10 +67,11 @@ void XMLAddAttribute(const char *attribute, const char *value);
void
XMLAddContent
(
const
char
*
content
);
void
XMLAddContent
(
const
char
*
content
);
/*!
/*!
* Closes previously opened element.
* Closes previously opened element
until tag given as parameter is met
.
* Enforces proper nesting by not allowing
end elements haphazardly
.
* Enforces proper nesting by not allowing
to close elements out-of-order
.
*
*
* Closes all the opened elements until the given element/tag is found
* Closes all the opened elements until the given element/tag is found
* which will be the last tag to be closed
*
*
* \param tag Element to close
* \param tag Element to close
*/
*/
...
...
test/test-automation/xml_logger.c
View file @
94c6ae4e
...
@@ -18,42 +18,16 @@
...
@@ -18,42 +18,16 @@
3. This notice may not be removed or altered from any source distribution.
3. This notice may not be removed or altered from any source distribution.
*/
*/
#ifndef _LOGGER_C
#ifndef _
XML_
LOGGER_C
#define _LOGGER_C
#define _
XML_
LOGGER_C
#include "xml.h"
#include "logger.h"
#include "logger.h"
#include "xml.h"
#include "xml_logger.h"
#include <SDL/SDL.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
/*!
* Prints the given message to stderr. Function adds nesting
* to the output.
*
* \return Possible error value (\todo)
*/
int
LogGenericOutput
(
const
char
*
message
)
{
/*
int depth = indentDepth;
while(depth--) {
fprintf(stderr, " ");
}
*/
fprintf
(
stderr
,
"%s
\n
"
,
message
);
fflush
(
stderr
);
}
void
void
RunStarted
(
LogOutputFp
outputFn
,
const
char
*
runnerParameters
,
time_t
eventTime
)
XML
RunStarted
(
LogOutputFp
outputFn
,
const
char
*
runnerParameters
,
time_t
eventTime
)
{
{
XMLOpenDocument
(
"testlog"
,
outputFn
);
XMLOpenDocument
(
"testlog"
,
outputFn
);
...
@@ -63,13 +37,13 @@ RunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTime)
...
@@ -63,13 +37,13 @@ RunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTime)
}
}
void
void
RunEnded
(
time_t
endTime
,
time_t
totalRuntime
)
XML
RunEnded
(
time_t
endTime
,
time_t
totalRuntime
)
{
{
XMLCloseDocument
();
XMLCloseDocument
(
"testlog"
);
}
}
void
void
SuiteStarted
(
const
char
*
suiteName
,
time_t
eventTime
)
XML
SuiteStarted
(
const
char
*
suiteName
,
time_t
eventTime
)
{
{
XMLOpenElement
(
"suite"
);
XMLOpenElement
(
"suite"
);
...
@@ -79,51 +53,59 @@ SuiteStarted(const char *suiteName, time_t eventTime)
...
@@ -79,51 +53,59 @@ SuiteStarted(const char *suiteName, time_t eventTime)
}
}
void
void
SuiteEnded
(
int
testsPassed
,
int
testsFailed
,
int
testsSkipped
,
XML
SuiteEnded
(
int
testsPassed
,
int
testsFailed
,
int
testsSkipped
,
double
endTime
,
time_t
totalRuntime
)
double
endTime
,
time_t
totalRuntime
)
{
{
XMLCloseElement
(
"suite"
);
XMLCloseElement
(
"suite"
);
}
}
void
void
TestStarted
(
const
char
*
testName
,
const
char
*
testDescription
,
time_t
startTime
)
XML
TestStarted
(
const
char
*
testName
,
const
char
*
testDescription
,
time_t
startTime
)
{
{
XMLOpenElement
(
"test"
);
XMLOpenElement
(
"name"
);
XMLAddContent
(
testName
);
XMLCloseElement
(
"name"
);
XMLOpenElement
(
"description"
);
XMLAddContent
(
testDescription
);
XMLCloseElement
(
"description"
);
XMLOpenElement
(
"starttime"
);
//XMLAddContent(startTime);
XMLCloseElement
(
"starttime"
);
}
}
void
void
TestEnded
(
const
char
*
testName
,
const
char
*
testDescription
,
int
testResult
,
XMLTestEnded
(
const
char
*
testName
,
const
char
*
testDescription
,
int
numAsserts
,
time_t
endTime
,
time_t
totalRuntime
)
int
testResult
,
int
numAsserts
,
time_t
endTime
,
time_t
totalRuntime
)
{
{
XMLCloseElement
(
"test"
);
}
}
void
void
Assert
(
const
char
*
assertName
,
int
assertResult
,
const
char
*
assertMessage
,
XML
Assert
(
const
char
*
assertName
,
int
assertResult
,
const
char
*
assertMessage
,
time_t
eventTime
)
time_t
eventTime
)
{
{
XMLOpenElement
(
"assert"
);
}
XMLOpenElement
(
"result"
);
XMLAddContent
((
assertResult
)
?
"pass"
:
"failure"
);
XMLOpenElement
(
"result"
);
void
Log
(
const
char
*
logMessage
,
time_t
eventTime
)
{
XMLCloseElement
(
"assert"
);
}
}
void
/*!
XMLLog
(
const
char
*
logMessage
,
time_t
eventTime
)
* Main for testing the logger
*/
int
main
(
int
argc
,
char
*
argv
[])
{
{
RunStarted
(
LogGenericOutput
,
"All the data from harness"
,
0
);
XMLOpenElement
(
"log"
);
SuiteStarted
(
"Suite data here"
,
0
);
SuiteEnded
(
0
,
0
,
0
,
0
.
0
f
,
0
);
XMLAddContent
(
logMessage
);
RunEnded
(
0
,
0
);
return
0
;
XMLCloseElement
(
"log"
)
;
}
}
#endif
#endif
test/test-automation/xml_logger.h
0 → 100644
View file @
94c6ae4e
#ifndef _XML_LOGGER_H
#define _XML_LOGGER_H
#include "logger.h"
void
XMLRunStarted
(
LogOutputFp
outputFn
,
const
char
*
runnerParameters
,
time_t
eventTime
);
void
XMLRunEnded
(
time_t
endTime
,
time_t
totalRuntime
);
void
XMLSuiteStarted
(
const
char
*
suiteName
,
time_t
eventTime
);
void
XMLSuiteEnded
(
int
testsPassed
,
int
testsFailed
,
int
testsSkipped
,
double
endTime
,
time_t
totalRuntime
);
void
XMLTestStarted
(
const
char
*
testName
,
const
char
*
testDescription
,
time_t
startTime
);
void
XMLTestEnded
(
const
char
*
testName
,
const
char
*
testDescription
,
int
testResult
,
int
numAsserts
,
time_t
endTime
,
time_t
totalRuntime
);
void
XMLAssert
(
const
char
*
assertName
,
int
assertResult
,
const
char
*
assertMessage
,
time_t
eventTime
);
void
XMLLog
(
const
char
*
logMessage
,
time_t
eventTime
);
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment