Qt: Add test for async keylisting
authorAndre Heinecke <aheinecke@intevation.de>
Fri, 6 May 2016 14:33:49 +0000 (16:33 +0200)
committerAndre Heinecke <aheinecke@intevation.de>
Tue, 10 May 2016 10:51:45 +0000 (12:51 +0200)
* src/lang/qt/tests/t-keylist.cpp(KeyListTest::testKeyListAsync): New.

lang/qt/tests/t-keylist.cpp

index 8aa5999..f5c7f13 100644 (file)
@@ -1,15 +1,20 @@
 #include <QDebug>
 #include <QTest>
+#include <QSignalSpy>
 #include "keylistjob.h"
 #include "qgpgmebackend.h"
 #include "keylistresult.h"
 
 using namespace QGpgME;
+using namespace GpgME;
 
 class KeyListTest : public QObject
 {
     Q_OBJECT
 
+Q_SIGNALS:
+    void asyncDone();
+
 private Q_SLOTS:
 
     void testSingleKeyListSync()
@@ -24,6 +29,19 @@ private Q_SLOTS:
         Q_ASSERT (kId == QStringLiteral("2D727CC768697734"));
     }
 
+    void testKeyListAsync()
+    {
+        KeyListJob *job = openpgp()->keyListJob();
+        connect(job, &KeyListJob::result, job, [this, job](KeyListResult, std::vector<Key> keys, QString, Error)
+        {
+            Q_ASSERT(keys.size() == 1);
+            Q_EMIT asyncDone();
+        });
+        job->start(QStringList() << "alfa@example.net");
+        QSignalSpy spy (this, &KeyListTest::asyncDone);
+        Q_ASSERT(spy.wait());
+    }
+
     void initTestCase()
     {
         const QString gpgHome = qgetenv("GNUPGHOME");