]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add another test case for extract_many_words
authorLuca Boccassi <luca.boccassi@microsoft.com>
Tue, 7 Jul 2020 16:10:47 +0000 (17:10 +0100)
committerLuca Boccassi <luca.boccassi@microsoft.com>
Wed, 5 Aug 2020 18:28:55 +0000 (19:28 +0100)
Covers some functionality that we want to use for config tuples

src/test/test-extract-word.c

index 4ca57555f1da419b710294f0ffa082a643502584..43ad1b7d82f99be64fda31d8975667ebdc31338f 100644 (file)
@@ -489,7 +489,7 @@ static void test_extract_first_word_and_warn(void) {
 
 static void test_extract_many_words(void) {
         const char *p, *original;
-        char *a, *b, *c;
+        char *a, *b, *c, *d, *e, *f;
 
         p = original = "foobar waldi piep";
         assert_se(extract_many_words(&p, NULL, 0, &a, &b, &c, NULL) == 3);
@@ -501,6 +501,24 @@ static void test_extract_many_words(void) {
         free(b);
         free(c);
 
+        p = original = "foobar:waldi:piep ba1:ba2";
+        assert_se(extract_many_words(&p, ":" WHITESPACE, 0, &a, &b, &c, NULL) == 3);
+        assert_se(!isempty(p));
+        assert_se(streq_ptr(a, "foobar"));
+        assert_se(streq_ptr(b, "waldi"));
+        assert_se(streq_ptr(c, "piep"));
+        assert_se(extract_many_words(&p, ":" WHITESPACE, 0, &d, &e, &f, NULL) == 2);
+        assert_se(isempty(p));
+        assert_se(streq_ptr(d, "ba1"));
+        assert_se(streq_ptr(e, "ba2"));
+        assert_se(isempty(f));
+        free(a);
+        free(b);
+        free(c);
+        free(d);
+        free(e);
+        free(f);
+
         p = original = "'foobar' wa\"ld\"i   ";
         assert_se(extract_many_words(&p, NULL, 0, &a, &b, &c, NULL) == 2);
         assert_se(isempty(p));