From bf4aae45129c1093ee7712bdbcdfe1c8f2ca7c0f Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Tue, 9 Oct 2018 09:37:28 +0200 Subject: [PATCH] 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. --- lang/qt/tests/t-keylist.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lang/qt/tests/t-keylist.cpp b/lang/qt/tests/t-keylist.cpp index bf57ba75..21349c1c 100644 --- a/lang/qt/tests/t-keylist.cpp +++ b/lang/qt/tests/t-keylist.cpp @@ -42,6 +42,10 @@ #include "qgpgmebackend.h" #include "keylistresult.h" +#include "context.h" + +#include + #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::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::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 expected {