diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2019-04-16 16:32:08 +0200 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2019-04-16 16:32:08 +0200 |
commit | 6630937e63ae5797487b86743a7733c8ae5cc42c (patch) | |
tree | 3d53dacf6430f9099e1fb20835881205de674961 /tests/auto/widgets/widgets | |
parent | 37ed6dae00640f9cc980ffda05347c12a7eb5d7e (diff) | |
parent | c7af193d2e49e9f10b86262e63d8d13abf72b5cf (diff) |
Merge commit 'dev' into 'wip/cmake-merge'
Change-Id: I176c40d031be26a1dd1cf08843e448a660598783
Diffstat (limited to 'tests/auto/widgets/widgets')
17 files changed, 1288 insertions, 249 deletions
diff --git a/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp b/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp index 70ae453896..1a0d7a9289 100644 --- a/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp +++ b/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp @@ -467,160 +467,1001 @@ void tst_QAbstractSlider::keyPressed_data() QTest::addColumn<int>("maximum"); QTest::addColumn<int>("stepSize"); QTest::addColumn<int>("pageSize"); + QTest::addColumn<bool>("invertedAppearance"); + QTest::addColumn<bool>("invertedControls"); QTest::addColumn<QList<Qt::Key> >("keySequence"); - QTest::addColumn<int>("expectedSliderPositionHorizontal"); - QTest::addColumn<int>("expectedSliderPositionVertical"); - QTest::addColumn<int>("expectedSliderPositionHorizontalInverted"); // :) - QTest::addColumn<int>("expectedSliderPositionVerticalInverted"); - + QTest::addColumn<int>("expectedSliderPosition"); QList<Qt::Key> list; - list << Qt::Key_Down; - QTest::newRow("Step down once 1") << 10 // initial position - << 0 // minimum - << 100 // maximum - << 3 // single step size - << 0 // page step size - << list // key sequence - << 7 // result in case of horizontal slider - << 7 // result in case of vertical slider - << 13 // result in case of inverted horiz. slider - << 13; // result in case of inverted vertical slider + QTest::newRow("Step down once 1, horizontal") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step down once 1, horizontal, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step down once 1, horizontal, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step down once 1, horizontal, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step down once 1, vertical") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step down once 1, vertical, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step down once 1, vertical, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step down once 1, vertical, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position list = QList<Qt::Key>(); list << Qt::Key_Up; - QTest::newRow("Step down once 2") << 10 // initial position - << 0 // minimum - << 100 // maximum - << 3 // single step size - << 0 // page step size - << list // key sequence - << 13 // result in case of horizontal slider - << 13 // result in case of vertical slider - << 7 // result in case of inverted horiz. slider - << 7; // result in case of inverted vertical slider - + QTest::newRow("Step up once 2, horizontal") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step up once 2, horizontal, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step up once 2, horizontal, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step up once 2, horizontal, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step up once 2, vertical") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step up once 2, vertical, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step up once 2, vertical, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step up once 2, vertical, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position list = QList<Qt::Key>(); list << Qt::Key_Left; - QTest::newRow("Step left once") << 10 // initial position - << 0 // minimum - << 100 // maximum - << 3 // single step size - << 0 // page step size - << list // key sequence - << 7 // result in case of horizontal slider - << 7 // result in case of vertical slider - << 13 // result in case of inverted horiz. slider - << 13; // result in case of inverted vertical slider + QTest::newRow("Step left once 2, horizontal") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step left once 2, horizontal, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step left once 2, horizontal, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step left once 2, horizontal, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step left once 2, vertical") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step left once 2, vertical, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step left once 2, vertical, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step left once 2, vertical, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position list = QList<Qt::Key>(); list << Qt::Key_Right; - QTest::newRow("Step right once") << 10 // initial position - << 0 // minimum - << 100 // maximum - << 3 // single step size - << 0 // page step size - << list // key sequence - << 13 // result in case of horizontal slider - << 13 // result in case of vertical slider - << 7 // result in case of inverted horiz. slider - << 7; // result in case of inverted vertical slider + QTest::newRow("Step right once 2, horizontal") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step right once 2, horizontal, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step right once 2, horizontal, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step right once 2, horizontal, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step right once 2, vertical") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step right once 2, vertical, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step right once 2, vertical, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step right once 2, vertical, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position list = QList<Qt::Key>(); list << Qt::Key_PageDown; - QTest::newRow("Page down once") << 10 // initial position - << 0 // minimum - << 100 // maximum - << 0 // single step size - << 3 // page step size - << list // key sequence - << 7 // result in case of horizontal slider - << 7 // result in case of vertical slider - << 13 // result in case of inverted horiz. slider - << 13; // result in case of inverted vertical slider + QTest::newRow("Page down once, horizontal") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Page down once, horizontal, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Page down once, horizontal, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Page down once, horizontal, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Page down once, vertical") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Page down once, vertical, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Page down once, vertical, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Page down once, vertical, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position list = QList<Qt::Key>(); list << Qt::Key_PageUp; - QTest::newRow("Page up once") << 10 // initial position - << 0 // minimum - << 100 // maximum - << 0 // single step size - << 3 // page step size - << list // key sequence - << 13 // result in case of horizontal slider - << 13 // result in case of vertical slider - << 7 // result in case of inverted horiz. slider - << 7; // result in case of inverted vertical slider + QTest::newRow("Page up once, horizontal") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Page up once, horizontal, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Page up once, horizontal, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Page up once, horizontal, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Page up once, vertical") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Page up once, vertical, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Page up once, vertical, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Page up once, vertical, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position list = QList<Qt::Key>(); list << Qt::Key_Up << Qt::Key_Up << Qt::Key_PageDown << Qt::Key_PageDown << Qt::Key_Left << Qt::Key_Left << Qt::Key_Right << Qt::Key_Down << Qt::Key_PageUp << Qt::Key_PageUp << Qt::Key_Down << Qt::Key_Right; - QTest::newRow("Symmetric seq") << 50 // initial position - << 0 // minimum - << 100 // maximum - << 3 // single step size - << 3 // page step size - << list // key sequence - << 50 // result in case of horizontal slider - << 50 // result in case of vertical slider - << 50 // result in case of inverted horiz. slider - << 50; // result in case of inverted vertical slider - + QTest::newRow("Symmetric seq, horizontal") + << 50 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 50; // expected position + + QTest::newRow("Symmetric seq, horizontal, appearance inverted") + << 50 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 50; // expected position + + QTest::newRow("Symmetric seq, horizontal, controls inverted") + << 50 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 50; // expected position + + QTest::newRow("Symmetric seq, horizontal, both inverted") + << 50 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 50; // expected position + + QTest::newRow("Symmetric seq, vertical") + << 50 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 50; // expected position + + QTest::newRow("Symmetric seq, vertical, appearance inverted") + << 50 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 50; // expected position + + QTest::newRow("Symmetric seq, vertical, controls inverted") + << 50 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 50; // expected position + + QTest::newRow("Symmetric seq, vertical, both inverted") + << 50 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 50; // expected position list = QList<Qt::Key>(); list << Qt::Key_Home; - QTest::newRow("Home") << 10 // initial position - << 0 // minimum - << 100 // maximum - << 0 // single step size - << 3 // page step size - << list // key sequence - << 0 // result in case of horizontal slider - << 0 // result in case of vertical slider - << 0 // result in case of inverted horiz. slider - << 0; // result in case of inverted vertical slider + QTest::newRow("Home, horizontal") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 0; // expected position + + QTest::newRow("Home, horizontal, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 0; // expected position + + QTest::newRow("Home, horizontal, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 0; // expected position + + QTest::newRow("Home, horizontal, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 0; // expected position + + QTest::newRow("Home, vertical") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 0; // expected position + + QTest::newRow("Home, vertical, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 0; // expected position + + QTest::newRow("Home, vertical, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 0; // expected position + + QTest::newRow("Home, vertical, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 0; // expected position list = QList<Qt::Key>(); list << Qt::Key_End; - QTest::newRow("End") << 10 // initial position - << 0 // minimum - << 100 // maximum - << 0 // single step size - << 3 // page step size - << list // key sequence - << 100 // result in case of horizontal slider - << 100 // result in case of vertical slider - << 100 // result in case of inverted horiz. slider - << 100; // result in case of inverted vertical slider + QTest::newRow("End, horizontal") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 100; // expected position + + QTest::newRow("End, horizontal, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 100; // expected position + + QTest::newRow("End, horizontal, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 100; // expected position + + QTest::newRow("End, horizontal, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 100; // expected position + + QTest::newRow("End, vertical") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 100; // expected position + + QTest::newRow("End, vertical, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 100; // expected position + + QTest::newRow("End, vertical, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 100; // expected position + + QTest::newRow("End, vertical, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 100; // expected position list = QList<Qt::Key>(); list << Qt::Key_End << Qt::Key_Up; - QTest::newRow("Past end")<< 10 // initial position - << 0 // minimum - << 100 // maximum - << 3 // single step size - << 3 // page step size - << list // key sequence - << 100 // result in case of horizontal slider - << 100 // result in case of vertical slider - << 97 // result in case of inverted horiz. slider - << 97; // result in case of inverted vertical slider + QTest::newRow("Past end, horizontal") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 100; // expected position + + QTest::newRow("Past end, horizontal, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 100; // expected position + + QTest::newRow("Past end, horizontal, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 97; // expected position + + QTest::newRow("Past end, horizontal, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 97; // expected position + + QTest::newRow("Past end, vertical") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 100; // expected position + + QTest::newRow("Past end, vertical, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 100; // expected position + + QTest::newRow("Past end, vertical, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 97; // expected position + + QTest::newRow("Past end, vertical, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 97; // expected position list = QList<Qt::Key>(); list << Qt::Key_Home << Qt::Key_Down; - QTest::newRow("Past home")<< 10 // initial position - << 0 // minimum - << 100 // maximum - << 3 // single step size - << 3 // page step size - << list // key sequence - << 0 // result in case of horizontal slider - << 0 // result in case of vertical slider - << 3 // result in case of inverted horiz. slider - << 3; // result in case of inverted vertical slider - + QTest::newRow("Past home, horizontal") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 0; // expected position + + QTest::newRow("Past home, horizontal, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 0; // expected position + + QTest::newRow("Past home, horizontal, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 3; // expected position + + QTest::newRow("Past home, horizontal, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 3; // expected position + + QTest::newRow("Past home, vertical") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 0; // expected position + + QTest::newRow("Past home, vertical, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 0; // expected position + + QTest::newRow("Past home, vertical, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 3; // expected position + + QTest::newRow("Past home, vertical, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 3; // expected position } void tst_QAbstractSlider::keyPressed() @@ -630,60 +1471,22 @@ void tst_QAbstractSlider::keyPressed() QFETCH(int, maximum); QFETCH(int, stepSize); QFETCH(int, pageSize); + QFETCH(bool, invertedAppearance); + QFETCH(bool, invertedControls); QFETCH(QList<Qt::Key>, keySequence); - QFETCH(int, expectedSliderPositionHorizontal); - QFETCH(int, expectedSliderPositionVertical); - QFETCH(int, expectedSliderPositionHorizontalInverted); - QFETCH(int, expectedSliderPositionVerticalInverted); + QFETCH(int, expectedSliderPosition); - // Horizontal non-inverted slider->setRange(minimum,maximum); slider->setSliderPosition(initialSliderPosition); slider->setSingleStep(stepSize); slider->setPageStep(pageSize); slider->setOrientation(Qt::Horizontal); - slider->setInvertedAppearance(false); - slider->setInvertedControls(false); + slider->setInvertedAppearance(invertedAppearance); + slider->setInvertedControls(invertedControls); for (int i=0;i<keySequence.count();i++) { QTest::keyClick(slider, keySequence.at(i)); } - QCOMPARE(slider->sliderPosition(), expectedSliderPositionHorizontal); - - // Horizontal inverted - slider->setRange(minimum,maximum); - slider->setSliderPosition(initialSliderPosition); - slider->setSingleStep(stepSize); - slider->setPageStep(pageSize); - slider->setOrientation(Qt::Horizontal); - slider->setInvertedAppearance(true); - slider->setInvertedControls(true); - for (int i=0;i<keySequence.count();i++) - QTest::keyPress(slider, keySequence.at(i)); - QCOMPARE(slider->sliderPosition(), expectedSliderPositionHorizontalInverted); - - // Vertical non-inverted - slider->setRange(minimum,maximum); - slider->setSliderPosition(initialSliderPosition); - slider->setSingleStep(stepSize); - slider->setPageStep(pageSize); - slider->setOrientation(Qt::Vertical); - slider->setInvertedAppearance(false); - slider->setInvertedControls(false); - for (int i=0;i<keySequence.count();i++) - QTest::keyPress(slider, keySequence.at(i)); - QCOMPARE(slider->sliderPosition(), expectedSliderPositionVertical); - - // Vertical inverted - slider->setRange(minimum,maximum); - slider->setSliderPosition(initialSliderPosition); - slider->setSingleStep(stepSize); - slider->setPageStep(pageSize); - slider->setOrientation(Qt::Vertical); - slider->setInvertedAppearance(true); - slider->setInvertedControls(true); - for (int i=0;i<keySequence.count();i++) - QTest::keyPress(slider, keySequence.at(i)); - QCOMPARE(slider->sliderPosition(), expectedSliderPositionVerticalInverted); + QCOMPARE(slider->sliderPosition(), expectedSliderPosition); } #if QT_CONFIG(wheelevent) diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index 943fb997cd..5b4761ba87 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -1671,6 +1671,13 @@ void tst_QComboBox::setCustomModelAndView() QTRY_VERIFY(combo.view()->isVisible()); const QRect subItemRect = view->visualRect(model->indexFromItem(subItem)); QWidget *window = view->window(); + + // QComboBox sometimes ignores the mouse click event for doubleClickInterval + // depending on which tests have been run previously. On arm this happens + // more often than on x86. Search for maybeIgnoreMouseButtonRelease to see + // why this happens. + QTest::qWait(QApplication::doubleClickInterval()); + QTest::mouseClick(window->windowHandle(), Qt::LeftButton, 0, view->mapTo(window, subItemRect.center())); #ifdef Q_OS_WINRT QEXPECT_FAIL("", "Fails on WinRT - QTBUG-68297", Abort); @@ -3421,6 +3428,11 @@ void tst_QComboBox::task_QTBUG_52027_mapCompleterIndex() model->setFilterFixedString("foobar1"); completer->setModel(model); + if (QGuiApplication::platformName() == "offscreen") { + QWARN("Offscreen platform requires explicit activateWindow()"); + cbox.activateWindow(); + } + QApplication::setActiveWindow(&cbox); QVERIFY(QTest::qWaitForWindowActive(&cbox)); diff --git a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp index e2f1307eb1..b5ef454b14 100644 --- a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp +++ b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp @@ -823,7 +823,7 @@ void tst_QDateTimeEdit::displayFormat_data() << QString("31 12 2999::59:59:03") << dt; QTest::newRow("valid-2") << QString("hh-dd-mm-MM-yy") << true << QString("03-31-59-12-99") << dt; QTest::newRow("valid-3") << QString("ddd MM d yyyy::ss:mm:hh") << true - << QDate::shortDayName(2) + " 12 31 2999::59:59:03" << dt; + << QLocale::system().dayName(2, QLocale::ShortFormat) + " 12 31 2999::59:59:03" << dt; QTest::newRow("valid-4") << QString("hh-dd-mm-MM-yyyy") << true << QString("03-31-59-12-2999") << dt; QTest::newRow("invalid-0") << QString("yyyy.MM.yy") << true << QString("2999.12.99") << dt; QTest::newRow("invalid-1") << QString("y") << false << QString() << dt; @@ -2611,9 +2611,13 @@ void tst_QDateTimeEdit::weirdCase() void tst_QDateTimeEdit::newCase() { - if (QDate::shortMonthName(6) != "Jun" || QDate::shortMonthName(7) != "Jul" || - QDate::longMonthName(6) != "June" || QDate::longMonthName(7) != "July") + const auto locale = QLocale::system(); + if (locale.monthName(6, QLocale::ShortFormat) != "Jun" || + locale.monthName(7, QLocale::ShortFormat) != "Jul" || + locale.monthName(6, QLocale::LongFormat) != "June" || + locale.monthName(7, QLocale::LongFormat) != "July") { QSKIP("This test only works in English"); + } testWidget->setDisplayFormat("MMMM'a'MbMMMcMM"); testWidget->setDate(QDate(2005, 6, 1)); @@ -2656,12 +2660,12 @@ void tst_QDateTimeEdit::newCase2() testWidget->setDate(QDate(2005, 8, 8)); QTest::keyClick(testWidget, Qt::Key_Return); QTest::keyClick(testWidget, Qt::Key_Backspace); - QCOMPARE(testWidget->text(), QString(" 2005-08-08 ") + QDate::longMonthName(8)); + QCOMPARE(testWidget->text(), QString(" 2005-08-08 ") + QLocale::system().monthName(8, QLocale::LongFormat)); } void tst_QDateTimeEdit::newCase3() { - if (!QDate::longMonthName(1).startsWith("Januar")) + if (!QLocale::system().monthName(1, QLocale::LongFormat).startsWith("Januar")) QSKIP("This test does not work in this locale"); testWidget->setDisplayFormat("dd MMMM yyyy"); @@ -2681,7 +2685,7 @@ void tst_QDateTimeEdit::newCase3() void tst_QDateTimeEdit::cursorPos() { - if (QDate::longMonthName(1) != "January") + if (QLocale::system().monthName(1, QLocale::LongFormat) != "January") QSKIP("This test only works in English"); testWidget->setDisplayFormat("dd MMMM yyyy"); @@ -3017,7 +3021,7 @@ void tst_QDateTimeEdit::yyTest() testWidget->setDate(testWidget->minimumDate()); testWidget->setCurrentSection(QDateTimeEdit::YearSection); - QString jan = QDate::shortMonthName(1); + QString jan = QLocale::system().monthName(1, QLocale::ShortFormat); QCOMPARE(testWidget->lineEdit()->displayText(), "01-" + jan + "-05"); QTest::keyClick(testWidget, Qt::Key_Up); QCOMPARE(testWidget->lineEdit()->displayText(), "01-" + jan + "-06"); @@ -3130,7 +3134,7 @@ void tst_QDateTimeEdit::ddMMMMyyyy() #ifdef Q_OS_MAC QEXPECT_FAIL("", "QTBUG-23674", Abort); #endif - QCOMPARE(testWidget->lineEdit()->text(), "01." + QDate::longMonthName(1) + ".200"); + QCOMPARE(testWidget->lineEdit()->text(), "01." + QLocale::system().monthName(1, QLocale::LongFormat) + ".200"); } void tst_QDateTimeEdit::wheelEvent_data() @@ -3848,7 +3852,7 @@ void tst_QDateTimeEdit::dateEditCorrectSectionSize_data() << threeDigitDayIssueKeypresses_DayName << QString::fromLatin1("00/2/Tuesday"); QTest::newRow("no fixday, leap, yy/M/ddd") << defaultLocale << defaultDate << QString::fromLatin1("yy/M/ddd") - << threeDigitDayIssueKeypresses_DayName << QString::fromLatin1("00/2/Tue."); + << threeDigitDayIssueKeypresses_DayName << QString::fromLatin1("00/2/Tue"); QTest::newRow("no fixday, leap, yy/MM/dddd") << defaultLocale << defaultDate << QString::fromLatin1("yy/MM/dddd") << threeDigitDayIssueKeypresses_DayName << QString::fromLatin1("00/02/Tuesday"); @@ -3896,13 +3900,13 @@ void tst_QDateTimeEdit::dateEditCorrectSectionSize_data() << threeDigitDayIssueKeypresses_YearDayMonth << QString::fromLatin1("2000/29/2"); QTest::newRow("fixday, leap, yyyy/MMM/dd") << defaultLocale << defaultDate << QString::fromLatin1("yyyy/MMM/dd") - << threeDigitDayIssueKeypresses_ShortMonthName << QString::fromLatin1("2000/Feb./29"); + << threeDigitDayIssueKeypresses_ShortMonthName << QString::fromLatin1("2000/Feb/29"); QTest::newRow("fixday, leap, yyyy/MMM/d") << defaultLocale << defaultDate << QString::fromLatin1("yyyy/MMM/d") - << threeDigitDayIssueKeypresses_ShortMonthName << QString::fromLatin1("2000/Feb./29"); + << threeDigitDayIssueKeypresses_ShortMonthName << QString::fromLatin1("2000/Feb/29"); QTest::newRow("fixday, leap, yy/MMM/dd") << defaultLocale << defaultDate << QString::fromLatin1("yy/MMM/dd") - << threeDigitDayIssueKeypresses_ShortMonthName << QString::fromLatin1("00/Feb./29"); + << threeDigitDayIssueKeypresses_ShortMonthName << QString::fromLatin1("00/Feb/29"); QTest::newRow("fixday, leap, yyyy/dddd/M") << defaultLocale << defaultDate << QString::fromLatin1("yyyy/dddd/M") << threeDigitDayIssueKeypresses_DayName_YearDayMonth << QString::fromLatin1("2000/Tuesday/2"); @@ -3977,16 +3981,16 @@ void tst_QDateTimeEdit::dateEditCorrectSectionSize_data() << threeDigitDayIssueKeypresses_MonthYearDay << QString::fromLatin1("02/2000/29"); QTest::newRow("fixday, leap, MMM/yy/d") << defaultLocale << defaultDate << QString::fromLatin1("MMM/yy/d") - << threeDigitDayIssueKeypresses_ShortMonthName_MonthYearDay << QString::fromLatin1("Feb./00/29"); + << threeDigitDayIssueKeypresses_ShortMonthName_MonthYearDay << QString::fromLatin1("Feb/00/29"); QTest::newRow("fixday, leap, MMM/yyyy/d") << defaultLocale << defaultDate << QString::fromLatin1("MMM/yyyy/d") - << threeDigitDayIssueKeypresses_ShortMonthName_MonthYearDay << QString::fromLatin1("Feb./2000/29"); + << threeDigitDayIssueKeypresses_ShortMonthName_MonthYearDay << QString::fromLatin1("Feb/2000/29"); QTest::newRow("fixday, MMM/yyyy/d") << defaultLocale << defaultDate.addYears(1) << QString::fromLatin1("MMM/yyyy/d") - << threeDigitDayIssueKeypresses_ShortMonthName_MonthYearDay << QString::fromLatin1("Feb./2001/28"); + << threeDigitDayIssueKeypresses_ShortMonthName_MonthYearDay << QString::fromLatin1("Feb/2001/28"); QTest::newRow("fixday, leap, MMM/yyyy/dd") << defaultLocale << defaultDate << QString::fromLatin1("MMM/yyyy/dd") - << threeDigitDayIssueKeypresses_ShortMonthName_MonthYearDay << QString::fromLatin1("Feb./2000/29"); + << threeDigitDayIssueKeypresses_ShortMonthName_MonthYearDay << QString::fromLatin1("Feb/2000/29"); QTest::newRow("fixday, leap, dddd, dd. MMMM yyyy") << defaultLocale << defaultDate << QString::fromLatin1("dddd, dd. MMMM yyyy") diff --git a/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp b/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp index 078a3215fd..f8ce6a2c0a 100644 --- a/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp +++ b/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp @@ -71,6 +71,7 @@ private slots: void restoreStateOfFloating(); void restoreDockWidget(); void restoreStateWhileStillFloating(); + void setWindowTitle(); // task specific tests: void task165177_deleteFocusWidget(); void task169808_setFloating(); @@ -993,7 +994,54 @@ void tst_QDockWidget::taskQTBUG_9758_undockedGeometry() QVERIFY(dock1.y() >= 0); } +void tst_QDockWidget::setWindowTitle() +{ + QMainWindow window; + QDockWidget dock1(&window); + QDockWidget dock2(&window); + const QString dock1Title = QStringLiteral("&Window"); + const QString dock2Title = QStringLiteral("&Modifiable Window [*]"); + + dock1.setWindowTitle(dock1Title); + dock2.setWindowTitle(dock2Title); + window.addDockWidget(Qt::RightDockWidgetArea, &dock1); + window.addDockWidget(Qt::RightDockWidgetArea, &dock2); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QCOMPARE(dock1.windowTitle(), dock1Title); + QCOMPARE(dock2.windowTitle(), dock2Title); + + dock1.setFloating(true); + dock1.show(); + QVERIFY(QTest::qWaitForWindowExposed(&dock1)); + QCOMPARE(dock1.windowTitle(), dock1Title); + dock1.setFloating(false); + QCOMPARE(dock1.windowTitle(), dock1Title); + dock1.setFloating(true); + dock1.show(); + QVERIFY(QTest::qWaitForWindowExposed(&dock1)); + const QString changed = QStringLiteral("Changed "); + dock1.setWindowTitle(QString(changed + dock1Title)); + QCOMPARE(dock1.windowTitle(), QString(changed + dock1Title)); + dock1.setFloating(false); + QCOMPARE(dock1.windowTitle(), QString(changed + dock1Title)); + + dock2.setWindowModified(true); + QCOMPARE(dock2.windowTitle(), dock2Title); + dock2.setFloating(true); + dock2.show(); + QVERIFY(QTest::qWaitForWindowExposed(&dock2)); + QCOMPARE(dock2.windowTitle(), dock2Title); + dock2.setWindowModified(false); + QCOMPARE(dock2.windowTitle(), dock2Title); + dock2.setFloating(false); + QCOMPARE(dock2.windowTitle(), dock2Title); + dock2.setFloating(true); + dock2.show(); + QVERIFY(QTest::qWaitForWindowExposed(&dock2)); + QCOMPARE(dock2.windowTitle(), dock2Title); +} QTEST_MAIN(tst_QDockWidget) #include "tst_qdockwidget.moc" diff --git a/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp b/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp index b1610c297d..b101f47bcd 100644 --- a/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp +++ b/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp @@ -326,14 +326,26 @@ void tst_QDoubleSpinBox::setPrefixSuffix() QDoubleSpinBox spin(0); spin.setDecimals(decimals); + const QSize size1 = spin.sizeHint(); spin.setPrefix(prefix); + const QSize size2 = spin.sizeHint(); spin.setSuffix(suffix); + const QSize size3 = spin.sizeHint(); spin.setValue(value); if (show) spin.show(); QCOMPARE(spin.text(), expectedText); QCOMPARE(spin.cleanText(), expectedCleanText); + + if (!prefix.isEmpty() && !suffix.isEmpty()) { + QVERIFY(size1.width() < size2.width()); + QVERIFY(size2.width() < size3.width()); + spin.setSuffix(QString()); + QCOMPARE(spin.sizeHint(), size2); + spin.setPrefix(QString()); + QCOMPARE(spin.sizeHint(), size1); + } } void tst_QDoubleSpinBox::valueChangedHelper(const QString &text) diff --git a/tests/auto/widgets/widgets/qfocusframe/tst_qfocusframe.cpp b/tests/auto/widgets/widgets/qfocusframe/tst_qfocusframe.cpp index e6e689336a..657a1ea55c 100644 --- a/tests/auto/widgets/widgets/qfocusframe/tst_qfocusframe.cpp +++ b/tests/auto/widgets/widgets/qfocusframe/tst_qfocusframe.cpp @@ -32,6 +32,8 @@ #include <qcoreapplication.h> #include <qdebug.h> #include <qfocusframe.h> +#include <qtableview.h> +#include <qstandarditemmodel.h> class tst_QFocusFrame : public QObject { @@ -43,6 +45,7 @@ public: private slots: void getSetCheck(); + void focusFrameInsideScrollview(); }; tst_QFocusFrame::tst_QFocusFrame() @@ -68,5 +71,41 @@ void tst_QFocusFrame::getSetCheck() delete obj1; } +void tst_QFocusFrame::focusFrameInsideScrollview() +{ + // Make sure that the focus frame follows the widget, even + // if the widget is inside a QAbstractItemView. A QAbstractItemView will scroll + // all the children, including the focus frame, when it scrolls, which + // is why special considerations are taken inside the focus frame to + // prevent the frame to scroll away from the widget it tracks. + + if (qApp->style()->objectName() != QLatin1String("macintosh")) + QSKIP("This test is only valid when using a style that has a focus frame"); + + QWidget window; + window.setGeometry(100, 100, 500, 500); + + QTableView tableView(&window); + tableView.resize(window.size()); + QStandardItemModel *itemModel = new QStandardItemModel(); + for (int i = 0; i < 50; ++i) + itemModel->appendRow(new QStandardItem("Value")); + tableView.setModel(itemModel); + tableView.edit(itemModel->index(8, 0)); + + window.show(); + QFocusFrame *focusFrame = nullptr; + QTRY_VERIFY(focusFrame = window.findChild<QFocusFrame *>()); + const QPoint initialOffset = focusFrame->widget()->mapToGlobal(QPoint()) - focusFrame->mapToGlobal(QPoint()); + + tableView.scrollTo(itemModel->index(40, 0)); + QPoint offsetAfterScroll = focusFrame->widget()->mapToGlobal(QPoint()) - focusFrame->mapToGlobal(QPoint()); + QCOMPARE(offsetAfterScroll, initialOffset); + + tableView.scrollTo(itemModel->index(0, 0)); + offsetAfterScroll = focusFrame->widget()->mapToGlobal(QPoint()) - focusFrame->mapToGlobal(QPoint()); + QCOMPARE(offsetAfterScroll, initialOffset); +} + QTEST_MAIN(tst_QFocusFrame) #include "tst_qfocusframe.moc" diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index 448e2030bc..7861065de9 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -3615,6 +3615,14 @@ void tst_QLineEdit::task174640_editingFinished() le2->setFocus(); QTRY_VERIFY(le2->hasFocus()); + // editingFinished will not be emitted anew because no editing happened + QCOMPARE(editingFinishedSpy.count(), 0); + + le1->setFocus(); + QTRY_VERIFY(le1->hasFocus()); + QTest::keyPress(le1, Qt::Key_Plus); + le2->setFocus(); + QTRY_VERIFY(le2->hasFocus()); QCOMPARE(editingFinishedSpy.count(), 1); editingFinishedSpy.clear(); @@ -3632,6 +3640,8 @@ void tst_QLineEdit::task174640_editingFinished() delete testMenu1; QCOMPARE(editingFinishedSpy.count(), 0); QTRY_VERIFY(le1->hasFocus()); + // Ensure le1 has been edited + QTest::keyPress(le1, Qt::Key_Plus); QMenu *testMenu2 = new QMenu(le2); testMenu2->addAction("foo2"); @@ -4451,10 +4461,11 @@ void tst_QLineEdit::clearButtonVisibleAfterSettingText_QTBUG_45518() QTRY_VERIFY(clearButton->opacity() > 0); QTRY_COMPARE(clearButton->cursor().shape(), Qt::ArrowCursor); - QTest::mouseClick(clearButton, Qt::LeftButton, 0, clearButton->rect().center()); + QTest::mouseClick(clearButton, Qt::LeftButton, nullptr, clearButton->rect().center()); QTRY_COMPARE(edit.text(), QString()); QTRY_COMPARE(clearButton->opacity(), qreal(0)); + QVERIFY(clearButton->isHidden()); QTRY_COMPARE(clearButton->cursor().shape(), clearButton->parentWidget()->cursor().shape()); edit.setClearButtonEnabled(false); diff --git a/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp b/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp index 1acf07301c..ea96322654 100644 --- a/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp +++ b/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp @@ -1343,8 +1343,10 @@ void tst_QMainWindow::restoreState() { QMainWindow mw; QToolBar tb(&mw); + tb.setObjectName(QLatin1String("toolBar")); mw.addToolBar(Qt::TopToolBarArea, &tb); QDockWidget dw(&mw); + dw.setObjectName(QLatin1String("dock")); mw.addDockWidget(Qt::LeftDockWidgetArea, &dw); QByteArray state; diff --git a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp index 6cc19051d2..046899ce05 100644 --- a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp +++ b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp @@ -333,6 +333,7 @@ void tst_QMdiArea::subWindowActivated() for ( i = 0; i < count; ++i ) { QWidget *widget = new QWidget(workspace, 0); widget->setAttribute(Qt::WA_DeleteOnClose); + widget->setFocus(); workspace->addSubWindow(widget)->show(); widget->show(); qApp->processEvents(); @@ -1689,14 +1690,16 @@ void tst_QMdiArea::tileSubWindows() workspace.setActiveSubWindow(0); QVERIFY(workspace.viewport()->childrenRect() != workspace.viewport()->rect()); - // Make sure the active window is placed in top left corner regardless + // Make sure the active window does not move position after a tile regardless // of whether we have any windows with staysOnTopHint or not. + workspace.tileSubWindows(); windows.at(3)->setWindowFlags(windows.at(3)->windowFlags() | Qt::WindowStaysOnTopHint); QMdiSubWindow *activeSubWindow = windows.at(6); workspace.setActiveSubWindow(activeSubWindow); QCOMPARE(workspace.activeSubWindow(), activeSubWindow); + QPoint pos = activeSubWindow->geometry().topLeft(); workspace.tileSubWindows(); - QCOMPARE(activeSubWindow->geometry().topLeft(), QPoint(0, 0)); + QCOMPARE(activeSubWindow->geometry().topLeft(), pos); // Verify that we try to resize the area such that all sub-windows are visible. // It's important that tiled windows are NOT overlapping. @@ -1713,6 +1716,8 @@ void tst_QMdiArea::tileSubWindows() // Prevent scrollbars from messing up the expected viewport calculation below workspace.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); workspace.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + QCOMPARE(workspace.horizontalScrollBarPolicy(), Qt::ScrollBarAlwaysOff); + QCOMPARE(workspace.verticalScrollBarPolicy(), Qt::ScrollBarAlwaysOff); workspace.tileSubWindows(); // The sub-windows are now tiled like this: @@ -1731,9 +1736,11 @@ void tst_QMdiArea::tileSubWindows() const QSize expectedViewportSize(3 * minSize.width() + spacing, 3 * minSize.height() + spacing); QTRY_COMPARE(workspace.viewport()->rect().size(), expectedViewportSize); - // Restore original scrollbar behavior for test below + // Enable scroll bar for test below (default property for QMdiArea is Qt::ScrollBarAlwaysOff) workspace.setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); workspace.setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + QCOMPARE(workspace.horizontalScrollBarPolicy(), Qt::ScrollBarAsNeeded); + QCOMPARE(workspace.verticalScrollBarPolicy(), Qt::ScrollBarAsNeeded); // Not enough space for all sub-windows to be visible -> provide scroll bars. workspace.resize(160, 150); @@ -1754,13 +1761,16 @@ void tst_QMdiArea::tileSubWindows() QCOMPARE(vBar->value(), 0); QCOMPARE(vBar->minimum(), 0); + // Tile windows with scroll bars enabled. workspace.tileSubWindows(); QVERIFY(QTest::qWaitForWindowExposed(&workspace)); qApp->processEvents(); - QTRY_VERIFY(workspace.size() != QSize(150, 150)); - QTRY_VERIFY(!vBar->isVisible()); - QTRY_VERIFY(!hBar->isVisible()); + // Workspace should not have changed size after tile. + QTRY_VERIFY(workspace.size() == QSize(160, 150)); + // Scroll bars should be visible. + QTRY_VERIFY(vBar->isVisible()); + QTRY_VERIFY(hBar->isVisible()); } void tst_QMdiArea::cascadeAndTileSubWindows() @@ -2180,7 +2190,7 @@ void tst_QMdiArea::setActivationOrder_data() list << 2 << 1 << 0 << 1 << 2 << 3 << 4; list2 << 0 << 1 << 2 << 3 << 4; - list3 << 1 << 4 << 3 << 1 << 2 << 0; + list3 << 4 << 3 << 2 << 4 << 1 << 0; // Most recently created window is in top-left position QTest::newRow("CreationOrder") << QMdiArea::CreationOrder << 5 << 3 << 1 << list << list2 << list3; list = QList<int>(); @@ -2188,7 +2198,7 @@ void tst_QMdiArea::setActivationOrder_data() list2 = QList<int>(); list2 << 0 << 2 << 4 << 1 << 3; list3 = QList<int>(); - list3 << 1 << 3 << 4 << 1 << 2 << 0; + list3 << 3 << 1 << 4 << 3 << 2 << 0; // Window with "stays-on-top" flag set will be in the top-left position QTest::newRow("StackingOrder") << QMdiArea::StackingOrder << 5 << 3 << 1 << list << list2 << list3; list = QList<int>(); diff --git a/tests/auto/widgets/widgets/qmenu/BLACKLIST b/tests/auto/widgets/widgets/qmenu/BLACKLIST index 89d12a259f..bac14ea225 100644 --- a/tests/auto/widgets/widgets/qmenu/BLACKLIST +++ b/tests/auto/widgets/widgets/qmenu/BLACKLIST @@ -1,7 +1,6 @@ [task258920_mouseBorder] osx [submenuTearOffDontClose] -osx-10.11 ci osx-10.12 ci [layoutDirection] # Fails when enabling synchronous expose events QTBUG-62092 diff --git a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp index 634e258250..3bfbe754ef 100644 --- a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp +++ b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp @@ -1001,7 +1001,7 @@ void tst_QMenu::task258920_mouseBorder() menu.setMouseTracking(true); QAction *action = menu.addAction("test"); - const QPoint center = QApplication::desktop()->availableGeometry().center(); + const QPoint center = QGuiApplication::primaryScreen()->availableGeometry().center(); menu.popup(center); QVERIFY(QTest::qWaitForWindowExposed(&menu)); QRect actionRect = menu.actionGeometry(action); @@ -1073,9 +1073,9 @@ void tst_QMenu::pushButtonPopulateOnAboutToShow() QMenu *buttonMenu= new PopulateOnAboutToShowTestMenu(&b); b.setMenu(buttonMenu); - const int scrNumber = QApplication::desktop()->screenNumber(&b); + const QScreen *scr = QGuiApplication::screenAt(b.pos()); b.show(); - const QRect screen = QApplication::desktop()->screenGeometry(scrNumber); + const QRect screen = scr->geometry(); QRect desiredGeometry = b.geometry(); desiredGeometry.moveTopLeft(QPoint(screen.x() + 10, screen.bottom() - b.height() - 5)); @@ -1450,13 +1450,14 @@ void tst_QMenu::QTBUG_56917_wideMenuScreenNumber() QString longString; longString.fill(QLatin1Char('Q'), 3000); - for (int i = 0; i < QApplication::desktop()->screenCount(); i++) { + const QList<QScreen *> screens = QGuiApplication::screens(); + for (QScreen *screen : screens) { QMenu menu; menu.addAction(longString); - menu.popup(QApplication::desktop()->screen(i)->geometry().center()); + menu.popup(screen->geometry().center()); QVERIFY(QTest::qWaitForWindowExposed(&menu)); QVERIFY(menu.isVisible()); - QCOMPARE(QApplication::desktop()->screenNumber(&menu), i); + QCOMPARE(QGuiApplication::screenAt(menu.pos()), screen); } } @@ -1468,19 +1469,20 @@ void tst_QMenu::QTBUG_56917_wideSubmenuScreenNumber() QString longString; longString.fill(QLatin1Char('Q'), 3000); - for (int i = 0; i < QApplication::desktop()->screenCount(); i++) { + const QList<QScreen *> screens = QGuiApplication::screens(); + for (QScreen *screen : screens) { QMenu menu; QMenu submenu("Submenu"); submenu.addAction(longString); QAction *action = menu.addMenu(&submenu); - menu.popup(QApplication::desktop()->screen(i)->geometry().center()); + menu.popup(screen->geometry().center()); QVERIFY(QTest::qWaitForWindowExposed(&menu)); QVERIFY(menu.isVisible()); QTest::mouseClick(&menu, Qt::LeftButton, 0, menu.actionGeometry(action).center()); QTest::qWait(100); QVERIFY(QTest::qWaitForWindowExposed(&submenu)); QVERIFY(submenu.isVisible()); - QCOMPARE(QApplication::desktop()->screenNumber(&submenu), i); + QCOMPARE(QGuiApplication::screenAt(submenu.pos()), screen); } } @@ -1577,6 +1579,13 @@ void tst_QMenu::menuSize_Scrolling() #ifdef Q_OS_WINRT QEXPECT_FAIL("", "Broken on WinRT - QTBUG-68297", Abort); #endif + if (!QGuiApplication::platformName().compare(QLatin1String("minimal"), Qt::CaseInsensitive) + || !QGuiApplication::platformName().compare(QLatin1String("offscreen"), Qt::CaseInsensitive)) { + QWARN("Skipping test on minimal/offscreen platforms - QTBUG-73522"); + QMenu::showEvent(e); + return; + } + QCOMPARE( s.width(), lastItem.right() + fw + hmargin + rightMargin + 1); QMenu::showEvent(e); } diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp index 3063d43aa6..cb829c81a6 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp @@ -326,7 +326,7 @@ TestMenu tst_QMenuBar::initComplexMenuBar(QMenuBar *mb) connect(action, SIGNAL(triggered()), this, SLOT(onComplexActionTriggered())); result.actions << action; - qFill(m_complexTriggerCount, m_complexTriggerCount + sizeof(m_complexTriggerCount) / sizeof(int), 0); + std::fill(m_complexTriggerCount, m_complexTriggerCount + sizeof(m_complexTriggerCount) / sizeof(int), 0); return result; } diff --git a/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp b/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp index be19cbc9d1..2ce75620cf 100644 --- a/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp +++ b/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp @@ -209,12 +209,12 @@ void tst_QPlainTextEdit::getSetCheck() // int QPlainTextEdit::tabStopWidth() // void QPlainTextEdit::setTabStopWidth(int) - obj1.setTabStopWidth(0); - QCOMPARE(0, obj1.tabStopWidth()); - obj1.setTabStopWidth(INT_MIN); - QCOMPARE(0, obj1.tabStopWidth()); // Makes no sense to set a negative tabstop value - obj1.setTabStopWidth(INT_MAX); - QCOMPARE(INT_MAX, obj1.tabStopWidth()); + obj1.setTabStopDistance(0); + QCOMPARE(0, obj1.tabStopDistance()); + obj1.setTabStopDistance(-1); + QCOMPARE(0, obj1.tabStopDistance()); // Makes no sense to set a negative tabstop value + obj1.setTabStopDistance(std::numeric_limits<qreal>::max()); + QCOMPARE(std::numeric_limits<qreal>::max(), obj1.tabStopDistance()); } class QtTestDocumentLayout : public QAbstractTextDocumentLayout diff --git a/tests/auto/widgets/widgets/qsizegrip/tst_qsizegrip.cpp b/tests/auto/widgets/widgets/qsizegrip/tst_qsizegrip.cpp index 4cc1810cd4..f4b91265a4 100644 --- a/tests/auto/widgets/widgets/qsizegrip/tst_qsizegrip.cpp +++ b/tests/auto/widgets/widgets/qsizegrip/tst_qsizegrip.cpp @@ -59,25 +59,22 @@ class tst_QSizeGrip : public QObject { Q_OBJECT public slots: - void initTestCase(); - void cleanupTestCase(); + void cleanup(); private slots: void hideAndShowOnWindowStateChange_data(); void hideAndShowOnWindowStateChange(); void orientation(); void dontCrashOnTLWChange(); - -private: - QLineEdit *dummyWidget; }; class TestWidget : public QWidget { public: - TestWidget(QWidget *parent = 0, Qt::WindowFlags flags = 0) : QWidget(parent, flags) {} - QSize sizeHint() const { return QSize(300, 200); } - void changeEvent(QEvent *event) + using QWidget::QWidget; + + QSize sizeHint() const override { return QSize(300, 200); } + void changeEvent(QEvent *event) override { QWidget::changeEvent(event); if (isWindow() && event->type() == QEvent::WindowStateChange) @@ -85,16 +82,9 @@ public: } }; -void tst_QSizeGrip::initTestCase() -{ - dummyWidget = new QLineEdit; - dummyWidget->show(); -} - -void tst_QSizeGrip::cleanupTestCase() +void tst_QSizeGrip::cleanup() { - delete dummyWidget; - dummyWidget = 0; + QVERIFY(QApplication::topLevelWidgets().isEmpty()); } void tst_QSizeGrip::hideAndShowOnWindowStateChange_data() @@ -111,46 +101,45 @@ void tst_QSizeGrip::hideAndShowOnWindowStateChange() QSKIP("Broken on WinRT - QTBUG-68297"); #endif - QWidget *parentWidget = windowType == Qt::Window ? 0 : new QWidget; - TestWidget *widget = new TestWidget(parentWidget, Qt::WindowFlags(windowType)); - QSizeGrip *sizeGrip = new QSizeGrip(widget); + QScopedPointer<QWidget> parentWidget; + if (windowType != Qt::Window) + parentWidget.reset(new QWidget); + QScopedPointer<TestWidget> widget(new TestWidget(parentWidget.data(), Qt::WindowFlags(windowType))); + QSizeGrip *sizeGrip = new QSizeGrip(widget.data()); // Normal. if (parentWidget) parentWidget->show(); else widget->show(); - QVERIFY(sizeGrip->isVisible()); + QTRY_VERIFY(sizeGrip->isVisible()); widget->showFullScreen(); - QVERIFY(!sizeGrip->isVisible()); + QTRY_VERIFY(!sizeGrip->isVisible()); widget->showNormal(); - QVERIFY(sizeGrip->isVisible()); + QTRY_VERIFY(sizeGrip->isVisible()); widget->showMaximized(); #ifndef Q_OS_MAC - QVERIFY(!sizeGrip->isVisible()); + QTRY_VERIFY(!sizeGrip->isVisible()); #else QEXPECT_FAIL("", "QTBUG-23681", Abort); QVERIFY(sizeGrip->isVisible()); #endif widget->showNormal(); - QVERIFY(sizeGrip->isVisible()); + QTRY_VERIFY(sizeGrip->isVisible()); sizeGrip->hide(); - QVERIFY(!sizeGrip->isVisible()); + QTRY_VERIFY(!sizeGrip->isVisible()); widget->showFullScreen(); widget->showNormal(); - QVERIFY(!sizeGrip->isVisible()); + QTRY_VERIFY(!sizeGrip->isVisible()); widget->showMaximized(); widget->showNormal(); - QVERIFY(!sizeGrip->isVisible()); - - delete widget; - delete parentWidget; + QTRY_VERIFY(!sizeGrip->isVisible()); } void tst_QSizeGrip::orientation() @@ -196,10 +185,10 @@ void tst_QSizeGrip::dontCrashOnTLWChange() QMdiArea mdiArea; mdiArea.show(); - QMainWindow *mw = new QMainWindow(); - QMdiSubWindow *mdi = mdiArea.addSubWindow(mw); + QScopedPointer<QMainWindow> mw(new QMainWindow); + QMdiSubWindow *mdi = mdiArea.addSubWindow(mw.data()); mw->statusBar()->setSizeGripEnabled(true); - mdiArea.removeSubWindow(mw); + mdiArea.removeSubWindow(mw.data()); delete mdi; mw->show(); @@ -209,7 +198,7 @@ void tst_QSizeGrip::dontCrashOnTLWChange() QEXPECT_FAIL("", "Broken on WinRT - QTBUG-68297", Abort); #endif QVERIFY(QTest::qWaitForWindowExposed(&mdiArea)); - QVERIFY(QTest::qWaitForWindowExposed(mw)); + QVERIFY(QTest::qWaitForWindowExposed(mw.data())); } QTEST_MAIN(tst_QSizeGrip) diff --git a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp index 37bb28dec9..b9d6888263 100644 --- a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp +++ b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp @@ -53,6 +53,8 @@ #include <QStyleOptionSpinBox> #include <QStyle> #include <QProxyStyle> +#include <QScreen> + class SpinBox : public QSpinBox { @@ -204,7 +206,7 @@ private slots: void stepModifierPressAndHold_data(); void stepModifierPressAndHold(); public slots: - void valueChangedHelper(const QString &); + void textChangedHelper(const QString &); void valueChangedHelper(int); private: QStringList actualTexts; @@ -343,6 +345,14 @@ tst_QSpinBox::tst_QSpinBox() void tst_QSpinBox::init() { QLocale::setDefault(QLocale(QLocale::C)); + +#if QT_CONFIG(cursor) + // Ensure mouse cursor was not left by previous tests where widgets + // will appear, as it could cause events and interfere with the tests. + const QScreen *screen = QGuiApplication::primaryScreen(); + const QRect availableGeometry = screen->availableGeometry(); + QCursor::setPos(availableGeometry.topLeft()); +#endif } void tst_QSpinBox::setValue_data() @@ -452,8 +462,11 @@ void tst_QSpinBox::setPrefixSuffix() QFETCH(bool, show); QSpinBox spin(0); + const QSize size1 = spin.sizeHint(); spin.setPrefix(prefix); + const QSize size2 = spin.sizeHint(); spin.setSuffix(suffix); + const QSize size3 = spin.sizeHint(); spin.setValue(value); if (show) spin.show(); @@ -462,9 +475,18 @@ void tst_QSpinBox::setPrefixSuffix() QCOMPARE(spin.suffix(), suffix); QCOMPARE(spin.text(), expectedText); QCOMPARE(spin.cleanText(), expectedCleanText); + + if (!prefix.isEmpty() && !suffix.isEmpty()) { + QVERIFY(size1.width() < size2.width()); + QVERIFY(size2.width() < size3.width()); + spin.setSuffix(QString()); + QCOMPARE(spin.sizeHint(), size2); + spin.setPrefix(QString()); + QCOMPARE(spin.sizeHint(), size1); + } } -void tst_QSpinBox::valueChangedHelper(const QString &text) +void tst_QSpinBox::textChangedHelper(const QString &text) { actualTexts << text; } @@ -542,7 +564,7 @@ void tst_QSpinBox::setTracking() QSpinBox spin(0); spin.setKeyboardTracking(tracking); spin.show(); - connect(&spin, SIGNAL(valueChanged(QString)), this, SLOT(valueChangedHelper(QString))); + connect(&spin, &QSpinBox::textChanged, this, &tst_QSpinBox::textChangedHelper); keys.simulate(&spin); QCOMPARE(actualTexts, texts); diff --git a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp index 5f5cd78215..3669935823 100644 --- a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp +++ b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp @@ -282,12 +282,12 @@ void tst_QTextEdit::getSetCheck() // int QTextEdit::tabStopWidth() // void QTextEdit::setTabStopWidth(int) - obj1.setTabStopWidth(0); - QCOMPARE(0, obj1.tabStopWidth()); - obj1.setTabStopWidth(INT_MIN); - QCOMPARE(0, obj1.tabStopWidth()); // Makes no sense to set a negative tabstop value - obj1.setTabStopWidth(INT_MAX); - QCOMPARE(INT_MAX, obj1.tabStopWidth()); + obj1.setTabStopDistance(0); + QCOMPARE(0, obj1.tabStopDistance()); + obj1.setTabStopDistance(-1); + QCOMPARE(0, obj1.tabStopDistance()); // Makes no sense to set a negative tabstop value + obj1.setTabStopDistance(std::numeric_limits<qreal>::max()); + QCOMPARE(std::numeric_limits<qreal>::max(), obj1.tabStopDistance()); // bool QTextEdit::acceptRichText() // void QTextEdit::setAcceptRichText(bool) diff --git a/tests/auto/widgets/widgets/qtoolbar/tst_qtoolbar.cpp b/tests/auto/widgets/widgets/qtoolbar/tst_qtoolbar.cpp index 301801ed2e..d6c165642e 100644 --- a/tests/auto/widgets/widgets/qtoolbar/tst_qtoolbar.cpp +++ b/tests/auto/widgets/widgets/qtoolbar/tst_qtoolbar.cpp @@ -42,6 +42,7 @@ #include <qlineedit.h> #include <qkeysequence.h> #include <qmenu.h> +#include <qlabel.h> #include <private/qtoolbarextension_p.h> QT_FORWARD_DECLARE_CLASS(QAction) @@ -80,6 +81,8 @@ private slots: void task191727_layout(); void task197996_visibility(); + + void extraCpuConsumption(); // QTBUG-54676 }; @@ -1098,5 +1101,81 @@ void tst_QToolBar::task197996_visibility() QTRY_VERIFY(toolBar->widgetForAction(pAction)->isVisible()); } +class ShowHideEventCounter : public QObject +{ +public: + using QObject::QObject; + + bool eventFilter(QObject *watched, QEvent *event) override + { + if (qobject_cast<QLineEdit*>(watched) && !event->spontaneous()) { + if (event->type() == QEvent::Show) + ++m_showEventsCount; + + if (event->type() == QEvent::Hide) + ++m_hideEventsCount; + } + + return QObject::eventFilter(watched, event); + } + + uint showEventsCount() const { return m_showEventsCount; } + uint hideEventsCount() const { return m_hideEventsCount; } + +private: + uint m_showEventsCount = 0; + uint m_hideEventsCount = 0; +}; + +void tst_QToolBar::extraCpuConsumption() +{ + QMainWindow mainWindow; + + auto tb = new QToolBar(&mainWindow); + tb->setMovable(false); + + auto extensions = tb->findChildren<QToolBarExtension *>(); + QVERIFY(!extensions.isEmpty()); + + auto extensionButton = extensions.at(0); + QVERIFY(extensionButton); + + tb->addWidget(new QLabel("Lorem ipsum dolor sit amet")); + + auto le = new QLineEdit; + le->setClearButtonEnabled(true); + le->setText("Lorem ipsum"); + tb->addWidget(le); + + mainWindow.addToolBar(tb); + mainWindow.show(); + QVERIFY(QTest::qWaitForWindowActive(&mainWindow)); + + auto eventCounter = new ShowHideEventCounter(&mainWindow); + le->installEventFilter(eventCounter); + + auto defaultSize = mainWindow.size(); + + // Line edit should be hidden now and extension button should be displayed + for (double p = 0.7; extensionButton->isHidden() || qFuzzyCompare(p, 0.); p -= 0.01) { + mainWindow.resize(int(defaultSize.width() * p), defaultSize.height()); + } + QVERIFY(!extensionButton->isHidden()); + + // Line edit should be visible, but smaller + for (double p = 0.75; !extensionButton->isHidden() || qFuzzyCompare(p, 1.); p += 0.01) { + mainWindow.resize(int(defaultSize.width() * p), defaultSize.height()); + } + QVERIFY(extensionButton->isHidden()); + + // Dispatch all pending events + qApp->sendPostedEvents(); + qApp->processEvents(); + + QCOMPARE(eventCounter->showEventsCount(), eventCounter->hideEventsCount()); + QCOMPARE(eventCounter->showEventsCount(), uint(1)); + QCOMPARE(eventCounter->hideEventsCount(), uint(1)); +} + QTEST_MAIN(tst_QToolBar) #include "tst_qtoolbar.moc" |