1 /* t-support.h - Helper routines for regression tests.
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
27 #ifdef HAVE_W32_SYSTEM
34 #define DIM(v) (sizeof(v)/sizeof((v)[0]))
37 #define fail_if_err(err) \
42 fprintf (stderr, "%s:%d: %s: %s\n", \
43 __FILE__, __LINE__, gpgme_strsource (err), \
44 gpgme_strerror (err)); \
52 nonnull (const char *s)
54 return s? s :"[none]";
59 print_data (gpgme_data_t dh)
62 char buf[BUF_SIZE + 1];
65 ret = gpgme_data_seek (dh, 0, SEEK_SET);
67 fail_if_err (gpgme_err_code_from_errno (errno));
68 while ((ret = gpgme_data_read (dh, buf, BUF_SIZE)) > 0)
69 fwrite (buf, ret, 1, stdout);
71 fail_if_err (gpgme_err_code_from_errno (errno));
76 passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
77 int last_was_bad, int fd)
79 #ifdef HAVE_W32_SYSTEM
81 WriteFile ((HANDLE) fd, "abc\n", 4, &written, 0);
85 int passlen = strlen (pass);
90 res = write (fd, &pass[off], passlen - off);
94 while (res > 0 && off != passlen);
96 return off == passlen ? 0 : gpgme_error_from_errno (errno);
104 make_filename (const char *fname)
106 const char *srcdir = getenv ("srcdir");
111 buf = malloc (strlen(srcdir) + strlen(fname) + 2);
114 strcpy (buf, srcdir);
122 init_gpgme (gpgme_protocol_t proto)
126 gpgme_check_version (NULL);
127 setlocale (LC_ALL, "");
128 gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
129 #ifndef HAVE_W32_SYSTEM
130 gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
133 err = gpgme_engine_check_version (proto);
139 print_import_result (gpgme_import_result_t r)
141 gpgme_import_status_t st;
143 for (st=r->imports; st; st = st->next)
145 printf (" fpr: %s err: %d (%s) status:", nonnull (st->fpr),
146 st->result, gpgme_strerror (st->result));
147 if (st->status & GPGME_IMPORT_NEW)
148 fputs (" new", stdout);
149 if (st->status & GPGME_IMPORT_UID)
150 fputs (" uid", stdout);
151 if (st->status & GPGME_IMPORT_SIG)
152 fputs (" sig", stdout);
153 if (st->status & GPGME_IMPORT_SUBKEY)
154 fputs (" subkey", stdout);
155 if (st->status & GPGME_IMPORT_SECRET)
156 fputs (" secret", stdout);
159 printf ("key import summary:\n"
163 " imported_rsa: %d\n"
165 " new user ids: %d\n"
167 " new signatures: %d\n"
168 " new revocations: %d\n"
170 " secret imported: %d\n"
171 " secret unchanged: %d\n"
172 " skipped new keys: %d\n"
173 " not imported: %d\n",