From 19f6d710772305610b928bc2678b9d77fe11e770 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 17 Sep 2013 10:03:46 -0500 Subject: specifier: rework specifier calls to return proper error message Previously the specifier calls could only indicate OOM by returning NULL. With this change they will return negative errno-style error codes like everything else. --- src/test/test-strv.c | 16 ++++++++++++++-- src/test/test-unit-file.c | 7 ++++--- src/test/test-unit-name.c | 8 ++++---- 3 files changed, 22 insertions(+), 9 deletions(-) (limited to 'src/test') diff --git a/src/test/test-strv.c b/src/test/test-strv.c index 25bee22dfe..6513d2e07b 100644 --- a/src/test/test-strv.c +++ b/src/test/test-strv.c @@ -28,18 +28,30 @@ static void test_specifier_printf(void) { _cleanup_free_ char *w = NULL; + int r; const Specifier table[] = { { 'a', specifier_string, (char*) "AAAA" }, { 'b', specifier_string, (char*) "BBBB" }, + { 'm', specifier_machine_id, NULL }, + { 'B', specifier_boot_id, NULL }, + { 'H', specifier_host_name, NULL }, + { 'v', specifier_kernel_release, NULL }, { 0, NULL, NULL } }; - w = specifier_printf("xxx a=%a b=%b yyy", table, NULL); + r = specifier_printf("xxx a=%a b=%b 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", table, NULL, &w); + assert_se(r >= 0); assert_se(w); - assert_se(streq(w, "xxx a=AAAA b=BBBB yyy")); + puts(w); } static const char* const input_table_multiple[] = { diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c index dc6bc55244..0413ae2117 100644 --- a/src/test/test-unit-file.c +++ b/src/test/test-unit-file.c @@ -302,17 +302,18 @@ static void test_install_printf(void) { _cleanup_free_ char *mid, *bid, *host; - assert_se((mid = specifier_machine_id('m', NULL, NULL))); - assert_se((bid = specifier_boot_id('b', NULL, NULL))); + assert_se(specifier_machine_id('m', NULL, NULL, &mid) >= 0 && mid); + assert_se(specifier_boot_id('b', NULL, NULL, &bid) >= 0 && bid); assert_se((host = gethostname_malloc())); #define expect(src, pattern, result) \ do { \ - _cleanup_free_ char *t = install_full_printf(&src, pattern); \ + _cleanup_free_ char *t = NULL; \ _cleanup_free_ char \ *d1 = strdup(i.name), \ *d2 = strdup(i.path), \ *d3 = strdup(i.user); \ + assert_se(install_full_printf(&src, pattern, &t) >= 0 || !result); \ memzero(i.name, strlen(i.name)); \ memzero(i.path, strlen(i.path)); \ memzero(i.user, strlen(i.user)); \ diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c index c17692b845..67ccdd4228 100644 --- a/src/test/test-unit-name.c +++ b/src/test/test-unit-name.c @@ -117,8 +117,8 @@ static int test_unit_printf(void) { _cleanup_free_ char *mid, *bid, *host, *root_uid; struct passwd *root; - assert_se((mid = specifier_machine_id('m', NULL, NULL))); - assert_se((bid = specifier_boot_id('b', NULL, NULL))); + assert_se(specifier_machine_id('m', NULL, NULL, &mid) >= 0 && mid); + assert_se(specifier_boot_id('b', NULL, NULL, &bid) >= 0 && bid); assert_se((host = gethostname_malloc())); assert_se((root = getpwnam("root"))); @@ -134,8 +134,8 @@ static int test_unit_printf(void) { #define expect(unit, pattern, expected) \ { \ char *e; \ - _cleanup_free_ char *t = \ - unit_full_printf(unit, pattern); \ + _cleanup_free_ char *t; \ + assert_se(unit_full_printf(unit, pattern, &t) >= 0); \ printf("result: %s\nexpect: %s\n", t, expected); \ if ((e = endswith(expected, "*"))) \ assert(strncmp(t, e, e-expected)); \ -- cgit v1.2.3-54-g00ecf