upload http
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / srclib / apr / test / testpath.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_file_info.h"
19 #include "apr_errno.h"
20 #include "apr_pools.h"
21 #include "apr_tables.h"
22
23 #if defined(WIN32) || defined(NETWARE) || defined(OS2)
24 #define PSEP ";"
25 #define DSEP "\\"
26 #else
27 #define PSEP ":"
28 #define DSEP "/"
29 #endif
30
31 #define PX ""
32 #define P1 "first path"
33 #define P2 "second" DSEP "path"
34 #define P3 "th ird" DSEP "path"
35 #define P4 "fourth" DSEP "pa th"
36 #define P5 "fifthpath"
37
38 static const char *parts_in[] = { P1, P2, P3, PX, P4, P5 };
39 static const char *path_in = P1 PSEP P2 PSEP P3 PSEP PX PSEP P4 PSEP P5;
40 static const int  parts_in_count = sizeof(parts_in)/sizeof(*parts_in);
41
42 static const char *parts_out[] = { P1, P2, P3, P4, P5 };
43 static const char *path_out = P1 PSEP P2 PSEP P3 PSEP P4 PSEP P5;
44 static const int  parts_out_count = sizeof(parts_out)/sizeof(*parts_out);
45
46 static void list_split_multi(CuTest *tc)
47 {
48     int i;
49     apr_status_t rv;
50     apr_array_header_t *pathelts;
51
52     pathelts = NULL;
53     rv = apr_filepath_list_split(&pathelts, path_in, p);
54     CuAssertPtrNotNull(tc, pathelts);
55     CuAssertIntEquals(tc, APR_SUCCESS, rv);
56     CuAssertIntEquals(tc, parts_out_count, pathelts->nelts);
57     for (i = 0; i < pathelts->nelts; ++i)
58         CuAssertStrEquals(tc, parts_out[i], ((char**)pathelts->elts)[i]);
59 }
60
61 static void list_split_single(CuTest *tc)
62 {
63     int i;
64     apr_status_t rv;
65     apr_array_header_t *pathelts;
66
67     for (i = 0; i < parts_in_count; ++i)
68     {
69         pathelts = NULL;
70         rv = apr_filepath_list_split(&pathelts, parts_in[i], p);
71         CuAssertPtrNotNull(tc, pathelts);
72         CuAssertIntEquals(tc, APR_SUCCESS, rv);
73         if (parts_in[i][0] == '\0')
74             CuAssertIntEquals(tc, 0, pathelts->nelts);
75         else
76         {
77             CuAssertIntEquals(tc, 1, pathelts->nelts);
78             CuAssertStrEquals(tc, parts_in[i], *(char**)pathelts->elts);
79         }
80     }
81 }
82
83 static void list_merge_multi(CuTest *tc)
84 {
85     int i;
86     char *liststr;
87     apr_status_t rv;
88     apr_array_header_t *pathelts;
89
90     pathelts = apr_array_make(p, parts_in_count, sizeof(const char*));
91     for (i = 0; i < parts_in_count; ++i)
92         *(const char**)apr_array_push(pathelts) = parts_in[i];
93
94     liststr = NULL;
95     rv = apr_filepath_list_merge(&liststr, pathelts, p);
96     CuAssertPtrNotNull(tc, liststr);
97     CuAssertIntEquals(tc, APR_SUCCESS, rv);
98     CuAssertStrEquals(tc, liststr, path_out);
99 }
100
101 static void list_merge_single(CuTest *tc)
102 {
103     int i;
104     char *liststr;
105     apr_status_t rv;
106     apr_array_header_t *pathelts;
107
108     pathelts = apr_array_make(p, 1, sizeof(const char*));
109     apr_array_push(pathelts);
110     for (i = 0; i < parts_in_count; ++i)
111     {
112         *(const char**)pathelts->elts = parts_in[i];
113         liststr = NULL;
114         rv = apr_filepath_list_merge(&liststr, pathelts, p);
115         if (parts_in[i][0] == '\0')
116             CuAssertPtrEquals(tc, NULL, liststr);
117         else
118         {
119             CuAssertPtrNotNull(tc, liststr);
120             CuAssertIntEquals(tc, APR_SUCCESS, rv);
121             CuAssertStrEquals(tc, liststr, parts_in[i]);
122         }
123     }
124 }
125
126
127 CuSuite *testpath(void)
128 {
129     CuSuite *suite = CuSuiteNew("Path lists");
130
131     SUITE_ADD_TEST(suite, list_split_multi);
132     SUITE_ADD_TEST(suite, list_split_single);
133     SUITE_ADD_TEST(suite, list_merge_multi);
134     SUITE_ADD_TEST(suite, list_merge_single);
135
136     return suite;
137 }
138