chiark / gitweb /
gpg agent lockup fix: Interrupt main loop when active_connections_value==0
[gnupg2.git] / common / t-ccparray.c
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 run_test_1 (void)
37 {
38   ccparray_t ccp;
39   const char **argv;
40   size_t nelem;
41
42   ccparray_init (&ccp, 0);
43   ccparray_put (&ccp, "First arg");
44   ccparray_put (&ccp, "Second arg");
45   ccparray_put (&ccp, NULL);
46   ccparray_put (&ccp, "Fourth arg");
47   argv = ccparray_get (&ccp, &nelem);
48   if (!argv)
49     {
50       fprintf (stderr, "error building array: %s\n", strerror (errno));
51       exit (1);
52     }
53
54   if (nelem != 4)
55     fail (1);
56
57   /* for (i=0; argv[i]; i++) */
58   /*   printf ("[%d] = '%s'\n", i, argv[i]); */
59   xfree (argv);
60 }
61
62
63 static void
64 run_test_var (int count)
65 {
66   ccparray_t ccp;
67   size_t nelem;
68   int i;
69
70   ccparray_init (&ccp, 0);
71   for (i=0; i < count; i++)
72     ccparray_put (&ccp, "An arg");
73   xfree (ccparray_get (&ccp, &nelem));
74   if (nelem != i)
75     fail (2);
76 }
77
78
79 int
80 main (int argc, char **argv)
81 {
82   (void)argc;
83   (void)argv;
84
85   run_test_1 ();
86   run_test_var (0);
87   run_test_var (7);
88   run_test_var (8);
89   run_test_var (9);
90   run_test_var (4096);
91
92   return 0;
93 }