Line data Source code
1 : /* t-ownertrust.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 <QDebug>
37 : #include <QTest>
38 : #include <QSignalSpy>
39 : #include "keylistjob.h"
40 : #include "protocol.h"
41 : #include "keylistresult.h"
42 : #include "changeownertrustjob.h"
43 :
44 : #include "t-support.h"
45 :
46 : using namespace QGpgME;
47 : using namespace GpgME;
48 :
49 0 : class ChangeOwnerTrustTest: public QGpgMETest
50 : {
51 : Q_OBJECT
52 :
53 : Q_SIGNALS:
54 : void asyncDone();
55 :
56 : private Q_SLOTS:
57 :
58 0 : void testChangeOwnerTrust()
59 : {
60 0 : KeyListJob *job = openpgp()->keyListJob(false, true, true);
61 0 : std::vector<GpgME::Key> keys;
62 0 : GpgME::KeyListResult result = job->exec(QStringList() << QStringLiteral("alfa@example.net"),
63 0 : false, keys);
64 0 : delete job;
65 0 : Q_ASSERT (!result.error());
66 0 : Q_ASSERT (keys.size() == 1);
67 0 : Key key = keys.front();
68 0 : Q_ASSERT (key.ownerTrust() == Key::Unknown);
69 :
70 0 : ChangeOwnerTrustJob *job2 = openpgp()->changeOwnerTrustJob();
71 0 : connect(job2, &ChangeOwnerTrustJob::result, this, [this](Error e)
72 0 : {
73 0 : if (e) {
74 0 : qDebug() << "Error in result: " << e.asString();
75 : }
76 0 : Q_ASSERT(!e);
77 0 : Q_EMIT asyncDone();
78 0 : });
79 0 : job2->start(key, Key::Ultimate);
80 0 : QSignalSpy spy (this, SIGNAL(asyncDone()));
81 0 : Q_ASSERT(spy.wait());
82 :
83 0 : job = openpgp()->keyListJob(false, true, true);
84 0 : result = job->exec(QStringList() << QStringLiteral("alfa@example.net"),
85 0 : false, keys);
86 0 : delete job;
87 0 : key = keys.front();
88 0 : Q_ASSERT (key.ownerTrust() == Key::Ultimate);
89 :
90 0 : ChangeOwnerTrustJob *job3 = openpgp()->changeOwnerTrustJob();
91 0 : connect(job3, &ChangeOwnerTrustJob::result, this, [this](Error e)
92 0 : {
93 0 : Q_ASSERT(!e);
94 0 : Q_EMIT asyncDone();
95 0 : });
96 0 : job3->start(key, Key::Unknown);
97 0 : Q_ASSERT(spy.wait());
98 :
99 0 : job = openpgp()->keyListJob(false, true, true);
100 0 : result = job->exec(QStringList() << QStringLiteral("alfa@example.net"),
101 0 : false, keys);
102 0 : delete job;
103 :
104 0 : key = keys.front();
105 0 : Q_ASSERT (key.ownerTrust() == Key::Unknown);
106 0 : }
107 : };
108 :
109 0 : QTEST_MAIN(ChangeOwnerTrustTest)
110 :
111 : #include "t-ownertrust.moc"
|