qt: Clean up test dirs on failure

* t-encrypt.cpp,
t-keylist.cpp,
t-keylocate.cpp,
t-ownertrust.cpp,
t-tofuinfo.cpp,
t-various.cpp,
t-verify.cpp,
t-wkspublish.cpp: Use QVERIFY instead of Q_ASSERT
This commit is contained in:
Andre Heinecke 2017-01-11 16:20:31 +01:00
parent 9e643ab671
commit 56926c9b50
8 changed files with 174 additions and 174 deletions

View File

@ -85,18 +85,18 @@ private Q_SLOTS:
std::vector<Key> keys;
auto keylistresult = listjob->exec(QStringList() << QStringLiteral("alfa@example.net"),
false, keys);
Q_ASSERT(!keylistresult.error());
Q_ASSERT(keys.size() == 1);
QVERIFY(!keylistresult.error());
QVERIFY(keys.size() == 1);
delete listjob;
auto job = openpgp()->encryptJob(/*ASCII Armor */true, /* Textmode */ true);
Q_ASSERT(job);
QVERIFY(job);
QByteArray cipherText;
auto result = job->exec(keys, QStringLiteral("Hello World").toUtf8(), Context::AlwaysTrust, cipherText);
delete job;
Q_ASSERT(!result.error());
QVERIFY(!result.error());
const auto cipherString = QString::fromUtf8(cipherText);
Q_ASSERT(cipherString.startsWith("-----BEGIN PGP MESSAGE-----"));
QVERIFY(cipherString.startsWith("-----BEGIN PGP MESSAGE-----"));
/* Now decrypt */
if (!decryptSupported()) {
@ -109,8 +109,8 @@ private Q_SLOTS:
auto decJob = new QGpgMEDecryptJob(ctx);
QByteArray plainText;
auto decResult = decJob->exec(cipherText, plainText);
Q_ASSERT(!result.error());
Q_ASSERT(QString::fromUtf8(plainText) == QStringLiteral("Hello World"));
QVERIFY(!result.error());
QVERIFY(QString::fromUtf8(plainText) == QStringLiteral("Hello World"));
delete decJob;
}
@ -125,12 +125,12 @@ private Q_SLOTS:
std::vector<Key> keys;
auto keylistresult = listjob->exec(QStringList() << QStringLiteral("alfa@example.net"),
false, keys);
Q_ASSERT(!keylistresult.error());
Q_ASSERT(keys.size() == 1);
QVERIFY(!keylistresult.error());
QVERIFY(keys.size() == 1);
delete listjob;
auto job = openpgp()->encryptJob(/*ASCII Armor */false, /* Textmode */ false);
Q_ASSERT(job);
QVERIFY(job);
QByteArray plainBa;
plainBa.fill('X', PROGRESS_TEST_SIZE);
QByteArray cipherText;
@ -140,21 +140,21 @@ private Q_SLOTS:
connect(job, &Job::progress, this, [this, &initSeen, &finishSeen] (const QString&, int current, int total) {
// We only check for progress 0 and max progress as the other progress
// lines depend on the system speed and are as such unreliable to test.
Q_ASSERT(total == PROGRESS_TEST_SIZE);
QVERIFY(total == PROGRESS_TEST_SIZE);
if (current == 0) {
initSeen = true;
}
if (current == total) {
finishSeen = true;
}
Q_ASSERT(current >= 0 && current <= total);
QVERIFY(current >= 0 && current <= total);
});
connect(job, &EncryptJob::result, this, [this, &initSeen, &finishSeen] (const GpgME::EncryptionResult &,
const QByteArray &,
const QString,
const GpgME::Error) {
Q_ASSERT(initSeen);
Q_ASSERT(finishSeen);
QVERIFY(initSeen);
QVERIFY(finishSeen);
Q_EMIT asyncDone();
});
@ -165,7 +165,7 @@ private Q_SLOTS:
job->start(keys, inptr, outptr, Context::AlwaysTrust);
QSignalSpy spy (this, SIGNAL(asyncDone()));
Q_ASSERT(spy.wait());
QVERIFY(spy.wait());
}
void testSymmetricEncryptDecrypt()
@ -183,9 +183,9 @@ private Q_SLOTS:
QByteArray cipherText;
auto result = job->exec(std::vector<Key>(), QStringLiteral("Hello symmetric World").toUtf8(), Context::AlwaysTrust, cipherText);
delete job;
Q_ASSERT(!result.error());
QVERIFY(!result.error());
const auto cipherString = QString::fromUtf8(cipherText);
Q_ASSERT(cipherString.startsWith("-----BEGIN PGP MESSAGE-----"));
QVERIFY(cipherString.startsWith("-----BEGIN PGP MESSAGE-----"));
killAgent(mDir.path());
@ -195,8 +195,8 @@ private Q_SLOTS:
auto decJob = new QGpgMEDecryptJob(ctx2);
QByteArray plainText;
auto decResult = decJob->exec(cipherText, plainText);
Q_ASSERT(!result.error());
Q_ASSERT(QString::fromUtf8(plainText) == QStringLiteral("Hello symmetric World"));
QVERIFY(!result.error());
QVERIFY(QString::fromUtf8(plainText) == QStringLiteral("Hello symmetric World"));
delete decJob;
}
@ -212,8 +212,8 @@ private:
std::vector<Key> keys;
auto keylistresult = listjob->exec(QStringList() << QStringLiteral("alfa@example.net"),
false, keys);
Q_ASSERT(!keylistresult.error());
Q_ASSERT(keys.size() == 1);
QVERIFY(!keylistresult.error());
QVERIFY(keys.size() == 1);
delete listjob;
auto ctx = Context::createForProtocol(OpenPGP);
@ -229,10 +229,10 @@ private:
cipherText);
printf("After exec\n");
delete job;
Q_ASSERT(!result.error());
QVERIFY(!result.error());
printf("Cipher:\n%s\n", cipherText.constData());
const auto cipherString = QString::fromUtf8(cipherText);
Q_ASSERT(cipherString.startsWith("-----BEGIN PGP MESSAGE-----"));
QVERIFY(cipherString.startsWith("-----BEGIN PGP MESSAGE-----"));
killAgent(mDir.path());
@ -240,7 +240,7 @@ private:
QTemporaryDir tmp;
qputenv("GNUPGHOME", tmp.path().toUtf8());
QFile agentConf(tmp.path() + QStringLiteral("/gpg-agent.conf"));
Q_ASSERT(agentConf.open(QIODevice::WriteOnly));
QVERIFY(agentConf.open(QIODevice::WriteOnly));
agentConf.write("allow-loopback-pinentry");
agentConf.close();
@ -251,9 +251,9 @@ private:
auto decJob = new QGpgMEDecryptJob(ctx2);
QByteArray plainText;
auto decResult = decJob->exec(cipherText, plainText);
Q_ASSERT(!decResult.error());
QVERIFY(!decResult.error());
qDebug() << "Plain: " << plainText;
Q_ASSERT(QString::fromUtf8(plainText) == QStringLiteral("Hello symmetric World"));
QVERIFY(QString::fromUtf8(plainText) == QStringLiteral("Hello symmetric World"));
delete decJob;
killAgent(tmp.path());
@ -267,12 +267,12 @@ public Q_SLOT:
QGpgMETest::initTestCase();
const QString gpgHome = qgetenv("GNUPGHOME");
qputenv("GNUPGHOME", mDir.path().toUtf8());
Q_ASSERT(mDir.isValid());
QVERIFY(mDir.isValid());
QFile agentConf(mDir.path() + QStringLiteral("/gpg-agent.conf"));
Q_ASSERT(agentConf.open(QIODevice::WriteOnly));
QVERIFY(agentConf.open(QIODevice::WriteOnly));
agentConf.write("allow-loopback-pinentry");
agentConf.close();
Q_ASSERT(copyKeyrings(gpgHome, mDir.path()));
QVERIFY(copyKeyrings(gpgHome, mDir.path()));
}
private:

