]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-strv.c
Merge pull request #2794 from jhol/dont-unmount-initramfs-mounts
[thirdparty/systemd.git] / src / test / test-strv.c
1 /***
2 This file is part of systemd.
3
4 Copyright 2010 Lennart Poettering
5 Copyright 2013 Thomas H.P. Andersen
6
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19 ***/
20
21 #include <string.h>
22
23 #include "alloc-util.h"
24 #include "specifier.h"
25 #include "string-util.h"
26 #include "strv.h"
27 #include "util.h"
28
29 static void test_specifier_printf(void) {
30 static const Specifier table[] = {
31 { 'a', specifier_string, (char*) "AAAA" },
32 { 'b', specifier_string, (char*) "BBBB" },
33 { 'm', specifier_machine_id, NULL },
34 { 'B', specifier_boot_id, NULL },
35 { 'H', specifier_host_name, NULL },
36 { 'v', specifier_kernel_release, NULL },
37 {}
38 };
39
40 _cleanup_free_ char *w = NULL;
41 int r;
42
43 r = specifier_printf("xxx a=%a b=%b yyy", table, NULL, &w);
44 assert_se(r >= 0);
45 assert_se(w);
46
47 puts(w);
48 assert_se(streq(w, "xxx a=AAAA b=BBBB yyy"));
49
50 free(w);
51 r = specifier_printf("machine=%m, boot=%B, host=%H, version=%v", table, NULL, &w);
52 assert_se(r >= 0);
53 assert_se(w);
54 puts(w);
55 }
56
57 static const char* const input_table_multiple[] = {
58 "one",
59 "two",
60 "three",
61 NULL,
62 };
63
64 static const char* const input_table_one[] = {
65 "one",
66 NULL,
67 };
68
69 static const char* const input_table_none[] = {
70 NULL,
71 };
72
73 static const char* const input_table_two_empties[] = {
74 "",
75 "",
76 NULL,
77 };
78
79 static const char* const input_table_one_empty[] = {
80 "",
81 NULL,
82 };
83
84
85 static const char* const input_table_quotes[] = {
86 "\"",
87 "'",
88 "\"\"",
89 "\\",
90 "\\\\",
91 NULL,
92 };
93 #define QUOTES_STRING \
94 "\"\\\"\" " \
95 "\"\\\'\" " \
96 "\"\\\"\\\"\" " \
97 "\"\\\\\" " \
98 "\"\\\\\\\\\""
99
100 static const char * const input_table_spaces[] = {
101 " ",
102 "' '",
103 "\" ",
104 " \"",
105 " \\\\ ",
106 NULL,
107 };
108 #define SPACES_STRING \
109 "\" \" " \
110 "\"\\' \\'\" " \
111 "\"\\\" \" " \
112 "\" \\\"\" " \
113 "\" \\\\\\\\ \""
114
115 static void test_strv_find(void) {
116 assert_se(strv_find((char **)input_table_multiple, "three"));
117 assert_se(!strv_find((char **)input_table_multiple, "four"));
118 }
119
120 static void test_strv_find_prefix(void) {
121 assert_se(strv_find_prefix((char **)input_table_multiple, "o"));
122 assert_se(strv_find_prefix((char **)input_table_multiple, "one"));
123 assert_se(strv_find_prefix((char **)input_table_multiple, ""));
124 assert_se(!strv_find_prefix((char **)input_table_multiple, "xxx"));
125 assert_se(!strv_find_prefix((char **)input_table_multiple, "onee"));
126 }
127
128 static void test_strv_find_startswith(void) {
129 char *r;
130
131 r = strv_find_startswith((char **)input_table_multiple, "o");
132 assert_se(r && streq(r, "ne"));
133
134 r = strv_find_startswith((char **)input_table_multiple, "one");
135 assert_se(r && streq(r, ""));
136
137 r = strv_find_startswith((char **)input_table_multiple, "");
138 assert_se(r && streq(r, "one"));
139
140 assert_se(!strv_find_startswith((char **)input_table_multiple, "xxx"));
141 assert_se(!strv_find_startswith((char **)input_table_multiple, "onee"));
142 }
143
144 static void test_strv_join(void) {
145 _cleanup_free_ char *p = NULL, *q = NULL, *r = NULL, *s = NULL, *t = NULL, *v = NULL, *w = NULL;
146
147 p = strv_join((char **)input_table_multiple, ", ");
148 assert_se(p);
149 assert_se(streq(p, "one, two, three"));
150
151 q = strv_join((char **)input_table_multiple, ";");
152 assert_se(q);
153 assert_se(streq(q, "one;two;three"));
154
155 r = strv_join((char **)input_table_multiple, NULL);
156 assert_se(r);
157 assert_se(streq(r, "one two three"));
158
159 s = strv_join((char **)input_table_one, ", ");
160 assert_se(s);
161 assert_se(streq(s, "one"));
162
163 t = strv_join((char **)input_table_none, ", ");
164 assert_se(t);
165 assert_se(streq(t, ""));
166
167 v = strv_join((char **)input_table_two_empties, ", ");
168 assert_se(v);
169 assert_se(streq(v, ", "));
170
171 w = strv_join((char **)input_table_one_empty, ", ");
172 assert_se(w);
173 assert_se(streq(w, ""));
174 }
175
176 static void test_strv_quote_unquote(const char* const *split, const char *quoted) {
177 _cleanup_free_ char *p;
178 _cleanup_strv_free_ char **s = NULL;
179 char **t;
180 int r;
181
182 p = strv_join_quoted((char **)split);
183 assert_se(p);
184 printf("-%s- --- -%s-\n", p, quoted); /* fprintf deals with NULL, puts does not */
185 assert_se(p);
186 assert_se(streq(p, quoted));
187
188 r = strv_split_extract(&s, quoted, WHITESPACE, EXTRACT_QUOTES);
189 assert_se(r == (int) strv_length(s));
190 assert_se(s);
191 STRV_FOREACH(t, s) {
192 assert_se(*t);
193 assert_se(streq(*t, *split));
194 split++;
195 }
196 }
197
198 static void test_strv_unquote(const char *quoted, char **list) {
199 _cleanup_strv_free_ char **s;
200 _cleanup_free_ char *j;
201 unsigned i = 0;
202 char **t;
203 int r;
204
205 r = strv_split_extract(&s, quoted, WHITESPACE, EXTRACT_QUOTES);
206 assert_se(r == (int) strv_length(list));
207 assert_se(s);
208 j = strv_join(s, " | ");
209 assert_se(j);
210 puts(j);
211
212 STRV_FOREACH(t, s)
213 assert_se(streq(list[i++], *t));
214
215 assert_se(list[i] == NULL);
216 }
217
218 static void test_invalid_unquote(const char *quoted) {
219 char **s = NULL;
220 int r;
221
222 r = strv_split_extract(&s, quoted, WHITESPACE, EXTRACT_QUOTES);
223 assert_se(s == NULL);
224 assert_se(r == -EINVAL);
225 }
226
227 static void test_strv_split(void) {
228 char **s;
229 unsigned i = 0;
230 _cleanup_strv_free_ char **l = NULL;
231 const char str[] = "one,two,three";
232
233 l = strv_split(str, ",");
234
235 assert_se(l);
236
237 STRV_FOREACH(s, l) {
238 assert_se(streq(*s, input_table_multiple[i++]));
239 }
240 }
241
242 static void test_strv_split_extract(void) {
243 _cleanup_strv_free_ char **l = NULL;
244 const char *str = ":foo\\:bar::waldo:";
245 int r;
246
247 r = strv_split_extract(&l, str, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
248 assert_se(r == (int) strv_length(l));
249 assert_se(streq_ptr(l[0], ""));
250 assert_se(streq_ptr(l[1], "foo:bar"));
251 assert_se(streq_ptr(l[2], ""));
252 assert_se(streq_ptr(l[3], "waldo"));
253 assert_se(streq_ptr(l[4], ""));
254 assert_se(streq_ptr(l[5], NULL));
255 }
256
257 static void test_strv_split_newlines(void) {
258 unsigned i = 0;
259 char **s;
260 _cleanup_strv_free_ char **l = NULL;
261 const char str[] = "one\ntwo\nthree";
262
263 l = strv_split_newlines(str);
264
265 assert_se(l);
266
267 STRV_FOREACH(s, l) {
268 assert_se(streq(*s, input_table_multiple[i++]));
269 }
270 }
271
272 static void test_strv_split_nulstr(void) {
273 _cleanup_strv_free_ char **l = NULL;
274 const char nulstr[] = "str0\0str1\0str2\0str3\0";
275
276 l = strv_split_nulstr (nulstr);
277 assert_se(l);
278
279 assert_se(streq(l[0], "str0"));
280 assert_se(streq(l[1], "str1"));
281 assert_se(streq(l[2], "str2"));
282 assert_se(streq(l[3], "str3"));
283 }
284
285 static void test_strv_parse_nulstr(void) {
286 _cleanup_strv_free_ char **l = NULL;
287 const char nulstr[] = "fuck\0fuck2\0fuck3\0\0fuck5\0\0xxx";
288
289 l = strv_parse_nulstr(nulstr, sizeof(nulstr)-1);
290 assert_se(l);
291 puts("Parse nulstr:");
292 strv_print(l);
293
294 assert_se(streq(l[0], "fuck"));
295 assert_se(streq(l[1], "fuck2"));
296 assert_se(streq(l[2], "fuck3"));
297 assert_se(streq(l[3], ""));
298 assert_se(streq(l[4], "fuck5"));
299 assert_se(streq(l[5], ""));
300 assert_se(streq(l[6], "xxx"));
301 }
302
303 static void test_strv_overlap(void) {
304 const char * const input_table[] = {
305 "one",
306 "two",
307 "three",
308 NULL
309 };
310 const char * const input_table_overlap[] = {
311 "two",
312 NULL
313 };
314 const char * const input_table_unique[] = {
315 "four",
316 "five",
317 "six",
318 NULL
319 };
320
321 assert_se(strv_overlap((char **)input_table, (char**)input_table_overlap));
322 assert_se(!strv_overlap((char **)input_table, (char**)input_table_unique));
323 }
324
325 static void test_strv_sort(void) {
326 const char* input_table[] = {
327 "durian",
328 "apple",
329 "citrus",
330 "CAPITAL LETTERS FIRST",
331 "banana",
332 NULL
333 };
334
335 strv_sort((char **)input_table);
336
337 assert_se(streq(input_table[0], "CAPITAL LETTERS FIRST"));
338 assert_se(streq(input_table[1], "apple"));
339 assert_se(streq(input_table[2], "banana"));
340 assert_se(streq(input_table[3], "citrus"));
341 assert_se(streq(input_table[4], "durian"));
342 }
343
344 static void test_strv_extend_strv_concat(void) {
345 _cleanup_strv_free_ char **a = NULL, **b = NULL;
346
347 a = strv_new("without", "suffix", NULL);
348 b = strv_new("with", "suffix", NULL);
349 assert_se(a);
350 assert_se(b);
351
352 assert_se(strv_extend_strv_concat(&a, b, "_suffix") >= 0);
353
354 assert_se(streq(a[0], "without"));
355 assert_se(streq(a[1], "suffix"));
356 assert_se(streq(a[2], "with_suffix"));
357 assert_se(streq(a[3], "suffix_suffix"));
358 }
359
360 static void test_strv_extend_strv(void) {
361 _cleanup_strv_free_ char **a = NULL, **b = NULL;
362
363 a = strv_new("abc", "def", "ghi", NULL);
364 b = strv_new("jkl", "mno", "abc", "pqr", NULL);
365 assert_se(a);
366 assert_se(b);
367
368 assert_se(strv_extend_strv(&a, b, true) == 3);
369
370 assert_se(streq(a[0], "abc"));
371 assert_se(streq(a[1], "def"));
372 assert_se(streq(a[2], "ghi"));
373 assert_se(streq(a[3], "jkl"));
374 assert_se(streq(a[4], "mno"));
375 assert_se(streq(a[5], "pqr"));
376
377 assert_se(strv_length(a) == 6);
378 }
379
380 static void test_strv_extend(void) {
381 _cleanup_strv_free_ char **a = NULL, **b = NULL;
382
383 a = strv_new("test", "test1", NULL);
384 assert_se(a);
385 assert_se(strv_extend(&a, "test2") >= 0);
386 assert_se(strv_extend(&b, "test3") >= 0);
387
388 assert_se(streq(a[0], "test"));
389 assert_se(streq(a[1], "test1"));
390 assert_se(streq(a[2], "test2"));
391 assert_se(streq(b[0], "test3"));
392 }
393
394 static void test_strv_extendf(void) {
395 _cleanup_strv_free_ char **a = NULL, **b = NULL;
396
397 a = strv_new("test", "test1", NULL);
398 assert_se(a);
399 assert_se(strv_extendf(&a, "test2 %s %d %s", "foo", 128, "bar") >= 0);
400 assert_se(strv_extendf(&b, "test3 %s %s %d", "bar", "foo", 128) >= 0);
401
402 assert_se(streq(a[0], "test"));
403 assert_se(streq(a[1], "test1"));
404 assert_se(streq(a[2], "test2 foo 128 bar"));
405 assert_se(streq(b[0], "test3 bar foo 128"));
406 }
407
408 static void test_strv_foreach(void) {
409 _cleanup_strv_free_ char **a;
410 unsigned i = 0;
411 char **check;
412
413 a = strv_new("one", "two", "three", NULL);
414
415 assert_se(a);
416
417 STRV_FOREACH(check, a) {
418 assert_se(streq(*check, input_table_multiple[i++]));
419 }
420 }
421
422 static void test_strv_foreach_backwards(void) {
423 _cleanup_strv_free_ char **a;
424 unsigned i = 2;
425 char **check;
426
427 a = strv_new("one", "two", "three", NULL);
428
429 assert_se(a);
430
431 STRV_FOREACH_BACKWARDS(check, a) {
432 assert_se(streq_ptr(*check, input_table_multiple[i--]));
433 }
434 }
435
436 static void test_strv_foreach_pair(void) {
437 _cleanup_strv_free_ char **a = NULL;
438 char **x, **y;
439
440 a = strv_new("pair_one", "pair_one",
441 "pair_two", "pair_two",
442 "pair_three", "pair_three",
443 NULL);
444
445 STRV_FOREACH_PAIR(x, y, a) {
446 assert_se(streq(*x, *y));
447 }
448 }
449
450 static void test_strv_from_stdarg_alloca_one(char **l, const char *first, ...) {
451 char **j;
452 unsigned i;
453
454 j = strv_from_stdarg_alloca(first);
455
456 for (i = 0;; i++) {
457 assert_se(streq_ptr(l[i], j[i]));
458
459 if (!l[i])
460 break;
461 }
462 }
463
464 static void test_strv_from_stdarg_alloca(void) {
465 test_strv_from_stdarg_alloca_one(STRV_MAKE("foo", "bar"), "foo", "bar", NULL);
466 test_strv_from_stdarg_alloca_one(STRV_MAKE("foo"), "foo", NULL);
467 test_strv_from_stdarg_alloca_one(STRV_MAKE_EMPTY, NULL);
468 }
469
470 static void test_strv_push_prepend(void) {
471 _cleanup_strv_free_ char **a = NULL;
472
473 a = strv_new("foo", "bar", "three", NULL);
474
475 assert_se(strv_push_prepend(&a, strdup("first")) >= 0);
476 assert_se(streq(a[0], "first"));
477 assert_se(streq(a[1], "foo"));
478 assert_se(streq(a[2], "bar"));
479 assert_se(streq(a[3], "three"));
480 assert_se(!a[4]);
481
482 assert_se(strv_consume_prepend(&a, strdup("first2")) >= 0);
483 assert_se(streq(a[0], "first2"));
484 assert_se(streq(a[1], "first"));
485 assert_se(streq(a[2], "foo"));
486 assert_se(streq(a[3], "bar"));
487 assert_se(streq(a[4], "three"));
488 assert_se(!a[5]);
489 }
490
491 static void test_strv_push(void) {
492 _cleanup_strv_free_ char **a = NULL;
493 char *i, *j;
494
495 assert_se(i = strdup("foo"));
496 assert_se(strv_push(&a, i) >= 0);
497
498 assert_se(i = strdup("a"));
499 assert_se(j = strdup("b"));
500 assert_se(strv_push_pair(&a, i, j) >= 0);
501
502 assert_se(streq_ptr(a[0], "foo"));
503 assert_se(streq_ptr(a[1], "a"));
504 assert_se(streq_ptr(a[2], "b"));
505 assert_se(streq_ptr(a[3], NULL));
506 }
507
508 static void test_strv_equal(void) {
509 _cleanup_strv_free_ char **a = NULL;
510 _cleanup_strv_free_ char **b = NULL;
511 _cleanup_strv_free_ char **c = NULL;
512
513 a = strv_new("one", "two", "three", NULL);
514 assert_se(a);
515 b = strv_new("one", "two", "three", NULL);
516 assert_se(a);
517 c = strv_new("one", "two", "three", "four", NULL);
518 assert_se(a);
519
520 assert_se(strv_equal(a, a));
521 assert_se(strv_equal(a, b));
522 assert_se(strv_equal(NULL, NULL));
523
524 assert_se(!strv_equal(a, c));
525 assert_se(!strv_equal(b, c));
526 assert_se(!strv_equal(b, NULL));
527 }
528
529 static void test_strv_is_uniq(void) {
530 _cleanup_strv_free_ char **a = NULL, **b = NULL, **c = NULL, **d = NULL;
531
532 a = strv_new(NULL, NULL);
533 assert_se(a);
534 assert_se(strv_is_uniq(a));
535
536 b = strv_new("foo", NULL);
537 assert_se(b);
538 assert_se(strv_is_uniq(b));
539
540 c = strv_new("foo", "bar", NULL);
541 assert_se(c);
542 assert_se(strv_is_uniq(c));
543
544 d = strv_new("foo", "bar", "waldo", "bar", "piep", NULL);
545 assert_se(d);
546 assert_se(!strv_is_uniq(d));
547 }
548
549 static void test_strv_reverse(void) {
550 _cleanup_strv_free_ char **a = NULL, **b = NULL, **c = NULL, **d = NULL;
551
552 a = strv_new(NULL, NULL);
553 assert_se(a);
554
555 strv_reverse(a);
556 assert_se(strv_isempty(a));
557
558 b = strv_new("foo", NULL);
559 assert_se(b);
560 strv_reverse(b);
561 assert_se(streq_ptr(b[0], "foo"));
562 assert_se(streq_ptr(b[1], NULL));
563
564 c = strv_new("foo", "bar", NULL);
565 assert_se(c);
566 strv_reverse(c);
567 assert_se(streq_ptr(c[0], "bar"));
568 assert_se(streq_ptr(c[1], "foo"));
569 assert_se(streq_ptr(c[2], NULL));
570
571 d = strv_new("foo", "bar", "waldo", NULL);
572 assert_se(d);
573 strv_reverse(d);
574 assert_se(streq_ptr(d[0], "waldo"));
575 assert_se(streq_ptr(d[1], "bar"));
576 assert_se(streq_ptr(d[2], "foo"));
577 assert_se(streq_ptr(d[3], NULL));
578 }
579
580 static void test_strv_shell_escape(void) {
581 _cleanup_strv_free_ char **v = NULL;
582
583 v = strv_new("foo:bar", "bar,baz", "wal\\do", NULL);
584 assert_se(v);
585 assert_se(strv_shell_escape(v, ",:"));
586 assert_se(streq_ptr(v[0], "foo\\:bar"));
587 assert_se(streq_ptr(v[1], "bar\\,baz"));
588 assert_se(streq_ptr(v[2], "wal\\\\do"));
589 assert_se(streq_ptr(v[3], NULL));
590 }
591
592 static void test_strv_skip_one(char **a, size_t n, char **b) {
593 a = strv_skip(a, n);
594 assert_se(strv_equal(a, b));
595 }
596
597 static void test_strv_skip(void) {
598 test_strv_skip_one(STRV_MAKE("foo", "bar", "baz"), 0, STRV_MAKE("foo", "bar", "baz"));
599 test_strv_skip_one(STRV_MAKE("foo", "bar", "baz"), 1, STRV_MAKE("bar", "baz"));
600 test_strv_skip_one(STRV_MAKE("foo", "bar", "baz"), 2, STRV_MAKE("baz"));
601 test_strv_skip_one(STRV_MAKE("foo", "bar", "baz"), 3, STRV_MAKE(NULL));
602 test_strv_skip_one(STRV_MAKE("foo", "bar", "baz"), 4, STRV_MAKE(NULL));
603 test_strv_skip_one(STRV_MAKE("foo", "bar", "baz"), 55, STRV_MAKE(NULL));
604
605 test_strv_skip_one(STRV_MAKE("quux"), 0, STRV_MAKE("quux"));
606 test_strv_skip_one(STRV_MAKE("quux"), 1, STRV_MAKE(NULL));
607 test_strv_skip_one(STRV_MAKE("quux"), 55, STRV_MAKE(NULL));
608
609 test_strv_skip_one(STRV_MAKE(NULL), 0, STRV_MAKE(NULL));
610 test_strv_skip_one(STRV_MAKE(NULL), 1, STRV_MAKE(NULL));
611 test_strv_skip_one(STRV_MAKE(NULL), 55, STRV_MAKE(NULL));
612 }
613
614 static void test_strv_extend_n(void) {
615 _cleanup_strv_free_ char **v = NULL;
616
617 v = strv_new("foo", "bar", NULL);
618 assert_se(v);
619
620 assert_se(strv_extend_n(&v, "waldo", 3) >= 0);
621 assert_se(strv_extend_n(&v, "piep", 2) >= 0);
622
623 assert_se(streq(v[0], "foo"));
624 assert_se(streq(v[1], "bar"));
625 assert_se(streq(v[2], "waldo"));
626 assert_se(streq(v[3], "waldo"));
627 assert_se(streq(v[4], "waldo"));
628 assert_se(streq(v[5], "piep"));
629 assert_se(streq(v[6], "piep"));
630 assert_se(v[7] == NULL);
631
632 v = strv_free(v);
633
634 assert_se(strv_extend_n(&v, "foo", 1) >= 0);
635 assert_se(strv_extend_n(&v, "bar", 0) >= 0);
636
637 assert_se(streq(v[0], "foo"));
638 assert_se(v[1] == NULL);
639 }
640
641 static void test_strv_make_nulstr_one(char **l) {
642 _cleanup_free_ char *b = NULL, *c = NULL;
643 _cleanup_strv_free_ char **q = NULL;
644 size_t n, m;
645
646 assert_se(strv_make_nulstr(l, &b, &n) >= 0);
647 assert_se(q = strv_parse_nulstr(b, n));
648 assert_se(strv_equal(l, q));
649
650 assert_se(strv_make_nulstr(q, &c, &m) >= 0);
651 assert_se(m == n);
652 assert_se(memcmp(b, c, m) == 0);
653 }
654
655 static void test_strv_make_nulstr(void) {
656 test_strv_make_nulstr_one(NULL);
657 test_strv_make_nulstr_one(STRV_MAKE(NULL));
658 test_strv_make_nulstr_one(STRV_MAKE("foo"));
659 test_strv_make_nulstr_one(STRV_MAKE("foo", "bar"));
660 test_strv_make_nulstr_one(STRV_MAKE("foo", "bar", "quuux"));
661 }
662
663 static void test_foreach_string(void) {
664 const char * const t[] = {
665 "foo",
666 "bar",
667 "waldo",
668 NULL
669 };
670 const char *x;
671 unsigned i = 0;
672
673 FOREACH_STRING(x, "foo", "bar", "waldo")
674 assert_se(streq_ptr(t[i++], x));
675
676 assert_se(i == 3);
677
678 FOREACH_STRING(x, "zzz")
679 assert_se(streq(x, "zzz"));
680 }
681
682 int main(int argc, char *argv[]) {
683 test_specifier_printf();
684 test_strv_foreach();
685 test_strv_foreach_backwards();
686 test_strv_foreach_pair();
687 test_strv_find();
688 test_strv_find_prefix();
689 test_strv_find_startswith();
690 test_strv_join();
691
692 test_strv_quote_unquote(input_table_multiple, "\"one\" \"two\" \"three\"");
693 test_strv_quote_unquote(input_table_one, "\"one\"");
694 test_strv_quote_unquote(input_table_none, "");
695 test_strv_quote_unquote(input_table_one_empty, "\"\"");
696 test_strv_quote_unquote(input_table_two_empties, "\"\" \"\"");
697 test_strv_quote_unquote(input_table_quotes, QUOTES_STRING);
698 test_strv_quote_unquote(input_table_spaces, SPACES_STRING);
699
700 test_strv_unquote(" foo=bar \"waldo\" zzz ", STRV_MAKE("foo=bar", "waldo", "zzz"));
701 test_strv_unquote("", STRV_MAKE_EMPTY);
702 test_strv_unquote(" ", STRV_MAKE_EMPTY);
703 test_strv_unquote(" ", STRV_MAKE_EMPTY);
704 test_strv_unquote(" x", STRV_MAKE("x"));
705 test_strv_unquote("x ", STRV_MAKE("x"));
706 test_strv_unquote(" x ", STRV_MAKE("x"));
707 test_strv_unquote(" \"x\" ", STRV_MAKE("x"));
708 test_strv_unquote(" 'x' ", STRV_MAKE("x"));
709 test_strv_unquote(" 'x\"' ", STRV_MAKE("x\""));
710 test_strv_unquote(" \"x'\" ", STRV_MAKE("x'"));
711 test_strv_unquote("a '--b=c \"d e\"'", STRV_MAKE("a", "--b=c \"d e\""));
712
713 /* trailing backslashes */
714 test_strv_unquote(" x\\\\", STRV_MAKE("x\\"));
715 test_invalid_unquote(" x\\");
716
717 test_invalid_unquote("a --b='c \"d e\"''");
718 test_invalid_unquote("a --b='c \"d e\" '\"");
719 test_invalid_unquote("a --b='c \"d e\"garbage");
720 test_invalid_unquote("'");
721 test_invalid_unquote("\"");
722 test_invalid_unquote("'x'y'g");
723
724 test_strv_split();
725 test_strv_split_extract();
726 test_strv_split_newlines();
727 test_strv_split_nulstr();
728 test_strv_parse_nulstr();
729 test_strv_overlap();
730 test_strv_sort();
731 test_strv_extend_strv();
732 test_strv_extend_strv_concat();
733 test_strv_extend();
734 test_strv_extendf();
735 test_strv_from_stdarg_alloca();
736 test_strv_push_prepend();
737 test_strv_push();
738 test_strv_equal();
739 test_strv_is_uniq();
740 test_strv_reverse();
741 test_strv_shell_escape();
742 test_strv_skip();
743 test_strv_extend_n();
744 test_strv_make_nulstr();
745
746 test_foreach_string();
747
748 return 0;
749 }