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