From: Yu Watanabe Date: Sun, 9 May 2021 15:13:14 +0000 (+0900) Subject: test: move test_specifier_printf() to test-specifier.c X-Git-Tag: v249-rc1~243^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f4767dc081a66ed50079e7e0a8829522cc57c8c6;p=thirdparty%2Fsystemd.git test: move test_specifier_printf() to test-specifier.c --- diff --git a/src/test/test-specifier.c b/src/test/test-specifier.c index 2648c1c3f51..cad4aa56eca 100644 --- a/src/test/test-specifier.c +++ b/src/test/test-specifier.c @@ -56,6 +56,38 @@ static const Specifier specifier_table[] = { {} }; +static void test_specifier_printf(void) { + static const Specifier table[] = { + { 'X', specifier_string, (char*) "AAAA" }, + { 'Y', specifier_string, (char*) "BBBB" }, + COMMON_SYSTEM_SPECIFIERS, + {} + }; + + _cleanup_free_ char *w = NULL; + int r; + + log_info("/* %s */", __func__); + + r = specifier_printf("xxx a=%X b=%Y yyy", table, NULL, &w); + assert_se(r >= 0); + assert_se(w); + + puts(w); + assert_se(streq(w, "xxx a=AAAA b=BBBB yyy")); + + free(w); + r = specifier_printf("machine=%m, boot=%b, host=%H, version=%v, arch=%a", table, NULL, &w); + assert_se(r >= 0); + assert_se(w); + puts(w); + + w = mfree(w); + specifier_printf("os=%o, os-version=%w, build=%B, variant=%W", table, NULL, &w); + if (w) + puts(w); +} + static void test_specifiers(void) { log_info("/* %s */", __func__); @@ -76,6 +108,7 @@ int main(int argc, char *argv[]) { test_specifier_escape(); test_specifier_escape_strv(); + test_specifier_printf(); test_specifiers(); return 0; diff --git a/src/test/test-strv.c b/src/test/test-strv.c index 039bb2c78af..134525288f1 100644 --- a/src/test/test-strv.c +++ b/src/test/test-strv.c @@ -3,42 +3,9 @@ #include "alloc-util.h" #include "escape.h" #include "nulstr-util.h" -#include "specifier.h" #include "string-util.h" #include "strv.h" -static void test_specifier_printf(void) { - static const Specifier table[] = { - { 'X', specifier_string, (char*) "AAAA" }, - { 'Y', specifier_string, (char*) "BBBB" }, - COMMON_SYSTEM_SPECIFIERS, - {} - }; - - _cleanup_free_ char *w = NULL; - int r; - - log_info("/* %s */", __func__); - - r = specifier_printf("xxx a=%X b=%Y yyy", table, NULL, &w); - assert_se(r >= 0); - assert_se(w); - - puts(w); - assert_se(streq(w, "xxx a=AAAA b=BBBB yyy")); - - free(w); - r = specifier_printf("machine=%m, boot=%b, host=%H, version=%v, arch=%a", table, NULL, &w); - assert_se(r >= 0); - assert_se(w); - puts(w); - - w = mfree(w); - specifier_printf("os=%o, os-version=%w, build=%B, variant=%W", table, NULL, &w); - if (w) - puts(w); -} - static void test_str_in_set(void) { log_info("/* %s */", __func__); @@ -1022,7 +989,6 @@ static void test_strv_fnmatch(void) { } int main(int argc, char *argv[]) { - test_specifier_printf(); test_str_in_set(); test_strptr_in_set(); test_startswith_set();