From faf987dd62893955251378a2a715edd2892a540c Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Sun, 3 Apr 2016 01:48:46 -0800 Subject: Qt: Add a unit test for qgpgme * configure.ac: Configure test Makefile. * m4/qt.m4: Look up Qt5Test flags. * lang/qt/tests/t-keylist.cpp: New. Simple keylist check. * lang/qt/tests/Makefile.am: New. General test framework. -- This test mostly checks that it basically compiles / works and adds a test framework. --- lang/qt/tests/t-keylist.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lang/qt/tests/t-keylist.cpp (limited to 'lang/qt/tests/t-keylist.cpp') diff --git a/lang/qt/tests/t-keylist.cpp b/lang/qt/tests/t-keylist.cpp new file mode 100644 index 00000000..67ace7f5 --- /dev/null +++ b/lang/qt/tests/t-keylist.cpp @@ -0,0 +1,31 @@ +#include +#include +#include "keylistjob.h" +#include "qgpgmebackend.h" +#include "keylistresult.h" + +using namespace QGpgME; + +class KeyListTest : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + + void testSingleKeyListSync() + { + QGpgMEBackend backend; + KeyListJob *job = backend.openpgp()->keyListJob(false, false, false); + std::vector keys; + GpgME::KeyListResult result = job->exec(QStringList() << QStringLiteral("alfa@example.net"), + false, keys); + Q_ASSERT (!result.error()); + Q_ASSERT (keys.size() == 1); + const QString kId = QLatin1String(keys.front().keyID()); + Q_ASSERT (kId == QStringLiteral("2D727CC768697734")); + } +}; + +QTEST_MAIN(KeyListTest) + +#include "t-keylist.moc" -- cgit v1.2.3 From 0991485170ca4ef90fd566540522027d0fc59a72 Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Sun, 3 Apr 2016 02:29:14 -0800 Subject: Qt: Add static factor methods for protocol * lang/qt/src/qgpgmebackend.cpp (QGpgME::openpgp, QGpgME::smime): New. * lang/qt/src/qgpgmebackend.h: Declare. * lang/qt/tests/t-keylist.cpp (KeyListTest::testSingleKeyListSync): Use new functions. -- This replaces the cryptobackendfactory functionality from libkleo. --- lang/qt/tests/t-keylist.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lang/qt/tests/t-keylist.cpp') diff --git a/lang/qt/tests/t-keylist.cpp b/lang/qt/tests/t-keylist.cpp index 67ace7f5..626d0a7f 100644 --- a/lang/qt/tests/t-keylist.cpp +++ b/lang/qt/tests/t-keylist.cpp @@ -14,8 +14,7 @@ private Q_SLOTS: void testSingleKeyListSync() { - QGpgMEBackend backend; - KeyListJob *job = backend.openpgp()->keyListJob(false, false, false); + KeyListJob *job = openpgp()->keyListJob(false, false, false); std::vector keys; GpgME::KeyListResult result = job->exec(QStringList() << QStringLiteral("alfa@example.net"), false, keys); -- cgit v1.2.3 From d9f7a18ed88127e7f05d770d55118d1e928f3b3f Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Mon, 11 Apr 2016 17:46:03 +0200 Subject: Qt: Fix unit test by adding initial.test dep * lang/qt/tests/t-keylist.cpp: Verify that GNUPGHOME is set. * lang/qt/tests/initial.test: New dummy test. * lang/qt/tests/Makefile.am: Add dependency to initial.test -- Feels weird but this follows the pattern in tests/gpg/Makefile.am and solves the problem that the environment is dirty. --- lang/qt/tests/t-keylist.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lang/qt/tests/t-keylist.cpp') diff --git a/lang/qt/tests/t-keylist.cpp b/lang/qt/tests/t-keylist.cpp index 626d0a7f..8aa59990 100644 --- a/lang/qt/tests/t-keylist.cpp +++ b/lang/qt/tests/t-keylist.cpp @@ -23,6 +23,12 @@ private Q_SLOTS: const QString kId = QLatin1String(keys.front().keyID()); Q_ASSERT (kId == QStringLiteral("2D727CC768697734")); } + + void initTestCase() + { + const QString gpgHome = qgetenv("GNUPGHOME"); + QVERIFY2(!gpgHome.isEmpty(), "GNUPGHOME environment variable is not set."); + } }; QTEST_MAIN(KeyListTest) -- cgit v1.2.3 From 0e3195948ddaba3af07d2415bb496491076edc17 Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Fri, 6 May 2016 16:33:49 +0200 Subject: Qt: Add test for async keylisting * src/lang/qt/tests/t-keylist.cpp(KeyListTest::testKeyListAsync): New. --- lang/qt/tests/t-keylist.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lang/qt/tests/t-keylist.cpp') diff --git a/lang/qt/tests/t-keylist.cpp b/lang/qt/tests/t-keylist.cpp index 8aa59990..f5c7f131 100644 --- a/lang/qt/tests/t-keylist.cpp +++ b/lang/qt/tests/t-keylist.cpp @@ -1,15 +1,20 @@ #include #include +#include #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 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"); -- cgit v1.2.3