LCOV - code coverage report
Current view: top level - lang/qt/tests - t-config.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 52 53 98.1 %
Date: 2018-11-15 08:49:49 Functions: 27 49 55.1 %

          Line data    Source code
       1             : /* t-config.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 <QTemporaryDir>
      39             : #include "t-support.h"
      40             : #include "protocol.h"
      41             : #include "cryptoconfig.h"
      42             : #include "engineinfo.h"
      43             : 
      44             : #include <unistd.h>
      45             : 
      46             : using namespace QGpgME;
      47             : 
      48           2 : class CryptoConfigTest: public QGpgMETest
      49             : {
      50             :     Q_OBJECT
      51             : 
      52             : private Q_SLOTS:
      53           1 :     void testKeyserver()
      54             :     {
      55             :         // Repeatedly set a config value and clear it
      56             :         // this was broken at some point so it gets a
      57             :         // unit test.
      58          11 :         for (int i = 0; i < 10; i++) {
      59          10 :             auto conf = cryptoConfig();
      60          10 :             QVERIFY(conf);
      61          30 :             auto entry = conf->entry(QStringLiteral("gpg"),
      62          30 :                     QStringLiteral("Keyserver"),
      63          40 :                     QStringLiteral("keyserver"));
      64          10 :             QVERIFY(entry);
      65          30 :             const QString url(QStringLiteral("hkp://foo.bar.baz"));
      66          10 :             entry->setStringValue(url);
      67          10 :             conf->sync(false);
      68          10 :             conf->clear();
      69          30 :             entry = conf->entry(QStringLiteral("gpg"),
      70          30 :                     QStringLiteral("Keyserver"),
      71          40 :                     QStringLiteral("keyserver"));
      72          10 :             QCOMPARE (entry->stringValue(), url);
      73          10 :             entry->setStringValue(QString());
      74          10 :             conf->sync(false);
      75          10 :             conf->clear();
      76          30 :             entry = conf->entry(QStringLiteral("gpg"),
      77          30 :                     QStringLiteral("Keyserver"),
      78          40 :                     QStringLiteral("keyserver"));
      79          10 :             QCOMPARE (entry->stringValue(), QString());
      80             :         }
      81             :     }
      82             : 
      83           1 :     void testDefault()
      84             :     {
      85           1 :         if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.2.0") {
      86             :             // We are using compliance here and other options might also
      87             :             // be unsupported in older versions.
      88           0 :             return;
      89             :         }
      90             :         // First set compliance to de-vs
      91           1 :         auto conf = cryptoConfig();
      92           1 :         QVERIFY(conf);
      93           3 :         auto entry = conf->entry(QStringLiteral("gpg"),
      94           3 :                 QStringLiteral("Configuration"),
      95           4 :                 QStringLiteral("compliance"));
      96           1 :         QVERIFY(entry);
      97           1 :         entry->setStringValue("de-vs");
      98           1 :         conf->sync(true);
      99           1 :         conf->clear();
     100           3 :         entry = conf->entry(QStringLiteral("gpg"),
     101           3 :                 QStringLiteral("Configuration"),
     102           4 :                 QStringLiteral("compliance"));
     103           2 :         QCOMPARE(entry->stringValue(), QStringLiteral("de-vs"));
     104           1 :         entry->resetToDefault();
     105           1 :         conf->sync(true);
     106           1 :         conf->clear();
     107           3 :         entry = conf->entry(QStringLiteral("gpg"),
     108           3 :                 QStringLiteral("Configuration"),
     109           4 :                 QStringLiteral("compliance"));
     110           2 :         QCOMPARE(entry->stringValue(), QStringLiteral("gnupg"));
     111             :     }
     112             : 
     113           1 :     void initTestCase()
     114             :     {
     115           1 :         QGpgMETest::initTestCase();
     116           2 :         const QString gpgHome = qgetenv("GNUPGHOME");
     117           1 :         qputenv("GNUPGHOME", mDir.path().toUtf8());
     118           1 :         QVERIFY(mDir.isValid());
     119             :     }
     120             : private:
     121             :     QTemporaryDir mDir;
     122             : 
     123             : };
     124             : 
     125           1 : QTEST_MAIN(CryptoConfigTest)
     126             : 
     127             : #include "t-config.moc"

Generated by: LCOV version 1.13