LCOV - code coverage report
Current view: top level - tests - t-syserror.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 12 24 50.0 %
Date: 2015-11-05 17:04:23 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* t-syserror.c - System error specific regression test.
       2             :    Copyright (C) 2006 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 libgpgme-error; if not, write to the Free
      18             :    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
      19             :    02110-1301, USA.  */
      20             : 
      21             : 
      22             : #if HAVE_CONFIG_H
      23             : #include <config.h>
      24             : #endif
      25             : 
      26             : #include <stdio.h>
      27             : #if HAVE_STDLIB_H
      28             : #include <stdlib.h>
      29             : #endif
      30             : #include <errno.h>
      31             : 
      32             : #include <gpg-error.h>
      33             : 
      34             : int
      35           1 : main (int argc, char *argv[])
      36             : {
      37             :   FILE *fp;
      38             :   int save_errno;
      39             :   gpg_err_code_t ec;
      40             : 
      41             :   (void)argc;
      42             :   (void)argv;
      43             : 
      44           1 :   fp = fopen ("/does-not-exist/110761/nowhere.foo", "r");
      45           1 :   if (fp)
      46             :     {
      47           0 :       fclose (fp);
      48           0 :       fp = fopen ("  no this file does not exists foo 4711", "r");
      49             :     }
      50           1 :   if (fp)
      51             :     {
      52           0 :       fprintf (stderr, "unable to run test\n");
      53           0 :       return 1;
      54             :     }
      55           1 :   save_errno = errno;
      56             : 
      57           1 :   ec = gpg_err_code_from_syserror ();
      58           1 :   if (ec != GPG_ERR_ENOENT)
      59             :     {
      60           0 :       fprintf (stderr, "fopen failed with bad code: %d\n", save_errno);
      61           0 :       return 1;
      62             :     }
      63             : 
      64           1 :   if (ec != gpg_err_code_from_errno (save_errno))
      65             :     {
      66           0 :       fprintf (stderr, "oops at %d\n",__LINE__);
      67           0 :       return 1;
      68             :     }
      69             : 
      70           1 :   gpg_err_set_errno (0);
      71             : 
      72           1 :   ec = gpg_err_code_from_syserror ();
      73           1 :   if (ec != GPG_ERR_MISSING_ERRNO)
      74             :     {
      75           0 :       fprintf (stderr, "oops at %d\n",__LINE__);
      76           0 :       return 1;
      77             :     }
      78             : 
      79           1 :   if ( gpg_err_code_from_errno (0) )
      80             :     {
      81           0 :       fprintf (stderr, "oops at %d\n",__LINE__);
      82           0 :       return 1;
      83             :     }
      84             : 
      85             : 
      86             :   return 0;
      87             : }

Generated by: LCOV version 1.11