]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/test/test-strv.c
tree-wide: drop license boilerplate
[thirdparty/systemd.git] / src / test / test-strv.c
index f78b1bcd4643baa6056fcd15432ed560c60cbbf3..fa658eb0566c9bf8a5526c84dd50ad9ac5fa6660 100644 (file)
@@ -4,19 +4,6 @@
 
   Copyright 2010 Lennart Poettering
   Copyright 2013 Thomas H.P. Andersen
-
-  systemd is free software; you can redistribute it and/or modify it
-  under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or
-  (at your option) any later version.
-
-  systemd is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
 #include <string.h>
@@ -447,6 +434,36 @@ static void test_strv_from_stdarg_alloca(void) {
         test_strv_from_stdarg_alloca_one(STRV_MAKE_EMPTY, NULL);
 }
 
+static void test_strv_insert(void) {
+        _cleanup_strv_free_ char **a = NULL;
+
+        assert_se(strv_insert(&a, 0, strdup("first")) == 0);
+        assert_se(streq(a[0], "first"));
+        assert_se(!a[1]);
+
+        assert_se(strv_insert(&a, 0, NULL) == 0);
+        assert_se(streq(a[0], "first"));
+        assert_se(!a[1]);
+
+        assert_se(strv_insert(&a, 1, strdup("two")) == 0);
+        assert_se(streq(a[0], "first"));
+        assert_se(streq(a[1], "two"));
+        assert_se(!a[2]);
+
+        assert_se(strv_insert(&a, 4, strdup("tri")) == 0);
+        assert_se(streq(a[0], "first"));
+        assert_se(streq(a[1], "two"));
+        assert_se(streq(a[2], "tri"));
+        assert_se(!a[3]);
+
+        assert_se(strv_insert(&a, 1, strdup("duo")) == 0);
+        assert_se(streq(a[0], "first"));
+        assert_se(streq(a[1], "duo"));
+        assert_se(streq(a[2], "two"));
+        assert_se(streq(a[3], "tri"));
+        assert_se(!a[4]);
+}
+
 static void test_strv_push_prepend(void) {
         _cleanup_strv_free_ char **a = NULL;
 
@@ -646,6 +663,17 @@ static void test_strv_make_nulstr(void) {
         test_strv_make_nulstr_one(STRV_MAKE("foo", "bar", "quuux"));
 }
 
+static void test_strv_free_free(void) {
+        char ***t;
+
+        assert_se(t = new(char**, 3));
+        assert_se(t[0] = strv_new("a", "b", NULL));
+        assert_se(t[1] = strv_new("c", "d", "e", NULL));
+        t[2] = NULL;
+
+        t = strv_free_free(t);
+}
+
 static void test_foreach_string(void) {
         const char * const t[] = {
                 "foo",
@@ -723,6 +751,7 @@ int main(int argc, char *argv[]) {
         test_strv_extend();
         test_strv_extendf();
         test_strv_from_stdarg_alloca();
+        test_strv_insert();
         test_strv_push_prepend();
         test_strv_push();
         test_strv_equal();
@@ -732,6 +761,7 @@ int main(int argc, char *argv[]) {
         test_strv_skip();
         test_strv_extend_n();
         test_strv_make_nulstr();
+        test_strv_free_free();
 
         test_foreach_string();
         test_strv_fnmatch();