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"
29 const char *unparsed_mergeinfo
;
30 svn_boolean_t remains
;
31 } mergeinfo_catalog_item
;
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
},
39 { {"/foo", "/bar: 1-4", TRUE
},
40 {"/foo/beep/baz", "/blaa/beep/baz: 1-4", TRUE
},
42 { {"/", "/gah: 1-4", TRUE
},
43 {"/foo/beep/baz", "/gah/foo/beep/baz: 1-4", FALSE
},
48 test_elide_mergeinfo_catalog(const char **msg
,
49 svn_boolean_t msg_only
,
50 svn_test_opts_t
*opts
,
56 *msg
= "test svn_client__elide_mergeinfo_catalog";
60 iterpool
= svn_pool_create(pool
);
63 i
< sizeof(elide_testcases
) / sizeof(elide_testcases
[0]);
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
,
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
,
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
);
103 test_args_to_target_array(const char **msg
,
104 svn_boolean_t msg_only
,
105 svn_test_opts_t
*opts
,
109 apr_pool_t
*iterpool
;
110 svn_client_ctx_t
*ctx
;
113 const char *output
; /* NULL means an error is expected. */
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";
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
;
149 const char *argv
[] = { "opt-test", input
, NULL
};
150 apr_status_t apr_err
;
153 apr_err
= apr_getopt_init(&os
, iterpool
, argc
, argv
);
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
);
162 const char *actual_output
;
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 "
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
,
179 "svn_client_args_to_target_array() should "
180 "have returned a canonical path but "
185 if (strcmp(expected_output
, actual_output
) != 0)
186 return svn_error_createf(SVN_ERR_TEST_FAILED
, NULL
,
188 "svn_client_args_to_target_array() should "
189 "have returned '%s' but returned '%s'.",
197 return svn_error_createf(SVN_ERR_TEST_FAILED
, NULL
,
198 "Unexpected success in passing '%s' "
199 "to svn_client_args_to_target_array().",
207 /* ========================================================================== */
209 struct svn_test_descriptor_t test_funcs
[] =
212 SVN_TEST_PASS(test_elide_mergeinfo_catalog
),
213 SVN_TEST_PASS(test_args_to_target_array
),