Qt: Create TestPassphraseProvider on stack

* lang/qt/tests/t-encrypt.cpp, lang/qt/tests/t-tofuinfo.cpp: Create
TestPassphraseProvider on stack.

--
Context does not delete the provider. This fixes ASAN errors.
This commit is contained in:
Andre Heinecke 2016-08-10 12:05:32 +02:00
parent 21d5e71d48
commit a27d7755d0
2 changed files with 7 additions and 4 deletions

View File

@ -71,7 +71,8 @@ private Q_SLOTS:
/* Now decrypt */ /* Now decrypt */
auto ctx = Context::createForProtocol(OpenPGP); auto ctx = Context::createForProtocol(OpenPGP);
ctx->setPassphraseProvider(new TestPassphraseProvider); TestPassphraseProvider provider;
ctx->setPassphraseProvider(&provider);
ctx->setPinentryMode(Context::PinentryLoopback); ctx->setPinentryMode(Context::PinentryLoopback);
auto decJob = new QGpgMEDecryptJob(ctx); auto decJob = new QGpgMEDecryptJob(ctx);
QByteArray plainText; QByteArray plainText;
@ -84,7 +85,8 @@ private Q_SLOTS:
void testSymmetricEncryptDecrypt() void testSymmetricEncryptDecrypt()
{ {
auto ctx = Context::createForProtocol(OpenPGP); auto ctx = Context::createForProtocol(OpenPGP);
ctx->setPassphraseProvider(new TestPassphraseProvider); TestPassphraseProvider provider;
ctx->setPassphraseProvider(&provider);
ctx->setPinentryMode(Context::PinentryLoopback); ctx->setPinentryMode(Context::PinentryLoopback);
ctx->setArmor(true); ctx->setArmor(true);
ctx->setTextMode(true); ctx->setTextMode(true);
@ -99,7 +101,7 @@ private Q_SLOTS:
killAgent(mDir.path()); killAgent(mDir.path());
auto ctx2 = Context::createForProtocol(OpenPGP); auto ctx2 = Context::createForProtocol(OpenPGP);
ctx2->setPassphraseProvider(new TestPassphraseProvider); ctx2->setPassphraseProvider(&provider);
ctx2->setPinentryMode(Context::PinentryLoopback); ctx2->setPinentryMode(Context::PinentryLoopback);
auto decJob = new QGpgMEDecryptJob(ctx2); auto decJob = new QGpgMEDecryptJob(ctx2);
QByteArray plainText; QByteArray plainText;

View File

@ -73,7 +73,8 @@ class TofuInfoTest: public QGpgMETest
void signAndVerify(const QString &what, const GpgME::Key &key, int expected) void signAndVerify(const QString &what, const GpgME::Key &key, int expected)
{ {
Context *ctx = Context::createForProtocol(OpenPGP); Context *ctx = Context::createForProtocol(OpenPGP);
ctx->setPassphraseProvider(new TestPassphraseProvider); TestPassphraseProvider provider;
ctx->setPassphraseProvider(&provider);
ctx->setPinentryMode(Context::PinentryLoopback); ctx->setPinentryMode(Context::PinentryLoopback);
auto *job = new QGpgMESignJob(ctx); auto *job = new QGpgMESignJob(ctx);