From 3e81a4a336e093d075f83afe3e1bd26493e64cac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Wed, 15 Dec 2021 12:21:28 +0100 Subject: [PATCH] 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 --- lang/qt/tests/t-import.cpp | 42 +++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/lang/qt/tests/t-import.cpp b/lang/qt/tests/t-import.cpp index aaa05c0d..a2cb7826 100644 --- a/lang/qt/tests/t-import.cpp +++ b/lang/qt/tests/t-import.cpp @@ -45,35 +45,29 @@ #include #include +#include #include 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,