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/libsvn_subr/config-test.c | |
parent | bb0ef45f7c46b0ae221b26265ef98a768c33f820 (diff) | |
download | subversion-tarball-master.tar.gz |
subversion-1.9.7HEADsubversion-1.9.7master
Diffstat (limited to 'subversion/tests/libsvn_subr/config-test.c')
-rw-r--r-- | subversion/tests/libsvn_subr/config-test.c | 193 |
1 files changed, 108 insertions, 85 deletions
diff --git a/subversion/tests/libsvn_subr/config-test.c b/subversion/tests/libsvn_subr/config-test.c index 8938457..919893e 100644 --- a/subversion/tests/libsvn_subr/config-test.c +++ b/subversion/tests/libsvn_subr/config-test.c @@ -33,48 +33,14 @@ #include <apr_getopt.h> #include <apr_pools.h> +#include "svn_dirent_uri.h" #include "svn_error.h" #include "svn_config.h" +#include "private/svn_subr_private.h" #include "../svn_test.h" -/* Initialize parameters for the tests. */ -extern int test_argc; -extern const char **test_argv; - -static const apr_getopt_option_t opt_def[] = - { - {"srcdir", 'S', 1, "the source directory for VPATH test runs"}, - {0, 0, 0, 0} - }; -static const char *srcdir = NULL; - -static svn_error_t *init_params(apr_pool_t *pool) -{ - apr_getopt_t *opt; - int optch; - const char *opt_arg; - apr_status_t status; - - apr_getopt_init(&opt, pool, test_argc, test_argv); - while (!(status = apr_getopt_long(opt, opt_def, &optch, &opt_arg))) - { - switch (optch) - { - case 'S': - srcdir = opt_arg; - break; - } - } - - if (!srcdir) - return svn_error_create(SVN_ERR_TEST_FAILED, 0, - "missing required parameter '--srcdir'"); - - return SVN_NO_ERROR; -} - /* A quick way to create error messages. */ static svn_error_t * fail(apr_pool_t *pool, const char *fmt, ...) @@ -89,6 +55,18 @@ fail(apr_pool_t *pool, const char *fmt, ...) return svn_error_create(SVN_ERR_TEST_FAILED, SVN_NO_ERROR, msg); } +static svn_error_t * +get_config_file_path(const char **cfg_file, + const svn_test_opts_t *opts, + apr_pool_t *pool) +{ + const char *srcdir; + + SVN_ERR(svn_test_get_srcdir(&srcdir, opts, pool)); + *cfg_file = svn_dirent_join(srcdir, "config-test.cfg", pool); + + return SVN_NO_ERROR; +} static const char *config_keys[] = { "foo", "a", "b", "c", "d", "e", "f", "g", "h", "i", NULL }; @@ -99,16 +77,14 @@ static const char *config_values[] = { "bar", "Aa", "100", "bar", "Aa 100", NULL }; static svn_error_t * -test_text_retrieval(apr_pool_t *pool) +test_text_retrieval(const svn_test_opts_t *opts, + apr_pool_t *pool) { svn_config_t *cfg; int i; const char *cfg_file; - if (!srcdir) - SVN_ERR(init_params(pool)); - - cfg_file = apr_pstrcat(pool, srcdir, "/", "config-test.cfg", (char *)NULL); + SVN_ERR(get_config_file_path(&cfg_file, opts, pool)); SVN_ERR(svn_config_read3(&cfg, cfg_file, TRUE, FALSE, FALSE, pool)); /* Test values retrieved from our ConfigParser instance against @@ -150,16 +126,14 @@ static const char *false_keys[] = {"false1", "false2", "false3", "false4", NULL}; static svn_error_t * -test_boolean_retrieval(apr_pool_t *pool) +test_boolean_retrieval(const svn_test_opts_t *opts, + apr_pool_t *pool) { svn_config_t *cfg; int i; const char *cfg_file; - if (!srcdir) - SVN_ERR(init_params(pool)); - - cfg_file = apr_pstrcat(pool, srcdir, "/", "config-test.cfg", (char *)NULL); + SVN_ERR(get_config_file_path(&cfg_file, opts, pool)); SVN_ERR(svn_config_read3(&cfg, cfg_file, TRUE, FALSE, FALSE, pool)); for (i = 0; true_keys[i] != NULL; i++) @@ -211,15 +185,13 @@ test_boolean_retrieval(apr_pool_t *pool) } static svn_error_t * -test_has_section_case_insensitive(apr_pool_t *pool) +test_has_section_case_insensitive(const svn_test_opts_t *opts, + apr_pool_t *pool) { svn_config_t *cfg; const char *cfg_file; - if (!srcdir) - SVN_ERR(init_params(pool)); - - cfg_file = apr_pstrcat(pool, srcdir, "/", "config-test.cfg", (char *)NULL); + SVN_ERR(get_config_file_path(&cfg_file, opts, pool)); SVN_ERR(svn_config_read3(&cfg, cfg_file, TRUE, FALSE, FALSE, pool)); if (! svn_config_has_section(cfg, "section1")) @@ -241,15 +213,13 @@ test_has_section_case_insensitive(apr_pool_t *pool) } static svn_error_t * -test_has_section_case_sensitive(apr_pool_t *pool) +test_has_section_case_sensitive(const svn_test_opts_t *opts, + apr_pool_t *pool) { svn_config_t *cfg; const char *cfg_file; - if (!srcdir) - SVN_ERR(init_params(pool)); - - cfg_file = apr_pstrcat(pool, srcdir, "/", "config-test.cfg", (char *)NULL); + SVN_ERR(get_config_file_path(&cfg_file, opts, pool)); SVN_ERR(svn_config_read3(&cfg, cfg_file, TRUE, TRUE, FALSE, pool)); if (! svn_config_has_section(cfg, "section1")) @@ -271,7 +241,8 @@ test_has_section_case_sensitive(apr_pool_t *pool) } static svn_error_t * -test_has_option_case_sensitive(apr_pool_t *pool) +test_has_option_case_sensitive(const svn_test_opts_t *opts, + apr_pool_t *pool) { svn_config_t *cfg; const char *cfg_file; @@ -289,10 +260,7 @@ test_has_option_case_sensitive(apr_pool_t *pool) }; static const int test_data_size = sizeof(test_data)/sizeof(*test_data); - if (!srcdir) - SVN_ERR(init_params(pool)); - - cfg_file = apr_pstrcat(pool, srcdir, "/", "config-test.cfg", (char *)NULL); + SVN_ERR(get_config_file_path(&cfg_file, opts, pool)); SVN_ERR(svn_config_read3(&cfg, cfg_file, TRUE, TRUE, TRUE, pool)); for (i = 0; i < test_data_size; ++i) @@ -313,16 +281,14 @@ test_has_option_case_sensitive(apr_pool_t *pool) } static svn_error_t * -test_stream_interface(apr_pool_t *pool) +test_stream_interface(const svn_test_opts_t *opts, + apr_pool_t *pool) { svn_config_t *cfg; const char *cfg_file; svn_stream_t *stream; - if (!srcdir) - SVN_ERR(init_params(pool)); - - cfg_file = apr_pstrcat(pool, srcdir, "/", "config-test.cfg", (char *)NULL); + SVN_ERR(get_config_file_path(&cfg_file, opts, pool)); SVN_ERR(svn_stream_open_readonly(&stream, cfg_file, pool, pool)); SVN_ERR(svn_config_parse(&cfg, stream, TRUE, TRUE, pool)); @@ -353,16 +319,42 @@ test_ignore_bom(apr_pool_t *pool) } static svn_error_t * +test_read_only_mode(const svn_test_opts_t *opts, + apr_pool_t *pool) +{ + svn_config_t *cfg; + svn_config_t *cfg2; + const char *cfg_file; + + SVN_ERR(get_config_file_path(&cfg_file, opts, pool)); + SVN_ERR(svn_config_read3(&cfg, cfg_file, TRUE, TRUE, FALSE, pool)); + + /* setting CFG to r/o mode shall toggle the r/o mode and expand values */ + + SVN_TEST_ASSERT(!svn_config__is_read_only(cfg)); + SVN_TEST_ASSERT(!svn_config__is_expanded(cfg, "section1", "i")); + + svn_config__set_read_only(cfg, pool); + + SVN_TEST_ASSERT(svn_config__is_read_only(cfg)); + SVN_TEST_ASSERT(svn_config__is_expanded(cfg, "section1", "i")); + + /* copies should be r/w with values */ + + SVN_ERR(svn_config_dup(&cfg2, cfg, pool)); + SVN_TEST_ASSERT(!svn_config__is_read_only(cfg2)); + + return SVN_NO_ERROR; +} + +static svn_error_t * test_expand(const svn_test_opts_t *opts, apr_pool_t *pool) { svn_config_t *cfg; const char *cfg_file, *val; - if (!srcdir) - SVN_ERR(init_params(pool)); - - cfg_file = apr_pstrcat(pool, srcdir, "/", "config-test.cfg", (char *)NULL); + SVN_ERR(get_config_file_path(&cfg_file, opts, pool)); SVN_ERR(svn_config_read3(&cfg, cfg_file, TRUE, TRUE, FALSE, pool)); /* Get expanded "g" which requires expanding "c". */ @@ -371,13 +363,34 @@ test_expand(const svn_test_opts_t *opts, /* Get expanded "c". */ svn_config_get(cfg, &val, "section1", "c", NULL); - /* With pool debugging enabled this ensures that the expanded value + /* With pool debugging enabled this ensures that the expanded value of "c" was not created in a temporary pool when expanding "g". */ SVN_TEST_STRING_ASSERT(val, "bar"); return SVN_NO_ERROR; } +static svn_error_t * +test_invalid_bom(apr_pool_t *pool) +{ + svn_config_t *cfg; + svn_error_t *err; + svn_string_t *cfg_string; + svn_stream_t *stream; + + cfg_string = svn_string_create("\xEF", pool); + stream = svn_stream_from_string(cfg_string, pool); + err = svn_config_parse(&cfg, stream, TRUE, TRUE, pool); + SVN_TEST_ASSERT_ERROR(err, SVN_ERR_MALFORMED_FILE); + + cfg_string = svn_string_create("\xEF\xBB", pool); + stream = svn_stream_from_string(cfg_string, pool); + err = svn_config_parse(&cfg, stream, TRUE, TRUE, pool); + SVN_TEST_ASSERT_ERROR(err, SVN_ERR_MALFORMED_FILE); + + return SVN_NO_ERROR; +} + /* ==================================================================== If you add a new test to this file, update this array. @@ -386,23 +399,33 @@ test_expand(const svn_test_opts_t *opts, */ /* An array of all test functions */ -struct svn_test_descriptor_t test_funcs[] = + +static int max_threads = 1; + +static struct svn_test_descriptor_t test_funcs[] = { SVN_TEST_NULL, - SVN_TEST_PASS2(test_text_retrieval, - "test svn_config"), - SVN_TEST_PASS2(test_boolean_retrieval, - "test svn_config boolean conversion"), - SVN_TEST_PASS2(test_has_section_case_insensitive, - "test svn_config_has_section (case insensitive)"), - SVN_TEST_PASS2(test_has_section_case_sensitive, - "test svn_config_has_section (case sensitive)"), - SVN_TEST_PASS2(test_has_option_case_sensitive, - "test case-sensitive option name lookup"), - SVN_TEST_PASS2(test_stream_interface, - "test svn_config_parse"), - SVN_TEST_PASS2(test_ignore_bom, "test parsing config file with BOM"), + SVN_TEST_OPTS_PASS(test_text_retrieval, + "test svn_config"), + SVN_TEST_OPTS_PASS(test_boolean_retrieval, + "test svn_config boolean conversion"), + SVN_TEST_OPTS_PASS(test_has_section_case_insensitive, + "test svn_config_has_section (case insensitive)"), + SVN_TEST_OPTS_PASS(test_has_section_case_sensitive, + "test svn_config_has_section (case sensitive)"), + SVN_TEST_OPTS_PASS(test_has_option_case_sensitive, + "test case-sensitive option name lookup"), + SVN_TEST_OPTS_PASS(test_stream_interface, + "test svn_config_parse"), + SVN_TEST_PASS2(test_ignore_bom, + "test parsing config file with BOM"), + SVN_TEST_OPTS_PASS(test_read_only_mode, + "test r/o mode"), SVN_TEST_OPTS_PASS(test_expand, "test variable expansion"), + SVN_TEST_PASS2(test_invalid_bom, + "test parsing config file with invalid BOM"), SVN_TEST_NULL }; + +SVN_TEST_MAIN |