1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
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
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(abts_case *tc, void *data)
50
apr_array_header_t *pathelts;
53
rv = apr_filepath_list_split(&pathelts, path_in, p);
54
ABTS_PTR_NOTNULL(tc, pathelts);
55
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
56
ABTS_INT_EQUAL(tc, parts_out_count, pathelts->nelts);
57
for (i = 0; i < pathelts->nelts; ++i)
58
ABTS_STR_EQUAL(tc, parts_out[i], ((char**)pathelts->elts)[i]);
61
static void list_split_single(abts_case *tc, void *data)
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
ABTS_PTR_NOTNULL(tc, pathelts);
72
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
73
if (parts_in[i][0] == '\0')
74
ABTS_INT_EQUAL(tc, 0, pathelts->nelts);
77
ABTS_INT_EQUAL(tc, 1, pathelts->nelts);
78
ABTS_STR_EQUAL(tc, parts_in[i], *(char**)pathelts->elts);
83
static void list_merge_multi(abts_case *tc, void *data)
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
ABTS_PTR_NOTNULL(tc, liststr);
97
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
98
ABTS_STR_EQUAL(tc, liststr, path_out);
101
static void list_merge_single(abts_case *tc, void *data)
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
ABTS_PTR_EQUAL(tc, NULL, liststr);
119
ABTS_PTR_NOTNULL(tc, liststr);
120
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
121
ABTS_STR_EQUAL(tc, liststr, parts_in[i]);
127
abts_suite *testpath(abts_suite *suite)
129
suite = ADD_SUITE(suite)
131
abts_run_test(suite, list_split_multi, NULL);
132
abts_run_test(suite, list_split_single, NULL);
133
abts_run_test(suite, list_merge_multi, NULL);
134
abts_run_test(suite, list_merge_single, NULL);