]> git.meshlink.io Git - catta/blob - tests/strlst-test.c
Fix compilation error caused by ACX_THREAD
[catta] / tests / strlst-test.c
1 /***
2   This file is part of catta.
3
4   catta is free software; you can redistribute it and/or modify it
5   under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2.1 of the
7   License, or (at your option) any later version.
8
9   catta is distributed in the hope that it will be useful, but WITHOUT
10   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11   or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
12   Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with catta; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17   USA.
18 ***/
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include <stdio.h>
25 #include <assert.h>
26
27 #include <catta/strlst.h>
28 #include <catta/malloc.h>
29
30 int main(CATTA_GCC_UNUSED int argc, CATTA_GCC_UNUSED char *argv[]) {
31     char *t, *v;
32     uint8_t data[1024];
33     CattaStringList *a = NULL, *b, *p;
34     size_t size, n;
35     int r;
36
37     a = catta_string_list_new("prefix", "a", "b", NULL);
38
39     a = catta_string_list_add(a, "start");
40     a = catta_string_list_add(a, "foo=99");
41     a = catta_string_list_add(a, "bar");
42     a = catta_string_list_add(a, "");
43     a = catta_string_list_add(a, "");
44     a = catta_string_list_add(a, "quux");
45     a = catta_string_list_add(a, "");
46     a = catta_string_list_add_arbitrary(a, (const uint8_t*) "null\0null", 9);
47     a = catta_string_list_add_printf(a, "seven=%i %c", 7, 'x');
48     a = catta_string_list_add_pair(a, "blubb", "blaa");
49     a = catta_string_list_add_pair(a, "uxknurz", NULL);
50     a = catta_string_list_add_pair_arbitrary(a, "uxknurz2", (const uint8_t*) "blafasel\0oerks", 14);
51
52     a = catta_string_list_add(a, "end");
53
54     t = catta_string_list_to_string(a);
55     printf("--%s--\n", t);
56     catta_free(t);
57
58     n = catta_string_list_serialize(a, NULL, 0);
59     size = catta_string_list_serialize(a, data, sizeof(data));
60     assert(size == n);
61
62     printf("%lu\n", (unsigned long)size);
63
64     for (t = (char*) data, n = 0; n < size; n++, t++) {
65         if (*t <= 32)
66             printf("(%u)", *t);
67         else
68             printf("%c", *t);
69     }
70
71     printf("\n");
72
73     assert(catta_string_list_parse(data, size, &b) == 0);
74
75     printf("equal: %i\n", catta_string_list_equal(a, b));
76
77     t = catta_string_list_to_string(b);
78     printf("--%s--\n", t);
79     catta_free(t);
80
81     catta_string_list_free(b);
82
83     b = catta_string_list_copy(a);
84
85     assert(catta_string_list_equal(a, b));
86
87     t = catta_string_list_to_string(b);
88     printf("--%s--\n", t);
89     catta_free(t);
90
91     p = catta_string_list_find(a, "seven");
92     assert(p);
93
94     r = catta_string_list_get_pair(p, &t, &v, NULL);
95     assert(r >= 0);
96     assert(t);
97     assert(v);
98
99     printf("<%s>=<%s>\n", t, v);
100     catta_free(t);
101     catta_free(v);
102
103     p = catta_string_list_find(a, "quux");
104     assert(p);
105
106     r = catta_string_list_get_pair(p, &t, &v, NULL);
107     assert(r >= 0);
108     assert(t);
109     assert(!v);
110
111     printf("<%s>=<%s>\n", t, v);
112     catta_free(t);
113     catta_free(v);
114
115     catta_string_list_free(a);
116     catta_string_list_free(b);
117
118     n = catta_string_list_serialize(NULL, NULL, 0);
119     size = catta_string_list_serialize(NULL, data, sizeof(data));
120     assert(size == 1);
121     assert(size == n);
122
123     assert(catta_string_list_parse(data, size, &a) == 0);
124     assert(!a);
125
126     return 0;
127 }