Fix compiler warning due to missing function prototype.
[svn.git] / subversion / tests / libsvn_client / client-test.c
blob89f5ab0a0116bb85433086c01e59ca9edf2f7175
1 /*
2 * Regression tests for logic in the libsvn_client library.
4 * ====================================================================
5 * Copyright (c) 2007 CollabNet. All rights reserved.
7 * This software is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at http://subversion.tigris.org/license-1.html.
10 * If newer versions of this license are posted there, you may use a
11 * newer version instead, at your option.
13 * This software consists of voluntary contributions made by many
14 * individuals. For exact contribution history, see the revision
15 * history and logs, available at http://subversion.tigris.org/.
16 * ====================================================================
20 #include "svn_mergeinfo.h"
21 #include "../../libsvn_client/mergeinfo.h"
22 #include "svn_pools.h"
23 #include "svn_client.h"
25 #include "../svn_test.h"
27 typedef struct {
28 const char *path;
29 const char *unparsed_mergeinfo;
30 svn_boolean_t remains;
31 } mergeinfo_catalog_item;
33 #define MAX_ITEMS 10
35 static mergeinfo_catalog_item elide_testcases[][MAX_ITEMS] = {
36 { {"/foo", "/bar: 1-4", TRUE},
37 {"/foo/beep/baz", "/bar/beep/baz: 1-4", FALSE},
38 { NULL }},
39 { {"/foo", "/bar: 1-4", TRUE},
40 {"/foo/beep/baz", "/blaa/beep/baz: 1-4", TRUE},
41 { NULL }},
42 { {"/", "/gah: 1-4", TRUE},
43 {"/foo/beep/baz", "/gah/foo/beep/baz: 1-4", FALSE},
44 { NULL }}
47 static svn_error_t *
48 test_elide_mergeinfo_catalog(const char **msg,
49 svn_boolean_t msg_only,
50 svn_test_opts_t *opts,
51 apr_pool_t *pool)
53 int i;
54 apr_pool_t *iterpool;
56 *msg = "test svn_client__elide_mergeinfo_catalog";
57 if (msg_only)
58 return SVN_NO_ERROR;
60 iterpool = svn_pool_create(pool);
62 for (i = 0;
63 i < sizeof(elide_testcases) / sizeof(elide_testcases[0]);
64 i++)
66 apr_hash_t *catalog;
67 mergeinfo_catalog_item *item;
69 svn_pool_clear(iterpool);
71 catalog = apr_hash_make(iterpool);
72 for (item = elide_testcases[i]; item->path; item++)
74 apr_hash_t *mergeinfo;
76 SVN_ERR(svn_mergeinfo_parse(&mergeinfo, item->unparsed_mergeinfo,
77 iterpool));
78 apr_hash_set(catalog, item->path, APR_HASH_KEY_STRING, mergeinfo);
81 SVN_ERR(svn_client__elide_mergeinfo_catalog(catalog, iterpool));
83 for (item = elide_testcases[i]; item->path; item++)
85 apr_hash_t *mergeinfo = apr_hash_get(catalog, item->path,
86 APR_HASH_KEY_STRING);
87 if (item->remains && !mergeinfo)
88 return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
89 "Elision for test case #%d incorrectly "
90 "elided '%s'", i, item->path);
91 if (!item->remains && mergeinfo)
92 return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
93 "Elision for test case #%d failed to "
94 "elide '%s'", i, item->path);
98 svn_pool_destroy(iterpool);
99 return SVN_NO_ERROR;
102 static svn_error_t *
103 test_args_to_target_array(const char **msg,
104 svn_boolean_t msg_only,
105 svn_test_opts_t *opts,
106 apr_pool_t *pool)
108 apr_size_t i;
109 apr_pool_t *iterpool;
110 svn_client_ctx_t *ctx;
111 static struct {
112 const char *input;
113 const char *output; /* NULL means an error is expected. */
114 } const tests[] = {
115 { ".", "" },
116 { ".@BASE", "@BASE" },
117 { "foo///bar", "foo/bar" },
118 { "foo///bar@13", "foo/bar@13" },
119 { "foo///bar@HEAD", "foo/bar@HEAD" },
120 { "foo///bar@{1999-12-31}", "foo/bar@{1999-12-31}" },
121 { "http://a//b////", "http://a/b" },
122 { "http://a///b@27", "http://a/b@27" },
123 { "http://a/b//@COMMITTED", "http://a/b@COMMITTED" },
124 { "foo///bar@1:2", "foo/bar@1:2" },
125 { "foo///bar@baz", "foo/bar@baz" },
126 { "foo///bar@", "foo/bar@" },
127 { "foo///bar///@13", "foo/bar@13" },
128 { "foo///bar@@13", "foo/bar@@13" },
129 { "foo///@bar@HEAD", "foo/@bar@HEAD" },
130 { "foo@///bar", "foo@/bar" },
131 { "foo@HEAD///bar", "foo@HEAD/bar" },
134 *msg = "test svn_client_args_to_target_array";
135 if (msg_only)
136 return SVN_NO_ERROR;
138 SVN_ERR(svn_client_create_context(&ctx, pool));
140 iterpool = svn_pool_create(pool);
142 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
144 const char *input = tests[i].input;
145 const char *expected_output = tests[i].output;
146 apr_array_header_t *targets;
147 apr_getopt_t *os;
148 const int argc = 2;
149 const char *argv[] = { "opt-test", input, NULL };
150 apr_status_t apr_err;
151 svn_error_t *err;
153 apr_err = apr_getopt_init(&os, iterpool, argc, argv);
154 if (apr_err)
155 return svn_error_wrap_apr(apr_err,
156 "Error initializing command line arguments");
158 err = svn_client_args_to_target_array(&targets, os, NULL, ctx, iterpool);
160 if (expected_output)
162 const char *actual_output;
164 if (err)
165 return err;
166 if (argc - 1 != targets->nelts)
167 return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
168 "Passed %d target(s) to "
169 "svn_client_args_to_target_array() but "
170 "got %d back.",
171 argc - 1,
172 targets->nelts);
174 actual_output = APR_ARRAY_IDX(targets, 0, const char *);
176 if (! svn_path_is_canonical(actual_output, iterpool))
177 return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
178 "Input '%s' to "
179 "svn_client_args_to_target_array() should "
180 "have returned a canonical path but "
181 "'%s' is not.",
182 input,
183 actual_output);
185 if (strcmp(expected_output, actual_output) != 0)
186 return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
187 "Input '%s' to "
188 "svn_client_args_to_target_array() should "
189 "have returned '%s' but returned '%s'.",
190 input,
191 expected_output,
192 actual_output);
194 else
196 if (! err)
197 return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
198 "Unexpected success in passing '%s' "
199 "to svn_client_args_to_target_array().",
200 input);
204 return SVN_NO_ERROR;
207 /* ========================================================================== */
209 struct svn_test_descriptor_t test_funcs[] =
211 SVN_TEST_NULL,
212 SVN_TEST_PASS(test_elide_mergeinfo_catalog),
213 SVN_TEST_PASS(test_args_to_target_array),
214 SVN_TEST_NULL