summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-08-13 20:37:59 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-08-13 20:37:59 (GMT)
commitcccf8e7d8df2dfe537d3194e6e0becfc1671b0c0 (patch)
tree626b3625eb75bc9e3e87817b5d02c5b4e367e8fc /tests
parent36b56ef1b0034758fa6ade302177365ebce9899a (diff)
parent3411ac72ffcbd8152342603152193aa7283bd149 (diff)
downloadQt-cccf8e7d8df2dfe537d3194e6e0becfc1671b0c0.zip
Qt-cccf8e7d8df2dfe537d3194e6e0becfc1671b0c0.tar.gz
Qt-cccf8e7d8df2dfe537d3194e6e0becfc1671b0c0.tar.bz2
Merge branch 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into master-integration
* 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1: Cannot enter text through character viewer on Mac (Cocoa) QNAM HTTP: Remove eatWhitespace() hack QNAM: Fix namespaced compilation Revert the addition of the test of QtTest's random feature. QAbstractSocket: Remove warning QNAM Zerocopy: Benchmark tst_qbytearray: Auto test for reserve() tst_qiodevice: Add peek()ing auto test tst_qnetworkreply: Zerocopy auto test tst_qhttpnetworkconnection: Pipelining auto test QNAM Zerocopy: QNAM implementation part QNAM Zerocopy: HTTP implementation part QAbstractSocket: Enable Unbuffered OpenMode for TCP QNativeSocketEngine: Fix wrong debug output Added QObject::senderSignalIndex() Cleanup the connection list logic in QObject::sender Fixed linking against libQtTest on Mac. Added -random option to tests, making the test cases within a test execute in arbitrary order. Very useful for avoiding test cases being dependent on the running order.
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qbytearray/tst_qbytearray.cpp18
-rw-r--r--tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp48
-rw-r--r--tests/auto/qiodevice/tst_qiodevice.cpp59
-rw-r--r--tests/auto/qnetworkreply/tst_qnetworkreply.cpp96
-rw-r--r--tests/auto/qobject/tst_qobject.cpp24
-rw-r--r--tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp72
6 files changed, 313 insertions, 4 deletions
diff --git a/tests/auto/qbytearray/tst_qbytearray.cpp b/tests/auto/qbytearray/tst_qbytearray.cpp
index 07fdbc3..e3341d1 100644
--- a/tests/auto/qbytearray/tst_qbytearray.cpp
+++ b/tests/auto/qbytearray/tst_qbytearray.cpp
@@ -142,6 +142,8 @@ private slots:
void repeated_data() const;
void byteRefDetaching() const;
+
+ void reserve();
};
tst_QByteArray::tst_QByteArray()
@@ -1516,6 +1518,22 @@ void tst_QByteArray::byteRefDetaching() const
}
}
+void tst_QByteArray::reserve()
+{
+ int capacity = 100;
+ QByteArray qba;
+ qba.reserve(capacity);
+ QVERIFY(qba.capacity() == capacity);
+ char *data = qba.data();
+
+ // FIXME count from 0 to make it fail
+ for (int i = 1; i < capacity; i++) {
+ qba.resize(i);
+ QVERIFY(capacity == qba.capacity());
+ QVERIFY(data == qba.data());
+ }
+}
+
const char globalChar = '1';
QTEST_APPLESS_MAIN(tst_QByteArray)
diff --git a/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp b/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp
index 89f608e..188ed29 100644
--- a/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp
+++ b/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp
@@ -110,6 +110,8 @@ private Q_SLOTS:
void getEmptyWithPipelining();
+ void getAndEverythingShouldBePipelined();
+
void getAndThenDeleteObject();
void getAndThenDeleteObject_data();
};
@@ -1036,6 +1038,52 @@ void tst_QHttpNetworkConnection::getEmptyWithPipelining()
qDeleteAll(replies);
}
+class GetAndEverythingShouldBePipelinedReceiver : public QObject
+{
+ Q_OBJECT
+public:
+ int receivedCount;
+ int requestCount;
+ GetAndEverythingShouldBePipelinedReceiver(int rq) : receivedCount(0),requestCount(rq) { }
+public Q_SLOTS:
+ void finishedSlot() {
+ QHttpNetworkReply *reply = (QHttpNetworkReply*) sender();
+ receivedCount++;
+
+ if (receivedCount == requestCount)
+ QTestEventLoop::instance().exitLoop();
+ }
+};
+
+void tst_QHttpNetworkConnection::getAndEverythingShouldBePipelined()
+{
+ quint16 requestCount = 100;
+ // use 1 connection.
+ QHttpNetworkConnection connection(1, QtNetworkSettings::serverName());
+ QUrl url("http://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt");
+ QList<QHttpNetworkRequest*> requests;
+ QList<QHttpNetworkReply*> replies;
+
+ GetAndEverythingShouldBePipelinedReceiver receiver(requestCount);
+
+ for (int i = 0; i < requestCount; i++) {
+ QHttpNetworkRequest *request = 0;
+ request = new QHttpNetworkRequest(url, QHttpNetworkRequest::Get);
+ request->setPipeliningAllowed(true);
+ requests.append(request);
+ QHttpNetworkReply *reply = connection.sendRequest(*request);
+ connect(reply, SIGNAL(finished()), &receiver, SLOT(finishedSlot()));
+ replies.append(reply);
+ }
+ QTestEventLoop::instance().enterLoop(40);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+
+ qDeleteAll(requests);
+ qDeleteAll(replies);
+
+}
+
+
void tst_QHttpNetworkConnection::getAndThenDeleteObject_data()
{
QTest::addColumn<bool>("replyFirst");
diff --git a/tests/auto/qiodevice/tst_qiodevice.cpp b/tests/auto/qiodevice/tst_qiodevice.cpp
index 7048754..0226402 100644
--- a/tests/auto/qiodevice/tst_qiodevice.cpp
+++ b/tests/auto/qiodevice/tst_qiodevice.cpp
@@ -81,6 +81,8 @@ private slots:
void readLine2_data();
void readLine2();
+
+ void peekBug();
};
// Testing get/set functions
@@ -591,5 +593,62 @@ void tst_QIODevice::readLine2()
}
}
+
+class PeekBug : public QIODevice {
+ Q_OBJECT
+public:
+ char alphabet[27];
+ qint64 counter;
+ PeekBug() : QIODevice(), counter(0) {
+ memcpy(alphabet,"abcdefghijklmnopqrstuvqxyz",27);
+ };
+ qint64 readData(char *data, qint64 maxlen) {
+ qint64 pos = 0;
+ while (pos < maxlen) {
+ *(data + pos) = alphabet[counter];
+ pos++;
+ counter++;
+ if (counter == 26)
+ counter = 0;
+ }
+ return maxlen;
+ }
+ qint64 writeData(const char *data, qint64 maxlen) {
+ return -1;
+ }
+
+};
+
+// This is a testcase for the bug fixed with bd287865
+void tst_QIODevice::peekBug()
+{
+ PeekBug peekBug;
+ peekBug.open(QIODevice::ReadOnly | QIODevice::Unbuffered);
+
+ char onetwo[2];
+ peekBug.peek(onetwo, 2);
+ QCOMPARE(onetwo[0], 'a');
+ QCOMPARE(onetwo[1], 'b');
+
+ peekBug.read(onetwo, 1);
+ QCOMPARE(onetwo[0], 'a');
+
+ peekBug.peek(onetwo, 2);
+ QCOMPARE(onetwo[0], 'b');
+ QCOMPARE(onetwo[1], 'c');
+
+ peekBug.read(onetwo, 1);
+ QCOMPARE(onetwo[0], 'b');
+ peekBug.read(onetwo, 1);
+ QCOMPARE(onetwo[0], 'c');
+ peekBug.read(onetwo, 1);
+ QCOMPARE(onetwo[0], 'd');
+
+ peekBug.peek(onetwo, 2);
+ QCOMPARE(onetwo[0], 'e');
+ QCOMPARE(onetwo[1], 'f');
+
+}
+
QTEST_MAIN(tst_QIODevice)
#include "tst_qiodevice.moc"
diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
index 5af8034..bb91965 100644
--- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
@@ -75,7 +75,8 @@
#include "../network-settings.h"
-
+typedef QSharedPointer<QVarLengthArray<char, 0> > QVarLengthArraySharedPointer;
+Q_DECLARE_METATYPE(QVarLengthArraySharedPointer)
Q_DECLARE_METATYPE(QNetworkReply*)
Q_DECLARE_METATYPE(QAuthenticator*)
Q_DECLARE_METATYPE(QNetworkProxy)
@@ -289,6 +290,13 @@ private Q_SLOTS:
void symbianOpenCDataUrlCrash();
+ void getFromHttpIntoBuffer_data();
+ void getFromHttpIntoBuffer();
+
+ void ioGetFromHttpWithoutContentLength();
+
+ void ioGetFromHttpBrokenChunkedEncoding();
+
// NOTE: This test must be last!
void parentingRepliesToTheApp();
};
@@ -3936,6 +3944,7 @@ void tst_QNetworkReply::authorizationError()
QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), httpStatusCode);
QFETCH(QString, httpBody);
+ QCOMPARE(qint64(reply->size()), qint64(httpBody.size()));
QCOMPARE(QString(reply->readAll()), httpBody);
}
@@ -4280,6 +4289,91 @@ void tst_QNetworkReply::symbianOpenCDataUrlCrash()
QCOMPARE(reply->header(QNetworkRequest::ContentLengthHeader).toLongLong(), qint64(598));
}
+void tst_QNetworkReply::getFromHttpIntoBuffer_data()
+{
+ QTest::addColumn<QUrl>("url");
+
+ QTest::newRow("rfc-internal") << QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt");
+}
+
+void tst_QNetworkReply::getFromHttpIntoBuffer()
+{
+ QFETCH(QUrl, url);
+ QNetworkRequest request(url);
+ request.setAttribute(QNetworkRequest::MaximumDownloadBufferSizeAttribute, 1024*128); // 128 kB
+
+ QNetworkAccessManager manager;
+ QNetworkReply *reply = manager.get(request);
+ connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+
+ QTestEventLoop::instance().enterLoop(10);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+ QVERIFY(reply->isFinished());
+
+ QFile reference(SRCDIR "/rfc3252.txt");
+ QVERIFY(reference.open(QIODevice::ReadOnly));
+
+ QCOMPARE(reference.bytesAvailable(), reply->bytesAvailable());
+ QCOMPARE(reference.size(), reply->size());
+
+ // Compare the memory buffer
+ QVariant downloadBufferAttribute = reply->attribute(QNetworkRequest::DownloadBufferAttribute);
+ bool memoryComparison =
+ (0 == memcmp(static_cast<void*>(reference.readAll().data()),
+ downloadBufferAttribute.value<QSharedPointer<QVarLengthArray<char, 0> > >()->constData(), reference.size()));
+ QVERIFY(memoryComparison);
+
+ // Make sure the normal reading works
+ reference.seek(0);
+ QCOMPARE(reply->read(42), reference.read(42));
+ QCOMPARE(reply->getChar(0), reference.getChar(0));
+ QCOMPARE(reply->peek(23), reference.peek(23));
+ QCOMPARE(reply->readLine(), reference.readLine());
+ QCOMPARE(reference.bytesAvailable(), reply->bytesAvailable());
+ QCOMPARE(reply->readAll(), reference.readAll());
+ QVERIFY(reply->atEnd());
+}
+
+// Is handled somewhere else too, introduced this special test to have it more accessible
+void tst_QNetworkReply::ioGetFromHttpWithoutContentLength()
+{
+ QByteArray dataToSend("HTTP/1.0 200 OK\r\n\r\nHALLO! 123!");
+ MiniHttpServer server(dataToSend);
+ server.doClose = true;
+
+ QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort())));
+ QNetworkReplyPtr reply = manager.get(request);
+
+ connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+ QTestEventLoop::instance().enterLoop(10);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+
+ QCOMPARE(reply->url(), request.url());
+ QVERIFY(reply->isFinished());
+ QVERIFY(reply->error() == QNetworkReply::NoError);
+}
+
+// Is handled somewhere else too, introduced this special test to have it more accessible
+void tst_QNetworkReply::ioGetFromHttpBrokenChunkedEncoding()
+{
+ // This is wrong chunked encoding because of the X. What actually has to follow is \r\n
+ // and then the declaration of the final 0 chunk
+ QByteArray dataToSend("HTTP/1.0 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n3\r\nABCX");
+ MiniHttpServer server(dataToSend);
+ server.doClose = false; // FIXME
+
+ QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort())));
+ QNetworkReplyPtr reply = manager.get(request);
+
+ connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+ QTestEventLoop::instance().enterLoop(10);
+
+ QEXPECT_FAIL(0, "We should close the socket and not just do nothing", Continue);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+ QEXPECT_FAIL(0, "We should close the socket and not just do nothing", Continue);
+ QVERIFY(reply->isFinished());
+ QCOMPARE(reply->error(), QNetworkReply::NoError);
+}
// NOTE: This test must be last testcase in tst_qnetworkreply!
diff --git a/tests/auto/qobject/tst_qobject.cpp b/tests/auto/qobject/tst_qobject.cpp
index fc38a84..abfe24b 100644
--- a/tests/auto/qobject/tst_qobject.cpp
+++ b/tests/auto/qobject/tst_qobject.cpp
@@ -1782,9 +1782,12 @@ class SuperObject : public QObject
Q_OBJECT
public:
QObject *theSender;
+ int theSignalId;
+
SuperObject()
{
theSender = 0;
+ theSignalId = 0;
}
friend class tst_QObject;
@@ -1795,16 +1798,17 @@ public slots:
void rememberSender()
{
theSender = sender();
+ theSignalId = senderSignalIndex();
}
void deleteAndRememberSender()
{
delete theSender;
- theSender = sender();
+ rememberSender();
}
signals:
+ void anotherSignal();
void theSignal();
-
};
void tst_QObject::sender()
@@ -1812,12 +1816,23 @@ void tst_QObject::sender()
{
SuperObject sender;
SuperObject receiver;
+ connect(&sender, SIGNAL(anotherSignal()),
+ &receiver, SLOT(rememberSender()));
connect(&sender, SIGNAL(theSignal()),
&receiver, SLOT(rememberSender()));
QCOMPARE(receiver.sender(), (QObject *)0);
+ QCOMPARE(receiver.senderSignalIndex(), -1);
emit sender.theSignal();
QCOMPARE(receiver.theSender, (QObject *)&sender);
QCOMPARE(receiver.sender(), (QObject *)0);
+ QCOMPARE(receiver.theSignalId,
+ sender.metaObject()->indexOfSignal("theSignal()"));
+ QCOMPARE(receiver.senderSignalIndex(), -1);
+
+ emit sender.anotherSignal();
+ QCOMPARE(receiver.theSignalId,
+ sender.metaObject()->indexOfSignal("anotherSignal()"));
+ QCOMPARE(receiver.senderSignalIndex(), -1);
}
{
@@ -1834,11 +1849,16 @@ void tst_QObject::sender()
Qt::DirectConnection);
QCOMPARE(receiver->sender(), (QObject *)0);
+ QCOMPARE(receiver->senderSignalIndex(), -1);
receiver->theSender = 0;
+ receiver->theSignalId = -1;
thread.start();
emit sender->theSignal();
QCOMPARE(receiver->theSender, (QObject *) sender);
QCOMPARE(receiver->sender(), (QObject *)0);
+ QCOMPARE(receiver->theSignalId,
+ sender->metaObject()->indexOfSignal("theSignal()"));
+ QCOMPARE(receiver->senderSignalIndex(), -1);
QVERIFY(thread.wait(10000));
delete receiver;
diff --git a/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp
index 90ae153..0098d8e 100644
--- a/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp
@@ -51,6 +51,9 @@
#include "../../../../auto/network-settings.h"
+typedef QSharedPointer<QVarLengthArray<char, 0> > QVarLengthArraySharedPointer;
+Q_DECLARE_METATYPE(QVarLengthArraySharedPointer)
+
class TimedSender: public QThread
{
Q_OBJECT
@@ -465,7 +468,8 @@ private slots:
void httpUploadPerformance();
void httpDownloadPerformance_data();
void httpDownloadPerformance();
-
+ void httpDownloadPerformanceDownloadBuffer_data();
+ void httpDownloadPerformanceDownloadBuffer();
};
void tst_qnetworkreply::httpLatency()
@@ -649,6 +653,72 @@ void tst_qnetworkreply::httpDownloadPerformance()
qint64 elapsed = time.elapsed();
qDebug() << "tst_QNetworkReply::httpDownloadPerformance" << elapsed << "msec, "
<< ((UploadSize/1024.0)/(elapsed/1000.0)) << " kB/sec";
+};
+
+class HttpDownloadPerformanceClientDownloadBuffer : QObject {
+ Q_OBJECT
+private:
+ bool useDownloadBuffer;
+ QNetworkReply *reply;
+ qint64 uploadSize;
+public:
+ HttpDownloadPerformanceClientDownloadBuffer (QNetworkReply *reply, bool useDownloadBuffer, qint64 uploadSize)
+ : useDownloadBuffer(useDownloadBuffer), reply(reply), uploadSize(uploadSize)
+ {
+ connect(reply, SIGNAL(finished()), this, SLOT(finishedSlot()));
+ }
+
+ public slots:
+ void finishedSlot() {
+ if (useDownloadBuffer) {
+ QVariant downloadBufferAttribute = reply->attribute(QNetworkRequest::DownloadBufferAttribute);
+ QSharedPointer<QVarLengthArray<char, 0> > data = downloadBufferAttribute.value<QSharedPointer<QVarLengthArray<char, 0> > >();
+ } else {
+ // We did not have a download buffer but we still need to benchmark having the data, e.g. reading it all.
+ char* replyData = (char*) qMalloc(uploadSize);
+ QVERIFY(reply->read(replyData, uploadSize) == uploadSize);
+ qFree(replyData);
+ }
+ }
+};
+
+void tst_qnetworkreply::httpDownloadPerformanceDownloadBuffer_data()
+{
+ QTest::addColumn<bool>("useDownloadBuffer");
+
+ QTest::newRow("use-download-buffer") << true;
+ QTest::newRow("do-not-use-download-buffer") << false;
+}
+
+void tst_qnetworkreply::httpDownloadPerformanceDownloadBuffer()
+{
+ QFETCH(bool, useDownloadBuffer);
+
+ // On my Linux Desktop the results are already visible with 128 kB, however we use this to have good results.
+#if defined(Q_OS_SYMBIAN) || defined(Q_WS_WINCE_WM)
+ // Show some mercy to non-desktop platform/s
+ enum {UploadSize = 4*1024*1024}; // 4 MB
+#else
+ enum {UploadSize = 32*1024*1024}; // 32 MB
+#endif
+
+ HttpDownloadPerformanceServer server(UploadSize, true, false);
+
+ QNetworkRequest request(QUrl("http://127.0.0.1:" + QString::number(server.serverPort()) + "/?bare=1"));
+ if (useDownloadBuffer)
+ request.setAttribute(QNetworkRequest::MaximumDownloadBufferSizeAttribute, 1024*1024*128); // 128 MB is max allowed
+
+ QNetworkAccessManager manager;
+ QNetworkReplyPtr reply = manager.get(request);
+
+ HttpDownloadPerformanceClientDownloadBuffer client(reply, useDownloadBuffer, UploadSize);
+
+ connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection);
+ QBENCHMARK {
+ QTestEventLoop::instance().enterLoop(40);
+ QCOMPARE(reply->error(), QNetworkReply::NoError);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+ }
}
QTEST_MAIN(tst_qnetworkreply)