qt: Avoid test failure when test is run multiple times

* lang/qt/tests/t-import.cpp (ImportTest): Add member tempGpgHome and
member function initTestCase.
(keyFpr, keyData): Move to ImportTest::testImportWithKeyOrigin.
--

Use different temporary GNUPGHOME's when running the test. This ensures
that the import in the test is always done with a new keyring.

GnuPG-bug-id: 5733
This commit is contained in:
Ingo Klöcker 2021-12-15 12:21:28 +01:00
parent 3c770013d7
commit 3e81a4a336

View File

@ -45,14 +45,39 @@
#include <QDebug>
#include <QSignalSpy>
#include <QTemporaryDir>
#include <QTest>
using namespace QGpgME;
using namespace GpgME;
static const char keyFpr[] = "5C5C428FABCC20F6913464BCCA6FB442887289B3";
class ImportTest : public QGpgMETest
{
Q_OBJECT
static const char keyData[] = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n"
private:
QTemporaryDir tempGpgHome;
Q_SIGNALS:
void asyncDone();
private Q_SLOTS:
void initTestCase()
{
QGpgMETest::initTestCase();
QVERIFY2(tempGpgHome.isValid(), "Failed to create temporary GNUPGHOME");
qputenv("GNUPGHOME", tempGpgHome.path().toLocal8Bit());
}
void testImportWithKeyOrigin()
{
if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.22") {
QSKIP("gpg does not yet support the --key-origin option");
}
static const char keyFpr[] = "5C5C428FABCC20F6913464BCCA6FB442887289B3";
static const char keyData[] =
"-----BEGIN PGP PUBLIC KEY BLOCK-----\n"
"\n"
"mDMEYbhuixYJKwYBBAHaRw8BAQdAulOM3IksCjdOJluEVlwalD8oZ5oa6wCw3EgW\n"
"NswXXb60H2ltcG9ydFdpdGhLZXlPcmlnaW5AZXhhbXBsZS5uZXSIlAQTFgoAPBYh\n"
@ -66,21 +91,6 @@ static const char keyData[] = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n"
"=putz\n"
"-----END PGP PUBLIC KEY BLOCK-----\n";
class ImportTest : public QGpgMETest
{
Q_OBJECT
Q_SIGNALS:
void asyncDone();
private Q_SLOTS:
void testImportWithKeyOrigin()
{
if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.22") {
QSKIP("gpg does not yet support the --key-origin option");
}
auto *job = openpgp()->importJob();
job->setKeyOrigin(GpgME::Key::OriginWKD, "https://example.net");
connect(job, &ImportJob::result, this,