LCOV - code coverage report
Current view: top level - tests/gpgscm - t-child.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 23 26 88.5 %
Date: 2016-11-29 15:00:56 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* Sanity check for the process and IPC primitives.
       2             :  *
       3             :  * Copyright (C) 2016 g10 code GmbH
       4             :  *
       5             :  * This file is part of GnuPG.
       6             :  *
       7             :  * GnuPG is free software; you can redistribute it and/or modify
       8             :  * it under the terms of the GNU General Public License as published by
       9             :  * the Free Software Foundation; either version 3 of the License, or
      10             :  * (at your option) any later version.
      11             :  *
      12             :  * GnuPG is distributed in the hope that it will be useful,
      13             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :  * GNU General Public License for more details.
      16             :  *
      17             :  * You should have received a copy of the GNU General Public License
      18             :  * along with this program; if not, see <https://www.gnu.org/licenses/>.
      19             :  */
      20             : 
      21             : #include <errno.h>
      22             : #include <stdio.h>
      23             : #include <string.h>
      24             : 
      25             : #ifdef _WIN32
      26             : # include <fcntl.h>
      27             : # include <io.h>
      28             : #endif
      29             : 
      30             : int
      31          24 : main (int argc, char **argv)
      32             : {
      33             :   char buffer[4096];
      34          24 :   memset (buffer, 'A', sizeof buffer);
      35             : #if _WIN32
      36             :   if (! setmode (stdin, O_BINARY))
      37             :     return 23;
      38             :   if (! setmode (stdout, O_BINARY))
      39             :     return 23;
      40             : #endif
      41             : 
      42          24 :   if (argc == 1)
      43           0 :     return 2;
      44          24 :   else if (strcmp (argv[1], "return0") == 0)
      45           6 :     return 0;
      46          18 :   else if (strcmp (argv[1], "return1") == 0)
      47           4 :     return 1;
      48          14 :   else if (strcmp (argv[1], "return77") == 0)
      49           3 :     return 77;
      50          11 :   else if (strcmp (argv[1], "hello_stdout") == 0)
      51           2 :     fprintf (stdout, "hello");
      52           9 :   else if (strcmp (argv[1], "hello_stderr") == 0)
      53           1 :     fprintf (stderr, "hello");
      54           8 :   else if (strcmp (argv[1], "stdout4096") == 0)
      55           2 :     fwrite (buffer, 1, sizeof buffer, stdout);
      56           6 :   else if (strcmp (argv[1], "stdout8192") == 0)
      57             :     {
      58           2 :       fwrite (buffer, 1, sizeof buffer, stdout);
      59           2 :       fwrite (buffer, 1, sizeof buffer, stdout);
      60             :     }
      61           4 :   else if (strcmp (argv[1], "cat") == 0)
      62          15 :     while (! feof (stdin))
      63             :       {
      64             :         size_t bytes_read;
      65           7 :         bytes_read = fread (buffer, 1, sizeof buffer, stdin);
      66           7 :         fwrite (buffer, 1, bytes_read, stdout);
      67             :       }
      68             :   else
      69             :     {
      70           0 :       fprintf (stderr, "unknown command %s\n", argv[1]);
      71           0 :       return 2;
      72             :     }
      73          11 :   return 0;
      74             : }

Generated by: LCOV version 1.11