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
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(CuTest *tc)
37 t1 = apr_table_make(p, 5);
38 CuAssertPtrNotNull(tc, t1);
41 static void table_get(CuTest *tc)
45 apr_table_set(t1, "foo", "bar");
46 val = apr_table_get(t1, "foo");
47 CuAssertStrEquals(tc, val, "bar");
50 static void table_set(CuTest *tc)
54 apr_table_set(t1, "setkey", "bar");
55 apr_table_set(t1, "setkey", "2ndtry");
56 val = apr_table_get(t1, "setkey");
57 CuAssertStrEquals(tc, val, "2ndtry");
60 static void table_getnotthere(CuTest *tc)
64 val = apr_table_get(t1, "keynotthere");
65 CuAssertPtrEquals(tc, NULL, (void *)val);
68 static void table_add(CuTest *tc)
72 apr_table_add(t1, "addkey", "bar");
73 apr_table_add(t1, "addkey", "foo");
74 val = apr_table_get(t1, "addkey");
75 CuAssertStrEquals(tc, val, "bar");
79 static void table_nelts(CuTest *tc)
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 CuAssertStrEquals(tc, val, "zzz");
89 val = apr_table_get(t, "abc");
90 CuAssertStrEquals(tc, val, "def");
91 val = apr_table_get(t, "def");
92 CuAssertStrEquals(tc, val, "abc");
93 CuAssertIntEquals(tc, 3, apr_table_elts(t)->nelts);
96 static void table_clear(CuTest *tc)
99 CuAssertIntEquals(tc, 0, apr_table_elts(t1)->nelts);
102 static void table_unset(CuTest *tc)
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 CuAssertIntEquals(tc, 1, apr_table_elts(t)->nelts);
111 val = apr_table_get(t, "a");
112 CuAssertStrEquals(tc, val, "1");
113 val = apr_table_get(t, "b");
114 CuAssertPtrEquals(tc, (void *)val, (void *)NULL);
117 static void table_overlap(CuTest *tc)
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 CuAssertIntEquals(tc, apr_table_elts(t1)->nelts, 7);
136 val = apr_table_get(t1, "a");
137 CuAssertStrEquals(tc, val, "1");
138 val = apr_table_get(t1, "b");
139 CuAssertStrEquals(tc, val, "2.");
140 val = apr_table_get(t1, "c");
141 CuAssertStrEquals(tc, val, "3");
142 val = apr_table_get(t1, "d");
143 CuAssertStrEquals(tc, val, "4");
144 val = apr_table_get(t1, "e");
145 CuAssertStrEquals(tc, val, "5");
146 val = apr_table_get(t1, "f");
147 CuAssertStrEquals(tc, val, "6");
148 val = apr_table_get(t1, "g");
149 CuAssertStrEquals(tc, val, "7");
152 CuSuite *testtable(void)
154 CuSuite *suite = CuSuiteNew("Table");
156 SUITE_ADD_TEST(suite, table_make);
157 SUITE_ADD_TEST(suite, table_get);
158 SUITE_ADD_TEST(suite, table_set);
159 SUITE_ADD_TEST(suite, table_getnotthere);
160 SUITE_ADD_TEST(suite, table_add);
161 SUITE_ADD_TEST(suite, table_nelts);
162 SUITE_ADD_TEST(suite, table_clear);
163 SUITE_ADD_TEST(suite, table_unset);
164 SUITE_ADD_TEST(suite, table_overlap);