summaryrefslogtreecommitdiffstats
path: root/src/testlib/qabstracttestlogger.cpp
diff options
context:
space:
mode:
authorJason McDonald <jason.mcdonald@nokia.com>2011-12-12 11:46:45 +1000
committerQt by Nokia <qt-info@nokia.com>2011-12-12 05:01:00 +0100
commitc5ee721795178ce38c61daf0f8bec0e762bdc3d7 (patch)
tree2cbdda475d4854763e3d4967a721ad4b239761ad /src/testlib/qabstracttestlogger.cpp
parent4c1f5edda6f6b5318a2564cba15551f8108ad264 (diff)
Filter unprintable chars out of all test output.
Previously, unprintable characters were filtered out of test output while the output strings were being formatted by either qt_snprintf() or qt_asprintf(). Any strings not formatted by one of those functions weren't filtered at all, and any strings passed more than once would be filtered more than once. This commit separates the filtering of output strings from their formatting, leaving the filtering until just before the strings are written to the output stream. For now, the filtering is done by a protected method of QAbstractTestLogger, but this could easily be changed to a virtual method in future to allow different filtering for loggers with different output character sets. Change-Id: Ia4bb49cd10d37c84af75d2cf58325d27f0e16d99 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
Diffstat (limited to 'src/testlib/qabstracttestlogger.cpp')
-rw-r--r--src/testlib/qabstracttestlogger.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/testlib/qabstracttestlogger.cpp b/src/testlib/qabstracttestlogger.cpp
index f7d8842c4c..9ac1de9909 100644
--- a/src/testlib/qabstracttestlogger.cpp
+++ b/src/testlib/qabstracttestlogger.cpp
@@ -80,12 +80,28 @@ QAbstractTestLogger::~QAbstractTestLogger()
stream = 0;
}
+void QAbstractTestLogger::filterUnprintable(char *str) const
+{
+ char *idx = str;
+ while (*idx) {
+ if (((*idx < 0x20 && *idx != '\n' && *idx != '\t') || *idx > 0x7e))
+ *idx = '?';
+ ++idx;
+ }
+}
+
void QAbstractTestLogger::outputString(const char *msg)
{
QTEST_ASSERT(stream);
- ::fputs(msg, stream);
+ char *filtered = new char[strlen(msg) + 1];
+ strcpy(filtered, msg);
+ filterUnprintable(filtered);
+
+ ::fputs(filtered, stream);
::fflush(stream);
+
+ delete [] filtered;
}
void QAbstractTestLogger::startLogging()
@@ -135,8 +151,6 @@ int qt_asprintf(QTestCharBuffer *str, const char *format, ...)
break; // out of memory - take what we have
}
- filter_unprintable(str->data());
-
return res;
}