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,35 +45,29 @@
#include <QDebug>
#include <QSignalSpy>
#include <QTemporaryDir>
#include <QTest>
using namespace QGpgME;
using namespace GpgME;
static const char keyFpr[] = "5C5C428FABCC20F6913464BCCA6FB442887289B3";
static const char keyData[] = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n"
"\n"
"mDMEYbhuixYJKwYBBAHaRw8BAQdAulOM3IksCjdOJluEVlwalD8oZ5oa6wCw3EgW\n"
"NswXXb60H2ltcG9ydFdpdGhLZXlPcmlnaW5AZXhhbXBsZS5uZXSIlAQTFgoAPBYh\n"
"BFxcQo+rzCD2kTRkvMpvtEKIcomzBQJhuG6LAhsDBQsJCAcCAyICAQYVCgkICwIE\n"
"FgIDAQIeBwIXgAAKCRDKb7RCiHKJs+cIAQDaeoOw1OCAGpZQb8xJmLJHul5dLLzU\n"
"RBdHauMx9NROmQEA23QUVedc7walQjNKFzyIJA/YqRdbAKPiLonRBmxk9Ay4OARh\n"
"uG6LEgorBgEEAZdVAQUBAQdAMVdO9mNWIP/q8PtNOnBGlPyhx/vs07sF5sXk50A+\n"
"61QDAQgHiHgEGBYKACAWIQRcXEKPq8wg9pE0ZLzKb7RCiHKJswUCYbhuiwIbDAAK\n"
"CRDKb7RCiHKJs/x6AP0SEbZqW4iLCz2i1JntQghK5qpSZOVqsBTcARd6pcJ/cwEA\n"
"mrwskWazuS9+GVbHT5RATWOXnGaj+AICSDPE6qHtGgA=\n"
"=putz\n"
"-----END PGP PUBLIC KEY BLOCK-----\n";
class ImportTest : public QGpgMETest
{
Q_OBJECT
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()
{
@ -81,6 +75,22 @@ private Q_SLOTS:
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"
"BFxcQo+rzCD2kTRkvMpvtEKIcomzBQJhuG6LAhsDBQsJCAcCAyICAQYVCgkICwIE\n"
"FgIDAQIeBwIXgAAKCRDKb7RCiHKJs+cIAQDaeoOw1OCAGpZQb8xJmLJHul5dLLzU\n"
"RBdHauMx9NROmQEA23QUVedc7walQjNKFzyIJA/YqRdbAKPiLonRBmxk9Ay4OARh\n"
"uG6LEgorBgEEAZdVAQUBAQdAMVdO9mNWIP/q8PtNOnBGlPyhx/vs07sF5sXk50A+\n"
"61QDAQgHiHgEGBYKACAWIQRcXEKPq8wg9pE0ZLzKb7RCiHKJswUCYbhuiwIbDAAK\n"
"CRDKb7RCiHKJs/x6AP0SEbZqW4iLCz2i1JntQghK5qpSZOVqsBTcARd6pcJ/cwEA\n"
"mrwskWazuS9+GVbHT5RATWOXnGaj+AICSDPE6qHtGgA=\n"
"=putz\n"
"-----END PGP PUBLIC KEY BLOCK-----\n";
auto *job = openpgp()->importJob();
job->setKeyOrigin(GpgME::Key::OriginWKD, "https://example.net");
connect(job, &ImportJob::result, this,