qt, tests: Add test for single get key
authorAndre Heinecke <aheinecke@intevation.de>
Tue, 9 Oct 2018 07:37:28 +0000 (09:37 +0200)
committerAndre Heinecke <aheinecke@intevation.de>
Tue, 9 Oct 2018 07:37:28 +0000 (09:37 +0200)
* 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

index bf57ba7..21349c1 100644 (file)
 #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 {