2
* prefix-string-test.c: a collection of svn_prefix_string__* tests
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
/* ====================================================================
25
To add tests, look toward the bottom of this file.
33
#include <apr_pools.h>
35
#include "../svn_test.h"
37
#include "svn_error.h"
38
#include "svn_string.h" /* This includes <apr_*.h> */
39
#include "private/svn_string_private.h"
42
test_empty_string(apr_pool_t *pool)
44
svn_prefix_tree__t *tree = svn_prefix_tree__create(pool);
45
svn_prefix_string__t *empty = svn_prefix_string__create(tree, "");
47
/* same instance for all strings of the same value */
48
SVN_TEST_ASSERT(empty == svn_prefix_string__create(tree, ""));
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, "");
54
/* strings shall be equal to themselves */
55
SVN_TEST_ASSERT(0 == svn_prefix_string__compare(empty, empty));
60
enum {TEST_CASE_COUNT = 9};
62
static const char *test_cases[TEST_CASE_COUNT] =
64
"a longish string of sorts, longer than 7 anyway",
67
"some shorter string",
71
"a longish string of sorts, longer than ?! anyway",
76
test_string_creation(apr_pool_t *pool)
78
svn_prefix_tree__t *tree = svn_prefix_tree__create(pool);
79
svn_prefix_string__t *strings[TEST_CASE_COUNT];
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]);
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]));
91
/* converting them back to strings must be the initial values */
92
for (i = 0; i < TEST_CASE_COUNT; ++i)
94
svn_string_t *expanded = svn_prefix_string__expand(strings[i], pool);
96
SVN_TEST_ASSERT(expanded->len == strlen(test_cases[i]));
97
SVN_TEST_STRING_ASSERT(expanded->data, test_cases[i]);
105
test_string_comparison(apr_pool_t *pool)
107
svn_prefix_tree__t *tree = svn_prefix_tree__create(pool);
108
svn_prefix_string__t *strings[TEST_CASE_COUNT];
112
for (i = 0; i < TEST_CASE_COUNT; ++i)
113
strings[i] = svn_prefix_string__create(tree, test_cases[i]);
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]));
119
/* compare with all other strings */
120
for (i = 0; i < TEST_CASE_COUNT; ++i)
122
svn_string_t *lhs = svn_prefix_string__expand(strings[i], pool);
123
for (k = 0; k < TEST_CASE_COUNT; ++k)
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]);
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);
138
/* An array of all test functions */
140
static int max_threads = 1;
142
static struct svn_test_descriptor_t test_funcs[] =
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,