View File

@ -61,14 +61,14 @@ private Q_SLOTS:
GpgME::KeyListResult result = job->exec(QStringList() << QStringLiteral("alfa@example.net"),
false, keys);
delete job;
Q_ASSERT (!result.error());
Q_ASSERT (keys.size() == 1);
QVERIFY (!result.error());
QVERIFY (keys.size() == 1);
const QString kId = QLatin1String(keys.front().keyID());
Q_ASSERT (kId == QStringLiteral("2D727CC768697734"));
QVERIFY (kId == QStringLiteral("2D727CC768697734"));
Q_ASSERT (keys[0].subkeys().size() == 2);
Q_ASSERT (keys[0].subkeys()[0].publicKeyAlgorithm() == Subkey::AlgoDSA);
Q_ASSERT (keys[0].subkeys()[1].publicKeyAlgorithm() == Subkey::AlgoELG_E);
QVERIFY (keys[0].subkeys().size() == 2);
QVERIFY (keys[0].subkeys()[0].publicKeyAlgorithm() == Subkey::AlgoDSA);
QVERIFY (keys[0].subkeys()[1].publicKeyAlgorithm() == Subkey::AlgoELG_E);
}
void testPubkeyAlgoAsString()
@ -87,7 +87,7 @@ private Q_SLOTS:
{ Subkey::AlgoUnknown, QString() }
};
Q_FOREACH (Subkey::PubkeyAlgo algo, expected.keys()) {
Q_ASSERT(QString::fromUtf8(Subkey::publicKeyAlgorithmAsString(algo)) ==
QVERIFY(QString::fromUtf8(Subkey::publicKeyAlgorithmAsString(algo)) ==
expected.value(algo));
}
}
@ -97,12 +97,12 @@ private Q_SLOTS:
KeyListJob *job = openpgp()->keyListJob();
connect(job, &KeyListJob::result, job, [this, job](KeyListResult, std::vector<Key> keys, QString, Error)
{
Q_ASSERT(keys.size() == 1);
QVERIFY(keys.size() == 1);
Q_EMIT asyncDone();
});
job->start(QStringList() << "alfa@example.net");
QSignalSpy spy (this, SIGNAL(asyncDone()));
Q_ASSERT(spy.wait());
QVERIFY(spy.wait());
}
};

