From c73838280cb107a10e0d8d45227d5471db56368f Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Sat, 3 Dec 2016 13:57:42 -0500 Subject: Modify mount_propagation_flags_from_string to return a normal int code This means that callers can distiguish an error from flags==0, and don't have to special-case the empty string. --- src/test/test-mount-util.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'src/test') diff --git a/src/test/test-mount-util.c b/src/test/test-mount-util.c index da7f35623b..7c5929d009 100644 --- a/src/test/test-mount-util.c +++ b/src/test/test-mount-util.c @@ -23,23 +23,35 @@ #include "mount-util.h" #include "string-util.h" -static void test_mount_propagation_flags(const char *name, unsigned long f) { - assert(mount_propagation_flags_from_string(name) == f); +static void test_mount_propagation_flags(const char *name, int ret, unsigned long expected) { + long unsigned flags; - if (f != 0) - assert_se(streq_ptr(mount_propagation_flags_to_string(f), name)); + assert(mount_propagation_flags_from_string(name, &flags) == ret); + + if (ret >= 0) { + const char *c; + + assert_se(flags == expected); + + c = mount_propagation_flags_to_string(flags); + if (isempty(name)) + assert_se(isempty(c)); + else + assert_se(streq(c, name)); + } } int main(int argc, char *argv[]) { log_set_max_level(LOG_DEBUG); - test_mount_propagation_flags("shared", MS_SHARED); - test_mount_propagation_flags("slave", MS_SLAVE); - test_mount_propagation_flags("private", MS_PRIVATE); - test_mount_propagation_flags(NULL, 0); - test_mount_propagation_flags("", 0); - test_mount_propagation_flags("xxxx", 0); + test_mount_propagation_flags("shared", 0, MS_SHARED); + test_mount_propagation_flags("slave", 0, MS_SLAVE); + test_mount_propagation_flags("private", 0, MS_PRIVATE); + test_mount_propagation_flags(NULL, 0, 0); + test_mount_propagation_flags("", 0, 0); + test_mount_propagation_flags("xxxx", -EINVAL, 0); + test_mount_propagation_flags(" ", -EINVAL, 0); return 0; } -- cgit v1.2.3-54-g00ecf