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 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 : #ifdef HAVE_CONFIG_H
32 : #include "config.h"
33 : #endif
34 :
35 : #include <QDebug>
36 : #include <QTest>
37 : #include <QTemporaryDir>
38 : #include "t-support.h"
39 : #include "protocol.h"
40 : #include "cryptoconfig.h"
41 : #include <unistd.h>
42 :
43 : using namespace QGpgME;
44 :
45 2 : class CryptoConfigTest: public QGpgMETest
46 : {
47 : Q_OBJECT
48 :
49 : private Q_SLOTS:
50 1 : void testKeyserver()
51 : {
52 : // Repeatedly set a config value and clear it
53 : // this war broken at some point so it gets a
54 : // unit test.
55 11 : for (int i = 0; i < 10; i++) {
56 10 : auto conf = cryptoConfig();
57 10 : QVERIFY(conf);
58 30 : auto entry = conf->entry(QStringLiteral("gpg"),
59 30 : QStringLiteral("Keyserver"),
60 40 : QStringLiteral("keyserver"));
61 10 : QVERIFY(entry);
62 30 : const QString url(QStringLiteral("hkp://foo.bar.baz"));
63 10 : entry->setStringValue(url);
64 10 : conf->sync(false);
65 10 : conf->clear();
66 20 : entry = conf->entry(QStringLiteral("gpg"),
67 30 : QStringLiteral("Keyserver"),
68 30 : QStringLiteral("keyserver"));
69 10 : QCOMPARE (entry->stringValue(), url);
70 10 : entry->setStringValue(QString());
71 10 : conf->sync(false);
72 10 : conf->clear();
73 20 : entry = conf->entry(QStringLiteral("gpg"),
74 30 : QStringLiteral("Keyserver"),
75 30 : QStringLiteral("keyserver"));
76 10 : QCOMPARE (entry->stringValue(), QString());
77 : }
78 : }
79 :
80 1 : void initTestCase()
81 : {
82 1 : QGpgMETest::initTestCase();
83 2 : const QString gpgHome = qgetenv("GNUPGHOME");
84 1 : qputenv("GNUPGHOME", mDir.path().toUtf8());
85 1 : QVERIFY(mDir.isValid());
86 : }
87 : private:
88 : QTemporaryDir mDir;
89 :
90 : };
91 :
92 1 : QTEST_MAIN(CryptoConfigTest)
93 :
94 : #include "t-config.moc"
|