LCOV - code coverage report
Current view: top level - tests - t-common.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 3 36 8.3 %
Date: 2016-12-01 18:32:04 Functions: 1 3 33.3 %

          Line data    Source code
       1             : /* t-common.h - Common code for the tests.
       2             :  * Copyright (C) 2013 g10 Code GmbH
       3             :  *
       4             :  * This file is part of libgpg-error.
       5             :  *
       6             :  * libgpg-error is free software; you can redistribute it and/or
       7             :  * modify it under the terms of the GNU Lesser General Public License
       8             :  * as published by the Free Software Foundation; either version 2.1 of
       9             :  * the License, or (at your option) any later version.
      10             :  *
      11             :  * libgpg-error 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 <http://www.gnu.org/licenses/>.
      18             :  */
      19             : 
      20             : #include <stdarg.h>
      21             : 
      22             : #include "../src/gcrypt.h"
      23             : 
      24             : #ifndef PGMNAME
      25             : # error Macro PGMNAME not defined.
      26             : #endif
      27             : #ifndef _GCRYPT_CONFIG_H_INCLUDED
      28             : # error config.h not included
      29             : #endif
      30             : 
      31             : /* A couple of useful macros.  */
      32             : #ifndef DIM
      33             : # define DIM(v)              (sizeof(v)/sizeof((v)[0]))
      34             : #endif
      35             : #define my_isascii(c) (!((c) & 0x80))
      36             : #define digitp(p)     (*(p) >= '0' && *(p) <= '9')
      37             : #define hexdigitp(a)  (digitp (a)                     \
      38             :                        || (*(a) >= 'A' && *(a) <= 'F')  \
      39             :                        || (*(a) >= 'a' && *(a) <= 'f'))
      40             : #define xtoi_1(p)     (*(p) <= '9'? (*(p)- '0'): \
      41             :                        *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10))
      42             : #define xtoi_2(p)     ((xtoi_1(p) * 16) + xtoi_1((p)+1))
      43             : #define xmalloc(a)    gcry_xmalloc ((a))
      44             : #define xcalloc(a,b)  gcry_xcalloc ((a),(b))
      45             : #define xstrdup(a)    gcry_xstrdup ((a))
      46             : #define xfree(a)      gcry_free ((a))
      47             : #define pass()        do { ; } while (0)
      48             : 
      49             : 
      50             : /* Standard global variables.  */
      51             : static int verbose;
      52             : static int debug;
      53             : static int errorcount;
      54             : 
      55             : /* If we have a decent libgpg-error we can use some gcc attributes.  */
      56             : #ifdef GPGRT_ATTR_NORETURN
      57             : static void die (const char *format, ...) GPGRT_ATTR_NR_PRINTF(1,2);
      58             : static void fail (const char *format, ...) GPGRT_ATTR_PRINTF(1,2);
      59             : static void info (const char *format, ...) GPGRT_ATTR_PRINTF(1,2);
      60             : #endif /*GPGRT_ATTR_NORETURN*/
      61             : 
      62             : 
      63             : /* Reporting functions.  */
      64             : static void
      65           0 : die (const char *format, ...)
      66             : {
      67             :   va_list arg_ptr ;
      68             : 
      69           0 :   fflush (stdout);
      70             : #ifdef HAVE_FLOCKFILE
      71           0 :   flockfile (stderr);
      72             : #endif
      73           0 :   fprintf (stderr, "%s: ", PGMNAME);
      74           0 :   va_start (arg_ptr, format) ;
      75           0 :   vfprintf (stderr, format, arg_ptr);
      76           0 :   va_end (arg_ptr);
      77           0 :   if (*format && format[strlen(format)-1] != '\n')
      78           0 :     putc ('\n', stderr);
      79             : #ifdef HAVE_FLOCKFILE
      80           0 :   funlockfile (stderr);
      81             : #endif
      82           0 :   exit (1);
      83             : }
      84             : 
      85             : 
      86             : static void
      87           0 : fail (const char *format, ...)
      88             : {
      89             :   va_list arg_ptr;
      90             : 
      91           0 :   fflush (stdout);
      92             : #ifdef HAVE_FLOCKFILE
      93           0 :   flockfile (stderr);
      94             : #endif
      95           0 :   fprintf (stderr, "%s: ", PGMNAME);
      96           0 :   va_start (arg_ptr, format);
      97           0 :   vfprintf (stderr, format, arg_ptr);
      98           0 :   va_end (arg_ptr);
      99           0 :   if (*format && format[strlen(format)-1] != '\n')
     100           0 :     putc ('\n', stderr);
     101             : #ifdef HAVE_FLOCKFILE
     102           0 :   funlockfile (stderr);
     103             : #endif
     104           0 :   errorcount++;
     105           0 :   if (errorcount >= 50)
     106           0 :     die ("stopped after 50 errors.");
     107           0 : }
     108             : 
     109             : 
     110             : static void
     111          99 : info (const char *format, ...)
     112             : {
     113             :   va_list arg_ptr;
     114             : 
     115          99 :   if (!verbose)
     116         198 :     return;
     117             : #ifdef HAVE_FLOCKFILE
     118           0 :   flockfile (stderr);
     119             : #endif
     120           0 :   fprintf (stderr, "%s: ", PGMNAME);
     121           0 :   va_start (arg_ptr, format);
     122           0 :   vfprintf (stderr, format, arg_ptr);
     123           0 :   if (*format && format[strlen(format)-1] != '\n')
     124           0 :     putc ('\n', stderr);
     125           0 :   va_end (arg_ptr);
     126             : #ifdef HAVE_FLOCKFILE
     127           0 :   funlockfile (stderr);
     128             : #endif
     129             : }

Generated by: LCOV version 1.11