From 2e7a61b898fccc1c20000b79dee83cd980901fa9 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Ingo=20Kl=C3=B6cker?= <dev@ingo-kloecker.de>
Date: Thu, 18 Aug 2022 10:55:09 +0200
Subject: [PATCH] qt,tests: Make test pass on 32-bit systems

* lang/qt/tests/t-addexistingsubkey.cpp
(AddExistingSubkeyJobTest::testAddExistingSubkeyWithExpiration): Handle
negative expiration date.
--

On 32-bit systems the expiration date of the test key overflows. This
will cause the AddExistingSubkeyJob to fail. We expect it to fail with
an "invalid time" error.

GnuPG-bug-id: 6137
---
 lang/qt/tests/t-addexistingsubkey.cpp | 42 ++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 18 deletions(-)

diff --git a/lang/qt/tests/t-addexistingsubkey.cpp b/lang/qt/tests/t-addexistingsubkey.cpp
index 87eadf43..c0eee57b 100644
--- a/lang/qt/tests/t-addexistingsubkey.cpp
+++ b/lang/qt/tests/t-addexistingsubkey.cpp
@@ -213,24 +213,30 @@ private Q_SLOTS:
 
         const auto result = job->exec(key, sourceSubkey);
 
-        QCOMPARE(result.code(), static_cast<int>(GPG_ERR_NO_ERROR));
-        key.update();
-        QCOMPARE(key.numSubkeys(), 3u);
-
-        // allow 1 second different expiration because gpg calculates with
-        // expiration as difference to current time and takes current time
-        // several times
-        const auto allowedDeltaTSeconds = 1;
-        const auto expectedExpirationRange = std::make_pair(
-            uint_least32_t(sourceSubkey.expirationTime()) - allowedDeltaTSeconds,
-            uint_least32_t(sourceSubkey.expirationTime()) + allowedDeltaTSeconds);
-        const auto actualExpiration = uint_least32_t(key.subkey(2).expirationTime());
-        QVERIFY2(actualExpiration >= expectedExpirationRange.first,
-                 ("actual: " + std::to_string(actualExpiration) +
-                  "; expected: " + std::to_string(expectedExpirationRange.first)).c_str());
-        QVERIFY2(actualExpiration <= expectedExpirationRange.second,
-                 ("actual: " + std::to_string(actualExpiration) +
-                  "; expected: " + std::to_string(expectedExpirationRange.second)).c_str());
+        if (sourceSubkey.expirationTime() > 0) {
+            QCOMPARE(result.code(), static_cast<int>(GPG_ERR_NO_ERROR));
+            key.update();
+            QCOMPARE(key.numSubkeys(), 3u);
+
+            // allow 1 second different expiration because gpg calculates with
+            // expiration as difference to current time and takes current time
+            // several times
+            const auto allowedDeltaTSeconds = 1;
+            const auto expectedExpirationRange = std::make_pair(
+                uint_least32_t(sourceSubkey.expirationTime()) - allowedDeltaTSeconds,
+                uint_least32_t(sourceSubkey.expirationTime()) + allowedDeltaTSeconds);
+            const auto actualExpiration = uint_least32_t(key.subkey(2).expirationTime());
+            QVERIFY2(actualExpiration >= expectedExpirationRange.first,
+                    ("actual: " + std::to_string(actualExpiration) +
+                    "; expected: " + std::to_string(expectedExpirationRange.first)).c_str());
+            QVERIFY2(actualExpiration <= expectedExpirationRange.second,
+                    ("actual: " + std::to_string(actualExpiration) +
+                    "; expected: " + std::to_string(expectedExpirationRange.second)).c_str());
+        } else {
+            // on 32-bit systems the expiration date of the test key overflows;
+            // in this case we expect an appropriate error code
+            QCOMPARE(result.code(), static_cast<int>(GPG_ERR_INV_TIME));
+        }
     }
 
 private:
-- 
2.11.0

