LCOV - code coverage report
Current view: top level - tests - t-version.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 10 28 35.7 %
Date: 2017-03-02 16:37:58 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* t-version.c - Check the version info function
       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 <https://www.gnu.org/licenses/>.
      18             :  */
      19             : 
      20             : #ifdef HAVE_CONFIG_H
      21             : #include <config.h>
      22             : #endif
      23             : 
      24             : #include <stdio.h>
      25             : #include <stdlib.h>
      26             : #include <string.h>
      27             : #include <assert.h>
      28             : 
      29             : #include "../src/gpg-error.h"
      30             : 
      31             : static const char *logpfx = "";
      32             : static int verbose;
      33             : static int debug;
      34             : static int errorcount;
      35             : 
      36             : int
      37           1 : main (int argc, char **argv)
      38             : {
      39             :   int last_argc = -1;
      40             : 
      41           1 :   if (argc)
      42             :     {
      43           1 :       logpfx = *argv;
      44           1 :       argc--; argv++;
      45             :     }
      46           1 :   while (argc && last_argc != argc )
      47             :     {
      48             :       last_argc = argc;
      49           0 :       if (!strcmp (*argv, "--help"))
      50             :         {
      51           0 :           puts (
      52             : "usage: ./version [options]\n"
      53             : "\n"
      54             : "Options:\n"
      55             : "  --verbose      Show what is going on\n"
      56             : );
      57           0 :           exit (0);
      58             :         }
      59           0 :       if (!strcmp (*argv, "--verbose"))
      60             :         {
      61           0 :           verbose = 1;
      62           0 :           argc--; argv++;
      63             :         }
      64           0 :       else if (!strcmp (*argv, "--debug"))
      65             :         {
      66           0 :           verbose = debug = 1;
      67           0 :           argc--; argv++;
      68             :         }
      69             :     }
      70             : 
      71           1 :   if (!gpg_error_check_version (GPG_ERROR_VERSION))
      72             :     {
      73           0 :       fprintf (stderr, "%s: gpg_error_check_version returned an error\n",
      74             :                logpfx);
      75           0 :       errorcount++;
      76             :     }
      77           1 :   if (!gpg_error_check_version ("1.10"))
      78             :     {
      79           0 :       fprintf (stderr, "%s: gpg_error_check_version returned an "
      80             :                "error for an old version\n", logpfx);
      81           0 :       errorcount++;
      82             :     }
      83           1 :   if (gpg_error_check_version ("15"))
      84             :     {
      85           0 :       fprintf (stderr, "%s: gpg_error_check_version did not return an error"
      86             :                " for a newer version\n", logpfx);
      87           0 :       errorcount++;
      88             :     }
      89           1 :   if (verbose || errorcount)
      90             :     {
      91           0 :       printf ("Version from header: %s (0x%06x)\n",
      92             :                GPG_ERROR_VERSION, GPG_ERROR_VERSION_NUMBER);
      93           0 :       printf ("Version from binary: %s\n", gpg_error_check_version (NULL));
      94           0 :       printf ("Copyright blurb ...:%s\n", gpg_error_check_version ("\x01\x01"));
      95             :     }
      96             : 
      97           1 :   return errorcount ? 1 : 0;
      98             : }

Generated by: LCOV version 1.13