diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-08-05 16:22:51 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-08-05 16:22:51 +0000 |
commit | cf46733632c7279a9fd0fe6ce26f9185a4ae82a9 (patch) | |
tree | da27775a2161723ef342e91af41a8b51fedef405 /subversion/tests/svn_test.h | |
parent | bb0ef45f7c46b0ae221b26265ef98a768c33f820 (diff) | |
download | subversion-tarball-master.tar.gz |
subversion-1.9.7HEADsubversion-1.9.7master
Diffstat (limited to 'subversion/tests/svn_test.h')
-rw-r--r-- | subversion/tests/svn_test.h | 148 |
1 files changed, 140 insertions, 8 deletions
diff --git a/subversion/tests/svn_test.h b/subversion/tests/svn_test.h index ab3a204..23e002e 100644 --- a/subversion/tests/svn_test.h +++ b/subversion/tests/svn_test.h @@ -27,6 +27,8 @@ #define SVN_DEPRECATED #endif /* ! SVN_ENABLE_DEPRECATION_WARNINGS_IN_TESTS */ +#include <stdio.h> + #include <apr_pools.h> #include "svn_delta.h" @@ -34,6 +36,7 @@ #include "svn_types.h" #include "svn_error.h" #include "svn_string.h" +#include "svn_auth.h" #ifdef __cplusplus extern "C" { @@ -53,6 +56,23 @@ extern "C" { #expr, __FILE__, __LINE__); \ } while (0) +/** + * Macro for testing assumptions when the context does not allow + * returning an svn_error_t*. + * + * Will write to stderr and cause a segfault if EXPR is false. + */ +#define SVN_TEST_ASSERT_NO_RETURN(expr) \ + do { \ + if (!(expr)) \ + { \ + unsigned int z_e_r_o_p_a_g_e__; \ + fprintf(stderr, "TEST ASSERTION FAILED: %s\n", #expr); \ + z_e_r_o_p_a_g_e__ = *(volatile unsigned int*)0; \ + *(volatile unsigned int*)0 = z_e_r_o_p_a_g_e__; \ + } \ + } while (0) + /** Handy macro for testing an expected svn_error_t return value. * EXPECTED must be a real error (neither SVN_NO_ERROR nor APR_SUCCESS). * The error returned by EXPR will be cleared. @@ -63,12 +83,13 @@ extern "C" { SVN_ERR_ASSERT((expected)); \ if (err__ == SVN_NO_ERROR || err__->apr_err != (expected)) \ return err__ ? svn_error_createf(SVN_ERR_TEST_FAILED, err__, \ - "Expected error %d but got %d", \ - (expected), \ - err__->apr_err) \ + "Expected error %s but got %s", \ + svn_error_symbolic_name(expected), \ + svn_error_symbolic_name( \ + err__->apr_err)) \ : svn_error_createf(SVN_ERR_TEST_FAILED, err__, \ - "Expected error %d but got %s", \ - (expected), \ + "Expected error %s but got %s", \ + svn_error_symbolic_name(expected), \ "SVN_NO_ERROR"); \ svn_error_clear(err__); \ } while (0) @@ -77,7 +98,7 @@ extern "C" { * The result must be neither SVN_NO_ERROR nor SVN_ERR_ASSERTION_FAIL. * The error returned by EXPR will be cleared. */ -#define SVN_TEST__ASSERT_ANY_ERROR(expr) \ +#define SVN_TEST_ASSERT_ANY_ERROR(expr) \ do { \ svn_error_t *err__ = (expr); \ if (err__ == SVN_NO_ERROR || err__->apr_err == SVN_ERR_ASSERTION_FAIL)\ @@ -110,21 +131,46 @@ extern "C" { tst_str2, tst_str1, __FILE__, __LINE__); \ } while(0) + /** Handy macro for testing integer equality. + */ +#define SVN_TEST_INT_ASSERT(expr, expected_expr) \ + do { \ + apr_int64_t tst_int1 = (expr); \ + apr_int64_t tst_int2 = (expected_expr); \ + \ + if (tst_int1 != tst_int2) \ + return svn_error_createf(SVN_ERR_TEST_FAILED, NULL, \ + "Integers not equal\n" \ + " Expected: %" APR_INT64_T_FMT "\n" \ + " Found: %" APR_INT64_T_FMT "\n" \ + "\n at %s:%d", \ + tst_int2, tst_int1, __FILE__, __LINE__); \ + } while(0) + /* Baton for any arguments that need to be passed from main() to svn * test functions. */ typedef struct svn_test_opts_t { + /* The name of the application (to generate unique names) */ + const char *prog_name; /* Description of the fs backend that should be used for testing. */ const char *fs_type; /* Config file. */ const char *config_file; /* Source dir. */ const char *srcdir; + /* Repository dir: temporary directory to create repositories in as subdir */ + const char *repos_dir; + /* Repository url: The url to access REPOS_DIR as */ + const char *repos_url; + /* Repository template: pre-created repository to copy for tests */ + const char *repos_template; /* Minor version to use for servers and FS backends, or zero to use the current latest version. */ int server_minor_version; + svn_boolean_t verbose; /* Add future "arguments" here. */ } svn_test_opts_t; @@ -135,6 +181,11 @@ typedef svn_error_t* (*svn_test_driver2_t)(apr_pool_t *pool); typedef svn_error_t* (*svn_test_driver_opts_t)(const svn_test_opts_t *opts, apr_pool_t *pool); +/* Prototype for test predicate functions. */ +typedef svn_boolean_t (*svn_test_predicate_func_t)(const svn_test_opts_t *opts, + const char *predicate_value, + apr_pool_t *pool); + /* Test modes. */ enum svn_test_mode_t { @@ -144,6 +195,23 @@ enum svn_test_mode_t svn_test_all }; +/* Structure for runtime test predicates. */ +struct svn_test_predicate_t +{ + /* The predicate function. */ + svn_test_predicate_func_t func; + + /* The value that the predicate function tests. */ + const char *value; + + /* The test mode that's used if the predicate matches. */ + enum svn_test_mode_t alternate_mode; + + /* Description for the test log */ + const char *description; +}; + + /* Each test gets a test descriptor, holding the function and other * associated data. */ @@ -163,12 +231,29 @@ struct svn_test_descriptor_t /* An optional description of a work-in-progress test. */ const char *wip; + + /* An optional runtiume predicate. */ + struct svn_test_predicate_t predicate; }; /* All Subversion test programs include an array of svn_test_descriptor_t's * (all of our sub-tests) that begins and ends with a SVN_TEST_NULL entry. + * This descriptor must be passed to the svn_test_main function. + * + * MAX_THREADS is the number of concurrent tests to run. Set to 1 if + * all tests must be executed serially. Numbers less than 1 mean + * "unbounded". */ -extern struct svn_test_descriptor_t test_funcs[]; +int svn_test_main(int argc, const char *argv[], int max_threads, + struct svn_test_descriptor_t *test_funcs); + +/* Boilerplate for the main function for each test program. */ +#define SVN_TEST_MAIN \ + int main(int argc, const char *argv[]) \ + { \ + return svn_test_main(argc, argv, \ + max_threads, test_funcs); \ + } /* A null initializer for the test descriptor. */ #define SVN_TEST_NULL {0} @@ -192,6 +277,8 @@ extern struct svn_test_descriptor_t test_funcs[]; #define SVN_TEST_OPTS_XFAIL(func, msg) {svn_test_xfail, NULL, func, msg} #define SVN_TEST_OPTS_XFAIL_COND(func, p, msg) \ {(p) ? svn_test_xfail : svn_test_pass, NULL, func, msg} +#define SVN_TEST_OPTS_XFAIL_OTOH(func, msg, predicate) \ + {svn_test_xfail, NULL, func, msg, NULL, predicate} #define SVN_TEST_OPTS_SKIP(func, p, msg) \ {(p) ? svn_test_skip : svn_test_pass, NULL, func, msg} @@ -205,7 +292,6 @@ extern struct svn_test_descriptor_t test_funcs[]; #define SVN_TEST_OPTS_WIMP_COND(func, p, msg, wip) \ {(p) ? svn_test_xfail : svn_test_pass, NULL, func, msg, wip} - /* Return a pseudo-random number based on SEED, and modify SEED. * @@ -240,6 +326,52 @@ svn_test__tree_t; extern const svn_test__tree_entry_t svn_test__greek_tree_nodes[21]; +/* Returns a path to BASENAME within the transient data area for the + current test. */ +const char * +svn_test_data_path(const char* basename, apr_pool_t *result_pool); + + +/* Some tests require the --srcdir option and should use this function + * to get it. If not provided, print a warning and attempt to run the + * tests under the assumption that --srcdir is the current directory. */ +svn_error_t * +svn_test_get_srcdir(const char **srcdir, + const svn_test_opts_t *opts, + apr_pool_t *pool); + +/* Initializes a standard auth baton for accessing the repositories */ +svn_error_t * +svn_test__init_auth_baton(svn_auth_baton_t **baton, + apr_pool_t *result_pool); + + +/* + * Test predicates + */ + +#define SVN_TEST_PASS_IF_FS_TYPE_IS(fs_type) \ + { svn_test__fs_type_is, fs_type, svn_test_pass, \ + "PASS if fs-type = " fs_type } + +#define SVN_TEST_PASS_IF_FS_TYPE_IS_NOT(fs_type) \ + { svn_test__fs_type_not, fs_type, svn_test_pass, \ + "PASS if fs-type != " fs_type } + +/* Return TRUE if the fs-type in OPTS matches PREDICATE_VALUE. */ +svn_boolean_t +svn_test__fs_type_is(const svn_test_opts_t *opts, + const char *predicate_value, + apr_pool_t *pool); + + +/* Return TRUE if the fs-type in OPTS does not matches PREDICATE_VALUE. */ +svn_boolean_t +svn_test__fs_type_not(const svn_test_opts_t *opts, + const char *predicate_value, + apr_pool_t *pool); + + #ifdef __cplusplus } #endif /* __cplusplus */ |