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>
This commit is contained in:
parent
4c1f5edda6
commit
c5ee721795
@ -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;
|
||||
}
|
||||
|
||||
|
@ -99,6 +99,7 @@ public:
|
||||
void outputString(const char *msg);
|
||||
|
||||
protected:
|
||||
void filterUnprintable(char *str) const;
|
||||
FILE *stream;
|
||||
};
|
||||
|
||||
|
@ -980,16 +980,6 @@ namespace QTest
|
||||
static bool noCrashHandler = false;
|
||||
#endif
|
||||
|
||||
void filter_unprintable(char *str)
|
||||
{
|
||||
char *idx = str;
|
||||
while (*idx) {
|
||||
if (((*idx < 0x20 && *idx != '\n' && *idx != '\t') || *idx > 0x7e))
|
||||
*idx = '?';
|
||||
++idx;
|
||||
}
|
||||
}
|
||||
|
||||
/*! \internal
|
||||
*/
|
||||
int qt_snprintf(char *str, int size, const char *format, ...)
|
||||
@ -1002,8 +992,6 @@ int qt_snprintf(char *str, int size, const char *format, ...)
|
||||
va_end(ap);
|
||||
str[size - 1] = '\0';
|
||||
|
||||
filter_unprintable(str);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user