Apache HTTPD
testtable.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "testutil.h"
18#include "apr.h"
19#include "apr_strings.h"
20#include "apr_general.h"
21#include "apr_pools.h"
22#include "apr_tables.h"
23#if APR_HAVE_STDIO_H
24#include <stdio.h>
25#endif
26#if APR_HAVE_STDLIB_H
27#include <stdlib.h>
28#endif
29#if APR_HAVE_STRING_H
30#include <string.h>
31#endif
32
35
36static void array_clear(abts_case *tc, void *data)
37{
38 a1 = apr_array_make(p, 2, sizeof(const char *));
39 APR_ARRAY_PUSH(a1, const char *) = "foo";
40 APR_ARRAY_PUSH(a1, const char *) = "bar";
42 ABTS_INT_EQUAL(tc, 0, a1->nelts);
43}
44
45static void table_make(abts_case *tc, void *data)
46{
47 t1 = apr_table_make(p, 5);
49}
50
51static void table_get(abts_case *tc, void *data)
52{
53 const char *val;
54
55 apr_table_set(t1, "foo", "bar");
56 val = apr_table_get(t1, "foo");
57 ABTS_STR_EQUAL(tc, "bar", val);
58}
59
60static void table_getm(abts_case *tc, void *data)
61{
62 const char *orig, *val;
64
66
67 orig = "bar";
68 apr_table_setn(t1, "foo", orig);
69 val = apr_table_getm(subp, t1, "foo");
71 ABTS_STR_EQUAL(tc, "bar", val);
72 apr_table_add(t1, "foo", "baz");
73 val = apr_table_getm(subp, t1, "foo");
74 ABTS_STR_EQUAL(tc, "bar,baz", val);
75
77}
78
79static void table_set(abts_case *tc, void *data)
80{
81 const char *val;
82
83 apr_table_set(t1, "setkey", "bar");
84 apr_table_set(t1, "setkey", "2ndtry");
85 val = apr_table_get(t1, "setkey");
86 ABTS_STR_EQUAL(tc, "2ndtry", val);
87}
88
89static void table_getnotthere(abts_case *tc, void *data)
90{
91 const char *val;
92
93 val = apr_table_get(t1, "keynotthere");
94 ABTS_PTR_EQUAL(tc, NULL, (void *)val);
95}
96
97static void table_add(abts_case *tc, void *data)
98{
99 const char *val;
100
101 apr_table_add(t1, "addkey", "bar");
102 apr_table_add(t1, "addkey", "foo");
103 val = apr_table_get(t1, "addkey");
104 ABTS_STR_EQUAL(tc, "bar", val);
105
106}
107
108static void table_nelts(abts_case *tc, void *data)
109{
110 const char *val;
112
113 apr_table_set(t, "abc", "def");
114 apr_table_set(t, "def", "abc");
115 apr_table_set(t, "foo", "zzz");
116 val = apr_table_get(t, "foo");
117 ABTS_STR_EQUAL(tc, "zzz", val);
118 val = apr_table_get(t, "abc");
119 ABTS_STR_EQUAL(tc, "def", val);
120 val = apr_table_get(t, "def");
121 ABTS_STR_EQUAL(tc, "abc", val);
123}
124
125static void table_clear(abts_case *tc, void *data)
126{
129}
130
131static void table_unset(abts_case *tc, void *data)
132{
133 const char *val;
135
136 apr_table_set(t, "a", "1");
137 apr_table_set(t, "b", "2");
138 apr_table_unset(t, "b");
140 val = apr_table_get(t, "a");
141 ABTS_STR_EQUAL(tc, "1", val);
142 val = apr_table_get(t, "b");
143 ABTS_PTR_EQUAL(tc, (void *)NULL, (void *)val);
144}
145
146static void table_overlap(abts_case *tc, void *data)
147{
148 const char *val;
151
152 apr_table_addn(t1, "a", "0");
153 apr_table_addn(t1, "g", "7");
154 apr_table_addn(t2, "a", "1");
155 apr_table_addn(t2, "b", "2");
156 apr_table_addn(t2, "c", "3");
157 apr_table_addn(t2, "b", "2.0");
158 apr_table_addn(t2, "d", "4");
159 apr_table_addn(t2, "e", "5");
160 apr_table_addn(t2, "b", "2.");
161 apr_table_addn(t2, "f", "6");
163
165 val = apr_table_get(t1, "a");
166 ABTS_STR_EQUAL(tc, "1", val);
167 val = apr_table_get(t1, "b");
168 ABTS_STR_EQUAL(tc, "2.", val);
169 val = apr_table_get(t1, "c");
170 ABTS_STR_EQUAL(tc, "3", val);
171 val = apr_table_get(t1, "d");
172 ABTS_STR_EQUAL(tc, "4", val);
173 val = apr_table_get(t1, "e");
174 ABTS_STR_EQUAL(tc, "5", val);
175 val = apr_table_get(t1, "f");
176 ABTS_STR_EQUAL(tc, "6", val);
177 val = apr_table_get(t1, "g");
178 ABTS_STR_EQUAL(tc, "7", val);
179}
180
181static void table_overlap2(abts_case *tc, void *data)
182{
184 apr_table_t *t1, *t2;
185
187
188 t1 = apr_table_make(subp, 1);
189 t2 = apr_table_make(p, 1);
190 apr_table_addn(t1, "t1", "one");
191 apr_table_addn(t2, "t2", "two");
192
194
196
197 ABTS_STR_EQUAL(tc, "one", apr_table_get(t1, "t1"));
198 ABTS_STR_EQUAL(tc, "two", apr_table_get(t1, "t2"));
199
200}
201
202static void table_overlap3(abts_case *tc, void *data)
203{
205 apr_table_t *t1, *t2;
206
208
209 t1 = apr_table_make(subp, 1);
210 t2 = apr_table_make(p, 1);
211 apr_table_addn(t1, "t1", "one");
212 apr_table_addn(t1, "t1", "overlay");
213 apr_table_addn(t2, "t2", "two");
214 apr_table_addn(t2, "t2", "overlay");
215
217
219
220 ABTS_STR_EQUAL(tc, "one", apr_table_get(t1, "t1"));
221 ABTS_STR_EQUAL(tc, "two", apr_table_get(t1, "t2"));
222
223}
224
226{
227 suite = ADD_SUITE(suite)
228
242
243 return suite;
244}
245
void abts_run_test(abts_suite *ts, test_func f, void *value)
Definition abts.c:175
#define ABTS_PTR_EQUAL(a, b, c)
Definition abts.h:126
#define ADD_SUITE(suite)
Definition abts.h:67
#define ABTS_PTR_NOTNULL(a, b)
Definition abts.h:125
#define ABTS_STR_EQUAL(a, b, c)
Definition abts.h:123
#define ABTS_INT_EQUAL(a, b, c)
Definition abts.h:109
APR Miscellaneous library routines.
APR memory allocation.
APR Strings library.
APR Table library.
apr_size_t size
apr_uint32_t val
Definition apr_atomic.h:66
void * data
apr_interval_time_t t
#define apr_pool_create(newpool, parent)
Definition apr_pools.h:322
#define APR_ARRAY_PUSH(ary, type)
Definition apr_tables.h:150
int nelts
Definition apr_tables.h:122
#define APR_OVERLAP_TABLES_SET
Definition apr_tables.h:437
#define APR_OVERLAP_TABLES_ADD
Definition apr_tables.h:441
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
static void table_overlap2(abts_case *tc, void *data)
Definition testtable.c:181
static void table_overlap3(abts_case *tc, void *data)
Definition testtable.c:202
static void table_make(abts_case *tc, void *data)
Definition testtable.c:45
static apr_array_header_t * a1
Definition testtable.c:33
static void table_add(abts_case *tc, void *data)
Definition testtable.c:97
static void table_nelts(abts_case *tc, void *data)
Definition testtable.c:108
static void table_getnotthere(abts_case *tc, void *data)
Definition testtable.c:89
static void table_unset(abts_case *tc, void *data)
Definition testtable.c:131
static void table_clear(abts_case *tc, void *data)
Definition testtable.c:125
static void table_set(abts_case *tc, void *data)
Definition testtable.c:79
static void array_clear(abts_case *tc, void *data)
Definition testtable.c:36
static void table_overlap(abts_case *tc, void *data)
Definition testtable.c:146
static apr_table_t * t1
Definition testtable.c:34
static void table_get(abts_case *tc, void *data)
Definition testtable.c:51
static void table_getm(abts_case *tc, void *data)
Definition testtable.c:60
abts_suite * testtable(abts_suite *suite)
Definition testtable.c:225