diff options
| author | Linus Jahn <lnj@kaidan.im> | 2023-01-02 00:27:52 +0100 |
|---|---|---|
| committer | Linus Jahn <lnj@kaidan.im> | 2023-01-03 22:05:54 +0100 |
| commit | a71be82575ff250acd82206ffa192e0f2c936696 (patch) | |
| tree | 02c8e7551f0a30ae62a17ae9c959a964c2ee9acd /tests | |
| parent | b17284ee7d674416e0d11f1699f73fcc606262d4 (diff) | |
| download | qxmpp-a71be82575ff250acd82206ffa192e0f2c936696.tar.gz | |
Add tests for QXmppTask
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/qxmppclient/tst_qxmppclient.cpp | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/tests/qxmppclient/tst_qxmppclient.cpp b/tests/qxmppclient/tst_qxmppclient.cpp index 8005a580..0b5d33ea 100644 --- a/tests/qxmppclient/tst_qxmppclient.cpp +++ b/tests/qxmppclient/tst_qxmppclient.cpp @@ -8,6 +8,8 @@ #include "QXmppFutureUtils_p.h" #include "QXmppLogger.h" #include "QXmppMessage.h" +#include "QXmppPromise.h" +#include "QXmppRegisterIq.h" #include "QXmppRosterManager.h" #include "QXmppVCardManager.h" #include "QXmppVersionManager.h" @@ -26,10 +28,10 @@ private: Q_SLOT void handleMessageSent(QXmppLogger::MessageType type, const QString &text) const; Q_SLOT void testSendMessage(); - Q_SLOT void testIndexOfExtension(); - Q_SLOT void testE2eeExtension(); + Q_SLOT void testTaskDirect(); + Q_SLOT void testTaskStore(); QXmppClient *client; }; @@ -163,5 +165,68 @@ void tst_QXmppClient::testE2eeExtension() encrypter.iqCalled = false; } +void tst_QXmppClient::testTaskDirect() +{ + QXmppPromise<QXmppIq> p; + QXmppRegisterIq iq; + iq.setUsername("username"); + + bool thenCalled = false; + p.task().then(this, [&thenCalled](QXmppIq &&iq) { + thenCalled = true; + QVERIFY(dynamic_cast<QXmppRegisterIq *>(&iq)); + QCOMPARE(dynamic_cast<QXmppRegisterIq &>(iq).username(), QStringLiteral("username")); + }); + p.finish(std::move(iq)); + + QVERIFY(thenCalled); + QVERIFY(p.task().isFinished()); + QVERIFY(!p.task().hasResult()); +} + +static QXmppTask<QXmppIq> generateRegisterIq() +{ + QXmppPromise<QXmppIq> p; + QXmppRegisterIq iq; + iq.setFrom("juliet"); + iq.setUsername("username"); + p.finish(std::move(iq)); + return p.task(); +} + +void tst_QXmppClient::testTaskStore() +{ + auto task = generateRegisterIq(); + + bool thenCalled = false; + task.then(this, [&thenCalled](QXmppIq &&iq) { + thenCalled = true; + + QCOMPARE(iq.from(), QStringLiteral("juliet")); + QVERIFY(dynamic_cast<QXmppRegisterIq *>(&iq)); + QCOMPARE(dynamic_cast<QXmppRegisterIq &>(iq).username(), QStringLiteral("username")); + }); + QVERIFY(thenCalled); + + QXmppPromise<QXmppIq> p; + QXmppRegisterIq iq; + iq.setUsername("username"); + p.finish(std::move(iq)); + + QVERIFY(p.task().hasResult()); + QVERIFY(p.task().isFinished()); + + thenCalled = false; + p.task().then(this, [&thenCalled](QXmppIq &&iq) { + thenCalled = true; + QVERIFY(dynamic_cast<QXmppRegisterIq *>(&iq)); + QCOMPARE(dynamic_cast<QXmppRegisterIq &>(iq).username(), QStringLiteral("username")); + }); + QVERIFY(thenCalled); + + QVERIFY(p.task().isFinished()); + QVERIFY(!p.task().hasResult()); +} + QTEST_MAIN(tst_QXmppClient) #include "tst_qxmppclient.moc" |
