summaryrefslogtreecommitdiff
path: root/src/test/test-mount-util.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-12-03 13:57:42 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-12-17 13:57:04 -0500
commitc73838280cb107a10e0d8d45227d5471db56368f (patch)
treef8e57c6d966b36f9ae8bc5301d36f3c27869ae3c /src/test/test-mount-util.c
parent117d5a27a3480fd9729cfadd98d135d21732a88d (diff)
downloadsystemd-c73838280cb107a10e0d8d45227d5471db56368f.tar.gz
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.
Diffstat (limited to 'src/test/test-mount-util.c')
-rw-r--r--src/test/test-mount-util.c32
1 files changed, 22 insertions, 10 deletions
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;
}