diff options
Diffstat (limited to 'subversion/tests/libsvn_subr/config-test.c')
-rw-r--r-- | subversion/tests/libsvn_subr/config-test.c | 168 |
1 files changed, 162 insertions, 6 deletions
diff --git a/subversion/tests/libsvn_subr/config-test.c b/subversion/tests/libsvn_subr/config-test.c index aee56f8..8938457 100644 --- a/subversion/tests/libsvn_subr/config-test.c +++ b/subversion/tests/libsvn_subr/config-test.c @@ -109,7 +109,7 @@ test_text_retrieval(apr_pool_t *pool) SVN_ERR(init_params(pool)); cfg_file = apr_pstrcat(pool, srcdir, "/", "config-test.cfg", (char *)NULL); - SVN_ERR(svn_config_read2(&cfg, cfg_file, TRUE, FALSE, pool)); + SVN_ERR(svn_config_read3(&cfg, cfg_file, TRUE, FALSE, FALSE, pool)); /* Test values retrieved from our ConfigParser instance against values retrieved using svn_config. */ @@ -160,7 +160,7 @@ test_boolean_retrieval(apr_pool_t *pool) SVN_ERR(init_params(pool)); cfg_file = apr_pstrcat(pool, srcdir, "/", "config-test.cfg", (char *)NULL); - SVN_ERR(svn_config_read2(&cfg, cfg_file, TRUE, FALSE, pool)); + SVN_ERR(svn_config_read3(&cfg, cfg_file, TRUE, FALSE, FALSE, pool)); for (i = 0; true_keys[i] != NULL; i++) { @@ -211,7 +211,7 @@ test_boolean_retrieval(apr_pool_t *pool) } static svn_error_t * -test_has_section(apr_pool_t *pool) +test_has_section_case_insensitive(apr_pool_t *pool) { svn_config_t *cfg; const char *cfg_file; @@ -220,17 +220,164 @@ test_has_section(apr_pool_t *pool) SVN_ERR(init_params(pool)); cfg_file = apr_pstrcat(pool, srcdir, "/", "config-test.cfg", (char *)NULL); - SVN_ERR(svn_config_read2(&cfg, cfg_file, TRUE, FALSE, pool)); + SVN_ERR(svn_config_read3(&cfg, cfg_file, TRUE, FALSE, FALSE, pool)); if (! svn_config_has_section(cfg, "section1")) return fail(pool, "Failed to find section1"); + if (! svn_config_has_section(cfg, "SECTION1")) + return fail(pool, "Failed to find SECTION1"); + + if (! svn_config_has_section(cfg, "UpperCaseSection")) + return fail(pool, "Failed to find UpperCaseSection"); + + if (! svn_config_has_section(cfg, "uppercasesection")) + return fail(pool, "Failed to find UpperCaseSection"); + + if (svn_config_has_section(cfg, "notthere")) + return fail(pool, "Returned true on missing section"); + + return SVN_NO_ERROR; +} + +static svn_error_t * +test_has_section_case_sensitive(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(svn_config_read3(&cfg, cfg_file, TRUE, TRUE, FALSE, pool)); + + if (! svn_config_has_section(cfg, "section1")) + return fail(pool, "Failed to find section1"); + + if (svn_config_has_section(cfg, "SECTION1")) + return fail(pool, "Returned true on missing section"); + + if (! svn_config_has_section(cfg, "UpperCaseSection")) + return fail(pool, "Failed to find UpperCaseSection"); + + if (svn_config_has_section(cfg, "uppercasesection")) + return fail(pool, "Returned true on missing section"); + if (svn_config_has_section(cfg, "notthere")) return fail(pool, "Returned true on missing section"); return SVN_NO_ERROR; } +static svn_error_t * +test_has_option_case_sensitive(apr_pool_t *pool) +{ + svn_config_t *cfg; + const char *cfg_file; + apr_int64_t value; + int i; + + static struct test_dataset { + const char *option; + apr_int64_t value; + } const test_data[] = { + { "a", 1 }, + { "A", 2 }, + { "B", 3 }, + { "b", 4 } + }; + 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(svn_config_read3(&cfg, cfg_file, TRUE, TRUE, TRUE, pool)); + + for (i = 0; i < test_data_size; ++i) + { + SVN_ERR(svn_config_get_int64(cfg, &value, "case-sensitive-option", + test_data[i].option, -1)); + if (test_data[i].value != value) + return fail(pool, + apr_psprintf(pool, + "case-sensitive-option.%s != %" + APR_INT64_T_FMT" but %"APR_INT64_T_FMT, + test_data[i].option, + test_data[i].value, + value)); + } + + return SVN_NO_ERROR; +} + +static svn_error_t * +test_stream_interface(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(svn_stream_open_readonly(&stream, cfg_file, pool, pool)); + + SVN_ERR(svn_config_parse(&cfg, stream, TRUE, TRUE, pool)); + + /* nominal test to make sure cfg is populated with something since + * svn_config_parse will happily return an empty cfg if the stream is + * empty. */ + if (! svn_config_has_section(cfg, "section1")) + return fail(pool, "Failed to find section1"); + + return SVN_NO_ERROR; +} + +static svn_error_t * +test_ignore_bom(apr_pool_t *pool) +{ + svn_config_t *cfg; + svn_string_t *cfg_string = svn_string_create("\xEF\xBB\xBF[s1]\nfoo=bar\n", + pool); + svn_stream_t *stream = svn_stream_from_string(cfg_string, pool); + + SVN_ERR(svn_config_parse(&cfg, stream, TRUE, TRUE, pool)); + + if (! svn_config_has_section(cfg, "s1")) + return fail(pool, "failed to find section s1"); + + 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(svn_config_read3(&cfg, cfg_file, TRUE, TRUE, FALSE, pool)); + + /* Get expanded "g" which requires expanding "c". */ + svn_config_get(cfg, &val, "section1", "g", NULL); + + /* Get expanded "c". */ + svn_config_get(cfg, &val, "section1", "c", NULL); + + /* 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; +} + /* ==================================================================== If you add a new test to this file, update this array. @@ -246,7 +393,16 @@ struct svn_test_descriptor_t test_funcs[] = "test svn_config"), SVN_TEST_PASS2(test_boolean_retrieval, "test svn_config boolean conversion"), - SVN_TEST_PASS2(test_has_section, - "test svn_config_has_section"), + 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_expand, + "test variable expansion"), SVN_TEST_NULL }; |