summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtest_widgets.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2014-12-17 15:49:50 +0100
committerThiago Macieira <thiago.macieira@intel.com>2015-01-16 03:12:59 +0100
commitba7653fb74a288fbb0c7df3c24001b7170e087ae (patch)
treef3eea61c711d133460cf20f12f58beed50fd3fb9 /src/testlib/qtest_widgets.h
parent49057a1eab3d226d504db0e12e65e27fa9b42c2d (diff)
qtest_widgets.h: add support for pretty-printing QSizePolicy
... in QCOMPAREs. The implementation is hidden in a nested Internal namespace that retrieves the strings without strdup()ing. That makes it easier to compose these functions as there is no need to delete character arrays when using them. The public interface (which qstrdup()s) is implemented on top of these. [ChangeLog][QtTest] QCOMPARE now pretty-prints QSizePolicy{,::Policy,::ControlType{,s}}. Change-Id: Ib03d969847e5a12474c71a7921366b400025f680 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/testlib/qtest_widgets.h')
-rw-r--r--src/testlib/qtest_widgets.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/testlib/qtest_widgets.h b/src/testlib/qtest_widgets.h
index f188e60b16..8d7752f964 100644
--- a/src/testlib/qtest_widgets.h
+++ b/src/testlib/qtest_widgets.h
@@ -49,8 +49,72 @@
#pragma qt_no_master_include
#endif
+#include <QtWidgets/QSizePolicy>
+#include <QtCore/QMetaEnum>
+
QT_BEGIN_NAMESPACE
+namespace QTest
+{
+
+//
+// QSizePolicy & friends:
+//
+
+namespace Internal
+{
+
+inline const char *toString(QSizePolicy::Policy p)
+{
+ static const QMetaEnum me = QSizePolicy::staticMetaObject.enumerator(QSizePolicy::staticMetaObject.indexOfEnumerator("Policy"));
+ return me.valueToKey(int(p));
+}
+
+inline QByteArray toString(QSizePolicy::ControlTypes ct)
+{
+ static const QMetaEnum me = QSizePolicy::staticMetaObject.enumerator(QSizePolicy::staticMetaObject.indexOfEnumerator("ControlTypes"));
+ return me.valueToKeys(int(ct));
+}
+
+inline QByteArray toString(QSizePolicy sp)
+{
+ static const char comma[] = ", ";
+ return QByteArray("QSizePolicy(")
+ + Internal::toString(sp.horizontalPolicy()) + comma
+ + Internal::toString(sp.verticalPolicy()) + comma
+ + QByteArray::number(sp.horizontalStretch()) + comma
+ + QByteArray::number(sp.verticalStretch()) + comma
+ + Internal::toString(QSizePolicy::ControlTypes(sp.controlType())) + comma
+ + "height for width: " + (sp.hasHeightForWidth() ? "yes" : "no") + comma
+ + "width for height: " + (sp.hasWidthForHeight() ? "yes" : "no") + comma
+ + (sp.retainSizeWhenHidden() ? "" : "don't " ) + "retain size when hidden"
+ + ')';
+}
+
+} // namespace Internal
+
+inline char *toString(QSizePolicy::Policy p)
+{
+ return qstrdup(Internal::toString(p));
+}
+
+inline char *toString(QSizePolicy::ControlTypes ct)
+{
+ return qstrdup(Internal::toString(ct).constData());
+}
+
+inline char *toString(QSizePolicy::ControlType ct)
+{
+ return toString(QSizePolicy::ControlTypes(ct));
+}
+
+inline char *toString(QSizePolicy sp)
+{
+ return qstrdup(Internal::toString(sp).constData());
+}
+
+} // namespace QTest
+
QT_END_NAMESPACE
#endif