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

« back to all changes in this revision

Viewing changes to subversion/tests/libsvn_subr/prefix-string-test.c

  • Committer: Package Import Robot
  • Author(s): James McCoy
  • Date: 2015-08-07 21:32:47 UTC
  • mfrom: (0.2.15) (4.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20150807213247-ozyewtmgsr6tkewl
Tags: 1.9.0-1
* Upload to unstable
* New upstream release.
  + Security fixes
    - CVE-2015-3184: Mixed anonymous/authenticated path-based authz with
      httpd 2.4
    - CVE-2015-3187: svn_repos_trace_node_locations() reveals paths hidden
      by authz
* Add >= 2.7 requirement for python-all-dev Build-Depends, needed to run
  tests.
* Remove Build-Conflicts against ruby-test-unit.  (Closes: #791844)
* Remove patches/apache_module_dependency in favor of expressing the
  dependencies in authz_svn.load/dav_svn.load.
* Build-Depend on apache2-dev (>= 2.4.16) to ensure ap_some_authn_required()
  is available when building mod_authz_svn and Depend on apache2-bin (>=
  2.4.16) for runtime support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * prefix-string-test.c:  a collection of svn_prefix_string__* tests
 
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
/* ====================================================================
 
25
   To add tests, look toward the bottom of this file.
 
26
 
 
27
*/
 
28
 
 
29
 
 
30
 
 
31
#include <stdio.h>
 
32
#include <string.h>
 
33
#include <apr_pools.h>
 
34
 
 
35
#include "../svn_test.h"
 
36
 
 
37
#include "svn_error.h"
 
38
#include "svn_string.h"   /* This includes <apr_*.h> */
 
39
#include "private/svn_string_private.h"
 
40
 
 
41
static svn_error_t *
 
42
test_empty_string(apr_pool_t *pool)
 
43
{
 
44
  svn_prefix_tree__t *tree = svn_prefix_tree__create(pool);
 
45
  svn_prefix_string__t *empty = svn_prefix_string__create(tree, "");
 
46
 
 
47
  /* same instance for all strings of the same value */
 
48
  SVN_TEST_ASSERT(empty == svn_prefix_string__create(tree, ""));
 
49
 
 
50
  /* does it actually have the right contents? */
 
51
  SVN_TEST_ASSERT(svn_prefix_string__expand(empty, pool)->len == 0);
 
52
  SVN_TEST_STRING_ASSERT(svn_prefix_string__expand(empty, pool)->data, "");
 
53
 
 
54
  /* strings shall be equal to themselves */
 
55
  SVN_TEST_ASSERT(0 == svn_prefix_string__compare(empty, empty));
 
56
 
 
57
  return SVN_NO_ERROR;
 
58
}
 
59
 
 
60
enum {TEST_CASE_COUNT = 9};
 
61
 
 
62
static const char *test_cases[TEST_CASE_COUNT] =
 
63
{
 
64
  "a longish string of sorts, longer than 7 anyway",
 
65
  "some other string",
 
66
  "more stuff on root",
 
67
  "some shorter string",
 
68
  "some short string",
 
69
  "some short str",
 
70
  "some short str2",
 
71
  "a longish string of sorts, longer than ?! anyway",
 
72
  "a"
 
73
};
 
74
 
 
75
static svn_error_t *
 
76
test_string_creation(apr_pool_t *pool)
 
77
{
 
78
  svn_prefix_tree__t *tree = svn_prefix_tree__create(pool);
 
79
  svn_prefix_string__t *strings[TEST_CASE_COUNT];
 
80
  int i;
 
81
 
 
82
  /* create strings and remember their initial references */
 
83
  for (i = 0; i < TEST_CASE_COUNT; ++i)
 
84
    strings[i] = svn_prefix_string__create(tree, test_cases[i]);
 
85
 
 
86
  /* doing this again must yield the same pointers */
 
87
  for (i = 0; i < TEST_CASE_COUNT; ++i)
 
88
    SVN_TEST_ASSERT(strings[i]
 
89
                    == svn_prefix_string__create(tree, test_cases[i]));
 
90
 
 
91
  /* converting them back to strings must be the initial values */
 
92
  for (i = 0; i < TEST_CASE_COUNT; ++i)
 
93
    {
 
94
      svn_string_t *expanded = svn_prefix_string__expand(strings[i], pool);
 
95
 
 
96
      SVN_TEST_ASSERT(expanded->len == strlen(test_cases[i]));
 
97
      SVN_TEST_STRING_ASSERT(expanded->data, test_cases[i]);
 
98
 
 
99
    }
 
100
 
 
101
  return SVN_NO_ERROR;
 
102
}
 
103
 
 
104
static svn_error_t *
 
105
test_string_comparison(apr_pool_t *pool)
 
106
{
 
107
  svn_prefix_tree__t *tree = svn_prefix_tree__create(pool);
 
108
  svn_prefix_string__t *strings[TEST_CASE_COUNT];
 
109
  int i, k;
 
110
 
 
111
  /* create strings */
 
112
  for (i = 0; i < TEST_CASE_COUNT; ++i)
 
113
    strings[i] = svn_prefix_string__create(tree, test_cases[i]);
 
114
 
 
115
  /* comparing them with themselves */
 
116
  for (i = 0; i < TEST_CASE_COUNT; ++i)
 
117
    SVN_TEST_ASSERT(! svn_prefix_string__compare(strings[i], strings[i]));
 
118
 
 
119
  /* compare with all other strings */
 
120
  for (i = 0; i < TEST_CASE_COUNT; ++i)
 
121
    {
 
122
      svn_string_t *lhs = svn_prefix_string__expand(strings[i], pool);
 
123
      for (k = 0; k < TEST_CASE_COUNT; ++k)
 
124
        {
 
125
          svn_string_t *rhs = svn_prefix_string__expand(strings[k], pool);
 
126
          int expected_diff = strcmp(lhs->data, rhs->data);
 
127
          int actual_diff = svn_prefix_string__compare(strings[i], strings[k]);
 
128
 
 
129
          SVN_TEST_ASSERT((actual_diff < 0) == (expected_diff < 0));
 
130
          SVN_TEST_ASSERT((actual_diff > 0) == (expected_diff > 0));
 
131
          SVN_TEST_ASSERT(!actual_diff == !expected_diff);
 
132
        }
 
133
    }
 
134
 
 
135
  return SVN_NO_ERROR;
 
136
}
 
137
 
 
138
/* An array of all test functions */
 
139
 
 
140
static int max_threads = 1;
 
141
 
 
142
static struct svn_test_descriptor_t test_funcs[] =
 
143
  {
 
144
    SVN_TEST_NULL,
 
145
    SVN_TEST_PASS2(test_empty_string,
 
146
                   "check empty strings"),
 
147
    SVN_TEST_PASS2(test_string_creation,
 
148
                   "create many strings"),
 
149
    SVN_TEST_PASS2(test_string_comparison,
 
150
                   "compare strings"),
 
151
    SVN_TEST_NULL
 
152
  };
 
153
 
 
154
SVN_TEST_MAIN