summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2011-02-16 18:01:17 (GMT)
committerJoão Abecasis <joao.abecasis@nokia.com>2011-02-16 18:01:17 (GMT)
commit9db05f0b7bf68392dc925d4047aa74dac88b348a (patch)
tree3690ea636187c9af9459ff3bfd4cab3e2af97c57 /tests
parent0df215e5afc780c1fddd9e410f7ef0814ac1307c (diff)
parent5a1676af979ab75c8939e53e0223ccbea7708de4 (diff)
downloadQt-9db05f0b7bf68392dc925d4047aa74dac88b348a.zip
Qt-9db05f0b7bf68392dc925d4047aa74dac88b348a.tar.gz
Qt-9db05f0b7bf68392dc925d4047aa74dac88b348a.tar.bz2
Merge branch earth-team/master into earth-staging
Conflicts: doc/src/development/qmake-manual.qdoc
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib.pro1
-rw-r--r--tests/auto/qnetworkreply/tst_qnetworkreply.cpp34
-rw-r--r--tests/auto/qscopedvaluerollback/qscopedvaluerollback.pro4
-rw-r--r--tests/auto/qscopedvaluerollback/tst_qscopedvaluerollback.cpp203
-rw-r--r--tests/auto/qthread/tst_qthread.cpp16
5 files changed, 246 insertions, 12 deletions
diff --git a/tests/auto/corelib.pro b/tests/auto/corelib.pro
index 3451b53..6810f76 100644
--- a/tests/auto/corelib.pro
+++ b/tests/auto/corelib.pro
@@ -59,6 +59,7 @@ SUBDIRS=\
qresourceengine \
qringbuffer \
qscopedpointer \
+ qscopedvaluerollback \
qsemaphore \
qsequentialanimationgroup \
qset \
diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
index 1d2a69f..3715162 100644
--- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
@@ -342,6 +342,8 @@ private Q_SLOTS:
void synchronousRequest();
void synchronousRequestSslFailure();
+ void httpAbort();
+
// NOTE: This test must be last!
void parentingRepliesToTheApp();
};
@@ -3850,19 +3852,13 @@ void tst_QNetworkReply::ioPostToHttpUploadProgress()
disconnect(&server, SIGNAL(newConnection()), &QTestEventLoop::instance(), SLOT(exitLoop()));
incomingSocket->setReadBufferSize(1*1024);
- QTestEventLoop::instance().enterLoop(2);
+ QTestEventLoop::instance().enterLoop(5);
// some progress should have been made
QList<QVariant> args = spy.last();
QVERIFY(!args.isEmpty());
QVERIFY(args.at(0).toLongLong() > 0);
-
- incomingSocket->setReadBufferSize(32*1024);
- incomingSocket->read(16*1024);
- QTestEventLoop::instance().enterLoop(2);
- // some more progress than before
- QList<QVariant> args2 = spy.last();
- QVERIFY(!args2.isEmpty());
- QVERIFY(args2.at(0).toLongLong() > args.at(0).toLongLong());
+ // but not everything!
+ QVERIFY(args.at(0).toLongLong() != sourceFile.size());
// set the read buffer to unlimited
incomingSocket->setReadBufferSize(0);
@@ -3870,8 +3866,10 @@ void tst_QNetworkReply::ioPostToHttpUploadProgress()
// progress should be finished
QList<QVariant> args3 = spy.last();
QVERIFY(!args3.isEmpty());
- QVERIFY(args3.at(0).toLongLong() > args2.at(0).toLongLong());
+ // More progress than before
+ QVERIFY(args3.at(0).toLongLong() > args.at(0).toLongLong());
QCOMPARE(args3.at(0).toLongLong(), args3.at(1).toLongLong());
+ // And actually finished..
QCOMPARE(args3.at(0).toLongLong(), sourceFile.size());
// after sending this, the QNAM should emit finished()
@@ -4570,7 +4568,7 @@ void tst_QNetworkReply::proxyChange()
manager.setProxy(dummyProxy);
QNetworkReplyPtr reply3 = manager.get(req);
connect(reply3, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
- QTestEventLoop::instance().enterLoop(1);
+ QTestEventLoop::instance().enterLoop(5);
QVERIFY(!QTestEventLoop::instance().timeout());
QVERIFY(int(reply3->error()) > 0);
@@ -5325,7 +5323,7 @@ void tst_QNetworkReply::qtbug13431replyThrottling()
connect(&nam, SIGNAL(finished(QNetworkReply*)), &helper, SLOT(replyFinished(QNetworkReply*)));
// Download a bigger file
- QNetworkRequest netRequest(QUrl("http://qt-test-server/qtest/bigfile"));
+ QNetworkRequest netRequest(QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/bigfile"));
helper.m_reply = nam.get(netRequest);
// Set the throttle
helper.m_reply->setReadBufferSize(36000);
@@ -5506,6 +5504,18 @@ void tst_QNetworkReply::synchronousRequestSslFailure()
QCOMPARE(sslErrorsSpy.count(), 0);
}
+void tst_QNetworkReply::httpAbort()
+{
+ // FIXME: Implement a test that aborts a big HTTP reply
+ // a) after the first readyRead()
+ // b) immediatly after the get()
+ // c) after the finished()
+ // The goal is no crash and no irrelevant signals after the abort
+
+ // FIXME Also implement one where we do a big upload and then abort().
+ // It must not crash either.
+}
+
// NOTE: This test must be last testcase in tst_qnetworkreply!
void tst_QNetworkReply::parentingRepliesToTheApp()
{
diff --git a/tests/auto/qscopedvaluerollback/qscopedvaluerollback.pro b/tests/auto/qscopedvaluerollback/qscopedvaluerollback.pro
new file mode 100644
index 0000000..f06e21b
--- /dev/null
+++ b/tests/auto/qscopedvaluerollback/qscopedvaluerollback.pro
@@ -0,0 +1,4 @@
+load(qttest_p4)
+SOURCES += tst_qscopedvaluerollback.cpp
+QT -= gui
+CONFIG += parallel_test
diff --git a/tests/auto/qscopedvaluerollback/tst_qscopedvaluerollback.cpp b/tests/auto/qscopedvaluerollback/tst_qscopedvaluerollback.cpp
new file mode 100644
index 0000000..956253f
--- /dev/null
+++ b/tests/auto/qscopedvaluerollback/tst_qscopedvaluerollback.cpp
@@ -0,0 +1,203 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QtCore/QScopedValueRollback>
+
+/*!
+ \class tst_QScopedValueRollback
+ \internal
+ \since 4.8
+ \brief Tests class QScopedValueRollback.
+
+ */
+class tst_QScopedValueRollback : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+ void leavingScope();
+ void leavingScopeAfterCommit();
+ void rollbackToPreviousCommit();
+ void exceptions();
+ void earlyExitScope();
+private:
+ void earlyExitScope_helper(int exitpoint, int &member);
+};
+
+void tst_QScopedValueRollback::leavingScope()
+{
+ int i = 0;
+ bool b = false;
+ QString s("This is useful");
+
+ //test rollback on going out of scope
+ {
+ QScopedValueRollback<int> ri(i);
+ QScopedValueRollback<bool> rb(b);
+ QScopedValueRollback<QString> rs(s);
+ QCOMPARE(b, false);
+ QCOMPARE(i, 0);
+ QCOMPARE(s, QString("This is useful"));
+ b = true;
+ i = 1;
+ s = "Useless";
+ QCOMPARE(b, true);
+ QCOMPARE(i, 1);
+ QCOMPARE(s, QString("Useless"));
+ }
+ QCOMPARE(b, false);
+ QCOMPARE(i, 0);
+ QCOMPARE(s, QString("This is useful"));
+}
+
+void tst_QScopedValueRollback::leavingScopeAfterCommit()
+{
+ int i = 0;
+ bool b = false;
+ QString s("This is useful");
+
+ //test rollback on going out of scope
+ {
+ QScopedValueRollback<int> ri(i);
+ QScopedValueRollback<bool> rb(b);
+ QScopedValueRollback<QString> rs(s);
+ QCOMPARE(b, false);
+ QCOMPARE(i, 0);
+ QCOMPARE(s, QString("This is useful"));
+ b = true;
+ i = 1;
+ s = "Useless";
+ QCOMPARE(b, true);
+ QCOMPARE(i, 1);
+ QCOMPARE(s, QString("Useless"));
+ ri.commit();
+ rb.commit();
+ rs.commit();
+ }
+ QCOMPARE(b, true);
+ QCOMPARE(i, 1);
+ QCOMPARE(s, QString("Useless"));
+}
+
+void tst_QScopedValueRollback::rollbackToPreviousCommit()
+{
+ int i=0;
+ {
+ QScopedValueRollback<int> ri(i);
+ i++;
+ ri.commit();
+ i++;
+ }
+ QCOMPARE(i,1);
+ {
+ QScopedValueRollback<int> ri1(i);
+ i++;
+ ri1.commit();
+ i++;
+ ri1.commit();
+ i++;
+ }
+ QCOMPARE(i,3);
+}
+
+void tst_QScopedValueRollback::exceptions()
+{
+ bool b = false;
+ bool caught = false;
+ QT_TRY
+ {
+ QScopedValueRollback<bool> rb(b);
+ b = true;
+ QT_THROW(std::bad_alloc()); //if Qt compiled without exceptions this is noop
+ rb.commit(); //if Qt compiled without exceptions, true is committed
+ }
+ QT_CATCH(...)
+ {
+ caught = true;
+ }
+ QCOMPARE(b, !caught); //expect false if exception was thrown, true otherwise
+}
+
+void tst_QScopedValueRollback::earlyExitScope()
+{
+ int i=0;
+ int j=0;
+ while (true) {
+ QScopedValueRollback<int> ri(i);
+ i++;
+ j=i;
+ if (i>8) break;
+ ri.commit();
+ }
+ QCOMPARE(i,8);
+ QCOMPARE(j,9);
+
+ for (i = 0; i < 5; i++) {
+ j=1;
+ earlyExitScope_helper(i,j);
+ QCOMPARE(j, 1<<i);
+ }
+}
+
+void tst_QScopedValueRollback::earlyExitScope_helper(int exitpoint, int& member)
+{
+ QScopedValueRollback<int> r(member);
+ member *= 2;
+ if (exitpoint == 0)
+ return;
+ r.commit();
+ member *= 2;
+ if (exitpoint == 1)
+ return;
+ r.commit();
+ member *= 2;
+ if (exitpoint == 2)
+ return;
+ r.commit();
+ member *= 2;
+ if (exitpoint == 3)
+ return;
+ r.commit();
+}
+
+QTEST_MAIN(tst_QScopedValueRollback)
+#include "tst_qscopedvaluerollback.moc"
diff --git a/tests/auto/qthread/tst_qthread.cpp b/tests/auto/qthread/tst_qthread.cpp
index 19c6c16..c69052e 100644
--- a/tests/auto/qthread/tst_qthread.cpp
+++ b/tests/auto/qthread/tst_qthread.cpp
@@ -113,6 +113,7 @@ private slots:
void wait3_slowDestructor();
void destroyFinishRace();
void startFinishRace();
+ void startAndQuitCustomEventLoop();
void stressTest();
};
@@ -1150,5 +1151,20 @@ void tst_QThread::startFinishRace()
}
}
+void tst_QThread::startAndQuitCustomEventLoop()
+{
+ struct Thread : QThread {
+ void run() { QEventLoop().exec(); }
+ };
+
+ for (int i = 0; i < 5; i++) {
+ Thread t;
+ t.start();
+ t.quit();
+ t.wait();
+ }
+}
+
+
QTEST_MAIN(tst_QThread)
#include "tst_qthread.moc"