From de747a0008876ea06c9bc73fff0f3d6593a9c399 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 29 Apr 2020 08:50:37 +0200 Subject: [PATCH] test-set: make test-set not link to libshared and test test_set_put_strdup*() The sets are such basic functionality that it is convenient to be able to build test-set without all the machinery in shared, and to test it without the mempool to validate memory accesses easier. --- src/test/meson.build | 2 +- src/test/test-set.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/test/meson.build b/src/test/meson.build index b133980e459..318dc25906b 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -470,7 +470,7 @@ tests += [ '', 'timeout=90'], [['src/test/test-set.c'], - [], + [libbasic], []], [['src/test/test-ordered-set.c'], diff --git a/src/test/test-set.c b/src/test/test-set.c index b4e7a52fd96..9c93685dbce 100644 --- a/src/test/test-set.c +++ b/src/test/test-set.c @@ -3,6 +3,8 @@ #include "set.h" #include "strv.h" +const bool mempool_use_allowed = VALGRIND; + static void test_set_steal_first(void) { _cleanup_set_free_ Set *m = NULL; int seen[3] = {}; @@ -86,11 +88,32 @@ static void test_set_put(void) { assert_se(strv_length(t) == 3); } +static void test_set_put_strdup(void) { + _cleanup_set_free_ Set *m = NULL; + + assert_se(set_put_strdup(&m, "aaa") == 1); + assert_se(set_put_strdup(&m, "aaa") == 0); + assert_se(set_put_strdup(&m, "bbb") == 1); + assert_se(set_put_strdup(&m, "bbb") == 0); + assert_se(set_put_strdup(&m, "aaa") == 0); + assert_se(set_size(m) == 2); +} + +static void test_set_put_strdupv(void) { + _cleanup_set_free_ Set *m = NULL; + + assert_se(set_put_strdupv(&m, STRV_MAKE("aaa", "aaa", "bbb", "bbb", "aaa")) == 2); + assert_se(set_put_strdupv(&m, STRV_MAKE("aaa", "aaa", "bbb", "bbb", "ccc")) == 1); + assert_se(set_size(m) == 3); +} + int main(int argc, const char *argv[]) { test_set_steal_first(); test_set_free_with_destructor(); test_set_free_with_hash_ops(); test_set_put(); + test_set_put_strdup(); + test_set_put_strdupv(); return 0; } -- 2.47.3