summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorteor (Tim Wilson-Brown) <teor2345@gmail.com>2016-01-29 08:15:14 +1100
committerteor (Tim Wilson-Brown) <teor2345@gmail.com>2016-02-01 09:11:16 +1100
commit26f68a771c2d3df12d0dce20f37ee6549e16c920 (patch)
tree119cd371fe8c18f29f70e2f2d9cb4beaf76e6a99 /src/test
parent13db39b8563b42cdf47b1feb546d33217c30c824 (diff)
downloadtor-26f68a771c2d3df12d0dce20f37ee6549e16c920.tar.gz
tor-26f68a771c2d3df12d0dce20f37ee6549e16c920.zip
Report malformed options in options_validate unit tests
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test_options.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/src/test/test_options.c b/src/test/test_options.c
index 35f9f676eb..eb2d3326fa 100644
--- a/src/test/test_options.c
+++ b/src/test/test_options.c
@@ -339,22 +339,47 @@ typedef struct {
or_options_t *def_opt;
} options_test_data_t;
+static void free_options_test_data(options_test_data_t *td);
+
static options_test_data_t *
get_options_test_data(const char *conf)
{
+ int rv = -1;
+ char *msg = NULL;
config_line_t *cl=NULL;
options_test_data_t *result = tor_malloc(sizeof(options_test_data_t));
result->opt = options_new();
result->old_opt = options_new();
result->def_opt = options_new();
- config_get_lines(conf, &cl, 1);
- config_assign(&options_format, result->opt, cl, 0, 0, NULL);
+ rv = config_get_lines(conf, &cl, 1);
+ tt_assert(rv == 0);
+ rv = config_assign(&options_format, result->opt, cl, 0, 0, &msg);
+ if (msg) {
+ /* Display the parse error message by comparing it with an empty string */
+ tt_str_op(msg, OP_EQ, "");
+ }
+ tt_assert(rv == 0);
config_free_lines(cl);
result->opt->LogTimeGranularity = 1;
result->opt->TokenBucketRefillInterval = 1;
- config_get_lines(TEST_OPTIONS_OLD_VALUES, &cl, 1);
- config_assign(&options_format, result->def_opt, cl, 0, 0, NULL);
+ rv = config_get_lines(TEST_OPTIONS_OLD_VALUES, &cl, 1);
+ tt_assert(rv == 0);
+ rv = config_assign(&options_format, result->def_opt, cl, 0, 0, &msg);
+ if (msg) {
+ /* Display the parse error message by comparing it with an empty string */
+ tt_str_op(msg, OP_EQ, "");
+ }
+ tt_assert(rv == 0);
+
+done:
config_free_lines(cl);
+ if (rv != 0) {
+ free_options_test_data(result);
+ result = NULL;
+ /* Callers expect a non-NULL result, so just die if we can't provide one.
+ */
+ tor_assert(0);
+ }
return result;
}