aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Klöcker <[email protected]>2022-08-18 08:55:09 +0000
committerIngo Klöcker <[email protected]>2022-08-18 08:55:09 +0000
commit2e7a61b898fccc1c20000b79dee83cd980901fa9 (patch)
tree46fe44f1eac55b60daf89ed016a666a044c0ef43
parentcpp: Fix handling of "no key" or "invalid time" situations (diff)
downloadgpgme-2e7a61b898fccc1c20000b79dee83cd980901fa9.tar.gz
gpgme-2e7a61b898fccc1c20000b79dee83cd980901fa9.zip
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
-rw-r--r--lang/qt/tests/t-addexistingsubkey.cpp42
1 files 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: