From c030a850ba59fbcdf796abfe48b2f220933c52c0 Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Sat, 1 Aug 2015 00:23:47 +0900 Subject: busctl: add and use strcmp_ptr() In member_compare_func(), it compares interface, type and name of members. But as it can contain NULL pointer, it needs to check them before calling strcmp(). So make it as a separate strcmp_ptr function (named after streq_ptr) so that it can be used by others. Also let streq_ptr() to use it in order to make the code simpler. --- src/test/test-util.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/test/test-util.c') diff --git a/src/test/test-util.c b/src/test/test-util.c index f43433baa1..7a1a4b6df2 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -2083,6 +2083,18 @@ static void test_tempfn(void) { free(ret); } +static void test_strcmp_ptr(void) { + assert_se(strcmp_ptr(NULL, NULL) == 0); + assert_se(strcmp_ptr("", NULL) > 0); + assert_se(strcmp_ptr("foo", NULL) > 0); + assert_se(strcmp_ptr(NULL, "") < 0); + assert_se(strcmp_ptr(NULL, "bar") < 0); + assert_se(strcmp_ptr("foo", "bar") > 0); + assert_se(strcmp_ptr("bar", "baz") < 0); + assert_se(strcmp_ptr("foo", "foo") == 0); + assert_se(strcmp_ptr("", "") == 0); +} + int main(int argc, char *argv[]) { log_parse_environment(); log_open(); @@ -2169,6 +2181,7 @@ int main(int argc, char *argv[]) { test_shell_maybe_quote(); test_parse_mode(); test_tempfn(); + test_strcmp_ptr(); return 0; } -- cgit v1.2.3-54-g00ecf