diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-05-07 16:25:36 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-05-07 17:36:44 +0200 |
commit | b6c93a5a4489d238a03ba70d9418951a0d379ddf (patch) | |
tree | 736d85a4f4dcd67fd9a891caa329ceab6831ce56 /src/test/test-specifier.c | |
parent | e97708fa3e029902c02676bba6e6c2f54f1eba3a (diff) | |
download | systemd-b6c93a5a4489d238a03ba70d9418951a0d379ddf.tar.gz |
test-specifier: add a simple test which prints "global" specifiers
...i.e. those which can be resolved without a context parameter.
Diffstat (limited to 'src/test/test-specifier.c')
-rw-r--r-- | src/test/test-specifier.c | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/src/test/test-specifier.c b/src/test/test-specifier.c index a0ffdf6cb6..e81b12b418 100644 --- a/src/test/test-specifier.c +++ b/src/test/test-specifier.c @@ -3,6 +3,7 @@ #include "alloc-util.h" #include "log.h" #include "specifier.h" +#include "stdio-util.h" #include "string-util.h" #include "strv.h" #include "tests.h" @@ -15,6 +16,8 @@ static void test_specifier_escape_one(const char *a, const char *b) { } static void test_specifier_escape(void) { + log_info("/* %s */", __func__); + test_specifier_escape_one(NULL, NULL); test_specifier_escape_one("", ""); test_specifier_escape_one("%", "%%"); @@ -31,12 +34,54 @@ static void test_specifier_escape_strv_one(char **a, char **b) { } static void test_specifier_escape_strv(void) { + log_info("/* %s */", __func__); + test_specifier_escape_strv_one(NULL, NULL); test_specifier_escape_strv_one(STRV_MAKE(NULL), STRV_MAKE(NULL)); test_specifier_escape_strv_one(STRV_MAKE(""), STRV_MAKE("")); test_specifier_escape_strv_one(STRV_MAKE("foo"), STRV_MAKE("foo")); test_specifier_escape_strv_one(STRV_MAKE("%"), STRV_MAKE("%%")); - test_specifier_escape_strv_one(STRV_MAKE("foo", "%", "foo%", "%foo", "foo%foo", "quux", "%%%"), STRV_MAKE("foo", "%%", "foo%%", "%%foo", "foo%%foo", "quux", "%%%%%%")); + test_specifier_escape_strv_one(STRV_MAKE("foo", "%", "foo%", "%foo", "foo%foo", "quux", "%%%"), + STRV_MAKE("foo", "%%", "foo%%", "%%foo", "foo%%foo", "quux", "%%%%%%")); +} + +/* Any specifier functions which don't need an argument. */ +static const Specifier specifier_table[] = { + { 'm', specifier_machine_id, NULL }, + { 'b', specifier_boot_id, NULL }, + { 'H', specifier_host_name, NULL }, + { 'l', specifier_short_host_name, NULL }, + { 'v', specifier_kernel_release, NULL }, + { 'a', specifier_architecture, NULL }, + { 'o', specifier_os_id, NULL }, + { 'w', specifier_os_version_id, NULL }, + { 'B', specifier_os_build_id, NULL }, + { 'W', specifier_os_variant_id, NULL }, + + { 'g', specifier_group_name, NULL }, + { 'G', specifier_group_id, NULL }, + { 'U', specifier_user_id, NULL }, + { 'u', specifier_user_name, NULL }, + { 'h', specifier_user_home, NULL }, + + { 'T', specifier_tmp_dir, NULL }, + { 'V', specifier_var_tmp_dir, NULL }, + {} +}; + +static void test_specifiers(void) { + log_info("/* %s */", __func__); + + for (const Specifier *s = specifier_table; s->specifier; s++) { + char spec[3]; + _cleanup_free_ char *resolved = NULL; + + xsprintf(spec, "%%%c", s->specifier); + + assert_se(specifier_printf(spec, specifier_table, NULL, &resolved) >= 0); + + log_info("%%%c → %s", s->specifier, resolved); + } } int main(int argc, char *argv[]) { @@ -44,6 +89,7 @@ int main(int argc, char *argv[]) { test_specifier_escape(); test_specifier_escape_strv(); + test_specifiers(); return 0; } |