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