From 55bd3cfd623a86044fd028787c216810ee274af7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 30 Jun 2021 21:06:21 +0200 Subject: [PATCH] config: add unit test for config_clone() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- config.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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", ¬s, &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) {