/* Test conversion from different codepages to utf8. */ static svn_error_t * test_utf_cstring_to_utf8_ex2(apr_pool_t *pool) { apr_size_t i; apr_pool_t *subpool = svn_pool_create(pool); struct data { const char *string; const char *expected_result; const char *from_page; } tests[] = { {"ascii text\n", "ascii text\n", "unexistant-page"}, {"Edelwei\xdf", "Edelwei\xc3\x9f", "ISO-8859-1"} }; for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) { const char *dest; svn_pool_clear(subpool); SVN_ERR(svn_utf_cstring_to_utf8_ex2(&dest, tests[i].string, tests[i].from_page, pool)); if (strcmp(dest, tests[i].expected_result)) { return svn_error_createf (SVN_ERR_TEST_FAILED, NULL, "svn_utf_cstring_to_utf8_ex2 ('%s', '%s') returned ('%s') " "instead of ('%s')", tests[i].string, tests[i].from_page, dest, tests[i].expected_result); } } svn_pool_destroy(subpool); return SVN_NO_ERROR; }
int main(int argc, char **argv) { apr_pool_t *pool; svn_error_t *err; apr_array_header_t *targets; apr_array_header_t *condensed_targets; const char *common_path = 0; const char *common_path2 = 0; int i; if (argc < 2) { fprintf(stderr, "USAGE: %s <list of entries to be compared>\n", argv[0]); return EXIT_FAILURE; } /* Initialize the app. */ if (svn_cmdline_init("target-test", stderr) != EXIT_SUCCESS) return EXIT_FAILURE; /* Create our top-level pool. */ pool = svn_pool_create(NULL); /* Create the target array */ targets = apr_array_make(pool, argc - 1, sizeof(const char *)); for (i = 1; i < argc; i++) { const char *path_utf8; #ifndef AS400_UTF8 err = svn_utf_cstring_to_utf8(&path_utf8, argv[i], pool); #else /* Even when compiled with UTF support in V5R4, argv is still * encoded in ebcdic. */ err = svn_utf_cstring_to_utf8_ex2(&path_utf8, argv[i], (const char *)0, pool); #endif if (err != SVN_NO_ERROR) svn_handle_error2(err, stderr, TRUE, "target-test: "); APR_ARRAY_PUSH(targets, const char *) = svn_path_internal_style(path_utf8, pool); } /* Call the function */ err = svn_path_condense_targets(&common_path, &condensed_targets, targets, TRUE, pool); if (err != SVN_NO_ERROR) svn_handle_error2(err, stderr, TRUE, "target-test: "); /* Display the results */ { const char *common_path_stdout; err = svn_utf_cstring_from_utf8(&common_path_stdout, common_path, pool); if (err != SVN_NO_ERROR) svn_handle_error2(err, stderr, TRUE, "target-test: "); printf("%s: ", common_path_stdout); } for (i = 0; i < condensed_targets->nelts; i++) { const char * target = APR_ARRAY_IDX(condensed_targets, i, const char*); if (target) { const char *target_stdout; err = svn_utf_cstring_from_utf8(&target_stdout, target, pool); if (err != SVN_NO_ERROR) svn_handle_error2(err, stderr, TRUE, "target-test: "); printf("%s, ", target_stdout); } else printf("NULL, "); } printf("\n"); /* Now ensure it works without the pbasename */ err = svn_path_condense_targets(&common_path2, NULL, targets, TRUE, pool); if (err != SVN_NO_ERROR) svn_handle_error2(err, stderr, TRUE, "target-test: "); if (strcmp(common_path, common_path2) != 0) { printf("Common path without getting targets does not match common path " "with targets\n"); return EXIT_FAILURE; } return EXIT_SUCCESS; }