LCOV - code coverage report
Current view: top level - lang/qt/tests - t-support.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 34 39 87.2 %
Date: 2018-11-15 08:49:49 Functions: 9 12 75.0 %

          Line data    Source code
       1             : /* t-support.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             : 
      33             : #ifdef HAVE_CONFIG_H
      34             :  #include "config.h"
      35             : #endif
      36             : 
      37             : #include "t-support.h"
      38             : #include "context.h"
      39             : 
      40             : #include <QTest>
      41             : 
      42             : #include <QProcess>
      43             : #include <QCoreApplication>
      44             : #include <QObject>
      45             : #include <QDir>
      46             : 
      47           8 : void QGpgMETest::initTestCase()
      48             : {
      49           8 :     GpgME::initializeLibrary();
      50          16 :     const QString gpgHome = qgetenv("GNUPGHOME");
      51           8 :     QVERIFY2(!gpgHome.isEmpty(), "GNUPGHOME environment variable is not set.");
      52             : }
      53             : 
      54           8 : void QGpgMETest::cleanupTestCase()
      55             : {
      56           8 :     QCoreApplication::sendPostedEvents();
      57           8 :     killAgent();
      58           8 : }
      59             : 
      60           2 : bool QGpgMETest::copyKeyrings(const QString &src, const QString &dest)
      61             : {
      62           4 :     bool is21dir = QFileInfo(src + QDir::separator() + QStringLiteral("pubring.kbx")).exists();
      63           2 :     const QString name = is21dir ? QStringLiteral("pubring.kbx") :
      64           4 :                                   QStringLiteral("pubring.gpg");
      65           2 :     if (!QFile::copy(src + QDir::separator() + name, dest + QDir::separator() + name)) {
      66           0 :         return false;
      67             :     }
      68           2 :     if (!is21dir) {
      69           0 :         return (QFile::copy(src + QDir::separator() + QStringLiteral("secring.gpg"),
      70           0 :                  dest + QDir::separator() + QStringLiteral("secring.gpg")));
      71             :     }
      72           6 :     QDir dir (src + QDir::separator() + QStringLiteral("private-keys-v1.d"));
      73           4 :     QDir target(dest);
      74           2 :     if (!target.mkdir("private-keys-v1.d")) {
      75           0 :         return false;
      76             :     }
      77          10 :     foreach (QString f, dir.entryList(QDir::Files)) {
      78          16 :         if (!QFile::copy(dir.path() + QDir::separator() + f,
      79          16 :                          dest + QDir::separator() +
      80          40 :                          QStringLiteral("private-keys-v1.d") + QDir::separator() + f)) {
      81           0 :             return false;
      82             :         }
      83             :     }
      84           2 :     return true;
      85             : }
      86             : 
      87           9 : void killAgent(const QString& dir)
      88             : {
      89          18 :     QProcess proc;
      90          18 :     proc.setProgram(QStringLiteral("gpg-connect-agent"));
      91          18 :     QStringList arguments;
      92           9 :     arguments << "-S " << dir + "/S.gpg-agent";
      93           9 :     proc.start();
      94           9 :     proc.waitForStarted();
      95           9 :     proc.write("KILLAGENT\n");
      96           9 :     proc.write("BYE\n");
      97           9 :     proc.closeWriteChannel();
      98           9 :     proc.waitForFinished();
      99           9 : }
     100             : 
     101             : 
     102             : #include "t-support.hmoc"

Generated by: LCOV version 1.13