summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-02-23 11:54:21 +0100
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-02-25 09:45:30 +0000
commit3126fa227b96b5e59e9975a47d78cd6245365b07 (patch)
tree4df2b2f7594a7ffd959b1d01ff493bd259292516
parentde9de96d81cdbad4880cc06fcfbe928606c3143e (diff)
Improve QCOMPARE output of char comparisons
Make actual and expected values of char tests more useful by using C syntax. This means we can actually read non-printable characters. Task-number: QTBUG-51294 Change-Id: I031e15916a2882c0499b6217ae1649d4eea09eb4 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
-rw-r--r--src/testlib/qtestcase.cpp48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 7b567674e4..4720c0564e 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -2296,12 +2296,58 @@ TO_STRING_IMPL(qint64, %lld)
TO_STRING_IMPL(quint64, %llu)
#endif
TO_STRING_IMPL(bool, %d)
-TO_STRING_IMPL(char, %c)
TO_STRING_IMPL(signed char, %hhd)
TO_STRING_IMPL(unsigned char, %hhu)
TO_STRING_IMPL(float, %g)
TO_STRING_IMPL(double, %lg)
+template <> Q_TESTLIB_EXPORT char *QTest::toString<char>(const char &t)
+{
+ unsigned char c = static_cast<unsigned char>(t);
+ char *msg = new char[16];
+ switch (c) {
+ case 0x00:
+ qstrcpy(msg, "'\\0'");
+ break;
+ case 0x07:
+ qstrcpy(msg, "'\\a'");
+ break;
+ case 0x08:
+ qstrcpy(msg, "'\\b'");
+ break;
+ case 0x09:
+ qstrcpy(msg, "'\\t'");
+ break;
+ case 0x0a:
+ qstrcpy(msg, "'\\n'");
+ break;
+ case 0x0b:
+ qstrcpy(msg, "'\\v'");
+ break;
+ case 0x0c:
+ qstrcpy(msg, "'\\f'");
+ break;
+ case 0x0d:
+ qstrcpy(msg, "'\\r'");
+ break;
+ case 0x22:
+ qstrcpy(msg, "'\\\"'");
+ break;
+ case 0x27:
+ qstrcpy(msg, "'\\\''");
+ break;
+ case 0x5c:
+ qstrcpy(msg, "'\\\\'");
+ break;
+ default:
+ if (c < 0x20 || c >= 0x7F)
+ qsnprintf(msg, 16, "'\\x%02x'", c);
+ else
+ qsnprintf(msg, 16, "'%c'" , c);
+ }
+ return msg;
+}
+
/*! \internal
*/
char *QTest::toString(const char *str)