2 * opt-test.c -- test the option functions
4 * ====================================================================
5 * Copyright (c) 2000-2004 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 * ====================================================================
21 #include <apr_general.h>
23 #include "../svn_test.h"
27 test_parse_peg_rev(const char **msg
,
28 svn_boolean_t msg_only
,
29 svn_test_opts_t
*opts
,
35 const char *path
; /* NULL means an error is expected. */
36 svn_opt_revision_t peg
;
38 { "foo/bar", "foo/bar", {svn_opt_revision_unspecified
} },
39 { "foo/bar@13", "foo/bar", {svn_opt_revision_number
, {13}} },
40 { "foo/bar@HEAD", "foo/bar", {svn_opt_revision_head
} },
41 { "foo/bar@{1999-12-31}", "foo/bar", {svn_opt_revision_date
, {0}} },
42 { "http://a/b@27", "http://a/b", {svn_opt_revision_number
, {27}} },
43 { "http://a/b@COMMITTED", "http://a/b", {svn_opt_revision_committed
} },
44 { "foo/bar@1:2", NULL
, {svn_opt_revision_unspecified
} },
45 { "foo/bar@baz", NULL
, {svn_opt_revision_unspecified
} },
46 { "foo/bar@", "foo/bar", {svn_opt_revision_unspecified
} },
47 { "foo/bar/@13", "foo/bar/", {svn_opt_revision_number
, {13}} },
48 { "foo/bar@@13", "foo/bar@", {svn_opt_revision_number
, {13}} },
49 { "foo/@bar@HEAD", "foo/@bar", {svn_opt_revision_head
} },
50 { "foo@/bar", "foo@/bar", {svn_opt_revision_unspecified
} },
51 { "foo@HEAD/bar", "foo@HEAD/bar", {svn_opt_revision_unspecified
} },
54 *msg
= "test svn_opt_parse_path";
58 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); i
++)
61 svn_opt_revision_t peg
;
64 err
= svn_opt_parse_path(&peg
, &path
, tests
[i
].input
, pool
);
70 return svn_error_createf
71 (SVN_ERR_TEST_FAILED
, NULL
,
72 "svn_opt_parse_path ('%s') returned an error instead of '%s'",
73 tests
[i
].input
, tests
[i
].path
);
79 || (tests
[i
].path
== NULL
)
80 || (strcmp(path
, tests
[i
].path
) != 0)
81 || (peg
.kind
!= tests
[i
].peg
.kind
)
82 || (peg
.kind
== svn_opt_revision_number
&& peg
.value
.number
!= tests
[i
].peg
.value
.number
))
83 return svn_error_createf
84 (SVN_ERR_TEST_FAILED
, NULL
,
85 "svn_opt_parse_path ('%s') returned '%s' instead of '%s'", tests
[i
].input
,
86 path
? path
: "NULL", tests
[i
].path
? tests
[i
].path
: "NULL");
94 test_svn_opt_args_to_target_array2(const char **msg
,
95 svn_boolean_t msg_only
,
96 svn_test_opts_t
*opts
,
102 const char *output
; /* NULL means an error is expected. */
105 { ".@BASE", "@BASE" },
106 { "foo///bar", "foo/bar" },
107 { "foo///bar@13", "foo/bar@13" },
108 { "foo///bar@HEAD", "foo/bar@HEAD" },
109 { "foo///bar@{1999-12-31}", "foo/bar@{1999-12-31}" },
110 { "http://a//b////", "http://a/b" },
111 { "http://a///b@27", "http://a/b@27" },
112 { "http://a/b//@COMMITTED", "http://a/b@COMMITTED" },
113 { "foo///bar@1:2", "foo/bar@1:2" },
114 { "foo///bar@baz", "foo/bar@baz" },
115 { "foo///bar@", "foo/bar@" },
116 { "foo///bar///@13", "foo/bar@13" },
117 { "foo///bar@@13", "foo/bar@@13" },
118 { "foo///@bar@HEAD", "foo/@bar@HEAD" },
119 { "foo@///bar", "foo@/bar" },
120 { "foo@HEAD///bar", "foo@HEAD/bar" },
123 *msg
= "test svn_opt_args_to_target_array2";
127 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); i
++)
129 const char *input
= tests
[i
].input
;
130 const char *expected_output
= tests
[i
].output
;
131 apr_array_header_t
*targets
;
134 const char *argv
[] = { "opt-test", input
, NULL
};
135 apr_status_t apr_err
;
138 apr_err
= apr_getopt_init(&os
, pool
, argc
, argv
);
140 return svn_error_wrap_apr(apr_err
,
141 "Error initializing command line arguments");
143 err
= svn_opt_args_to_target_array2(&targets
, os
, NULL
, pool
);
147 const char *actual_output
;
151 if (argc
- 1 != targets
->nelts
)
152 return svn_error_createf(SVN_ERR_TEST_FAILED
, NULL
,
153 "Passed %d target(s) to "
154 "svn_opt_args_to_target_array2() but "
159 actual_output
= APR_ARRAY_IDX(targets
, 0, const char *);
161 if (! svn_path_is_canonical(actual_output
, pool
))
162 return svn_error_createf(SVN_ERR_TEST_FAILED
, NULL
,
164 "svn_opt_args_to_target_array2() should "
165 "have returned a canonical path but "
170 if (strcmp(expected_output
, actual_output
) != 0)
171 return svn_error_createf(SVN_ERR_TEST_FAILED
, NULL
,
173 "svn_opt_args_to_target_array2() should "
174 "have returned '%s' but returned '%s'.",
182 return svn_error_createf(SVN_ERR_TEST_FAILED
, NULL
,
183 "Unexpected success in passing '%s' "
184 "to svn_opt_args_to_target_array2().",
193 /* The test table. */
195 struct svn_test_descriptor_t test_funcs
[] =
198 SVN_TEST_PASS(test_parse_peg_rev
),
199 SVN_TEST_PASS(test_svn_opt_args_to_target_array2
),