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
29 #define fail_if_err(err) \
34 fprintf (stderr, "%s:%d: %s: %s (%d.%d)\n", \
35 __FILE__, __LINE__, gpgme_strsource (err), \
36 gpgme_strerror (err), \
37 gpgme_err_source (err), gpgme_err_code (err)); \
45 print_data (gpgme_data_t dh)
48 char buf[BUF_SIZE + 1];
51 ret = gpgme_data_seek (dh, 0, SEEK_SET);
53 fail_if_err (gpgme_error_from_errno (errno));
54 while ((ret = gpgme_data_read (dh, buf, BUF_SIZE)) > 0)
55 fwrite (buf, ret, 1, stdout);
57 fail_if_err (gpgme_error_from_errno (errno));
62 passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
63 int last_was_bad, int fd)
67 int passlen = strlen (pass);
72 res = write (fd, &pass[off], passlen - off);
76 while (res > 0 && off != passlen);
78 return off == passlen ? 0 : gpgme_error_from_errno (errno);
83 make_filename (const char *fname)
85 const char *srcdir = getenv ("srcdir");
90 buf = malloc (strlen(srcdir) + strlen(fname) + 2);
101 init_gpgme (gpgme_protocol_t proto)
105 gpgme_check_version (NULL);
106 #ifndef HAVE_W32_SYSTEM
107 setlocale (LC_ALL, "");
108 gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
109 gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
112 err = gpgme_engine_check_version (proto);