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.
18 #include "apr_file_info.h"
19 #include "apr_errno.h"
20 #include "apr_pools.h"
21 #include "apr_tables.h"
23 #if defined(WIN32) || defined(NETWARE) || defined(OS2)
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"
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);
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);
46 static void list_split_multi(CuTest *tc)
50 apr_array_header_t *pathelts;
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]);
61 static void list_split_single(CuTest *tc)
65 apr_array_header_t *pathelts;
67 for (i = 0; i < parts_in_count; ++i)
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);
77 CuAssertIntEquals(tc, 1, pathelts->nelts);
78 CuAssertStrEquals(tc, parts_in[i], *(char**)pathelts->elts);
83 static void list_merge_multi(CuTest *tc)
88 apr_array_header_t *pathelts;
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];
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);
101 static void list_merge_single(CuTest *tc)
106 apr_array_header_t *pathelts;
108 pathelts = apr_array_make(p, 1, sizeof(const char*));
109 apr_array_push(pathelts);
110 for (i = 0; i < parts_in_count; ++i)
112 *(const char**)pathelts->elts = parts_in[i];
114 rv = apr_filepath_list_merge(&liststr, pathelts, p);
115 if (parts_in[i][0] == '\0')
116 CuAssertPtrEquals(tc, NULL, liststr);
119 CuAssertPtrNotNull(tc, liststr);
120 CuAssertIntEquals(tc, APR_SUCCESS, rv);
121 CuAssertStrEquals(tc, liststr, parts_in[i]);
127 CuSuite *testpath(void)
129 CuSuite *suite = CuSuiteNew("Path lists");
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);