LCOV - code coverage report
Current view: top level - tests/opassuan - t-command.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 35 0.0 %
Date: 2018-11-14 16:53:58 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /* t-command.c - Regression test.
       2             :    Copyright (C) 2009 g10 Code GmbH
       3             : 
       4             :    This file is part of GPGME.
       5             : 
       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.
      10             : 
      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.
      15             : 
      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/>.
      18             :  */
      19             : 
      20             : #ifdef HAVE_CONFIG_H
      21             : #include <config.h>
      22             : #endif
      23             : 
      24             : #include <stdlib.h>
      25             : #include <string.h>
      26             : #include <locale.h>
      27             : #include <assert.h>
      28             : 
      29             : #include <gpgme.h>
      30             : 
      31             : #define fail_if_err(err)                                        \
      32             :   do                                                            \
      33             :     {                                                           \
      34             :       if (err)                                                  \
      35             :         {                                                       \
      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)); \
      40             :           exit (1);                                             \
      41             :         }                                                       \
      42             :     }                                                           \
      43             :   while (0)
      44             : 
      45             : 
      46             : static gpgme_error_t
      47           0 : data_cb (void *opaque, const void *data, size_t datalen)
      48             : {
      49             :   (void)opaque;
      50             :   (void)data;
      51             : 
      52           0 :   printf ("DATA_CB: datalen=%d\n", (int)datalen);
      53           0 :   return 0;
      54             : }
      55             : 
      56             : 
      57             : static gpgme_error_t
      58           0 : inq_cb (void *opaque, const char *name, const char *args,
      59             :         gpgme_data_t *r_data)
      60             : {
      61             :   gpgme_data_t data;
      62             :   gpgme_error_t err;
      63             : 
      64             :   (void)opaque;
      65             : 
      66           0 :   if (name)
      67             :     {
      68           0 :       printf ("INQ_CB: name=`%s' args=`%s'\n", name, args);
      69             :       /* There shall be no data object.  */
      70           0 :       assert (!*r_data);
      71             : 
      72           0 :       err = gpgme_data_new (&data);
      73           0 :       fail_if_err (err);
      74           0 :       *r_data = data;
      75           0 :       printf ("        sending data object %p\n", data);
      76             :     }
      77             :   else /* Finished using the formerly returned data object.  */
      78             :     {
      79           0 :       printf ("INQ_CB: data object %p finished\n", *r_data);
      80             :       /* There shall be a data object so that it can be cleaned up. */
      81           0 :       assert (r_data);
      82             : 
      83           0 :       gpgme_data_release (*r_data);
      84             :     }
      85             : 
      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); */
      90             : 
      91             : 
      92           0 :   return 0;
      93             : }
      94             : 
      95             : 
      96             : static gpgme_error_t
      97           0 : status_cb (void *opaque, const char *status, const char *args)
      98             : {
      99             :   (void)opaque;
     100             : 
     101           0 :   printf ("STATUS_CB: status=`%s'  args=`%s'\n", status, args);
     102           0 :   return 0;
     103             : }
     104             : 
     105             : 
     106             : 
     107             : int
     108           0 : main (int argc, char **argv)
     109             : {
     110             :   gpgme_error_t err;
     111             :   gpgme_error_t op_err;
     112             :   gpgme_ctx_t ctx;
     113             :   const char *command;
     114             : 
     115           0 :   gpgme_check_version (NULL);
     116             : #ifndef HAVE_W32_SYSTEM
     117           0 :   setlocale (LC_ALL, "");
     118           0 :   gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
     119           0 :   gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
     120             : #endif
     121             : 
     122           0 :   if (argc)
     123             :     {
     124           0 :       argc--;
     125           0 :       argv++;
     126             :     }
     127           0 :   command = argc? *argv : "NOP";
     128             : 
     129             : 
     130           0 :   err = gpgme_new (&ctx);
     131           0 :   fail_if_err (err);
     132             : 
     133           0 :   err = gpgme_set_protocol (ctx, GPGME_PROTOCOL_ASSUAN);
     134           0 :   fail_if_err (err);
     135             : 
     136           0 :   err = gpgme_op_assuan_transact_ext (ctx, command, data_cb, NULL,
     137             :                                   inq_cb, NULL, status_cb, NULL, &op_err);
     138           0 :   fail_if_err (err || op_err);
     139             : 
     140           0 :   gpgme_release (ctx);
     141             : 
     142           0 :   return 0;
     143             : }
     144             : 

Generated by: LCOV version 1.13