LCOV - code coverage report
Current view: top level - common - t-ccparray.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 26 30 86.7 %
Date: 2016-11-29 15:00:56 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /* t-ccparray.c - Module test for ccparray.c
       2             :  * Copyright (C) 2016 g10 Code GmbH
       3             :  *
       4             :  * This file is part of GnuPG.
       5             :  *
       6             :  * GnuPG is free software; you can redistribute it and/or modify
       7             :  * it under the terms of the GNU General Public License as published by
       8             :  * the Free Software Foundation; either version 3 of the License, or
       9             :  * (at your option) any later version.
      10             :  *
      11             :  * GnuPG is distributed in the hope that it will be useful,
      12             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  * GNU General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU General Public License
      17             :  * along with this program; if not, see <https://www.gnu.org/licenses/>.
      18             :  */
      19             : 
      20             : #include <config.h>
      21             : #include <stdio.h>
      22             : #include <stdlib.h>
      23             : #include <string.h>
      24             : 
      25             : #include "util.h"
      26             : #include "ccparray.h"
      27             : 
      28             : #define pass()  do { ; } while(0)
      29             : #define fail(a)  do { fprintf (stderr, "%s:%d: test %d failed\n",\
      30             :                                __FILE__,__LINE__, (a));          \
      31             :                        exit (1);                                 \
      32             :                     } while(0)
      33             : 
      34             : 
      35             : static void
      36           1 : run_test_1 (void)
      37             : {
      38             :   ccparray_t ccp;
      39             :   const char **argv;
      40             :   size_t nelem;
      41             : 
      42           1 :   ccparray_init (&ccp, 0);
      43           1 :   ccparray_put (&ccp, "First arg");
      44           1 :   ccparray_put (&ccp, "Second arg");
      45           1 :   ccparray_put (&ccp, NULL);
      46           1 :   ccparray_put (&ccp, "Fourth arg");
      47           1 :   argv = ccparray_get (&ccp, &nelem);
      48           1 :   if (!argv)
      49             :     {
      50           0 :       fprintf (stderr, "error building array: %s\n", strerror (errno));
      51           0 :       exit (1);
      52             :     }
      53             : 
      54           1 :   if (nelem != 4)
      55           0 :     fail (1);
      56             : 
      57             :   /* for (i=0; argv[i]; i++) */
      58             :   /*   printf ("[%d] = '%s'\n", i, argv[i]); */
      59           1 :   xfree (argv);
      60           1 : }
      61             : 
      62             : 
      63             : static void
      64           5 : run_test_var (int count)
      65             : {
      66             :   ccparray_t ccp;
      67             :   size_t nelem;
      68             :   int i;
      69             : 
      70           5 :   ccparray_init (&ccp, 0);
      71        4125 :   for (i=0; i < count; i++)
      72        4120 :     ccparray_put (&ccp, "An arg");
      73           5 :   xfree (ccparray_get (&ccp, &nelem));
      74           5 :   if (nelem != i)
      75           0 :     fail (2);
      76           5 : }
      77             : 
      78             : 
      79             : int
      80           1 : main (int argc, char **argv)
      81             : {
      82             :   (void)argc;
      83             :   (void)argv;
      84             : 
      85           1 :   run_test_1 ();
      86           1 :   run_test_var (0);
      87           1 :   run_test_var (7);
      88           1 :   run_test_var (8);
      89           1 :   run_test_var (9);
      90           1 :   run_test_var (4096);
      91             : 
      92           1 :   return 0;
      93             : }

Generated by: LCOV version 1.11