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