]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-set: make test-set not link to libshared and test test_set_put_strdup*()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 29 Apr 2020 06:50:37 +0000 (08:50 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 6 May 2020 14:55:07 +0000 (16:55 +0200)
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
src/test/test-set.c

index b133980e4592f3c47380dbfc227d67119c20ad72..318dc25906be9e1754283e10f376970846253e16 100644 (file)
@@ -470,7 +470,7 @@ tests += [
          '', 'timeout=90'],
 
         [['src/test/test-set.c'],
-         [],
+         [libbasic],
          []],
 
         [['src/test/test-ordered-set.c'],
index b4e7a52fd964aef5713d42283526be2ab18106b3..9c93685dbce975ac1c52069a1ccfd3c6f4b5824d 100644 (file)
@@ -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;
 }