aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-06-30 19:06:21 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-06-30 19:06:21 +0000
commit55bd3cfd623a86044fd028787c216810ee274af7 (patch)
treed5eab7558e4795df69017feb4abffa1d46c11985
parentconfig: NOINLINE a couple of functions doing tll operations (diff)
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.
-rw-r--r--config.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/config.c b/config.c
index 5fd68a2d..372e9f9c 100644
--- a/config.c
+++ b/config.c
@@ -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)
{