summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/tools/qhash/tst_qhash.cpp11
-rw-r--r--tests/auto/corelib/tools/qmap/tst_qmap.cpp11
-rw-r--r--tests/auto/corelib/tools/qset/tst_qset.cpp2
-rw-r--r--tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp92
4 files changed, 109 insertions, 7 deletions
diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
index 9c96aaf78d..77baed87c2 100644
--- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp
+++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
@@ -1327,10 +1327,15 @@ void tst_QHash::twoArguments_qHash()
void tst_QHash::initializerList()
{
#ifdef Q_COMPILER_INITIALIZER_LISTS
- QHash<int, QString> hash{{1, "hello"}, {2, "initializer_list"}};
+ QHash<int, QString> hash = {{1, "bar"}, {1, "hello"}, {2, "initializer_list"}};
QCOMPARE(hash.count(), 2);
- QVERIFY(hash[1] == "hello");
- QVERIFY(hash[2] == "initializer_list");
+ QCOMPARE(hash[1], QString("hello"));
+ QCOMPARE(hash[2], QString("initializer_list"));
+
+ // note the difference to std::unordered_map:
+ // std::unordered_map<int, QString> stdh = {{1, "bar"}, {1, "hello"}, {2, "initializer_list"}};
+ // QCOMPARE(stdh.size(), 2UL);
+ // QCOMPARE(stdh[1], QString("bar"));
QMultiHash<QString, int> multiHash{{"il", 1}, {"il", 2}, {"il", 3}};
QCOMPARE(multiHash.count(), 3);
diff --git a/tests/auto/corelib/tools/qmap/tst_qmap.cpp b/tests/auto/corelib/tools/qmap/tst_qmap.cpp
index 00e669c1d8..3daab73cc2 100644
--- a/tests/auto/corelib/tools/qmap/tst_qmap.cpp
+++ b/tests/auto/corelib/tools/qmap/tst_qmap.cpp
@@ -1179,10 +1179,15 @@ void tst_QMap::checkMostLeftNode()
void tst_QMap::initializerList()
{
#ifdef Q_COMPILER_INITIALIZER_LISTS
- QMap<int, QString> map{{1, "hello"}, {2, "initializer_list"}};
+ QMap<int, QString> map = {{1, "bar"}, {1, "hello"}, {2, "initializer_list"}};
QCOMPARE(map.count(), 2);
- QVERIFY(map[1] == "hello");
- QVERIFY(map[2] == "initializer_list");
+ QCOMPARE(map[1], QString("hello"));
+ QCOMPARE(map[2], QString("initializer_list"));
+
+ // note the difference to std::map:
+ // std::map<int, QString> stdm = {{1, "bar"}, {1, "hello"}, {2, "initializer_list"}};
+ // QCOMPARE(stdm.size(), 2UL);
+ // QCOMPARE(stdm[1], QString("bar"));
QMultiMap<QString, int> multiMap{{"il", 1}, {"il", 2}, {"il", 3}};
QCOMPARE(multiMap.count(), 3);
diff --git a/tests/auto/corelib/tools/qset/tst_qset.cpp b/tests/auto/corelib/tools/qset/tst_qset.cpp
index eaa1c018ba..5ef1b44b6f 100644
--- a/tests/auto/corelib/tools/qset/tst_qset.cpp
+++ b/tests/auto/corelib/tools/qset/tst_qset.cpp
@@ -922,7 +922,7 @@ void tst_QSet::makeSureTheComfortFunctionsCompile()
void tst_QSet::initializerList()
{
#ifdef Q_COMPILER_INITIALIZER_LISTS
- QSet<int> set{1, 2, 3, 4, 5};
+ QSet<int> set = {1, 1, 2, 3, 4, 5};
QCOMPARE(set.count(), 5);
QVERIFY(set.contains(1));
QVERIFY(set.contains(2));
diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
index 0509eb9a77..480eeecb63 100644
--- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
@@ -461,6 +461,8 @@ private Q_SLOTS:
void backgroundRequestConnectInBackground();
#endif
+ void putWithRateLimiting();
+
// NOTE: This test must be last!
void parentingRepliesToTheApp();
private:
@@ -7776,6 +7778,96 @@ void tst_QNetworkReply::backgroundRequestConnectInBackground()
}
#endif
+class RateLimitedUploadDevice : public QIODevice
+{
+ Q_OBJECT
+public:
+ QByteArray data;
+ QBuffer buffer;
+ qint64 read;
+ qint64 bandwidthQuota;
+ QTimer timer;
+
+ RateLimitedUploadDevice(QByteArray d) : QIODevice(),data(d),read(0),bandwidthQuota(0) {
+ buffer.setData(data);
+ buffer.open(QIODevice::ReadOnly);
+ timer.setInterval(200);
+ QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeoutSlot()));
+ timer.start();
+ }
+
+ virtual qint64 writeData(const char* , qint64 ) {
+ Q_ASSERT(false);
+ return 0;
+ }
+
+ virtual qint64 readData(char* data, qint64 maxlen) {
+ //qDebug() << Q_FUNC_INFO << maxlen << bandwidthQuota;
+ maxlen = qMin(maxlen, buffer.bytesAvailable());
+ maxlen = qMin(maxlen, bandwidthQuota);
+ if (maxlen <= 0) { // no quota or at end
+ return 0;
+ }
+ bandwidthQuota -= maxlen; // reduce quota
+
+ qint64 ret = buffer.read(data, maxlen);
+ if (ret == -1) {
+ return -1;
+ }
+ read += ret;
+ //qDebug() << Q_FUNC_INFO << maxlen << bandwidthQuota << read << ret << buffer.bytesAvailable();
+ return ret;
+ }
+ virtual bool atEnd() const {
+ return buffer.atEnd();
+ }
+ virtual qint64 size() const{
+ return data.length();
+ }
+ qint64 bytesAvailable() const
+ {
+ return buffer.bytesAvailable() + QIODevice::bytesAvailable();
+ }
+ virtual bool isSequential() const{ // random access, we can seek
+ return false;
+ }
+ virtual bool seek ( qint64 pos ) {
+ return buffer.seek(pos);
+ }
+protected slots:
+ void timeoutSlot() {
+ //qDebug() << Q_FUNC_INFO;
+ bandwidthQuota = 8*1024; // fill quota
+ emit readyRead();
+ }
+};
+
+void tst_QNetworkReply::putWithRateLimiting()
+{
+ QFile reference(testDataDir + "/rfc3252.txt");
+ reference.open(QIODevice::ReadOnly);
+ QByteArray data = reference.readAll();
+ QVERIFY(data.length() > 0);
+
+ QUrl url = QUrl::fromUserInput("http://" + QtNetworkSettings::serverName()+ "/qtest/cgi-bin/echo.cgi?");
+
+ QNetworkRequest request(url);
+ QNetworkReplyPtr reply;
+
+ RateLimitedUploadDevice rateLimitedUploadDevice(data);
+ rateLimitedUploadDevice.open(QIODevice::ReadOnly);
+
+ RUN_REQUEST(runCustomRequest(request, reply,QByteArray("POST"), &rateLimitedUploadDevice));
+ QCOMPARE(reply->error(), QNetworkReply::NoError);
+ QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200);
+
+ QByteArray uploadedData = reply->readAll();
+ QCOMPARE(uploadedData.length(), data.length());
+ QCOMPARE(uploadedData, data);
+}
+
+
+
// NOTE: This test must be last testcase in tst_qnetworkreply!
void tst_QNetworkReply::parentingRepliesToTheApp()
{