LCOV - code coverage report
Current view: top level - lang/qt/tests - t-support.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 27 39 69.2 %
Date: 2016-11-29 15:07:43 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 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 "t-support.h"
      37             : 
      38             : #include <QTest>
      39             : 
      40             : #include <QProcess>
      41             : #include <QCoreApplication>
      42             : #include <QObject>
      43             : #include <QDir>
      44             : 
      45           6 : void QGpgMETest::initTestCase()
      46             : {
      47           6 :     const QString gpgHome = qgetenv("GNUPGHOME");
      48           6 :     QVERIFY2(!gpgHome.isEmpty(), "GNUPGHOME environment variable is not set.");
      49             : }
      50             : 
      51           6 : void QGpgMETest::cleanupTestCase()
      52             : {
      53           6 :     QCoreApplication::sendPostedEvents();
      54           6 :     killAgent();
      55           6 : }
      56             : 
      57           1 : bool QGpgMETest::copyKeyrings(const QString &src, const QString &dest)
      58             : {
      59           2 :     bool is21dir = QFileInfo(src + QDir::separator() + QStringLiteral("pubring.kbx")).exists();
      60           0 :     const QString name = is21dir ? QStringLiteral("pubring.kbx") :
      61           2 :                                   QStringLiteral("pubring.gpg");
      62           1 :     if (!QFile::copy(src + QDir::separator() + name, dest + QDir::separator() + name)) {
      63           0 :         return false;
      64             :     }
      65           1 :     if (!is21dir) {
      66           3 :         return (QFile::copy(src + QDir::separator() + QStringLiteral("secring.gpg"),
      67           4 :                  dest + QDir::separator() + QStringLiteral("secring.gpg")));
      68             :     }
      69           0 :     QDir dir (src + QDir::separator() + QStringLiteral("private-keys-v1.d"));
      70           0 :     QDir target(dest);
      71           0 :     if (!target.mkdir("private-keys-v1.d")) {
      72           0 :         return false;
      73             :     }
      74           0 :     foreach (QString f, dir.entryList(QDir::Files)) {
      75           0 :         if (!QFile::copy(dir.path() + QDir::separator() + f,
      76           0 :                          dest + QDir::separator() +
      77           0 :                          QStringLiteral("private-keys-v1.d") + QDir::separator() + f)) {
      78           0 :             return false;
      79             :         }
      80           0 :     }
      81           1 :     return true;
      82             : }
      83             : 
      84           7 : void killAgent(const QString& dir)
      85             : {
      86           7 :     QProcess proc;
      87          14 :     proc.setProgram(QStringLiteral("gpg-connect-agent"));
      88          14 :     QStringList arguments;
      89           7 :     arguments << "-S " << dir + "/S.gpg-agent";
      90           7 :     proc.start();
      91           7 :     proc.waitForStarted();
      92           7 :     proc.write("KILLAGENT\n");
      93           7 :     proc.write("BYE\n");
      94           7 :     proc.closeWriteChannel();
      95          14 :     proc.waitForFinished();
      96           7 : }
      97             : 
      98             : 
      99             : #include "t-support.hmoc"

Generated by: LCOV version 1.11