~ubuntu-branches/debian/sid/subversion/sid

« back to all changes in this revision

Viewing changes to subversion/tests/libsvn_subr/path-test.c

  • Committer: Package Import Robot
  • Author(s): James McCoy, Peter Samuelson, James McCoy
  • Date: 2014-01-12 19:48:33 UTC
  • mfrom: (0.2.10)
  • Revision ID: package-import@ubuntu.com-20140112194833-w3axfwksn296jn5x
Tags: 1.8.5-1
[ Peter Samuelson ]
* New upstream release.  (Closes: #725787) Rediff patches:
  - Remove apr-abi1 (applied upstream), rename apr-abi2 to apr-abi
  - Remove loosen-sqlite-version-check (shouldn't be needed)
  - Remove java-osgi-metadata (applied upstream)
  - svnmucc prompts for a changelog if none is provided. (Closes: #507430)
  - Remove fix-bdb-version-detection, upstream uses "apu-config --dbm-libs"
  - Remove ruby-test-wc (applied upstream)
  - Fix “svn diff -r N file” when file has svn:mime-type set.
    (Closes: #734163)
  - Support specifying an encoding for mod_dav_svn's environment in which
    hooks are run.  (Closes: #601544)
  - Fix ordering of “svnadmin dump” paths with certain APR versions.
    (Closes: #687291)
  - Provide a better error message when authentication fails with an
    svn+ssh:// URL.  (Closes: #273874)
  - Updated Polish translations.  (Closes: #690815)

[ James McCoy ]
* Remove all traces of libneon, replaced by libserf.
* patches/sqlite_3.8.x_workaround: Upstream fix for wc-queries-test test
  failurse.
* Run configure with --with-apache-libexecdir, which allows removing part of
  patches/rpath.
* Re-enable auth-test as upstream has fixed the problem of picking up
  libraries from the environment rather than the build tree.
  (Closes: #654172)
* Point LD_LIBRARY_PATH at the built auth libraries when running the svn
  command during the build.  (Closes: #678224)
* Add a NEWS entry describing how to configure mod_dav_svn to understand
  UTF-8.  (Closes: #566148)
* Remove ancient transitional package, libsvn-ruby.
* Enable compatibility with Sqlite3 versions back to Wheezy.
* Enable hardening flags.  (Closes: #734918)
* patches/build-fixes: Enable verbose build logs.
* Build against the default ruby version.  (Closes: #722393)

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 * ====================================================================
22
22
 */
23
23
 
 
24
#ifdef _MSC_VER
 
25
#include <direct.h>
 
26
#define getcwd _getcwd
 
27
#else
 
28
#include <unistd.h> /* for getcwd() */
 
29
#endif
 
30
 
24
31
#include <stdio.h>
25
32
#include <string.h>
26
33
#include <apr_general.h>
871
878
  int i;
872
879
  svn_stringbuf_t *buf;
873
880
 
874
 
  buf = svn_stringbuf_create("", pool);
 
881
  buf = svn_stringbuf_create_empty(pool);
875
882
 
876
883
  i = 0;
877
884
  while (tests[i].path)
1195
1202
    const char *path;
1196
1203
    const char *path_root;
1197
1204
    const char *path_ext;
1198
 
    svn_boolean_t result;
1199
1205
  } tests[] = {
1200
1206
    { "no-ext",                    "no-ext",                 "" },
1201
1207
    { "test-file.py",              "test-file.",             "py" },
1465
1471
}
1466
1472
 
1467
1473
 
 
1474
/* The type of a function to be tested by condense_targets_tests_helper().
 
1475
 * Matches svn_path_condense_targets().
 
1476
 */
 
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,
 
1482
                            apr_pool_t *pool);
 
1483
 
 
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).
 
1487
 *
 
1488
 * @note: a '%' character at the beginning of EXP_COMMON or EXP_TARGETS will
 
1489
 * be replaced by the current working directory.
 
1490
 *
 
1491
 * Returns an error if any of the comparisons fail.
 
1492
 */
 
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,
 
1500
                              apr_pool_t *pool)
 
1501
{
 
1502
  apr_array_header_t *targets;
 
1503
  apr_array_header_t *condensed_targets;
 
1504
  const char *common_path, *common_path2, *curdir;
 
1505
  char *token, *iter;
 
1506
  const char *exp_common_abs = exp_common;
 
1507
  int i;
 
1508
  char buf[8192];
 
1509
 
 
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);
 
1513
 
 
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);
 
1517
  while (token)
 
1518
    {
 
1519
      APR_ARRAY_PUSH(targets, const char *) =
 
1520
        svn_path_internal_style(token, pool);
 
1521
      token = apr_strtok(NULL, ",", &iter);
 
1522
    };
 
1523
 
 
1524
  /* Call the function */
 
1525
  SVN_ERR(condense_targets(&common_path, &condensed_targets, targets,
 
1526
                           TRUE, pool));
 
1527
 
 
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);
 
1531
 
 
1532
  if (strcmp(common_path, exp_common_abs) != 0)
 
1533
    {
 
1534
      return svn_error_createf
 
1535
        (SVN_ERR_TEST_FAILED, NULL,
 
1536
         "%s (test %s) returned %s instead of %s",
 
1537
           func_name, title,
 
1538
           common_path, exp_common_abs);
 
1539
    }
 
1540
 
 
1541
  /* Verify the condensed targets */
 
1542
  token = apr_strtok(apr_pstrdup(pool, exp_targets), ",", &iter);
 
1543
  for (i = 0; i < condensed_targets->nelts; i++)
 
1544
    {
 
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);
 
1548
      if (! token ||
 
1549
          (target && (strcmp(target, token) != 0)))
 
1550
        {
 
1551
          return svn_error_createf
 
1552
            (SVN_ERR_TEST_FAILED, NULL,
 
1553
             "%s (test %s) couldn't find %s in expected targets list",
 
1554
               func_name, title,
 
1555
               target);
 
1556
        }
 
1557
      token = apr_strtok(NULL, ",", &iter);
 
1558
    }
 
1559
 
 
1560
  /* Now ensure it works without the pbasename */
 
1561
  SVN_ERR(condense_targets(&common_path2, NULL, targets, TRUE, pool));
 
1562
 
 
1563
  /* Verify the common part again */
 
1564
  if (strcmp(common_path, common_path2) != 0)
 
1565
    {
 
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",
 
1570
          func_name, title,
 
1571
          common_path2, common_path);
 
1572
    }
 
1573
 
 
1574
  return SVN_NO_ERROR;
 
1575
}
 
1576
 
 
1577
 
 
1578
static svn_error_t *
 
1579
test_path_condense_targets(apr_pool_t *pool)
 
1580
{
 
1581
  int i;
 
1582
  struct {
 
1583
    const char* title;
 
1584
    const char* targets;
 
1585
    const char* exp_common;
 
1586
    const char* exp_targets;
 
1587
  } tests[] = {
 
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",
 
1589
      "%/z", "A,D,G" },
 
1590
    {"identical dirs", "z/A,z/A,z/A,z/A",
 
1591
     "%/z/A", "" },
 
1592
    {"identical files", "z/A/file,z/A/file,z/A/file,z/A/file",
 
1593
     "%/z/A/file", "" },
 
1594
    {"single dir", "z/A",
 
1595
     "%/z/A", "" },
 
1596
    {"single file", "z/A/file",
 
1597
     "%/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" },
 
1611
  };
 
1612
 
 
1613
  for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
 
1614
    {
 
1615
      SVN_ERR(condense_targets_tests_helper(tests[i].title,
 
1616
                                            tests[i].targets,
 
1617
                                            tests[i].exp_common,
 
1618
                                            tests[i].exp_targets,
 
1619
                                            "svn_path_condense_targets",
 
1620
                                            svn_path_condense_targets,
 
1621
                                            pool));
 
1622
    }
 
1623
 
 
1624
  return SVN_NO_ERROR;
 
1625
}
 
1626
 
 
1627
static svn_error_t *
 
1628
test_path_is_repos_relative_url(apr_pool_t *pool)
 
1629
{
 
1630
  int i;
 
1631
  struct {
 
1632
    const char* path;
 
1633
    svn_boolean_t result;
 
1634
  } tests[] = {
 
1635
    { "^/A",           TRUE },
 
1636
    { "http://host/A", FALSE },
 
1637
    { "/A/B",          FALSE },
 
1638
  };
 
1639
 
 
1640
  for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
 
1641
    {
 
1642
      svn_boolean_t result = svn_path_is_repos_relative_url(tests[i].path);
 
1643
 
 
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\"",
 
1648
                                 tests[i].path,
 
1649
                                 result ? "TRUE" : "FALSE",
 
1650
                                 tests[i].result ? "TRUE" : "FALSE");
 
1651
    }
 
1652
 
 
1653
  return SVN_NO_ERROR;
 
1654
}
 
1655
 
 
1656
static svn_error_t *
 
1657
test_path_resolve_repos_relative_url(apr_pool_t *pool)
 
1658
{
 
1659
  int i;
 
1660
  struct {
 
1661
    const char *relative_url;
 
1662
    const char *repos_root_url;
 
1663
    const char *absolute_url;
 
1664
  } tests[] = {
 
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 */
 
1669
  };
 
1670
 
 
1671
  for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
 
1672
    {
 
1673
      const char *result;
 
1674
 
 
1675
      SVN_ERR(svn_path_resolve_repos_relative_url(&result,
 
1676
                                                  tests[i].relative_url,
 
1677
                                                  tests[i].repos_root_url,
 
1678
                                                  pool));
 
1679
 
 
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);
 
1687
    }
 
1688
 
 
1689
  return SVN_NO_ERROR;
 
1690
}
 
1691
 
 
1692
 
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
1526
1751
                   "test svn_path_local_style"),
1527
1752
    SVN_TEST_PASS2(test_path_internal_style,
1528
1753
                   "test svn_path_internal_style"),
 
1754
    SVN_TEST_PASS2(test_path_condense_targets,
 
1755
                   "test svn_path_condense_targets"),
 
1756
    SVN_TEST_PASS2(test_path_is_repos_relative_url,
 
1757
                   "test svn_path_is_repos_relative_url"),
 
1758
    SVN_TEST_PASS2(test_path_resolve_repos_relative_url,
 
1759
                   "test svn_path_resolve_repos_relative_url"),
1529
1760
    SVN_TEST_NULL
1530
1761
  };