config: add unit test for config_clone()

We’re mainly interested in seeing that we don’t leak memory, or double
free heap allocated data.

Valgrind and/or gcc/clang sanitizers are best at this, hence the very
few asserts in the test itself.
This commit is contained in:
Daniel Eklöf 2021-06-30 21:06:21 +02:00
parent 88fb8429b0
commit 55bd3cfd62
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -3140,6 +3140,27 @@ config_clone(const struct config *old)
return conf;
}
UNITTEST
{
struct config original;
user_notifications_t nots = tll_init();
config_override_t overrides = tll_init();
bool ret = config_load(&original, "/dev/null", &nots, &overrides, false);
xassert(ret);
struct config *clone = config_clone(&original);
xassert(clone != NULL);
xassert(clone != &original);
config_free(original);
config_free(*clone);
free(clone);
tll_free(overrides);
tll_free(nots);
}
void
config_free(struct config conf)
{