View File

@ -63,7 +63,7 @@ private Q_SLOTS:
qputenv("GNUPGHOME", dir.path().toUtf8());
/* Could do this with gpgconf but this is not a gpgconf test ;-) */
QFile conf(dir.path() + QStringLiteral("/gpg.conf"));
Q_ASSERT(conf.open(QIODevice::WriteOnly));
QVERIFY(conf.open(QIODevice::WriteOnly));
conf.write("auto-key-locate dane");
conf.close();
@ -71,11 +71,11 @@ private Q_SLOTS:
mTestpattern = QStringLiteral("wk@gnupg.org");
connect(job, &KeyListJob::result, job, [this, job](KeyListResult result, std::vector<Key> keys, QString, Error)
{
Q_ASSERT(!result.error());
Q_ASSERT(keys.size() == 1);
QVERIFY(!result.error());
QVERIFY(keys.size() == 1);
Key k = keys.front();
Q_ASSERT(k.numUserIDs());
QVERIFY(k.numUserIDs());
bool found = false;
Q_FOREACH (const UserID uid, k.userIDs()) {
const QString mailBox = QString::fromUtf8(uid.email());
@ -83,12 +83,12 @@ private Q_SLOTS:
found = true;
}
}
Q_ASSERT(found);
QVERIFY(found);
Q_EMIT asyncDone();
});
job->start(QStringList() << mTestpattern);
QSignalSpy spy (this, SIGNAL(asyncDone()));
Q_ASSERT(spy.wait());
QVERIFY(spy.wait());
qputenv("GNUPGHOME", oldHome.toUtf8());
}
#endif
@ -103,13 +103,13 @@ private Q_SLOTS:
connect(job, &KeyListJob::result, job, [this, job](KeyListResult result, std::vector<Key> keys, QString, Error)
{
Q_ASSERT(!result.isNull());
Q_ASSERT(!result.isTruncated());
Q_ASSERT(!result.error());
Q_ASSERT(keys.size() == 1);
QVERIFY(!result.isNull());
QVERIFY(!result.isTruncated());
QVERIFY(!result.error());
QVERIFY(keys.size() == 1);
Key k = keys.front();
Q_ASSERT(k.numUserIDs());
QVERIFY(k.numUserIDs());
bool found = false;
Q_FOREACH (const UserID uid, k.userIDs()) {
const QString mailBox = QString::fromUtf8(uid.email());
@ -117,12 +117,12 @@ private Q_SLOTS:
found = true;
}
}
Q_ASSERT(found);
QVERIFY(found);
Q_EMIT asyncDone();
});
job->start(QStringList() << mTestpattern);
QSignalSpy spy (this, SIGNAL(asyncDone()));
Q_ASSERT(spy.wait());
QVERIFY(spy.wait());
}
private:

View File

