summaryrefslogtreecommitdiffstats
path: root/src/test/test-string-util.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-07-31 15:07:23 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-09-09 09:34:55 +0200
commitd59d954d7f6f5f3772b12e8078875183e0b27889 (patch)
treeb1303e094d07160803c6ed81f698d60d140c92b7 /src/test/test-string-util.c
parentshared/fstab-util: replace FOREACH_WORD_SEPARATOR() with open-coded loop (diff)
downloadsystemd-d59d954d7f6f5f3772b12e8078875183e0b27889.tar.xz
systemd-d59d954d7f6f5f3772b12e8078875183e0b27889.zip
test-string-util: stop testing FOREACH_WORD
Diffstat (limited to '')
-rw-r--r--src/test/test-string-util.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/test/test-string-util.c b/src/test/test-string-util.c
index b39fda0313..196c96aa8c 100644
--- a/src/test/test-string-util.c
+++ b/src/test/test-string-util.c
@@ -396,26 +396,34 @@ static void test_strcmp_ptr(void) {
static void test_foreach_word(void) {
log_info("/* %s */", __func__);
- const char *word, *state;
- size_t l;
- int i = 0;
- const char test[] = "test abc d\te f ";
+ const char *test = "test abc d\te f ";
const char * const expected[] = {
"test",
"abc",
"d",
"e",
"f",
- "",
- NULL
};
- FOREACH_WORD(word, l, test, state)
- assert_se(strneq(expected[i++], word, l));
+ size_t i = 0;
+ int r;
+ for (const char *p = test;;) {
+ _cleanup_free_ char *word = NULL;
+
+ r = extract_first_word(&p, &word, NULL, 0);
+ if (r == 0) {
+ assert_se(i == ELEMENTSOF(expected));
+ break;
+ }
+ assert_se(r > 0);
+
+ assert_se(streq(expected[i++], word));
+ }
}
static void check(const char *test, char** expected, bool trailing) {
- int i = 0, r;
+ size_t i = 0;
+ int r;
printf("<<<%s>>>\n", test);
for (;;) {