1474
/* The type of a function to be tested by condense_targets_tests_helper().
1475
* Matches svn_path_condense_targets().
1477
typedef svn_error_t *(*condense_targets_func_t)
1478
(const char **pcommon,
1479
apr_array_header_t **pcondensed_targets,
1480
const apr_array_header_t *targets,
1481
svn_boolean_t remove_redundancies,
1484
/** Executes function CONDENSE_TARGETS twice - with and without requesting the
1485
* condensed targets list - on TEST_TARGETS (comma sep. string) and compares
1486
* the results with EXP_COMMON and EXP_TARGETS (comma sep. string).
1488
* @note: a '%' character at the beginning of EXP_COMMON or EXP_TARGETS will
1489
* be replaced by the current working directory.
1491
* Returns an error if any of the comparisons fail.
1493
static svn_error_t *
1494
condense_targets_tests_helper(const char* title,
1495
const char* test_targets,
1496
const char* exp_common,
1497
const char* exp_targets,
1498
const char* func_name,
1499
condense_targets_func_t condense_targets,
1502
apr_array_header_t *targets;
1503
apr_array_header_t *condensed_targets;
1504
const char *common_path, *common_path2, *curdir;
1506
const char *exp_common_abs = exp_common;
1510
if (! getcwd(buf, sizeof(buf)))
1511
return svn_error_create(SVN_ERR_BASE, NULL, "getcwd() failed");
1512
curdir = svn_path_internal_style(buf, pool);
1514
/* Create the target array */
1515
targets = apr_array_make(pool, sizeof(test_targets), sizeof(const char *));
1516
token = apr_strtok(apr_pstrdup(pool, test_targets), ",", &iter);
1519
APR_ARRAY_PUSH(targets, const char *) =
1520
svn_path_internal_style(token, pool);
1521
token = apr_strtok(NULL, ",", &iter);
1524
/* Call the function */
1525
SVN_ERR(condense_targets(&common_path, &condensed_targets, targets,
1528
/* Verify the common part with the expected (prefix with cwd). */
1529
if (*exp_common == '%')
1530
exp_common_abs = apr_pstrcat(pool, curdir, exp_common + 1, (char *)NULL);
1532
if (strcmp(common_path, exp_common_abs) != 0)
1534
return svn_error_createf
1535
(SVN_ERR_TEST_FAILED, NULL,
1536
"%s (test %s) returned %s instead of %s",
1538
common_path, exp_common_abs);
1541
/* Verify the condensed targets */
1542
token = apr_strtok(apr_pstrdup(pool, exp_targets), ",", &iter);
1543
for (i = 0; i < condensed_targets->nelts; i++)
1545
const char * target = APR_ARRAY_IDX(condensed_targets, i, const char*);
1546
if (token && (*token == '%'))
1547
token = apr_pstrcat(pool, curdir, token + 1, (char *)NULL);
1549
(target && (strcmp(target, token) != 0)))
1551
return svn_error_createf
1552
(SVN_ERR_TEST_FAILED, NULL,
1553
"%s (test %s) couldn't find %s in expected targets list",
1557
token = apr_strtok(NULL, ",", &iter);
1560
/* Now ensure it works without the pbasename */
1561
SVN_ERR(condense_targets(&common_path2, NULL, targets, TRUE, pool));
1563
/* Verify the common part again */
1564
if (strcmp(common_path, common_path2) != 0)
1566
return svn_error_createf
1567
(SVN_ERR_TEST_FAILED, NULL,
1568
"%s (test %s): Common path without getting targets %s does not match" \
1569
"common path with targets %s",
1571
common_path2, common_path);
1574
return SVN_NO_ERROR;
1578
static svn_error_t *
1579
test_path_condense_targets(apr_pool_t *pool)
1584
const char* targets;
1585
const char* exp_common;
1586
const char* exp_targets;
1588
{ "normal use", "z/A/B,z/A,z/A/C,z/D/E,z/D/F,z/D,z/G,z/G/H,z/G/I",
1590
{"identical dirs", "z/A,z/A,z/A,z/A",
1592
{"identical files", "z/A/file,z/A/file,z/A/file,z/A/file",
1594
{"single dir", "z/A",
1596
{"single file", "z/A/file",
1598
{"URLs", "http://host/A/C,http://host/A/C/D,http://host/A/B/D",
1599
"http://host/A", "C,B/D" },
1600
{"URLs with no common prefix",
1601
"http://host1/A/C,http://host2/A/C/D,http://host3/A/B/D",
1602
"", "http://host1/A/C,http://host2/A/C/D,http://host3/A/B/D" },
1603
{"file URLs with no common prefix", "file:///A/C,file:///B/D",
1604
"", "file:///A/C,file:///B/D" },
1605
{"URLs with mixed protocols",
1606
"http://host/A/C,file:///B/D,gopher://host/A",
1607
"", "http://host/A/C,file:///B/D,gopher://host/A" },
1608
{"mixed paths and URLs",
1609
"z/A/B,z/A,http://host/A/C/D,http://host/A/C",
1610
"", "%/z/A,http://host/A/C" },
1613
for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
1615
SVN_ERR(condense_targets_tests_helper(tests[i].title,
1617
tests[i].exp_common,
1618
tests[i].exp_targets,
1619
"svn_path_condense_targets",
1620
svn_path_condense_targets,
1624
return SVN_NO_ERROR;
1627
static svn_error_t *
1628
test_path_is_repos_relative_url(apr_pool_t *pool)
1633
svn_boolean_t result;
1636
{ "http://host/A", FALSE },
1640
for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
1642
svn_boolean_t result = svn_path_is_repos_relative_url(tests[i].path);
1644
if (tests[i].result != result)
1645
return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
1646
"svn_path_is_repos_relative_url(\"%s\")"
1647
" returned \"%s\" expected \"%s\"",
1649
result ? "TRUE" : "FALSE",
1650
tests[i].result ? "TRUE" : "FALSE");
1653
return SVN_NO_ERROR;
1656
static svn_error_t *
1657
test_path_resolve_repos_relative_url(apr_pool_t *pool)
1661
const char *relative_url;
1662
const char *repos_root_url;
1663
const char *absolute_url;
1665
{ "^/A", "file:///Z/X", "file:///Z/X/A" },
1666
{ "^/A", "file:///Z/X/", "file:///Z/X//A" }, /* doesn't canonicalize */
1667
{ "^/A@2", "file:///Z/X", "file:///Z/X/A@2" }, /* peg rev */
1668
{ "^/A", "/Z/X", "/Z/X/A" }, /* doesn't verify repos_root is URL */
1671
for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
1675
SVN_ERR(svn_path_resolve_repos_relative_url(&result,
1676
tests[i].relative_url,
1677
tests[i].repos_root_url,
1680
if (strcmp(tests[i].absolute_url,result))
1681
return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
1682
"svn_path_resolve_repos_relative_url(\"%s\","
1683
"\"%s\") returned \"%s\" expected \"%s\"",
1684
tests[i].relative_url,
1685
tests[i].repos_root_url,
1686
result, tests[i].absolute_url);
1689
return SVN_NO_ERROR;
1468
1693
/* local define to support XFail-ing tests on Windows/Cygwin only */
1469
1694
#ifdef SVN_USE_DOS_PATHS
1470
1695
#define WINDOWS_OR_CYGWIN TRUE