@ -62,10 +62,10 @@ private Q_SLOTS:
GpgME::KeyListResult result = job->exec(QStringList() << QStringLiteral("alfa@example.net"),
false, keys);
delete job;
Q_ASSERT (!result.error());
Q_ASSERT (keys.size() == 1);
QVERIFY (!result.error());
QVERIFY (keys.size() == 1);
Key key = keys.front();
Q_ASSERT (key.ownerTrust() == Key::Unknown);
QVERIFY (key.ownerTrust() == Key::Unknown);
ChangeOwnerTrustJob *job2 = openpgp()->changeOwnerTrustJob();
connect(job2, &ChangeOwnerTrustJob::result, this, [this](Error e)
@ -73,28 +73,28 @@ private Q_SLOTS:
if (e) {
qDebug() << "Error in result: " << e.asString();
}
Q_ASSERT(!e);
QVERIFY(!e);
Q_EMIT asyncDone();
});
job2->start(key, Key::Ultimate);
QSignalSpy spy (this, SIGNAL(asyncDone()));
Q_ASSERT(spy.wait());
QVERIFY(spy.wait());
job = openpgp()->keyListJob(false, true, true);
result = job->exec(QStringList() << QStringLiteral("alfa@example.net"),
false, keys);
delete job;
key = keys.front();
Q_ASSERT (key.ownerTrust() == Key::Ultimate);
QVERIFY (key.ownerTrust() == Key::Ultimate);
ChangeOwnerTrustJob *job3 = openpgp()->changeOwnerTrustJob();
connect(job3, &ChangeOwnerTrustJob::result, this, [this](Error e)
{
Q_ASSERT(!e);
QVERIFY(!e);
Q_EMIT asyncDone();
});
job3->start(key, Key::Unknown);
Q_ASSERT(spy.wait());
QVERIFY(spy.wait());
job = openpgp()->keyListJob(false, true, true);
result = job->exec(QStringList() << QStringLiteral("alfa@example.net"),
@ -102,7 +102,7 @@ private Q_SLOTS:
delete job;
key = keys.front();
Q_ASSERT (key.ownerTrust() == Key::Unknown);
QVERIFY (key.ownerTrust() == Key::Unknown);
}
};

View File

