2 * target-test.c -- test the target condensing function
4 * ====================================================================
5 * Copyright (c) 2000-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 * ====================================================================
19 #define APR_WANT_STDIO
21 #include <apr_general.h>
23 #include "svn_cmdline.h"
24 #include "svn_pools.h"
27 #include "svn_error.h"
29 int main(int argc
, char **argv
)
33 apr_array_header_t
*targets
;
34 apr_array_header_t
*condensed_targets
;
35 const char *common_path
= 0;
36 const char *common_path2
= 0;
40 fprintf(stderr
, "USAGE: %s <list of entries to be compared>\n", argv
[0]);
44 /* Initialize the app. */
45 if (svn_cmdline_init("target-test", stderr
) != EXIT_SUCCESS
)
48 /* Create our top-level pool. */
49 pool
= svn_pool_create(NULL
);
51 /* Create the target array */
52 targets
= apr_array_make(pool
, argc
- 1, sizeof(const char *));
53 for (i
= 1; i
< argc
; i
++)
55 const char *path_utf8
;
57 err
= svn_utf_cstring_to_utf8(&path_utf8
, argv
[i
], pool
);
59 /* Even when compiled with UTF support in V5R4, argv is still
60 * encoded in ebcdic. */
61 err
= svn_utf_cstring_to_utf8_ex2(&path_utf8
, argv
[i
],
62 (const char *)0, pool
);
64 if (err
!= SVN_NO_ERROR
)
65 svn_handle_error2(err
, stderr
, TRUE
, "target-test: ");
66 APR_ARRAY_PUSH(targets
, const char *) =
67 svn_path_internal_style(path_utf8
, pool
);
71 /* Call the function */
72 err
= svn_path_condense_targets(&common_path
, &condensed_targets
, targets
,
74 if (err
!= SVN_NO_ERROR
)
75 svn_handle_error2(err
, stderr
, TRUE
, "target-test: ");
77 /* Display the results */
79 const char *common_path_stdout
;
80 err
= svn_utf_cstring_from_utf8(&common_path_stdout
, common_path
, pool
);
81 if (err
!= SVN_NO_ERROR
)
82 svn_handle_error2(err
, stderr
, TRUE
, "target-test: ");
83 printf("%s: ", common_path_stdout
);
85 for (i
= 0; i
< condensed_targets
->nelts
; i
++)
87 const char * target
= APR_ARRAY_IDX(condensed_targets
, i
, const char*);
90 const char *target_stdout
;
91 err
= svn_utf_cstring_from_utf8(&target_stdout
, target
, pool
);
92 if (err
!= SVN_NO_ERROR
)
93 svn_handle_error2(err
, stderr
, TRUE
, "target-test: ");
94 printf("%s, ", target_stdout
);
101 /* Now ensure it works without the pbasename */
102 err
= svn_path_condense_targets(&common_path2
, NULL
, targets
, TRUE
, pool
);
103 if (err
!= SVN_NO_ERROR
)
104 svn_handle_error2(err
, stderr
, TRUE
, "target-test: ");
106 if (strcmp(common_path
, common_path2
) != 0)
108 printf("Common path without getting targets does not match common path "