summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-11-21 14:34:31 +0100
committerLiang Qi <liang.qi@qt.io>2017-11-23 09:36:03 +0100
commit153e8b49adfe210cb00490284a14c94c08e03c3f (patch)
tree59d9522d6dc96215cc2cb1d19b3e8a0e580bcb41 /tests/auto
parentef7c0594bf9e41813c9c841e00c3a52269d363f5 (diff)
parenta4113d0c644edba1c39d9d268a259e95ae51c61e (diff)
Merge remote-tracking branch 'origin/5.10' into dev
Conflicts: src/network/access/qhttp2protocolhandler_p.h src/network/kernel/kernel.pri src/network/ssl/qsslkey_qt.cpp src/plugins/platforms/cocoa/qcocoascreen.mm src/plugins/platforms/windows/accessible/iaccessible2.cpp src/plugins/platforms/windows/accessible/iaccessible2.h src/plugins/platforms/windows/accessible/qwindowsaccessibility.cpp src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.cpp src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.h src/widgets/widgets/qmenu_p.h tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp tests/auto/other/qaccessibility/tst_qaccessibility.cpp tests/auto/testlib/selftests/expected_cmptest.lightxml tests/auto/testlib/selftests/expected_cmptest.teamcity tests/auto/testlib/selftests/expected_cmptest.txt tests/auto/testlib/selftests/expected_cmptest.xml Done-with: Edward Welbourne <edward.welbourne@qt.io> Change-Id: I4217cc7d840cbae3e3dd28574741544469c4c6b9
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/auto.pro2
-rw-r--r--tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp4
-rw-r--r--tests/auto/corelib/animation/qsequentialanimationgroup/BLACKLIST2
-rw-r--r--tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp395
-rw-r--r--tests/auto/corelib/io/largefile/tst_largefile.cpp4
-rw-r--r--tests/auto/corelib/io/qfile/tst_qfile.cpp117
-rw-r--r--tests/auto/corelib/io/qfileselector/platforms/+qnx/test0
-rw-r--r--tests/auto/corelib/io/qfileselector/platforms/+qnx/test20
-rw-r--r--tests/auto/corelib/io/qfileselector/platforms/+unix/+qnx/test0
-rw-r--r--tests/auto/corelib/io/qfileselector/qfileselector.qrc3
-rw-r--r--tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp2
-rw-r--r--tests/auto/corelib/io/qstandardpaths/BLACKLIST3
-rw-r--r--tests/auto/corelib/io/qtemporarydir/qtemporarydir.pro2
-rw-r--r--tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp13
-rw-r--r--tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro2
-rw-r--r--tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp16
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp35
-rw-r--r--tests/auto/corelib/kernel/qobject/tst_qobject.cpp4
-rw-r--r--tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp1
-rw-r--r--tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp3
-rw-r--r--tests/auto/corelib/thread/qfuture/tst_qfuture.cpp3
-rw-r--r--tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp11
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp5
-rw-r--r--tests/auto/gui/image/qimage/tst_qimage.cpp3
-rw-r--r--tests/auto/gui/painting/qpainter/tst_qpainter.cpp3
-rw-r--r--tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp5
-rw-r--r--tests/auto/gui/text/qtextpiecetable/tst_qtextpiecetable.cpp19
-rw-r--r--tests/auto/network/access/hpack/tst_hpack.cpp12
-rw-r--r--tests/auto/network/access/http2/tst_http2.cpp2
-rw-r--r--tests/auto/network/access/qftp/tst_qftp.cpp3
-rw-r--r--tests/auto/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp14
-rw-r--r--tests/auto/network/access/qnetworkreply/BLACKLIST32
-rw-r--r--tests/auto/network/access/qnetworkreply/test/test.pro3
-rw-r--r--tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp144
-rw-r--r--tests/auto/network/socket/qtcpsocket/qtcpsocket.pro6
-rw-r--r--tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp8
-rw-r--r--tests/auto/network/socket/qudpsocket/qudpsocket.pro3
-rw-r--r--tests/auto/network/socket/qudpsocket/test/test.pro1
-rw-r--r--tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp171
-rw-r--r--tests/auto/opengl/qglthreads/tst_qglthreads.cpp20
-rw-r--r--tests/auto/other/compiler/tst_compiler.cpp10
-rw-r--r--tests/auto/other/networkselftest/tst_networkselftest.cpp3
-rw-r--r--tests/auto/other/qaccessibility/qaccessibility.pro2
-rw-r--r--tests/auto/other/qaccessibility/tst_qaccessibility.cpp35
-rw-r--r--tests/auto/other/qnetworkaccessmanager_and_qprogressdialog/BLACKLIST2
-rw-r--r--tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp2
-rw-r--r--tests/auto/sql/kernel/qsqldriver/tst_qsqldriver.cpp19
-rw-r--r--tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp2
-rw-r--r--tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp20
-rw-r--r--tests/auto/testlib/selftests/expected_cmptest.lightxml14
-rw-r--r--tests/auto/testlib/selftests/expected_cmptest.teamcity11
-rw-r--r--tests/auto/testlib/selftests/expected_cmptest.txt13
-rw-r--r--tests/auto/testlib/selftests/expected_cmptest.xml14
-rw-r--r--tests/auto/testlib/selftests/expected_cmptest.xunitxml11
-rw-r--r--tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp3
-rw-r--r--tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp20
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsitem/qgraphicsitem.pro2
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp31
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp30
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsview/qgraphicsview.pro2
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp12
-rw-r--r--tests/auto/widgets/itemviews/qabstractitemview/qabstractitemview.pro2
-rw-r--r--tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp15
-rw-r--r--tests/auto/widgets/itemviews/qcolumnview/qcolumnview.pro2
-rw-r--r--tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp11
-rw-r--r--tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp4
-rw-r--r--tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp23
-rw-r--r--tests/auto/widgets/itemviews/qlistview/qlistview.pro2
-rw-r--r--tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp14
-rw-r--r--tests/auto/widgets/itemviews/qtableview/qtableview.pro2
-rw-r--r--tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp14
-rw-r--r--tests/auto/widgets/itemviews/qtreeview/qtreeview.pro2
-rw-r--r--tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp23
-rw-r--r--tests/auto/widgets/kernel/qaction/tst_qaction.cpp68
-rw-r--r--tests/auto/widgets/kernel/qboxlayout/qboxlayout.pro2
-rw-r--r--tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp10
-rw-r--r--tests/auto/widgets/kernel/qformlayout/qformlayout.pro2
-rw-r--r--tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp12
-rw-r--r--tests/auto/widgets/kernel/qgridlayout/qgridlayout.pro2
-rw-r--r--tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp12
-rw-r--r--tests/auto/widgets/kernel/qlayout/qlayout.pro2
-rw-r--r--tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp10
-rw-r--r--tests/auto/widgets/kernel/qwidget/BLACKLIST2
-rw-r--r--tests/auto/widgets/kernel/qwidget/qwidget.pro2
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp29
-rw-r--r--tests/auto/widgets/kernel/qwidget_window/qwidget_window.pro2
-rw-r--r--tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp10
-rw-r--r--tests/auto/widgets/kernel/qwidgetaction/qwidgetaction.pro2
-rw-r--r--tests/auto/widgets/kernel/qwidgetaction/tst_qwidgetaction.cpp10
-rw-r--r--tests/auto/widgets/styles/qstyle/qstyle.pro2
-rw-r--r--tests/auto/widgets/styles/qstyle/tst_qstyle.cpp12
-rw-r--r--tests/auto/widgets/styles/qstylesheetstyle/qstylesheetstyle.pro2
-rw-r--r--tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp7
-rw-r--r--tests/auto/widgets/util/qcompleter/qcompleter.pro2
-rw-r--r--tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp10
-rw-r--r--tests/auto/widgets/widgets/qabstractbutton/tst_qabstractbutton.cpp32
-rw-r--r--tests/auto/widgets/widgets/qabstractslider/qabstractslider.pro2
-rw-r--r--tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp12
-rw-r--r--tests/auto/widgets/widgets/qabstractspinbox/qabstractspinbox.pro2
-rw-r--r--tests/auto/widgets/widgets/qabstractspinbox/tst_qabstractspinbox.cpp13
-rw-r--r--tests/auto/widgets/widgets/qcombobox/qcombobox.pro2
-rw-r--r--tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp10
-rw-r--r--tests/auto/widgets/widgets/qlineedit/qlineedit.pro2
-rw-r--r--tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp28
-rw-r--r--tests/auto/widgets/widgets/qmenu/qmenu.pro2
-rw-r--r--tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp14
-rw-r--r--tests/auto/widgets/widgets/qmenubar/BLACKLIST2
-rw-r--r--tests/auto/widgets/widgets/qmenubar/qmenubar.pro2
-rw-r--r--tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp100
-rw-r--r--tests/auto/widgets/widgets/qscrollbar/qscrollbar.pro2
-rw-r--r--tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp11
-rw-r--r--tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp32
112 files changed, 1256 insertions, 672 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 3caa6a3b65..a1ffe5b3ce 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -46,5 +46,5 @@ else:!qtConfig(process): SUBDIRS -= tools
# QTBUG-63915
boot2qt: {
- contains(QT_ARCH, arm64): SUBDIRS -= dbus
+ SUBDIRS -= dbus
}
diff --git a/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp b/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp
index 96656a6dff..2d7c0c2f64 100644
--- a/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp
+++ b/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp
@@ -2204,13 +2204,13 @@ InstanceCounter slowMap(const InstanceCounter &in)
InstanceCounter fastMap(const InstanceCounter &in)
{
- QTest::qSleep(rand() % 2 + 1);
+ QTest::qSleep(QRandomGenerator::global()->bounded(2) + 1);
return in;
}
void slowReduce(int &result, const InstanceCounter&)
{
- QTest::qSleep(rand() % 4 + 1);
+ QTest::qSleep(QRandomGenerator::global()->bounded(4) + 1);
++result;
}
diff --git a/tests/auto/corelib/animation/qsequentialanimationgroup/BLACKLIST b/tests/auto/corelib/animation/qsequentialanimationgroup/BLACKLIST
index 391e3f67af..2a31afd735 100644
--- a/tests/auto/corelib/animation/qsequentialanimationgroup/BLACKLIST
+++ b/tests/auto/corelib/animation/qsequentialanimationgroup/BLACKLIST
@@ -3,3 +3,5 @@ windows
[finishWithUncontrolledAnimation]
windows
osx-10.12
+[groupWithZeroDurationAnimations]
+osx
diff --git a/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp b/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp
index 4b38d46317..220ec9a2f8 100644
--- a/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp
+++ b/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp
@@ -43,8 +43,8 @@
#define COMMA ,
#define QVERIFY_3TIMES(statement) \
do {\
- if (!QTest::qVerify(static_cast<bool>(statement), #statement, "1st try", __FILE__, __LINE__))\
- if (!QTest::qVerify(static_cast<bool>(statement), #statement, "2nd try", __FILE__, __LINE__))\
+ if (!static_cast<bool>(statement))\
+ if (!static_cast<bool>(statement))\
if (!QTest::qVerify(static_cast<bool>(statement), #statement, "3rd try", __FILE__, __LINE__))\
return;\
} while (0)
@@ -71,6 +71,15 @@ public slots:
void cleanup() { setRNGControl(0); }
private slots:
+ void basics();
+ void knownSequence();
+ void discard();
+ void copying();
+ void copyingGlobal();
+ void copyingSystem();
+ void systemRng();
+ void securelySeeding();
+
void generate32_data();
void generate32();
void generate64_data() { generate32_data(); }
@@ -110,19 +119,212 @@ private slots:
void stdRandomDistributions();
};
+// The first 20 results of the sequence:
+static const quint32 defaultRngResults[] = {
+ 853323747U, 2396352728U, 3025954838U, 2985633182U, 2815751046U,
+ 340588426U, 3587208406U, 298087538U, 2912478009U, 3642122814U,
+ 3202916223U, 799257577U, 1872145992U, 639469699U, 3201121432U,
+ 2388658094U, 1735523408U, 2215232359U, 668106566U, 2554687763U
+};
+
+
using namespace std;
QT_WARNING_DISABLE_GCC("-Wfloat-equal")
QT_WARNING_DISABLE_CLANG("-Wfloat-equal")
+struct RandomGenerator : public QRandomGenerator
+{
+ RandomGenerator(uint control)
+ : QRandomGenerator(control ?
+ QRandomGenerator(control & RandomDataMask) :
+ *QRandomGenerator::global())
+ {
+ setRNGControl(control);
+ }
+};
+
+void tst_QRandomGenerator::basics()
+{
+ // default constructible
+ QRandomGenerator rng;
+
+ // copyable && movable
+ rng = rng;
+ rng = std::move(rng);
+
+ // 64-bit
+ QRandomGenerator64 rng64;
+ rng64 = rng64;
+ rng64 = std::move(rng64);
+
+ // 32- and 64-bit should be interchangeable:
+ rng = rng64;
+ rng64 = rng;
+ rng = std::move(rng64);
+ rng64 = std::move(rng);
+
+ rng = QRandomGenerator64::securelySeeded();
+ rng64 = QRandomGenerator::securelySeeded();
+
+ // access global
+ QRandomGenerator *global = QRandomGenerator::global();
+ QRandomGenerator globalCopy = *global;
+ globalCopy = *global;
+ QRandomGenerator64 *global64 = QRandomGenerator64::global();
+ QRandomGenerator64 globalCopy64 = *global64;
+ globalCopy64 = *global64;
+
+ // access system
+ QRandomGenerator *system = QRandomGenerator::system();
+ QRandomGenerator systemRng = *system;
+ systemRng = *system;
+
+ QRandomGenerator64 *system64 = QRandomGenerator64::system();
+ QRandomGenerator64 systemRng64 = *system64;
+ systemRng64 = *system64;
+
+ Q_STATIC_ASSERT(std::is_same<decltype(rng64.generate()) COMMA quint64>::value);
+ Q_STATIC_ASSERT(std::is_same<decltype(system64->generate()) COMMA quint64>::value);
+}
+
+void tst_QRandomGenerator::knownSequence()
+{
+ QRandomGenerator rng;
+ for (quint32 x : defaultRngResults)
+ QCOMPARE(rng(), x);
+
+ // should work again if we reseed it
+ rng.seed();
+ for (quint32 x : defaultRngResults)
+ QCOMPARE(rng(), x);
+}
+
+void tst_QRandomGenerator::discard()
+{
+ QRandomGenerator rng;
+ rng.discard(1);
+ QCOMPARE(rng(), defaultRngResults[1]);
+
+ rng.discard(9);
+ QCOMPARE(rng(), defaultRngResults[11]);
+}
+
+void tst_QRandomGenerator::copying()
+{
+ QRandomGenerator rng1;
+ QRandomGenerator rng2 = rng1;
+ QCOMPARE(rng1, rng2);
+
+ quint32 samples[20];
+ rng1.fillRange(samples);
+
+ // not equal anymore
+ QVERIFY(rng1 != rng2);
+
+ // should produce the same sequence, whichever it was
+ for (quint32 x : samples)
+ QCOMPARE(rng2(), x);
+
+ // now they should compare equal again
+ QCOMPARE(rng1, rng2);
+}
+
+void tst_QRandomGenerator::copyingGlobal()
+{
+ QRandomGenerator &global = *QRandomGenerator::global();
+ QRandomGenerator copy = global;
+ QCOMPARE(copy, global);
+ QCOMPARE(global, copy);
+
+ quint32 samples[20];
+ global.fillRange(samples);
+
+ // not equal anymore
+ QVERIFY(copy != global);
+
+ // should produce the same sequence, whichever it was
+ for (quint32 x : samples)
+ QCOMPARE(copy(), x);
+
+ // equal again
+ QCOMPARE(copy, global);
+ QCOMPARE(global, copy);
+}
+
+void tst_QRandomGenerator::copyingSystem()
+{
+ QRandomGenerator &system = *QRandomGenerator::system();
+ QRandomGenerator copy = system;
+ QRandomGenerator copy2 = copy;
+ copy2 = copy;
+ QCOMPARE(system, copy);
+ QCOMPARE(copy, copy2);
+
+ quint32 samples[20];
+ copy2.fillRange(samples);
+
+ // they still compre equally
+ QCOMPARE(system, copy);
+ QCOMPARE(copy, copy2);
+
+ // should NOT produce the same sequence, whichever it was
+ int sameCount = 0;
+ for (quint32 x : samples)
+ sameCount += (copy() == x);
+ QVERIFY(sameCount < 20);
+
+ QCOMPARE(system, copy);
+ QCOMPARE(copy, copy2);
+}
+
+void tst_QRandomGenerator::systemRng()
+{
+ QRandomGenerator *rng = QRandomGenerator::system();
+ rng->generate();
+ rng->generate64();
+ rng->generateDouble();
+ rng->bounded(100);
+ rng->bounded(100U);
+
+#ifdef QT_BUILD_INTERNAL
+ quint32 setpoint = std::numeric_limits<int>::max();
+ ++setpoint;
+ quint64 setpoint64 = quint64(setpoint) << 32 | setpoint;
+ setRNGControl(SetRandomData | setpoint);
+
+ QCOMPARE(rng->generate(), setpoint);
+ QCOMPARE(rng->generate64(), setpoint64);
+ QCOMPARE(rng->generateDouble(), ldexp(setpoint64, -64));
+ QCOMPARE(rng->bounded(100), 50);
+#endif
+}
+
+void tst_QRandomGenerator::securelySeeding()
+{
+ QRandomGenerator rng1 = QRandomGenerator::securelySeeded();
+ QRandomGenerator rng2 = QRandomGenerator::securelySeeded();
+
+ quint32 samples[20];
+ rng1.fillRange(samples);
+
+ // should NOT produce the same sequence, whichever it was
+ int sameCount = 0;
+ for (quint32 x : samples)
+ sameCount += (rng2() == x);
+ QVERIFY(sameCount < 20);
+}
+
void tst_QRandomGenerator::generate32_data()
{
QTest::addColumn<uint>("control");
- QTest::newRow("default") << 0U;
+ QTest::newRow("fixed") << (RandomValue32 & RandomDataMask);
+ QTest::newRow("global") << 0U;
#ifdef QT_BUILD_INTERNAL
- QTest::newRow("direct") << uint(SkipMemfill);
- QTest::newRow("system") << uint(SkipHWRNG);
+ if (qt_has_hwrng())
+ QTest::newRow("hwrng") << uint(UseSystemRNG);
+ QTest::newRow("system") << uint(UseSystemRNG | SkipHWRNG);
# ifdef HAVE_FALLBACK_ENGINE
- QTest::newRow("fallback") << uint(SkipHWRNG | SkipSystemRNG);
+ QTest::newRow("system-fallback") << uint(UseSystemRNG | SkipHWRNG | SkipSystemRNG);
# endif
#endif
}
@@ -130,39 +332,40 @@ void tst_QRandomGenerator::generate32_data()
void tst_QRandomGenerator::generate32()
{
QFETCH(uint, control);
- setRNGControl(control);
+ RandomGenerator rng(control);
for (int i = 0; i < 4; ++i) {
- QVERIFY_3TIMES([] {
- quint32 value = QRandomGenerator::generate();
+ QVERIFY_3TIMES([&] {
+ quint32 value = rng.generate();
return value != 0 && value != RandomValue32;
}());
}
// and should hopefully be different from repeated calls
for (int i = 0; i < 4; ++i)
- QVERIFY_3TIMES(QRandomGenerator::generate() != QRandomGenerator::generate());
+ QVERIFY_3TIMES(rng.generate() != rng.generate());
}
void tst_QRandomGenerator::generate64()
{
QFETCH(uint, control);
- setRNGControl(control);
+ RandomGenerator rng(control);
+ QVERIFY_3TIMES(rng.generate64() > std::numeric_limits<quint32>::max());
for (int i = 0; i < 4; ++i) {
- QVERIFY_3TIMES([] {
- quint64 value = QRandomGenerator::generate();
+ QVERIFY_3TIMES([&] {
+ quint64 value = rng.generate64();
return value != 0 && value != RandomValue32 && value != RandomValue64;
}());
}
// and should hopefully be different from repeated calls
for (int i = 0; i < 4; ++i)
- QVERIFY_3TIMES(QRandomGenerator::generate64() != QRandomGenerator::generate64());
+ QVERIFY_3TIMES(rng.generate64() != rng.generate64());
for (int i = 0; i < 4; ++i)
- QVERIFY_3TIMES(QRandomGenerator::generate() != quint32(QRandomGenerator::generate64()));
+ QVERIFY_3TIMES(rng.generate() != quint32(rng.generate64()));
for (int i = 0; i < 4; ++i)
- QVERIFY_3TIMES(QRandomGenerator::generate() != (QRandomGenerator::generate64() >> 32));
+ QVERIFY_3TIMES(rng.generate() != (rng.generate64() >> 32));
}
void tst_QRandomGenerator::quality()
@@ -191,7 +394,9 @@ void tst_QRandomGenerator::quality()
Q_STATIC_ASSERT(FailureThreshold > AcceptableThreshold);
QFETCH(uint, control);
- setRNGControl(control);
+ if (control & RandomDataMask)
+ return;
+ RandomGenerator rng(control);
int histogram[UCHAR_MAX + 1];
memset(histogram, 0, sizeof(histogram));
@@ -200,7 +405,7 @@ void tst_QRandomGenerator::quality()
// test the quality of the generator
quint32 buffer[BufferCount];
memset(buffer, 0xcc, sizeof(buffer));
- generate_n(buffer, +BufferCount, [] { return QRandomGenerator::generate(); });
+ generate_n(buffer, +BufferCount, [&] { return rng.generate(); });
quint8 *ptr = reinterpret_cast<quint8 *>(buffer);
quint8 *end = ptr + sizeof(buffer);
@@ -225,20 +430,20 @@ void tst_QRandomGenerator::quality()
template <typename T> void fillRange_template()
{
QFETCH(uint, control);
- setRNGControl(control);
+ RandomGenerator rng(control);
for (int i = 0; i < 4; ++i) {
- QVERIFY_3TIMES([] {
+ QVERIFY_3TIMES([&] {
T value[1] = { RandomValue32 };
- QRandomGenerator::fillRange(value);
+ rng.fillRange(value);
return value[0] != 0 && value[0] != RandomValue32;
}());
}
for (int i = 0; i < 4; ++i) {
- QVERIFY_3TIMES([] {
+ QVERIFY_3TIMES([&] {
T array[2] = {};
- QRandomGenerator::fillRange(array);
+ rng.fillRange(array);
return array[0] != array[1];
}());
}
@@ -246,18 +451,18 @@ template <typename T> void fillRange_template()
if (sizeof(T) > sizeof(quint32)) {
// just to shut up a warning about shifting uint more than the width
enum { Shift = sizeof(T) / 2 * CHAR_BIT };
- QVERIFY_3TIMES([] {
+ QVERIFY_3TIMES([&] {
T value[1] = { };
- QRandomGenerator::fillRange(value);
+ rng.fillRange(value);
return quint32(value[0] >> Shift) != quint32(value[0]);
}());
}
// fill in a longer range
- auto longerArrayCheck = [] {
+ auto longerArrayCheck = [&] {
T array[32];
memset(array, 0, sizeof(array));
- QRandomGenerator::fillRange(array);
+ rng.fillRange(array);
if (sizeof(T) == sizeof(RandomValue64)
&& find(begin(array), end(array), RandomValue64) != end(array))
return false;
@@ -274,11 +479,11 @@ void tst_QRandomGenerator::fillRangeULLong() { fillRange_template<qulonglong>();
template <typename T> void generate_template()
{
QFETCH(uint, control);
- setRNGControl(control);
+ RandomGenerator rng(control);
// almost the same as fillRange, but limited to 32 bits
for (int i = 0; i < 4; ++i) {
- QVERIFY_3TIMES([] {
+ QVERIFY_3TIMES([&] {
T value[1] = { RandomValue32 };
QRandomGenerator().generate(begin(value), end(value));
return value[0] != 0 && value[0] != RandomValue32
@@ -287,10 +492,10 @@ template <typename T> void generate_template()
}
// fill in a longer range
- auto longerArrayCheck = [] {
+ auto longerArrayCheck = [&] {
T array[72] = {}; // at least 256 bytes
QRandomGenerator().generate(begin(array), end(array));
- return find_if(begin(array), end(array), [](T cur) {
+ return find_if(begin(array), end(array), [&](T cur) {
return cur == 0 || cur == RandomValue32 ||
cur == RandomValue64 || cur > numeric_limits<quint32>::max();
}) == end(array);
@@ -304,12 +509,12 @@ void tst_QRandomGenerator::generateULLong() { generate_template<qulonglong>(); }
void tst_QRandomGenerator::generateNonContiguous()
{
QFETCH(uint, control);
- setRNGControl(control);
+ RandomGenerator rng(control);
QLinkedList<quint64> list = { 0, 0, 0, 0, 0, 0, 0, 0 };
auto longerArrayCheck = [&] {
QRandomGenerator().generate(list.begin(), list.end());
- return find_if(list.begin(), list.end(), [](quint64 cur) {
+ return find_if(list.begin(), list.end(), [&](quint64 cur) {
return cur == 0 || cur == RandomValue32 ||
cur == RandomValue64 || cur > numeric_limits<quint32>::max();
}) == list.end();
@@ -327,7 +532,7 @@ void tst_QRandomGenerator::bounded_data()
QTest::addColumn<quint32>("sup");
QTest::addColumn<quint32>("expected");
- auto newRow = [](quint32 val, quint32 sup) {
+ auto newRow = [&](quint32 val, quint32 sup) {
// calculate the scaled value
quint64 scaled = val;
scaled <<= 32;
@@ -353,31 +558,31 @@ void tst_QRandomGenerator::bounded()
QFETCH(uint, control);
QFETCH(quint32, sup);
QFETCH(quint32, expected);
- setRNGControl(control);
+ RandomGenerator rng(control);
- quint32 value = QRandomGenerator::bounded(sup);
+ quint32 value = rng.bounded(sup);
QVERIFY(value < sup);
QCOMPARE(value, expected);
- int ivalue = QRandomGenerator::bounded(sup);
+ int ivalue = rng.bounded(sup);
QVERIFY(ivalue < int(sup));
QCOMPARE(ivalue, int(expected));
// confirm only the bound now
- setRNGControl(control & (SkipHWRNG|SkipSystemRNG));
- value = QRandomGenerator::bounded(sup);
+ setRNGControl(control & (SkipHWRNG|SkipSystemRNG|UseSystemRNG));
+ value = rng.bounded(sup);
QVERIFY(value < sup);
- value = QRandomGenerator::bounded(sup / 2, 3 * sup / 2);
+ value = rng.bounded(sup / 2, 3 * sup / 2);
QVERIFY(value >= sup / 2);
QVERIFY(value < 3 * sup / 2);
- ivalue = QRandomGenerator::bounded(-int(sup), int(sup));
+ ivalue = rng.bounded(-int(sup), int(sup));
QVERIFY(ivalue >= -int(sup));
QVERIFY(ivalue < int(sup));
// wholly negative range
- ivalue = QRandomGenerator::bounded(-int(sup), 0);
+ ivalue = rng.bounded(-int(sup), 0);
QVERIFY(ivalue >= -int(sup));
QVERIFY(ivalue < 0);
}
@@ -408,7 +613,9 @@ void tst_QRandomGenerator::boundedQuality()
Q_STATIC_ASSERT(FailureThreshold > AcceptableThreshold);
QFETCH(uint, control);
- setRNGControl(control);
+ if (control & RandomDataMask)
+ return;
+ RandomGenerator rng(control);
int histogram[Bound];
memset(histogram, 0, sizeof(histogram));
@@ -416,7 +623,7 @@ void tst_QRandomGenerator::boundedQuality()
{
// test the quality of the generator
QVector<quint32> buffer(BufferCount, 0xcdcdcdcd);
- generate(buffer.begin(), buffer.end(), [] { return QRandomGenerator::bounded(Bound); });
+ generate(buffer.begin(), buffer.end(), [&] { return rng.bounded(Bound); });
for (quint32 value : qAsConst(buffer)) {
QVERIFY(value < Bound);
@@ -442,24 +649,26 @@ void tst_QRandomGenerator::boundedQuality()
void tst_QRandomGenerator::generateReal()
{
QFETCH(uint, control);
- setRNGControl(control);
+ RandomGenerator rng(control);
for (int i = 0; i < 4; ++i) {
- QVERIFY_3TIMES([] {
- qreal value = QRandomGenerator::generateDouble();
+ QVERIFY_3TIMES([&] {
+ qreal value = rng.generateDouble();
return value >= 0 && value < 1 && value != RandomValueFP;
}());
}
// and should hopefully be different from repeated calls
for (int i = 0; i < 4; ++i)
- QVERIFY_3TIMES(QRandomGenerator::generateDouble() != QRandomGenerator::generateDouble());
+ QVERIFY_3TIMES(rng.generateDouble() != rng.generateDouble());
}
void tst_QRandomGenerator::qualityReal()
{
QFETCH(uint, control);
- setRNGControl(control);
+ if (control & RandomDataMask)
+ return;
+ RandomGenerator rng(control);
enum {
SampleSize = 160,
@@ -475,7 +684,7 @@ void tst_QRandomGenerator::qualityReal()
};
double data[SampleSize];
- std::generate(std::begin(data), std::end(data), &QRandomGenerator::generateDouble);
+ std::generate(std::begin(data), std::end(data), [&rng] { return rng.generateDouble(); });
int aboveHalf = 0;
int belowOneEighth = 0;
@@ -504,12 +713,22 @@ void tst_QRandomGenerator::qualityReal()
template <typename Engine> void seedStdRandomEngine()
{
- QRandomGenerator rd;
- Engine e(rd);
- QVERIFY_3TIMES(e() != 0);
+ {
+ QRandomGenerator &rd = *QRandomGenerator::system();
+ Engine e(rd);
+ QVERIFY_3TIMES(e() != 0);
+
+ e.seed(rd);
+ QVERIFY_3TIMES(e() != 0);
+ }
+ {
+ QRandomGenerator64 &rd = *QRandomGenerator64::system();
+ Engine e(rd);
+ QVERIFY_3TIMES(e() != 0);
- e.seed(rd);
- QVERIFY_3TIMES(e() != 0);
+ e.seed(rd);
+ QVERIFY_3TIMES(e() != 0);
+ }
}
void tst_QRandomGenerator::seedStdRandomEngines()
@@ -534,12 +753,16 @@ void tst_QRandomGenerator::stdUniformIntDistribution_data()
QTest::addColumn<uint>("control");
QTest::addColumn<quint32>("max");
- auto newRow = [](quint32 max) {
- QTest::addRow("default:%u", max) << 0U << max;
- QTest::addRow("system:%u", max) << uint(SkipHWRNG) << max;
- #ifdef HAVE_FALLBACK_ENGINE
- QTest::addRow("fallback:%u", max) << uint(SkipHWRNG | SkipSystemRNG) << max;
- #endif
+ auto newRow = [&](quint32 max) {
+#ifdef QT_BUILD_INTERNAL
+ if (qt_has_hwrng())
+ QTest::addRow("hwrng:%u", max) << uint(UseSystemRNG) << max;
+ QTest::addRow("system:%u", max) << uint(UseSystemRNG | SkipHWRNG) << max;
+# ifdef HAVE_FALLBACK_ENGINE
+ QTest::addRow("system-fallback:%u", max) << uint(UseSystemRNG | SkipHWRNG | SkipSystemRNG) << max;
+# endif
+#endif
+ QTest::addRow("global:%u", max) << 0U << max;
};
// useless: we can only generate zeroes:
@@ -554,7 +777,7 @@ void tst_QRandomGenerator::stdUniformIntDistribution()
{
QFETCH(uint, control);
QFETCH(quint32, max);
- setRNGControl(control & (SkipHWRNG|SkipSystemRNG));
+ RandomGenerator rng(control);
{
QRandomGenerator rd;
@@ -622,21 +845,19 @@ void tst_QRandomGenerator::stdGenerateCanonical()
QSKIP("MSVC 2013's std::generate_canonical is broken");
#else
QFETCH(uint, control);
- setRNGControl(control);
+ RandomGenerator rng(control);
for (int i = 0; i < 4; ++i) {
- QVERIFY_3TIMES([] {
- QRandomGenerator rd;
- qreal value = std::generate_canonical<qreal COMMA 32>(rd);
+ QVERIFY_3TIMES([&] {
+ qreal value = std::generate_canonical<qreal COMMA 32>(rng);
return value > 0 && value < 1 && value != RandomValueFP;
}());
}
// and should hopefully be different from repeated calls
- QRandomGenerator rd;
for (int i = 0; i < 4; ++i)
- QVERIFY_3TIMES(std::generate_canonical<qreal COMMA 32>(rd) !=
- std::generate_canonical<qreal COMMA 32>(rd));
+ QVERIFY_3TIMES(std::generate_canonical<qreal COMMA 32>(rng) !=
+ std::generate_canonical<qreal COMMA 32>(rng));
#endif
}
@@ -650,12 +871,16 @@ void tst_QRandomGenerator::stdUniformRealDistribution_data()
QTest::addColumn<double>("min");
QTest::addColumn<double>("sup");
- auto newRow = [](double min, double sup) {
- QTest::addRow("default:%g-%g", min, sup) << 0U << min << sup;
- QTest::addRow("system:%g-%g", min, sup) << uint(SkipHWRNG) << min << sup;
- #ifdef HAVE_FALLBACK_ENGINE
- QTest::addRow("fallback:%g-%g", min, sup) << uint(SkipHWRNG | SkipSystemRNG) << min << sup;
- #endif
+ auto newRow = [&](double min, double sup) {
+#ifdef QT_BUILD_INTERNAL
+ if (qt_has_hwrng())
+ QTest::addRow("hwrng:%g-%g", min, sup) << uint(UseSystemRNG) << min << sup;
+ QTest::addRow("system:%g-%g", min, sup) << uint(UseSystemRNG | SkipHWRNG) << min << sup;
+# ifdef HAVE_FALLBACK_ENGINE
+ QTest::addRow("system-fallback:%g-%g", min, sup) << uint(UseSystemRNG | SkipHWRNG | SkipSystemRNG) << min << sup;
+# endif
+#endif
+ QTest::addRow("global:%g-%g", min, sup) << 0U << min << sup;
};
newRow(0, 0); // useless: we can only generate zeroes
@@ -671,7 +896,7 @@ void tst_QRandomGenerator::stdUniformRealDistribution()
QFETCH(uint, control);
QFETCH(double, min);
QFETCH(double, sup);
- setRNGControl(control & (SkipHWRNG|SkipSystemRNG));
+ RandomGenerator rng(control & (SkipHWRNG|SkipSystemRNG|UseSystemRNG));
{
QRandomGenerator rd;
@@ -696,13 +921,9 @@ void tst_QRandomGenerator::stdUniformRealDistribution()
}
}
-void tst_QRandomGenerator::stdRandomDistributions()
+template <typename Generator> void stdRandomDistributions_template()
{
- // just a compile check for some of the distributions, besides
- // std::uniform_int_distribution and std::uniform_real_distribution (tested
- // above)
-
- QRandomGenerator rd;
+ Generator rd;
std::bernoulli_distribution()(rd);
@@ -724,6 +945,16 @@ void tst_QRandomGenerator::stdRandomDistributions()
}
}
+void tst_QRandomGenerator::stdRandomDistributions()
+{
+ // just a compile check for some of the distributions, besides
+ // std::uniform_int_distribution and std::uniform_real_distribution (tested
+ // above)
+
+ stdRandomDistributions_template<QRandomGenerator>();
+ stdRandomDistributions_template<QRandomGenerator64>();
+}
+
QTEST_APPLESS_MAIN(tst_QRandomGenerator)
#include "tst_qrandomgenerator.moc"
diff --git a/tests/auto/corelib/io/largefile/tst_largefile.cpp b/tests/auto/corelib/io/largefile/tst_largefile.cpp
index 5975303ca6..2d13e6166d 100644
--- a/tests/auto/corelib/io/largefile/tst_largefile.cpp
+++ b/tests/auto/corelib/io/largefile/tst_largefile.cpp
@@ -31,6 +31,7 @@
#include <QtAlgorithms>
#include <QFile>
#include <QFileInfo>
+#include <QRandomGenerator>
#include <qplatformdefs.h>
#include <QDebug>
@@ -174,8 +175,7 @@ static inline QByteArray generateDataBlock(int blockSize, QString text, qint64 u
static qint64 counter = 0;
- qint64 randomBits = ((qint64)qrand() << 32)
- | ((qint64)qrand() & 0x00000000ffffffff);
+ qint64 randomBits = QRandomGenerator::global()->generate64();
appendRaw(block, randomBits);
appendRaw(block, userBits);
diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp
index 372bca6ffd..06c3a9578f 100644
--- a/tests/auto/corelib/io/qfile/tst_qfile.cpp
+++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp
@@ -107,6 +107,30 @@ QT_END_NAMESPACE
Q_DECLARE_METATYPE(QFile::FileError)
+
+class StdioFileGuard
+{
+ Q_DISABLE_COPY(StdioFileGuard)
+public:
+ explicit StdioFileGuard(FILE *f = nullptr) : m_file(f) {}
+ ~StdioFileGuard() { close(); }
+
+ operator FILE *() const { return m_file; }
+
+ void close();
+
+private:
+ FILE * m_file;
+};
+
+void StdioFileGuard::close()
+{
+ if (m_file != nullptr) {
+ fclose(m_file);
+ m_file = nullptr;
+ }
+}
+
class tst_QFile : public QObject
{
Q_OBJECT
@@ -379,6 +403,8 @@ void tst_QFile::cleanup()
QDir remainingDir(absoluteFilePath);
QVERIFY2(remainingDir.removeRecursively(), qPrintable(absoluteFilePath));
} else {
+ if (!(QFile::permissions(absoluteFilePath) & QFile::WriteUser))
+ QVERIFY2(QFile::setPermissions(absoluteFilePath, QFile::WriteUser), qPrintable(absoluteFilePath));
QVERIFY2(QFile::remove(absoluteFilePath), qPrintable(absoluteFilePath));
}
}
@@ -417,8 +443,6 @@ void tst_QFile::initTestCase()
m_stdinProcessDir = QFINDTESTDATA("stdinprocess");
QVERIFY(!m_stdinProcessDir.isEmpty());
#endif
- m_testSourceFile = QFINDTESTDATA("tst_qfile.cpp");
- QVERIFY(!m_testSourceFile.isEmpty());
m_testLogFile = QFINDTESTDATA("testlog.txt");
QVERIFY(!m_testLogFile.isEmpty());
m_dosFile = QFINDTESTDATA("dosfile.txt");
@@ -431,15 +455,19 @@ void tst_QFile::initTestCase()
QVERIFY(!m_twoDotsFile.isEmpty());
#ifndef BUILTIN_TESTDATA
+ m_testSourceFile = QFINDTESTDATA("tst_qfile.cpp");
+ QVERIFY(!m_testSourceFile.isEmpty());
m_testFile = QFINDTESTDATA("testfile.txt");
QVERIFY(!m_testFile.isEmpty());
+ m_resourcesDir = QFINDTESTDATA("resources");
+ QVERIFY(!m_resourcesDir.isEmpty());
#else
m_dataDir = QEXTRACTTESTDATA("/");
QVERIFY2(!m_dataDir.isNull(), qPrintable("Could not extract test data"));
m_testFile = m_dataDir->path() + "/testfile.txt";
+ m_testSourceFile = m_dataDir->path() + "/tst_qfile.cpp";
+ m_resourcesDir = m_dataDir->path() + "/resources";
#endif
- m_resourcesDir = QFINDTESTDATA("resources");
- QVERIFY(!m_resourcesDir.isEmpty());
m_noEndOfLineFile = QFINDTESTDATA("noendofline.txt");
QVERIFY(!m_noEndOfLineFile.isEmpty());
@@ -658,14 +686,13 @@ void tst_QFile::size()
}
{
- QFile f;
- FILE* stream = QT_FOPEN(filename.toLocal8Bit().constData(), "rb");
+ StdioFileGuard stream(QT_FOPEN(filename.toLocal8Bit().constData(), "rb"));
QVERIFY( stream );
+ QFile f;
QVERIFY( f.open(stream, QIODevice::ReadOnly) );
QCOMPARE( f.size(), size );
f.close();
- fclose(stream);
}
{
@@ -1590,12 +1617,34 @@ void tst_QFile::writeTextFile()
}
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
+// Helper for executing QFile::open() with warning in QTRY_VERIFY(), which evaluates the condition
+// multiple times
+static bool qFileOpen(QFile &file, QIODevice::OpenMode ioFlags)
+{
+ const bool result = file.isOpen() || file.open(ioFlags);
+ if (!result)
+ qWarning() << "Cannot open" << file.fileName() << ':' << file.errorString();
+ return result;
+}
+
+// Helper for executing fopen() with warning in QTRY_VERIFY(), which evaluates the condition
+// multiple times
+static bool fOpen(const QByteArray &fileName, const char *mode, FILE **file)
+{
+ if (*file == nullptr)
+ *file = fopen(fileName.constData(), mode);
+ if (*file == nullptr)
+ qWarning("Cannot open %s: %s", fileName.constData(), strerror(errno));
+ return *file != nullptr;
+}
+
void tst_QFile::largeUncFileSupport()
{
qint64 size = Q_INT64_C(8589934592);
qint64 dataOffset = Q_INT64_C(8589914592);
QByteArray knownData("LargeFile content at offset 8589914592");
QString largeFile("//" + QtNetworkSettings::winServerName() + "/testsharelargefile/file.bin");
+ const QByteArray largeFileEncoded = QFile::encodeName(largeFile);
{
// 1) Native file handling.
@@ -1603,31 +1652,36 @@ void tst_QFile::largeUncFileSupport()
QVERIFY2(file.exists(), msgFileDoesNotExist(largeFile));
QCOMPARE(file.size(), size);
- QVERIFY2(file.open(QIODevice::ReadOnly), msgOpenFailed(file).constData());
+ // Retry in case of sharing violation
+ QTRY_VERIFY2(qFileOpen(file, QIODevice::ReadOnly), msgOpenFailed(file).constData());
QCOMPARE(file.size(), size);
QVERIFY(file.seek(dataOffset));
QCOMPARE(file.read(knownData.size()), knownData);
}
{
// 2) stdlib file handling.
+ FILE *fhF = nullptr;
+ // Retry in case of sharing violation
+ QTRY_VERIFY(fOpen(largeFileEncoded, "rb", &fhF));
+ StdioFileGuard fh(fhF);
QFile file;
- FILE *fh = fopen(QFile::encodeName(largeFile).data(), "rb");
QVERIFY(file.open(fh, QIODevice::ReadOnly));
QCOMPARE(file.size(), size);
QVERIFY(file.seek(dataOffset));
QCOMPARE(file.read(knownData.size()), knownData);
- fclose(fh);
}
{
// 3) stdio file handling.
- QFile file;
- FILE *fh = fopen(QFile::encodeName(largeFile).data(), "rb");
+ FILE *fhF = nullptr;
+ // Retry in case of sharing violation
+ QTRY_VERIFY(fOpen(largeFileEncoded, "rb", &fhF));
+ StdioFileGuard fh(fhF);
int fd = int(_fileno(fh));
+ QFile file;
QVERIFY(file.open(fd, QIODevice::ReadOnly));
QCOMPARE(file.size(), size);
QVERIFY(file.seek(dataOffset));
QCOMPARE(file.read(knownData.size()), knownData);
- fclose(fh);
}
}
#endif
@@ -1668,7 +1722,7 @@ void tst_QFile::bufferedRead()
file.write("abcdef");
file.close();
- FILE *stdFile = fopen("stdfile.txt", "r");
+ StdioFileGuard stdFile(fopen("stdfile.txt", "r"));
QVERIFY(stdFile);
char c;
QCOMPARE(int(fread(&c, 1, 1, stdFile)), 1);
@@ -1683,8 +1737,6 @@ void tst_QFile::bufferedRead()
QCOMPARE(c, 'b');
QCOMPARE(file.pos(), qlonglong(2));
}
-
- fclose(stdFile);
}
#ifdef Q_OS_UNIX
@@ -1813,7 +1865,7 @@ void tst_QFile::FILEReadWrite()
f.close();
}
- FILE *fp = fopen("FILEReadWrite.txt", "r+b");
+ StdioFileGuard fp(fopen("FILEReadWrite.txt", "r+b"));
QVERIFY(fp);
QFile file;
QVERIFY2(file.open(fp, QFile::ReadWrite), msgOpenFailed(file).constData());
@@ -1848,7 +1900,7 @@ void tst_QFile::FILEReadWrite()
}
file.close();
- fclose(fp);
+ fp.close();
// check modified file
{
@@ -2135,12 +2187,20 @@ public:
if (fileName.startsWith(":!")) {
QDir dir;
- QString realFile = QFINDTESTDATA(fileName.mid(2));
+#ifndef BUILTIN_TESTDATA
+ const QString realFile = QFINDTESTDATA(fileName.mid(2));
+#else
+ const QString realFile = m_dataDir->filePath(fileName.mid(2));
+#endif
if (dir.exists(realFile))
return new QFSFileEngine(realFile);
}
return 0;
}
+
+#ifdef BUILTIN_TESTDATA
+ QSharedPointer<QTemporaryDir> m_dataDir;
+#endif
};
#endif
@@ -2149,6 +2209,9 @@ void tst_QFile::useQFileInAFileHandler()
{
// This test should not dead-lock
MyRecursiveHandler handler;
+#ifdef BUILTIN_TESTDATA
+ handler.m_dataDir = m_dataDir;
+#endif
QFile file(":!tst_qfile.cpp");
QVERIFY(file.exists());
}
@@ -2430,11 +2493,10 @@ void tst_QFile::virtualFile()
void tst_QFile::textFile()
{
-#if defined(Q_OS_WIN)
- FILE *fs = ::fopen("writeabletextfile", "wt");
-#else
- FILE *fs = ::fopen("writeabletextfile", "w");
-#endif
+ const char *openMode = QOperatingSystemVersion::current().type() != QOperatingSystemVersion::Windows
+ ? "w" : "wt";
+ StdioFileGuard fs(fopen("writeabletextfile", openMode));
+ QVERIFY(fs);
QFile f;
QByteArray part1("This\nis\na\nfile\nwith\nnewlines\n");
QByteArray part2("Add\nsome\nmore\nnewlines\n");
@@ -2443,7 +2505,7 @@ void tst_QFile::textFile()
f.write(part1);
f.write(part2);
f.close();
- ::fclose(fs);
+ fs.close();
QFile file("writeabletextfile");
QVERIFY2(file.open(QIODevice::ReadOnly), msgOpenFailed(file).constData());
@@ -2699,11 +2761,12 @@ void tst_QFile::handle()
//test round trip of adopted stdio file handle
QFile file2;
- FILE *fp = fopen(qPrintable(m_testSourceFile), "r");
+ StdioFileGuard fp(fopen(qPrintable(m_testSourceFile), "r"));
+ QVERIFY(fp);
file2.open(fp, QIODevice::ReadOnly);
QCOMPARE(int(file2.handle()), int(fileno(fp)));
QCOMPARE(int(file2.handle()), int(fileno(fp)));
- fclose(fp);
+ fp.close();
//test round trip of adopted posix file handle
#ifdef Q_OS_UNIX
diff --git a/tests/auto/corelib/io/qfileselector/platforms/+qnx/test b/tests/auto/corelib/io/qfileselector/platforms/+qnx/test
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/platforms/+qnx/test
diff --git a/tests/auto/corelib/io/qfileselector/platforms/+qnx/test2 b/tests/auto/corelib/io/qfileselector/platforms/+qnx/test2
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/platforms/+qnx/test2
diff --git a/tests/auto/corelib/io/qfileselector/platforms/+unix/+qnx/test b/tests/auto/corelib/io/qfileselector/platforms/+unix/+qnx/test
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/platforms/+unix/+qnx/test
diff --git a/tests/auto/corelib/io/qfileselector/qfileselector.qrc b/tests/auto/corelib/io/qfileselector/qfileselector.qrc
index ea9b8270e0..54b2e0a0e2 100644
--- a/tests/auto/corelib/io/qfileselector/qfileselector.qrc
+++ b/tests/auto/corelib/io/qfileselector/qfileselector.qrc
@@ -21,6 +21,7 @@
<file>platforms/+unix/+darwin/test</file>
<file>platforms/+unix/+haiku/test</file>
<file>platforms/+unix/+linux/test</file>
+ <file>platforms/+unix/+qnx/test</file>
<file>platforms/+unix/test</file>
<file>platforms/+windows/+wince/test</file>
<file>platforms/+windows/+winnt/test</file>
@@ -34,6 +35,7 @@
<file>platforms/+mac/test</file>
<file>platforms/+haiku/test</file>
<file>platforms/+linux/test</file>
+ <file>platforms/+qnx/test</file>
<file>platforms/+wince/test</file>
<file>platforms/+winrt/test</file>
@@ -44,6 +46,7 @@
<file>platforms/+macos/test2</file>
<file>platforms/+haiku/test2</file>
<file>platforms/+linux/test2</file>
+ <file>platforms/+qnx/test2</file>
<file>platforms/+wince/test2</file>
<file>platforms/+winnt/test2</file>
<file>platforms/+winrt/test2</file>
diff --git a/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp b/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp
index c537e43802..c9f1e3d9f6 100644
--- a/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp
+++ b/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp
@@ -86,7 +86,7 @@ void tst_QFileSelector::basicTest_data()
QString expectedPlatform2File(""); //Only the last selector
QString expectedPlatform3File; // Only the first selector (the family)
#if defined(Q_OS_UNIX) && !defined(Q_OS_ANDROID) && \
- !defined(Q_OS_DARWIN) && !defined(Q_OS_LINUX) && !defined(Q_OS_HAIKU)
+ !defined(Q_OS_DARWIN) && !defined(Q_OS_LINUX) && !defined(Q_OS_HAIKU) && !defined(Q_OS_QNX)
/* We are only aware of specific unixes, and do not have test files for any of the others.
However those unixes can get a selector added from the result of a uname call, so this will
lead to a case where we don't have that file so we can't expect the concatenation of platform
diff --git a/tests/auto/corelib/io/qstandardpaths/BLACKLIST b/tests/auto/corelib/io/qstandardpaths/BLACKLIST
new file mode 100644
index 0000000000..d5ee9650cd
--- /dev/null
+++ b/tests/auto/corelib/io/qstandardpaths/BLACKLIST
@@ -0,0 +1,3 @@
+[testFindExecutable]
+# QTBUG-64404
+b2qt 64bit
diff --git a/tests/auto/corelib/io/qtemporarydir/qtemporarydir.pro b/tests/auto/corelib/io/qtemporarydir/qtemporarydir.pro
index 351e263093..5908648378 100644
--- a/tests/auto/corelib/io/qtemporarydir/qtemporarydir.pro
+++ b/tests/auto/corelib/io/qtemporarydir/qtemporarydir.pro
@@ -4,4 +4,4 @@ SOURCES += tst_qtemporarydir.cpp
INCLUDEPATH += ../../../../shared/
HEADERS += ../../../../shared/emulationdetector.h
-QT = core testlib
+QT = core testlib testlib-private
diff --git a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp
index fcd9133099..76462be376 100644
--- a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp
+++ b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp
@@ -35,6 +35,7 @@
#include <qdir.h>
#include <qset.h>
#include <qtextcodec.h>
+#include <QtTest/private/qtesthelpers_p.h>
#ifdef Q_OS_WIN
# include <windows.h>
#endif
@@ -112,16 +113,6 @@ void tst_QTemporaryDir::getSetCheck()
QCOMPARE(true, obj1.autoRemove());
}
-static inline bool canHandleUnicodeFileNames()
-{
-#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
- return true;
-#else
- // Check for UTF-8 by converting the Euro symbol (see tst_utf8)
- return QFile::encodeName(QString(QChar(0x20AC))) == QByteArrayLiteral("\342\202\254");
-#endif
-}
-
static QString hanTestText()
{
QString text;
@@ -159,7 +150,7 @@ void tst_QTemporaryDir::fileTemplate_data()
QTest::newRow("4Xsuffix") << "qt_XXXXXX_XXXX" << "qt_" << "_XXXX";
QTest::newRow("4Xprefix") << "qt_XXXX" << "qt_XXXX" << "";
QTest::newRow("5Xprefix") << "qt_XXXXX" << "qt_XXXXX" << "";
- if (canHandleUnicodeFileNames()) {
+ if (QTestPrivate::canHandleUnicodeFileNames()) {
// Test Umlauts (contained in Latin1)
QString prefix = "qt_" + umlautTestText();
QTest::newRow("Umlauts") << (prefix + "XXXXXX") << prefix << "";
diff --git a/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro b/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro
index a89e5c66ff..e17cb05cd8 100644
--- a/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro
+++ b/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro
@@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qtemporaryfile
-QT = core testlib
+QT = core testlib testlib-private
SOURCES = tst_qtemporaryfile.cpp
TESTDATA += tst_qtemporaryfile.cpp
RESOURCES += qtemporaryfile.qrc
diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
index 11c24ca86f..f3ce902bbd 100644
--- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
+++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
@@ -38,6 +38,8 @@
#include <qset.h>
#include <qtextcodec.h>
+#include <QtTest/private/qtesthelpers_p.h>
+
#if defined(Q_OS_WIN)
# include <windows.h>
#endif
@@ -143,16 +145,6 @@ void tst_QTemporaryFile::getSetCheck()
QCOMPARE(true, obj1.autoRemove());
}
-static inline bool canHandleUnicodeFileNames()
-{
-#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
- return true;
-#else
- // Check for UTF-8 by converting the Euro symbol (see tst_utf8)
- return QFile::encodeName(QString(QChar(0x20AC))) == QByteArrayLiteral("\342\202\254");
-#endif
-}
-
static QString hanTestText()
{
QString text;
@@ -201,7 +193,7 @@ void tst_QTemporaryFile::fileTemplate_data()
QTest::newRow("set template, with xxx") << "" << "qt_" << ".xxx" << "qt_XXXXXX.xxx";
QTest::newRow("set template, with >6 X's") << "" << "qt_" << ".xxx" << "qt_XXXXXXXXXXXXXX.xxx";
QTest::newRow("set template, with >6 X's, no suffix") << "" << "qt_" << "" << "qt_XXXXXXXXXXXXXX";
- if (canHandleUnicodeFileNames()) {
+ if (QTestPrivate::canHandleUnicodeFileNames()) {
// Test Umlauts (contained in Latin1)
QString prefix = "qt_" + umlautTestText();
QTest::newRow("Umlauts") << (prefix + "XXXXXX") << prefix << QString() << QString();
@@ -824,7 +816,7 @@ void tst_QTemporaryFile::QTBUG_4796_data()
QTest::newRow("XXXXXXbla") << QString() << QString("bla") << true;
QTest::newRow("does-not-exist/qt_temp.XXXXXX") << QString("does-not-exist/qt_temp") << QString() << false;
- if (canHandleUnicodeFileNames()) {
+ if (QTestPrivate::canHandleUnicodeFileNames()) {
QTest::newRow("XXXXXX<unicode>") << QString() << unicode << true;
QTest::newRow("<unicode>XXXXXX") << unicode << QString() << true;
QTest::newRow("<unicode>XXXXXX<unicode>") << unicode << unicode << true;
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp
index 400a89c03f..20282068cb 100644
--- a/tests/auto/corelib/io/qurl/tst_qurl.cpp
+++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp
@@ -2063,6 +2063,11 @@ void tst_QUrl::isValid()
QVERIFY(!url.isValid());
QVERIFY(url.toString().isEmpty());
QVERIFY(url.errorString().contains("Path component starts with '//' and authority is absent"));
+
+ // should disappear if we set a port
+ url.setPort(80);
+ QVERIFY(url.isValid());
+ QCOMPARE(url.toString(), QString("http://:80//example.com"));
}
{
@@ -2071,6 +2076,13 @@ void tst_QUrl::isValid()
QVERIFY(!url.isValid());
QVERIFY(url.toString().isEmpty());
QVERIFY(url.errorString().contains("':' before any '/'"));
+
+ // this specific error disappears if we set anything in the authority,
+ // but then we run into another error
+ url.setPort(80);
+ QVERIFY(!url.isValid());
+ QVERIFY(url.toString().isEmpty());
+ QVERIFY(url.errorString().contains("Path component is relative and authority is present"));
}
{
@@ -2810,6 +2822,29 @@ void tst_QUrl::setPort()
QCOMPARE(url.port(), -1);
QVERIFY(url.errorString().contains("out of range"));
}
+
+ {
+ QUrl reference("//:80");
+ QUrl piecewise;
+ piecewise.setPort(80);
+ QCOMPARE(piecewise, reference);
+ }
+
+ {
+ // setAuthority must clear the port
+ QUrl url("http://example.com:80");
+ url.setAuthority("example.org");
+ QCOMPARE(url.port(), -1);
+ QCOMPARE(url.toString(), QString("http://example.org"));
+ }
+
+ {
+ // setAuthority must clear the port
+ QUrl url("http://example.com:80");
+ url.setAuthority(QString());
+ QCOMPARE(url.port(), -1);
+ QCOMPARE(url.toString(), QString("http:"));
+ }
}
void tst_QUrl::port_data()
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
index a3f3550307..f6feac29dc 100644
--- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
+++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
@@ -2362,8 +2362,8 @@ void tst_QObject::testUserData()
// Randomize the table a bit
for (int i=0; i<100; ++i) {
- int p1 = rand() % USER_DATA_COUNT;
- int p2 = rand() % USER_DATA_COUNT;
+ int p1 = QRandomGenerator::global()->bounded(USER_DATA_COUNT);
+ int p2 = QRandomGenerator::global()->bounded(USER_DATA_COUNT);
int tmp = user_data_ids[p1];
user_data_ids[p1] = user_data_ids[p2];
diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp
index 8a46bc1c55..8883b6360f 100644
--- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp
+++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp
@@ -115,7 +115,6 @@ Q_CONSTRUCTOR_FUNCTION(initializeLang)
static QString seedAndTemplate()
{
- qsrand(QDateTime::currentSecsSinceEpoch());
return QDir::tempPath() + "/tst_qmimedatabase-XXXXXX";
}
diff --git a/tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp b/tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp
index daf9b1579a..d1e138d8eb 100644
--- a/tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp
+++ b/tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp
@@ -35,9 +35,6 @@ int main(int argc, char **argv)
Q_UNUSED(argc)
Q_UNUSED(argv)
- // First, break QUuid.
- qrand();
-
// Now print a few uuids.
printf("%s", qPrintable(QUuid::createUuid().toString()));
printf("%s", qPrintable(QUuid::createUuid().toString()));
diff --git a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp
index 408a90afc4..d4a3ee6054 100644
--- a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp
+++ b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp
@@ -36,6 +36,7 @@
#include <qresultstore.h>
#include <qthreadpool.h>
#include <qexception.h>
+#include <qrandom.h>
#include <private/qfutureinterface_p.h>
// COM interface macro.
@@ -1456,7 +1457,7 @@ void tst_QFuture::nonGlobalThreadPool()
void run() override
{
- const int ms = 100 + (qrand() % 100 - 100/2);
+ const int ms = 100 + (QRandomGenerator::global()->bounded(100) - 100/2);
QThread::msleep(ms);
reportResult(Answer);
reportFinished();
diff --git a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp
index e13c2894af..72299402f0 100644
--- a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp
+++ b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp
@@ -37,6 +37,7 @@
#include <qalgorithms.h>
#include <QStringList>
#include <QString>
+#include <QRandomGenerator>
#include <QVector>
#define Q_TEST_PERFORMANCE 0
@@ -133,7 +134,7 @@ QVector<DataType> generateData(QString dataSetType, const int length)
QVector<DataType> container;
if (dataSetType == "Random") {
for (int i = 0; i < length; ++i)
- container.append(rand());
+ container.append(QRandomGenerator::global()->generate());
} else if (dataSetType == "Ascending") {
for (int i = 0; i < length; ++i)
container.append(i);
@@ -1082,12 +1083,12 @@ void tst_QAlgorithms::popCount_data_impl(size_t sizeof_T_Int)
// and some random ones:
if (sizeof_T_Int >= 8)
for (size_t i = 0; i < 1000; ++i) {
- const quint64 input = quint64(qrand()) << 32 | quint32(qrand());
+ const quint64 input = QRandomGenerator::global()->generate64();
QTest::addRow("0x%016llx", input) << input << bitsSetInInt64(input);
}
else if (sizeof_T_Int >= 2)
for (size_t i = 0; i < 1000 ; ++i) {
- const quint32 input = qrand();
+ const quint32 input = QRandomGenerator::global()->generate();
if (sizeof_T_Int >= 4)
QTest::addRow("0x%08x", input) << quint64(input) << bitsSetInInt(input);
else
@@ -1129,7 +1130,7 @@ void tst_QAlgorithms::countTrailing_data_impl(size_t sizeof_T_Int)
// and some random ones:
for (uint i = 0; i < sizeof_T_Int*8; ++i) {
for (uint j = 0; j < sizeof_T_Int*3; ++j) { // 3 is arbitrary
- const quint64 r = quint64(qrand()) << 32 | quint32(qrand());
+ const quint64 r = QRandomGenerator::global()->generate64();
const quint64 b = Q_UINT64_C(1) << i;
const quint64 mask = ((~(b-1)) ^ b) & type_mask;
const quint64 input = (r&mask) | b;
@@ -1166,7 +1167,7 @@ void tst_QAlgorithms::countLeading_data_impl(size_t sizeof_T_Int)
// and some random ones:
for (uint i = 0; i < sizeof_T_Int*8; ++i) {
for (uint j = 0; j < sizeof_T_Int*3; ++j) { // 3 is arbitrary
- const quint64 r = quint64(qrand()) << 32 | quint32(qrand());
+ const quint64 r = QRandomGenerator::global()->generate64();
const quint64 b = Q_UINT64_C(1) << i;
const quint64 mask = b-1;
const quint64 input = (r&mask) | b;
diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
index c684af5418..203d9d8683 100644
--- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
@@ -1898,7 +1898,7 @@ class StrongThread: public QThread
protected:
void run()
{
- usleep(rand() % 2000);
+ usleep(QRandomGenerator::global()->bounded(2000));
ptr->ref();
ptr.clear();
}
@@ -1911,7 +1911,7 @@ class WeakThread: public QThread
protected:
void run()
{
- usleep(rand() % 2000);
+ usleep(QRandomGenerator::global()->bounded(2000));
QSharedPointer<ThreadData> ptr = weak;
if (ptr)
ptr->ref();
@@ -1973,7 +1973,6 @@ void tst_QSharedPointer::threadStressTest()
base.clear();
- srand(time(NULL));
// start threads
for (int i = 0; i < allThreads.count(); ++i)
if (allThreads[i]) allThreads[i]->start();
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp
index 235d53f3c1..54eb8ab99c 100644
--- a/tests/auto/gui/image/qimage/tst_qimage.cpp
+++ b/tests/auto/gui/image/qimage/tst_qimage.cpp
@@ -33,6 +33,7 @@
#include <qimagereader.h>
#include <qlist.h>
#include <qmatrix.h>
+#include <qrandom.h>
#include <stdio.h>
#include <qpainter.h>
@@ -1754,7 +1755,7 @@ void tst_QImage::smoothScale2()
static inline int rand8()
{
- return int(256. * (qrand() / (RAND_MAX + 1.0)));
+ return QRandomGenerator::global()->bounded(256);
}
void tst_QImage::smoothScale3_data()
diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
index c0f5fc5f59..5fe17ebb68 100644
--- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
+++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
@@ -45,6 +45,7 @@
#include <qdesktopwidget.h>
#endif
#include <qpixmap.h>
+#include <qrandom.h>
#include <private/qdrawhelper_p.h>
#include <qpainter.h>
@@ -3052,7 +3053,7 @@ void tst_QPainter::fpe_steepSlopes_data()
qreal randf()
{
- return rand() / (RAND_MAX + 1.0);
+ return QRandomGenerator::global()->bounded(1.0);
}
QPointF randInRect(const QRectF &rect)
diff --git a/tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp b/tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp
index 14ba9c5c84..93035af7d3 100644
--- a/tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp
+++ b/tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp
@@ -35,6 +35,7 @@
#include <qpolygon.h>
#include <qdebug.h>
#include <qpainter.h>
+#include <qrandom.h>
#include <math.h>
@@ -423,8 +424,8 @@ void tst_QPathClipper::clip()
static inline QPointF randomPointInRect(const QRectF &rect)
{
- qreal rx = qrand() / (RAND_MAX + 1.);
- qreal ry = qrand() / (RAND_MAX + 1.);
+ qreal rx = QRandomGenerator::global()->bounded(1.0);
+ qreal ry = QRandomGenerator::global()->bounded(1.0);
return QPointF(rect.left() + rx * rect.width(),
rect.top() + ry * rect.height());
diff --git a/tests/auto/gui/text/qtextpiecetable/tst_qtextpiecetable.cpp b/tests/auto/gui/text/qtextpiecetable/tst_qtextpiecetable.cpp
index ca01e83dbe..39f5e9ecc3 100644
--- a/tests/auto/gui/text/qtextpiecetable/tst_qtextpiecetable.cpp
+++ b/tests/auto/gui/text/qtextpiecetable/tst_qtextpiecetable.cpp
@@ -145,7 +145,7 @@ void tst_QTextPieceTable::insertion3()
{
QString compare;
for (int i = 0; i < 20000; ++i) {
- int pos = rand() % (i+1);
+ int pos = QRandomGenerator::global()->bounded(i+1);
QChar c((unsigned short)(i & 0xff) + 1);
QString str;
str += c;
@@ -159,7 +159,7 @@ void tst_QTextPieceTable::insertion4()
{
QString compare;
for (int i = 0; i < 20000; ++i) {
- int pos = rand() % (i+1);
+ int pos = QRandomGenerator::global()->generate() % (i+1);
QChar c((unsigned short)((i % 26) + (i>25?'A':'a')));
QString str;
str += c;
@@ -178,7 +178,7 @@ void tst_QTextPieceTable::insertion5()
{
QString compare;
for (int i = 0; i < 20000; ++i) {
- int pos = rand() % (i+1);
+ int pos = QRandomGenerator::global()->generate() % (i+1);
QChar c((unsigned short)((i % 26) + (i>25?'A':'a')));
QString str;
str += c;
@@ -236,8 +236,8 @@ void tst_QTextPieceTable::removal3()
QString compare;
int l = 0;
for (int i = 0; i < 20000; ++i) {
- bool remove = l && (rand() % 2);
- int pos = rand() % (remove ? l : (l+1));
+ bool remove = l && (QRandomGenerator::global()->bounded(2));
+ int pos = QRandomGenerator::global()->bounded(remove ? l : (l+1));
QChar c((unsigned short)((i % 26) + (i>25?'A':'a')));
QString str;
str += c;
@@ -263,8 +263,8 @@ void tst_QTextPieceTable::removal4()
QString compare;
int l = 0;
for (int i = 0; i < 20000; ++i) {
- bool remove = l && (rand() % 2);
- int pos = (l > 1) ? rand() % (remove ? l-1 : l) : 0;
+ bool remove = l && (QRandomGenerator::global()->bounded(2));
+ int pos = (l > 1) ? QRandomGenerator::global()->bounded(remove ? l-1 : l) : 0;
QChar c((unsigned short)((i % 26) + (i>25?'A':'a')));
QString str;
if (c != 'a') {
@@ -472,13 +472,12 @@ void tst_QTextPieceTable::undoRedo10()
void tst_QTextPieceTable::undoRedo11()
{
- srand(3);
const int loops = 20;
QString compare;
int l = 0;
for (int i = 0; i < loops; ++i) {
- bool remove = l && (rand() % 2);
- int pos = (l > 1) ? rand() % (remove ? l-1 : l) : 0;
+ bool remove = l && (QRandomGenerator::global()->bounded(2));
+ int pos = (l > 1) ? QRandomGenerator::global()->bounded(remove ? l-1 : l) : 0;
QChar c((unsigned short)((i % 26) + (i>25?'A':'a')));
QString str;
str += c;
diff --git a/tests/auto/network/access/hpack/tst_hpack.cpp b/tests/auto/network/access/hpack/tst_hpack.cpp
index bd337c9f5f..810745a065 100644
--- a/tests/auto/network/access/hpack/tst_hpack.cpp
+++ b/tests/auto/network/access/hpack/tst_hpack.cpp
@@ -273,13 +273,13 @@ void tst_Hpack::bitstreamCompression()
std::vector<uchar> buffer;
BitOStream out(buffer);
for (unsigned i = 0; i < nValues; ++i) {
- const bool isString = std::rand() % 1000 > 500;
+ const bool isString = QRandomGenerator::global()->bounded(1000) > 500;
isA.push_back(isString);
if (!isString) {
- integers.push_back(std::rand() % 1000);
+ integers.push_back(QRandomGenerator::global()->bounded(1000u));
out.write(integers.back());
} else {
- const auto start = std::rand() % (bytes.length() / 2);
+ const auto start = QRandomGenerator::global()->bounded(uint(bytes.length()) / 2);
auto end = start * 2;
if (!end)
end = bytes.length() / 2;
@@ -287,7 +287,7 @@ void tst_Hpack::bitstreamCompression()
const auto &s = strings.back();
totalStringBytes += s.size();
QByteArray data(s.c_str(), int(s.size()));
- const bool compressed(std::rand() % 1000 > 500);
+ const bool compressed(QRandomGenerator::global()->bounded(1000) > 500);
out.write(data, compressed);
}
}
@@ -442,8 +442,8 @@ void tst_Hpack::lookupTableDynamic()
// Strings are repeating way too often, I want to
// have at least some items really evicted and not found,
// therefore these weird dances with start/len.
- const quint32 start = std::rand() % (dataSize - 10);
- quint32 len = std::rand() % (dataSize - start);
+ const quint32 start = QRandomGenerator::global()->bounded(dataSize - 10);
+ quint32 len = QRandomGenerator::global()->bounded(dataSize - start);
if (!len)
len = 1;
diff --git a/tests/auto/network/access/http2/tst_http2.cpp b/tests/auto/network/access/http2/tst_http2.cpp
index 7b453ca635..51e1849512 100644
--- a/tests/auto/network/access/http2/tst_http2.cpp
+++ b/tests/auto/network/access/http2/tst_http2.cpp
@@ -224,7 +224,7 @@ void tst_Http2::multipleRequests()
};
for (int i = 0; i < nRequests; ++i)
- sendRequest(i, priorities[std::rand() % 3]);
+ sendRequest(i, priorities[QRandomGenerator::global()->bounded(3)]);
runEventLoop();
diff --git a/tests/auto/network/access/qftp/tst_qftp.cpp b/tests/auto/network/access/qftp/tst_qftp.cpp
index fba0508f04..4bc43f068c 100644
--- a/tests/auto/network/access/qftp/tst_qftp.cpp
+++ b/tests/auto/network/access/qftp/tst_qftp.cpp
@@ -276,8 +276,7 @@ void tst_QFtp::init()
inFileDirExistsFunction = false;
- srand(time(0));
- uniqueExtension = QString::number((quintptr)this) + QString::number(rand())
+ uniqueExtension = QString::number((quintptr)this) + QString::number(QRandomGenerator::global()->generate())
+ QString::number((qulonglong)time(0));
}
diff --git a/tests/auto/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp b/tests/auto/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp
index e996347a9a..856033fb63 100644
--- a/tests/auto/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp
+++ b/tests/auto/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp
@@ -30,6 +30,7 @@
#include <QtTest/QtTest>
#include <QtNetwork/QtNetwork>
#include <qnetworkdiskcache.h>
+#include <qrandom.h>
#include <algorithm>
@@ -693,25 +694,25 @@ public:
if (write) {
QNetworkCacheMetaData m;
- if (qrand() % 2 == 0)
+ if (QRandomGenerator::global()->bounded(2) == 0)
m = metaData;
else
m = metaData2;
- if (qrand() % 20 == 1) {
+ if (QRandomGenerator::global()->bounded(20) == 1) {
//qDebug() << "write update";
cache.updateMetaData(m);
continue;
}
QIODevice *device = cache.prepare(m);
- if (qrand() % 20 == 1) {
+ if (QRandomGenerator::global()->bounded(20) == 1) {
//qDebug() << "write remove";
cache.remove(url);
continue;
}
QVERIFY(device);
- if (qrand() % 2 == 0)
+ if (QRandomGenerator::global()->bounded(2) == 0)
device->write(longString);
else
device->write(longString2);
@@ -740,9 +741,9 @@ public:
delete d;
}
}
- if (qrand() % 5 == 1)
+ if (QRandomGenerator::global()->bounded(5) == 1)
cache.remove(url);
- if (qrand() % 5 == 1)
+ if (QRandomGenerator::global()->bounded(5) == 1)
cache.clear();
sleep(0);
}
@@ -791,7 +792,6 @@ void tst_QNetworkDiskCache::sync()
return;
QTime midnight(0, 0, 0);
- qsrand(midnight.secsTo(QTime::currentTime()));
Runner reader(tempDir.path());
reader.dt = QDateTime::currentDateTime();
reader.write = false;
diff --git a/tests/auto/network/access/qnetworkreply/BLACKLIST b/tests/auto/network/access/qnetworkreply/BLACKLIST
index 1d56c78bbc..d6fc717e37 100644
--- a/tests/auto/network/access/qnetworkreply/BLACKLIST
+++ b/tests/auto/network/access/qnetworkreply/BLACKLIST
@@ -1,5 +1,7 @@
# See qtbase/src/testlib/qtestblacklist.cpp for format
osx
+[authenticationCacheAfterCancel]
+windows
[ioGetFromBuiltinHttp:http+limited]
ubuntu-14.04
[ioGetFromBuiltinHttp:https+limited]
@@ -8,3 +10,33 @@ ubuntu-14.04
*
[backgroundRequestInterruption:ftp, bg, nobg]
*
+[getErrors:ftp-host]
+linux
+[getFromHttpIntoBuffer]
+windows
+[getFromHttpIntoBuffer2]
+windows
+[headFromHttp]
+windows
+[ioGetFromHttpWithSocksProxy]
+windows
+[ioPostToHttpFromSocket]
+windows
+[ioHttpRedirectMultipartPost]
+linux
+[ioHttpRedirectPolicy]
+b2qt 64bit
+linux
+[ioHttpRedirectPostPut]
+linux
+windows
+[putToFtp]
+windows ci
+[putWithServerClosingConnectionImmediately]
+windows
+[qtbug28035browserDoesNotLoadQtProjectOrgCorrectly]
+windows
+[getFromUnreachableIp]
+windows msvc-2017
+[ioHttpRedirectErrors:too-many-redirects]
+rhel-6.6 ci
diff --git a/tests/auto/network/access/qnetworkreply/test/test.pro b/tests/auto/network/access/qnetworkreply/test/test.pro
index 0dcf5a250c..1f45ac0c49 100644
--- a/tests/auto/network/access/qnetworkreply/test/test.pro
+++ b/tests/auto/network/access/qnetworkreply/test/test.pro
@@ -13,7 +13,4 @@ RESOURCES += ../qnetworkreply.qrc
TESTDATA += ../empty ../rfc3252.txt ../resource ../bigfile ../*.jpg ../certs \
../index.html ../smb-file.txt
-qtConfig(xcb): CONFIG+=insignificant_test # unstable, QTBUG-21102
-win32:CONFIG += insignificant_test # QTBUG-24226
-
!winrt: TEST_HELPER_INSTALLS = ../echo/echo
diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
index f6e3962454..df68d4fcd5 100644
--- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
@@ -33,6 +33,7 @@
#include <QtCore/QUrl>
#include <QtCore/QEventLoop>
#include <QtCore/QFile>
+#include <QtCore/QRandomGenerator>
#include <QtCore/QSharedPointer>
#include <QtCore/QScopedPointer>
#include <QtCore/QTemporaryFile>
@@ -120,12 +121,11 @@ class tst_QNetworkReply: public QObject
static QString createUniqueExtension()
{
if (!seedCreated) {
- qsrand(QTime(0,0,0).msecsTo(QTime::currentTime()) + QCoreApplication::applicationPid());
seedCreated = true; // not thread-safe, but who cares
}
return QString::number(QTime(0, 0, 0).msecsTo(QTime::currentTime()))
+ QLatin1Char('-') + QString::number(QCoreApplication::applicationPid())
- + QLatin1Char('-') + QString::number(qrand());
+ + QLatin1Char('-') + QString::number(QRandomGenerator::global()->generate());
}
static QString tempRedirectReplyStr() {
@@ -491,10 +491,12 @@ private Q_SLOTS:
void ioHttpRedirect_data();
void ioHttpRedirect();
void ioHttpRedirectFromLocalToRemote();
- void ioHttpRedirectPost_data();
- void ioHttpRedirectPost();
+ void ioHttpRedirectPostPut_data();
+ void ioHttpRedirectPostPut();
void ioHttpRedirectMultipartPost_data();
void ioHttpRedirectMultipartPost();
+ void ioHttpRedirectDelete();
+ void ioHttpRedirectCustom();
#ifndef QT_NO_SSL
void putWithServerClosingConnectionImmediately();
#endif
@@ -2002,6 +2004,16 @@ void tst_QNetworkReply::getErrors_data()
<< int(QNetworkReply::AuthenticationRequiredError) << 401 << false;
}
+static QByteArray msgGetErrors(int waitResult, const QNetworkReplyPtr &reply)
+{
+ QByteArray result ="waitResult=" + QByteArray::number(waitResult);
+ if (reply->isFinished())
+ result += ", finished";
+ if (reply->error() != QNetworkReply::NoError)
+ result += ", error: " + QByteArray::number(int(reply->error()));
+ return result;
+}
+
void tst_QNetworkReply::getErrors()
{
QFETCH(QString, url);
@@ -2031,7 +2043,8 @@ void tst_QNetworkReply::getErrors()
QCOMPARE(reply->error(), QNetworkReply::NoError);
// now run the request:
- QVERIFY(waitForFinish(reply) != Timeout);
+ const int waitResult = waitForFinish(reply);
+ QVERIFY2(waitResult != Timeout, msgGetErrors(waitResult, reply));
QFETCH(int, error);
QEXPECT_FAIL("ftp-is-dir", "QFtp cannot provide enough detail", Abort);
@@ -4860,7 +4873,7 @@ void tst_QNetworkReply::ioPostToHttpsUploadProgress()
// server send the data much faster than expected.
// So better provide random data that cannot be compressed.
for (int i = 0; i < wantedSize; ++i)
- sourceFile += (char)qrand();
+ sourceFile += (char)QRandomGenerator::global()->generate();
// emulate a minimal https server
SslServer server;
@@ -4940,7 +4953,7 @@ void tst_QNetworkReply::ioGetFromBuiltinHttp()
// server send the data much faster than expected.
// So better provide random data that cannot be compressed.
for (int i = 0; i < wantedSize; ++i)
- testData += (char)qrand();
+ testData += (char)QRandomGenerator::global()->generate();
QByteArray httpResponse = QByteArray("HTTP/1.0 200 OK\r\nContent-Length: ");
httpResponse += QByteArray::number(testData.size());
@@ -6763,6 +6776,48 @@ void tst_QNetworkReply::getFromUnreachableIp()
{
QNetworkAccessManager manager;
+#ifdef Q_OS_WIN
+ // This test assumes that attempt to connect to 255.255.255.255 fails more
+ // or less fast/immediately. This is not what we observe on Windows:
+ // WSAConnect on non-blocking socket returns SOCKET_ERROR, WSAGetLastError
+ // returns WSAEWOULDBLOCK (expected) and getsockopt most of the time returns
+ // NOERROR; so socket engine starts a timer (30 s.) and waits for a timeout/
+ // error/success. Unfortunately, the test itself is waiting only for 5 s.
+ // So we have to adjust the connection timeout or skip the test completely
+ // if the 'bearermanagement' feature is not available.
+#if QT_CONFIG(bearermanagement)
+ class ConfigurationGuard
+ {
+ public:
+ explicit ConfigurationGuard(QNetworkAccessManager *m)
+ : manager(m)
+ {
+ Q_ASSERT(m);
+ auto conf = manager->configuration();
+ previousTimeout = conf.connectTimeout();
+ conf.setConnectTimeout(1500);
+ manager->setConfiguration(conf);
+ }
+ ~ConfigurationGuard()
+ {
+ Q_ASSERT(manager);
+ auto conf = manager->configuration();
+ conf.setConnectTimeout(previousTimeout);
+ manager->setConfiguration(conf);
+ }
+ private:
+ QNetworkAccessManager *manager = nullptr;
+ int previousTimeout = 0;
+
+ Q_DISABLE_COPY(ConfigurationGuard)
+ };
+
+ const ConfigurationGuard restorer(&manager);
+#else // bearermanagement
+ QSKIP("This test is non-deterministic on Windows x86");
+#endif // !bearermanagement
+#endif // Q_OS_WIN
+
QNetworkRequest request(QUrl("http://255.255.255.255/42/23/narf/narf/narf"));
QNetworkReplyPtr reply(manager.get(request));
@@ -8563,37 +8618,46 @@ void tst_QNetworkReply::ioHttpRedirectFromLocalToRemote()
QCOMPARE(reply->readAll(), reference.readAll());
}
-void tst_QNetworkReply::ioHttpRedirectPost_data()
+void tst_QNetworkReply::ioHttpRedirectPostPut_data()
{
+ QTest::addColumn<bool>("usePost");
QTest::addColumn<QString>("status");
QTest::addColumn<QByteArray>("data");
QTest::addColumn<QString>("contentType");
QByteArray data;
data = "hello world";
- QTest::addRow("307") << "307 Temporary Redirect" << data << "text/plain";
+ QTest::addRow("post-307") << true << "307 Temporary Redirect" << data << "text/plain";
+ QTest::addRow("put-307") << false << "307 Temporary Redirect" << data << "text/plain";
QString permanentRedirect = "308 Permanent Redirect";
- QTest::addRow("308") << permanentRedirect << data << "text/plain";
+ QTest::addRow("post-308") << true << permanentRedirect << data << "text/plain";
+ QTest::addRow("put-308") << false << permanentRedirect << data << "text/plain";
// Some data from ::putToFile_data
data = "";
- QTest::newRow("empty") << permanentRedirect << data << "application/octet-stream";
+ QTest::newRow("post-empty") << true << permanentRedirect << data << "application/octet-stream";
+ QTest::newRow("put-empty") << false << permanentRedirect << data << "application/octet-stream";
data = QByteArray("abcd\0\1\2\abcd",12);
- QTest::newRow("with-nul") << permanentRedirect << data << "application/octet-stream";
+ QTest::newRow("post-with-nul") << true << permanentRedirect << data << "application/octet-stream";
+ QTest::newRow("put-with-nul") << false << permanentRedirect << data << "application/octet-stream";
data = QByteArray(4097, '\4');
- QTest::newRow("4k+1") << permanentRedirect << data << "application/octet-stream";
+ QTest::newRow("post-4k+1") << true << permanentRedirect << data << "application/octet-stream";
+ QTest::newRow("put-4k+1") << false << permanentRedirect << data << "application/octet-stream";
data = QByteArray(128*1024+1, '\177');
- QTest::newRow("128k+1") << permanentRedirect << data << "application/octet-stream";
+ QTest::newRow("post-128k+1") << true << permanentRedirect << data << "application/octet-stream";
+ QTest::newRow("put-128k+1") << false << permanentRedirect << data << "application/octet-stream";
data = QByteArray(2*1024*1024+1, '\177');
- QTest::newRow("2MB+1") << permanentRedirect << data << "application/octet-stream";
+ QTest::newRow("post-2MB+1") << true << permanentRedirect << data << "application/octet-stream";
+ QTest::newRow("put-2MB+1") << false << permanentRedirect << data << "application/octet-stream";
}
-void tst_QNetworkReply::ioHttpRedirectPost()
+void tst_QNetworkReply::ioHttpRedirectPostPut()
{
+ QFETCH(bool, usePost);
QFETCH(QString, status);
QFETCH(QByteArray, data);
QFETCH(QString, contentType);
@@ -8612,7 +8676,7 @@ void tst_QNetworkReply::ioHttpRedirectPost()
auto oldRedirectPolicy = manager.redirectPolicy();
manager.setRedirectPolicy(QNetworkRequest::RedirectPolicy::NoLessSafeRedirectPolicy);
- QNetworkReplyPtr reply(manager.post(request, data));
+ QNetworkReplyPtr reply(usePost ? manager.post(request, data) : manager.put(request, data));
// Restore previous policy:
manager.setRedirectPolicy(oldRedirectPolicy);
@@ -8681,6 +8745,50 @@ void tst_QNetworkReply::ioHttpRedirectMultipartPost()
QCOMPARE(replyData, expectedReplyData);
}
+void tst_QNetworkReply::ioHttpRedirectDelete()
+{
+ MiniHttpServer target(httpEmpty200Response, false);
+ QUrl targetUrl("http://localhost/");
+ targetUrl.setPort(target.serverPort());
+
+ QString redirectReply = tempRedirectReplyStr().arg(targetUrl.toString());
+ MiniHttpServer redirectServer(redirectReply.toLatin1());
+ QUrl url("http://localhost/");
+ url.setPort(redirectServer.serverPort());
+ QNetworkRequest request(url);
+ auto oldRedirectPolicy = manager.redirectPolicy();
+ manager.setRedirectPolicy(QNetworkRequest::RedirectPolicy::NoLessSafeRedirectPolicy);
+
+ QNetworkReplyPtr reply(manager.deleteResource(request));
+ // Restore previous policy:
+ manager.setRedirectPolicy(oldRedirectPolicy);
+
+ QCOMPARE(waitForFinish(reply), int(Success));
+ QVERIFY2(target.receivedData.startsWith("DELETE"), "Target server called with the wrong method");
+}
+
+void tst_QNetworkReply::ioHttpRedirectCustom()
+{
+ MiniHttpServer target(httpEmpty200Response, false);
+ QUrl targetUrl("http://localhost/");
+ targetUrl.setPort(target.serverPort());
+
+ QString redirectReply = tempRedirectReplyStr().arg(targetUrl.toString());
+ MiniHttpServer redirectServer(redirectReply.toLatin1());
+ QUrl url("http://localhost/");
+ url.setPort(redirectServer.serverPort());
+ QNetworkRequest request(url);
+ auto oldRedirectPolicy = manager.redirectPolicy();
+ manager.setRedirectPolicy(QNetworkRequest::RedirectPolicy::NoLessSafeRedirectPolicy);
+
+ QNetworkReplyPtr reply(manager.sendCustomRequest(request, QByteArrayLiteral("CUSTOM")));
+ // Restore previous policy:
+ manager.setRedirectPolicy(oldRedirectPolicy);
+
+ QCOMPARE(waitForFinish(reply), int(Success));
+ QVERIFY2(target.receivedData.startsWith("CUSTOM"), "Target server called with the wrong method");
+}
+
#ifndef QT_NO_SSL
class PutWithServerClosingConnectionImmediatelyHandler: public QObject
@@ -8710,7 +8818,7 @@ public slots:
m_receivedData += data;
if (!m_parsedHeaders && m_receivedData.contains("\r\n\r\n")) {
m_parsedHeaders = true;
- QTimer::singleShot(qrand()%60, this, SLOT(closeDelayed())); // simulate random network latency
+ QTimer::singleShot(QRandomGenerator::global()->bounded(60), this, SLOT(closeDelayed())); // simulate random network latency
// This server simulates a web server connection closing, e.g. because of Apaches MaxKeepAliveRequests or KeepAliveTimeout
// In this case QNAM needs to re-send the upload data but it had a bug which then corrupts the upload
// This test catches that.
diff --git a/tests/auto/network/socket/qtcpsocket/qtcpsocket.pro b/tests/auto/network/socket/qtcpsocket/qtcpsocket.pro
index 1183b23556..1f13a396dd 100644
--- a/tests/auto/network/socket/qtcpsocket/qtcpsocket.pro
+++ b/tests/auto/network/socket/qtcpsocket/qtcpsocket.pro
@@ -1,6 +1,8 @@
TEMPLATE = subdirs
SUBDIRS = test
-!vxworks: SUBDIRS += stressTest
-
+!vxworks{
+SUBDIRS += stressTest
+test.depends = stressTest
+}
requires(qtConfig(private_tests))
diff --git a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
index 493263f2b8..396ce62536 100644
--- a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
+++ b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
+** Copyright (C) 2017 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
@@ -57,6 +57,7 @@
#if QT_CONFIG(process)
# include <QProcess>
#endif
+#include <QRandomGenerator>
#include <QStringList>
#include <QTcpServer>
#include <QTcpSocket>
@@ -305,8 +306,6 @@ public:
tst_QTcpSocket::tst_QTcpSocket()
: firstFailName("qt-test-server-first-fail")
{
- qsrand(time(NULL));
-
tmpSocket = 0;
//This code relates to the socketsConstructedBeforeEventLoop test case
@@ -581,8 +580,7 @@ void tst_QTcpSocket::bind()
// try to get a random port number
// we do this to ensure we're not trying to bind to the same port as we've just used in
// a previous run - race condition with the OS actually freeing the port
- Q_STATIC_ASSERT(RAND_MAX > 1024);
- port = qrand() & USHRT_MAX;
+ port = QRandomGenerator::global()->generate() & USHRT_MAX;
if (port < 1024)
continue;
}
diff --git a/tests/auto/network/socket/qudpsocket/qudpsocket.pro b/tests/auto/network/socket/qudpsocket/qudpsocket.pro
index 4ddb7178a4..b267d5f249 100644
--- a/tests/auto/network/socket/qudpsocket/qudpsocket.pro
+++ b/tests/auto/network/socket/qudpsocket/qudpsocket.pro
@@ -1,4 +1,3 @@
TEMPLATE = subdirs
SUBDIRS = test clientserver
-
-
+test.depends = clientserver
diff --git a/tests/auto/network/socket/qudpsocket/test/test.pro b/tests/auto/network/socket/qudpsocket/test/test.pro
index 73486a2bc3..e856776ddc 100644
--- a/tests/auto/network/socket/qudpsocket/test/test.pro
+++ b/tests/auto/network/socket/qudpsocket/test/test.pro
@@ -1,6 +1,7 @@
CONFIG += testcase
testcase.timeout = 800 # this test is slow
SOURCES += ../tst_qudpsocket.cpp
+INCLUDEPATH += ../../../../../shared/
QT = core network testlib
MOC_DIR=tmp
diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
index aeb6e61cd2..0f46caa7c2 100644
--- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
+++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
+** Copyright (C) 2017 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
@@ -45,6 +45,7 @@
#include <qstringlist.h>
#include "../../../network-settings.h"
+#include "emulationdetector.h"
#ifndef QT_NO_BEARERMANAGEMENT
#include <QtNetwork/qnetworkconfigmanager.h>
@@ -227,6 +228,9 @@ void tst_QUdpSocket::initTestCase()
QSKIP("No network test server available");
allAddresses = QNetworkInterface::allAddresses();
m_skipUnsupportedIPv6Tests = shouldSkipIpv6TestsForBrokenSetsockopt();
+
+ if (EmulationDetector::isRunningArmOnX86())
+ QSKIP("This test is unreliable due to QEMU emulation shortcomings.");
}
void tst_QUdpSocket::init()
@@ -445,31 +449,58 @@ void tst_QUdpSocket::loop()
paul.setProperty("_q_networksession", QVariant::fromValue(networkSession));
#endif
- QVERIFY2(peter.bind(), peter.errorString().toLatin1().constData());
- QVERIFY2(paul.bind(), paul.errorString().toLatin1().constData());
+ // make sure we bind to IPv4
+ QHostAddress localhost = QHostAddress::LocalHost;
+ QVERIFY2(peter.bind(localhost), peter.errorString().toLatin1().constData());
+ QVERIFY2(paul.bind(localhost), paul.errorString().toLatin1().constData());
QHostAddress peterAddress = makeNonAny(peter.localAddress());
- QHostAddress pualAddress = makeNonAny(paul.localAddress());
+ QHostAddress paulAddress = makeNonAny(paul.localAddress());
QCOMPARE(peter.writeDatagram(peterMessage.data(), peterMessage.length(),
- pualAddress, paul.localPort()), qint64(peterMessage.length()));
+ paulAddress, paul.localPort()), qint64(peterMessage.length()));
QCOMPARE(paul.writeDatagram(paulMessage.data(), paulMessage.length(),
peterAddress, peter.localPort()), qint64(paulMessage.length()));
QVERIFY2(peter.waitForReadyRead(9000), QtNetworkSettings::msgSocketError(peter).constData());
QVERIFY2(paul.waitForReadyRead(9000), QtNetworkSettings::msgSocketError(paul).constData());
- char peterBuffer[16*1024];
- char paulBuffer[16*1024];
+
+ QNetworkDatagram peterDatagram = peter.receiveDatagram(paulMessage.length() * 2);
+ QNetworkDatagram paulDatagram = paul.receiveDatagram(peterMessage.length() * 2);
if (success) {
- QCOMPARE(peter.readDatagram(peterBuffer, sizeof(peterBuffer)), qint64(paulMessage.length()));
- QCOMPARE(paul.readDatagram(paulBuffer, sizeof(peterBuffer)), qint64(peterMessage.length()));
+ QCOMPARE(peterDatagram.data().length(), qint64(paulMessage.length()));
+ QCOMPARE(paulDatagram.data().length(), qint64(peterMessage.length()));
} else {
- QVERIFY(peter.readDatagram(peterBuffer, sizeof(peterBuffer)) != paulMessage.length());
- QVERIFY(paul.readDatagram(paulBuffer, sizeof(peterBuffer)) != peterMessage.length());
+ // this code path seems to never be executed
+ QVERIFY(peterDatagram.data().length() != paulMessage.length());
+ QVERIFY(paulDatagram.data().length() != peterMessage.length());
}
- QCOMPARE(QByteArray(peterBuffer, paulMessage.length()), paulMessage);
- QCOMPARE(QByteArray(paulBuffer, peterMessage.length()), peterMessage);
+ QCOMPARE(peterDatagram.data().left(paulMessage.length()), paulMessage);
+ QCOMPARE(paulDatagram.data().left(peterMessage.length()), peterMessage);
+
+ QCOMPARE(peterDatagram.senderAddress(), paulAddress);
+ QCOMPARE(paulDatagram.senderAddress(), peterAddress);
+ QCOMPARE(paulDatagram.senderPort(), int(peter.localPort()));
+ QCOMPARE(peterDatagram.senderPort(), int(paul.localPort()));
+
+ // Unlike for IPv6 with IPV6_PKTINFO, IPv4 has no standardized way of
+ // obtaining the packet's destination addresses. The destinationAddress and
+ // destinationPort calls could fail, so whitelist the OSes for which we
+ // know we have an implementation.
+#if defined(Q_OS_LINUX) || defined(Q_OS_BSD4) || defined(Q_OS_WIN)
+ QVERIFY(peterDatagram.destinationPort() != -1);
+ QVERIFY(paulDatagram.destinationPort() != -1);
+#endif
+ if (peterDatagram.destinationPort() == -1) {
+ QCOMPARE(peterDatagram.destinationAddress().protocol(), QAbstractSocket::UnknownNetworkLayerProtocol);
+ QCOMPARE(paulDatagram.destinationAddress().protocol(), QAbstractSocket::UnknownNetworkLayerProtocol);
+ } else {
+ QCOMPARE(peterDatagram.destinationAddress(), makeNonAny(peter.localAddress()));
+ QCOMPARE(paulDatagram.destinationAddress(), makeNonAny(paul.localAddress()));
+ QVERIFY(peterDatagram.destinationAddress().isEqual(makeNonAny(peter.localAddress())));
+ QVERIFY(paulDatagram.destinationAddress().isEqual(makeNonAny(paul.localAddress())));
+ }
}
//----------------------------------------------------------------------------------
@@ -492,8 +523,8 @@ void tst_QUdpSocket::ipv6Loop()
paul.setProperty("_q_networksession", QVariant::fromValue(networkSession));
#endif
- quint16 peterPort;
- quint16 paulPort;
+ int peterPort;
+ int paulPort;
if (!peter.bind(QHostAddress(QHostAddress::LocalHostIPv6), 0)) {
QCOMPARE(peter.error(), QUdpSocket::UnsupportedSocketOperationError);
@@ -502,6 +533,8 @@ void tst_QUdpSocket::ipv6Loop()
QVERIFY(paul.bind(QHostAddress(QHostAddress::LocalHostIPv6), 0));
+ QHostAddress peterAddress = makeNonAny(peter.localAddress());
+ QHostAddress paulAddress = makeNonAny(paul.localAddress());
peterPort = peter.localPort();
paulPort = paul.localPort();
@@ -510,20 +543,33 @@ void tst_QUdpSocket::ipv6Loop()
QCOMPARE(paul.writeDatagram(paulMessage.data(), paulMessage.length(),
QHostAddress("::1"), peterPort), qint64(paulMessage.length()));
- char peterBuffer[16*1024];
- char paulBuffer[16*1024];
QVERIFY(peter.waitForReadyRead(5000));
QVERIFY(paul.waitForReadyRead(5000));
+ QNetworkDatagram peterDatagram = peter.receiveDatagram(paulMessage.length() * 2);
+ QNetworkDatagram paulDatagram = paul.receiveDatagram(peterMessage.length() * 2);
+
if (success) {
- QCOMPARE(peter.readDatagram(peterBuffer, sizeof(peterBuffer)), qint64(paulMessage.length()));
- QCOMPARE(paul.readDatagram(paulBuffer, sizeof(peterBuffer)), qint64(peterMessage.length()));
+ QCOMPARE(peterDatagram.data().length(), qint64(paulMessage.length()));
+ QCOMPARE(paulDatagram.data().length(), qint64(peterMessage.length()));
} else {
- QVERIFY(peter.readDatagram(peterBuffer, sizeof(peterBuffer)) != paulMessage.length());
- QVERIFY(paul.readDatagram(paulBuffer, sizeof(peterBuffer)) != peterMessage.length());
+ // this code path seems to never be executed
+ QVERIFY(peterDatagram.data().length() != paulMessage.length());
+ QVERIFY(paulDatagram.data().length() != peterMessage.length());
}
- QCOMPARE(QByteArray(peterBuffer, paulMessage.length()), paulMessage);
- QCOMPARE(QByteArray(paulBuffer, peterMessage.length()), peterMessage);
+ QCOMPARE(peterDatagram.data().left(paulMessage.length()), paulMessage);
+ QCOMPARE(paulDatagram.data().left(peterMessage.length()), peterMessage);
+
+ QCOMPARE(peterDatagram.senderAddress(), paulAddress);
+ QCOMPARE(paulDatagram.senderAddress(), peterAddress);
+ QCOMPARE(paulDatagram.senderPort(), peterPort);
+ QCOMPARE(peterDatagram.senderPort(), paulPort);
+
+ // For IPv6, IPV6_PKTINFO is a mandatory feature (RFC 3542).
+ QCOMPARE(peterDatagram.destinationAddress(), makeNonAny(peter.localAddress()));
+ QCOMPARE(paulDatagram.destinationAddress(), makeNonAny(paul.localAddress()));
+ QCOMPARE(peterDatagram.destinationPort(), peterPort);
+ QCOMPARE(paulDatagram.destinationPort(), paulPort);
}
void tst_QUdpSocket::dualStack()
@@ -539,17 +585,23 @@ void tst_QUdpSocket::dualStack()
QByteArray v4Data("v4");
QVERIFY(v4Sock.bind(QHostAddress(QHostAddress::AnyIPv4), 0));
- QHostAddress from;
- quint16 port;
- QByteArray buffer;
//test v4 -> dual
QCOMPARE((int)v4Sock.writeDatagram(v4Data.constData(), v4Data.length(), QHostAddress(QHostAddress::LocalHost), dualSock.localPort()), v4Data.length());
QVERIFY2(dualSock.waitForReadyRead(5000), QtNetworkSettings::msgSocketError(dualSock).constData());
- buffer.reserve(100);
- qint64 size = dualSock.readDatagram(buffer.data(), 100, &from, &port);
- QCOMPARE((int)size, v4Data.length());
- buffer.resize(size);
- QCOMPARE(buffer, v4Data);
+ QNetworkDatagram dgram = dualSock.receiveDatagram(100);
+ QVERIFY(dgram.isValid());
+ QCOMPARE(dgram.data(), v4Data);
+ QCOMPARE(dgram.senderPort(), int(v4Sock.localPort()));
+ // receiving v4 on dual stack will receive as IPv6, so use isEqual()
+ QVERIFY(dgram.senderAddress().isEqual(makeNonAny(v4Sock.localAddress(), QHostAddress::Null)));
+ if (dualSock.localAddress().protocol() == QAbstractSocket::IPv4Protocol)
+ QCOMPARE(dgram.senderAddress(), makeNonAny(v4Sock.localAddress(), QHostAddress::Null));
+ if (dgram.destinationPort() != -1) {
+ QCOMPARE(dgram.destinationPort(), int(dualSock.localPort()));
+ QVERIFY(dgram.destinationAddress().isEqual(dualSock.localAddress()));
+ } else {
+ qInfo("Getting IPv4 destination address failed.");
+ }
if (QtNetworkSettings::hasIPv6()) {
QUdpSocket v6Sock;
@@ -559,30 +611,41 @@ void tst_QUdpSocket::dualStack()
//test v6 -> dual
QCOMPARE((int)v6Sock.writeDatagram(v6Data.constData(), v6Data.length(), QHostAddress(QHostAddress::LocalHostIPv6), dualSock.localPort()), v6Data.length());
QVERIFY2(dualSock.waitForReadyRead(5000), QtNetworkSettings::msgSocketError(dualSock).constData());
- buffer.reserve(100);
- size = dualSock.readDatagram(buffer.data(), 100, &from, &port);
- QCOMPARE((int)size, v6Data.length());
- buffer.resize(size);
- QCOMPARE(buffer, v6Data);
+ dgram = dualSock.receiveDatagram(100);
+ QVERIFY(dgram.isValid());
+ QCOMPARE(dgram.data(), v6Data);
+ QCOMPARE(dgram.senderPort(), int(v6Sock.localPort()));
+ QCOMPARE(dgram.senderAddress(), makeNonAny(v6Sock.localAddress(), QHostAddress::LocalHostIPv6));
+ QCOMPARE(dgram.destinationPort(), int(dualSock.localPort()));
+ QCOMPARE(dgram.destinationAddress(), makeNonAny(dualSock.localAddress(), QHostAddress::LocalHostIPv6));
//test dual -> v6
QCOMPARE((int)dualSock.writeDatagram(dualData.constData(), dualData.length(), QHostAddress(QHostAddress::LocalHostIPv6), v6Sock.localPort()), dualData.length());
QVERIFY2(v6Sock.waitForReadyRead(5000), QtNetworkSettings::msgSocketError(v6Sock).constData());
- buffer.reserve(100);
- size = v6Sock.readDatagram(buffer.data(), 100, &from, &port);
- QCOMPARE((int)size, dualData.length());
- buffer.resize(size);
- QCOMPARE(buffer, dualData);
+ dgram = v6Sock.receiveDatagram(100);
+ QVERIFY(dgram.isValid());
+ QCOMPARE(dgram.data(), dualData);
+ QCOMPARE(dgram.senderPort(), int(dualSock.localPort()));
+ QCOMPARE(dgram.senderAddress(), makeNonAny(dualSock.localAddress(), QHostAddress::LocalHostIPv6));
+ QCOMPARE(dgram.destinationPort(), int(v6Sock.localPort()));
+ QCOMPARE(dgram.destinationAddress(), makeNonAny(v6Sock.localAddress(), QHostAddress::LocalHostIPv6));
}
//test dual -> v4
QCOMPARE((int)dualSock.writeDatagram(dualData.constData(), dualData.length(), QHostAddress(QHostAddress::LocalHost), v4Sock.localPort()), dualData.length());
QVERIFY2(v4Sock.waitForReadyRead(5000), QtNetworkSettings::msgSocketError(v4Sock).constData());
- buffer.reserve(100);
- size = v4Sock.readDatagram(buffer.data(), 100, &from, &port);
- QCOMPARE((int)size, dualData.length());
- buffer.resize(size);
- QCOMPARE(buffer, dualData);
+ dgram = v4Sock.receiveDatagram(100);
+ QVERIFY(dgram.isValid());
+ QCOMPARE(dgram.data(), dualData);
+ QCOMPARE(dgram.senderPort(), int(dualSock.localPort()));
+ QCOMPARE(dgram.senderAddress(), makeNonAny(dualSock.localAddress(), QHostAddress::LocalHost));
+#if defined(Q_OS_LINUX) || defined(Q_OS_BSD4) || defined(Q_OS_WIN)
+ QVERIFY(dgram.destinationPort() != -1);
+#endif
+ if (dgram.destinationPort() != -1) {
+ QCOMPARE(dgram.destinationPort(), int(v4Sock.localPort()));
+ QCOMPARE(dgram.destinationAddress(), makeNonAny(v4Sock.localAddress(), QHostAddress::LocalHost));
+ }
}
void tst_QUdpSocket::dualStackAutoBinding()
@@ -1603,6 +1666,8 @@ void tst_QUdpSocket::linkLocalIPv6()
QVERIFY(dgram.isValid());
QCOMPARE(dgram.senderAddress(), s->localAddress());
QCOMPARE(dgram.senderPort(), int(s->localPort()));
+ QCOMPARE(dgram.destinationAddress(), s->localAddress());
+ QCOMPARE(dgram.destinationPort(), int(neutral.localPort()));
QCOMPARE(dgram.data().length(), testData.length());
QCOMPARE(dgram.data(), testData);
@@ -1684,6 +1749,20 @@ void tst_QUdpSocket::linkLocalIPv4()
QCOMPARE(dgram.data().length(), testData.length());
QCOMPARE(dgram.data(), testData);
+ // Unlike for IPv6 with IPV6_PKTINFO, IPv4 has no standardized way of
+ // obtaining the packet's destination addresses. The destinationAddress
+ // and destinationPort calls could fail, so whitelist the OSes we know
+ // we have an implementation.
+#if defined(Q_OS_LINUX) || defined(Q_OS_BSD4) || defined(Q_OS_WIN)
+ QVERIFY(dgram.destinationPort() != -1);
+#endif
+ if (dgram.destinationPort() == -1) {
+ QCOMPARE(dgram.destinationAddress().protocol(), QAbstractSocket::UnknownNetworkLayerProtocol);
+ } else {
+ QCOMPARE(dgram.destinationAddress(), s->localAddress());
+ QCOMPARE(dgram.destinationPort(), int(neutral.localPort()));
+ }
+
QVERIFY(neutral.writeDatagram(dgram.makeReply(testData)));
dgram = s->receiveDatagram(testData.length() * 2);
diff --git a/tests/auto/opengl/qglthreads/tst_qglthreads.cpp b/tests/auto/opengl/qglthreads/tst_qglthreads.cpp
index 1a7ccba9be..90fc4e0f2a 100644
--- a/tests/auto/opengl/qglthreads/tst_qglthreads.cpp
+++ b/tests/auto/opengl/qglthreads/tst_qglthreads.cpp
@@ -138,7 +138,7 @@ public:
makeCurrent();
QPainter p(this);
- p.fillRect(rect(), QColor(rand() % 256, rand() % 256, rand() % 256));
+ p.fillRect(rect(), QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
p.setPen(Qt::red);
p.setFont(QFont("SansSerif", 24));
p.drawText(rect(), Qt::AlignCenter, "This is an autotest");
@@ -229,7 +229,7 @@ public:
int height = 300;
QImage image(width, height, QImage::Format_RGB32);
QPainter p(&image);
- p.fillRect(image.rect(), QColor(rand() % 256, rand() % 256, rand() % 256));
+ p.fillRect(image.rect(), QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
p.setPen(Qt::red);
p.setFont(QFont("SansSerif", 24));
p.drawText(image.rect(), Qt::AlignCenter, "This is an autotest");
@@ -271,7 +271,7 @@ public:
public slots:
void receiveImage(const QImage &image) {
m_images << image;
- m_positions << QPoint(-rand() % width() / 2, -rand() % height() / 2);
+ m_positions << QPoint(-QRandomGenerator::global()->bounded(width() / 2), -QRandomGenerator::global()->bounded(height() / 2));
m_semaphore->release(1);
@@ -326,7 +326,7 @@ void tst_QGLThreads::textureUploadInThread()
if that works, we're in good shape..
*/
-static inline float qrandom() { return (rand() % 100) / 100.f; }
+static inline float qrandom() { return (QRandomGenerator::global()->bounded(100)) / 100.f; }
void renderAScene(int w, int h)
{
@@ -345,12 +345,12 @@ void renderAScene(int w, int h)
for (int i=0; i<1000; ++i) {
GLfloat pos[] = {
- (rand() % 100) / 100.f,
- (rand() % 100) / 100.f,
- (rand() % 100) / 100.f,
- (rand() % 100) / 100.f,
- (rand() % 100) / 100.f,
- (rand() % 100) / 100.f
+ (QRandomGenerator::global()->bounded(100)) / 100.f,
+ (QRandomGenerator::global()->bounded(100)) / 100.f,
+ (QRandomGenerator::global()->bounded(100)) / 100.f,
+ (QRandomGenerator::global()->bounded(100)) / 100.f,
+ (QRandomGenerator::global()->bounded(100)) / 100.f,
+ (QRandomGenerator::global()->bounded(100)) / 100.f
};
funcs->glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, pos);
diff --git a/tests/auto/other/compiler/tst_compiler.cpp b/tests/auto/other/compiler/tst_compiler.cpp
index 121d731757..8b59f2758f 100644
--- a/tests/auto/other/compiler/tst_compiler.cpp
+++ b/tests/auto/other/compiler/tst_compiler.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
+** Copyright (C) 2017 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
@@ -802,7 +802,7 @@ void tst_Compiler::cxx11_auto_type()
QSKIP("Compiler does not support C++11 feature");
#else
auto i = 1;
- auto x = qrand();
+ auto x = QRandomGenerator::global()->generate();
auto l = 1L;
auto s = QStringLiteral("Hello World");
@@ -851,8 +851,8 @@ void tst_Compiler::cxx11_decltype()
#ifndef Q_COMPILER_DECLTYPE
QSKIP("Compiler does not support C++11 feature");
#else
- decltype(qrand()) i = 0;
- QCOMPARE(i, 0);
+ decltype(QRandomGenerator::global()->generate()) i = 0;
+ QCOMPARE(i, 0U);
#endif
}
@@ -1549,7 +1549,7 @@ void tst_Compiler::runtimeArrays()
#if __cpp_runtime_arrays-0 < 201304
QSKIP("Compiler does not support this C++14 feature");
#else
- int i[qrand() & 0x1f];
+ int i[QRandomGenerator::global()->generate() & 0x1f];
Q_UNUSED(i);
#endif
}
diff --git a/tests/auto/other/networkselftest/tst_networkselftest.cpp b/tests/auto/other/networkselftest/tst_networkselftest.cpp
index 3b696604b5..dc353d2090 100644
--- a/tests/auto/other/networkselftest/tst_networkselftest.cpp
+++ b/tests/auto/other/networkselftest/tst_networkselftest.cpp
@@ -30,6 +30,7 @@
#include <QtNetwork/QtNetwork>
#include <QtCore/QDateTime>
#include <QtCore/QTextStream>
+#include <QtCore/QRandomGenerator>
#include <QtCore/QStandardPaths>
#include <QtCore/private/qiodevice_p.h>
@@ -538,7 +539,7 @@ void tst_NetworkSelfTest::imapServer()
void tst_NetworkSelfTest::httpServer()
{
QByteArray uniqueExtension = QByteArray::number((qulonglong)this) +
- QByteArray::number((qulonglong)qrand()) +
+ QByteArray::number((qulonglong)QRandomGenerator::global()->generate()) +
QByteArray::number(QDateTime::currentSecsSinceEpoch());
netChat(80, QList<Chat>()
diff --git a/tests/auto/other/qaccessibility/qaccessibility.pro b/tests/auto/other/qaccessibility/qaccessibility.pro
index 91e0f7472e..3587c38e76 100644
--- a/tests/auto/other/qaccessibility/qaccessibility.pro
+++ b/tests/auto/other/qaccessibility/qaccessibility.pro
@@ -1,7 +1,7 @@
CONFIG += testcase
TARGET = tst_qaccessibility
requires(qtConfig(accessibility))
-QT += testlib core-private gui-private widgets-private
+QT += testlib core-private gui-private widgets-private testlib-private
SOURCES += tst_qaccessibility.cpp
HEADERS += accessiblewidgets.h
diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp
index 8d54108737..7976e0d626 100644
--- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp
+++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp
@@ -45,6 +45,7 @@
#include <qpa/qplatformintegration.h>
#include <qpa/qplatformaccessibility.h>
#include <QtGui/private/qguiapplication_p.h>
+#include <QtGui/private/qhighdpiscaling_p.h>
#if defined(Q_OS_WIN) && defined(interface)
# undef interface
@@ -56,15 +57,9 @@
#include "accessiblewidgets.h"
-// Make a widget frameless to prevent size constraints of title bars
-// from interfering (Windows).
-static inline void setFrameless(QWidget *w)
-{
- Qt::WindowFlags flags = w->windowFlags();
- flags |= Qt::FramelessWindowHint;
- flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
- w->setWindowFlags(flags);
-}
+#include <QtTest/private/qtesthelpers_p.h>
+
+using namespace QTestPrivate;
static inline bool verifyChild(QWidget *child, QAccessibleInterface *interface,
int index, const QRect &domain)
@@ -299,6 +294,7 @@ void tst_QAccessibility::cleanup()
qAccessibleEventString(list.at(i)->type()), list.at(i)->child());
}
QTestAccessibility::clearEvents();
+ QTRY_VERIFY(QApplication::topLevelWidgets().isEmpty());
}
void tst_QAccessibility::eventTest()
@@ -3741,14 +3737,14 @@ void tst_QAccessibility::bridgeTest()
// Ideally it should be extended to test all aspects of the bridge.
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
- QWidget *window = new QWidget;
- QVBoxLayout *lay = new QVBoxLayout(window);
- QPushButton *button = new QPushButton(tr("Push me"), window);
- QTextEdit *te = new QTextEdit(window);
+ QWidget window;
+ QVBoxLayout *lay = new QVBoxLayout(&window);
+ QPushButton *button = new QPushButton(tr("Push me"), &window);
+ QTextEdit *te = new QTextEdit(&window);
te->setText(QLatin1String("hello world\nhow are you today?\n"));
// Add QTableWidget
- QTableWidget *tableWidget = new QTableWidget(3, 3, window);
+ QTableWidget *tableWidget = new QTableWidget(3, 3, &window);
tableWidget->setColumnCount(3);
QStringList hHeader;
hHeader << "h1" << "h2" << "h3";
@@ -3774,8 +3770,8 @@ void tst_QAccessibility::bridgeTest()
lay->addWidget(tableWidget);
lay->addWidget(label);
- window->show();
- QVERIFY(QTest::qWaitForWindowExposed(window));
+ window.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
// Validate button position through the accessible interface.
QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(button);
@@ -3784,9 +3780,8 @@ void tst_QAccessibility::bridgeTest()
QCOMPARE(buttonRect.topLeft(), buttonPos);
// All set, now test the bridge.
- POINT pt;
- pt.x = buttonRect.center().x();
- pt.y = buttonRect.center().y();
+ const QPoint nativePos = QHighDpi::toNativePixels(buttonRect.center(), window.windowHandle());
+ POINT pt{nativePos.x(), nativePos.y()};
// Initialize COM stuff.
HRESULT hr = CoInitialize(nullptr);
@@ -3817,7 +3812,7 @@ void tst_QAccessibility::bridgeTest()
buttonElement->Release();
// Get native window handle.
- QWindow *windowHandle = window->windowHandle();
+ QWindow *windowHandle = window.windowHandle();
QVERIFY(windowHandle != 0);
QPlatformNativeInterface *platform = QGuiApplication::platformNativeInterface();
QVERIFY(platform != 0);
diff --git a/tests/auto/other/qnetworkaccessmanager_and_qprogressdialog/BLACKLIST b/tests/auto/other/qnetworkaccessmanager_and_qprogressdialog/BLACKLIST
new file mode 100644
index 0000000000..aea819fc2e
--- /dev/null
+++ b/tests/auto/other/qnetworkaccessmanager_and_qprogressdialog/BLACKLIST
@@ -0,0 +1,2 @@
+[downloadCheck:with-zeroCopy]
+windows
diff --git a/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp b/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp
index 9b0d5b6920..4395a04976 100644
--- a/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp
+++ b/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp
@@ -1252,7 +1252,7 @@ void tst_QSqlDatabase::psql_schemas()
QString table = schemaName + '.' + qTableName("qtesttable", __FILE__, db);
QVERIFY_SQL(q, exec("CREATE TABLE " + table + " (id int primary key, name varchar(20))"));
- QVERIFY(db.tables().contains(table));
+ QVERIFY(db.tables().contains(table, Qt::CaseInsensitive));
QSqlRecord rec = db.record(table);
QCOMPARE(rec.count(), 2);
diff --git a/tests/auto/sql/kernel/qsqldriver/tst_qsqldriver.cpp b/tests/auto/sql/kernel/qsqldriver/tst_qsqldriver.cpp
index 8f8cfe009d..7bfa29ec8e 100644
--- a/tests/auto/sql/kernel/qsqldriver/tst_qsqldriver.cpp
+++ b/tests/auto/sql/kernel/qsqldriver/tst_qsqldriver.cpp
@@ -77,6 +77,8 @@ void tst_QSqlDriver::recreateTestTables(QSqlDatabase db)
doubleField = "more_data double";
else if (dbType == QSqlDriver::Oracle)
doubleField = "more_data number(8,7)";
+ else if (dbType == QSqlDriver::PostgreSQL)
+ doubleField = "more_data double precision";
else
doubleField = "more_data double(8,7)";
QVERIFY_SQL( q, exec("create table " + relTEST1 +
@@ -98,6 +100,9 @@ void tst_QSqlDriver::cleanupTestCase()
foreach (const QString &dbName, dbs.dbNames) {
QSqlDatabase db = QSqlDatabase::database(dbName);
tst_Databases::safeDropTable(db, qTableName("relTEST1", __FILE__, db));
+ const QSqlDriver::DbmsType dbType = tst_Databases::getDatabaseType(db);
+ if (dbType == QSqlDriver::Oracle)
+ tst_Databases::safeDropTable(db, qTableName("clobTable", __FILE__, db));
}
dbs.close();
}
@@ -212,6 +217,20 @@ void tst_QSqlDriver::primaryIndex()
QCOMPARE(index.count(), 1); //mysql will always find the table name regardless of casing
else
QCOMPARE(index.count(), 0);
+
+ // Test getting a primary index for a table with a clob in it - QTBUG-64427
+ if (dbType == QSqlDriver::Oracle) {
+ const QString clobTable(qTableName("clobTable", __FILE__, db));
+ QSqlQuery qry(db);
+ QVERIFY_SQL(qry, exec("CREATE TABLE " + clobTable + " (id INTEGER, clobField CLOB)"));
+ QVERIFY_SQL(qry, exec("CREATE UNIQUE INDEX " + clobTable + "IDX ON " + clobTable + " (id)"));
+ QVERIFY_SQL(qry, exec("ALTER TABLE " + clobTable + " ADD CONSTRAINT " + clobTable +
+ "PK PRIMARY KEY(id)"));
+ QVERIFY_SQL(qry, exec("ALTER TABLE " + clobTable + " MODIFY (id NOT NULL ENABLE)"));
+ const QSqlIndex primaryIndex = db.driver()->primaryIndex(clobTable);
+ QCOMPARE(primaryIndex.count(), 1);
+ QCOMPARE(primaryIndex.fieldName(0), QStringLiteral("ID"));
+ }
}
void tst_QSqlDriver::formatValue()
diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
index 2a27f24314..1935bb6501 100644
--- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
+++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
@@ -146,7 +146,7 @@ private slots:
void batchExec();
void QTBUG_43874_data() { generic_data(); }
void QTBUG_43874();
- void oraArrayBind_data() { generic_data(); }
+ void oraArrayBind_data() { generic_data("QOCI"); }
void oraArrayBind();
void lastInsertId_data() { generic_data(); }
void lastInsertId();
diff --git a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
index 2cfe987f7d..a662fea615 100644
--- a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
+++ b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
@@ -140,6 +140,7 @@ private slots:
void compareQListInt();
void compareQListDouble();
#ifdef QT_GUI_LIB
+ void compareQColor_data();
void compareQColor();
void compareQPixmaps();
void compareQPixmaps_data();
@@ -377,13 +378,22 @@ void tst_Cmptest::compareQListDouble()
}
#ifdef QT_GUI_LIB
+void tst_Cmptest::compareQColor_data()
+{
+ QTest::addColumn<QColor>("colorA");
+ QTest::addColumn<QColor>("colorB");
+
+ QTest::newRow("Qt::yellow vs \"yellow\"") << QColor(Qt::yellow) << QColor(QStringLiteral("yellow"));
+ QTest::newRow("Qt::yellow vs Qt::green") << QColor(Qt::yellow) << QColor(Qt::green);
+ QTest::newRow("0x88ff0000 vs 0xffff0000") << QColor::fromRgba(0x88ff0000) << QColor::fromRgba(0xffff0000);
+}
+
void tst_Cmptest::compareQColor()
{
- const QColor yellow(Qt::yellow);
- const QColor yellowFromName(QStringLiteral("yellow"));
- const QColor green(Qt::green);
- QCOMPARE(yellow, yellowFromName);
- QCOMPARE(yellow, green);
+ QFETCH(QColor, colorA);
+ QFETCH(QColor, colorB);
+
+ QCOMPARE(colorA, colorB);
}
void tst_Cmptest::compareQPixmaps_data()
diff --git a/tests/auto/testlib/selftests/expected_cmptest.lightxml b/tests/auto/testlib/selftests/expected_cmptest.lightxml
index 41cfb03f18..d47967a445 100644
--- a/tests/auto/testlib/selftests/expected_cmptest.lightxml
+++ b/tests/auto/testlib/selftests/expected_cmptest.lightxml
@@ -127,10 +127,20 @@
<Duration msecs="0"/>
</TestFunction>
<TestFunction name="compareQColor">
+<Incident type="pass" file="" line="0">
+ <DataTag><![CDATA[Qt::yellow vs "yellow"]]></DataTag>
+</Incident>
+<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
+ <DataTag><![CDATA[Qt::yellow vs Qt::green]]></DataTag>
+ <Description><![CDATA[Compared values are not the same
+ Actual (colorA): #ffffff00
+ Expected (colorB): #ff00ff00]]></Description>
+</Incident>
<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
+ <DataTag><![CDATA[0x88ff0000 vs 0xffff0000]]></DataTag>
<Description><![CDATA[Compared values are not the same
- Actual (yellow): #ffff00
- Expected (green) : #00ff00]]></Description>
+ Actual (colorA): #88ff0000
+ Expected (colorB): #ffff0000]]></Description>
</Incident>
<Duration msecs="0"/>
</TestFunction>
diff --git a/tests/auto/testlib/selftests/expected_cmptest.teamcity b/tests/auto/testlib/selftests/expected_cmptest.teamcity
index bb94fe3f50..a0dc509279 100644
--- a/tests/auto/testlib/selftests/expected_cmptest.teamcity
+++ b/tests/auto/testlib/selftests/expected_cmptest.teamcity
@@ -55,9 +55,14 @@
##teamcity[testStarted name='compareQListDouble()' flowId='tst_Cmptest']
##teamcity[testFailed name='compareQListDouble()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)|]' details='Compared lists differ at index 0.|n Actual (double1): 1.5|n Expected (double2): 1' flowId='tst_Cmptest']
##teamcity[testFinished name='compareQListDouble()' flowId='tst_Cmptest']
-##teamcity[testStarted name='compareQColor()' flowId='tst_Cmptest']
-##teamcity[testFailed name='compareQColor()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)|]' details='Compared values are not the same|n Actual (yellow): #ffff00|n Expected (green) : #00ff00' flowId='tst_Cmptest']
-##teamcity[testFinished name='compareQColor()' flowId='tst_Cmptest']
+##teamcity[testStarted name='compareQColor(Qt::yellow vs "yellow")' flowId='tst_Cmptest']
+##teamcity[testFinished name='compareQColor(Qt::yellow vs "yellow")' flowId='tst_Cmptest']
+##teamcity[testStarted name='compareQColor(Qt::yellow vs Qt::green)' flowId='tst_Cmptest']
+##teamcity[testFailed name='compareQColor(Qt::yellow vs Qt::green)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)|]' details='Compared values are not the same|n Actual (colorA): #ffffff00|n Expected (colorB): #ff00ff00' flowId='tst_Cmptest']
+##teamcity[testFinished name='compareQColor(Qt::yellow vs Qt::green)' flowId='tst_Cmptest']
+##teamcity[testStarted name='compareQColor(0x88ff0000 vs 0xffff0000)' flowId='tst_Cmptest']
+##teamcity[testFailed name='compareQColor(0x88ff0000 vs 0xffff0000)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)|]' details='Compared values are not the same|n Actual (colorA): #88ff0000|n Expected (colorB): #ffff0000' flowId='tst_Cmptest']
+##teamcity[testFinished name='compareQColor(0x88ff0000 vs 0xffff0000)' flowId='tst_Cmptest']
##teamcity[testStarted name='compareQPixmaps(both null)' flowId='tst_Cmptest']
##teamcity[testFinished name='compareQPixmaps(both null)' flowId='tst_Cmptest']
##teamcity[testStarted name='compareQPixmaps(one null)' flowId='tst_Cmptest']
diff --git a/tests/auto/testlib/selftests/expected_cmptest.txt b/tests/auto/testlib/selftests/expected_cmptest.txt
index c833bf6d81..78df990dea 100644
--- a/tests/auto/testlib/selftests/expected_cmptest.txt
+++ b/tests/auto/testlib/selftests/expected_cmptest.txt
@@ -61,9 +61,14 @@ FAIL! : tst_Cmptest::compareQListDouble() Compared lists differ at index 0.
Actual (double1): 1.5
Expected (double2): 1
Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)]
-FAIL! : tst_Cmptest::compareQColor() Compared values are not the same
- Actual (yellow): #ffff00
- Expected (green) : #00ff00
+PASS : tst_Cmptest::compareQColor(Qt::yellow vs "yellow")
+FAIL! : tst_Cmptest::compareQColor(Qt::yellow vs Qt::green) Compared values are not the same
+ Actual (colorA): #ffffff00
+ Expected (colorB): #ff00ff00
+ Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)]
+FAIL! : tst_Cmptest::compareQColor(0x88ff0000 vs 0xffff0000) Compared values are not the same
+ Actual (colorA): #88ff0000
+ Expected (colorB): #ffff0000
Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)]
PASS : tst_Cmptest::compareQPixmaps(both null)
FAIL! : tst_Cmptest::compareQPixmaps(one null) Compared QPixmaps differ.
@@ -133,5 +138,5 @@ FAIL! : tst_Cmptest::tryVerify2() 'opaqueFunc() < 2' returned FALSE. (42)
Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)]
PASS : tst_Cmptest::verifyExplicitOperatorBool()
PASS : tst_Cmptest::cleanupTestCase()
-Totals: 15 passed, 33 failed, 0 skipped, 0 blacklisted, 0ms
+Totals: 16 passed, 34 failed, 0 skipped, 0 blacklisted, 0ms
********* Finished testing of tst_Cmptest *********
diff --git a/tests/auto/testlib/selftests/expected_cmptest.xml b/tests/auto/testlib/selftests/expected_cmptest.xml
index 12d8263e55..01b725f247 100644
--- a/tests/auto/testlib/selftests/expected_cmptest.xml
+++ b/tests/auto/testlib/selftests/expected_cmptest.xml
@@ -129,10 +129,20 @@
<Duration msecs="0"/>
</TestFunction>
<TestFunction name="compareQColor">
+<Incident type="pass" file="" line="0">
+ <DataTag><![CDATA[Qt::yellow vs "yellow"]]></DataTag>
+</Incident>
+<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
+ <DataTag><![CDATA[Qt::yellow vs Qt::green]]></DataTag>
+ <Description><![CDATA[Compared values are not the same
+ Actual (colorA): #ffffff00
+ Expected (colorB): #ff00ff00]]></Description>
+</Incident>
<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0">
+ <DataTag><![CDATA[0x88ff0000 vs 0xffff0000]]></DataTag>
<Description><![CDATA[Compared values are not the same
- Actual (yellow): #ffff00
- Expected (green) : #00ff00]]></Description>
+ Actual (colorA): #88ff0000
+ Expected (colorB): #ffff0000]]></Description>
</Incident>
<Duration msecs="0"/>
</TestFunction>
diff --git a/tests/auto/testlib/selftests/expected_cmptest.xunitxml b/tests/auto/testlib/selftests/expected_cmptest.xunitxml
index c2c0c86058..812696ffcf 100644
--- a/tests/auto/testlib/selftests/expected_cmptest.xunitxml
+++ b/tests/auto/testlib/selftests/expected_cmptest.xunitxml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<testsuite errors="0" failures="33" tests="24" name="tst_Cmptest">
+<testsuite errors="0" failures="34" tests="24" name="tst_Cmptest">
<properties>
<property value="@INSERT_QT_VERSION_HERE@" name="QTestVersion"/>
<property value="@INSERT_QT_VERSION_HERE@" name="QtVersion"/>
@@ -64,9 +64,12 @@
Expected (double2): 1" result="fail"/>
</testcase>
<testcase result="fail" name="compareQColor">
- <failure message="Compared values are not the same
- Actual (yellow): #ffff00
- Expected (green) : #00ff00" result="fail"/>
+ <failure tag="Qt::yellow vs Qt::green" message="Compared values are not the same
+ Actual (colorA): #ffffff00
+ Expected (colorB): #ff00ff00" result="fail"/>
+ <failure tag="0x88ff0000 vs 0xffff0000" message="Compared values are not the same
+ Actual (colorA): #88ff0000
+ Expected (colorB): #ffff0000" result="fail"/>
</testcase>
<testcase result="fail" name="compareQPixmaps">
<failure tag="one null" message="Compared QPixmaps differ.
diff --git a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp
index 09e070ac20..eafd4d7cea 100644
--- a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp
+++ b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp
@@ -48,6 +48,7 @@
#include <qlineedit.h>
#include <qlayout.h>
#include <qmenu.h>
+#include <qrandom.h>
#include "../../../../../src/widgets/dialogs/qsidebar_p.h"
#include "../../../../../src/widgets/dialogs/qfilesystemmodel_p.h"
#include "../../../../../src/widgets/dialogs/qfiledialog_p.h"
@@ -1196,7 +1197,7 @@ void tst_QFileDialog2::QTBUG6558_showDirsOnly()
{
const QString tempPath = tempDir.path();
QDir dirTemp(tempPath);
- const QString tempName = QLatin1String("showDirsOnly.") + QString::number(qrand());
+ const QString tempName = QLatin1String("showDirsOnly.") + QString::number(QRandomGenerator::global()->generate());
dirTemp.mkdir(tempName);
dirTemp.cd(tempName);
QTRY_VERIFY(dirTemp.exists());
diff --git a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp
index db86fba59c..6ad93b2666 100644
--- a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp
+++ b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp
@@ -96,6 +96,7 @@ private slots:
void task248107_backButton();
void task255350_fieldObjectDestroyed();
void taskQTBUG_25691_fieldObjectDestroyed2();
+ void taskQTBUG_46894_nextButtonShortcut();
/*
Things that could be added:
@@ -2700,5 +2701,24 @@ void tst_QWizard::taskQTBUG_25691_fieldObjectDestroyed2()
::taskQTBUG_25691_fieldObjectDestroyed2();
}
+void tst_QWizard::taskQTBUG_46894_nextButtonShortcut()
+{
+ for (int i = 0; i < QWizard::NStyles; ++i) {
+ QWizard wizard;
+ QWizard::WizardStyle style = static_cast<QWizard::WizardStyle>(i);
+ wizard.setWizardStyle(style);
+ wizard.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&wizard));
+
+ if (wizard.button(QWizard::NextButton)->text() == "&Next") {
+ QCOMPARE(wizard.button(QWizard::NextButton)->shortcut(),
+ QKeySequence(Qt::ALT | Qt::Key_Right));
+ } else {
+ QCOMPARE(wizard.button(QWizard::NextButton)->shortcut(),
+ QKeySequence::mnemonic(wizard.button(QWizard::NextButton)->text()));
+ }
+ }
+}
+
QTEST_MAIN(tst_QWizard)
#include "tst_qwizard.moc"
diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/qgraphicsitem.pro b/tests/auto/widgets/graphicsview/qgraphicsitem/qgraphicsitem.pro
index 88526144fc..ae6de48195 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsitem/qgraphicsitem.pro
+++ b/tests/auto/widgets/graphicsview/qgraphicsitem/qgraphicsitem.pro
@@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qgraphicsitem
-QT += widgets widgets-private testlib
+QT += widgets widgets-private testlib testlib-private
QT += core-private gui-private
SOURCES += tst_qgraphicsitem.cpp
DEFINES += QT_NO_CAST_TO_ASCII
diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp
index 2599718651..26831002ce 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -28,10 +28,12 @@
#include <QtTest/QtTest>
+#include <QtTest/private/qtesthelpers_p.h>
#include <private/qgraphicsitem_p.h>
#include <private/qgraphicsview_p.h>
#include <private/qgraphicsscene_p.h>
+#include <QRandomGenerator>
#include <QStyleOptionGraphicsItem>
#include <QAbstractTextDocumentLayout>
#include <QBitmap>
@@ -127,17 +129,6 @@ static void sendKeyClick(QGraphicsScene *scene, Qt::Key key)
sendKeyRelease(scene, key);
}
-static inline void centerOnScreen(QWidget *w, const QSize &size)
-{
- const QPoint offset = QPoint(size.width() / 2, size.height() / 2);
- w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset);
-}
-
-static inline void centerOnScreen(QWidget *w)
-{
- centerOnScreen(w, w->geometry().size());
-}
-
class EventSpy : public QGraphicsWidget
{
Q_OBJECT
@@ -3595,12 +3586,12 @@ void tst_QGraphicsItem::group()
QList<QGraphicsItem *> newItems;
for (int i = 0; i < 100; ++i) {
QGraphicsItem *item = scene.addRect(QRectF(-25, -25, 50, 50), QPen(Qt::black, 0),
- QBrush(QColor(rand() % 255, rand() % 255,
- rand() % 255, rand() % 255)));
+ QBrush(QColor(QRandomGenerator::global()->bounded(255), QRandomGenerator::global()->bounded(255),
+ QRandomGenerator::global()->bounded(255), QRandomGenerator::global()->bounded(255))));
newItems << item;
- item->setPos(-1000 + rand() % 2000,
- -1000 + rand() % 2000);
- item->setTransform(QTransform().rotate(rand() % 90), true);
+ item->setPos(-1000 + QRandomGenerator::global()->bounded(2000),
+ -1000 + QRandomGenerator::global()->bounded(2000));
+ item->setTransform(QTransform().rotate(QRandomGenerator::global()->bounded(90)), true);
}
view.fitInView(scene.itemsBoundingRect());
@@ -4143,8 +4134,8 @@ void tst_QGraphicsItem::ensureVisible()
for (int x = -100; x < 100; x += 25) {
for (int y = -100; y < 100; y += 25) {
- int xmargin = rand() % 75;
- int ymargin = rand() % 75;
+ int xmargin = QRandomGenerator::global()->bounded(75);
+ int ymargin = QRandomGenerator::global()->bounded(75);
item->ensureVisible(x, y, 25, 25, xmargin, ymargin);
QApplication::processEvents();
@@ -4211,7 +4202,7 @@ void tst_QGraphicsItem::cursor()
QWidget topLevel;
topLevel.resize(250, 150);
- centerOnScreen(&topLevel);
+ QTestPrivate::centerOnScreen(&topLevel);
QGraphicsView view(&scene,&topLevel);
view.setFixedSize(200, 100);
topLevel.show();
@@ -7137,7 +7128,7 @@ public:
: QGraphicsRectItem(QRectF(-10, -10, 20, 20))
{
setPen(QPen(Qt::black, 0));
- setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256));
+ setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
}
QTransform x;
diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp
index 6e4da153d2..539580f628 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp
@@ -1507,10 +1507,10 @@ void tst_QGraphicsScene::mouseGrabberItem()
QCOMPARE(scene.mouseGrabberItem(), topMostItem);
// Geometrical changes should not affect the mouse grabber.
- item->setZValue(rand() % 500);
- item2->setZValue(rand() % 500);
- item->setPos(rand() % 50000, rand() % 50000);
- item2->setPos(rand() % 50000, rand() % 50000);
+ item->setZValue(QRandomGenerator::global()->bounded(500));
+ item2->setZValue(QRandomGenerator::global()->bounded(500));
+ item->setPos(QRandomGenerator::global()->bounded(50000), QRandomGenerator::global()->bounded(50000));
+ item2->setPos(QRandomGenerator::global()->bounded(50000), QRandomGenerator::global()->bounded(50000));
}
QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease);
@@ -3424,7 +3424,7 @@ void tst_QGraphicsScene::task139710_bspTreeCrash()
// add 1000 more items - the BSP tree is now resized
for (int i = 0; i < 1000; ++i) {
QGraphicsRectItem *item = scene.addRect(QRectF(0, 0, 200, 200));
- item->setPos(qrand() % 10000, qrand() % 10000);
+ item->setPos(QRandomGenerator::global()->bounded(10000), QRandomGenerator::global()->bounded(10000));
}
// trigger delayed item indexing for the first 1000 items
@@ -3433,7 +3433,7 @@ void tst_QGraphicsScene::task139710_bspTreeCrash()
// add 1000 more items - the BSP tree is now resized
for (int i = 0; i < 1000; ++i) {
QGraphicsRectItem *item = scene.addRect(QRectF(0, 0, 200, 200));
- item->setPos(qrand() % 10000, qrand() % 10000);
+ item->setPos(QRandomGenerator::global()->bounded(10000), QRandomGenerator::global()->bounded(10000));
}
// get items from the BSP tree and use them. there was junk in the tree
@@ -3543,15 +3543,15 @@ void tst_QGraphicsScene::sorting()
QGraphicsRectItem *c_2_1 = new QGraphicsRectItem(0, 0, 30, 30, c_2);
QGraphicsRectItem *c_2_1_1 = new QGraphicsRectItem(0, 0, 20, 20, c_2_1);
QGraphicsRectItem *c_2_2 = new QGraphicsRectItem(0, 0, 30, 30, c_2);
- t_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256));
- c_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256));
- c_1_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256));
- c_1_1_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256));
- c_1_2->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256));
- c_2->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256));
- c_2_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256));
- c_2_1_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256));
- c_2_2->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256));
+ t_1->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
+ c_1->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
+ c_1_1->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
+ c_1_1_1->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
+ c_1_2->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
+ c_2->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
+ c_2_1->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
+ c_2_1_1->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
+ c_2_2->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
c_1->setPos(23, 18);
c_1_1->setPos(24, 28);
diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/qgraphicsview.pro b/tests/auto/widgets/graphicsview/qgraphicsview/qgraphicsview.pro
index 258b5e0e14..8ed19697a4 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsview/qgraphicsview.pro
+++ b/tests/auto/widgets/graphicsview/qgraphicsview/qgraphicsview.pro
@@ -3,7 +3,7 @@ testcase.timeout = 500 # this test is slow
TARGET = tst_qgraphicsview
QT += widgets widgets-private testlib
-QT += core-private gui-private
+QT += core-private gui-private testlib-private
SOURCES += tst_qgraphicsview.cpp tst_qgraphicsview_2.cpp
HEADERS += tst_qgraphicsview.h
diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
index ac38819385..f624bb6a5f 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
@@ -61,6 +61,10 @@
#include "tst_qgraphicsview.h"
+#include <QtTest/private/qtesthelpers_p.h>
+
+using namespace QTestPrivate;
+
Q_DECLARE_METATYPE(ExpectedValueDescription)
Q_DECLARE_METATYPE(QList<int>)
Q_DECLARE_METATYPE(QList<QRectF>)
@@ -130,14 +134,6 @@ class FriendlyGraphicsScene : public QGraphicsScene
};
#endif
-static inline void setFrameless(QWidget *w)
-{
- Qt::WindowFlags flags = w->windowFlags();
- flags |= Qt::FramelessWindowHint;
- flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
- w->setWindowFlags(flags);
-}
-
class tst_QGraphicsView : public QObject
{
Q_OBJECT
diff --git a/tests/auto/widgets/itemviews/qabstractitemview/qabstractitemview.pro b/tests/auto/widgets/itemviews/qabstractitemview/qabstractitemview.pro
index 2f0ca73265..4ee7f28af6 100644
--- a/tests/auto/widgets/itemviews/qabstractitemview/qabstractitemview.pro
+++ b/tests/auto/widgets/itemviews/qabstractitemview/qabstractitemview.pro
@@ -1,4 +1,4 @@
CONFIG += testcase
TARGET = tst_qabstractitemview
-QT += widgets testlib
+QT += widgets testlib testlib-private
SOURCES += tst_qabstractitemview.cpp
diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
index 7811c13ee1..f6723ceba4 100644
--- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
+++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
@@ -28,6 +28,7 @@
#include <QtTest/QtTest>
+#include <QtTest/private/qtesthelpers_p.h>
#include <qabstractitemview.h>
#include <qstandarditemmodel.h>
@@ -57,19 +58,7 @@
Q_DECLARE_METATYPE(Qt::ItemFlags);
-static inline void setFrameless(QWidget *w)
-{
- Qt::WindowFlags flags = w->windowFlags();
- flags |= Qt::FramelessWindowHint;
- flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
- w->setWindowFlags(flags);
-}
-
-static inline void centerOnScreen(QWidget *w)
-{
- const QPoint offset = QPoint(w->width() / 2, w->height() / 2);
- w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset);
-}
+using namespace QTestPrivate;
// Move cursor out of widget area to avoid undesired interaction on Mac.
static inline void moveCursorAway(const QWidget *topLevel)
diff --git a/tests/auto/widgets/itemviews/qcolumnview/qcolumnview.pro b/tests/auto/widgets/itemviews/qcolumnview/qcolumnview.pro
index 5096cc691a..0b3dcd9e80 100644
--- a/tests/auto/widgets/itemviews/qcolumnview/qcolumnview.pro
+++ b/tests/auto/widgets/itemviews/qcolumnview/qcolumnview.pro
@@ -1,6 +1,6 @@
CONFIG += testcase
QT += widgets widgets-private
-QT += gui-private core-private testlib
+QT += gui-private core-private testlib testlib-private
SOURCES += tst_qcolumnview.cpp
HEADERS += ../../../../shared/fakedirmodel.h
diff --git a/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp b/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp
index 62acf49f4a..38e6d95ba4 100644
--- a/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp
+++ b/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp
@@ -28,6 +28,7 @@
#include "../../../../shared/fakedirmodel.h"
#include <QtTest/QtTest>
+#include <QtTest/private/qtesthelpers_p.h>
#include <qitemdelegate.h>
#include <qcolumnview.h>
#include <private/qcolumnviewgrip_p.h>
@@ -369,12 +370,6 @@ void tst_QColumnView::scrollTo_data()
QTest::newRow("reverse") << true << false;
}
-static inline void centerOnScreen(QWidget *w)
-{
- const QPoint offset = QPoint(w->width() / 2, w->height() / 2);
- w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset);
-}
-
void tst_QColumnView::scrollTo()
{
QFETCH(bool, reverse);
@@ -386,7 +381,7 @@ void tst_QColumnView::scrollTo()
view.resize(200, 200);
topLevel.show();
topLevel.activateWindow();
- centerOnScreen(&topLevel);
+ QTestPrivate::centerOnScreen(&topLevel);
QVERIFY(QTest::qWaitForWindowActive(&topLevel));
view.scrollTo(QModelIndex(), QAbstractItemView::EnsureVisible);
@@ -1004,7 +999,7 @@ void tst_QColumnView::dynamicModelChanges()
ColumnView view;
view.setModel(&model);
view.setItemDelegate(&delegate);
- centerOnScreen(&view);
+ QTestPrivate::centerOnScreen(&view);
view.show();
QStandardItem *item = new QStandardItem(QLatin1String("item"));
diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
index fea41f64a3..f2279ea4d4 100644
--- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
@@ -3006,6 +3006,7 @@ void tst_QHeaderView::stretchAndRestoreLastSection()
tv.setModel(&m);
tv.showMaximized();
+ const int minimumSectionSize = 20;
const int defaultSectionSize = 30;
const int someOtherSectionSize = 40;
const int biggerSizeThanAnySection = 50;
@@ -3013,6 +3014,9 @@ void tst_QHeaderView::stretchAndRestoreLastSection()
QVERIFY(QTest::qWaitForWindowExposed(&tv));
QHeaderView &header = *tv.horizontalHeader();
+ // set minimum size before resizeSections() is called
+ // which is done inside setStretchLastSection
+ header.setMinimumSectionSize(minimumSectionSize);
header.setDefaultSectionSize(defaultSectionSize);
header.resizeSection(9, someOtherSectionSize);
header.setStretchLastSection(true);
diff --git a/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp b/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp
index 1fd7b31e22..f1239b2e7c 100644
--- a/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp
+++ b/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp
@@ -30,16 +30,6 @@
#include <QtTest/QtTest>
#include <QtCore/QtCore>
#include "viewstotest.cpp"
-#include <stdlib.h>
-
-#if defined(Q_OS_UNIX) || defined(Q_OS_WIN)
-#include <time.h>
-#endif
-
-#if defined(Q_OS_WIN)
-# define random rand
-# define srandom srand
-#endif
/*!
See viewstotest.cpp for instructions on how to have your view tested with these tests.
@@ -410,13 +400,15 @@ void touch(QWidget *widget, Qt::KeyboardModifier modifier, Qt::Key keyPress){
int width = widget->width();
int height = widget->height();
for (int i = 0; i < 5; ++i) {
- QTest::mouseClick(widget, Qt::LeftButton, modifier, QPoint(random() % width, random() % height));
- QTest::mouseDClick(widget, Qt::LeftButton, modifier, QPoint(random() % width, random() % height));
- QPoint press(random() % width, random() % height);
- QPoint releasePoint(random() % width, random() % height);
+ QTest::mouseClick(widget, Qt::LeftButton, modifier,
+ QPoint(QRandomGenerator::global()->bounded(width), QRandomGenerator::global()->bounded(height)));
+ QTest::mouseDClick(widget, Qt::LeftButton, modifier,
+ QPoint(QRandomGenerator::global()->bounded(width), QRandomGenerator::global()->bounded(height)));
+ QPoint press(QRandomGenerator::global()->bounded(width), QRandomGenerator::global()->bounded(height));
+ QPoint releasePoint(QRandomGenerator::global()->bounded(width), QRandomGenerator::global()->bounded(height));
QTest::mousePress(widget, Qt::LeftButton, modifier, press);
QTest::mouseMove(widget, releasePoint);
- if (random() % 1 == 0)
+ if (QRandomGenerator::global()->bounded(1) == 0)
QTest::mouseRelease(widget, Qt::LeftButton, 0, releasePoint);
else
QTest::mouseRelease(widget, Qt::LeftButton, modifier, releasePoint);
@@ -443,7 +435,6 @@ void tst_QItemView::spider()
view->setModel(treeModel);
view->show();
QVERIFY(QTest::qWaitForWindowActive(view));
- srandom(time(0));
touch(view->viewport(), Qt::NoModifier, Qt::Key_Left);
touch(view->viewport(), Qt::ShiftModifier, Qt::Key_Enter);
touch(view->viewport(), Qt::ControlModifier, Qt::Key_Backspace);
diff --git a/tests/auto/widgets/itemviews/qlistview/qlistview.pro b/tests/auto/widgets/itemviews/qlistview/qlistview.pro
index 44e25ded66..e49a0c5fbf 100644
--- a/tests/auto/widgets/itemviews/qlistview/qlistview.pro
+++ b/tests/auto/widgets/itemviews/qlistview/qlistview.pro
@@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qlistview
-QT += widgets gui-private widgets-private core-private testlib
+QT += widgets gui-private widgets-private core-private testlib testlib-private
SOURCES += tst_qlistview.cpp
win32:!winrt: LIBS += -luser32
linux*: CONFIG += insignificant_test # Crashes
diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
index 59895e4e7d..1d8286b3cf 100644
--- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
+++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
@@ -46,6 +46,10 @@
#include <QtWidgets/QStyleFactory>
#include <QtWidgets/QVBoxLayout>
+#include <QtTest/private/qtesthelpers_p.h>
+
+using namespace QTestPrivate;
+
#if defined(Q_OS_WIN)
# include <windows.h>
# include <QtGui/QGuiApplication>
@@ -64,16 +68,6 @@ Q_DECLARE_METATYPE(QAbstractItemView::ScrollMode)
Q_DECLARE_METATYPE(QMargins)
Q_DECLARE_METATYPE(QSize)
-// Make a widget frameless to prevent size constraints of title bars
-// from interfering (Windows).
-static inline void setFrameless(QWidget *w)
-{
- Qt::WindowFlags flags = w->windowFlags();
- flags |= Qt::FramelessWindowHint;
- flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
- w->setWindowFlags(flags);
-}
-
static QStringList generateList(const QString &prefix, int size)
{
QStringList result;
diff --git a/tests/auto/widgets/itemviews/qtableview/qtableview.pro b/tests/auto/widgets/itemviews/qtableview/qtableview.pro
index e02da95ab9..a02f96eb99 100644
--- a/tests/auto/widgets/itemviews/qtableview/qtableview.pro
+++ b/tests/auto/widgets/itemviews/qtableview/qtableview.pro
@@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qtableview
QT += widgets widgets-private testlib
-QT += core-private gui-private
+QT += core-private gui-private testlib-private
SOURCES += tst_qtableview.cpp
diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
index a27e0b6048..4e401ddd86 100644
--- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
+++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
@@ -35,6 +35,10 @@
#include <algorithm>
+#include <QtTest/private/qtesthelpers_p.h>
+
+using namespace QTestPrivate;
+
#ifdef QT_BUILD_INTERNAL
#define VERIFY_SPANS_CONSISTENCY(TEST_VIEW_) \
QVERIFY(static_cast<QTableViewPrivate*>(QObjectPrivate::get(TEST_VIEW_))->spans.checkConsistency())
@@ -46,16 +50,6 @@ typedef QList<int> IntList;
typedef QList<bool> BoolList;
-// Make a widget frameless to prevent size constraints of title bars
-// from interfering (Windows).
-static inline void setFrameless(QWidget *w)
-{
- Qt::WindowFlags flags = w->windowFlags();
- flags |= Qt::FramelessWindowHint;
- flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
- w->setWindowFlags(flags);
-}
-
class tst_QTableView : public QObject
{
Q_OBJECT
diff --git a/tests/auto/widgets/itemviews/qtreeview/qtreeview.pro b/tests/auto/widgets/itemviews/qtreeview/qtreeview.pro
index 3abd58e73d..2530b44935 100644
--- a/tests/auto/widgets/itemviews/qtreeview/qtreeview.pro
+++ b/tests/auto/widgets/itemviews/qtreeview/qtreeview.pro
@@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qtreeview
QT += widgets testlib
-QT += widgets-private gui-private core-private
+QT += widgets-private gui-private core-private testlib-private
SOURCES += tst_qtreeview.cpp
HEADERS += ../../../../shared/fakedirmodel.h
diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
index 3a676f1275..1d82081bec 100644
--- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
+++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
@@ -33,6 +33,10 @@
#include <QtWidgets/QtWidgets>
#include <private/qtreeview_p.h>
+#include <QtTest/private/qtesthelpers_p.h>
+
+using namespace QTestPrivate;
+
#ifndef QT_NO_DRAGANDDROP
Q_DECLARE_METATYPE(QAbstractItemView::DragDropMode)
#endif
@@ -57,16 +61,6 @@ static void initStandardTreeModel(QStandardItemModel *model)
model->insertRow(2, item);
}
-// Make a widget frameless to prevent size constraints of title bars
-// from interfering (Windows).
-static inline void setFrameless(QWidget *w)
-{
- Qt::WindowFlags flags = w->windowFlags();
- flags |= Qt::FramelessWindowHint;
- flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
- w->setWindowFlags(flags);
-}
-
class tst_QTreeView : public QObject
{
Q_OBJECT
@@ -215,12 +209,14 @@ public:
QtTestModel(int _rows, int _cols, QObject *parent = 0): QAbstractItemModel(parent),
fetched(false), rows(_rows), cols(_cols), levels(INT_MAX), wrongIndex(false) { init(); }
- void init() {
+ void init()
+ {
decorationsEnabled = false;
statusTipsEnabled = false;
}
- inline qint32 level(const QModelIndex &index) const {
+ inline qint32 level(const QModelIndex &index) const
+ {
return index.isValid() ? qint32(index.internalId()) : qint32(-1);
}
@@ -252,7 +248,8 @@ public:
return cols;
}
- bool isEditable(const QModelIndex &index) const {
+ bool isEditable(const QModelIndex &index) const
+ {
if (index.isValid())
return true;
return false;
diff --git a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp
index 2eb8c17359..272ec6d60b 100644
--- a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp
+++ b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp
@@ -26,7 +26,8 @@
**
****************************************************************************/
-
+#include <QDialog>
+#include <QMainWindow>
#include <QtTest/QtTest>
#include <qapplication.h>
@@ -62,7 +63,10 @@ private slots:
void task229128TriggeredSignalWithoutActiongroup();
void task229128TriggeredSignalWhenInActiongroup();
void repeat();
+ void setData();
void keysequence(); // QTBUG-53381
+ void disableShortcutsWithBlockedWidgets_data();
+ void disableShortcutsWithBlockedWidgets();
private:
int m_lastEventType;
@@ -443,5 +447,67 @@ void tst_QAction::repeat()
QCOMPARE(spy.count(), 2);
}
+void tst_QAction::setData() // QTBUG-62006
+{
+ QAction act(nullptr);
+ QSignalSpy spy(&act, &QAction::changed);
+ QCOMPARE(act.data(), QVariant());
+ QCOMPARE(spy.count(), 0);
+ act.setData(QVariant());
+ QCOMPARE(spy.count(), 0);
+
+ act.setData(-1);
+ QCOMPARE(spy.count(), 1);
+ act.setData(-1);
+ QCOMPARE(spy.count(), 1);
+}
+
+void tst_QAction::disableShortcutsWithBlockedWidgets_data()
+{
+ QTest::addColumn<Qt::ShortcutContext>("shortcutContext");
+ QTest::addColumn<Qt::WindowModality>("windowModality");
+
+ QTest::newRow("application modal dialog should block window shortcut.")
+ << Qt::WindowShortcut << Qt::ApplicationModal;
+
+ QTest::newRow("application modal dialog should block application shortcut.")
+ << Qt::ApplicationShortcut << Qt::ApplicationModal;
+
+ QTest::newRow("window modal dialog should block application shortcut.")
+ << Qt::ApplicationShortcut << Qt::WindowModal;
+
+ QTest::newRow("window modal dialog should block window shortcut.")
+ << Qt::WindowShortcut << Qt::WindowModal;
+}
+
+
+void tst_QAction::disableShortcutsWithBlockedWidgets()
+{
+ QMainWindow window;
+
+ QFETCH(Qt::ShortcutContext, shortcutContext);
+ QAction action(&window);
+ window.addAction(&action);
+ action.setShortcut(QKeySequence(Qt::Key_1));
+ action.setShortcutContext(shortcutContext);
+
+ window.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
+
+ QDialog dialog(&window);
+ QFETCH(Qt::WindowModality, windowModality);
+ dialog.setWindowModality(windowModality);
+
+ dialog.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&dialog));
+
+ QApplication::setActiveWindow(&window);
+ QVERIFY(QTest::qWaitForWindowActive(&window));
+
+ QSignalSpy spy(&action, &QAction::triggered);
+ QTest::keyPress(&window, Qt::Key_1);
+ QCOMPARE(spy.count(), 0);
+}
+
QTEST_MAIN(tst_QAction)
#include "tst_qaction.moc"
diff --git a/tests/auto/widgets/kernel/qboxlayout/qboxlayout.pro b/tests/auto/widgets/kernel/qboxlayout/qboxlayout.pro
index 90e83f5285..1a2c6d6f66 100644
--- a/tests/auto/widgets/kernel/qboxlayout/qboxlayout.pro
+++ b/tests/auto/widgets/kernel/qboxlayout/qboxlayout.pro
@@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qboxlayout
-QT += widgets testlib
+QT += widgets testlib testlib-private
SOURCES += tst_qboxlayout.cpp
diff --git a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp
index 570caf851d..2f1a305710 100644
--- a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp
+++ b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp
@@ -31,13 +31,9 @@
#include <QtGui>
#include <QtWidgets>
-static inline void setFrameless(QWidget *w)
-{
- Qt::WindowFlags flags = w->windowFlags();
- flags |= Qt::FramelessWindowHint;
- flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
- w->setWindowFlags(flags);
-}
+#include <QtTest/private/qtesthelpers_p.h>
+
+using namespace QTestPrivate;
class tst_QBoxLayout : public QObject
{
diff --git a/tests/auto/widgets/kernel/qformlayout/qformlayout.pro b/tests/auto/widgets/kernel/qformlayout/qformlayout.pro
index be944605a3..617183fee6 100644
--- a/tests/auto/widgets/kernel/qformlayout/qformlayout.pro
+++ b/tests/auto/widgets/kernel/qformlayout/qformlayout.pro
@@ -1,4 +1,4 @@
CONFIG += testcase
TARGET = tst_qformlayout
-QT += widgets testlib
+QT += widgets testlib testlib-private
SOURCES += tst_qformlayout.cpp
diff --git a/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp b/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp
index c324a4bd56..1ccda25339 100644
--- a/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp
+++ b/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp
@@ -41,20 +41,16 @@
#include <QStyleFactory>
#include <QSharedPointer>
+#include <QtTest/private/qtesthelpers_p.h>
+
+using namespace QTestPrivate;
+
#include <qformlayout.h>
// ItemRole has enumerators for numerical values 0..2, thus the only
// valid numerical values for storing into an ItemRole variable are 0..3:
Q_CONSTEXPR QFormLayout::ItemRole invalidRole = QFormLayout::ItemRole(3);
-static inline void setFrameless(QWidget *w)
-{
- Qt::WindowFlags flags = w->windowFlags();
- flags |= Qt::FramelessWindowHint;
- flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
- w->setWindowFlags(flags);
-}
-
struct QFormLayoutTakeRowResultHolder {
QFormLayoutTakeRowResultHolder(QFormLayout::TakeRowResult result) Q_DECL_NOTHROW
: labelItem(result.labelItem),
diff --git a/tests/auto/widgets/kernel/qgridlayout/qgridlayout.pro b/tests/auto/widgets/kernel/qgridlayout/qgridlayout.pro
index ee64f8538f..8947658e8c 100644
--- a/tests/auto/widgets/kernel/qgridlayout/qgridlayout.pro
+++ b/tests/auto/widgets/kernel/qgridlayout/qgridlayout.pro
@@ -2,7 +2,7 @@ CONFIG += testcase
TARGET = tst_qgridlayout
QT += widgets widgets-private testlib
-QT += core-private gui-private
+QT += core-private gui-private testlib-private
SOURCES += tst_qgridlayout.cpp
FORMS += sortdialog.ui
diff --git a/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp b/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp
index 50de83c8f7..40a2319910 100644
--- a/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp
+++ b/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp
@@ -41,15 +41,9 @@
#include <QStyleFactory>
#include <QSharedPointer>
-// Make a widget frameless to prevent size constraints of title bars
-// from interfering (Windows).
-static inline void setFrameless(QWidget *w)
-{
- Qt::WindowFlags flags = w->windowFlags();
- flags |= Qt::FramelessWindowHint;
- flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
- w->setWindowFlags(flags);
-}
+#include <QtTest/private/qtesthelpers_p.h>
+
+using namespace QTestPrivate;
class tst_QGridLayout : public QObject
{
diff --git a/tests/auto/widgets/kernel/qlayout/qlayout.pro b/tests/auto/widgets/kernel/qlayout/qlayout.pro
index d460785158..8e0ea1bfdb 100644
--- a/tests/auto/widgets/kernel/qlayout/qlayout.pro
+++ b/tests/auto/widgets/kernel/qlayout/qlayout.pro
@@ -1,7 +1,7 @@
CONFIG += testcase
TARGET = tst_qlayout
-QT += widgets widgets-private testlib
+QT += widgets widgets-private testlib testlib-private
SOURCES += tst_qlayout.cpp
TESTDATA += baseline/*
diff --git a/tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp b/tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp
index 829d0ea098..a55693bb6c 100644
--- a/tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp
+++ b/tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp
@@ -44,13 +44,9 @@
#include <QRadioButton>
#include <private/qlayoutengine_p.h>
-static inline void setFrameless(QWidget *w)
-{
- Qt::WindowFlags flags = w->windowFlags();
- flags |= Qt::FramelessWindowHint;
- flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
- w->setWindowFlags(flags);
-}
+#include <QtTest/private/qtesthelpers_p.h>
+
+using namespace QTestPrivate;
class tst_QLayout : public QObject
{
diff --git a/tests/auto/widgets/kernel/qwidget/BLACKLIST b/tests/auto/widgets/kernel/qwidget/BLACKLIST
index 0b1d7b4437..4cef2d57a4 100644
--- a/tests/auto/widgets/kernel/qwidget/BLACKLIST
+++ b/tests/auto/widgets/kernel/qwidget/BLACKLIST
@@ -81,3 +81,5 @@ ubuntu-14.04
osx
[activateWindow]
osx-10.12 ci
+[multipleToplevelFocusCheck]
+linux
diff --git a/tests/auto/widgets/kernel/qwidget/qwidget.pro b/tests/auto/widgets/kernel/qwidget/qwidget.pro
index 0e95d454cf..c1908af2a2 100644
--- a/tests/auto/widgets/kernel/qwidget/qwidget.pro
+++ b/tests/auto/widgets/kernel/qwidget/qwidget.pro
@@ -2,7 +2,7 @@ CONFIG += testcase
testcase.timeout = 600 # this test is slow
TARGET = tst_qwidget
-QT += widgets core-private gui-private widgets-private testlib
+QT += widgets core-private gui-private widgets-private testlib testlib-private
SOURCES += tst_qwidget.cpp
RESOURCES = qwidget.qrc
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index df6eab7a45..d2c89e31c3 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -50,6 +50,7 @@
#include <qcalendarwidget.h>
#include <qmainwindow.h>
#include <qdockwidget.h>
+#include <qrandom.h>
#include <qtoolbar.h>
#include <qtoolbutton.h>
#include <QtGui/qpaintengine.h>
@@ -72,6 +73,9 @@
#endif
#include <QtTest/QTest>
+#include <QtTest/private/qtesthelpers_p.h>
+
+using namespace QTestPrivate;
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
# include <QtCore/qt_windows.h>
@@ -108,22 +112,6 @@ bool macHasAccessToWindowsServer()
}
#endif
-// Make a widget frameless to prevent size constraints of title bars
-// from interfering (Windows).
-static inline void setFrameless(QWidget *w)
-{
- Qt::WindowFlags flags = w->windowFlags();
- flags |= Qt::FramelessWindowHint;
- flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
- w->setWindowFlags(flags);
-}
-
-static inline void centerOnScreen(QWidget *w)
-{
- const QPoint offset = QPoint(w->width() / 2, w->height() / 2);
- w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset);
-}
-
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
static inline void setWindowsAnimationsEnabled(bool enabled)
{
@@ -5396,19 +5384,22 @@ void tst_QWidget::multipleToplevelFocusCheck()
TopLevelFocusCheck w1;
TopLevelFocusCheck w2;
+ const QString title = QLatin1String(QTest::currentTestFunction());
+ w1.setWindowTitle(title + QLatin1String("_W1"));
+ w1.move(m_availableTopLeft + QPoint(20, 20));
w1.resize(200, 200);
w1.show();
QVERIFY(QTest::qWaitForWindowExposed(&w1));
+ w2.setWindowTitle(title + QLatin1String("_W2"));
+ w2.move(w1.frameGeometry().topRight() + QPoint(20, 0));
w2.resize(200,200);
w2.show();
QVERIFY(QTest::qWaitForWindowExposed(&w2));
- QTest::qWait(50);
QApplication::setActiveWindow(&w1);
w1.activateWindow();
QVERIFY(QTest::qWaitForWindowActive(&w1));
QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&w1));
- QTest::qWait(50);
QTest::mouseDClick(&w1, Qt::LeftButton);
QTRY_COMPARE(QApplication::focusWidget(), static_cast<QWidget *>(w1.edit));
@@ -9826,7 +9817,7 @@ void tst_QWidget::grab()
for (int row = 0; row < image.height(); ++row) {
QRgb *line = reinterpret_cast<QRgb *>(image.scanLine(row));
for (int col = 0; col < image.width(); ++col)
- line[col] = qRgba(rand() & 255, row, col, opaque ? 255 : 127);
+ line[col] = qRgba(QRandomGenerator::global()->bounded(255), row, col, opaque ? 255 : 127);
}
QPalette pal = widget.palette();
diff --git a/tests/auto/widgets/kernel/qwidget_window/qwidget_window.pro b/tests/auto/widgets/kernel/qwidget_window/qwidget_window.pro
index a6248dfd16..00bf763c35 100644
--- a/tests/auto/widgets/kernel/qwidget_window/qwidget_window.pro
+++ b/tests/auto/widgets/kernel/qwidget_window/qwidget_window.pro
@@ -1,4 +1,4 @@
CONFIG += testcase
TARGET = tst_qwidget_window
-QT += widgets testlib core-private gui-private
+QT += widgets testlib core-private gui-private testlib-private
SOURCES += tst_qwidget_window.cpp
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 71faf99790..9021be1515 100644
--- a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp
+++ b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp
@@ -45,13 +45,9 @@
#include <qtoolbar.h>
#include <private/qwindow_p.h>
-static inline void setFrameless(QWidget *w)
-{
- Qt::WindowFlags flags = w->windowFlags();
- flags |= Qt::FramelessWindowHint;
- flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
- w->setWindowFlags(flags);
-}
+#include <QtTest/private/qtesthelpers_p.h>
+
+using namespace QTestPrivate;
class tst_QWidget_window : public QObject
{
diff --git a/tests/auto/widgets/kernel/qwidgetaction/qwidgetaction.pro b/tests/auto/widgets/kernel/qwidgetaction/qwidgetaction.pro
index e4158559a9..f443758eea 100644
--- a/tests/auto/widgets/kernel/qwidgetaction/qwidgetaction.pro
+++ b/tests/auto/widgets/kernel/qwidgetaction/qwidgetaction.pro
@@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qwidgetaction
-QT += widgets testlib
+QT += widgets testlib testlib-private
SOURCES += tst_qwidgetaction.cpp
diff --git a/tests/auto/widgets/kernel/qwidgetaction/tst_qwidgetaction.cpp b/tests/auto/widgets/kernel/qwidgetaction/tst_qwidgetaction.cpp
index 1824285f05..28731223a9 100644
--- a/tests/auto/widgets/kernel/qwidgetaction/tst_qwidgetaction.cpp
+++ b/tests/auto/widgets/kernel/qwidgetaction/tst_qwidgetaction.cpp
@@ -38,13 +38,9 @@
#include <qmainwindow.h>
#include <qmenubar.h>
-static inline void setFrameless(QWidget *w)
-{
- Qt::WindowFlags flags = w->windowFlags();
- flags |= Qt::FramelessWindowHint;
- flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
- w->setWindowFlags(flags);
-}
+#include <QtTest/private/qtesthelpers_p.h>
+
+using namespace QTestPrivate;
class tst_QWidgetAction : public QObject
{
diff --git a/tests/auto/widgets/styles/qstyle/qstyle.pro b/tests/auto/widgets/styles/qstyle/qstyle.pro
index a1e5a70a08..0fb7499946 100644
--- a/tests/auto/widgets/styles/qstyle/qstyle.pro
+++ b/tests/auto/widgets/styles/qstyle/qstyle.pro
@@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qstyle
-QT += widgets testlib
+QT += widgets testlib testlib-private
SOURCES += tst_qstyle.cpp
android {
diff --git a/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp b/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp
index 30177dfa86..e49fd701d6 100644
--- a/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp
+++ b/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp
@@ -60,15 +60,9 @@
#include <algorithm>
-// Make a widget frameless to prevent size constraints of title bars
-// from interfering (Windows).
-static inline void setFrameless(QWidget *w)
-{
- Qt::WindowFlags flags = w->windowFlags();
- flags |= Qt::FramelessWindowHint;
- flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
- w->setWindowFlags(flags);
-}
+#include <QtTest/private/qtesthelpers_p.h>
+
+using namespace QTestPrivate;
class tst_QStyle : public QObject
{
diff --git a/tests/auto/widgets/styles/qstylesheetstyle/qstylesheetstyle.pro b/tests/auto/widgets/styles/qstylesheetstyle/qstylesheetstyle.pro
index 7d9a8576d3..3bf1b94050 100644
--- a/tests/auto/widgets/styles/qstylesheetstyle/qstylesheetstyle.pro
+++ b/tests/auto/widgets/styles/qstylesheetstyle/qstylesheetstyle.pro
@@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qstylesheetstyle
-QT += widgets widgets-private gui-private testlib
+QT += widgets widgets-private gui-private testlib testlib-private
SOURCES += tst_qstylesheetstyle.cpp
RESOURCES += resources.qrc
diff --git a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
index 693b0b8aee..7953077152 100644
--- a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
+++ b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
@@ -33,12 +33,9 @@
#include <QMetaObject>
#include <private/qstylesheetstyle_p.h>
+#include <QtTest/private/qtesthelpers_p.h>
-static inline void centerOnScreen(QWidget *w)
-{
- const QPoint offset = QPoint(w->width() / 2, w->height() / 2);
- w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset);
-}
+using namespace QTestPrivate;
class tst_QStyleSheetStyle : public QObject
{
diff --git a/tests/auto/widgets/util/qcompleter/qcompleter.pro b/tests/auto/widgets/util/qcompleter/qcompleter.pro
index 19d8d500b8..fcdce93079 100644
--- a/tests/auto/widgets/util/qcompleter/qcompleter.pro
+++ b/tests/auto/widgets/util/qcompleter/qcompleter.pro
@@ -1,6 +1,6 @@
CONFIG += testcase
TEMPLATE = app
TARGET = tst_qcompleter
-QT += widgets testlib
+QT += widgets testlib testlib-private
SOURCES += tst_qcompleter.cpp
diff --git a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp
index af63e807ca..6fbb0fe5fa 100644
--- a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp
+++ b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp
@@ -34,15 +34,11 @@
#include <QList>
#include <QPointer>
+#include <QtTest/private/qtesthelpers_p.h>
+
#include "../../../../shared/filesystem.h"
-static inline void setFrameless(QWidget *w)
-{
- Qt::WindowFlags flags = w->windowFlags();
- flags |= Qt::FramelessWindowHint;
- flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
- w->setWindowFlags(flags);
-}
+using namespace QTestPrivate;
class CsvCompleter : public QCompleter
{
diff --git a/tests/auto/widgets/widgets/qabstractbutton/tst_qabstractbutton.cpp b/tests/auto/widgets/widgets/qabstractbutton/tst_qabstractbutton.cpp
index 9efa8cf47e..bc7756d32f 100644
--- a/tests/auto/widgets/widgets/qabstractbutton/tst_qabstractbutton.cpp
+++ b/tests/auto/widgets/widgets/qabstractbutton/tst_qabstractbutton.cpp
@@ -68,6 +68,7 @@ private slots:
void shortcutEvents();
void stopRepeatTimer();
+ void mouseReleased(); // QTBUG-53244
#ifdef QT_KEYPAD_NAVIGATION
void keyNavigation();
#endif
@@ -563,6 +564,37 @@ void tst_QAbstractButton::stopRepeatTimer()
QCOMPARE(button.timerEventCount(), 0);
}
+void tst_QAbstractButton::mouseReleased() // QTBUG-53244
+{
+ MyButton button(nullptr);
+ button.setObjectName("button");
+ button.setGeometry(0, 0, 20, 20);
+ QSignalSpy spyPress(&button, &QAbstractButton::pressed);
+ QSignalSpy spyRelease(&button, &QAbstractButton::released);
+
+ QTest::mousePress(&button, Qt::LeftButton);
+ QCOMPARE(spyPress.count(), 1);
+ QCOMPARE(button.isDown(), true);
+ QCOMPARE(spyRelease.count(), 0);
+
+ QTest::mouseClick(&button, Qt::RightButton);
+ QCOMPARE(spyPress.count(), 1);
+ QCOMPARE(button.isDown(), true);
+ QCOMPARE(spyRelease.count(), 0);
+
+ QPointF posOutOfWidget = QPointF(30, 30);
+ QMouseEvent me(QEvent::MouseMove,
+ posOutOfWidget, Qt::NoButton,
+ Qt::MouseButtons(Qt::LeftButton),
+ Qt::NoModifier); // mouse press and move
+
+ qApp->sendEvent(&button, &me);
+ // should emit released signal once mouse is dragging out of boundary
+ QCOMPARE(spyPress.count(), 1);
+ QCOMPARE(button.isDown(), false);
+ QCOMPARE(spyRelease.count(), 1);
+}
+
#ifdef QT_KEYPAD_NAVIGATION
void tst_QAbstractButton::keyNavigation()
{
diff --git a/tests/auto/widgets/widgets/qabstractslider/qabstractslider.pro b/tests/auto/widgets/widgets/qabstractslider/qabstractslider.pro
index 6453999786..95385e2172 100644
--- a/tests/auto/widgets/widgets/qabstractslider/qabstractslider.pro
+++ b/tests/auto/widgets/widgets/qabstractslider/qabstractslider.pro
@@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qabstractslider
-QT += widgets testlib
+QT += widgets testlib testlib-private
SOURCES += tst_qabstractslider.cpp
diff --git a/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp b/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp
index f0d74e7797..70ae453896 100644
--- a/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp
+++ b/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp
@@ -36,17 +36,13 @@
#include <QTime>
#include <QDebug>
+#include <QtTest/private/qtesthelpers_p.h>
+
+using namespace QTestPrivate;
+
// defined to be 120 by the wheel mouse vendors according to the docs
#define WHEEL_DELTA 120
-static inline void setFrameless(QWidget *w)
-{
- Qt::WindowFlags flags = w->windowFlags();
- flags |= Qt::FramelessWindowHint;
- flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
- w->setWindowFlags(flags);
-}
-
class Slider : public QAbstractSlider
{
public:
diff --git a/tests/auto/widgets/widgets/qabstractspinbox/qabstractspinbox.pro b/tests/auto/widgets/widgets/qabstractspinbox/qabstractspinbox.pro
index be758a8bdd..a4a6f84ee4 100644
--- a/tests/auto/widgets/widgets/qabstractspinbox/qabstractspinbox.pro
+++ b/tests/auto/widgets/widgets/qabstractspinbox/qabstractspinbox.pro
@@ -4,7 +4,7 @@
CONFIG += testcase
TARGET = tst_qabstractspinbox
-QT += widgets gui-private core-private testlib
+QT += widgets gui-private core-private testlib testlib-private
SOURCES += tst_qabstractspinbox.cpp
diff --git a/tests/auto/widgets/widgets/qabstractspinbox/tst_qabstractspinbox.cpp b/tests/auto/widgets/widgets/qabstractspinbox/tst_qabstractspinbox.cpp
index 3fb4863b0e..0ce3b4cefe 100644
--- a/tests/auto/widgets/widgets/qabstractspinbox/tst_qabstractspinbox.cpp
+++ b/tests/auto/widgets/widgets/qabstractspinbox/tst_qabstractspinbox.cpp
@@ -28,6 +28,7 @@
#include <QtTest/QtTest>
+#include <QtTest/private/qtesthelpers_p.h>
#include <qcoreapplication.h>
#include <qdebug.h>
@@ -38,16 +39,6 @@
#include "../../../shared/platforminputcontext.h"
#include <private/qinputmethod_p.h>
-static inline void centerOnScreen(QWidget *w, const QSize &size)
-{
- const QPoint offset = QPoint(size.width() / 2, size.height() / 2);
- w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset);
-}
-
-static inline void centerOnScreen(QWidget *w)
-{
- centerOnScreen(w, w->geometry().size());
-}
class tst_QAbstractSpinBox : public QObject
{
@@ -182,7 +173,7 @@ void tst_QAbstractSpinBox::inputMethodUpdate()
QSpinBox *testWidget = &box;
testWidget->setRange(0, 1);
- centerOnScreen(testWidget);
+ QTestPrivate::centerOnScreen(testWidget);
testWidget->clear();
testWidget->show();
QVERIFY(QTest::qWaitForWindowExposed(testWidget));
diff --git a/tests/auto/widgets/widgets/qcombobox/qcombobox.pro b/tests/auto/widgets/widgets/qcombobox/qcombobox.pro
index 88b9d08557..939153dc88 100644
--- a/tests/auto/widgets/widgets/qcombobox/qcombobox.pro
+++ b/tests/auto/widgets/widgets/qcombobox/qcombobox.pro
@@ -1,4 +1,4 @@
CONFIG += testcase
TARGET = tst_qcombobox
-QT += widgets widgets-private gui-private core-private testlib
+QT += widgets widgets-private gui-private core-private testlib testlib-private
SOURCES += tst_qcombobox.cpp
diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
index e33171a7cf..c65cfa3e1a 100644
--- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
+++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
@@ -67,13 +67,9 @@
#include "../../../shared/platforminputcontext.h"
#include <private/qinputmethod_p.h>
-static inline void setFrameless(QWidget *w)
-{
- Qt::WindowFlags flags = w->windowFlags();
- flags |= Qt::FramelessWindowHint;
- flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
- w->setWindowFlags(flags);
-}
+#include <QtTest/private/qtesthelpers_p.h>
+
+using namespace QTestPrivate;
class tst_QComboBox : public QObject
{
diff --git a/tests/auto/widgets/widgets/qlineedit/qlineedit.pro b/tests/auto/widgets/widgets/qlineedit/qlineedit.pro
index 636208d67a..cb24a80afd 100644
--- a/tests/auto/widgets/widgets/qlineedit/qlineedit.pro
+++ b/tests/auto/widgets/widgets/qlineedit/qlineedit.pro
@@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qlineedit
-QT += gui-private core-private widgets widgets-private testlib
+QT += gui-private core-private widgets widgets-private testlib testlib-private
SOURCES += tst_qlineedit.cpp
osx: LIBS += -framework AppKit
diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
index 255ea04771..54e9ec0bf2 100644
--- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
+++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
@@ -28,6 +28,7 @@
#include <QtTest/QtTest>
+#include <QtTest/private/qtesthelpers_p.h>
#include "qlineedit.h"
#include "qapplication.h"
#include "qstringlist.h"
@@ -43,10 +44,6 @@
#include <private/qapplication_p.h>
#include "qclipboard.h"
-#ifdef Q_OS_MAC
-#include <cstdlib> // For the random function.
-#endif
-
#include <qlineedit.h>
#include <private/qlineedit_p.h>
#include <private/qwidgetlinecontrol_p.h>
@@ -74,16 +71,7 @@ QT_BEGIN_NAMESPACE
class QPainter;
QT_END_NAMESPACE
-static inline void centerOnScreen(QWidget *w, const QSize &size)
-{
- const QPoint offset = QPoint(size.width() / 2, size.height() / 2);
- w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset);
-}
-
-static inline void centerOnScreen(QWidget *w)
-{
- centerOnScreen(w, w->geometry().size());
-}
+using namespace QTestPrivate;
class StyleOptionTestStyle : public QCommonStyle
{
@@ -1949,17 +1937,7 @@ void tst_QLineEdit::noCursorBlinkWhenReadOnly()
static void figureOutProperKey(Qt::Key &key, Qt::KeyboardModifiers &pressState)
{
#ifdef Q_OS_MAC
- static bool tst_lineedit_randomized = false;
- // Mac has 3 different ways of accomplishing this (same for moving to the back)
- // So I guess we should just randomly do this for now. Which may get people mad, but if
- // we fail at one point, it's just a matter of setting roll to the correct value
- // instead of random.
-
- if (!tst_lineedit_randomized) {
- tst_lineedit_randomized = true;
- ::srandom(ulong(time(0)));
- }
- long roll = ::random() % 3;
+ long roll = QRandomGenerator::global()->bounded(3);
switch (roll) {
case 0:
key = key == Qt::Key_Home ? Qt::Key_Up : Qt::Key_Down;
diff --git a/tests/auto/widgets/widgets/qmenu/qmenu.pro b/tests/auto/widgets/widgets/qmenu/qmenu.pro
index 55fff01138..84b6530184 100644
--- a/tests/auto/widgets/widgets/qmenu/qmenu.pro
+++ b/tests/auto/widgets/widgets/qmenu/qmenu.pro
@@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qmenu
-QT += gui-private widgets testlib
+QT += gui-private widgets testlib testlib-private
SOURCES += tst_qmenu.cpp
macx:{
OBJECTIVE_SOURCES += tst_qmenu_mac.mm
diff --git a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
index 7689669d9b..15e2d9fa11 100644
--- a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
+++ b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
@@ -27,6 +27,7 @@
****************************************************************************/
#include <QtTest/QtTest>
+#include <QtTest/private/qtesthelpers_p.h>
#include <qapplication.h>
#include <QPushButton>
#include <QMainWindow>
@@ -48,15 +49,11 @@
#include <qpa/qplatformtheme.h>
+using namespace QTestPrivate;
+
Q_DECLARE_METATYPE(Qt::Key);
Q_DECLARE_METATYPE(Qt::KeyboardModifiers);
-static inline void centerOnScreen(QWidget *w, const QSize &size)
-{
- const QPoint offset = QPoint(size.width() / 2, size.height() / 2);
- w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset);
-}
-
struct MenuMetrics {
int fw;
int hmargin;
@@ -71,11 +68,6 @@ struct MenuMetrics {
}
};
-static inline void centerOnScreen(QWidget *w)
-{
- centerOnScreen(w, w->geometry().size());
-}
-
class tst_QMenu : public QObject
{
Q_OBJECT
diff --git a/tests/auto/widgets/widgets/qmenubar/BLACKLIST b/tests/auto/widgets/widgets/qmenubar/BLACKLIST
index ee08086e83..e2194e69ca 100644
--- a/tests/auto/widgets/widgets/qmenubar/BLACKLIST
+++ b/tests/auto/widgets/widgets/qmenubar/BLACKLIST
@@ -1,5 +1,3 @@
[check_menuPosition]
ubuntu-14.04
ubuntu-16.04
-[task256322_highlight]
-osx
diff --git a/tests/auto/widgets/widgets/qmenubar/qmenubar.pro b/tests/auto/widgets/widgets/qmenubar/qmenubar.pro
index e680cf4d7d..bde0026517 100644
--- a/tests/auto/widgets/widgets/qmenubar/qmenubar.pro
+++ b/tests/auto/widgets/widgets/qmenubar/qmenubar.pro
@@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qmenubar
-QT += widgets testlib
+QT += widgets testlib testlib-private
SOURCES += tst_qmenubar.cpp
macos: {
diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
index 2ccd87d1cc..96a64b18c1 100644
--- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
+++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
@@ -48,6 +48,22 @@ QT_FORWARD_DECLARE_CLASS(QMainWindow)
#include <qmenubar.h>
+#include <QtTest/private/qtesthelpers_p.h>
+
+using namespace QTestPrivate;
+
+// Helper to calculate the action position in window coordinates
+static inline QPoint widgetToWindowPos(const QWidget *w, const QPoint &pos)
+{
+ const QWindow *window = w->window()->windowHandle();
+ Q_ASSERT(window);
+ return window->mapFromGlobal(w->mapToGlobal(pos));
+}
+
+static QPoint menuBarActionWindowPos(const QMenuBar *mb, QAction *a)
+{
+ return widgetToWindowPos(mb, mb->actionGeometry(a).center());
+}
class Menu : public QMenu
{
@@ -61,12 +77,6 @@ class Menu : public QMenu
}
};
-static inline void centerOnScreen(QWidget *w)
-{
- const QPoint offset = QPoint(w->width() / 2, w->height() / 2);
- w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset);
-}
-
struct TestMenu
{
QList<QMenu *> menus;
@@ -621,6 +631,9 @@ void tst_QMenuBar::check_accelKeys()
#if !defined(Q_OS_DARWIN)
void tst_QMenuBar::check_cursorKeys1()
{
+ if (qgetenv("XDG_CURRENT_DESKTOP") == "Unity")
+ QSKIP("This test is flaky on Ubuntu/Unity due to regression introduced by QTBUG-39362");
+
QMainWindow w;
initWindowWithComplexMenuBar(w);
w.show();
@@ -655,6 +668,9 @@ void tst_QMenuBar::check_cursorKeys1()
#if !defined(Q_OS_DARWIN)
void tst_QMenuBar::check_cursorKeys2()
{
+ if (qgetenv("XDG_CURRENT_DESKTOP") == "Unity")
+ QSKIP("This test is flaky on Ubuntu/Unity due to regression introduced by QTBUG-39362");
+
QMainWindow w;
initWindowWithComplexMenuBar(w);
w.show();
@@ -688,6 +704,9 @@ void tst_QMenuBar::check_cursorKeys2()
#if !defined(Q_OS_DARWIN)
void tst_QMenuBar::check_cursorKeys3()
{
+ if (qgetenv("XDG_CURRENT_DESKTOP") == "Unity")
+ QSKIP("This test is flaky on Ubuntu/Unity due to regression introduced by QTBUG-39362");
+
QMainWindow w;
initWindowWithComplexMenuBar(w);
w.show();
@@ -719,9 +738,7 @@ void tst_QMenuBar::taskQTBUG56860_focus()
#endif
QMainWindow w;
QMenuBar *mb = w.menuBar();
-
- if (mb->platformMenuBar())
- QSKIP("This test requires the Qt menubar.");
+ mb->setNativeMenuBar(false);
QMenu *em = mb->addMenu("&Edit");
em->setObjectName("EditMenu");
@@ -765,8 +782,7 @@ void tst_QMenuBar::check_homeKey()
{
// I'm temporarily shutting up this testcase.
// Seems like the behaviour i'm expecting isn't ok.
- QVERIFY( true );
- return;
+ QSKIP("This test has been \"temporarily\" disabled at least since 2009 :)");
QEXPECT_FAIL( "0", "Popupmenu should respond to a Home key", Abort );
@@ -807,8 +823,7 @@ void tst_QMenuBar::check_endKey()
{
// I'm temporarily silenting this testcase.
// Seems like the behaviour i'm expecting isn't ok.
- QVERIFY( true );
- return;
+ QSKIP("This test has been \"temporarily\" disabled at least since 2009 :)");
QEXPECT_FAIL( "0", "Popupmenu should respond to an End key", Abort );
@@ -1198,21 +1213,19 @@ void tst_QMenuBar::check_menuPosition()
menu.close();
}
-# ifndef QT_NO_CURSOR
// QTBUG-28031: Click at bottom-right corner.
{
w.move(400, 200);
LayoutDirectionSaver directionSaver(Qt::RightToLeft);
QMenuBar *mb = w.menuBar();
- const QPoint localPos = mb->actionGeometry(menu.menuAction()).bottomRight() - QPoint(1, 1);
- const QPoint globalPos = mb->mapToGlobal(localPos);
- QCursor::setPos(globalPos);
- QTest::mouseClick(mb, Qt::LeftButton, 0, localPos);
+ const QPoint bottomRight = mb->actionGeometry(menu.menuAction()).bottomRight() - QPoint(1, 1);
+ const QPoint localPos = widgetToWindowPos(mb, bottomRight);
+ const QPoint globalPos = w.mapToGlobal(localPos);
+ QTest::mouseClick(w.windowHandle(), Qt::LeftButton, 0, localPos);
QTRY_VERIFY(menu.isActiveWindow());
QCOMPARE(menu.geometry().right() - 1, globalPos.x());
menu.close();
}
-# endif // QT_NO_CURSOR
}
#endif
@@ -1250,10 +1263,8 @@ void tst_QMenuBar::task223138_triggered()
void tst_QMenuBar::task256322_highlight()
{
- if (!QGuiApplication::platformName().compare(QLatin1String("minimal"), Qt::CaseInsensitive)
- || !QGuiApplication::platformName().compare(QLatin1String("offscreen"), Qt::CaseInsensitive)) {
- QSKIP("Highlighting does not work correctly for minimal/offscreen platforms");
- }
+ if (!QGuiApplication::platformName().compare(QLatin1String("minimal"), Qt::CaseInsensitive))
+ QSKIP("Highlighting does not work correctly for minimal platform");
QMainWindow win;
win.menuBar()->setNativeMenuBar(false); //we can't check the geometry of native menubars
@@ -1270,31 +1281,26 @@ void tst_QMenuBar::task256322_highlight()
QApplication::setActiveWindow(&win);
QVERIFY(QTest::qWaitForWindowActive(&win));
- QTest::mousePress(win.menuBar(), Qt::LeftButton, 0, win.menuBar()->actionGeometry(file).center());
- QTest::mouseMove(win.menuBar(), win.menuBar()->actionGeometry(file).center());
- QTest::mouseRelease(win.menuBar(), Qt::LeftButton, 0, win.menuBar()->actionGeometry(file).center());
+ const QPoint filePos = menuBarActionWindowPos(win.menuBar(), file);
+ QWindow *window = win.windowHandle();
+ QTest::mousePress(window, Qt::LeftButton, 0, filePos);
+ QTest::mouseMove(window, filePos);
+ QTest::mouseRelease(window, Qt::LeftButton, 0, filePos);
QTRY_VERIFY(menu.isVisible());
QVERIFY(!menu2.isVisible());
QCOMPARE(win.menuBar()->activeAction(), file);
- QTest::mousePress(win.menuBar(), Qt::LeftButton, 0, win.menuBar()->actionGeometry(file2).center());
- QTest::mouseMove(win.menuBar(), win.menuBar()->actionGeometry(file2).center());
+ const QPoint file2Pos = menuBarActionWindowPos(win.menuBar(), file2);
+ QTest::mouseMove(window, file2Pos);
QTRY_VERIFY(!menu.isVisible());
- QVERIFY(menu2.isVisible());
+ QTRY_VERIFY(menu2.isVisible());
QCOMPARE(win.menuBar()->activeAction(), file2);
- QTest::mouseRelease(win.menuBar(), Qt::LeftButton, 0, win.menuBar()->actionGeometry(file2).center());
- QPoint nothingCenter = win.menuBar()->actionGeometry(nothing).center();
- QTest::mousePress(win.menuBar(), Qt::LeftButton, 0, nothingCenter);
- QTest::mouseMove(win.menuBar(), nothingCenter);
+ QPoint nothingCenter = menuBarActionWindowPos(win.menuBar(), nothing);
+ QTest::mouseMove(window, nothingCenter);
QTRY_VERIFY(!menu2.isVisible());
QVERIFY(!menu.isVisible());
-#ifdef Q_OS_MAC
- if (win.menuBar()->activeAction() != nothing)
- QEXPECT_FAIL("", "QTBUG-30565: Unstable test", Continue);
-#endif
QTRY_COMPARE(win.menuBar()->activeAction(), nothing);
- QTest::mouseRelease(win.menuBar(), Qt::LeftButton, 0, nothingCenter);
}
void tst_QMenuBar::menubarSizeHint()
@@ -1431,9 +1437,6 @@ void tst_QMenuBar::closeOnSecondClickAndOpenOnThirdClick() // QTBUG-32807, menu
QMainWindow mainWindow;
mainWindow.resize(300, 200);
centerOnScreen(&mainWindow);
-#ifndef QT_NO_CURSOR
- QCursor::setPos(mainWindow.geometry().topLeft() - QPoint(100, 0));
-#endif
QMenuBar *menuBar = mainWindow.menuBar();
menuBar->setNativeMenuBar(false);
QMenu *fileMenu = menuBar->addMenu(QStringLiteral("OpenCloseOpen"));
@@ -1441,14 +1444,17 @@ void tst_QMenuBar::closeOnSecondClickAndOpenOnThirdClick() // QTBUG-32807, menu
mainWindow.show();
QApplication::setActiveWindow(&mainWindow);
QVERIFY(QTest::qWaitForWindowActive(&mainWindow));
- const QPoint center = menuBar->actionGeometry(fileMenu->menuAction()).center();
- const QPoint globalPos = menuBar->mapToGlobal(center);
- QTest::mouseMove(menuBar, center);
- QTest::mouseClick(menuBar, Qt::LeftButton, 0, center);
+
+ const QPoint center = menuBarActionWindowPos(mainWindow.menuBar(), fileMenu->menuAction());
+ const QPoint globalPos = mainWindow.mapToGlobal(center);
+
+ QWindow *window = mainWindow.windowHandle();
+ QTest::mouseMove(window, center);
+ QTest::mouseClick(window, Qt::LeftButton, 0, center);
QTRY_VERIFY(fileMenu->isVisible());
- QTest::mouseClick(fileMenu, Qt::LeftButton, 0, fileMenu->mapFromGlobal(globalPos));
+ QTest::mouseClick(window, Qt::LeftButton, 0, fileMenu->mapFromGlobal(globalPos));
QTRY_VERIFY(!fileMenu->isVisible());
- QTest::mouseClick(menuBar, Qt::LeftButton, 0, center);
+ QTest::mouseClick(window, Qt::LeftButton, 0, center);
QTRY_VERIFY(fileMenu->isVisible());
}
diff --git a/tests/auto/widgets/widgets/qscrollbar/qscrollbar.pro b/tests/auto/widgets/widgets/qscrollbar/qscrollbar.pro
index 2863dd2034..51f955200b 100644
--- a/tests/auto/widgets/widgets/qscrollbar/qscrollbar.pro
+++ b/tests/auto/widgets/widgets/qscrollbar/qscrollbar.pro
@@ -1,4 +1,4 @@
CONFIG += testcase
TARGET = tst_qscrollbar
-QT += widgets testlib
+QT += widgets testlib testlib-private
SOURCES += tst_qscrollbar.cpp
diff --git a/tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp b/tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp
index 5ef2c7bc50..278f5cdd68 100644
--- a/tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp
+++ b/tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp
@@ -33,16 +33,9 @@
#include <QScrollArea>
#include <QScreen>
-static inline void centerOnScreen(QWidget *w, const QSize &size)
-{
- const QPoint offset = QPoint(size.width() / 2, size.height() / 2);
- w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset);
-}
+#include <QtTest/private/qtesthelpers_p.h>
-static inline void centerOnScreen(QWidget *w)
-{
- centerOnScreen(w, w->geometry().size());
-}
+using namespace QTestPrivate;
class tst_QScrollBar : public QObject
{
diff --git a/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp b/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp
index f77fd2ebab..8c4c6c7179 100644
--- a/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp
+++ b/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp
@@ -32,6 +32,8 @@
#include <qtcpserver.h>
#include <qtcpsocket.h>
#include <QtTest/QtTest>
+#include <QtCore/qatomic.h>
+#include <QtCore/qsemaphore.h>
#include <qfile.h>
#include <qstring.h>
#include <qdir.h>
@@ -47,10 +49,11 @@ class XmlServer : public QThread
{
Q_OBJECT
public:
- XmlServer(QObject *parent = 0) : QThread(parent), quit_soon(false), listening(false) {}
+ XmlServer(QObject *parent = 0) : QThread(parent) {}
- bool quit_soon;
- bool listening;
+ QSemaphore threadStarted;
+ bool listening = false;
+ QAtomicInt quitSoon;
protected:
virtual void run();
@@ -63,6 +66,8 @@ void XmlServer::run()
QTcpServer srv;
listening = srv.listen(QHostAddress::Any, TEST_PORT);
+ threadStarted.release();
+
if (!listening) {
qWarning() << "Failed to listen on" << TEST_PORT << srv.errorString();
return;
@@ -95,14 +100,13 @@ void XmlServer::run()
QByteArray data = file.readAll();
for (int i = 0; i < data.size();) {
-// sock->putChar(data.at(i));
int cnt = qMin(CHUNK_SIZE, data.size() - i);
sock->write(data.constData() + i, cnt);
i += cnt;
sock->flush();
QTest::qSleep(1);
- if (quit_soon) {
+ if (quitSoon.loadAcquire()) {
sock->abort();
break;
}
@@ -112,7 +116,7 @@ void XmlServer::run()
delete sock;
}
- if (quit_soon)
+ if (quitSoon.loadAcquire())
break;
}
@@ -162,7 +166,7 @@ tst_QXmlSimpleReader::tst_QXmlSimpleReader() : server(new XmlServer(this))
tst_QXmlSimpleReader::~tst_QXmlSimpleReader()
{
- server->quit_soon = true;
+ server->quitSoon.storeRelease(1);
server->wait();
}
@@ -562,7 +566,19 @@ void tst_QXmlSimpleReader::inputFromSocket()
QSKIP("WinRT does not support connecting to localhost");
#endif
- QTRY_VERIFY_WITH_TIMEOUT(server->listening, 15000);
+ if (!server->threadStarted.tryAcquire(1, 15000)) {
+ // If something is wrong with QThreads, it's not a reason to fail
+ // XML-test, we are not testing QThread here after all!
+ QSKIP("XmlServer/thread has not started yet");
+ }
+
+ // Subsequent runs should be able to acquire the semaphore.
+ server->threadStarted.release(1);
+
+ if (!server->listening) {
+ // Again, QTcpServer is not the subject of this test!
+ QSKIP("QTcpServer::listen failed, bailing out");
+ }
QTcpSocket sock;
sock.connectToHost(QHostAddress::LocalHost, TEST_PORT);