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
7b600bf8
Commit
7b600bf8
authored
Jun 23, 2011
by
Markus Kauppila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
XML component no longer outputs the generated XML.
Fixed a bunch of compiler warnings.
parent
eb1a1826
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
162 additions
and
54 deletions
+162
-54
plain_logger.c
test/test-automation/plain_logger.c
+1
-1
xml.c
test/test-automation/xml.c
+54
-17
xml.h
test/test-automation/xml.h
+7
-6
xml_logger.c
test/test-automation/xml_logger.c
+100
-30
No files found.
test/test-automation/plain_logger.c
View file @
7b600bf8
...
...
@@ -53,7 +53,7 @@ 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
);
printf
(
"%s %
d
: %s
\n
"
,
assertName
,
assertResult
,
assertMessage
);
}
void
...
...
test/test-automation/xml.c
View file @
7b600bf8
...
...
@@ -118,7 +118,7 @@ const char *EscapeString(const char *string) {
memset
(
buffer
,
0
,
bufferSize
);
// prevents the code doing a 'bus error'
char
stringBuffer
[
bufferSize
]
;
char
*
stringBuffer
=
SDL_malloc
(
bufferSize
)
;
strncpy
(
stringBuffer
,
string
,
bufferSize
);
// Ampersand (&) must be first, otherwise it'll mess up the other entities
...
...
@@ -170,40 +170,55 @@ static const char *root;
/*! Buffer for storing the xml element under construction */
static
char
buffer
[
bufferSize
];
void
XMLOpenDocument
(
const
char
*
rootTag
,
LogOutputFp
log
)
char
*
XMLOpenDocument
(
const
char
*
rootTag
)
{
assert
(
log
!=
NULL
);
logger
=
log
;
logger
(
"<?xml version=
\"
1.0
\"
encoding=
\"
utf-8
\"
?>"
);
const
char
*
doctype
=
"<?xml version=
\"
1.0
\"
encoding=
\"
utf-8
\"
?>
\n
"
;
memset
(
buffer
,
0
,
bufferSize
);
snprintf
(
buffer
,
bufferSize
,
"<%s>"
,
rootTag
);
logger
(
buffer
);
//
logger(buffer);
AddOpenTag
(
rootTag
);
root
=
rootTag
;
// it's fine, as long as rootTag points to static memory?
const
int
doctypeSize
=
SDL_strlen
(
doctype
);
const
int
tagSize
=
SDL_strlen
(
buffer
);
const
int
size
=
doctypeSize
+
tagSize
+
1
;
// extra byte for '\0'
char
*
ret
=
SDL_malloc
(
size
);
// copy doctype
strncpy
(
ret
,
doctype
,
doctypeSize
);
// copy tag
strncpy
(
ret
+
doctypeSize
,
buffer
,
tagSize
);
ret
[
size
]
=
'\0'
;
return
ret
;
}
void
char
*
XMLCloseDocument
()
{
XMLCloseElement
(
root
);
return
XMLCloseElement
(
root
);
}
void
char
*
XMLOpenElement
(
const
char
*
tag
)
{
memset
(
buffer
,
0
,
bufferSize
);
snprintf
(
buffer
,
bufferSize
,
"<%s>"
,
tag
);
logger
(
buffer
);
AddOpenTag
(
tag
);
const
int
size
=
SDL_strlen
(
buffer
);
char
*
ret
=
SDL_malloc
(
size
+
1
);
strncpy
(
ret
,
buffer
,
size
);
ret
[
size
]
=
'\0'
;
return
ret
;
}
void
char
*
XMLOpenElementWithAttribute
(
const
char
*
tag
,
Attribute
*
attribute
)
{
memset
(
buffer
,
0
,
bufferSize
);
...
...
@@ -212,21 +227,38 @@ XMLOpenElementWithAttribute(const char *tag, Attribute *attribute)
logger
(
buffer
);
AddOpenTag
(
tag
);
const
int
size
=
SDL_strlen
(
buffer
);
char
*
ret
=
SDL_malloc
(
size
+
1
);
strncpy
(
ret
,
buffer
,
size
);
ret
[
size
]
=
'\0'
;
return
ret
;
}
void
char
*
XMLAddContent
(
const
char
*
content
)
{
const
char
*
escapedContent
=
EscapeString
(
content
);
memset
(
buffer
,
0
,
bufferSize
);
snprintf
(
buffer
,
bufferSize
,
"%s"
,
escapedContent
);
logger
(
buffer
);
SDL_free
((
char
*
)
escapedContent
);
const
int
size
=
SDL_strlen
(
buffer
);
char
*
ret
=
SDL_malloc
(
size
+
1
);
strncpy
(
ret
,
buffer
,
size
);
ret
[
size
]
=
'\0'
;
return
ret
;
}
void
char
*
XMLCloseElement
(
const
char
*
tag
)
{
char
*
ret
=
SDL_malloc
(
bufferSize
);
memset
(
ret
,
0
,
bufferSize
);
// Close the open tags with proper nesting. Closes tags until it finds
// the given tag which is the last tag that will be closed
TagList
*
openTag
=
openTags
;
...
...
@@ -235,7 +267,10 @@ XMLCloseElement(const char *tag)
memset
(
buffer
,
0
,
bufferSize
);
snprintf
(
buffer
,
bufferSize
,
"</%s>"
,
openTag
->
tag
);
logger
(
buffer
);
// \todo use strNcat
strcat
(
ret
,
buffer
);
//logger(buffer);
const
int
openTagSize
=
SDL_strlen
(
openTag
->
tag
);
const
int
tagSize
=
SDL_strlen
(
tag
);
...
...
@@ -254,5 +289,7 @@ XMLCloseElement(const char *tag)
break
;
}
}
return
ret
;
}
test/test-automation/xml.h
View file @
7b600bf8
...
...
@@ -35,34 +35,35 @@ typedef struct Attribute {
* Creates header and start tag for root element.
*
* \param rootTag Root tag for the XML document
* \return The generated XML output
*/
void
XMLOpenDocument
(
const
char
*
rootTag
,
LogOutputFp
lo
g
);
char
*
XMLOpenDocument
(
const
char
*
rootTa
g
);
/*!
* Closes the XML-document.
* Creates end tag for root element and closes other open elements
* with correct nesting.
*/
void
XMLCloseDocument
();
char
*
XMLCloseDocument
();
/*!
* Opens XML-element.
*
* \param tag Element to be opened
*/
void
XMLOpenElement
(
const
char
*
tag
);
char
*
XMLOpenElement
(
const
char
*
tag
);
/*!
* Opens XML-element with given attributes
*/
void
XMLOpenElementWithAttribute
(
const
char
*
tag
,
Attribute
*
attribute
);
char
*
XMLOpenElementWithAttribute
(
const
char
*
tag
,
Attribute
*
attribute
);
/*!
* Add content to currently open element.
*
* \param content Content for the currently open element
*/
void
XMLAddContent
(
const
char
*
content
);
char
*
XMLAddContent
(
const
char
*
content
);
/*!
* Closes previously opened element until tag given as parameter is met.
...
...
@@ -73,7 +74,7 @@ void XMLAddContent(const char *content);
*
* \param tag Element to close
*/
void
XMLCloseElement
(
const
char
*
tag
);
char
*
XMLCloseElement
(
const
char
*
tag
);
#endif
test/test-automation/xml_logger.c
View file @
7b600bf8
...
...
@@ -18,95 +18,165 @@
3. This notice may not be removed or altered from any source distribution.
*/
#include <SDL/SDL.h>
#include "xml.h"
#include "logger.h"
#include "xml_logger.h"
LogOutputFp
logger
;
void
XMLRunStarted
(
LogOutputFp
outputFn
,
const
char
*
runnerParameters
,
time_t
eventTime
)
{
//! \todo Giving outputFn to the function is awful, fix it
//! Make the outputting differently
XMLOpenDocument
(
"testlog"
,
outputFn
);
logger
=
outputFn
;
char
*
output
=
XMLOpenDocument
(
"testlog"
);
logger
(
output
);
SDL_free
(
output
);
output
=
XMLOpenElement
(
"parameters"
);
logger
(
output
);
SDL_free
(
output
);
XMLOpenElement
(
"parameters"
);
XMLAddContent
(
runnerParameters
);
XMLCloseElement
(
"parameters"
);
output
=
XMLAddContent
(
runnerParameters
);
logger
(
output
);
SDL_free
(
output
);
output
=
XMLCloseElement
(
"parameters"
);
logger
(
output
);
SDL_free
(
output
);
}
void
XMLRunEnded
(
int
testCount
,
int
suiteCount
,
int
testPassCount
,
int
testFailCount
,
time_t
endTime
,
time_t
totalRuntime
)
{
XMLCloseDocument
(
"testlog"
);
char
*
output
=
XMLCloseDocument
(
"testlog"
);
logger
(
output
);
SDL_free
(
output
);
}
void
XMLSuiteStarted
(
const
char
*
suiteName
,
time_t
eventTime
)
{
XMLOpenElement
(
"suite"
);
char
*
output
=
XMLOpenElement
(
"suite"
);
logger
(
output
);
SDL_free
(
output
);
output
=
XMLOpenElement
(
"eventTime"
);
logger
(
output
);
SDL_free
(
output
);
XMLOpenElement
(
"eventTime"
);
//XMLAddContent(evenTime);
XMLCloseElement
(
"eventTime"
);
output
=
XMLCloseElement
(
"eventTime"
);
logger
(
output
);
SDL_free
(
output
);
}
void
XMLSuiteEnded
(
int
testsPassed
,
int
testsFailed
,
int
testsSkipped
,
double
endTime
,
time_t
totalRuntime
)
{
XMLCloseElement
(
"suite"
);
char
*
output
=
XMLCloseElement
(
"suite"
);
logger
(
output
);
SDL_free
(
output
);
}
void
XMLTestStarted
(
const
char
*
testName
,
const
char
*
suiteName
,
const
char
*
testDescription
,
time_t
startTime
)
{
XMLOpenElement
(
"test"
);
char
*
output
=
XMLOpenElement
(
"test"
);
logger
(
output
);
SDL_free
(
output
);
Attribute
attribute
=
{
"test"
,
"value"
};
//Attribute attribute = {"test", "value"};
//XMLOpenElementWithAttribute("name", &attribute);
output
=
XMLOpenElement
(
"name"
);
logger
(
output
);
SDL_free
(
output
);
XMLOpenElementWithAttribute
(
"name"
,
&
attribut
e
);
XMLAddContent
(
testName
);
XMLCloseElement
(
"name"
);
output
=
XMLAddContent
(
testNam
e
);
logger
(
output
);
SDL_free
(
output
);
XMLOpenElement
(
"description"
);
XMLAddContent
(
testDescription
);
XMLCloseElement
(
"description"
);
output
=
XMLCloseElement
(
"name"
);
logger
(
output
);
SDL_free
(
output
);
output
=
XMLOpenElement
(
"description"
);
logger
(
output
);
SDL_free
(
output
);
output
=
XMLAddContent
(
testDescription
);
logger
(
output
);
SDL_free
(
output
);
output
=
XMLCloseElement
(
"description"
);
logger
(
output
);
SDL_free
(
output
);
output
=
XMLOpenElement
(
"starttime"
);
logger
(
output
);
SDL_free
(
output
);
XMLOpenElement
(
"starttime"
);
//XMLAddContent(startTime);
XMLCloseElement
(
"starttime"
);
output
=
XMLCloseElement
(
"starttime"
);
logger
(
output
);
SDL_free
(
output
);
}
void
XMLTestEnded
(
const
char
*
testName
,
const
char
*
suiteName
,
int
testResult
,
int
numAsserts
,
time_t
endTime
,
time_t
totalRuntime
)
{
XMLCloseElement
(
"test"
);
char
*
output
=
XMLCloseElement
(
"test"
);
logger
(
output
);
SDL_free
(
output
);
}
void
XMLAssert
(
const
char
*
assertName
,
int
assertResult
,
const
char
*
assertMessage
,
time_t
eventTime
)
{
XMLOpenElement
(
"assert"
);
char
*
output
=
XMLOpenElement
(
"assert"
);
logger
(
output
);
SDL_free
(
output
);
output
=
XMLOpenElement
(
"result"
);
logger
(
output
);
SDL_free
(
output
);
XMLOpenElement
(
"result
"
);
XMLAddContent
((
assertResult
)
?
"pass"
:
"failure"
);
XMLOpenElement
(
"result"
);
output
=
XMLAddContent
((
assertResult
)
?
"pass"
:
"failure
"
);
logger
(
output
);
SDL_free
(
output
);
output
=
XMLOpenElement
(
"result"
);
logger
(
output
);
SDL_free
(
output
);
XMLCloseElement
(
"assert"
);
output
=
XMLCloseElement
(
"assert"
);
logger
(
output
);
SDL_free
(
output
);
}
void
XMLLog
(
const
char
*
logMessage
,
time_t
eventTime
)
{
XMLOpenElement
(
"log"
);
char
*
output
=
XMLOpenElement
(
"log"
);
logger
(
output
);
SDL_free
(
output
);
XMLAddContent
(
logMessage
);
output
=
XMLAddContent
(
logMessage
);
logger
(
output
);
SDL_free
(
output
);
XMLCloseElement
(
"log"
);
output
=
XMLCloseElement
(
"log"
);
logger
(
output
);
SDL_free
(
output
);
}
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