LCOV - code coverage report
Current view: top level - tests/gpgsm - t-support.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 24 37 64.9 %
Date: 2016-09-12 13:07:23 Functions: 3 4 75.0 %

          Line data    Source code
       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
       4             : 
       5             :    This file is part of GPGME.
       6             :  
       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.
      11             :    
      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.
      16             :    
      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
      20             :    02111-1307, USA.  */
      21             : 
      22             : #include <unistd.h>
      23             : #include <errno.h>
      24             : #include <stdlib.h>
      25             : #include <locale.h>
      26             : 
      27             : #include <gpgme.h>
      28             : 
      29             : #define fail_if_err(err)                                        \
      30             :   do                                                            \
      31             :     {                                                           \
      32             :       if (err)                                                  \
      33             :         {                                                       \
      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)); \
      38             :           exit (1);                                             \
      39             :         }                                                       \
      40             :     }                                                           \
      41             :   while (0)
      42             : 
      43             : 
      44             : void
      45           8 : print_data (gpgme_data_t dh)
      46             : {
      47             : #define BUF_SIZE 512
      48             :   char buf[BUF_SIZE + 1];
      49             :   int ret;
      50             :   
      51           8 :   ret = gpgme_data_seek (dh, 0, SEEK_SET);
      52           8 :   if (ret)
      53           0 :     fail_if_err (gpgme_error_from_errno (errno));
      54          38 :   while ((ret = gpgme_data_read (dh, buf, BUF_SIZE)) > 0)
      55          22 :     fwrite (buf, ret, 1, stdout);
      56           8 :   if (ret < 0)
      57           0 :     fail_if_err (gpgme_error_from_errno (errno));
      58           8 : }
      59             : 
      60             : 
      61             : gpgme_error_t
      62           0 : passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
      63             :                int last_was_bad, int fd)
      64             : {
      65             :   int res;
      66           0 :   char *pass = "abc\n";
      67           0 :   int passlen = strlen (pass);
      68           0 :   int off = 0;
      69             : 
      70             :   do
      71             :     {
      72           0 :       res = write (fd, &pass[off], passlen - off);
      73           0 :       if (res > 0)
      74           0 :         off += res;
      75             :     }
      76           0 :   while (res > 0 && off != passlen);
      77             : 
      78           0 :   return off == passlen ? 0 : gpgme_error_from_errno (errno);
      79             : }
      80             : 
      81             : 
      82             : char *
      83           2 : make_filename (const char *fname)
      84             : {
      85           2 :   const char *srcdir = getenv ("srcdir");
      86             :   char *buf;
      87             : 
      88           2 :   if (!srcdir)
      89           0 :     srcdir = ".";
      90           2 :   buf = malloc (strlen(srcdir) + strlen(fname) + 2);
      91           2 :   if (!buf) 
      92           0 :     exit (8);
      93           2 :   strcpy (buf, srcdir);
      94           2 :   strcat (buf, "/");
      95           2 :   strcat (buf, fname);
      96           2 :   return buf;
      97             : }
      98             : 
      99             : 
     100             : void
     101           7 : init_gpgme (gpgme_protocol_t proto)
     102             : {
     103             :   gpgme_error_t err;
     104             : 
     105           7 :   gpgme_check_version (NULL);
     106             : #ifndef HAVE_W32_SYSTEM
     107           7 :   setlocale (LC_ALL, "");
     108           7 :   gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
     109           7 :   gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
     110             : #endif
     111             : 
     112           7 :   err = gpgme_engine_check_version (proto);
     113           7 :   fail_if_err (err);
     114           7 : }

Generated by: LCOV version 1.11