Skip to content
Snippets Groups Projects
Commit 26436fb1 authored by Nick Mathewson's avatar Nick Mathewson :game_die:
Browse files

Add more unit tests for confparse.c, so we can refactor.

This set of tests gets the line coverage to 100%.
parent fe9d15cf
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,7 @@
* specified, and a linked list of key-value pairs.
*/
#define CONFPARSE_PRIVATE
#include "core/or/or.h"
#include "app/config/confparse.h"
#include "feature/nodelist/routerset.h"
......@@ -87,7 +88,7 @@ const char *
config_find_deprecation(const config_format_t *fmt, const char *key)
{
if (BUG(fmt == NULL) || BUG(key == NULL))
return NULL;
return NULL; // LCOV_EXCL_LINE
if (fmt->deprecations == NULL)
return NULL;
......@@ -352,9 +353,11 @@ config_assign_value(const config_format_t *fmt, void *options,
tor_asprintf(msg,
"You may not provide a value for virtual option '%s'", c->key);
return -1;
// LCOV_EXCL_START
default:
tor_assert(0);
tor_assert_unreached();
break;
// LCOV_EXCL_STOP
}
return 0;
}
......@@ -455,7 +458,9 @@ config_assign_line(const config_format_t *fmt, void *options,
}
return 0;
} else if (c->command == CONFIG_LINE_CLEAR && !clear_first) {
config_reset(fmt, options, var, use_defaults);
// XXXX This is unreachable, since a CLEAR line always has an
// XXXX empty value.
config_reset(fmt, options, var, use_defaults); // LCOV_EXCL_LINE
}
if (options_seen && (var->type != CONFIG_TYPE_LINELIST &&
......@@ -477,7 +482,7 @@ config_assign_line(const config_format_t *fmt, void *options,
/** Restore the option named <b>key</b> in options to its default value.
* Called from config_assign(). */
static void
STATIC void
config_reset_line(const config_format_t *fmt, void *options,
const char *key, int use_defaults)
{
......@@ -625,12 +630,14 @@ config_get_assigned_option(const config_format_t *fmt, const void *options,
tor_free(result);
result = config_lines_dup(*(const config_line_t**)value);
break;
// LCOV_EXCL_START
default:
tor_free(result->key);
tor_free(result);
log_warn(LD_BUG,"Unknown type %d for known key '%s'",
var->type, key);
return NULL;
// LCOV_EXCL_STOP
}
if (escape_val) {
......@@ -829,8 +836,10 @@ config_reset(const config_format_t *fmt, void *options,
c->key = tor_strdup(var->name);
c->value = tor_strdup(var->initvalue);
if (config_assign_value(fmt, options, c, &msg) < 0) {
// LCOV_EXCL_START
log_warn(LD_BUG, "Failed to assign default: %s", msg);
tor_free(msg); /* if this happens it's a bug */
// LCOV_EXCL_STOP
}
config_free_lines(c);
}
......@@ -896,10 +905,12 @@ config_dup(const config_format_t *fmt, const void *old)
if (line) {
char *msg = NULL;
if (config_assign(fmt, newopts, line, 0, &msg) < 0) {
// LCOV_EXCL_START
log_err(LD_BUG, "config_get_assigned_option() generated "
"something we couldn't config_assign(): %s", msg);
tor_free(msg);
tor_assert(0);
// LCOV_EXCL_STOP
}
}
config_free_lines(line);
......@@ -948,9 +959,11 @@ config_dump(const config_format_t *fmt, const void *default_options,
/* XXX use a 1 here so we don't add a new log line while dumping */
if (default_options == NULL) {
if (fmt->validate_fn(NULL, defaults_tmp, defaults_tmp, 1, &msg) < 0) {
// LCOV_EXCL_START
log_err(LD_BUG, "Failed to validate default config: %s", msg);
tor_free(msg);
tor_assert(0);
// LCOV_EXCL_STOP
}
}
......
......@@ -228,4 +228,9 @@ void warn_deprecated_option(const char *what, const char *why);
#define CFG_EQ_LINELIST(a,b,opt) config_lines_eq((a)->opt, (b)->opt)
#define CFG_EQ_ROUTERSET(a,b,opt) routerset_equal((a)->opt, (b)->opt)
#ifdef CONFPARSE_PRIVATE
STATIC void config_reset_line(const config_format_t *fmt, void *options,
const char *key, int use_defaults);
#endif
#endif /* !defined(TOR_CONFPARSE_H) */
......@@ -120,6 +120,7 @@ src_test_test_SOURCES += \
src/test/test_circuitstats.c \
src/test/test_compat_libevent.c \
src/test/test_config.c \
src/test/test_confparse.c \
src/test/test_connection.c \
src/test/test_conscache.c \
src/test/test_consdiff.c \
......
......@@ -840,6 +840,7 @@ struct testgroup_t testgroups[] = {
{ "circuituse/", circuituse_tests },
{ "compat/libevent/", compat_libevent_tests },
{ "config/", config_tests },
{ "config/parse/", confparse_tests },
{ "connection/", connection_tests },
{ "conscache/", conscache_tests },
{ "consdiff/", consdiff_tests },
......
......@@ -197,6 +197,7 @@ extern struct testcase_t circuitstats_tests[];
extern struct testcase_t circuituse_tests[];
extern struct testcase_t compat_libevent_tests[];
extern struct testcase_t config_tests[];
extern struct testcase_t confparse_tests[];
extern struct testcase_t connection_tests[];
extern struct testcase_t conscache_tests[];
extern struct testcase_t consdiff_tests[];
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment