LCOV - code coverage report
Current view: top level - lang/qt/tests - t-keylocate.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 25 26 96.2 %
Date: 2018-11-14 16:53:58 Functions: 6 8 75.0 %

          Line data    Source code
       1             : /* t-keylocate.cpp
       2             : 
       3             :     This file is part of qgpgme, the Qt API binding for gpgme
       4             :     Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik
       5             :     Software engineering by Intevation GmbH
       6             : 
       7             :     QGpgME is free software; you can redistribute it and/or
       8             :     modify it under the terms of the GNU General Public License as
       9             :     published by the Free Software Foundation; either version 2 of the
      10             :     License, or (at your option) any later version.
      11             : 
      12             :     QGpgME is distributed in the hope that it will be useful,
      13             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :     General Public License for more details.
      16             : 
      17             :     You should have received a copy of the GNU General Public License
      18             :     along with this program; if not, write to the Free Software
      19             :     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
      20             : 
      21             :     In addition, as a special exception, the copyright holders give
      22             :     permission to link the code of this program with any edition of
      23             :     the Qt library by Trolltech AS, Norway (or with modified versions
      24             :     of Qt that use the same license as Qt), and distribute linked
      25             :     combinations including the two.  You must obey the GNU General
      26             :     Public License in all respects for all of the code used other than
      27             :     Qt.  If you modify this file, you may extend this exception to
      28             :     your version of the file, but you are not obligated to do so.  If
      29             :     you do not wish to do so, delete this exception statement from
      30             :     your version.
      31             : */
      32             : #ifdef HAVE_CONFIG_H
      33             :  #include "config.h"
      34             : #endif
      35             : 
      36             : #include <QDebug>
      37             : #include <QTest>
      38             : #include <QSignalSpy>
      39             : #include <QTemporaryDir>
      40             : #include "keylistjob.h"
      41             : #include "protocol.h"
      42             : #include "keylistresult.h"
      43             : #include "engineinfo.h"
      44             : 
      45             : #include "t-support.h"
      46             : 
      47             : using namespace QGpgME;
      48             : using namespace GpgME;
      49             : 
      50           2 : class KeyLocateTest : public QGpgMETest
      51             : {
      52             :     Q_OBJECT
      53             : 
      54             : Q_SIGNALS:
      55             :     void asyncDone();
      56             : 
      57             : private Q_SLOTS:
      58             : 
      59             : #ifdef DO_ONLINE_TESTS
      60             :     void testDaneKeyLocate()
      61             :     {
      62             :         QTemporaryDir dir;
      63             :         const QString oldHome = qgetenv("GNUPGHOME");
      64             :         qputenv("GNUPGHOME", dir.path().toUtf8());
      65             :         /* Could do this with gpgconf but this is not a gpgconf test ;-) */
      66             :         QFile conf(dir.path() + QStringLiteral("/gpg.conf"));
      67             :         QVERIFY(conf.open(QIODevice::WriteOnly));
      68             :         conf.write("auto-key-locate dane");
      69             :         conf.close();
      70             : 
      71             :         auto *job = openpgp()->locateKeysJob();
      72             :         mTestpattern = QStringLiteral("wk@gnupg.org");
      73             :         connect(job, &KeyListJob::result, job, [this, job](KeyListResult result, std::vector<Key> keys, QString, Error)
      74             :         {
      75             :             QVERIFY(!result.error());
      76             :             QVERIFY(keys.size() == 1);
      77             : 
      78             :             Key k = keys.front();
      79             :             QVERIFY(k.numUserIDs());
      80             :             bool found = false;
      81             :             Q_FOREACH (const UserID uid, k.userIDs()) {
      82             :                 const QString mailBox = QString::fromUtf8(uid.email());
      83             :                 if (mTestpattern.toLower() == mailBox.toLower()) {
      84             :                     found = true;
      85             :                 }
      86             :             }
      87             :             QVERIFY(found);
      88             :             Q_EMIT asyncDone();
      89             :         });
      90             :         job->start(QStringList() << mTestpattern);
      91             :         QSignalSpy spy (this, SIGNAL(asyncDone()));
      92             :         QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT));
      93             :         qputenv("GNUPGHOME", oldHome.toUtf8());
      94             :     }
      95             : #endif
      96             : 
      97           1 :     void testKeyLocateSingle()
      98             :     {
      99           1 :         if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.0.10") {
     100           0 :             return;
     101             :         }
     102           1 :         auto *job = openpgp()->locateKeysJob();
     103           2 :         mTestpattern = QStringLiteral("alfa@example.net");
     104             : 
     105           1 :         connect(job, &KeyListJob::result, job, [this, job](KeyListResult result, std::vector<Key> keys, QString, Error)
     106           4 :         {
     107           1 :             QVERIFY(!result.isNull());
     108           1 :             QVERIFY(!result.isTruncated());
     109           1 :             QVERIFY(!result.error());
     110           1 :             QVERIFY(keys.size() == 1);
     111             : 
     112           2 :             Key k = keys.front();
     113           1 :             QVERIFY(k.numUserIDs());
     114           1 :             bool found = false;
     115           4 :             Q_FOREACH (const UserID uid, k.userIDs()) {
     116           6 :                 const QString mailBox = QString::fromUtf8(uid.email());
     117           6 :                 if (mTestpattern.toLower() == mailBox.toLower()) {
     118           1 :                     found = true;
     119             :                 }
     120             :             }
     121           1 :             QVERIFY(found);
     122           1 :             Q_EMIT asyncDone();
     123           1 :         });
     124           1 :         job->start(QStringList() << mTestpattern);
     125           2 :         QSignalSpy spy (this, SIGNAL(asyncDone()));
     126           1 :         QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT));
     127             :     }
     128             : 
     129             : private:
     130             :     QString mTestpattern;
     131             : };
     132             : 
     133           1 : QTEST_MAIN(KeyLocateTest)
     134             : 
     135             : #include "t-keylocate.moc"

Generated by: LCOV version 1.13