diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 12 | ||||
-rw-r--r-- | tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp | 3 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qhash/tst_qhash.cpp | 34 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qmap/tst_qmap.cpp | 33 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qset/tst_qset.cpp | 26 | ||||
-rw-r--r-- | tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp | 12 | ||||
-rw-r--r-- | tests/manual/qnetworkreply/main.cpp | 82 |
7 files changed, 196 insertions, 6 deletions
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 0308e870be..647ddf1b96 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -6174,6 +6174,18 @@ void tst_QObject::connectBase() QCOMPARE( r1.count_slot1, 1 ); QCOMPARE( r1.count_slot2, 1 ); QCOMPARE( r1.count_slot3, 1 ); + + QVERIFY( QObject::disconnect( &sub, &SubSender::signal1 , &r1, &ReceiverObject::slot1 ) ); + QVERIFY( QObject::disconnect( &sub, static_cast<void (SenderObject::*)()>(&SubSender::signal2) , &r1, &ReceiverObject::slot2 ) ); + QVERIFY( QObject::disconnect( &sub, static_cast<void (SubSender::*)()>(&SubSender::signal3) , &r1, &ReceiverObject::slot3 ) ); + + sub.emitSignal1(); + sub.emitSignal2(); + sub.emitSignal3(); + + QCOMPARE( r1.count_slot1, 1 ); + QCOMPARE( r1.count_slot2, 1 ); + QCOMPARE( r1.count_slot3, 1 ); } struct QmlReceiver : public QtPrivate::QSlotObjectBase diff --git a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp index 67f3477eee..b66667d56b 100644 --- a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp @@ -5766,6 +5766,9 @@ void tst_QStateMachine::propertiesAreAssignedBeforeEntryCallbacks() // QTBUG-25958 void tst_QStateMachine::multiTargetTransitionInsideParallelStateGroup() { + // TODO QTBUG-25958 was reopened, see https://codereview.qt-project.org/89775 + return; + QStateMachine machine; QState *s1 = new QState(&machine); DEFINE_ACTIVE_SPY(s1); diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp index 77baed87c2..7e8fc234de 100644 --- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp +++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp @@ -84,6 +84,14 @@ private slots: void eraseValidIteratorOnSharedHash(); }; +struct IdentityTracker { + int value, id; +}; + +inline uint qHash(IdentityTracker key) { return qHash(key.value); } +inline bool operator==(IdentityTracker lhs, IdentityTracker rhs) { return lhs.value == rhs.value; } + + struct Foo { static int count; Foo():c(count) { ++count; } @@ -443,6 +451,32 @@ void tst_QHash::insert1() QVERIFY(((const QHash<int,int*>*) &hash)->operator[](7) == 0); } } + { + QHash<IdentityTracker, int> hash; + QCOMPARE(hash.size(), 0); + const int dummy = -1; + IdentityTracker id00 = {0, 0}, id01 = {0, 1}, searchKey = {0, dummy}; + QCOMPARE(hash.insert(id00, id00.id).key().id, id00.id); + QCOMPARE(hash.size(), 1); + QCOMPARE(hash.insert(id01, id01.id).key().id, id00.id); // first key inserted is kept + QCOMPARE(hash.size(), 1); + QCOMPARE(hash.find(searchKey).value(), id01.id); // last-inserted value + QCOMPARE(hash.find(searchKey).key().id, id00.id); // but first-inserted key + } + { + QMultiHash<IdentityTracker, int> hash; + QCOMPARE(hash.size(), 0); + const int dummy = -1; + IdentityTracker id00 = {0, 0}, id01 = {0, 1}, searchKey = {0, dummy}; + QCOMPARE(hash.insert(id00, id00.id).key().id, id00.id); + QCOMPARE(hash.size(), 1); + QCOMPARE(hash.insert(id01, id01.id).key().id, id01.id); + QCOMPARE(hash.size(), 2); + QMultiHash<IdentityTracker, int>::const_iterator pos = hash.constFind(searchKey); + QCOMPARE(pos.value(), pos.key().id); // key fits to value it was inserted with + ++pos; + QCOMPARE(pos.value(), pos.key().id); // key fits to value it was inserted with + } } void tst_QHash::erase() diff --git a/tests/auto/corelib/tools/qmap/tst_qmap.cpp b/tests/auto/corelib/tools/qmap/tst_qmap.cpp index 3daab73cc2..108dc35907 100644 --- a/tests/auto/corelib/tools/qmap/tst_qmap.cpp +++ b/tests/auto/corelib/tools/qmap/tst_qmap.cpp @@ -89,6 +89,12 @@ private slots: void eraseValidIteratorOnSharedMap(); }; +struct IdentityTracker { + int value, id; +}; + +inline bool operator<(IdentityTracker lhs, IdentityTracker rhs) { return lhs.value < rhs.value; } + typedef QMap<QString, QString> StringMap; class MyClass @@ -1122,6 +1128,33 @@ void tst_QMap::insert() QCOMPARE(intMap.size(), 1000); QCOMPARE(intMap.value(i), -1); } + + { + QMap<IdentityTracker, int> map; + QCOMPARE(map.size(), 0); + const int dummy = -1; + IdentityTracker id00 = {0, 0}, id01 = {0, 1}, searchKey = {0, dummy}; + QCOMPARE(map.insert(id00, id00.id).key().id, id00.id); + QCOMPARE(map.size(), 1); + QCOMPARE(map.insert(id01, id01.id).key().id, id00.id); // first key inserted is kept + QCOMPARE(map.size(), 1); + QCOMPARE(map.find(searchKey).value(), id01.id); // last-inserted value + QCOMPARE(map.find(searchKey).key().id, id00.id); // but first-inserted key + } + { + QMultiMap<IdentityTracker, int> map; + QCOMPARE(map.size(), 0); + const int dummy = -1; + IdentityTracker id00 = {0, 0}, id01 = {0, 1}, searchKey = {0, dummy}; + QCOMPARE(map.insert(id00, id00.id).key().id, id00.id); + QCOMPARE(map.size(), 1); + QCOMPARE(map.insert(id01, id01.id).key().id, id01.id); + QCOMPARE(map.size(), 2); + QMultiMap<IdentityTracker, int>::const_iterator pos = map.constFind(searchKey); + QCOMPARE(pos.value(), pos.key().id); // key fits to value it was inserted with + ++pos; + QCOMPARE(pos.value(), pos.key().id); // key fits to value it was inserted with + } } void tst_QMap::checkMostLeftNode() diff --git a/tests/auto/corelib/tools/qset/tst_qset.cpp b/tests/auto/corelib/tools/qset/tst_qset.cpp index 5ef1b44b6f..11873a7661 100644 --- a/tests/auto/corelib/tools/qset/tst_qset.cpp +++ b/tests/auto/corelib/tools/qset/tst_qset.cpp @@ -82,6 +82,13 @@ private slots: void initializerList(); }; +struct IdentityTracker { + int value, id; +}; + +inline uint qHash(IdentityTracker key) { return qHash(key.value); } +inline bool operator==(IdentityTracker lhs, IdentityTracker rhs) { return lhs.value == rhs.value; } + void tst_QSet::operator_eq() { { @@ -530,6 +537,18 @@ void tst_QSet::insert() QVERIFY(set1.size() == 2); QVERIFY(set1.contains(2)); } + + { + QSet<IdentityTracker> set; + QCOMPARE(set.size(), 0); + const int dummy = -1; + IdentityTracker id00 = {0, 0}, id01 = {0, 1}, searchKey = {0, dummy}; + QCOMPARE(set.insert(id00)->id, id00.id); + QCOMPARE(set.size(), 1); + QCOMPARE(set.insert(id01)->id, id00.id); // first inserted is kept + QCOMPARE(set.size(), 1); + QCOMPARE(set.find(searchKey)->id, id00.id); + } } void tst_QSet::setOperations() @@ -930,6 +949,13 @@ void tst_QSet::initializerList() QVERIFY(set.contains(4)); QVERIFY(set.contains(5)); + // check _which_ of the equal elements gets inserted (in the QHash/QMap case, it's the last): + const QSet<IdentityTracker> set2 = {{1, 0}, {1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}}; + QCOMPARE(set2.count(), 5); + const int dummy = -1; + const IdentityTracker searchKey = {1, dummy}; + QCOMPARE(set2.find(searchKey)->id, 0); + QSet<int> emptySet{}; QVERIFY(emptySet.isEmpty()); diff --git a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp index b1e43b69ad..efc80ff9ce 100644 --- a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp +++ b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp @@ -147,7 +147,7 @@ tst_QStyleSheetStyle::~tst_QStyleSheetStyle() void tst_QStyleSheetStyle::numinstances() { - /*QWidget w; + QWidget w; w.resize(200, 200); centerOnScreen(&w); QCommonStyle *style = new QCommonStyle; @@ -180,7 +180,7 @@ void tst_QStyleSheetStyle::numinstances() c.setStyle(style); QCOMPARE(QStyleSheetStyle::numinstances, 2); w.setStyleSheet(""); - QCOMPARE(QStyleSheetStyle::numinstances, 0);*/ + QCOMPARE(QStyleSheetStyle::numinstances, 0); } void tst_QStyleSheetStyle::widgetsBeforeAppStyleSheet() @@ -351,7 +351,7 @@ void tst_QStyleSheetStyle::repolish() void tst_QStyleSheetStyle::widgetStyle() { - /*qApp->setStyleSheet(""); + qApp->setStyleSheet(""); QWidget *window1 = new QWidget; window1->setObjectName("window1"); @@ -488,12 +488,12 @@ void tst_QStyleSheetStyle::widgetStyle() delete widget2; delete window2; delete style1; - delete style2;*/ + delete style2; } void tst_QStyleSheetStyle::appStyle() { - /* qApp->setStyleSheet(""); + qApp->setStyleSheet(""); // qApp style can never be 0 QVERIFY(QApplication::style() != 0); QPointer<QStyle> style1 = QStyleFactory::create("Windows"); @@ -531,7 +531,7 @@ void tst_QStyleSheetStyle::appStyle() QVERIFY(qApp->style() == style1); qApp->setStyleSheet(""); - QVERIFY(qApp->style() == style1);*/ + QVERIFY(qApp->style() == style1); } void tst_QStyleSheetStyle::dynamicProperty() diff --git a/tests/manual/qnetworkreply/main.cpp b/tests/manual/qnetworkreply/main.cpp index ff96f2598d..3618828f80 100644 --- a/tests/manual/qnetworkreply/main.cpp +++ b/tests/manual/qnetworkreply/main.cpp @@ -49,6 +49,7 @@ #include <QtNetwork/qnetworkaccessmanager.h> #include <QtNetwork/qsslconfiguration.h> #include <QtNetwork/qhttpmultipart.h> +#include <QtNetwork/qauthenticator.h> #include <QtCore/QJsonDocument> #include "../../auto/network-settings.h" @@ -73,9 +74,13 @@ private slots: void spdy_data(); void spdy(); void spdyMultipleRequestsPerHost(); + void proxyAuthentication_data(); + void proxyAuthentication(); + void authentication(); protected slots: void spdyReplyFinished(); // only used by spdyMultipleRequestsPerHost test + void authenticationRequiredSlot(QNetworkReply *, QAuthenticator *authenticator); private: QHttpMultiPart *createFacebookMultiPart(const QByteArray &accessToken); @@ -504,6 +509,83 @@ void tst_qnetworkreply::spdyMultipleRequestsPerHost() #endif // defined(QT_BUILD_INTERNAL) && !defined(QT_NO_SSL) ... } +void tst_qnetworkreply::proxyAuthentication_data() +{ + QTest::addColumn<QUrl>("url"); + + QTest::newRow("http://www.google.com") << QUrl("http://www.google.com"); + QTest::newRow("https://www.google.com") << QUrl("https://www.google.com"); +} + +void tst_qnetworkreply::proxyAuthentication() +{ + QFETCH(QUrl, url); + QNetworkRequest request(url); + QNetworkAccessManager manager; + + QByteArray proxyHostName = qgetenv("QT_PROXY_HOST"); + QByteArray proxyPort = qgetenv("QT_PROXY_PORT"); + QByteArray proxyUser = qgetenv("QT_PROXY_USER"); + QByteArray proxyPassword = qgetenv("QT_PROXY_PASSWORD"); + if (proxyHostName.isEmpty() || proxyPort.isEmpty() || proxyUser.isEmpty() + || proxyPassword.isEmpty()) + QSKIP("This test requires the QT_PROXY_* environment variables to be set. " + "Do something like:\n" + "export QT_PROXY_HOST=myNTLMHost\n" + "export QT_PROXY_PORT=8080\n" + "export QT_PROXY_USER='myDomain\\myUser'\n" + "export QT_PROXY_PASSWORD=myPassword\n"); + + QNetworkProxy proxy(QNetworkProxy::HttpProxy); + proxy.setHostName(proxyHostName); + proxy.setPort(proxyPort.toInt()); + proxy.setUser(proxyUser); + proxy.setPassword(proxyPassword); + + manager.setProxy(proxy); + + reply = manager.get(request); + QObject::connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + QTestEventLoop::instance().enterLoop(15); + QVERIFY(!QTestEventLoop::instance().timeout()); + QCOMPARE(reply->error(), QNetworkReply::NoError); + int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + QVERIFY(statusCode >= 200 && statusCode < 400); +} + +void tst_qnetworkreply::authenticationRequiredSlot(QNetworkReply *, + QAuthenticator *authenticator) +{ + QString authUser = QString::fromLocal8Bit(qgetenv("QT_AUTH_USER")); + QString authPassword = QString::fromLocal8Bit(qgetenv("QT_AUTH_PASSWORD")); + authenticator->setUser(authUser); + authenticator->setPassword(authPassword); +} + +void tst_qnetworkreply::authentication() +{ + QByteArray authUrl = qgetenv("QT_AUTH_URL"); + if (authUrl.isEmpty()) + QSKIP("This test requires the QT_AUTH_* environment variables to be set. " + "Do something like:\n" + "export QT_AUTH_URL='http://myUrl.com/myPath'\n" + "export QT_AUTH_USER='myDomain\\myUser'\n" + "export QT_AUTH_PASSWORD=myPassword\n"); + + QUrl url(QString::fromLocal8Bit(authUrl)); + QNetworkRequest request(url); + QNetworkAccessManager manager; + QObject::connect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), + this, SLOT(authenticationRequiredSlot(QNetworkReply*,QAuthenticator*))); + reply = manager.get(request); + QObject::connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + QTestEventLoop::instance().enterLoop(15); + QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY2(reply->error() == QNetworkReply::NoError, reply->errorString().toLocal8Bit()); + int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + QVERIFY(statusCode >= 200 && statusCode < 400); +} + QTEST_MAIN(tst_qnetworkreply) #include "main.moc" |