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