summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp
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 /tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp
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 'tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp')
-rw-r--r--tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp50
1 files changed, 50 insertions, 0 deletions
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()
{
{