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);
83 write (fd, "abc\n", 4);
91 make_filename (const char *fname)
93 const char *srcdir = getenv ("srcdir");
98 buf = malloc (strlen(srcdir) + strlen(fname) + 2);
101 strcpy (buf, srcdir);
109 init_gpgme (gpgme_protocol_t proto)
113 gpgme_check_version (NULL);
114 setlocale (LC_ALL, "");
115 gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
116 #ifndef HAVE_W32_SYSTEM
117 gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
120 err = gpgme_engine_check_version (proto);
126 print_import_result (gpgme_import_result_t r)
128 gpgme_import_status_t st;
130 for (st=r->imports; st; st = st->next)
132 printf (" fpr: %s err: %d (%s) status:", nonnull (st->fpr),
133 st->result, gpg_strerror (st->result));
134 if (st->status & GPGME_IMPORT_NEW)
135 fputs (" new", stdout);
136 if (st->status & GPGME_IMPORT_UID)
137 fputs (" uid", stdout);
138 if (st->status & GPGME_IMPORT_SIG)
139 fputs (" sig", stdout);
140 if (st->status & GPGME_IMPORT_SUBKEY)
141 fputs (" subkey", stdout);
142 if (st->status & GPGME_IMPORT_SECRET)
143 fputs (" secret", stdout);
146 printf ("key import summary:\n"
150 " imported_rsa: %d\n"
152 " new user ids: %d\n"
154 " new signatures: %d\n"
155 " new revocations: %d\n"
157 " secret imported: %d\n"
158 " secret unchanged: %d\n"
159 " skipped new keys: %d\n"
160 " not imported: %d\n",