aboutsummaryrefslogtreecommitdiffstats
path: root/g10/t-keydb.c
diff options
context:
space:
mode:
authorNeal H. Walfield <[email protected]>2015-09-02 13:07:06 +0000
committerNeal H. Walfield <[email protected]>2015-09-02 13:08:57 +0000
commitee7ec1256b24dc340656c331ef92fc59cad817b6 (patch)
treec9642ff125bbbe5b095be55aa148110dae823fb0 /g10/t-keydb.c
parentg10: Make the keyblock cache per-handle rather than global. (diff)
downloadgnupg-ee7ec1256b24dc340656c331ef92fc59cad817b6.tar.gz
gnupg-ee7ec1256b24dc340656c331ef92fc59cad817b6.zip
g10: Add test for keydb as well as new testing infrastructure.
* g10/Makefile.am (EXTRA_DIST): Add test.c. (AM_CPPFLAGS): Add -DSOURCE_DIR="\"$(srcdir)\"". (module_tests): Add t-keydb. (t_keydb_SOURCES): New variable. (t_keydb_LDADD): Likewise. * g10/t-keydb.c: New file. * g10/t-keydb-keyring.kbx: New file. * g10/test-stubs.c: New file. * g10/test.c: New file. -- Signed-off-by: Neal H. Walfield <[email protected]>.
Diffstat (limited to 'g10/t-keydb.c')
-rw-r--r--g10/t-keydb.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/g10/t-keydb.c b/g10/t-keydb.c
new file mode 100644
index 000000000..0f176431c
--- /dev/null
+++ b/g10/t-keydb.c
@@ -0,0 +1,87 @@
+/* t-keydb.c - Tests for keydb.c.
+ * Copyright (C) 2015 g10 Code GmbH
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "test.c"
+
+#include "keydb.h"
+
+static void
+do_test (int argc, char *argv[])
+{
+ int rc;
+ KEYDB_HANDLE hd1, hd2;
+ KEYDB_SEARCH_DESC desc1, desc2;
+ KBNODE kb1, kb2;
+ char *uid1;
+ char *uid2;
+
+ (void) argc;
+ (void) argv;
+
+ rc = keydb_add_resource (SOURCE_DIR "/t-keydb-keyring.kbx", 0);
+ if (rc)
+ ABORT ("Failed to open keyring.");
+
+ hd1 = keydb_new ();
+ hd2 = keydb_new ();
+
+ rc = classify_user_id ("2689 5E25 E844 6D44 A26D 8FAF 2F79 98F3 DBFC 6AD9",
+ &desc1, 0);
+ if (rc)
+ ABORT ("Failed to convert fingerprint for DBFC6AD9");
+
+ rc = keydb_search (hd1, &desc1, 1, NULL);
+ if (rc)
+ ABORT ("Failed to lookup key associated with DBFC6AD9");
+
+
+ classify_user_id ("8061 5870 F5BA D690 3336 86D0 F2AD 85AC 1E42 B367",
+ &desc2, 0);
+ if (rc)
+ ABORT ("Failed to convert fingerprint for 1E42B367");
+
+ rc = keydb_search (hd2, &desc2, 1, NULL);
+ if (rc)
+ ABORT ("Failed to lookup key associated with 1E42B367");
+
+ rc = keydb_get_keyblock (hd2, &kb2);
+ if (rc)
+ ABORT ("Failed to get keyblock for 1E42B367");
+
+ rc = keydb_get_keyblock (hd1, &kb1);
+ if (rc)
+ ABORT ("Failed to get keyblock for DBFC6AD9");
+
+ while (kb1 && kb1->pkt->pkttype != PKT_USER_ID)
+ kb1 = kb1->next;
+ if (! kb1)
+ ABORT ("DBFC6AD9 has no user id packet");
+ uid1 = kb1->pkt->pkt.user_id->name;
+
+ while (kb2 && kb2->pkt->pkttype != PKT_USER_ID)
+ kb2 = kb2->next;
+ if (! kb2)
+ ABORT ("1E42B367 has no user id packet");
+ uid2 = kb2->pkt->pkt.user_id->name;
+
+ printf ("user id for DBFC6AD9: %s\n", uid1);
+ printf ("user id for 1E42B367: %s\n", uid2);
+
+ TEST_P ("cache consistency", strcmp (uid1, uid2) != 0);
+}