diff options
author | Liang Qi <liang.qi@qt.io> | 2016-08-16 07:58:32 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-08-16 07:58:32 +0200 |
commit | 17198e03ab36e5f579a1477b09cc3e601975eb5f (patch) | |
tree | 61ba826e9edd53469abdc1e1f58b1223d0336c56 /tests/auto/corelib | |
parent | a5e89005445ac8ca18ac046eaf55fe2230e47cd6 (diff) | |
parent | 2e2b32a9ab459f6618d02e4b454c75a787172def (diff) |
Merge remote-tracking branch 'origin/5.7' into dev
Conflicts:
qmake/doc/src/qmake-manual.qdoc
src/corelib/global/qglobal.cpp
src/corelib/tools/qstring.cpp
src/network/socket/qabstractsocket.cpp
src/network/socket/qnativesocketengine_unix.cpp
src/plugins/platforms/eglfs/api/qeglfsglobal.h
Change-Id: Id5dfdbd30fa996f9b4b66a0b030b7d3b8c0ef288
Diffstat (limited to 'tests/auto/corelib')
5 files changed, 138 insertions, 28 deletions
diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index 68d7a4fe5f..021d581aac 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -2509,7 +2509,7 @@ void tst_QFile::rename() \since 4.5 Some special files have QFile::atEnd() returning true, even though there is - more data available. True for corner cases, as well as some mounts on OS X. + more data available. True for corner cases, as well as some mounts on \macos. Here, we reproduce that condition by having a QFile sub-class with this peculiar atEnd() behavior. diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index 0bc1e77925..3f3533c9a1 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -734,6 +734,7 @@ void tst_QProcess::restartProcess() void tst_QProcess::closeWriteChannel() { + QByteArray testData("Data to read"); QProcess more; more.start("testProcessEOF/testProcessEOF"); @@ -741,19 +742,21 @@ void tst_QProcess::closeWriteChannel() QVERIFY(!more.waitForReadyRead(250)); QCOMPARE(more.error(), QProcess::Timedout); - QVERIFY(more.write("Data to read") != -1); + QCOMPARE(more.write(testData), qint64(testData.size())); QVERIFY(!more.waitForReadyRead(250)); QCOMPARE(more.error(), QProcess::Timedout); more.closeWriteChannel(); - - QVERIFY(more.waitForReadyRead(5000)); - QVERIFY(more.readAll().startsWith("Data to read")); + // During closeWriteChannel() call, we might also get an I/O completion + // on the read pipe. So, take this into account before waiting for + // the new incoming data. + while (more.bytesAvailable() < testData.size()) + QVERIFY(more.waitForReadyRead(5000)); + QCOMPARE(more.readAll(), testData); if (more.state() == QProcess::Running) - more.write("q"); - QVERIFY(more.waitForFinished(5000)); + QVERIFY(more.waitForFinished(5000)); QCOMPARE(more.exitStatus(), QProcess::NormalExit); QCOMPARE(more.exitCode(), 0); } diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index 04a7129f01..38e3c6890d 100644 --- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp @@ -2129,17 +2129,23 @@ void tst_QSortFilterProxyModel::changeSourceDataForwardsRoles_qtbug35440() QModelIndex index; + // QStringListModel doesn't distinguish between edit and display roles, + // so changing one always changes the other, too. + QVector<int> expectedChangedRoles; + expectedChangedRoles.append(Qt::DisplayRole); + expectedChangedRoles.append(Qt::EditRole); + index = model.index(0, 0); QVERIFY(index.isValid()); model.setData(index, QStringLiteral("teststring"), Qt::DisplayRole); QCOMPARE(spy.length(), 1); - QCOMPARE(spy.at(0).at(2).value<QVector<int> >(), QVector<int>() << Qt::DisplayRole); + QCOMPARE(spy.at(0).at(2).value<QVector<int> >(), expectedChangedRoles); index = model.index(1, 0); QVERIFY(index.isValid()); model.setData(index, QStringLiteral("teststring2"), Qt::EditRole); QCOMPARE(spy.length(), 2); - QCOMPARE(spy.at(1).at(2).value<QVector<int> >(), QVector<int>() << Qt::EditRole); + QCOMPARE(spy.at(1).at(2).value<QVector<int> >(), expectedChangedRoles); } void tst_QSortFilterProxyModel::sortFilterRole() diff --git a/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp b/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp index 61dda782d8..f99241da3b 100644 --- a/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp +++ b/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp @@ -35,6 +35,8 @@ #include "qmodellistener.h" #include <qstringlistmodel.h> +#include <algorithm> + void QModelListener::rowsAboutToBeRemovedOrInserted(const QModelIndex & parent, int start, int end ) { for (int i = 0; start + i <= end; i++) { @@ -75,6 +77,9 @@ private slots: void rowsAboutToBeInserted_rowsInserted(); void rowsAboutToBeInserted_rowsInserted_data(); + + void setData_emits_both_roles_data(); + void setData_emits_both_roles(); }; void tst_QStringListModel::rowsAboutToBeRemoved_rowsRemoved_data() @@ -129,22 +134,19 @@ void tst_QStringListModel::rowsAboutToBeRemoved_rowsRemoved() QFETCH(QStringList, aboutto); QFETCH(QStringList, res); - QStringListModel *model = new QStringListModel(input); - QModelListener *pListener = new QModelListener(&aboutto, &res, model); - pListener->connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), - pListener, SLOT(rowsAboutToBeRemovedOrInserted(QModelIndex,int,int)) ); + QStringListModel model(input); + QModelListener listener(&aboutto, &res, &model); + connect(&model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), + &listener, SLOT(rowsAboutToBeRemovedOrInserted(QModelIndex,int,int))); - pListener->connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), - pListener, SLOT(rowsRemovedOrInserted(QModelIndex,int,int)) ); + connect(&model, SIGNAL(rowsRemoved(QModelIndex,int,int)), + &listener, SLOT(rowsRemovedOrInserted(QModelIndex,int,int))); - model->removeRows(row,count); + model.removeRows(row, count); // At this point, control goes to our connected slots inn this order: // 1. rowsAboutToBeRemovedOrInserted // 2. rowsRemovedOrInserted // Control returns here - - delete pListener; - delete model; } void tst_QStringListModel::rowsAboutToBeInserted_rowsInserted_data() @@ -193,22 +195,59 @@ void tst_QStringListModel::rowsAboutToBeInserted_rowsInserted() QFETCH(QStringList, aboutto); QFETCH(QStringList, res); - QStringListModel *model = new QStringListModel(input); - QModelListener *pListener = new QModelListener(&aboutto, &res, model); - connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), - pListener, SLOT(rowsAboutToBeRemovedOrInserted(QModelIndex,int,int)) ); + QStringListModel model(input); + QModelListener listener(&aboutto, &res, &model); + connect(&model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), + &listener, SLOT(rowsAboutToBeRemovedOrInserted(QModelIndex,int,int))); - connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), - pListener, SLOT(rowsRemovedOrInserted(QModelIndex,int,int)) ); + connect(&model, SIGNAL(rowsInserted(QModelIndex,int,int)), + &listener, SLOT(rowsRemovedOrInserted(QModelIndex,int,int))); - model->insertRows(row,count); + model.insertRows(row, count); // At this point, control goes to our connected slots inn this order: // 1. rowsAboutToBeRemovedOrInserted // 2. rowsRemovedOrInserted // Control returns here +} - delete pListener; - delete model; +void tst_QStringListModel::setData_emits_both_roles_data() +{ + QTest::addColumn<int>("row"); + QTest::addColumn<QString>("data"); + QTest::addColumn<int>("role"); + +#define ROW(row, string, role) \ + QTest::newRow(#row " -> " string) << row << QString(string) << int(Qt::role) + ROW(0, "1", EditRole); + ROW(1, "2", DisplayRole); +#undef ROW +} + +template <class C> +C sorted(C c) +{ + std::sort(c.begin(), c.end()); + return qMove(c); +} + +void tst_QStringListModel::setData_emits_both_roles() +{ + QFETCH(int, row); + QFETCH(QString, data); + QFETCH(int, role); + + QStringListModel model(QStringList() << "one" << "two"); + QVector<int> expected; + expected.reserve(2); + expected.append(Qt::DisplayRole); + expected.append(Qt::EditRole); + + QSignalSpy spy(&model, &QAbstractItemModel::dataChanged); + QVERIFY(spy.isValid()); + model.setData(model.index(row, 0), data, role); + QCOMPARE(spy.size(), 1); + QCOMPARE(sorted(spy.at(0).at(2).value<QVector<int> >()), + expected); } QTEST_MAIN(tst_QStringListModel) diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 7a37fdfa46..8f0f599622 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -496,6 +496,8 @@ private slots: void fromLocal8Bit(); void local8Bit_data(); void local8Bit(); + void invalidToLocal8Bit_data(); + void invalidToLocal8Bit(); void nullFromLocal8Bit(); void fromLatin1Roundtrip_data(); void fromLatin1Roundtrip(); @@ -4290,6 +4292,66 @@ void tst_QString::local8Bit() QCOMPARE(local8Bit.toLocal8Bit(), QByteArray(result)); } +void tst_QString::invalidToLocal8Bit_data() +{ + QTest::addColumn<QString>("unicode"); + QTest::addColumn<QByteArray>("expect"); // Initial validly-converted prefix + + { + const QChar malformed[] = { 'A', 0xd800, 'B', 0 }; + const char expected[] = "A"; + QTest::newRow("LoneHighSurrogate") + << QString(malformed, sizeof(malformed) / sizeof(QChar)) + // Don't include the terminating '\0' of expected: + << QByteArray(expected, sizeof(expected) / sizeof(char) - 1); + } + { + const QChar malformed[] = { 'A', 0xdc00, 'B', 0 }; + const char expected[] = "A"; + QTest::newRow("LoneLowSurrogate") + << QString(malformed, sizeof(malformed) / sizeof(QChar)) + << QByteArray(expected, sizeof(expected) / sizeof(char) - 1); + } + { + const QChar malformed[] = { 'A', 0xd800, 0xd801, 'B', 0 }; + const char expected[] = "A"; + QTest::newRow("DoubleHighSurrogate") + << QString(malformed, sizeof(malformed) / sizeof(QChar)) + << QByteArray(expected, sizeof(expected) / sizeof(char) - 1); + } + { + const QChar malformed[] = { 'A', 0xdc00, 0xdc01, 'B', 0 }; + const char expected[] = "A"; + QTest::newRow("DoubleLowSurrogate") + << QString(malformed, sizeof(malformed) / sizeof(QChar)) + << QByteArray(expected, sizeof(expected) / sizeof(char) - 1); + } + { + const QChar malformed[] = { 'A', 0xdc00, 0xd800, 'B', 0 }; + const char expected[] = "A"; + QTest::newRow("ReversedSurrogates") // low before high + << QString(malformed, sizeof(malformed) / sizeof(QChar)) + << QByteArray(expected, sizeof(expected) / sizeof(char) - 1); + } +} + +void tst_QString::invalidToLocal8Bit() +{ + QFETCH(QString, unicode); + QFETCH(QByteArray, expect); + QByteArray local = unicode.toLocal8Bit(); + /* + The main concern of this test is to check that any error-reporting that + toLocal8Bit() prompts on failure isn't dependent on outputting the data + it's converting via toLocal8Bit(), which would be apt to recurse. So the + real purpose of this QVERIFY(), for all that we should indeed check we get + the borked output that matches what we can reliably expect (despite + variation in how codecs respond to errors), is to verify that we got here + - i.e. we didn't crash in such a recursive stack over-flow. + */ + QVERIFY(local.startsWith(expect)); +} + void tst_QString::nullFromLocal8Bit() { QString a; |