Fix compiler warning due to missing function prototype.
[svn.git] / subversion / tests / libsvn_subr / config-test.c
blob9d23af21ed5fb304397f7337985b598517cb3f39
1 /*
2 * config-test.c: tests svn_config
4 * ====================================================================
5 * Copyright (c) 2000-2004 CollabNet. All rights reserved.
7 * This software is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at http://subversion.tigris.org/license-1.html.
10 * If newer versions of this license are posted there, you may use a
11 * newer version instead, at your option.
13 * This software consists of voluntary contributions made by many
14 * individuals. For exact contribution history, see the revision
15 * history and logs, available at http://subversion.tigris.org/.
16 * ====================================================================
19 /* ====================================================================
20 To add tests, look toward the bottom of this file.
26 #include <string.h>
28 #include <apr_getopt.h>
29 #include <apr_pools.h>
31 #include "svn_error.h"
32 #include "svn_config.h"
34 #include "../svn_test.h"
37 /* Initialize parameters for the tests. */
38 extern int test_argc;
39 extern const char **test_argv;
41 static const apr_getopt_option_t opt_def[] =
43 {"srcdir", 'S', 1, "the source directory for VPATH test runs"},
44 {0, 0, 0, 0}
46 static const char *srcdir = NULL;
48 static svn_error_t *init_params(apr_pool_t *pool)
50 apr_getopt_t *opt;
51 int optch;
52 const char *opt_arg;
53 apr_status_t status;
55 apr_getopt_init(&opt, pool, test_argc, test_argv);
56 while (!(status = apr_getopt_long(opt, opt_def, &optch, &opt_arg)))
58 switch (optch)
60 case 'S':
61 srcdir = opt_arg;
62 break;
66 if (!srcdir)
67 return svn_error_create(SVN_ERR_TEST_FAILED, 0,
68 "missing required parameter '--srcdir'");
70 return SVN_NO_ERROR;
73 /* A quick way to create error messages. */
74 static svn_error_t *
75 fail(apr_pool_t *pool, const char *fmt, ...)
77 va_list ap;
78 char *msg;
80 va_start(ap, fmt);
81 msg = apr_pvsprintf(pool, fmt, ap);
82 va_end(ap);
84 return svn_error_create(SVN_ERR_TEST_FAILED, 0, msg);
88 static const char *config_keys[] = { "foo", "a", "b", "c", "d", "e", "f", "g",
89 "h", "i", NULL };
90 static const char *config_values[] = { "bar", "Aa", "100", "bar",
91 "a %(bogus)s oyster bar",
92 "%(bogus)s shmoo %(",
93 "%Aa", "lyrical bard", "%(unterminated",
94 "Aa 100", NULL };
96 static svn_error_t *
97 test1(const char **msg,
98 svn_boolean_t msg_only,
99 svn_test_opts_t *opts,
100 apr_pool_t *pool)
102 svn_config_t *cfg;
103 int i;
104 const char *cfg_file;
106 *msg = "test svn_config";
108 if (msg_only)
109 return SVN_NO_ERROR;
111 if (!srcdir)
112 SVN_ERR(init_params(pool));
114 cfg_file = apr_pstrcat(pool, srcdir, "/", "config-test.cfg", NULL);
115 SVN_ERR(svn_config_read(&cfg, cfg_file, TRUE, pool));
117 /* Test values retrieved from our ConfigParser instance against
118 values retrieved using svn_config. */
119 for (i = 0; config_keys[i] != NULL; i++)
121 const char *key, *py_val, *c_val;
123 key = config_keys[i];
124 py_val = config_values[i];
125 svn_config_get(cfg, &c_val, "section1", key, "default value");
126 #if 0
127 printf("Testing expected value '%s' against '%s' for "
128 "option '%s'\n", py_val, c_val, key);
129 #endif
130 /* Fail iff one value is null, or the strings don't match. */
131 if ((c_val == NULL) != (py_val == NULL)
132 || (c_val != NULL && py_val != NULL && strcmp(c_val, py_val) != 0))
133 return fail(pool, "Expected value '%s' not equal to '%s' for "
134 "option '%s'", py_val, c_val, key);
136 return SVN_NO_ERROR;
140 static const char *true_keys[] = {"true1", "true2", "true3", "true4",
141 NULL};
142 static const char *false_keys[] = {"false1", "false2", "false3", "false4",
143 NULL};
145 static svn_error_t *
146 test2(const char **msg,
147 svn_boolean_t msg_only,
148 svn_test_opts_t *opts,
149 apr_pool_t *pool)
151 svn_config_t *cfg;
152 int i;
153 const char *cfg_file;
155 *msg = "test svn_config boolean conversion";
157 if (msg_only)
158 return SVN_NO_ERROR;
160 if (!srcdir)
161 SVN_ERR(init_params(pool));
163 cfg_file = apr_pstrcat(pool, srcdir, "/", "config-test.cfg", NULL);
164 SVN_ERR(svn_config_read(&cfg, cfg_file, TRUE, pool));
166 for (i = 0; true_keys[i] != NULL; i++)
168 svn_boolean_t value;
169 SVN_ERR(svn_config_get_bool(cfg, &value, "booleans", true_keys[i],
170 FALSE));
171 if (!value)
172 return fail(pool, "Value of option '%s' is not true", true_keys[i]);
175 for (i = 0; false_keys[i] != NULL; i++)
177 svn_boolean_t value;
178 SVN_ERR(svn_config_get_bool(cfg, &value, "booleans", false_keys[i],
179 TRUE));
180 if (value)
181 return fail(pool, "Value of option '%s' is not true", false_keys[i]);
185 svn_error_t *err;
186 svn_boolean_t value;
188 svn_error_clear((err = svn_config_get_bool(cfg, &value,
189 "booleans", "bad_true",
190 TRUE)));
191 if (!err)
192 return fail(pool, "No error on bad truth value");
194 svn_error_clear((err = svn_config_get_bool(cfg, &value,
195 "booleans", "bad_false",
196 FALSE)));
197 if (!err)
198 return fail(pool, "No error on bad truth value");
201 return SVN_NO_ERROR;
204 static svn_error_t *
205 has_section_test(const char **msg,
206 svn_boolean_t msg_only,
207 svn_test_opts_t *opts,
208 apr_pool_t *pool)
210 svn_config_t *cfg;
211 const char *cfg_file;
213 *msg = "test svn_config_has_section";
215 if (msg_only)
216 return SVN_NO_ERROR;
218 if (!srcdir)
219 SVN_ERR(init_params(pool));
221 cfg_file = apr_pstrcat(pool, srcdir, "/", "config-test.cfg", NULL);
222 SVN_ERR(svn_config_read(&cfg, cfg_file, TRUE, pool));
224 if (! svn_config_has_section(cfg, "section1"))
225 return fail(pool, "Failed to find section1");
227 if (svn_config_has_section(cfg, "notthere"))
228 return fail(pool, "Returned true on missing section");
230 return SVN_NO_ERROR;
234 ====================================================================
235 If you add a new test to this file, update this array.
237 (These globals are required by our included main())
240 /* An array of all test functions */
241 struct svn_test_descriptor_t test_funcs[] =
243 SVN_TEST_NULL,
244 SVN_TEST_PASS(test1),
245 SVN_TEST_PASS(test2),
246 SVN_TEST_PASS(has_section_test),
247 SVN_TEST_NULL