You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by ju...@apache.org on 2012/11/17 02:51:41 UTC
svn commit: r1410667 - in /subversion/trunk: build.conf
subversion/tests/libsvn_subr/path-test.c
subversion/tests/libsvn_subr/target-test.c
Author: julianfoad
Date: Sat Nov 17 01:51:40 2012
New Revision: 1410667
URL: http://svn.apache.org/viewvc?rev=1410667&view=rev
Log:
Combine two unit test files, one of which only had one test in it.
* subversion/tests/libsvn_subr/path-test.c
(condense_targets_func_t, condense_targets_tests_helper,
test_path_condense_targets): Move these here from target-test.c.
(test_funcs): Add 'test_path_condense_targets'.
* subversion/tests/libsvn_subr/target-test.c
Delete this file.
* build.conf
(target-test): Remove this section.
(__ALL__): Remove 'target-test'.
Removed:
subversion/trunk/subversion/tests/libsvn_subr/target-test.c
Modified:
subversion/trunk/build.conf
subversion/trunk/subversion/tests/libsvn_subr/path-test.c
Modified: subversion/trunk/build.conf
URL: http://svn.apache.org/viewvc/subversion/trunk/build.conf?rev=1410667&r1=1410666&r2=1410667&view=diff
==============================================================================
--- subversion/trunk/build.conf (original)
+++ subversion/trunk/build.conf Sat Nov 17 01:51:40 2012
@@ -886,14 +886,6 @@ sources = utf-test.c
install = test
libs = libsvn_test libsvn_subr apriconv apr
-[target-test]
-description = Test the condense_targets functions
-type = exe
-path = subversion/tests/libsvn_subr
-sources = target-test.c
-install = test
-libs = libsvn_test libsvn_subr apriconv apr
-
[subst_translate-test]
description = Test the svn_subst_translate* functions
type = exe
@@ -1179,7 +1171,7 @@ libs = __ALL__
strings-reps-test changes-test locks-test repos-test
checksum-test compat-test config-test hashdump-test mergeinfo-test
opt-test path-test stream-test string-test time-test utf-test
- target-test error-test cache-test spillbuf-test crypto-test
+ error-test cache-test spillbuf-test crypto-test
named_atomic-test named_atomic-proc-test revision-test
subst_translate-test io-test
translate-test
Modified: subversion/trunk/subversion/tests/libsvn_subr/path-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_subr/path-test.c?rev=1410667&r1=1410666&r2=1410667&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/path-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/path-test.c Sat Nov 17 01:51:40 2012
@@ -21,6 +21,13 @@
* ====================================================================
*/
+#ifdef _MSC_VER
+#include <direct.h>
+#define getcwd _getcwd
+#else
+#include <unistd.h> /* for getcwd() */
+#endif
+
#include <stdio.h>
#include <string.h>
#include <apr_general.h>
@@ -1465,6 +1472,160 @@ test_path_internal_style(apr_pool_t *poo
}
+/* The type of a function to be tested by condense_targets_tests_helper().
+ * Matches svn_path_condense_targets().
+ */
+typedef svn_error_t *(*condense_targets_func_t)
+ (const char **pcommon,
+ apr_array_header_t **pcondensed_targets,
+ const apr_array_header_t *targets,
+ svn_boolean_t remove_redundancies,
+ apr_pool_t *pool);
+
+/** Executes function CONDENSE_TARGETS twice - with and without requesting the
+ * condensed targets list - on TEST_TARGETS (comma sep. string) and compares
+ * the results with EXP_COMMON and EXP_TARGETS (comma sep. string).
+ *
+ * @note: a '%' character at the beginning of EXP_COMMON or EXP_TARGETS will
+ * be replaced by the current working directory.
+ *
+ * Returns an error if any of the comparisons fail.
+ */
+static svn_error_t *
+condense_targets_tests_helper(const char* title,
+ const char* test_targets,
+ const char* exp_common,
+ const char* exp_targets,
+ const char* func_name,
+ condense_targets_func_t condense_targets,
+ apr_pool_t *pool)
+{
+ apr_array_header_t *targets;
+ apr_array_header_t *condensed_targets;
+ const char *common_path, *common_path2, *curdir;
+ char *token, *iter;
+ const char *exp_common_abs = exp_common;
+ int i;
+ char buf[8192];
+
+ if (! getcwd(buf, sizeof(buf)))
+ return svn_error_create(SVN_ERR_BASE, NULL, "getcwd() failed");
+ curdir = svn_path_internal_style(buf, pool);
+
+ /* Create the target array */
+ targets = apr_array_make(pool, sizeof(test_targets), sizeof(const char *));
+ token = apr_strtok(apr_pstrdup(pool, test_targets), ",", &iter);
+ while (token)
+ {
+ APR_ARRAY_PUSH(targets, const char *) =
+ svn_path_internal_style(token, pool);
+ token = apr_strtok(NULL, ",", &iter);
+ };
+
+ /* Call the function */
+ SVN_ERR(condense_targets(&common_path, &condensed_targets, targets,
+ TRUE, pool));
+
+ /* Verify the common part with the expected (prefix with cwd). */
+ if (*exp_common == '%')
+ exp_common_abs = apr_pstrcat(pool, curdir, exp_common + 1, (char *)NULL);
+
+ if (strcmp(common_path, exp_common_abs) != 0)
+ {
+ return svn_error_createf
+ (SVN_ERR_TEST_FAILED, NULL,
+ "%s (test %s) returned %s instead of %s",
+ func_name, title,
+ common_path, exp_common_abs);
+ }
+
+ /* Verify the condensed targets */
+ token = apr_strtok(apr_pstrdup(pool, exp_targets), ",", &iter);
+ for (i = 0; i < condensed_targets->nelts; i++)
+ {
+ const char * target = APR_ARRAY_IDX(condensed_targets, i, const char*);
+ if (token && (*token == '%'))
+ token = apr_pstrcat(pool, curdir, token + 1, (char *)NULL);
+ if (! token ||
+ (target && (strcmp(target, token) != 0)))
+ {
+ return svn_error_createf
+ (SVN_ERR_TEST_FAILED, NULL,
+ "%s (test %s) couldn't find %s in expected targets list",
+ func_name, title,
+ target);
+ }
+ token = apr_strtok(NULL, ",", &iter);
+ }
+
+ /* Now ensure it works without the pbasename */
+ SVN_ERR(condense_targets(&common_path2, NULL, targets, TRUE, pool));
+
+ /* Verify the common part again */
+ if (strcmp(common_path, common_path2) != 0)
+ {
+ return svn_error_createf
+ (SVN_ERR_TEST_FAILED, NULL,
+ "%s (test %s): Common path without getting targets %s does not match" \
+ "common path with targets %s",
+ func_name, title,
+ common_path2, common_path);
+ }
+
+ return SVN_NO_ERROR;
+}
+
+
+static svn_error_t *
+test_path_condense_targets(apr_pool_t *pool)
+{
+ int i;
+ struct {
+ const char* title;
+ const char* targets;
+ const char* exp_common;
+ const char* exp_targets;
+ } tests[] = {
+ { "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",
+ "%/z", "A,D,G" },
+ {"identical dirs", "z/A,z/A,z/A,z/A",
+ "%/z/A", "" },
+ {"identical files", "z/A/file,z/A/file,z/A/file,z/A/file",
+ "%/z/A/file", "" },
+ {"single dir", "z/A",
+ "%/z/A", "" },
+ {"single file", "z/A/file",
+ "%/z/A/file", "" },
+ {"URLs", "http://host/A/C,http://host/A/C/D,http://host/A/B/D",
+ "http://host/A", "C,B/D" },
+ {"URLs with no common prefix",
+ "http://host1/A/C,http://host2/A/C/D,http://host3/A/B/D",
+ "", "http://host1/A/C,http://host2/A/C/D,http://host3/A/B/D" },
+ {"file URLs with no common prefix", "file:///A/C,file:///B/D",
+ "", "file:///A/C,file:///B/D" },
+ {"URLs with mixed protocols",
+ "http://host/A/C,file:///B/D,gopher://host/A",
+ "", "http://host/A/C,file:///B/D,gopher://host/A" },
+ {"mixed paths and URLs",
+ "z/A/B,z/A,http://host/A/C/D,http://host/A/C",
+ "", "%/z/A,http://host/A/C" },
+ };
+
+ for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
+ {
+ SVN_ERR(condense_targets_tests_helper(tests[i].title,
+ tests[i].targets,
+ tests[i].exp_common,
+ tests[i].exp_targets,
+ "svn_path_condense_targets",
+ svn_path_condense_targets,
+ pool));
+ }
+
+ return SVN_NO_ERROR;
+}
+
+
/* local define to support XFail-ing tests on Windows/Cygwin only */
#ifdef SVN_USE_DOS_PATHS
#define WINDOWS_OR_CYGWIN TRUE
@@ -1526,5 +1687,7 @@ struct svn_test_descriptor_t test_funcs[
"test svn_path_local_style"),
SVN_TEST_PASS2(test_path_internal_style,
"test svn_path_internal_style"),
+ SVN_TEST_PASS2(test_path_condense_targets,
+ "test svn_path_condense_targets"),
SVN_TEST_NULL
};