diff options
Diffstat (limited to 'tests/auto/qcoapclient/tst_qcoapclient.cpp')
-rw-r--r-- | tests/auto/qcoapclient/tst_qcoapclient.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/auto/qcoapclient/tst_qcoapclient.cpp b/tests/auto/qcoapclient/tst_qcoapclient.cpp index 0af3bee..aa8f70f 100644 --- a/tests/auto/qcoapclient/tst_qcoapclient.cpp +++ b/tests/auto/qcoapclient/tst_qcoapclient.cpp @@ -77,6 +77,8 @@ private Q_SLOTS: void confirmableMulticast(); void multicast(); void multicast_blockwise(); + void setMinimumTokenSize_data(); + void setMinimumTokenSize(); }; #ifdef QT_BUILD_INTERNAL @@ -871,6 +873,49 @@ void tst_QCoapClient::multicast_blockwise() #endif } +void tst_QCoapClient::setMinimumTokenSize_data() +{ + QTest::addColumn<int>("minTokenSize"); + QTest::addColumn<int>("expectedMinSize"); + + QTest::newRow("in_range") << 6 << 6; + QTest::newRow("out_of_range_small") << 0 << 4; + QTest::newRow("out_of_range_big") << 9 << 4; +} + +void noMessageOutput(QtMsgType, const QMessageLogContext &, const QString &) {} + +void tst_QCoapClient::setMinimumTokenSize() +{ +#ifdef QT_BUILD_INTERNAL + // Don't show warning messages for the out of range values + qInstallMessageHandler(noMessageOutput); + + QFETCH(int, minTokenSize); + QFETCH(int, expectedMinSize); + + const int maxSize = 8; + + for (int i = 0; i < 20; ++i) { + QCoapClientForSocketErrorTests client; + client.setMinumumTokenSize(minTokenSize); + + // With QCoapClientForSocketErrorTests the request will fail, but it doesn't matter, + // we are interested only in the generated token. + QSignalSpy spyClientError(&client, &QCoapClient::error); + + QScopedPointer<QCoapReply> reply; + reply.reset(client.get(QCoapRequest("127.0.0.1"))); + + QTRY_COMPARE_WITH_TIMEOUT(spyClientError.count(), 1, 10); + QVERIFY(reply->request().tokenLength() >= expectedMinSize); + QVERIFY(reply->request().tokenLength() <= maxSize); + } +#else + QSKIP("Not an internal build, skipping this test"); +#endif +} + QTEST_MAIN(tst_QCoapClient) #include "tst_qcoapclient.moc" |