summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-10-25 01:00:16 +0200
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-10-25 01:00:16 +0200
commit375efdd0e157a80de08627612e36597a22c6ac06 (patch)
tree493209a04e60a8ccc9c2e551637db8cec1c92f0a /tests/auto
parent9ae0fa4d4977ef1eb28eff2f95b429e9455ba748 (diff)
parent5edf34848a51c7678031aeb9576b8f3b7b5fceab (diff)
Merge remote-tracking branch 'origin/5.14' into 5.15
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/io/qfile/tst_qfile.cpp4
-rw-r--r--tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp34
-rw-r--r--tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp8
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp54
-rw-r--r--tests/auto/gui/image/qimage/tst_qimage.cpp6
-rw-r--r--tests/auto/network/ssl/qdtls/tst_qdtls.cpp2
-rw-r--r--tests/auto/network/ssl/qdtlscookie/tst_qdtlscookie.cpp6
-rw-r--r--tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp27
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp2
-rw-r--r--tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp26
10 files changed, 131 insertions, 38 deletions
diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp
index 4f010f37c2..b8ae95dd93 100644
--- a/tests/auto/corelib/io/qfile/tst_qfile.cpp
+++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp
@@ -550,6 +550,10 @@ void tst_QFile::exists()
QFile unc(uncPath);
QVERIFY2(unc.exists(), msgFileDoesNotExist(uncPath).constData());
#endif
+
+ QTest::ignoreMessage(QtWarningMsg, "Broken filename passed to function");
+ QVERIFY(!QFile::exists(QDir::currentPath() + QLatin1Char('/') +
+ QChar(QChar::Null) + QLatin1String("x/y")));
}
void tst_QFile::open_data()
diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp
index 56d924dcc6..dae4e66106 100644
--- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp
+++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp
@@ -465,16 +465,6 @@ void tst_qstandardpaths::testRuntimeDirectory()
#ifdef Q_XDG_PLATFORM
const QString runtimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
QVERIFY(!runtimeDir.isEmpty());
-
- // Check that it can automatically fix permissions
- QFile file(runtimeDir);
- const QFile::Permissions wantedPerms = QFile::ReadUser | QFile::WriteUser | QFile::ExeUser;
- const QFile::Permissions additionalPerms = QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner;
- QCOMPARE(file.permissions(), wantedPerms | additionalPerms);
- QVERIFY(file.setPermissions(wantedPerms | QFile::ExeGroup));
- const QString runtimeDirAgain = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
- QCOMPARE(runtimeDirAgain, runtimeDir);
- QCOMPARE(QFile(runtimeDirAgain).permissions(), wantedPerms | additionalPerms);
#endif
}
@@ -516,11 +506,27 @@ void tst_qstandardpaths::testCustomRuntimeDirectory()
const QString runtimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
QVERIFY2(runtimeDir.isEmpty(), qPrintable(runtimeDir));
- // When $XDG_RUNTIME_DIR points to a non-existing directory, QStandardPaths should warn (QTBUG-48771)
- qputenv("XDG_RUNTIME_DIR", "does_not_exist");
- QTest::ignoreMessage(QtWarningMsg, "QStandardPaths: XDG_RUNTIME_DIR points to non-existing path 'does_not_exist', please create it with 0700 permissions.");
+ // When $XDG_RUNTIME_DIR points to a directory with wrong permissions, QStandardPaths should warn
+ const QByteArray wrongPermissionFileName = "wrong_permissions";
+ QDir::current().mkdir(wrongPermissionFileName);
+ QFile wrongPermissionFile(wrongPermissionFileName);
+ const QFile::Permissions wantedPerms = QFile::ReadUser | QFile::WriteUser | QFile::ExeUser;
+ QVERIFY(wrongPermissionFile.setPermissions(wantedPerms | QFile::ExeGroup));
+
+ qputenv("XDG_RUNTIME_DIR", wrongPermissionFileName);
+ QTest::ignoreMessage(QtWarningMsg,
+ qPrintable(QString::fromLatin1("QStandardPaths: wrong permissions on runtime directory " + wrongPermissionFileName + ", 7710 instead of 7700")));
+ const QString wrongPermissionRuntimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
+ QVERIFY(wrongPermissionRuntimeDir.isEmpty());
+ QDir::current().rmdir(wrongPermissionFileName);
+
+ // When $XDG_RUNTIME_DIR points to a non-existing directory, QStandardPaths should create it first
+ const QByteArray nonExistingDir = "does_not_exist";
+ qputenv("XDG_RUNTIME_DIR", nonExistingDir);
const QString nonExistingRuntimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
- QVERIFY2(nonExistingRuntimeDir.isEmpty(), qPrintable(nonExistingRuntimeDir));
+ QVERIFY2(!nonExistingRuntimeDir.compare(nonExistingDir), qPrintable(nonExistingRuntimeDir));
+ QVERIFY(QDir::current().exists(nonExistingRuntimeDir));
+ QDir::current().rmdir(nonExistingRuntimeDir);
// When $XDG_RUNTIME_DIR points to a file, QStandardPaths should warn
const QString file = QFINDTESTDATA("tst_qstandardpaths.cpp");
diff --git a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
index 72a6f0360d..4b13ac45cc 100644
--- a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
@@ -338,7 +338,7 @@ void tst_QStateMachine::transitionToRootState()
machine.postEvent(new QEvent(QEvent::User));
QTest::ignoreMessage(QtWarningMsg,
"Unrecoverable error detected in running state machine: "
- "Child mode of state machine 'machine' is not 'ExclusiveStates'!");
+ "Child mode of state machine 'machine' is not 'ExclusiveStates'.");
QCoreApplication::processEvents();
QVERIFY(machine.configuration().isEmpty());
QVERIFY(!machine.isRunning());
@@ -1064,7 +1064,7 @@ void tst_QStateMachine::transitionToStateNotInGraph()
machine.start();
QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: "
- "Child mode of state machine '' is not 'ExclusiveStates'!");
+ "Child mode of state machine '' is not 'ExclusiveStates'.");
QCoreApplication::processEvents();
QCOMPARE(machine.isRunning(), false);
@@ -2103,7 +2103,7 @@ void tst_QStateMachine::parallelRootState()
QVERIFY(finishedSpy.isValid());
machine.start();
QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: "
- "Child mode of state machine '' is not 'ExclusiveStates'!");
+ "Child mode of state machine '' is not 'ExclusiveStates'.");
QTRY_COMPARE(startedSpy.count(), 1);
QCOMPARE(machine.configuration().size(), 4);
QVERIFY(machine.configuration().contains(s1));
@@ -3316,7 +3316,7 @@ void tst_QStateMachine::targetStateWithNoParent()
machine.start();
QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: "
- "Child mode of state machine '' is not 'ExclusiveStates'!");
+ "Child mode of state machine '' is not 'ExclusiveStates'.");
TEST_ACTIVE_CHANGED(s1, 2);
QTRY_COMPARE(startedSpy.count(), 1);
QCOMPARE(machine.isRunning(), false);
diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
index f3c647515a..a9fd282ac9 100644
--- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
@@ -40,6 +40,7 @@
#include "nontracked.h"
#include "wrapper.h"
+#include <array>
#include <memory>
#include <stdlib.h>
#include <time.h>
@@ -106,12 +107,15 @@ private slots:
void sharedFromThis();
void constructorThrow();
+ void overloads();
void threadStressTest_data();
void threadStressTest();
void validConstructs();
void invalidConstructs_data();
void invalidConstructs();
+
+
// let invalidConstructs be the last test, because it's the slowest;
// add new tests above this block
public slots:
@@ -2383,6 +2387,11 @@ void tst_QSharedPointer::invalidConstructs_data()
QTest::newRow("incompatible-custom-lambda-deleter")
<< &QTest::QExternalTest::tryCompileFail
<< "QSharedPointer<Data> ptr(new Data, [](int *) {});\n";
+
+ QTest::newRow("incompatible-overload")
+ << &QTest::QExternalTest::tryCompileFail
+ << "void foo(QSharedPointer<DerivedData>) {}\n"
+ "void bar() { foo(QSharedPointer<Data>()); }\n";
}
void tst_QSharedPointer::invalidConstructs()
@@ -2883,5 +2892,50 @@ void tst_QSharedPointer::reentrancyWhileDestructing()
ReentrancyWhileDestructing::A obj;
}
+namespace {
+struct Base1 {};
+struct Base2 {};
+
+struct Child1 : Base1 {};
+struct Child2 : Base2 {};
+
+template<template<typename> class SmartPtr>
+struct Overloaded
+{
+ std::array<int, 1> call(const SmartPtr<const Base1> &)
+ {
+ return {};
+ }
+ std::array<int, 2> call(const SmartPtr<const Base2> &)
+ {
+ return {};
+ }
+ static const Q_CONSTEXPR uint base1Called = sizeof(std::array<int, 1>);
+ static const Q_CONSTEXPR uint base2Called = sizeof(std::array<int, 2>);
+
+ void test()
+ {
+#define QVERIFY_CALLS(expr, base) Q_STATIC_ASSERT(sizeof(call(expr)) == base##Called)
+ QVERIFY_CALLS(SmartPtr<Base1>{}, base1);
+ QVERIFY_CALLS(SmartPtr<Base2>{}, base2);
+ QVERIFY_CALLS(SmartPtr<const Base1>{}, base1);
+ QVERIFY_CALLS(SmartPtr<const Base2>{}, base2);
+ QVERIFY_CALLS(SmartPtr<Child1>{}, base1);
+ QVERIFY_CALLS(SmartPtr<Child2>{}, base2);
+ QVERIFY_CALLS(SmartPtr<const Child1>{}, base1);
+ QVERIFY_CALLS(SmartPtr<const Child2>{}, base2);
+#undef QVERIFY_CALLS
+ }
+};
+}
+
+void tst_QSharedPointer::overloads()
+{
+ Overloaded<QSharedPointer> sharedOverloaded;
+ sharedOverloaded.test();
+ Overloaded<QWeakPointer> weakOverloaded;
+ weakOverloaded.test();
+}
+
QTEST_MAIN(tst_QSharedPointer)
#include "tst_qsharedpointer.moc"
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp
index b84aa52465..2a9b92ed35 100644
--- a/tests/auto/gui/image/qimage/tst_qimage.cpp
+++ b/tests/auto/gui/image/qimage/tst_qimage.cpp
@@ -2132,6 +2132,12 @@ void tst_QImage::paintEngine()
QCOMPARE(engine, img.paintEngine());
QCOMPARE(img, expected);
+
+ {
+ QImage img1(16, 16, QImage::Format_ARGB32);
+ QImage img2 = img1;
+ QVERIFY(img2.paintEngine());
+ }
}
void tst_QImage::setAlphaChannelWhilePainting()
diff --git a/tests/auto/network/ssl/qdtls/tst_qdtls.cpp b/tests/auto/network/ssl/qdtls/tst_qdtls.cpp
index 6a94eee389..4dfdf14e5b 100644
--- a/tests/auto/network/ssl/qdtls/tst_qdtls.cpp
+++ b/tests/auto/network/ssl/qdtls/tst_qdtls.cpp
@@ -1131,7 +1131,7 @@ void tst_QDtls::handshakeReadyRead()
QUdpSocket *socket = qobject_cast<QUdpSocket *>(sender());
Q_ASSERT(socket);
- if (!socket->pendingDatagramSize())
+ if (socket->pendingDatagramSize() <= 0)
return;
const bool isServer = socket == &serverSocket;
diff --git a/tests/auto/network/ssl/qdtlscookie/tst_qdtlscookie.cpp b/tests/auto/network/ssl/qdtlscookie/tst_qdtlscookie.cpp
index c90e9cb2c8..a273ceaa17 100644
--- a/tests/auto/network/ssl/qdtlscookie/tst_qdtlscookie.cpp
+++ b/tests/auto/network/ssl/qdtlscookie/tst_qdtlscookie.cpp
@@ -352,7 +352,7 @@ void tst_QDtlsCookie::receiveMessage(QUdpSocket *socket, QByteArray *message,
{
Q_ASSERT(socket && message);
- if (!socket->pendingDatagramSize())
+ if (socket->pendingDatagramSize() <= 0)
testLoop.enterLoopMSecs(handshakeTimeoutMS);
QVERIFY(!testLoop.timeout());
@@ -377,7 +377,7 @@ void tst_QDtlsCookie::serverReadyRead()
{
Q_ASSERT(clientsToWait);
- if (!serverSocket.pendingDatagramSize())
+ if (serverSocket.pendingDatagramSize() <= 0)
return;
QByteArray hello;
@@ -410,7 +410,7 @@ void tst_QDtlsCookie::clientReadyRead()
QUdpSocket *clientSocket = qobject_cast<QUdpSocket *>(sender());
Q_ASSERT(clientSocket);
- if (!clientSocket->pendingDatagramSize())
+ if (clientSocket->pendingDatagramSize() <= 0)
return;
QDtls *handshake = nullptr;
diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
index cc58356103..1a5aa63489 100644
--- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
+++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
@@ -190,8 +190,7 @@ private slots:
void task_250026_data() { generic_data("QODBC"); }
void task_250026();
- void task_205701_data() { generic_data("QMYSQL"); }
- void task_205701();
+ void crashQueryOnCloseDatabase();
void task_233829_data() { generic_data("QPSQL"); }
void task_233829();
@@ -305,6 +304,8 @@ void tst_QSqlQuery::init()
void tst_QSqlQuery::cleanup()
{
+ if (QTest::currentTestFunction() == QLatin1String("crashQueryOnCloseDatabase"))
+ return;
QFETCH( QString, dbName );
QSqlDatabase db = QSqlDatabase::database( dbName );
CHECK_DATABASE( db );
@@ -3427,19 +3428,17 @@ void tst_QSqlQuery::task_250026()
QCOMPARE( q.value( 0 ).toString().length(), data1026.length() );
}
-void tst_QSqlQuery::task_205701()
+void tst_QSqlQuery::crashQueryOnCloseDatabase()
{
- QSqlDatabase qsdb = QSqlDatabase::addDatabase("QMYSQL", "atest");
- qsdb.setHostName("test");
- qsdb.setDatabaseName("test");
- qsdb.setUserName("test");
- qsdb.setPassword("test");
- qsdb.open();
-
-// {
- QSqlQuery query(qsdb);
-// }
- QSqlDatabase::removeDatabase("atest");
+ for (const auto &dbName : qAsConst(dbs.dbNames)) {
+ QSqlDatabase clonedDb = QSqlDatabase::cloneDatabase(
+ QSqlDatabase::database(dbName), "crashTest");
+ qDebug() << "Testing crash in sqlquery dtor for driver" << clonedDb.driverName();
+ QVERIFY(clonedDb.open());
+ QSqlQuery q(clonedDb);
+ clonedDb.close();
+ QSqlDatabase::removeDatabase("crashTest");
+ }
}
void tst_QSqlQuery::task_233829()
diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp
index b49d2cd8b0..cfbe1f96ee 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp
@@ -3747,8 +3747,6 @@ void tst_QGraphicsScene::changedSignal()
QCoreApplication::processEvents();
QCOMPARE(cl.changes.size(), 2);
QCOMPARE(cl.changes.at(1).size(), 2);
- QCOMPARE(cl.changes.at(1).first(), QRectF(0, 0, 10, 10));
- QCOMPARE(cl.changes.at(1).last(), QRectF(20, 0, 10, 10));
QCOMPARE(scene.sceneRect(), QRectF(0, 0, 30, 10));
}
diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
index 142db4334c..12b24798f4 100644
--- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
+++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
@@ -418,6 +418,7 @@ private slots:
void taskQTBUG_10169_sizeHintForRow();
void taskQTBUG_30653_doItemsLayout();
void taskQTBUG_50171_selectRowAfterSwapColumns();
+ void deselectRow();
#if QT_CONFIG(wheelevent)
void mouseWheel_data();
@@ -4519,6 +4520,31 @@ void tst_QTableView::taskQTBUG_50171_selectRowAfterSwapColumns()
}
}
+class DeselectTableWidget : public QTableWidget
+{
+public:
+ using QTableWidget::QTableWidget;
+ QItemSelectionModel::SelectionFlags selectionCommand(const QModelIndex &,
+ const QEvent * = nullptr) const override
+ {
+ return QItemSelectionModel::Toggle;
+ }
+};
+
+void tst_QTableView::deselectRow()
+{
+ DeselectTableWidget tw(20, 20);
+ tw.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&tw));
+ tw.hideColumn(0);
+ QVERIFY(tw.isColumnHidden(0));
+ tw.selectRow(1);
+ QVERIFY(tw.selectionModel()->isRowSelected(1, QModelIndex()));
+ tw.selectRow(1);
+ // QTBUG-79092 - deselection was not possible when column 0 was hidden
+ QVERIFY(!tw.selectionModel()->isRowSelected(1, QModelIndex()));
+}
+
// This has nothing to do with QTableView, but it's convenient to reuse the QtTestTableModel
#if QT_CONFIG(textmarkdownwriter)