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
e6225c94
Commit
e6225c94
authored
13 years ago
by
Markus Kauppila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added escaping special characters to their corresponding
entities in XML output.
parent
2dd346fa
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
7 deletions
+57
-7
logger.c
test/test-automation/logger.c
+1
-5
xml.c
test/test-automation/xml.c
+54
-2
xml_logger.c
test/test-automation/xml_logger.c
+2
-0
No files found.
test/test-automation/logger.c
View file @
e6225c94
...
...
@@ -31,7 +31,6 @@ LogGenericOutput(const char *message)
fflush
(
stderr
);
}
/*!
* Test app for logging functionality
*/
...
...
@@ -66,15 +65,12 @@ main(int argc, char *argv[])
Log
=
PlainLog
;
}
RunStarted
(
LogGenericOutput
,
"some_
data_
here"
,
0
);
RunStarted
(
LogGenericOutput
,
"some_
<data_>here&
here"
,
0
);
SuiteStarted
(
"Suite data here"
,
0
);
TestStarted
(
"test1"
,
"suite"
,
"desc"
,
0
);
TestEnded
(
"test1"
,
"suite"
,
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
,
0
,
0
,
0
,
0
);
...
...
This diff is collapsed.
Click to expand it.
test/test-automation/xml.c
View file @
e6225c94
...
...
@@ -104,6 +104,57 @@ PrintOpenTags()
}
}
/*!
* Converts the special characters ', ", <, >, and & to
* corresponding entities: ' " < > and &
*
* \param string String to be escaped
* \return Escaped string
*/
const
char
*
EscapeString
(
const
char
*
string
)
{
const
int
bufferSize
=
4096
;
char
buffer
[
bufferSize
];
memset
(
buffer
,
0
,
bufferSize
);
// prevents the code doing a 'bus error'
char
stringBuffer
[
bufferSize
];
strncpy
(
stringBuffer
,
string
,
bufferSize
);
// Ampersand (&) must be first, otherwise it'll mess up the other entities
char
*
characters
[]
=
{
"&"
,
"'"
,
"
\"
"
,
"<"
,
">"
};
char
*
entities
[]
=
{
"&"
,
"'"
,
"""
,
"<"
,
">"
};
int
maxCount
=
5
;
int
counter
=
0
;
for
(;
counter
<
maxCount
;
++
counter
)
{
char
*
character
=
characters
[
counter
];
char
*
entity
=
entities
[
counter
];
if
(
strstr
(
stringBuffer
,
character
)
==
NULL
)
continue
;
char
*
token
=
strtok
(
stringBuffer
,
character
);
while
(
token
)
{
char
*
nextToken
=
strtok
(
NULL
,
character
);
//! \todo use strncat and count the bytes left in the buffer
strcat
(
buffer
,
token
);
if
(
nextToken
)
strcat
(
buffer
,
entity
);
token
=
nextToken
;
}
memcpy
(
stringBuffer
,
buffer
,
bufferSize
);
memset
(
buffer
,
0
,
bufferSize
);
}
return
stringBuffer
;
}
/*
===================
...
...
@@ -131,7 +182,6 @@ XMLOpenDocument(const char *rootTag, LogOutputFp log)
snprintf
(
buffer
,
bufferSize
,
"<%s>"
,
rootTag
);
logger
(
buffer
);
// add open tag
AddOpenTag
(
rootTag
);
root
=
rootTag
;
// it's fine, as long as rootTag points to static memory?
...
...
@@ -167,8 +217,10 @@ XMLOpenElementWithAttribute(const char *tag, Attribute *attribute)
void
XMLAddContent
(
const
char
*
content
)
{
const
char
*
escapedContent
=
EscapeString
(
content
);
memset
(
buffer
,
0
,
bufferSize
);
snprintf
(
buffer
,
bufferSize
,
"%s"
,
c
ontent
);
snprintf
(
buffer
,
bufferSize
,
"%s"
,
escapedC
ontent
);
logger
(
buffer
);
}
...
...
This diff is collapsed.
Click to expand it.
test/test-automation/xml_logger.c
View file @
e6225c94
...
...
@@ -26,6 +26,8 @@
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
);
XMLOpenElement
(
"parameters"
);
...
...
This diff is collapsed.
Click to expand it.
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