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