diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ChangeLog | 11 | ||||
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/gpg/Makefile.am | 6 | ||||
-rw-r--r-- | tests/gpg/t-gpgconf.c | 305 | ||||
-rw-r--r-- | tests/gpgsm/Makefile.am | 2 |
5 files changed, 321 insertions, 5 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog index 9e16ce2e..dd7c3968 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,14 @@ +2008-01-04 Marcus Brinkmann <[email protected]> + + * Makefile.am (TESTS_ENVIRONMENT): Use absolute path for + GNUPGHOME. + * gpg/Makefile.am (TESTS_ENVIRONMENT): Use absolute path for + GNUPGHOME. + * gpgsm/Makefile.am (TESTS_ENVIRONMENT): Use absolute path for + GNUPGHOME. + * gpg/Makefile.am (TESTS): Add t-gpgconf. + t-gpgconf.c: New file. + 2007-11-23 Marcus Brinkmann <[email protected]> * gpgsm/t-verify.c (show_auditlog): Check for GPG_ERR_ASS_UNKNOWN_CMD. diff --git a/tests/Makefile.am b/tests/Makefile.am index aee20ca1..ceabc999 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -20,7 +20,7 @@ ## Process this file with automake to produce Makefile.in -TESTS_ENVIRONMENT = GNUPGHOME=. +TESTS_ENVIRONMENT = GNUPGHOME=$(abs_builddir) TESTS = t-version t-data t-engine-info diff --git a/tests/gpg/Makefile.am b/tests/gpg/Makefile.am index e5d9de9b..cac589f2 100644 --- a/tests/gpg/Makefile.am +++ b/tests/gpg/Makefile.am @@ -21,7 +21,7 @@ GPG = @GPG@ -TESTS_ENVIRONMENT = GNUPGHOME=. GPG_AGENT_INFO= +TESTS_ENVIRONMENT = GNUPGHOME=$(abs_builddir) GPG_AGENT_INFO= # The keylist tests must come after the import and the edit test. noinst_HEADERS = t-support.h @@ -35,9 +35,9 @@ endif TESTS = t-encrypt t-encrypt-sym t-encrypt-sign t-sign t-signers \ t-decrypt t-verify t-decrypt-verify t-sig-notation t-export \ t-import t-trustlist t-edit t-keylist t-keylist-sig t-wait \ - t-encrypt-large t-file-name $(tests_unix) + t-encrypt-large t-file-name t-gpgconf $(tests_unix) -CLEANFILES = secring.gpg pubring.gpg trustdb.gpg +CLEANFILES = secring.gpg pubring.gpg trustdb.gpg dirmngr.conf DISTCLEANFILES = pubring.gpg~ random_seed gpg.conf EXTRA_DIST = mkdemodirs pubdemo.asc secdemo.asc cipher-1.asc cipher-2.asc \ diff --git a/tests/gpg/t-gpgconf.c b/tests/gpg/t-gpgconf.c new file mode 100644 index 00000000..458bbe75 --- /dev/null +++ b/tests/gpg/t-gpgconf.c @@ -0,0 +1,305 @@ +/* t-gpgconf.c - Regression test. + Copyright (C) 2001, 2004, 2007 g10 Code GmbH + + This file is part of GPGME. + + GPGME is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of + the License, or (at your option) any later version. + + GPGME is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <unistd.h> +#include <errno.h> +#include <stdlib.h> +#include <locale.h> +#include <string.h> + +#ifdef HAVE_W32_SYSTEM +#include <windows.h> +#endif + +#include <gpgme.h> + + +#define fail_if_err(err) \ + do \ + { \ + if (err) \ + { \ + fprintf (stderr, "%s:%d: %s: %s\n", \ + __FILE__, __LINE__, gpgme_strsource (err), \ + gpgme_strerror (err)); \ + exit (1); \ + } \ + } \ + while (0) + + +void +init_gpgme (gpgme_protocol_t proto) +{ + gpgme_error_t err; + + gpgme_check_version (NULL); + setlocale (LC_ALL, ""); + gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL)); +#ifndef HAVE_W32_SYSTEM + gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL)); +#endif + + err = gpgme_engine_check_version (proto); + fail_if_err (err); +} + + +static char * +spaces (char *str, int extra) +{ + static char buf[80]; + int len = str ? strlen (str) : 0; + int n; + +#define TABSTOP 30 + n = TABSTOP - len - extra; + + memset (buf, ' ', sizeof (buf)); + if (n < 1 || n > (sizeof (buf) - 1)) + { + buf[0] = '\n'; + n = TABSTOP + 1; + } + + buf[n] = '\0'; + return buf; +} + + +void +dump_arg (int type, gpgme_conf_arg_t arg) +{ + if (!arg) + { + printf ("(none)"); + return; + } + + while (arg) + { + switch (type) + { + case GPGME_CONF_STRING: + case GPGME_CONF_PATHNAME: + case GPGME_CONF_LDAP_SERVER: + printf ("%s", arg->value.string); + break; + + case GPGME_CONF_UINT32: + printf ("%u", arg->value.uint32); + break; + + case GPGME_CONF_INT32: + printf ("%i", arg->value.int32); + break; + + case GPGME_CONF_NONE: + printf ("%i (times)", arg->value.count); + break; + + default: + printf ("(unknown type)"); + } + + arg = arg->next; + if (arg) + printf (" "); + } +} + + +void +dump_opt (gpgme_conf_opt_t opt) +{ + char level; + char runtime = (opt->flags & GPGME_CONF_RUNTIME) ? 'r' : ' '; + + switch (opt->level) + { + case GPGME_CONF_BASIC: + level = 'b'; + break; + case GPGME_CONF_ADVANCED: + level = 'a'; + break; + case GPGME_CONF_EXPERT: + level = 'e'; + break; + case GPGME_CONF_INVISIBLE: + level = 'i'; + break; + case GPGME_CONF_INTERNAL: + level = '#'; + break; + default: + level = '?'; + } + + if (opt->flags & GPGME_CONF_GROUP) + { + printf ("\n"); + printf ("%c%c [%s]%s%s\n", level, runtime, opt->name, spaces (opt->name, 5), + opt->description + ? opt->description : ""); + } + else + { + if (opt->argname) + { + char *more = (opt->flags & GPGME_CONF_LIST) ? "..." : ""; + + if (opt->flags & GPGME_CONF_OPTIONAL) + { + printf ("%c%c --%s [%s%s] %s", level, runtime, opt->name, opt->argname, more, + spaces (opt->name, 9 + strlen (opt->argname) + strlen (more))); + } + else + { + printf ("%c%c --%s %s%s %s", level, runtime, opt->name, opt->argname, more, + spaces (opt->name, 7 + strlen (opt->argname) + strlen (more))); + } + } + else + printf ("%c%c --%s%s", level, runtime, opt->name, spaces (opt->name, 5)); + + if (opt->description) + printf ("%s", opt->description); + printf ("\n"); + + if (opt->flags & GPGME_CONF_DEFAULT) + { + printf ("%s%s = ", spaces (NULL, 0), opt->argname ? opt->argname : "(default)"); + dump_arg (opt->type, opt->default_value); + printf ("\n"); + } + else if (opt->flags & GPGME_CONF_DEFAULT_DESC) + printf ("%s%s = %s\n", spaces (NULL, 0), opt->argname ? opt->argname : "(default)", + opt->default_description); + + if (opt->no_arg_value) + { + printf ("%sNo Arg Def = ", spaces (NULL, 0)); + dump_arg (opt->type, opt->no_arg_value); + printf ("\n"); + } + if (opt->value) + { + printf ("%sCurrent = ", spaces (NULL, 0)); + dump_arg (opt->type, opt->value); + printf ("\n"); + } + } + +#if 0 + arg = comp->options; + while (opt) + { + dump_opt (opt); + opt = opt->next; + } +#endif +} + + +void +dump_comp (gpgme_conf_comp_t comp) +{ + gpgme_conf_opt_t opt; + + printf ("COMPONENT\n"); + printf ("=========\n"); + printf (" Name: %s\n", comp->name); + if (comp->description) + printf (" Desc: %s\n", comp->description); + if (comp->program_name) + printf (" Path: %s\n", comp->program_name); + printf ("\n"); + + opt = comp->options; + while (opt) + { + dump_opt (opt); + opt = opt->next; + } +} + + +int +main (int argc, char **argv) +{ + gpgme_ctx_t ctx; + gpgme_error_t err; + gpgme_conf_comp_t conf; + gpgme_conf_comp_t comp; + int first; + init_gpgme (GPGME_PROTOCOL_GPGCONF); + + err = gpgme_new (&ctx); + fail_if_err (err); + + err = gpgme_op_conf_load (ctx, &conf); + fail_if_err (err); + + comp = conf; + first = 1; + while (comp) + { + if (!first) + printf ("\n"); + else + first = 0; + dump_comp (comp); + comp = comp->next; + } + +#if 1 + /* Now change something. */ + { + unsigned int count = 1; + gpgme_conf_arg_t arg; + gpgme_conf_opt_t opt; + + err = gpgme_conf_arg_new (&arg, GPGME_CONF_NONE, &count); + fail_if_err (err); + + comp = conf; + while (comp && strcmp (comp->name, "dirmngr")) + comp = comp->next; + opt = comp->options; + while (opt && strcmp (opt->name, "verbose")) + opt = opt->next; + + err = gpgme_conf_opt_change (opt, 0, arg); + fail_if_err (err); + + err = gpgme_op_conf_save (ctx, comp); + fail_if_err (err); + } +#endif + + gpgme_conf_release (conf); + + return 0; +} diff --git a/tests/gpgsm/Makefile.am b/tests/gpgsm/Makefile.am index 86c04b0d..4d34b91f 100644 --- a/tests/gpgsm/Makefile.am +++ b/tests/gpgsm/Makefile.am @@ -21,7 +21,7 @@ GPGSM = @GPGSM@ -TESTS_ENVIRONMENT = GNUPGHOME=. GPG_AGENT_INFO= +TESTS_ENVIRONMENT = GNUPGHOME=$(abs_builddir) GPG_AGENT_INFO= noinst_HEADERS = t-support.h TESTS = t-import t-keylist t-encrypt t-verify t-decrypt t-sign t-export |