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
This commit is contained in:
Ingo Klöcker 2022-08-18 10:55:09 +02:00
parent 2fa5c80aeb
commit 2e7a61b898

View File

@ -213,24 +213,30 @@ private Q_SLOTS:
const auto result = job->exec(key, sourceSubkey); const auto result = job->exec(key, sourceSubkey);
QCOMPARE(result.code(), static_cast<int>(GPG_ERR_NO_ERROR)); if (sourceSubkey.expirationTime() > 0) {
key.update(); QCOMPARE(result.code(), static_cast<int>(GPG_ERR_NO_ERROR));
QCOMPARE(key.numSubkeys(), 3u); key.update();
QCOMPARE(key.numSubkeys(), 3u);
// allow 1 second different expiration because gpg calculates with // allow 1 second different expiration because gpg calculates with
// expiration as difference to current time and takes current time // expiration as difference to current time and takes current time
// several times // several times
const auto allowedDeltaTSeconds = 1; const auto allowedDeltaTSeconds = 1;
const auto expectedExpirationRange = std::make_pair( const auto expectedExpirationRange = std::make_pair(
uint_least32_t(sourceSubkey.expirationTime()) - allowedDeltaTSeconds, uint_least32_t(sourceSubkey.expirationTime()) - allowedDeltaTSeconds,
uint_least32_t(sourceSubkey.expirationTime()) + allowedDeltaTSeconds); uint_least32_t(sourceSubkey.expirationTime()) + allowedDeltaTSeconds);
const auto actualExpiration = uint_least32_t(key.subkey(2).expirationTime()); const auto actualExpiration = uint_least32_t(key.subkey(2).expirationTime());
QVERIFY2(actualExpiration >= expectedExpirationRange.first, QVERIFY2(actualExpiration >= expectedExpirationRange.first,
("actual: " + std::to_string(actualExpiration) + ("actual: " + std::to_string(actualExpiration) +
"; expected: " + std::to_string(expectedExpirationRange.first)).c_str()); "; expected: " + std::to_string(expectedExpirationRange.first)).c_str());
QVERIFY2(actualExpiration <= expectedExpirationRange.second, QVERIFY2(actualExpiration <= expectedExpirationRange.second,
("actual: " + std::to_string(actualExpiration) + ("actual: " + std::to_string(actualExpiration) +
"; expected: " + std::to_string(expectedExpirationRange.second)).c_str()); "; 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: private: