summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/kernel')
-rw-r--r--tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp34
-rw-r--r--tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp150
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp20
-rw-r--r--tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp4
-rw-r--r--tests/auto/widgets/kernel/qwidgetmetatype/tst_qwidgetmetatype.cpp1
5 files changed, 181 insertions, 28 deletions
diff --git a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp
index 1d6f577192..0691801553 100644
--- a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp
+++ b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp
@@ -42,6 +42,7 @@
#include <qdebug.h>
#include <qstring.h>
#include <qshortcut.h>
+#include <qscreen.h>
class AccelForm;
QT_BEGIN_NAMESPACE
@@ -119,6 +120,7 @@ private slots:
void keypressConsumption();
void unicodeCompare();
void context();
+ void duplicatedShortcutOverride();
protected:
static Qt::KeyboardModifiers toButtons( int key );
@@ -1082,6 +1084,36 @@ void tst_QShortcut::context()
clearAllShortcuts();
}
+// QTBUG-38986, do not generate duplicated QEvent::ShortcutOverride in event processing.
+class OverrideCountingWidget : public QWidget
+{
+public:
+ OverrideCountingWidget(QWidget *parent = 0) : QWidget(parent), overrideCount(0) {}
+
+ int overrideCount;
+
+ bool event(QEvent *e) Q_DECL_OVERRIDE
+ {
+ if (e->type() == QEvent::ShortcutOverride)
+ overrideCount++;
+ return QWidget::event(e);
+ }
+};
+
+void tst_QShortcut::duplicatedShortcutOverride()
+{
+ OverrideCountingWidget w;
+ w.setWindowTitle(Q_FUNC_INFO);
+ w.resize(200, 200);
+ w.move(QGuiApplication::primaryScreen()->availableGeometry().center() - QPoint(100, 100));
+ w.show();
+ QApplication::setActiveWindow(&w);
+ QVERIFY(QTest::qWaitForWindowActive(&w));
+ QTest::keyPress(w.windowHandle(), Qt::Key_A);
+ QCoreApplication::processEvents();
+ QCOMPARE(w.overrideCount, 1);
+}
+
// ------------------------------------------------------------------
// Element Testing helper functions ---------------------------------
// ------------------------------------------------------------------
@@ -1226,7 +1258,7 @@ void tst_QShortcut::testElement()
setupShortcut(testWidget, txt, k1, k2, k3, k4);
} else {
sendKeyEvents(k1, c1, k2, c2, k3, c3, k4, c4);
- QCOMPARE(currentResult, result);
+ QCOMPARE((int)currentResult, (int)result);
}
}
diff --git a/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp b/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp
index 1facf99afa..e0533d129a 100644
--- a/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp
+++ b/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp
@@ -31,39 +31,83 @@
**
****************************************************************************/
-
#include <QtTest/QtTest>
#include <qsizepolicy.h>
+Q_DECLARE_METATYPE(Qt::Orientations)
+Q_DECLARE_METATYPE(QSizePolicy)
+Q_DECLARE_METATYPE(QSizePolicy::Policy)
+Q_DECLARE_METATYPE(QSizePolicy::ControlType)
+
class tst_QSizePolicy : public QObject
{
-Q_OBJECT
+ Q_OBJECT
-public:
- tst_QSizePolicy();
- virtual ~tst_QSizePolicy();
-
-private slots:
+private Q_SLOTS:
+ void qtest();
+ void defaultValues();
+ void getSetCheck_data() { data(); }
void getSetCheck();
void dataStream();
void horizontalStretch();
void verticalStretch();
+private:
+ void data() const;
};
-tst_QSizePolicy::tst_QSizePolicy()
-{
-}
-tst_QSizePolicy::~tst_QSizePolicy()
+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
}
-
-// Testing get/set functions
-void tst_QSizePolicy::getSetCheck()
+void tst_QSizePolicy::defaultValues()
{
{
- // check values of a default constructed QSizePolicy
+ // check values of a default-constructed QSizePolicy
QSizePolicy sp;
QCOMPARE(sp.horizontalPolicy(), QSizePolicy::Fixed);
QCOMPARE(sp.verticalPolicy(), QSizePolicy::Fixed);
@@ -74,6 +118,61 @@ void tst_QSizePolicy::getSetCheck()
QCOMPARE(sp.hasHeightForWidth(), false);
QCOMPARE(sp.hasWidthForHeight(), false);
}
+}
+
+#define FETCH_TEST_DATA \
+ QFETCH(QSizePolicy, sp); \
+ QFETCH(QSizePolicy::Policy, hp); \
+ QFETCH(QSizePolicy::Policy, vp); \
+ QFETCH(int, hst); \
+ QFETCH(int, vst); \
+ QFETCH(QSizePolicy::ControlType, ct); \
+ QFETCH(bool, hfw); \
+ QFETCH(bool, wfh); \
+ QFETCH(Qt::Orientations, ed)
+
+
+// Testing get/set functions
+void tst_QSizePolicy::getSetCheck()
+{
+ FETCH_TEST_DATA;
+
+ QCOMPARE(QPixmap(), QPixmap());
+
+ QCOMPARE(sp.horizontalPolicy(), hp);
+ QCOMPARE(sp.verticalPolicy(), vp);
+ QCOMPARE(sp.horizontalStretch(), hst);
+ QCOMPARE(sp.verticalStretch(), vst);
+ QCOMPARE(sp.controlType(), ct);
+ QCOMPARE(sp.hasHeightForWidth(), hfw);
+ QCOMPARE(sp.hasWidthForHeight(), wfh);
+ QCOMPARE(sp.expandingDirections(), ed);
+}
+
+#undef FETCH_TEST_DATA
+
+static void makeRow(QSizePolicy sp, QSizePolicy::Policy hp, QSizePolicy::Policy vp,
+ int hst, int vst, QSizePolicy::ControlType ct, bool hfw, bool wfh,
+ Qt::Orientations orients)
+{
+ QTest::newRow(qPrintable(QString().sprintf("%s-%s-%d-%d-%s-%s-%s",
+ PrettyPrint(hp).s(), PrettyPrint(vp).s(), hst, vst,
+ PrettyPrint(ct).s(),
+ hfw ? "true" : "false", wfh ? "true" : "false")))
+ << sp << hp << vp << hst << vst << ct << hfw << wfh << orients;
+}
+
+void tst_QSizePolicy::data() const
+{
+ QTest::addColumn<QSizePolicy>("sp");
+ QTest::addColumn<QSizePolicy::Policy>("hp");
+ QTest::addColumn<QSizePolicy::Policy>("vp");
+ QTest::addColumn<int>("hst");
+ QTest::addColumn<int>("vst");
+ QTest::addColumn<QSizePolicy::ControlType>("ct");
+ QTest::addColumn<bool>("hfw");
+ QTest::addColumn<bool>("wfh");
+ QTest::addColumn<Qt::Orientations>("ed");
{
static const QSizePolicy::Policy policies[3] = {
@@ -118,18 +217,11 @@ void tst_QSizePolicy::getSetCheck()
case 0: sp.setHorizontalPolicy(hp); break;
case 1: sp.setVerticalPolicy(vp); break;
case 2: sp.setHorizontalStretch(hst); break;
- case 3: sp.setVerticalStretch(vst); break;
+ case 3: sp.setVerticalStretch(vst); break;
case 4: sp.setControlType(ct); break;
case 5: sp.setHeightForWidth(hfw); sp.setWidthForHeight(wfh); break;
default: break;
}
- QCOMPARE(sp.horizontalPolicy(), (i >= 0 ? hp : oldsp.horizontalPolicy()));
- QCOMPARE(sp.verticalPolicy(), (i >= 1 ? vp : oldsp.verticalPolicy()));
- QCOMPARE(sp.horizontalStretch(), (i >= 2 ? hst : oldsp.horizontalStretch()));
- QCOMPARE(sp.verticalStretch(), (i >= 3 ? vst : oldsp.verticalStretch()));
- QCOMPARE(sp.controlType(), (i >= 4 ? ct : oldsp.controlType()));
- QCOMPARE(sp.hasHeightForWidth(), (i >= 5 ? hfw : oldsp.hasHeightForWidth()));
- QCOMPARE(sp.hasWidthForHeight(), (i >= 5 ? wfh : oldsp.hasWidthForHeight()));
Qt::Orientations orients;
if (sp.horizontalPolicy() & QSizePolicy::ExpandFlag)
@@ -137,7 +229,15 @@ void tst_QSizePolicy::getSetCheck()
if (sp.verticalPolicy() & QSizePolicy::ExpandFlag)
orients |= Qt::Vertical;
- QCOMPARE(sp.expandingDirections(), orients);
+ makeRow(sp,
+ i >= 0 ? hp : oldsp.horizontalPolicy(),
+ i >= 1 ? vp : oldsp.verticalPolicy(),
+ i >= 2 ? hst : oldsp.horizontalStretch(),
+ i >= 3 ? vst : oldsp.verticalStretch(),
+ i >= 4 ? ct : oldsp.controlType(),
+ i >= 5 ? hfw : oldsp.hasHeightForWidth(),
+ i >= 5 ? wfh : oldsp.hasWidthForHeight(),
+ orients);
#ifdef GENERATE_BASELINE
stream << sp;
#endif
@@ -152,6 +252,7 @@ void tst_QSizePolicy::getSetCheck()
out.close();
}
#endif
+#undef ITEMCOUNT
}
}
@@ -212,5 +313,6 @@ void tst_QSizePolicy::verticalStretch()
sp.setVerticalStretch(257);
QCOMPARE(sp.verticalStretch(), 255);
}
+
QTEST_MAIN(tst_QSizePolicy)
#include "tst_qsizepolicy.moc"
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index d977f78b23..8dacab7c3b 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -69,6 +69,7 @@
#include <QtWidgets/QGraphicsView>
#include <QtWidgets/QGraphicsProxyWidget>
#include <QtGui/qwindow.h>
+#include <qtimer.h>
#include "../../../qtest-config.h"
@@ -76,7 +77,7 @@
#include "tst_qwidget_mac_helpers.h" // Abstract the ObjC stuff out so not everyone must run an ObjC++ compile.
#endif
-#include <QtTest/QtTest>
+#include <QtTest/QTest>
#ifdef Q_OS_WIN
# include <QtCore/qt_windows.h>
@@ -446,6 +447,8 @@ private slots:
void resizeStaticContentsChildWidget_QTBUG35282();
+ void qmlSetParentHelper();
+
private:
bool ensureScreenSize(int width, int height);
QWidget *testWidget;
@@ -10418,5 +10421,20 @@ void tst_QWidget::resizeStaticContentsChildWidget_QTBUG35282()
msgComparisonFailed(childWidget.numPaintEvents, ">=", 1));
}
+void tst_QWidget::qmlSetParentHelper()
+{
+#ifdef QT_BUILD_INTERNAL
+ QWidget parent;
+ QWidget child;
+ QVERIFY(QAbstractDeclarativeData::setWidgetParent);
+ QAbstractDeclarativeData::setWidgetParent(&child, &parent);
+ QVERIFY(child.parentWidget() == &parent);
+ QAbstractDeclarativeData::setWidgetParent(&child, 0);
+ QVERIFY(!child.parentWidget());
+#else
+ QSKIP("Needs QT_BUILD_INTERNAL");
+#endif
+}
+
QTEST_MAIN(tst_QWidget)
#include "tst_qwidget.moc"
diff --git a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp
index 36791293ab..6a06884989 100644
--- a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp
+++ b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp
@@ -336,7 +336,7 @@ void tst_QWidget_window::tst_windowFilePath()
void tst_QWidget_window::tst_showWithoutActivating()
{
-#ifndef Q_WS_X11
+#ifndef Q_DEAD_CODE_FROM_QT4_X11
QSKIP("This test is X11-only.");
#else
QWidget w;
@@ -359,7 +359,7 @@ void tst_QWidget_window::tst_showWithoutActivating()
// Note the use of the , before window because we want the XGetInputFocus to be re-executed
// in each iteration of the inside loop of the QTRY_COMPARE macro
-#endif // Q_WS_X11
+#endif // Q_DEAD_CODE_FROM_QT4_X11
}
void tst_QWidget_window::tst_paintEventOnSecondShow()
diff --git a/tests/auto/widgets/kernel/qwidgetmetatype/tst_qwidgetmetatype.cpp b/tests/auto/widgets/kernel/qwidgetmetatype/tst_qwidgetmetatype.cpp
index 917a00e6db..30b0b2b896 100644
--- a/tests/auto/widgets/kernel/qwidgetmetatype/tst_qwidgetmetatype.cpp
+++ b/tests/auto/widgets/kernel/qwidgetmetatype/tst_qwidgetmetatype.cpp
@@ -70,6 +70,7 @@ void tst_QWidgetMetaType::metaObject()
QCOMPARE(QMetaType::metaObjectForType(qMetaTypeId<QWidget*>()), &QWidget::staticMetaObject);
QCOMPARE(QMetaType::metaObjectForType(qMetaTypeId<QLabel*>()), &QLabel::staticMetaObject);
QCOMPARE(QMetaType::metaObjectForType(qMetaTypeId<CustomWidget*>()), &CustomWidget::staticMetaObject);
+ QCOMPARE(QMetaType::metaObjectForType(qMetaTypeId<QSizePolicy>()), &QSizePolicy::staticMetaObject);
}
QTEST_MAIN(tst_QWidgetMetaType)