From c5ee721795178ce38c61daf0f8bec0e762bdc3d7 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Mon, 12 Dec 2011 11:46:45 +1000 Subject: 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 --- src/testlib/qabstracttestlogger.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/testlib/qabstracttestlogger.cpp') 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; } -- cgit v1.2.3