1 /* t-edit.c - Regression test.
2 Copyright (C) 2000 Werner Koch (dd9jn)
3 Copyright (C) 2001, 2002, 2003, 2004 g10 Code GmbH
5 This file is part of GPGME.
7 GPGME is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 2.1 of
10 the License, or (at your option) any later version.
12 GPGME is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 /* We need to include config.h so that we know whether we are building
23 with large file system (LFS) support. */
38 #include "t-support.h"
42 flush_data (gpgme_data_t dh)
47 ret = gpgme_data_seek (dh, 0, SEEK_SET);
49 fail_if_err (gpg_error_from_errno (errno));
50 while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
51 fwrite (buf, ret, 1, stdout);
53 fail_if_err (gpg_error_from_errno (errno));
58 edit_fnc (void *opaque, gpgme_status_code_t status, const char *args, int fd)
61 gpgme_data_t out = (gpgme_data_t) opaque;
63 fputs ("[-- Response --]\n", stdout);
66 fprintf (stdout, "[-- Code: %i, %s --]\n", status, args);
70 if (!strcmp (args, "keyedit.prompt"))
83 /* This fixes the primary user ID so the keylisting
84 tests will have predictable output. */
98 else if (!strcmp (args, "keyedit.save.okay"))
100 else if (!strcmp (args, "keygen.valid"))
106 gpgme_io_write (fd, result, strlen (result));
107 gpgme_io_write (fd, "\n", 1);
114 main (int argc, char **argv)
118 gpgme_data_t out = NULL;
119 gpgme_key_t key = NULL;
120 const char *pattern = "Alpha";
123 init_gpgme (GPGME_PROTOCOL_OpenPGP);
125 err = gpgme_new (&ctx);
127 err = gpgme_data_new (&out);
130 agent_info = getenv("GPG_AGENT_INFO");
131 if (!(agent_info && strchr (agent_info, ':')))
132 gpgme_set_passphrase_cb (ctx, passphrase_cb, 0);
134 err = gpgme_op_keylist_start (ctx, pattern, 0);
136 err = gpgme_op_keylist_next (ctx, &key);
138 err = gpgme_op_keylist_end (ctx);
141 err = gpgme_op_edit (ctx, key, edit_fnc, out, out);
144 fputs ("[-- Last response --]\n", stdout);
147 gpgme_data_release (out);
148 gpgme_key_unref (key);