1 /* run-support.h - Helper routines for run-* test programs.
2 Copyright (C) 2000 Werner Koch (dd9jn)
3 Copyright (C) 2001, 2002, 2003, 2004, 2009 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, see <http://www.gnu.org/licenses/>.
26 #ifdef HAVE_W32_SYSTEM
33 #define DIM(v) (sizeof(v)/sizeof((v)[0]))
36 #define fail_if_err(err) \
41 fprintf (stderr, PGM": file %s line %d: <%s> %s\n", \
42 __FILE__, __LINE__, gpgme_strsource (err), \
43 gpgme_strerror (err)); \
51 nonnull (const char *s)
53 return s? s :"[none]";
58 print_data (gpgme_data_t dh)
61 char buf[BUF_SIZE + 1];
64 ret = gpgme_data_seek (dh, 0, SEEK_SET);
66 fail_if_err (gpgme_err_code_from_errno (errno));
67 while ((ret = gpgme_data_read (dh, buf, BUF_SIZE)) > 0)
68 fwrite (buf, ret, 1, stdout);
70 fail_if_err (gpgme_err_code_from_errno (errno));
75 passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
76 int last_was_bad, int fd)
78 #ifdef HAVE_W32_SYSTEM
80 WriteFile ((HANDLE) fd, "abc\n", 4, &written, 0);
84 int passlen = strlen (pass);
89 res = write (fd, &pass[off], passlen - off);
93 while (res > 0 && off != passlen);
95 return off == passlen ? 0 : gpgme_error_from_errno (errno);
103 make_filename (const char *fname)
105 const char *srcdir = getenv ("srcdir");
110 buf = malloc (strlen(srcdir) + strlen(fname) + 2);
113 strcpy (buf, srcdir);
121 init_gpgme (gpgme_protocol_t proto)
125 gpgme_check_version (NULL);
126 setlocale (LC_ALL, "");
127 gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
128 #ifndef HAVE_W32_SYSTEM
129 gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
132 err = gpgme_engine_check_version (proto);
138 print_import_result (gpgme_import_result_t r)
140 gpgme_import_status_t st;
142 for (st=r->imports; st; st = st->next)
144 printf (" fpr: %s err: %d (%s) status:", nonnull (st->fpr),
145 st->result, gpg_strerror (st->result));
146 if (st->status & GPGME_IMPORT_NEW)
147 fputs (" new", stdout);
148 if (st->status & GPGME_IMPORT_UID)
149 fputs (" uid", stdout);
150 if (st->status & GPGME_IMPORT_SIG)
151 fputs (" sig", stdout);
152 if (st->status & GPGME_IMPORT_SUBKEY)
153 fputs (" subkey", stdout);
154 if (st->status & GPGME_IMPORT_SECRET)
155 fputs (" secret", stdout);
158 printf ("key import summary:\n"
162 " imported_rsa: %d\n"
164 " new user ids: %d\n"
166 " new signatures: %d\n"
167 " new revocations: %d\n"
169 " secret imported: %d\n"
170 " secret unchanged: %d\n"
171 " skipped new keys: %d\n"
172 " not imported: %d\n",