2
* target-test.c: test the condense_targets functions
4
* ====================================================================
5
* Licensed to the Apache Software Foundation (ASF) under one
6
* or more contributor license agreements. See the NOTICE file
7
* distributed with this work for additional information
8
* regarding copyright ownership. The ASF licenses this file
9
* to you under the Apache License, Version 2.0 (the
10
* "License"); you may not use this file except in compliance
11
* with the License. You may obtain a copy of the License at
13
* http://www.apache.org/licenses/LICENSE-2.0
15
* Unless required by applicable law or agreed to in writing,
16
* software distributed under the License is distributed on an
17
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18
* KIND, either express or implied. See the License for the
19
* specific language governing permissions and limitations
21
* ====================================================================
24
#include <apr_general.h>
29
#define getcwd _getcwd
31
#include <unistd.h> /* for getcwd() */
34
#define SVN_DEPRECATED
36
#include "svn_pools.h"
39
#include "../svn_test.h"
41
typedef svn_error_t *(*condense_targets_func_t)
42
(const char **pcommon,
43
apr_array_header_t **pcondensed_targets,
44
const apr_array_header_t *targets,
45
svn_boolean_t remove_redundancies,
48
/** Executes function CONDENSE_TARGETS twice - with and without requesting the
49
* condensed targets list - on TEST_TARGETS (comma sep. string) and compares
50
* the results with EXP_COMMON and EXP_TARGETS (comma sep. string).
52
* @note: a '%' character at the beginning of EXP_COMMON or EXP_TARGETS will
53
* be replaced by the current working directory.
55
* Returns an error if any of the comparisons fail.
58
condense_targets_tests_helper(const char* title,
59
const char* test_targets,
60
const char* exp_common,
61
const char* exp_targets,
62
const char* func_name,
63
condense_targets_func_t condense_targets,
66
apr_array_header_t *targets;
67
apr_array_header_t *condensed_targets;
68
const char *common_path, *common_path2, *curdir;
70
const char *exp_common_abs = exp_common;
74
if (! getcwd(buf, sizeof(buf)))
75
return svn_error_create(SVN_ERR_BASE, NULL, "getcwd() failed");
76
curdir = svn_path_internal_style(buf, pool);
78
/* Create the target array */
79
targets = apr_array_make(pool, sizeof(test_targets), sizeof(const char *));
80
token = apr_strtok(apr_pstrdup(pool, test_targets), ",", &iter);
83
APR_ARRAY_PUSH(targets, const char *) =
84
svn_path_internal_style(token, pool);
85
token = apr_strtok(NULL, ",", &iter);
88
/* Call the function */
89
SVN_ERR(condense_targets(&common_path, &condensed_targets, targets,
92
/* Verify the common part with the expected (prefix with cwd). */
93
if (*exp_common == '%')
94
exp_common_abs = apr_pstrcat(pool, curdir, exp_common + 1, (char *)NULL);
96
if (strcmp(common_path, exp_common_abs) != 0)
98
return svn_error_createf
99
(SVN_ERR_TEST_FAILED, NULL,
100
"%s (test %s) returned %s instead of %s",
102
common_path, exp_common_abs);
105
/* Verify the condensed targets */
106
token = apr_strtok(apr_pstrdup(pool, exp_targets), ",", &iter);
107
for (i = 0; i < condensed_targets->nelts; i++)
109
const char * target = APR_ARRAY_IDX(condensed_targets, i, const char*);
110
if (token && (*token == '%'))
111
token = apr_pstrcat(pool, curdir, token + 1, (char *)NULL);
113
(target && (strcmp(target, token) != 0)))
115
return svn_error_createf
116
(SVN_ERR_TEST_FAILED, NULL,
117
"%s (test %s) couldn't find %s in expected targets list",
121
token = apr_strtok(NULL, ",", &iter);
124
/* Now ensure it works without the pbasename */
125
SVN_ERR(condense_targets(&common_path2, NULL, targets, TRUE, pool));
127
/* Verify the common part again */
128
if (strcmp(common_path, common_path2) != 0)
130
return svn_error_createf
131
(SVN_ERR_TEST_FAILED, NULL,
132
"%s (test %s): Common path without getting targets %s does not match" \
133
"common path with targets %s",
135
common_path2, common_path);
143
test_path_condense_targets(apr_pool_t *pool)
149
const char* exp_common;
150
const char* exp_targets;
152
{ "normal use", "z/A/B,z/A,z/A/C,z/D/E,z/D/F,z/D,z/G,z/G/H,z/G/I",
154
{"identical dirs", "z/A,z/A,z/A,z/A",
156
{"identical files", "z/A/file,z/A/file,z/A/file,z/A/file",
158
{"single dir", "z/A",
160
{"single file", "z/A/file",
162
{"URLs", "http://host/A/C,http://host/A/C/D,http://host/A/B/D",
163
"http://host/A", "C,B/D" },
164
{"URLs with no common prefix",
165
"http://host1/A/C,http://host2/A/C/D,http://host3/A/B/D",
166
"", "http://host1/A/C,http://host2/A/C/D,http://host3/A/B/D" },
167
{"file URLs with no common prefix", "file:///A/C,file:///B/D",
168
"", "file:///A/C,file:///B/D" },
169
{"URLs with mixed protocols",
170
"http://host/A/C,file:///B/D,gopher://host/A",
171
"", "http://host/A/C,file:///B/D,gopher://host/A" },
172
{"mixed paths and URLs",
173
"z/A/B,z/A,http://host/A/C/D,http://host/A/C",
174
"", "%/z/A,http://host/A/C" },
177
for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
179
SVN_ERR(condense_targets_tests_helper(tests[i].title,
182
tests[i].exp_targets,
183
"svn_path_condense_targets",
184
svn_path_condense_targets,
193
/* The test table. */
195
struct svn_test_descriptor_t test_funcs[] =
198
SVN_TEST_PASS2(test_path_condense_targets,
199
"test svn_path_condense_targets"),