Line data Source code
1 : /* SPDX-License-Identifier: LGPL-2.1+ */ 2 : 3 : #include "alloc-util.h" 4 : #include "log.h" 5 : #include "specifier.h" 6 : #include "string-util.h" 7 : #include "strv.h" 8 : #include "tests.h" 9 : 10 6 : static void test_specifier_escape_one(const char *a, const char *b) { 11 6 : _cleanup_free_ char *x = NULL; 12 : 13 6 : x = specifier_escape(a); 14 6 : assert_se(streq_ptr(x, b)); 15 6 : } 16 : 17 1 : static void test_specifier_escape(void) { 18 1 : test_specifier_escape_one(NULL, NULL); 19 1 : test_specifier_escape_one("", ""); 20 1 : test_specifier_escape_one("%", "%%"); 21 1 : test_specifier_escape_one("foo bar", "foo bar"); 22 1 : test_specifier_escape_one("foo%bar", "foo%%bar"); 23 1 : test_specifier_escape_one("%%%%%", "%%%%%%%%%%"); 24 1 : } 25 : 26 6 : static void test_specifier_escape_strv_one(char **a, char **b) { 27 6 : _cleanup_strv_free_ char **x = NULL; 28 : 29 6 : assert_se(specifier_escape_strv(a, &x) >= 0); 30 6 : assert_se(strv_equal(x, b)); 31 6 : } 32 : 33 1 : static void test_specifier_escape_strv(void) { 34 1 : test_specifier_escape_strv_one(NULL, NULL); 35 1 : test_specifier_escape_strv_one(STRV_MAKE(NULL), STRV_MAKE(NULL)); 36 1 : test_specifier_escape_strv_one(STRV_MAKE(""), STRV_MAKE("")); 37 1 : test_specifier_escape_strv_one(STRV_MAKE("foo"), STRV_MAKE("foo")); 38 1 : test_specifier_escape_strv_one(STRV_MAKE("%"), STRV_MAKE("%%")); 39 1 : test_specifier_escape_strv_one(STRV_MAKE("foo", "%", "foo%", "%foo", "foo%foo", "quux", "%%%"), STRV_MAKE("foo", "%%", "foo%%", "%%foo", "foo%%foo", "quux", "%%%%%%")); 40 1 : } 41 : 42 1 : int main(int argc, char *argv[]) { 43 1 : test_setup_logging(LOG_DEBUG); 44 : 45 1 : test_specifier_escape(); 46 1 : test_specifier_escape_strv(); 47 : 48 1 : return 0; 49 : }