[Pkg-gnupg-commit] [gpgme] 286/412: Qt: Add test for progress signal of encryptjob

Daniel Kahn Gillmor dkg at fifthhorseman.net
Thu Sep 22 21:27:04 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gpgme.

commit 391e55411cda11446ca9de4dd0dc2b54d3e6fff5
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Fri Aug 12 16:55:51 2016 +0200

    Qt: Add test for progress signal of encryptjob
    
    * lang/qt/tests/t-encrypt.cpp (testProgress): New.
    
    --
    This tests that a ByteArray IODevice now gives proper progress
    signals.
---
 lang/qt/tests/t-encrypt.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/lang/qt/tests/t-encrypt.cpp b/lang/qt/tests/t-encrypt.cpp
index c6fcaa2..708c205 100644
--- a/lang/qt/tests/t-encrypt.cpp
+++ b/lang/qt/tests/t-encrypt.cpp
@@ -31,6 +31,8 @@
 #include <QDebug>
 #include <QTest>
 #include <QTemporaryDir>
+#include <QSignalSpy>
+#include <QBuffer>
 #include "keylistjob.h"
 #include "encryptjob.h"
 #include "qgpgmeencryptjob.h"
@@ -39,8 +41,11 @@
 #include "qgpgmedecryptjob.h"
 #include "qgpgmebackend.h"
 #include "keylistresult.h"
+#include "engineinfo.h"
 #include "t-support.h"
 
+#define PROGRESS_TEST_SIZE 1 * 1024 * 1024
+
 using namespace QGpgME;
 using namespace GpgME;
 
@@ -48,6 +53,9 @@ class EncryptionTest : public QGpgMETest
 {
     Q_OBJECT
 
+Q_SIGNALS:
+    void asyncDone();
+
 private Q_SLOTS:
 
     void testSimpleEncryptDecrypt()
@@ -82,6 +90,60 @@ private Q_SLOTS:
         delete decJob;
     }
 
+    void testProgress()
+    {
+        if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.15") {
+            // We can only test the progress with 2.1.15 as this started to
+            // have total progress for memory callbacks
+            return;
+        }
+        auto listjob = openpgp()->keyListJob(false, false, false);
+        std::vector<Key> keys;
+        auto keylistresult = listjob->exec(QStringList() << QStringLiteral("alfa at example.net"),
+                                          false, keys);
+        Q_ASSERT(!keylistresult.error());
+        Q_ASSERT(keys.size() == 1);
+        delete listjob;
+
+        auto job = openpgp()->encryptJob(/*ASCII Armor */false, /* Textmode */ false);
+        Q_ASSERT(job);
+        QByteArray plainBa;
+        plainBa.fill('X', PROGRESS_TEST_SIZE);
+        QByteArray cipherText;
+
+        bool initSeen = false;
+        bool finishSeen = false;
+        connect(job, &Job::progress, this, [this, &initSeen, &finishSeen] (const QString& what, int current, int total) {
+                // We only check for progress 0 and max progress as the other progress
+                // lines depend on the system speed and are as such unreliable to test.
+                Q_ASSERT(total == PROGRESS_TEST_SIZE);
+                if (current == 0) {
+                    initSeen = true;
+                }
+                if (current == total) {
+                    finishSeen = true;
+                }
+                Q_ASSERT(current >= 0 && current <= total);
+            });
+        connect(job, &EncryptJob::result, this, [this, &initSeen, &finishSeen] (const GpgME::EncryptionResult &result,
+                                                                                const QByteArray &cipherText,
+                                                                                const QString,
+                                                                                const GpgME::Error) {
+                Q_ASSERT(initSeen);
+                Q_ASSERT(finishSeen);
+                Q_EMIT asyncDone();
+            });
+
+        auto inptr  = std::shared_ptr<QIODevice>(new QBuffer(&plainBa));
+        inptr->open(QIODevice::ReadOnly);
+        auto outptr = std::shared_ptr<QIODevice>(new QBuffer(&cipherText));
+        outptr->open(QIODevice::WriteOnly);
+
+        job->start(keys, inptr, outptr, Context::AlwaysTrust);
+        QSignalSpy spy (this, SIGNAL(asyncDone()));
+        Q_ASSERT(spy.wait());
+    }
+
     void testSymmetricEncryptDecrypt()
     {
         auto ctx = Context::createForProtocol(OpenPGP);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git



More information about the Pkg-gnupg-commit mailing list