qt, tests: Add test for single get key

* lang/qt/tests/t-keylist.cpp (testGetKey): New.

--
Added this to check if there was a memleak in that function.
This commit is contained in:
Andre Heinecke 2018-10-09 09:37:28 +02:00
parent 1c7f93fbc8
commit bf4aae4512
No known key found for this signature in database
GPG Key ID: 2978E9D40CBABA5C

View File

@ -42,6 +42,10 @@
#include "qgpgmebackend.h"
#include "keylistresult.h"
#include "context.h"
#include <memory>
#include "t-support.h"
using namespace QGpgME;
@ -72,6 +76,35 @@ private Q_SLOTS:
QVERIFY (keys[0].subkeys()[1].publicKeyAlgorithm() == Subkey::AlgoELG_E);
}
// This test can help with valgrind to check for memleaks when handling
// keys
void testGetKey()
{
GpgME::Key key;
{
auto ctx = std::unique_ptr<GpgME::Context> (GpgME::Context::createForProtocol(GpgME::OpenPGP));
ctx->setKeyListMode (GpgME::KeyListMode::Local |
GpgME::KeyListMode::Signatures |
GpgME::KeyListMode::Validate |
GpgME::KeyListMode::WithTofu);
GpgME::Error err;
key = ctx->key ("A0FF4590BB6122EDEF6E3C542D727CC768697734", err, false);
}
QVERIFY(key.primaryFingerprint());
QVERIFY(!strcmp(key.primaryFingerprint(), "A0FF4590BB6122EDEF6E3C542D727CC768697734"));
{
auto ctx = std::unique_ptr<GpgME::Context> (GpgME::Context::createForProtocol(GpgME::OpenPGP));
ctx->setKeyListMode (GpgME::KeyListMode::Local |
GpgME::KeyListMode::Signatures |
GpgME::KeyListMode::Validate |
GpgME::KeyListMode::WithTofu);
GpgME::Error err;
key = ctx->key ("A0FF4590BB6122EDEF6E3C542D727CC768697734", err, false);
}
QVERIFY(key.primaryFingerprint());
QVERIFY(!strcmp(key.primaryFingerprint(), "A0FF4590BB6122EDEF6E3C542D727CC768697734"));
}
void testPubkeyAlgoAsString()
{
static const QMap<Subkey::PubkeyAlgo, QString> expected {