diff options
Diffstat (limited to 'src/testlib/qtestcase.cpp')
-rw-r--r-- | src/testlib/qtestcase.cpp | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index cbf479f1d2..ffcc7abbfe 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -2143,18 +2143,26 @@ char *toHexRepresentation(const char *ba, int length) char *toPrettyUnicode(const ushort *p, int length) { // keep it simple for the vast majority of cases - QScopedArrayPointer<char> buffer(new char[length * 6 + 3]); + bool trimmed = false; + QScopedArrayPointer<char> buffer(new char[256]); const ushort *end = p + length; char *dst = buffer.data(); *dst++ = '"'; for ( ; p != end; ++p) { + if (dst - buffer.data() > 245) { + // plus the the quote, the three dots and NUL, it's 250, 251 or 255 + trimmed = true; + break; + } + if (*p < 0x7f && *p >= 0x20 && *p != '\\') { *dst++ = *p; continue; } // write as an escape sequence + // this means we may advance dst to buffer.data() + 246 or 250 *dst++ = '\\'; switch (*p) { case 0x22: @@ -2186,6 +2194,11 @@ char *toPrettyUnicode(const ushort *p, int length) } *dst++ = '"'; + if (trimmed) { + *dst++ = '.'; + *dst++ = '.'; + *dst++ = '.'; + } *dst++ = '\0'; return buffer.take(); } @@ -2863,8 +2876,6 @@ bool QTest::currentTestFailed() void QTest::qSleep(int ms) { QTEST_ASSERT(ms > 0); - QElapsedTimer timer; - timer.start(); #if defined(Q_OS_WINRT) WaitForSingleObjectEx(GetCurrentThread(), ms, true); @@ -2874,20 +2885,6 @@ void QTest::qSleep(int ms) struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 }; nanosleep(&ts, NULL); #endif - // Warn if the elapsed time was more than 50% longer or more than 10% shorter than the - // requested time. - qint64 requested = 1000000 * (qint64)ms; - qint64 diff = timer.nsecsElapsed() - requested; -#ifndef Q_OS_WIN - const qint64 factor = 2; // more than 50% longer -#else - const qint64 factor = 1; // Windows: 50% is quite common, warn about 100% -#endif - if (diff * factor > requested || diff * 10 < -requested) { - QTestLog::warn(qPrintable( - QString::fromLatin1("QTest::qSleep() should have taken %1ns, but actually took %2ns!") - .arg(requested).arg(diff + requested)), __FILE__, __LINE__); - } } /*! \internal |