~ubuntu-branches/debian/sid/subversion/sid

« back to all changes in this revision

Viewing changes to subversion/tests/libsvn_subr/target-test.c

  • Committer: Package Import Robot
  • Author(s): James McCoy, Peter Samuelson, James McCoy
  • Date: 2014-01-12 19:48:33 UTC
  • mfrom: (0.2.10)
  • Revision ID: package-import@ubuntu.com-20140112194833-w3axfwksn296jn5x
Tags: 1.8.5-1
[ Peter Samuelson ]
* New upstream release.  (Closes: #725787) Rediff patches:
  - Remove apr-abi1 (applied upstream), rename apr-abi2 to apr-abi
  - Remove loosen-sqlite-version-check (shouldn't be needed)
  - Remove java-osgi-metadata (applied upstream)
  - svnmucc prompts for a changelog if none is provided. (Closes: #507430)
  - Remove fix-bdb-version-detection, upstream uses "apu-config --dbm-libs"
  - Remove ruby-test-wc (applied upstream)
  - Fix “svn diff -r N file” when file has svn:mime-type set.
    (Closes: #734163)
  - Support specifying an encoding for mod_dav_svn's environment in which
    hooks are run.  (Closes: #601544)
  - Fix ordering of “svnadmin dump” paths with certain APR versions.
    (Closes: #687291)
  - Provide a better error message when authentication fails with an
    svn+ssh:// URL.  (Closes: #273874)
  - Updated Polish translations.  (Closes: #690815)

[ James McCoy ]
* Remove all traces of libneon, replaced by libserf.
* patches/sqlite_3.8.x_workaround: Upstream fix for wc-queries-test test
  failurse.
* Run configure with --with-apache-libexecdir, which allows removing part of
  patches/rpath.
* Re-enable auth-test as upstream has fixed the problem of picking up
  libraries from the environment rather than the build tree.
  (Closes: #654172)
* Point LD_LIBRARY_PATH at the built auth libraries when running the svn
  command during the build.  (Closes: #678224)
* Add a NEWS entry describing how to configure mod_dav_svn to understand
  UTF-8.  (Closes: #566148)
* Remove ancient transitional package, libsvn-ruby.
* Enable compatibility with Sqlite3 versions back to Wheezy.
* Enable hardening flags.  (Closes: #734918)
* patches/build-fixes: Enable verbose build logs.
* Build against the default ruby version.  (Closes: #722393)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * target-test.c: test the condense_targets functions
3
 
 *
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
12
 
 *
13
 
 *      http://www.apache.org/licenses/LICENSE-2.0
14
 
 *
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
20
 
 *    under the License.
21
 
 * ====================================================================
22
 
 */
23
 
 
24
 
#include <apr_general.h>
25
 
 
26
 
 
27
 
#ifdef _MSC_VER
28
 
#include <direct.h>
29
 
#define getcwd _getcwd
30
 
#else
31
 
#include <unistd.h> /* for getcwd() */
32
 
#endif
33
 
 
34
 
#define SVN_DEPRECATED
35
 
 
36
 
#include "svn_pools.h"
37
 
#include "svn_path.h"
38
 
 
39
 
#include "../svn_test.h"
40
 
 
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,
46
 
                            apr_pool_t *pool);
47
 
 
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).
51
 
 *
52
 
 * @note: a '%' character at the beginning of EXP_COMMON or EXP_TARGETS will
53
 
 * be replaced by the current working directory.
54
 
 *
55
 
 * Returns an error if any of the comparisons fail.
56
 
 */
57
 
static svn_error_t *
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,
64
 
                              apr_pool_t *pool)
65
 
{
66
 
  apr_array_header_t *targets;
67
 
  apr_array_header_t *condensed_targets;
68
 
  const char *common_path, *common_path2, *curdir;
69
 
  char *token, *iter;
70
 
  const char *exp_common_abs = exp_common;
71
 
  int i;
72
 
  char buf[8192];
73
 
 
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);
77
 
 
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);
81
 
  while (token)
82
 
    {
83
 
      APR_ARRAY_PUSH(targets, const char *) =
84
 
        svn_path_internal_style(token, pool);
85
 
      token = apr_strtok(NULL, ",", &iter);
86
 
    };
87
 
 
88
 
  /* Call the function */
89
 
  SVN_ERR(condense_targets(&common_path, &condensed_targets, targets,
90
 
                           TRUE, pool));
91
 
 
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);
95
 
 
96
 
  if (strcmp(common_path, exp_common_abs) != 0)
97
 
    {
98
 
      return svn_error_createf
99
 
        (SVN_ERR_TEST_FAILED, NULL,
100
 
         "%s (test %s) returned %s instead of %s",
101
 
           func_name, title,
102
 
           common_path, exp_common_abs);
103
 
    }
104
 
 
105
 
  /* Verify the condensed targets */
106
 
  token = apr_strtok(apr_pstrdup(pool, exp_targets), ",", &iter);
107
 
  for (i = 0; i < condensed_targets->nelts; i++)
108
 
    {
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);
112
 
      if (! token ||
113
 
          (target && (strcmp(target, token) != 0)))
114
 
        {
115
 
          return svn_error_createf
116
 
            (SVN_ERR_TEST_FAILED, NULL,
117
 
             "%s (test %s) couldn't find %s in expected targets list",
118
 
               func_name, title,
119
 
               target);
120
 
        }
121
 
      token = apr_strtok(NULL, ",", &iter);
122
 
    }
123
 
 
124
 
  /* Now ensure it works without the pbasename */
125
 
  SVN_ERR(condense_targets(&common_path2, NULL, targets, TRUE, pool));
126
 
 
127
 
  /* Verify the common part again */
128
 
  if (strcmp(common_path, common_path2) != 0)
129
 
    {
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",
134
 
          func_name, title,
135
 
          common_path2, common_path);
136
 
    }
137
 
 
138
 
  return SVN_NO_ERROR;
139
 
}
140
 
 
141
 
 
142
 
static svn_error_t *
143
 
test_path_condense_targets(apr_pool_t *pool)
144
 
{
145
 
  int i;
146
 
  struct {
147
 
    const char* title;
148
 
    const char* targets;
149
 
    const char* exp_common;
150
 
    const char* exp_targets;
151
 
  } tests[] = {
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",
153
 
      "%/z", "A,D,G" },
154
 
    {"identical dirs", "z/A,z/A,z/A,z/A",
155
 
     "%/z/A", "" },
156
 
    {"identical files", "z/A/file,z/A/file,z/A/file,z/A/file",
157
 
     "%/z/A/file", "" },
158
 
    {"single dir", "z/A",
159
 
     "%/z/A", "" },
160
 
    {"single file", "z/A/file",
161
 
     "%/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" },
175
 
  };
176
 
 
177
 
  for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
178
 
    {
179
 
      SVN_ERR(condense_targets_tests_helper(tests[i].title,
180
 
                                            tests[i].targets,
181
 
                                            tests[i].exp_common,
182
 
                                            tests[i].exp_targets,
183
 
                                            "svn_path_condense_targets",
184
 
                                            svn_path_condense_targets,
185
 
                                            pool));
186
 
    }
187
 
 
188
 
  return SVN_NO_ERROR;
189
 
}
190
 
 
191
 
 
192
 
 
193
 
/* The test table.  */
194
 
 
195
 
struct svn_test_descriptor_t test_funcs[] =
196
 
  {
197
 
    SVN_TEST_NULL,
198
 
    SVN_TEST_PASS2(test_path_condense_targets,
199
 
                   "test svn_path_condense_targets"),
200
 
    SVN_TEST_NULL
201
 
  };