aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qcoapclient/tst_qcoapclient.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qcoapclient/tst_qcoapclient.cpp')
-rw-r--r--tests/auto/qcoapclient/tst_qcoapclient.cpp61
1 files changed, 55 insertions, 6 deletions
diff --git a/tests/auto/qcoapclient/tst_qcoapclient.cpp b/tests/auto/qcoapclient/tst_qcoapclient.cpp
index 6f66346..20f1cab 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
@@ -108,9 +110,11 @@ private:
class QCoapClientForSocketErrorTests : public QCoapClient
{
public:
- QCoapClientForSocketErrorTests() :
- QCoapClient(new QCoapQUdpConnectionSocketTests)
- {}
+ QCoapClientForSocketErrorTests()
+ {
+ QCoapClientPrivate *privateClient = static_cast<QCoapClientPrivate *>(d_func());
+ privateClient->setConnection(new QCoapQUdpConnectionSocketTests());
+ }
QCoapQUdpConnection *connection()
{
@@ -162,9 +166,11 @@ public:
class QCoapClientForMulticastTests : public QCoapClient
{
public:
- QCoapClientForMulticastTests() :
- QCoapClient(new QCoapConnectionMulticastTests)
- {}
+ QCoapClientForMulticastTests()
+ {
+ QCoapClientPrivate *privateClient = static_cast<QCoapClientPrivate *>(d_func());
+ privateClient->setConnection(new QCoapConnectionMulticastTests());
+ }
QCoapConnection *connection()
{
@@ -867,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.setMinimumTokenSize(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"