@ -72,12 +72,12 @@ class TofuInfoTest: public QGpgMETest
void testTofuCopy(TofuInfo other, const TofuInfo &orig)
{
Q_ASSERT(!orig.isNull());
Q_ASSERT(!other.isNull());
Q_ASSERT(orig.signLast() == other.signLast());
Q_ASSERT(orig.signCount() == other.signCount());
Q_ASSERT(orig.validity() == other.validity());
Q_ASSERT(orig.policy() == other.policy());
QVERIFY(!orig.isNull());
QVERIFY(!other.isNull());
QVERIFY(orig.signLast() == other.signLast());
QVERIFY(orig.signCount() == other.signCount());
QVERIFY(orig.validity() == other.validity());
QVERIFY(orig.policy() == other.policy());
}
void signAndVerify(const QString &what, const GpgME::Key &key, int expected)
@ -94,10 +94,10 @@ class TofuInfoTest: public QGpgMETest
auto sigResult = job->exec(keys, what.toUtf8(), NormalSignatureMode, signedData);
delete job;
Q_ASSERT(!sigResult.error());
QVERIFY(!sigResult.error());
foreach (const auto uid, keys[0].userIDs()) {
auto info = uid.tofuInfo();
Q_ASSERT(info.signCount() == expected - 1);
QVERIFY(info.signCount() == expected - 1);
}
auto verifyJob = openpgp()->verifyOpaqueJob();
@ -106,25 +106,25 @@ class TofuInfoTest: public QGpgMETest
auto result = verifyJob->exec(signedData, verified);
delete verifyJob;
Q_ASSERT(!result.error());
Q_ASSERT(verified == what.toUtf8());
QVERIFY(!result.error());
QVERIFY(verified == what.toUtf8());
Q_ASSERT(result.numSignatures() == 1);
QVERIFY(result.numSignatures() == 1);
auto sig = result.signatures()[0];
auto key2 = sig.key();
Q_ASSERT(!key.isNull());
Q_ASSERT(!strcmp (key2.primaryFingerprint(), key.primaryFingerprint()));
Q_ASSERT(!strcmp (key.primaryFingerprint(), sig.fingerprint()));
QVERIFY(!key.isNull());
QVERIFY(!strcmp (key2.primaryFingerprint(), key.primaryFingerprint()));
QVERIFY(!strcmp (key.primaryFingerprint(), sig.fingerprint()));
auto stats = key2.userID(0).tofuInfo();
Q_ASSERT(!stats.isNull());
QVERIFY(!stats.isNull());
if (stats.signCount() != expected) {
std::cout << "################ Key before verify: "
<< key
<< "################ Key after verify: "
<< key2;
}
Q_ASSERT(stats.signCount() == expected);
QVERIFY(stats.signCount() == expected);
}
private Q_SLOTS:
@ -134,13 +134,13 @@ private Q_SLOTS:
return;
}
TofuInfo tofu;
Q_ASSERT(tofu.isNull());
Q_ASSERT(!tofu.description());
Q_ASSERT(!tofu.signCount());
Q_ASSERT(!tofu.signLast());
Q_ASSERT(!tofu.signFirst());
Q_ASSERT(tofu.validity() == TofuInfo::ValidityUnknown);
Q_ASSERT(tofu.policy() == TofuInfo::PolicyUnknown);
QVERIFY(tofu.isNull());
QVERIFY(!tofu.description());
QVERIFY(!tofu.signCount());
QVERIFY(!tofu.signLast());
QVERIFY(!tofu.signFirst());
QVERIFY(tofu.validity() == TofuInfo::ValidityUnknown);
QVERIFY(tofu.policy() == TofuInfo::PolicyUnknown);
}
void testTofuInfo()
@ -153,30 +153,30 @@ private Q_SLOTS:
QByteArray plaintext;
auto ctx = Job::context(job);
Q_ASSERT(ctx);
QVERIFY(ctx);
ctx->setSender("alfa@example.net");
auto result = job->exec(data1, plaintext);
delete job;
Q_ASSERT(!result.isNull());
Q_ASSERT(!result.error());
Q_ASSERT(!strcmp(plaintext.constData(), "Just GNU it!\n"));
QVERIFY(!result.isNull());
QVERIFY(!result.error());
QVERIFY(!strcmp(plaintext.constData(), "Just GNU it!\n"));
Q_ASSERT(result.numSignatures() == 1);
QVERIFY(result.numSignatures() == 1);
Signature sig = result.signatures()[0];
/* TOFU is always marginal */
Q_ASSERT(sig.validity() == Signature::Marginal);
QVERIFY(sig.validity() == Signature::Marginal);
auto stats = sig.key().userID(0).tofuInfo();
Q_ASSERT(!stats.isNull());
Q_ASSERT(sig.key().primaryFingerprint());
Q_ASSERT(sig.fingerprint());
Q_ASSERT(!strcmp(sig.key().primaryFingerprint(), sig.fingerprint()));
Q_ASSERT(stats.signFirst() == stats.signLast());
Q_ASSERT(stats.signCount() == 1);
Q_ASSERT(stats.policy() == TofuInfo::PolicyAuto);
Q_ASSERT(stats.validity() == TofuInfo::LittleHistory);
QVERIFY(!stats.isNull());
QVERIFY(sig.key().primaryFingerprint());
QVERIFY(sig.fingerprint());
QVERIFY(!strcmp(sig.key().primaryFingerprint(), sig.fingerprint()));
QVERIFY(stats.signFirst() == stats.signLast());
QVERIFY(stats.signCount() == 1);
QVERIFY(stats.policy() == TofuInfo::PolicyAuto);
QVERIFY(stats.validity() == TofuInfo::LittleHistory);
testTofuCopy(stats, stats);
@ -186,42 +186,42 @@ private Q_SLOTS:
result = job->exec(data1, plaintext);
delete job;
Q_ASSERT(!result.isNull());
Q_ASSERT(!result.error());
QVERIFY(!result.isNull());
QVERIFY(!result.error());
Q_ASSERT(result.numSignatures() == 1);
QVERIFY(result.numSignatures() == 1);
sig = result.signatures()[0];
/* TOFU is always marginal */
Q_ASSERT(sig.validity() == Signature::Marginal);
QVERIFY(sig.validity() == Signature::Marginal);
stats = sig.key().userID(0).tofuInfo();
Q_ASSERT(!stats.isNull());
Q_ASSERT(!strcmp(sig.key().primaryFingerprint(), sig.fingerprint()));
Q_ASSERT(stats.signFirst() == stats.signLast());
Q_ASSERT(stats.signCount() == 1);
Q_ASSERT(stats.policy() == TofuInfo::PolicyAuto);
Q_ASSERT(stats.validity() == TofuInfo::LittleHistory);
QVERIFY(!stats.isNull());
QVERIFY(!strcmp(sig.key().primaryFingerprint(), sig.fingerprint()));
QVERIFY(stats.signFirst() == stats.signLast());
QVERIFY(stats.signCount() == 1);
QVERIFY(stats.policy() == TofuInfo::PolicyAuto);
QVERIFY(stats.validity() == TofuInfo::LittleHistory);
/* Verify that another call yields the same result */
job = openpgp()->verifyOpaqueJob(true);
result = job->exec(data1, plaintext);
delete job;
Q_ASSERT(!result.isNull());
Q_ASSERT(!result.error());
QVERIFY(!result.isNull());
QVERIFY(!result.error());
Q_ASSERT(result.numSignatures() == 1);
QVERIFY(result.numSignatures() == 1);
sig = result.signatures()[0];
/* TOFU is always marginal */
Q_ASSERT(sig.validity() == Signature::Marginal);
QVERIFY(sig.validity() == Signature::Marginal);
stats = sig.key().userID(0).tofuInfo();
Q_ASSERT(!stats.isNull());
Q_ASSERT(!strcmp(sig.key().primaryFingerprint(), sig.fingerprint()));
Q_ASSERT(stats.signFirst() == stats.signLast());
Q_ASSERT(stats.signCount() == 1);
Q_ASSERT(stats.policy() == TofuInfo::PolicyAuto);
Q_ASSERT(stats.validity() == TofuInfo::LittleHistory);
QVERIFY(!stats.isNull());
QVERIFY(!strcmp(sig.key().primaryFingerprint(), sig.fingerprint()));
QVERIFY(stats.signFirst() == stats.signLast());
QVERIFY(stats.signCount() == 1);
QVERIFY(stats.policy() == TofuInfo::PolicyAuto);
QVERIFY(stats.validity() == TofuInfo::LittleHistory);
}
void testTofuSignCount()
@ -235,9 +235,9 @@ private Q_SLOTS:
GpgME::KeyListResult result = job->exec(QStringList() << QStringLiteral("zulu@example.net"),
true, keys);
delete job;
Q_ASSERT(!keys.empty());
QVERIFY(!keys.empty());
Key key = keys[0];
Q_ASSERT(!key.isNull());
QVERIFY(!key.isNull());
/* As we sign & verify quickly here we need different
* messages to avoid having them treated as the same
@ -266,10 +266,10 @@ private Q_SLOTS:
auto result = job->exec(QStringList() << QStringLiteral("zulu@example.net"),
true, keys);
delete job;
Q_ASSERT(!keys.empty());
QVERIFY(!keys.empty());
auto key = keys[0];
Q_ASSERT(!key.isNull());
Q_ASSERT(key.userID(0).tofuInfo().isNull());
QVERIFY(!key.isNull());
QVERIFY(key.userID(0).tofuInfo().isNull());
auto keyCopy = key;
keyCopy.update();
auto sigCnt = keyCopy.userID(0).tofuInfo().signCount();
@ -285,13 +285,13 @@ private Q_SLOTS:
result = job->exec(QStringList() << QStringLiteral("zulu@example.net"),
true, keys);
delete job;
Q_ASSERT(!result.error());
Q_ASSERT(!keys.empty());
QVERIFY(!result.error());
QVERIFY(!keys.empty());
auto key2 = keys[0];
Q_ASSERT(!key2.isNull());
QVERIFY(!key2.isNull());
auto info = key2.userID(0).tofuInfo();
Q_ASSERT(!info.isNull());
Q_ASSERT(info.signCount());
QVERIFY(!info.isNull());
QVERIFY(info.signCount());
}
void testTofuPolicy()
@ -326,25 +326,25 @@ private Q_SLOTS:
<< ">\n fpr: " << key.primaryFingerprint();
}
}
Q_ASSERT(!result.error());
Q_ASSERT(!keys.empty());
QVERIFY(!result.error());
QVERIFY(!keys.empty());
auto key = keys[0];
Q_ASSERT(!key.isNull());
Q_ASSERT(key.userID(0).tofuInfo().policy() != TofuInfo::PolicyBad);
QVERIFY(!key.isNull());
QVERIFY(key.userID(0).tofuInfo().policy() != TofuInfo::PolicyBad);
auto *tofuJob = openpgp()->tofuPolicyJob();
auto err = tofuJob->exec(key, TofuInfo::PolicyBad);
Q_ASSERT(!err);
QVERIFY(!err);
result = job->exec(QStringList() << QStringLiteral("bravo@example.net"),
false, keys);
Q_ASSERT(!keys.empty());
QVERIFY(!keys.empty());
key = keys[0];
Q_ASSERT(key.userID(0).tofuInfo().policy() == TofuInfo::PolicyBad);
QVERIFY(key.userID(0).tofuInfo().policy() == TofuInfo::PolicyBad);
err = tofuJob->exec(key, TofuInfo::PolicyGood);
result = job->exec(QStringList() << QStringLiteral("bravo@example.net"),
false, keys);
key = keys[0];
Q_ASSERT(key.userID(0).tofuInfo().policy() == TofuInfo::PolicyGood);
QVERIFY(key.userID(0).tofuInfo().policy() == TofuInfo::PolicyGood);
delete tofuJob;
delete job;
}
@ -354,16 +354,16 @@ private Q_SLOTS:
QGpgMETest::initTestCase();
const QString gpgHome = qgetenv("GNUPGHOME");
qputenv("GNUPGHOME", mDir.path().toUtf8());
Q_ASSERT(mDir.isValid());
QVERIFY(mDir.isValid());
QFile conf(mDir.path() + QStringLiteral("/gpg.conf"));
Q_ASSERT(conf.open(QIODevice::WriteOnly));
QVERIFY(conf.open(QIODevice::WriteOnly));
conf.write("trust-model tofu+pgp");
conf.close();
QFile agentConf(mDir.path() + QStringLiteral("/gpg-agent.conf"));
Q_ASSERT(agentConf.open(QIODevice::WriteOnly));
QVERIFY(agentConf.open(QIODevice::WriteOnly));
agentConf.write("allow-loopback-pinentry");
agentConf.close();
Q_ASSERT(copyKeyrings(gpgHome, mDir.path()));
QVERIFY(copyKeyrings(gpgHome, mDir.path()));
}
private:
QTemporaryDir mDir;

View File

@ -66,15 +66,15 @@ private Q_SLOTS:
GpgME::KeyListResult result = job->exec(QStringList() << QStringLiteral("alfa@example.net"),
false, keys);
delete job;
Q_ASSERT (!result.error());
Q_ASSERT (keys.size() == 1);
QVERIFY (!result.error());
QVERIFY (keys.size() == 1);
Key key = keys.front();
QVERIFY (key.numUserIDs() == 3);
const char uid[] = "Foo Bar (with comment) <foo@bar.baz>";
auto ctx = Context::createForProtocol(key.protocol());
Q_ASSERT (ctx);
QVERIFY (ctx);
TestPassphraseProvider provider;
ctx->setPassphraseProvider(&provider);
ctx->setPinentryMode(Context::PinentryLoopback);
@ -106,14 +106,14 @@ private Q_SLOTS:
break;
}
}
Q_ASSERT(id_revoked);
QVERIFY(id_revoked);
}
void initTestCase()
{
QGpgMETest::initTestCase();
const QString gpgHome = qgetenv("GNUPGHOME");
Q_ASSERT(copyKeyrings(gpgHome, mDir.path()));
QVERIFY(copyKeyrings(gpgHome, mDir.path()));
qputenv("GNUPGHOME", mDir.path().toUtf8());
}

View File

@ -70,14 +70,14 @@ private Q_SLOTS:
QByteArray verified;
auto result = verifyJob->exec(signedData, verified);
Q_ASSERT(!result.error());
QVERIFY(!result.error());
delete verifyJob;
Q_ASSERT(result.numSignatures() == 1);
QVERIFY(result.numSignatures() == 1);
auto sig = result.signatures()[0];
const auto key = sig.key(true, false);
Q_ASSERT(!key.isNull());
QVERIFY(!key.isNull());
bool found = false;
for (const auto subkey: key.subkeys()) {
@ -85,7 +85,7 @@ private Q_SLOTS:
found = true;
}
}
Q_ASSERT(found);
QVERIFY(found);
}
};

View File

@ -127,12 +127,12 @@ private Q_SLOTS:
auto job = openpgp()->wksPublishJob();
connect(job, &WKSPublishJob::result, this,
[this] (Error err, QByteArray, QByteArray, QString, Error) {
Q_ASSERT(err);
QVERIFY(err);
Q_EMIT asyncDone();
});
job->startCheck ("testuser1@localhost");
QSignalSpy spy (this, SIGNAL(asyncDone()));
Q_ASSERT(spy.wait());
QVERIFY(spy.wait());
}
#ifdef DO_ONLINE_TESTS
private Q_SLOTS:
@ -147,15 +147,15 @@ private:
[this] (Error err, QByteArray, QByteArray, QString, Error) {
if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.0.16") {
std::cout << err;
Q_ASSERT(err);
QVERIFY(err);
} else {
Q_ASSERT(!err);
QVERIFY(!err);
}
Q_EMIT asyncDone();
});
job->startCheck ("testuser1@test.gnupg.org");
QSignalSpy spy (this, SIGNAL(asyncDone()));
Q_ASSERT(spy.wait());
QVERIFY(spy.wait());
}
void testWKSPublishErrors() {
@ -166,13 +166,13 @@ private:
auto job = openpgp()->wksPublishJob();
connect(job, &WKSPublishJob::result, this,
[this] (Error err, QByteArray, QByteArray, QString, Error) {
Q_ASSERT(err);
QVERIFY(err);
Q_EMIT asyncDone();
});
job->startCreate("AB874F24E98EBB8487EE7B170F8E3D97FE7011B7",
QStringLiteral("Foo@bar.baz"));
QSignalSpy spy (this, SIGNAL(asyncDone()));
Q_ASSERT(spy.wait());
QVERIFY(spy.wait());
}
void testWKSPublishCreate() {
@ -199,31 +199,31 @@ private:
connect(keygenjob, &KeyGenerationJob::result, this,
[this, &fpr](KeyGenerationResult result, QByteArray, QString, Error)
{
Q_ASSERT(!result.error());
QVERIFY(!result.error());
fpr = QByteArray(result.fingerprint());
Q_ASSERT(!fpr.isEmpty());
QVERIFY(!fpr.isEmpty());
Q_EMIT asyncDone();
});
keygenjob->start(args);
QSignalSpy spy (this, SIGNAL(asyncDone()));
Q_ASSERT(spy.wait());
QVERIFY(spy.wait());
/* Then try to create a request. */
auto job = openpgp()->wksPublishJob();
connect(job, &WKSPublishJob::result, this,
[this] (Error err, QByteArray out, QByteArray, QString, Error) {
Q_ASSERT(!err);
QVERIFY(!err);
Q_EMIT asyncDone();
const QString outstr = QString(out);
Q_ASSERT(outstr.contains(
QVERIFY(outstr.contains(
QStringLiteral("-----BEGIN PGP PUBLIC KEY BLOCK-----")));
Q_ASSERT(outstr.contains(
QVERIFY(outstr.contains(
QStringLiteral("Content-Type: application/pgp-keys")));
Q_ASSERT(outstr.contains(
QVERIFY(outstr.contains(
QStringLiteral("From: " TEST_ADDRESS)));
});
job->startCreate(fpr.constData(), QLatin1String(TEST_ADDRESS));
Q_ASSERT(spy.wait());
QVERIFY(spy.wait());
}
void testWKSPublishReceive() {
@ -235,31 +235,31 @@ private:
connect(importjob, &ImportJob::result, this,
[this](ImportResult result, QString, Error)
{
Q_ASSERT(!result.error());
Q_ASSERT(!result.imports().empty());
Q_ASSERT(result.numSecretKeysImported());
QVERIFY(!result.error());
QVERIFY(!result.imports().empty());
QVERIFY(result.numSecretKeysImported());
Q_EMIT asyncDone();
});
importjob->start(QByteArray(testSecKey));
QSignalSpy spy (this, SIGNAL(asyncDone()));
Q_ASSERT(spy.wait());
QVERIFY(spy.wait());
/* Get a response. */
auto job = openpgp()->wksPublishJob();
connect(job, &WKSPublishJob::result, this,
[this] (Error err, QByteArray out, QByteArray, QString, Error) {
Q_ASSERT(!err);
QVERIFY(!err);
Q_EMIT asyncDone();
const QString outstr = QString(out);
Q_ASSERT(outstr.contains(
QVERIFY(outstr.contains(
QStringLiteral("-----BEGIN PGP MESSAGE-----")));
Q_ASSERT(outstr.contains(
QVERIFY(outstr.contains(
QStringLiteral("Content-Type: multipart/encrypted;")));
Q_ASSERT(outstr.contains(
QVERIFY(outstr.contains(
QStringLiteral("From: " TEST_ADDRESS)));
});
job->startReceive(QByteArray(testResponse));
Q_ASSERT(spy.wait());
QVERIFY(spy.wait());
}
void initTestCase()
@ -267,9 +267,9 @@ private:
QGpgMETest::initTestCase();
const QString gpgHome = qgetenv("GNUPGHOME");
qputenv("GNUPGHOME", mDir.path().toUtf8());
Q_ASSERT(mDir.isValid());
QVERIFY(mDir.isValid());
QFile agentConf(mDir.path() + QStringLiteral("/gpg-agent.conf"));
Q_ASSERT(agentConf.open(QIODevice::WriteOnly));
QVERIFY(agentConf.open(QIODevice::WriteOnly));
agentConf.write("allow-loopback-pinentry");
agentConf.close();
}