summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/testlib/qtest_widgets.h64
-rw-r--r--src/testlib/qtestcase.cpp37
-rw-r--r--tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp50
3 files changed, 151 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
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 4e7ab18e9b..dc03968258 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -97,6 +97,11 @@ using QtMiscUtils::toHexUpper;
See the \l{Qt Test Overview} for information about how to write unit tests.
*/
+/*!
+ \namespace QTest::Internal
+ \internal
+*/
+
/*! \macro QVERIFY(condition)
\relates QTest
@@ -1041,6 +1046,38 @@ using QtMiscUtils::toHexUpper;
Returns a textual representation of the given \a variant.
*/
+/*!
+ \fn char *QTest::toString(QSizePolicy::ControlType ct)
+ \overload
+ \since 5.5
+
+ Returns a textual representation of control type \a ct.
+*/
+
+/*!
+ \fn char *QTest::toString(QSizePolicy::ControlTypes cts)
+ \overload
+ \since 5.5
+
+ Returns a textual representation of control types \a cts.
+*/
+
+/*!
+ \fn char *QTest::toString(QSizePolicy::Policy p)
+ \overload
+ \since 5.5
+
+ Returns a textual representation of policy \a p.
+*/
+
+/*!
+ \fn char *QTest::toString(QSizePolicy sp)
+ \overload
+ \since 5.5
+
+ Returns a textual representation of size policy \a sp.
+*/
+
/*! \fn void QTest::qWait(int ms)
Waits for \a ms milliseconds. While waiting, events will be processed and
diff --git a/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp b/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp
index 022bd7f61e..eacbd645fa 100644
--- a/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp
+++ b/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp
@@ -40,6 +40,7 @@ class tst_QSizePolicy : public QObject
Q_OBJECT
private Q_SLOTS:
+ void qtest();
void defaultValues();
void getSetCheck();
void dataStream();
@@ -47,6 +48,55 @@ private Q_SLOTS:
void verticalStretch();
};
+
+struct PrettyPrint {
+ const char *m_s;
+ template <typename T>
+ explicit PrettyPrint(const T &t) : m_s(Q_NULLPTR)
+ {
+ using QT_PREPEND_NAMESPACE(QTest)::toString;
+ m_s = toString(t);
+ }
+ ~PrettyPrint() { delete[] m_s; }
+ const char* s() const { return m_s ? m_s : "<null>" ; }
+};
+
+void tst_QSizePolicy::qtest()
+{
+#define CHECK(x) QCOMPARE(PrettyPrint(QSizePolicy::x).s(), #x)
+ // Policy:
+ CHECK(Fixed);
+ CHECK(Minimum);
+ CHECK(Ignored);
+ CHECK(MinimumExpanding);
+ CHECK(Expanding);
+ CHECK(Maximum);
+ CHECK(Preferred);
+ // ControlType:
+ CHECK(ButtonBox);
+ CHECK(CheckBox);
+ CHECK(ComboBox);
+ CHECK(Frame);
+ CHECK(GroupBox);
+ CHECK(Label);
+ CHECK(Line);
+ CHECK(LineEdit);
+ CHECK(PushButton);
+ CHECK(RadioButton);
+ CHECK(Slider);
+ CHECK(SpinBox);
+ CHECK(TabWidget);
+ CHECK(ToolButton);
+#undef CHECK
+#define CHECK2(x, y) QCOMPARE(PrettyPrint(QSizePolicy::x|QSizePolicy::y).s(), \
+ QSizePolicy::x < QSizePolicy::y ? #x "|" #y : #y "|" #x)
+ // ControlTypes (sample)
+ CHECK2(ButtonBox, CheckBox);
+ CHECK2(CheckBox, ButtonBox);
+ CHECK2(ToolButton, Slider);
+#undef CHECK2
+}
+
void tst_QSizePolicy::defaultValues()
{
{