From e524724f9dc6f64f6f94b842682c751dcd07225f Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Mon, 15 Oct 2018 09:51:12 +0200 Subject: tst_qfilesystemmodel: Do not use nested calls of auto test functions Calling rowCount inside another auto test function yields unexpected results, if rowCount fails. Without a check for QTest::currentTestFailed the failure will not stop the calling function and other functions like rowsInserted and rowsRemoved might happily continue even though their requirements are not met. That caused a crash on winrt under certain circumstances. In addition to that TRY_WAIT now does not only wait for the given amount of time, but also gives feedback about its result. Before this change TRY_WAIT was basically useless, as it gave no indication about its success/failure. Fixes: QTBUG-71121 Change-Id: Ibd3f233a0b913db799814be97c4274d510643c74 Reviewed-by: Friedemann Kleint --- .../qfilesystemmodel/tst_qfilesystemmodel.cpp | 79 +++++++++++++++------- 1 file changed, 56 insertions(+), 23 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp index d8a680881a..9ee5292fcb 100644 --- a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -51,10 +51,15 @@ // Will try to wait for the condition while allowing event processing // for a maximum of 5 seconds. -#define TRY_WAIT(expr) \ +#define TRY_WAIT(expr, timedOut) \ do { \ + *timedOut = true; \ const int step = 50; \ - for (int __i = 0; __i < 5000 && !(expr); __i+=step) { \ + for (int __i = 0; __i < 5000; __i += step) { \ + if (expr) { \ + *timedOut = false; \ + break; \ + } \ QTest::qWait(step); \ } \ } while(0) @@ -123,6 +128,8 @@ private slots: protected: bool createFiles(const QString &test_path, const QStringList &initial_files, int existingFileCount = 0, const QStringList &intial_dirs = QStringList()); + QModelIndex prepareTestModelRoot(const QString &test_path, QSignalSpy **spy2 = nullptr, + QSignalSpy **spy3 = nullptr); private: QFileSystemModel *model; @@ -306,7 +313,11 @@ void tst_QFileSystemModel::iconProvider() bool tst_QFileSystemModel::createFiles(const QString &test_path, const QStringList &initial_files, int existingFileCount, const QStringList &initial_dirs) { //qDebug() << (model->rowCount(model->index(test_path))) << existingFileCount << initial_files; - TRY_WAIT((model->rowCount(model->index(test_path)) == existingFileCount)); + bool timedOut = false; + TRY_WAIT((model->rowCount(model->index(test_path)) == existingFileCount), &timedOut); + if (timedOut) + return false; + for (int i = 0; i < initial_dirs.count(); ++i) { QDir dir(test_path); if (!dir.exists()) { @@ -363,23 +374,45 @@ bool tst_QFileSystemModel::createFiles(const QString &test_path, const QStringLi return true; } -void tst_QFileSystemModel::rowCount() +QModelIndex tst_QFileSystemModel::prepareTestModelRoot(const QString &test_path, QSignalSpy **spy2, + QSignalSpy **spy3) { - QString tmp = flatDirTestPath; - QVERIFY(createFiles(tmp, QStringList())); + if (model->rowCount(model->index(test_path)) != 0) + return QModelIndex(); - QSignalSpy spy2(model, SIGNAL(rowsInserted(QModelIndex,int,int))); - QSignalSpy spy3(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int))); + if (spy2) + *spy2 = new QSignalSpy(model, &QFileSystemModel::rowsInserted); + if (spy3) + *spy3 = new QSignalSpy(model, &QFileSystemModel::rowsAboutToBeInserted); - QStringList files = QStringList() << "b" << "d" << "f" << "h" << "j" << ".a" << ".c" << ".e" << ".g"; + QStringList files = { "b", "d", "f", "h", "j", ".a", ".c", ".e", ".g" }; QString l = "b,d,f,h,j,.a,.c,.e,.g"; - QVERIFY(createFiles(tmp, files)); + if (!createFiles(test_path, files)) + return QModelIndex(); - QModelIndex root = model->setRootPath(tmp); - QTRY_COMPARE(model->rowCount(root), 5); - QVERIFY(spy2.count() > 0); - QVERIFY(spy3.count() > 0); + QModelIndex root = model->setRootPath(test_path); + if (!root.isValid()) + return QModelIndex(); + + bool timedOut = false; + TRY_WAIT(model->rowCount(root) == 5, &timedOut); + if (timedOut) + return QModelIndex(); + + return root; +} + +void tst_QFileSystemModel::rowCount() +{ + const QString tmp = flatDirTestPath; + QSignalSpy *spy2 = nullptr; + QSignalSpy *spy3 = nullptr; + QModelIndex root = prepareTestModelRoot(flatDirTestPath, &spy2, &spy3); + QVERIFY(root.isValid()); + + QVERIFY(spy2 && spy2->count() > 0); + QVERIFY(spy3 && spy3->count() > 0); } void tst_QFileSystemModel::rowsInserted_data() @@ -401,9 +434,9 @@ static inline QString lastEntry(const QModelIndex &root) void tst_QFileSystemModel::rowsInserted() { - QString tmp = flatDirTestPath; - rowCount(); - QModelIndex root = model->index(model->rootPath()); + const QString tmp = flatDirTestPath; + QModelIndex root = prepareTestModelRoot(tmp); + QVERIFY(root.isValid()); QFETCH(int, ascending); QFETCH(int, count); @@ -454,9 +487,9 @@ void tst_QFileSystemModel::rowsRemoved_data() void tst_QFileSystemModel::rowsRemoved() { - QString tmp = flatDirTestPath; - rowCount(); - QModelIndex root = model->index(model->rootPath()); + const QString tmp = flatDirTestPath; + QModelIndex root = prepareTestModelRoot(tmp); + QVERIFY(root.isValid()); QFETCH(int, count); QFETCH(int, ascending); @@ -509,9 +542,9 @@ void tst_QFileSystemModel::dataChanged() { QSKIP("This can't be tested right now since we don't watch files, only directories."); - QString tmp = flatDirTestPath; - rowCount(); - QModelIndex root = model->index(model->rootPath()); + const QString tmp = flatDirTestPath; + QModelIndex root = prepareTestModelRoot(tmp); + QVERIFY(root.isValid()); QFETCH(int, count); QFETCH(int, assending); -- cgit v1.2.3 From 95ba049f8787258ccb28eeda72d1fac71f90e6f6 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Tue, 23 Oct 2018 11:18:22 +0200 Subject: Remove QSKIP and bring the test back to business MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit on macOS, where it was skipped but where it now seems to be stable/work. Task-number: QTBUG-39983 Change-Id: I100a57f23b43074ebacc012be247d92acc6ae336 Reviewed-by: Mårten Nordheim Reviewed-by: Edward Welbourne --- tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp b/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp index fed05698fd..da5327594c 100644 --- a/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp +++ b/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp @@ -209,9 +209,6 @@ void tst_QIODevice::read_QByteArray() //-------------------------------------------------------------------- void tst_QIODevice::unget() { -#if defined(Q_OS_MAC) - QSKIP("The unget network test is unstable on Mac. See QTBUG-39983."); -#endif QBuffer buffer; buffer.open(QBuffer::ReadWrite); buffer.write("ZXCV"); -- cgit v1.2.3 From 321f11db53422fe797c881cafa36ee44406d803c Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Tue, 23 Oct 2018 11:37:07 +0200 Subject: tst_QLocalSocket::processConnections: remove QSKIP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit on macOS, the test seems to be stable nowadays. Task-number: QTBUG-39986 Change-Id: I18430c3feb27a5bee5474e1eb95f7d89b25f00a9 Reviewed-by: Edward Welbourne Reviewed-by: Mårten Nordheim --- tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp index 779d55a77a..45ab275510 100644 --- a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp +++ b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp @@ -962,9 +962,6 @@ void tst_QLocalSocket::processConnection() #if !QT_CONFIG(process) QSKIP("No qprocess support", SkipAll); #else -#ifdef Q_OS_MAC - QSKIP("The processConnection test is unstable on Mac. See QTBUG-39986."); -#endif #ifdef Q_OS_WIN const QString exeSuffix = QStringLiteral(".exe"); -- cgit v1.2.3 From b10ee45546e152e08b2494bd45eb22426e9d2dc9 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Tue, 23 Oct 2018 15:42:24 +0200 Subject: tst_qeventdispatcher: remove macOS from the BLACKLIST MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit the test is stable in Qt 5.12. Task-number: QTBUG-60993 Change-Id: I0c366567121688d9518e90b5e8f9ec1b4006b7b9 Reviewed-by: Mårten Nordheim Reviewed-by: Edward Welbourne --- tests/auto/corelib/kernel/qeventdispatcher/BLACKLIST | 2 -- 1 file changed, 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/kernel/qeventdispatcher/BLACKLIST b/tests/auto/corelib/kernel/qeventdispatcher/BLACKLIST index fb7e025b7c..b1590a5ccf 100644 --- a/tests/auto/corelib/kernel/qeventdispatcher/BLACKLIST +++ b/tests/auto/corelib/kernel/qeventdispatcher/BLACKLIST @@ -1,7 +1,5 @@ [sendPostedEvents] windows -osx [registerTimer] windows -osx winrt -- cgit v1.2.3 From 95476bfcf64aa9cb43775ebfe3410ce9565de4d5 Mon Sep 17 00:00:00 2001 From: Ivan Komissarov Date: Mon, 22 Oct 2018 19:08:57 +0200 Subject: qendian: Fix float conversions Since Qt 5.10, qTo/FromBig/LittleEndian stopped working. It may be confusing, but big endian floats do exist, so not to break old code, we should support them. Change-Id: I21cdbc7f48ec030ce3d82f1cd1aad212f0fe5dd0 Reviewed-by: Thiago Macieira --- .../auto/corelib/global/qtendian/tst_qtendian.cpp | 40 ++++++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/global/qtendian/tst_qtendian.cpp b/tests/auto/corelib/global/qtendian/tst_qtendian.cpp index 7043969c2f..2345bb39c1 100644 --- a/tests/auto/corelib/global/qtendian/tst_qtendian.cpp +++ b/tests/auto/corelib/global/qtendian/tst_qtendian.cpp @@ -64,6 +64,9 @@ struct TestData quint16 data16; quint8 data8; + float dataFloat; + double dataDouble; + quint8 reserved; }; @@ -72,6 +75,7 @@ template <> quint8 getData(const TestData &d) { return d.data8; } template <> quint16 getData(const TestData &d) { return d.data16; } template <> quint32 getData(const TestData &d) { return d.data32; } template <> quint64 getData(const TestData &d) { return d.data64; } +template <> float getData(const TestData &d) { return d.dataFloat; } union RawTestData { @@ -79,9 +83,39 @@ union RawTestData TestData data; }; -static const TestData inNativeEndian = { Q_UINT64_C(0x0123456789abcdef), 0x00c0ffee, 0xcafe, 0xcf, '\0' }; -static const RawTestData inBigEndian = { "\x01\x23\x45\x67\x89\xab\xcd\xef" "\x00\xc0\xff\xee" "\xca\xfe" "\xcf" }; -static const RawTestData inLittleEndian = { "\xef\xcd\xab\x89\x67\x45\x23\x01" "\xee\xff\xc0\x00" "\xfe\xca" "\xcf" }; +template +Float int2Float(typename QIntegerForSizeof::Unsigned i) +{ + Float result = 0; + memcpy(reinterpret_cast(&result), reinterpret_cast(&i), sizeof (Float)); + return result; +} + +static const TestData inNativeEndian = { + Q_UINT64_C(0x0123456789abcdef), + 0x00c0ffee, + 0xcafe, + 0xcf, + int2Float(0x00c0ffeeU), + int2Float(Q_UINT64_C(0x0123456789abcdef)), + '\0' +}; +static const RawTestData inBigEndian = { + "\x01\x23\x45\x67\x89\xab\xcd\xef" + "\x00\xc0\xff\xee" + "\xca\xfe" + "\xcf" + "\x00\xc0\xff\xee" + "\x01\x23\x45\x67\x89\xab\xcd\xef" +}; +static const RawTestData inLittleEndian = { + "\xef\xcd\xab\x89\x67\x45\x23\x01" + "\xee\xff\xc0\x00" + "\xfe\xca" + "\xcf" + "\xee\xff\xc0\x00" + "\xef\xcd\xab\x89\x67\x45\x23\x01" +}; #define EXPAND_ENDIAN_TEST(endian) \ do { \ -- cgit v1.2.3