1 /* t-command.c - Regression test.
2 Copyright (C) 2009 g10 Code GmbH
4 This file is part of GPGME.
6 GPGME is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of
9 the License, or (at your option) any later version.
11 GPGME is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this program; if not, see <https://www.gnu.org/licenses/>.
31 #define fail_if_err(err) \
36 fprintf (stderr, "%s:%d: %s: %s (%d.%d)\n", \
37 __FILE__, __LINE__, gpgme_strsource (err), \
38 gpgme_strerror (err), \
39 gpgme_err_source (err), gpgme_err_code (err)); \
47 data_cb (void *opaque, const void *data, size_t datalen)
52 printf ("DATA_CB: datalen=%d\n", (int)datalen);
58 inq_cb (void *opaque, const char *name, const char *args,
68 printf ("INQ_CB: name=`%s' args=`%s'\n", name, args);
69 /* There shall be no data object. */
72 err = gpgme_data_new (&data);
75 printf (" sending data object %p\n", data);
77 else /* Finished using the formerly returned data object. */
79 printf ("INQ_CB: data object %p finished\n", *r_data);
80 /* There shall be a data object so that it can be cleaned up. */
83 gpgme_data_release (*r_data);
86 /* Uncomment the next lines and send a "SCD LEARN" to test sending
87 cancel from in inquiry. */
88 /* if (name && !strcmp (name, "KNOWNCARDP")) */
89 /* return gpgme_error (GPG_ERR_ASS_CANCELED); */
97 status_cb (void *opaque, const char *status, const char *args)
101 printf ("STATUS_CB: status=`%s' args=`%s'\n", status, args);
108 main (int argc, char **argv)
111 gpgme_error_t op_err;
115 gpgme_check_version (NULL);
116 #ifndef HAVE_W32_SYSTEM
117 setlocale (LC_ALL, "");
118 gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
119 gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
127 command = argc? *argv : "NOP";
130 err = gpgme_new (&ctx);
133 err = gpgme_set_protocol (ctx, GPGME_PROTOCOL_ASSUAN);
136 err = gpgme_op_assuan_transact_ext (ctx, command, data_cb, NULL,
137 inq_cb, NULL, status_cb, NULL, &op_err);
138 fail_if_err (err || op_err);