summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
authorRohan McGovern <rohan.mcgovern@nokia.com>2009-07-28 06:52:13 (GMT)
committerRohan McGovern <rohan.mcgovern@nokia.com>2009-07-28 22:45:05 (GMT)
commit62d81d9955f39bac327affd703b9df006ee8f6f7 (patch)
tree102f5c8b22a96f17d64d2b3e687c0f9a29b8c203 /src/testlib
parentca1060fbc3a949ec3e0f67017efe8ee6c0b7b86e (diff)
downloadQt-62d81d9955f39bac327affd703b9df006ee8f6f7.zip
Qt-62d81d9955f39bac327affd703b9df006ee8f6f7.tar.gz
Qt-62d81d9955f39bac327affd703b9df006ee8f6f7.tar.bz2
Added a QVariant testlib toString specialization.
If comparing two variants fails, the failure message will now output the type and value of the variants (rather than "Compared values are not the same"). Reviewed-by: Thiago
Diffstat (limited to 'src/testlib')
-rw-r--r--src/testlib/qtest.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/testlib/qtest.h b/src/testlib/qtest.h
index 9d6f68d..8cdfab0 100644
--- a/src/testlib/qtest.h
+++ b/src/testlib/qtest.h
@@ -53,6 +53,7 @@
#include <QtCore/qstringlist.h>
#include <QtCore/qdatetime.h>
#include <QtCore/qobject.h>
+#include <QtCore/qvariant.h>
#include <QtCore/qurl.h>
#include <QtCore/qpoint.h>
@@ -146,6 +147,30 @@ template<> inline char *toString(const QUrl &uri)
return qstrdup(uri.toEncoded().constData());
}
+template<> inline char *toString(const QVariant &v)
+{
+ QByteArray vstring("QVariant(");
+ if (v.isValid()) {
+ QByteArray type(v.typeName());
+ if (type.isEmpty()) {
+ type = QByteArray::number(v.userType());
+ }
+ vstring.append(type);
+ if (!v.isNull()) {
+ vstring.append(',');
+ if (v.canConvert(QVariant::String)) {
+ vstring.append(qVariantValue<QString>(v).toLatin1());
+ }
+ else {
+ vstring.append("<value not representable as string>");
+ }
+ }
+ }
+ vstring.append(')');
+
+ return qstrdup(vstring.constData());
+}
+
#ifndef QTEST_NO_SPECIALIZATIONS
template<>
#endif