1
/* Copyright 2002-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
19
#include "apr_strings.h"
20
#include "apr_general.h"
21
#include "apr_pools.h"
22
#include "apr_tables.h"
33
static apr_table_t *t1 = NULL;
35
static void table_make(abts_case *tc, void *data)
37
t1 = apr_table_make(p, 5);
38
ABTS_PTR_NOTNULL(tc, t1);
41
static void table_get(abts_case *tc, void *data)
45
apr_table_set(t1, "foo", "bar");
46
val = apr_table_get(t1, "foo");
47
ABTS_STR_EQUAL(tc, val, "bar");
50
static void table_set(abts_case *tc, void *data)
54
apr_table_set(t1, "setkey", "bar");
55
apr_table_set(t1, "setkey", "2ndtry");
56
val = apr_table_get(t1, "setkey");
57
ABTS_STR_EQUAL(tc, val, "2ndtry");
60
static void table_getnotthere(abts_case *tc, void *data)
64
val = apr_table_get(t1, "keynotthere");
65
ABTS_PTR_EQUAL(tc, NULL, (void *)val);
68
static void table_add(abts_case *tc, void *data)
72
apr_table_add(t1, "addkey", "bar");
73
apr_table_add(t1, "addkey", "foo");
74
val = apr_table_get(t1, "addkey");
75
ABTS_STR_EQUAL(tc, val, "bar");
79
static void table_nelts(abts_case *tc, void *data)
82
apr_table_t *t = apr_table_make(p, 1);
84
apr_table_set(t, "abc", "def");
85
apr_table_set(t, "def", "abc");
86
apr_table_set(t, "foo", "zzz");
87
val = apr_table_get(t, "foo");
88
ABTS_STR_EQUAL(tc, val, "zzz");
89
val = apr_table_get(t, "abc");
90
ABTS_STR_EQUAL(tc, val, "def");
91
val = apr_table_get(t, "def");
92
ABTS_STR_EQUAL(tc, val, "abc");
93
ABTS_INT_EQUAL(tc, 3, apr_table_elts(t)->nelts);
96
static void table_clear(abts_case *tc, void *data)
99
ABTS_INT_EQUAL(tc, 0, apr_table_elts(t1)->nelts);
102
static void table_unset(abts_case *tc, void *data)
105
apr_table_t *t = apr_table_make(p, 1);
107
apr_table_set(t, "a", "1");
108
apr_table_set(t, "b", "2");
109
apr_table_unset(t, "b");
110
ABTS_INT_EQUAL(tc, 1, apr_table_elts(t)->nelts);
111
val = apr_table_get(t, "a");
112
ABTS_STR_EQUAL(tc, val, "1");
113
val = apr_table_get(t, "b");
114
ABTS_PTR_EQUAL(tc, (void *)val, (void *)NULL);
117
static void table_overlap(abts_case *tc, void *data)
120
apr_table_t *t1 = apr_table_make(p, 1);
121
apr_table_t *t2 = apr_table_make(p, 1);
123
apr_table_addn(t1, "a", "0");
124
apr_table_addn(t1, "g", "7");
125
apr_table_addn(t2, "a", "1");
126
apr_table_addn(t2, "b", "2");
127
apr_table_addn(t2, "c", "3");
128
apr_table_addn(t2, "b", "2.0");
129
apr_table_addn(t2, "d", "4");
130
apr_table_addn(t2, "e", "5");
131
apr_table_addn(t2, "b", "2.");
132
apr_table_addn(t2, "f", "6");
133
apr_table_overlap(t1, t2, APR_OVERLAP_TABLES_SET);
135
ABTS_INT_EQUAL(tc, apr_table_elts(t1)->nelts, 7);
136
val = apr_table_get(t1, "a");
137
ABTS_STR_EQUAL(tc, val, "1");
138
val = apr_table_get(t1, "b");
139
ABTS_STR_EQUAL(tc, val, "2.");
140
val = apr_table_get(t1, "c");
141
ABTS_STR_EQUAL(tc, val, "3");
142
val = apr_table_get(t1, "d");
143
ABTS_STR_EQUAL(tc, val, "4");
144
val = apr_table_get(t1, "e");
145
ABTS_STR_EQUAL(tc, val, "5");
146
val = apr_table_get(t1, "f");
147
ABTS_STR_EQUAL(tc, val, "6");
148
val = apr_table_get(t1, "g");
149
ABTS_STR_EQUAL(tc, val, "7");
152
static void table_overlap2(abts_case *tc, void *data)
155
apr_table_t *t1, *t2;
157
apr_pool_create(&subp, p);
159
t1 = apr_table_make(subp, 1);
160
t2 = apr_table_make(p, 1);
161
apr_table_addn(t1, "t1", "one");
162
apr_table_addn(t2, "t2", "two");
164
apr_table_overlap(t1, t2, APR_OVERLAP_TABLES_SET);
166
ABTS_INT_EQUAL(tc, 2, apr_table_elts(t1)->nelts);
168
ABTS_STR_EQUAL(tc, apr_table_get(t1, "t1"), "one");
169
ABTS_STR_EQUAL(tc, apr_table_get(t1, "t2"), "two");
173
abts_suite *testtable(abts_suite *suite)
175
suite = ADD_SUITE(suite)
177
abts_run_test(suite, table_make, NULL);
178
abts_run_test(suite, table_get, NULL);
179
abts_run_test(suite, table_set, NULL);
180
abts_run_test(suite, table_getnotthere, NULL);
181
abts_run_test(suite, table_add, NULL);
182
abts_run_test(suite, table_nelts, NULL);
183
abts_run_test(suite, table_clear, NULL);
184
abts_run_test(suite, table_unset, NULL);
185
abts_run_test(suite, table_overlap, NULL);
186
abts_run_test(suite, table_overlap2, NULL);