upload http
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / srclib / apr / test / testtable.c
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 "test_apr.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
33 static apr_table_t *t1 = NULL;
34
35 static void table_make(CuTest *tc)
36 {
37     t1 = apr_table_make(p, 5);
38     CuAssertPtrNotNull(tc, t1);
39 }
40
41 static void table_get(CuTest *tc)
42 {
43     const char *val;
44
45     apr_table_set(t1, "foo", "bar");
46     val = apr_table_get(t1, "foo");
47     CuAssertStrEquals(tc, val, "bar");
48 }
49
50 static void table_set(CuTest *tc)
51 {
52     const char *val;
53
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");
58 }
59
60 static void table_getnotthere(CuTest *tc)
61 {
62     const char *val;
63
64     val = apr_table_get(t1, "keynotthere");
65     CuAssertPtrEquals(tc, NULL, (void *)val);
66 }
67
68 static void table_add(CuTest *tc)
69 {
70     const char *val;
71
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");
76
77 }
78
79 static void table_nelts(CuTest *tc)
80 {
81     const char *val;
82     apr_table_t *t = apr_table_make(p, 1);
83
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);
94 }
95
96 static void table_clear(CuTest *tc)
97 {
98     apr_table_clear(t1);
99     CuAssertIntEquals(tc, 0, apr_table_elts(t1)->nelts);
100 }
101
102 static void table_unset(CuTest *tc)
103 {
104     const char *val;
105     apr_table_t *t = apr_table_make(p, 1);
106
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);
115 }
116
117 static void table_overlap(CuTest *tc)
118 {
119     const char *val;
120     apr_table_t *t1 = apr_table_make(p, 1);
121     apr_table_t *t2 = apr_table_make(p, 1);
122
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);
134     
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");
150 }
151
152 CuSuite *testtable(void)
153 {
154     CuSuite *suite = CuSuiteNew("Table");
155
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);
165
166     return suite;
167 }
168