LCOV - code coverage report
Current view: top level - lang/qt/tests - t-keylist.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 43 43 100.0 %
Date: 2016-12-01 18:45:36 Functions: 19 32 59.4 %

          Line data    Source code
       1             : /* t-keylist.cpp
       2             : 
       3             :     This file is part of qgpgme, the Qt API binding for gpgme
       4             :     Copyright (c) 2016 Intevation GmbH
       5             : 
       6             :     QGpgME is free software; you can redistribute it and/or
       7             :     modify it under the terms of the GNU General Public License as
       8             :     published by the Free Software Foundation; either version 2 of the
       9             :     License, or (at your option) any later version.
      10             : 
      11             :     QGpgME is distributed in the hope that it will be useful,
      12             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14             :     General Public License for more details.
      15             : 
      16             :     You should have received a copy of the GNU General Public License
      17             :     along with this program; if not, write to the Free Software
      18             :     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
      19             : 
      20             :     In addition, as a special exception, the copyright holders give
      21             :     permission to link the code of this program with any edition of
      22             :     the Qt library by Trolltech AS, Norway (or with modified versions
      23             :     of Qt that use the same license as Qt), and distribute linked
      24             :     combinations including the two.  You must obey the GNU General
      25             :     Public License in all respects for all of the code used other than
      26             :     Qt.  If you modify this file, you may extend this exception to
      27             :     your version of the file, but you are not obligated to do so.  If
      28             :     you do not wish to do so, delete this exception statement from
      29             :     your version.
      30             : */
      31             : 
      32             : #ifdef HAVE_CONFIG_H
      33             :  #include "config.h"
      34             : #endif
      35             : 
      36             : #include <QDebug>
      37             : #include <QTest>
      38             : #include <QSignalSpy>
      39             : #include <QMap>
      40             : #include "keylistjob.h"
      41             : #include "qgpgmebackend.h"
      42             : #include "keylistresult.h"
      43             : 
      44             : #include "t-support.h"
      45             : 
      46             : using namespace QGpgME;
      47             : using namespace GpgME;
      48             : 
      49           2 : class KeyListTest : public QGpgMETest
      50             : {
      51             :     Q_OBJECT
      52             : 
      53             : Q_SIGNALS:
      54             :     void asyncDone();
      55             : 
      56             : private Q_SLOTS:
      57           1 :     void testSingleKeyListSync()
      58             :     {
      59           1 :         KeyListJob *job = openpgp()->keyListJob(false, false, false);
      60           1 :         std::vector<GpgME::Key> keys;
      61           3 :         GpgME::KeyListResult result = job->exec(QStringList() << QStringLiteral("alfa@example.net"),
      62           3 :                                                 false, keys);
      63           1 :         delete job;
      64           1 :         Q_ASSERT (!result.error());
      65           1 :         Q_ASSERT (keys.size() == 1);
      66           2 :         const QString kId = QLatin1String(keys.front().keyID());
      67           2 :         Q_ASSERT (kId == QStringLiteral("2D727CC768697734"));
      68             : 
      69           1 :         Q_ASSERT (keys[0].subkeys().size() == 2);
      70           1 :         Q_ASSERT (keys[0].subkeys()[0].publicKeyAlgorithm() == Subkey::AlgoDSA);
      71           2 :         Q_ASSERT (keys[0].subkeys()[1].publicKeyAlgorithm() == Subkey::AlgoELG_E);
      72           1 :     }
      73             : 
      74           1 :     void testPubkeyAlgoAsString()
      75             :     {
      76             :         static const QMap<Subkey::PubkeyAlgo, QString> expected {
      77           1 :             { Subkey::AlgoRSA,    QStringLiteral("RSA") },
      78           1 :             { Subkey::AlgoRSA_E,  QStringLiteral("RSA-E") },
      79           1 :             { Subkey::AlgoRSA_S,  QStringLiteral("RSA-S") },
      80           1 :             { Subkey::AlgoELG_E,  QStringLiteral("ELG-E") },
      81           1 :             { Subkey::AlgoDSA,    QStringLiteral("DSA") },
      82           1 :             { Subkey::AlgoECC,    QStringLiteral("ECC") },
      83           1 :             { Subkey::AlgoELG,    QStringLiteral("ELG") },
      84           1 :             { Subkey::AlgoECDSA,  QStringLiteral("ECDSA") },
      85           1 :             { Subkey::AlgoECDH,   QStringLiteral("ECDH") },
      86           1 :             { Subkey::AlgoEDDSA,  QStringLiteral("EdDSA") },
      87             :             { Subkey::AlgoUnknown, QString() }
      88           1 :         };
      89          12 :         Q_FOREACH (Subkey::PubkeyAlgo algo, expected.keys()) {
      90          11 :             Q_ASSERT(QString::fromUtf8(Subkey::publicKeyAlgorithmAsString(algo)) ==
      91          11 :                      expected.value(algo));
      92           1 :         }
      93           1 :     }
      94             : 
      95           1 :     void testKeyListAsync()
      96             :     {
      97           1 :         KeyListJob *job = openpgp()->keyListJob();
      98           1 :         connect(job, &KeyListJob::result, job, [this, job](KeyListResult, std::vector<Key> keys, QString, Error)
      99             :         {
     100           1 :             Q_ASSERT(keys.size() == 1);
     101           1 :             Q_EMIT asyncDone();
     102           2 :         });
     103           1 :         job->start(QStringList() << "alfa@example.net");
     104           1 :         QSignalSpy spy (this, SIGNAL(asyncDone()));
     105           1 :         Q_ASSERT(spy.wait());
     106           1 :     }
     107             : };
     108             : 
     109           1 : QTEST_MAIN(KeyListTest)
     110             : 
     111             : #include "t-keylist.moc"

Generated by: LCOV version 1.11