~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr/test/testtable.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2002-2005 The Apache Software Foundation or its licensors, as
 
2
 * applicable.
 
3
 *
 
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
 
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
 
 
33
static apr_table_t *t1 = NULL;
 
34
 
 
35
static void table_make(abts_case *tc, void *data)
 
36
{
 
37
    t1 = apr_table_make(p, 5);
 
38
    ABTS_PTR_NOTNULL(tc, t1);
 
39
}
 
40
 
 
41
static void table_get(abts_case *tc, void *data)
 
42
{
 
43
    const char *val;
 
44
 
 
45
    apr_table_set(t1, "foo", "bar");
 
46
    val = apr_table_get(t1, "foo");
 
47
    ABTS_STR_EQUAL(tc, val, "bar");
 
48
}
 
49
 
 
50
static void table_set(abts_case *tc, void *data)
 
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
    ABTS_STR_EQUAL(tc, val, "2ndtry");
 
58
}
 
59
 
 
60
static void table_getnotthere(abts_case *tc, void *data)
 
61
{
 
62
    const char *val;
 
63
 
 
64
    val = apr_table_get(t1, "keynotthere");
 
65
    ABTS_PTR_EQUAL(tc, NULL, (void *)val);
 
66
}
 
67
 
 
68
static void table_add(abts_case *tc, void *data)
 
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
    ABTS_STR_EQUAL(tc, val, "bar");
 
76
 
 
77
}
 
78
 
 
79
static void table_nelts(abts_case *tc, void *data)
 
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
    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);
 
94
}
 
95
 
 
96
static void table_clear(abts_case *tc, void *data)
 
97
{
 
98
    apr_table_clear(t1);
 
99
    ABTS_INT_EQUAL(tc, 0, apr_table_elts(t1)->nelts);
 
100
}
 
101
 
 
102
static void table_unset(abts_case *tc, void *data)
 
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
    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);
 
115
}
 
116
 
 
117
static void table_overlap(abts_case *tc, void *data)
 
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
    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");
 
150
}
 
151
 
 
152
static void table_overlap2(abts_case *tc, void *data)
 
153
{
 
154
    apr_pool_t *subp;
 
155
    apr_table_t *t1, *t2;
 
156
 
 
157
    apr_pool_create(&subp, p);
 
158
 
 
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");
 
163
    
 
164
    apr_table_overlap(t1, t2, APR_OVERLAP_TABLES_SET);
 
165
    
 
166
    ABTS_INT_EQUAL(tc, 2, apr_table_elts(t1)->nelts);
 
167
    
 
168
    ABTS_STR_EQUAL(tc, apr_table_get(t1, "t1"), "one");
 
169
    ABTS_STR_EQUAL(tc, apr_table_get(t1, "t2"), "two");
 
170
 
 
171
}
 
172
 
 
173
abts_suite *testtable(abts_suite *suite)
 
174
{
 
175
    suite = ADD_SUITE(suite)
 
176
 
 
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);
 
187
 
 
188
    return suite;
 
189
}
 
190