aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lang/qt/tests/t-encrypt.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/lang/qt/tests/t-encrypt.cpp b/lang/qt/tests/t-encrypt.cpp
index c6fcaa21..708c2050 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("[email protected]"),
+ 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);