chiark / gitweb /
gnupg2 (2.1.17-3) unstable; urgency=medium
[gnupg2.git] / common / t-strlist.c
1 /* t-strlist.c - Regression tests for strist.c
2  * Copyright (C) 2015  g10 Code GmbH
3  *
4  * This file is part of GnuPG.
5  *
6  * GnuPG is free software; you can redistribute it and/or modify it
7  * under the terms of either
8  *
9  *   - the GNU Lesser General Public License as published by the Free
10  *     Software Foundation; either version 3 of the License, or (at
11  *     your option) any later version.
12  *
13  * or
14  *
15  *   - the GNU General Public License as published by the Free
16  *     Software Foundation; either version 2 of the License, or (at
17  *     your option) any later version.
18  *
19  * or both in parallel, as here.
20  *
21  * GnuPG is distributed in the hope that it will be useful, but
22  * WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24  * General Public License for more details.
25  *
26  * You should have received a copies of the GNU General Public License
27  * and the GNU Lesser General Public License along with this program;
28  * if not, see <https://www.gnu.org/licenses/>.
29  */
30
31 #include <config.h>
32 #include <string.h>
33
34 #include "strlist.h"
35
36 #include "t-support.h"
37
38 static void
39 test_strlist_rev (void)
40 {
41   strlist_t s = NULL;
42
43   /* Reversing an empty list should yield the empty list.  */
44   if (! (strlist_rev (&s) == NULL))
45     fail (1);
46
47   add_to_strlist (&s, "1");
48   add_to_strlist (&s, "2");
49   add_to_strlist (&s, "3");
50
51   if (strcmp (s->d, "3") != 0)
52     fail (2);
53   if (strcmp (s->next->d, "2") != 0)
54     fail (2);
55   if (strcmp (s->next->next->d, "1") != 0)
56     fail (2);
57   if (s->next->next->next)
58     fail (2);
59
60   strlist_rev (&s);
61
62   if (strcmp (s->d, "1") != 0)
63     fail (2);
64   if (strcmp (s->next->d, "2") != 0)
65     fail (2);
66   if (strcmp (s->next->next->d, "3") != 0)
67     fail (2);
68   if (s->next->next->next)
69     fail (2);
70
71   free_strlist (s);
72 }
73
74
75 int
76 main (int argc, char **argv)
77 {
78   (void)argc;
79   (void)argv;
80
81   test_strlist_rev ();
82
83   return 0;
84 }