LCOV - code coverage report
Current view: top level - lang/qt/tests - t-various.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 45 46 97.8 %
Date: 2017-03-02 17:11:10 Functions: 6 8 75.0 %

          Line data    Source code
       1             : /* t-various.cpp
       2             : 
       3             :     This file is part of qgpgme, the Qt API binding for gpgme
       4             :     Copyright (c) 2017 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 <QTemporaryDir>
      40             : #include "keylistjob.h"
      41             : #include "protocol.h"
      42             : #include "keylistresult.h"
      43             : #include "context.h"
      44             : #include "engineinfo.h"
      45             : 
      46             : #include "t-support.h"
      47             : 
      48             : using namespace QGpgME;
      49             : using namespace GpgME;
      50             : 
      51           2 : class TestVarious: public QGpgMETest
      52             : {
      53             :     Q_OBJECT
      54             : 
      55             : Q_SIGNALS:
      56             :     void asyncDone();
      57             : 
      58             : private Q_SLOTS:
      59             : 
      60           1 :     void testQuickUid()
      61             :     {
      62           1 :         if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.13") {
      63           0 :             return;
      64             :         }
      65           1 :         KeyListJob *job = openpgp()->keyListJob(false, true, true);
      66           2 :         std::vector<GpgME::Key> keys;
      67           3 :         GpgME::KeyListResult result = job->exec(QStringList() << QStringLiteral("alfa@example.net"),
      68           3 :                                                 false, keys);
      69           1 :         delete job;
      70           1 :         QVERIFY (!result.error());
      71           1 :         QVERIFY (keys.size() == 1);
      72           2 :         Key key = keys.front();
      73             : 
      74           1 :         QVERIFY (key.numUserIDs() == 3);
      75           1 :         const char uid[] = "Foo Bar (with comment) <foo@bar.baz>";
      76             : 
      77           1 :         auto ctx = Context::createForProtocol(key.protocol());
      78           1 :         QVERIFY (ctx);
      79           2 :         TestPassphraseProvider provider;
      80           1 :         ctx->setPassphraseProvider(&provider);
      81           1 :         ctx->setPinentryMode(Context::PinentryLoopback);
      82             : 
      83           1 :         QVERIFY(!ctx->addUid(key, uid));
      84           1 :         delete ctx;
      85           1 :         key.update();
      86             : 
      87           1 :         QVERIFY (key.numUserIDs() == 4);
      88           1 :         bool id_found = false;;
      89           1 :         for (const auto &u: key.userIDs()) {
      90           1 :             if (!strcmp (u.id(), uid)) {
      91           1 :                 QVERIFY (!u.isRevoked());
      92           1 :                 id_found = true;
      93           1 :                 break;
      94             :             }
      95             :         }
      96           1 :         QVERIFY (id_found);
      97             : 
      98           1 :         ctx = Context::createForProtocol(key.protocol());
      99           1 :         QVERIFY (!ctx->revUid(key, uid));
     100           1 :         delete ctx;
     101           1 :         key.update();
     102             : 
     103           1 :         bool id_revoked = false;;
     104           1 :         for (const auto &u: key.userIDs()) {
     105           1 :             if (!strcmp (u.id(), uid)) {
     106           1 :                 id_revoked = true;
     107           1 :                 break;
     108             :             }
     109             :         }
     110           1 :         QVERIFY(id_revoked);
     111             :     }
     112             : 
     113           1 :     void initTestCase()
     114             :     {
     115           1 :         QGpgMETest::initTestCase();
     116           2 :         const QString gpgHome = qgetenv("GNUPGHOME");
     117           1 :         QVERIFY(copyKeyrings(gpgHome, mDir.path()));
     118           1 :         qputenv("GNUPGHOME", mDir.path().toUtf8());
     119             :     }
     120             : 
     121             : private:
     122             :     QTemporaryDir mDir;
     123             : };
     124             : 
     125           1 : QTEST_MAIN(TestVarious)
     126             : 
     127             : #include "t-various.moc"

Generated by: LCOV version 1.13