diff --git a/include/portability.h b/include/portability.h index fc40145c7d..a6eff73cd4 100644 --- a/include/portability.h +++ b/include/portability.h @@ -1,180 +1,186 @@ /* * Copyright 2001-2020 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #ifndef PORTABILITY_H # define PORTABILITY_H # define EOS '\0' # define DIMOF(a) ((int) (sizeof(a)/sizeof(a[0])) ) /* Needs to be defined before any other includes, otherwise some system * headers do not behave as expected! Major black magic... */ # undef _GNU_SOURCE /* in case it was defined on the command line */ # define _GNU_SOURCE /* Please leave this as the first #include - Solaris needs it there */ # ifdef HAVE_CONFIG_H # ifndef PCMK__CONFIG_H # define PCMK__CONFIG_H # include # endif # endif /* Prototypes for libreplace functions */ # ifndef HAVE_DAEMON /* We supply a replacement function, but need a prototype */ int daemon(int nochdir, int noclose); # endif /* HAVE_DAEMON */ # ifndef HAVE_SETENV /* We supply a replacement function, but need a prototype */ int setenv(const char *name, const char *value, int why); # endif /* HAVE_SETENV */ # ifndef HAVE_STRERROR /* We supply a replacement function, but need a prototype */ char *strerror(int errnum); # endif /* HAVE_STRERROR */ # ifndef HAVE_STRCHRNUL /* We supply a replacement function, but need a prototype */ char *strchrnul(const char *s, int c_in); # endif /* HAVE_STRCHRNUL */ # ifndef HAVE_ALPHASORT # include int alphasort(const void *dirent1, const void *dirent2); # endif /* HAVE_ALPHASORT */ # ifndef HAVE_STRNLEN size_t strnlen(const char *s, size_t maxlen); # else # define USE_GNU # endif # ifndef HAVE_STRNDUP char *strndup(const char *str, size_t len); # else # define USE_GNU # endif // This test could be better, but it covers platforms of interest # if defined(ON_BSD) || defined(ON_SOLARIS) # define SUPPORT_PROCFS 0 # else # define SUPPORT_PROCFS 1 # endif # include # if !GLIB_CHECK_VERSION(2,28,0) # include /* Since: 2.28 */ static inline void g_list_free_full(GList * list, GDestroyNotify free_func) { g_list_foreach(list, (GFunc) free_func, NULL); g_list_free(list); } # endif +# if !GLIB_CHECK_VERSION(2,38,0) +# define g_assert_true(expr) g_assert_cmpint((expr), ==, TRUE) +# define g_assert_false(expr) g_assert_cmpint((expr), !=, TRUE) +# define g_assert_null(expr) g_assert_cmpint((expr) == NULL, ==, TRUE) +# endif + # if SUPPORT_DBUS # ifndef HAVE_DBUSBASICVALUE # include # include /** * An 8-byte struct you could use to access int64 without having * int64 support */ typedef struct { uint32_t first32; /**< first 32 bits in the 8 bytes (beware endian issues) */ uint32_t second32; /**< second 32 bits in the 8 bytes (beware endian issues) */ } DBus8ByteStruct; /** * A simple value union that lets you access bytes as if they * were various types; useful when dealing with basic types via * void pointers and varargs. * * This union also contains a pointer member (which can be used * to retrieve a string from dbus_message_iter_get_basic(), for * instance), so on future platforms it could conceivably be larger * than 8 bytes. */ typedef union { unsigned char bytes[8]; /**< as 8 individual bytes */ int16_t i16; /**< as int16 */ uint16_t u16; /**< as int16 */ int32_t i32; /**< as int32 */ uint32_t u32; /**< as int32 */ uint32_t bool_val; /**< as boolean */ # ifdef DBUS_HAVE_INT64 int64_t i64; /**< as int64 */ uint64_t u64; /**< as int64 */ # endif DBus8ByteStruct eight; /**< as 8-byte struct */ double dbl; /**< as double */ unsigned char byt; /**< as byte */ char *str; /**< as char* (string, object path or signature) */ int fd; /**< as Unix file descriptor */ } DBusBasicValue; # endif # endif /* Replacement error codes for non-linux */ # include # ifndef ENOTUNIQ # define ENOTUNIQ 190 # endif # ifndef ECOMM # define ECOMM 191 # endif # ifndef ELIBACC # define ELIBACC 192 # endif # ifndef EREMOTEIO # define EREMOTEIO 193 # endif # ifndef EUNATCH # define EUNATCH 194 # endif # ifndef ENOKEY # define ENOKEY 195 # endif # ifndef ENODATA # define ENODATA 196 # endif # ifndef ETIME # define ETIME 197 # endif # ifndef ENOSR # define ENOSR 198 # endif # ifndef ENOSTR # define ENOSTR 199 # endif # ifndef EKEYREJECTED # define EKEYREJECTED 200 # endif #endif /* PORTABILITY_H */ diff --git a/lib/common/tests/agents/pcmk_stonith_param_test.c b/lib/common/tests/agents/pcmk_stonith_param_test.c index bf509e9dc2..1e67057a82 100644 --- a/lib/common/tests/agents/pcmk_stonith_param_test.c +++ b/lib/common/tests/agents/pcmk_stonith_param_test.c @@ -1,58 +1,58 @@ /* * Copyright 2020 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include #include #include static void is_stonith_param(void) { - g_assert_cmpint(pcmk_stonith_param(NULL), ==, false); - g_assert_cmpint(pcmk_stonith_param(""), ==, false); - g_assert_cmpint(pcmk_stonith_param("unrecognized"), ==, false); - g_assert_cmpint(pcmk_stonith_param("pcmk_unrecognized"), ==, false); - g_assert_cmpint(pcmk_stonith_param("x" PCMK_STONITH_ACTION_LIMIT), ==, false); - g_assert_cmpint(pcmk_stonith_param(PCMK_STONITH_ACTION_LIMIT "x"), ==, false); + g_assert_false(pcmk_stonith_param(NULL)); + g_assert_false(pcmk_stonith_param("")); + g_assert_false(pcmk_stonith_param("unrecognized")); + g_assert_false(pcmk_stonith_param("pcmk_unrecognized")); + g_assert_false(pcmk_stonith_param("x" PCMK_STONITH_ACTION_LIMIT)); + g_assert_false(pcmk_stonith_param(PCMK_STONITH_ACTION_LIMIT "x")); - g_assert_cmpint(pcmk_stonith_param(PCMK_STONITH_ACTION_LIMIT), ==, true); - g_assert_cmpint(pcmk_stonith_param(PCMK_STONITH_DELAY_BASE), ==, true); - g_assert_cmpint(pcmk_stonith_param(PCMK_STONITH_DELAY_MAX), ==, true); - g_assert_cmpint(pcmk_stonith_param(PCMK_STONITH_HOST_ARGUMENT), ==, true); - g_assert_cmpint(pcmk_stonith_param(PCMK_STONITH_HOST_CHECK), ==, true); - g_assert_cmpint(pcmk_stonith_param(PCMK_STONITH_HOST_LIST), ==, true); - g_assert_cmpint(pcmk_stonith_param(PCMK_STONITH_HOST_MAP), ==, true); - g_assert_cmpint(pcmk_stonith_param(PCMK_STONITH_PROVIDES), ==, true); - g_assert_cmpint(pcmk_stonith_param(PCMK_STONITH_STONITH_TIMEOUT), ==, true); + g_assert_true(pcmk_stonith_param(PCMK_STONITH_ACTION_LIMIT)); + g_assert_true(pcmk_stonith_param(PCMK_STONITH_DELAY_BASE)); + g_assert_true(pcmk_stonith_param(PCMK_STONITH_DELAY_MAX)); + g_assert_true(pcmk_stonith_param(PCMK_STONITH_HOST_ARGUMENT)); + g_assert_true(pcmk_stonith_param(PCMK_STONITH_HOST_CHECK)); + g_assert_true(pcmk_stonith_param(PCMK_STONITH_HOST_LIST)); + g_assert_true(pcmk_stonith_param(PCMK_STONITH_HOST_MAP)); + g_assert_true(pcmk_stonith_param(PCMK_STONITH_PROVIDES)); + g_assert_true(pcmk_stonith_param(PCMK_STONITH_STONITH_TIMEOUT)); } static void is_stonith_action_param(void) { /* Currently, the function accepts any string not containing underbars as * the action name, so we do not need to verify particular action names. */ - g_assert_cmpint(pcmk_stonith_param("pcmk_on_unrecognized"), ==, false); - g_assert_cmpint(pcmk_stonith_param("pcmk_on_action"), ==, true); - g_assert_cmpint(pcmk_stonith_param("pcmk_on_timeout"), ==, true); - g_assert_cmpint(pcmk_stonith_param("pcmk_on_retries"), ==, true); + g_assert_false(pcmk_stonith_param("pcmk_on_unrecognized")); + g_assert_true(pcmk_stonith_param("pcmk_on_action")); + g_assert_true(pcmk_stonith_param("pcmk_on_timeout")); + g_assert_true(pcmk_stonith_param("pcmk_on_retries")); } int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); g_test_add_func("/common/utils/parse_op_key/is_stonith_param", is_stonith_param); g_test_add_func("/common/utils/parse_op_key/is_stonith_action_param", is_stonith_action_param); return g_test_run(); } diff --git a/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c b/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c index e13c983cf8..b8506c60f7 100644 --- a/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c +++ b/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c @@ -1,102 +1,102 @@ /* * Copyright 2020 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include #include #define LISTS_EQ(a, b) { \ g_assert_cmpint(g_strv_length((gchar **) (a)), ==, g_strv_length((gchar **) (b))); \ for (int i = 0; i < g_strv_length((a)); i++) { \ g_assert_cmpstr((a)[i], ==, (b)[i]); \ } \ } static void empty_input(void) { - g_assert_cmpint(pcmk__cmdline_preproc(NULL, "") == NULL, ==, TRUE); + g_assert_null(pcmk__cmdline_preproc(NULL, "")); } static void no_specials(void) { const char *argv[] = { "-a", "-b", "-c", "-d", NULL }; const gchar *expected[] = { "-a", "-b", "-c", "-d", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL); LISTS_EQ(processed, expected); g_strfreev(processed); processed = pcmk__cmdline_preproc((char **) argv, ""); LISTS_EQ(processed, expected); g_strfreev(processed); } static void single_dash(void) { const char *argv[] = { "-", NULL }; const gchar *expected[] = { "-", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL); LISTS_EQ(processed, expected); g_strfreev(processed); } static void double_dash(void) { const char *argv[] = { "-a", "--", "-bc", NULL }; const gchar *expected[] = { "-a", "--", "-bc", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL); LISTS_EQ(processed, expected); g_strfreev(processed); } static void special_args(void) { const char *argv[] = { "-aX", "-Fval", NULL }; const gchar *expected[] = { "-a", "X", "-F", "val", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, "aF"); LISTS_EQ(processed, expected); g_strfreev(processed); } static void special_arg_at_end(void) { const char *argv[] = { "-a", NULL }; const gchar *expected[] = { "-a", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, "a"); LISTS_EQ(processed, expected); g_strfreev(processed); } static void long_arg(void) { const char *argv[] = { "--blah=foo", NULL }; const gchar *expected[] = { "--blah=foo", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL); LISTS_EQ(processed, expected); g_strfreev(processed); } int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); g_test_add_func("/common/cmdline/preproc/empty_input", empty_input); g_test_add_func("/common/cmdline/preproc/no_specials", no_specials); g_test_add_func("/common/cmdline/preproc/single_dash", single_dash); g_test_add_func("/common/cmdline/preproc/double_dash", double_dash); g_test_add_func("/common/cmdline/preproc/special_args", special_args); g_test_add_func("/common/cmdline/preproc/special_arg_at_end", special_arg_at_end); g_test_add_func("/common/cmdline/preproc/long_arg", long_arg); return g_test_run(); } diff --git a/lib/common/tests/flags/pcmk_all_flags_set_test.c b/lib/common/tests/flags/pcmk_all_flags_set_test.c index a67239e97a..ebe175d7da 100644 --- a/lib/common/tests/flags/pcmk_all_flags_set_test.c +++ b/lib/common/tests/flags/pcmk_all_flags_set_test.c @@ -1,39 +1,39 @@ /* * Copyright 2020 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include #include #include static void all_set(void) { - g_assert_cmpint(pcmk_all_flags_set(0x000, 0x003), ==, false); - g_assert_cmpint(pcmk_all_flags_set(0x00f, 0x003), ==, true); - g_assert_cmpint(pcmk_all_flags_set(0x00f, 0x010), ==, false); - g_assert_cmpint(pcmk_all_flags_set(0x00f, 0x011), ==, false); - g_assert_cmpint(pcmk_all_flags_set(0x000, 0x000), ==, true); - g_assert_cmpint(pcmk_all_flags_set(0x00f, 0x000), ==, true); + g_assert_false(pcmk_all_flags_set(0x000, 0x003)); + g_assert_true(pcmk_all_flags_set(0x00f, 0x003)); + g_assert_false(pcmk_all_flags_set(0x00f, 0x010)); + g_assert_false(pcmk_all_flags_set(0x00f, 0x011)); + g_assert_true(pcmk_all_flags_set(0x000, 0x000)); + g_assert_true(pcmk_all_flags_set(0x00f, 0x000)); } static void one_is_set(void) { // pcmk_is_set() is a simple macro alias for pcmk_all_flags_set() - g_assert_cmpint(pcmk_is_set(0x00f, 0x001), ==, true); - g_assert_cmpint(pcmk_is_set(0x00f, 0x010), ==, false); + g_assert_true(pcmk_is_set(0x00f, 0x001)); + g_assert_false(pcmk_is_set(0x00f, 0x010)); } int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); g_test_add_func("/common/flags/all_set/all_set", all_set); g_test_add_func("/common/flags/all_set/is_set", one_is_set); return g_test_run(); } diff --git a/lib/common/tests/flags/pcmk_any_flags_set_test.c b/lib/common/tests/flags/pcmk_any_flags_set_test.c index e748aa6455..d465d0d626 100644 --- a/lib/common/tests/flags/pcmk_any_flags_set_test.c +++ b/lib/common/tests/flags/pcmk_any_flags_set_test.c @@ -1,32 +1,32 @@ /* * Copyright 2020 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include #include #include static void any_set(void) { - g_assert_cmpint(pcmk_any_flags_set(0x000, 0x000), ==, false); - g_assert_cmpint(pcmk_any_flags_set(0x000, 0x001), ==, false); - g_assert_cmpint(pcmk_any_flags_set(0x00f, 0x001), ==, true); - g_assert_cmpint(pcmk_any_flags_set(0x00f, 0x010), ==, false); - g_assert_cmpint(pcmk_any_flags_set(0x00f, 0x011), ==, true); - g_assert_cmpint(pcmk_any_flags_set(0x000, 0x000), ==, false); - g_assert_cmpint(pcmk_any_flags_set(0x00f, 0x000), ==, false); + g_assert_false(pcmk_any_flags_set(0x000, 0x000)); + g_assert_false(pcmk_any_flags_set(0x000, 0x001)); + g_assert_true(pcmk_any_flags_set(0x00f, 0x001)); + g_assert_false(pcmk_any_flags_set(0x00f, 0x010)); + g_assert_true(pcmk_any_flags_set(0x00f, 0x011)); + g_assert_false(pcmk_any_flags_set(0x000, 0x000)); + g_assert_false(pcmk_any_flags_set(0x00f, 0x000)); } int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); g_test_add_func("/common/flags/any_set/any_set", any_set); return g_test_run(); } diff --git a/lib/common/tests/operations/parse_op_key_test.c b/lib/common/tests/operations/parse_op_key_test.c index a527185c16..37b5d95724 100644 --- a/lib/common/tests/operations/parse_op_key_test.c +++ b/lib/common/tests/operations/parse_op_key_test.c @@ -1,219 +1,219 @@ #include #include #include static void basic(void) { char *rsc = NULL; char *ty = NULL; guint ms = 0; - g_assert_cmpint(parse_op_key("Fencing_monitor_60000", &rsc, &ty, &ms), ==, TRUE); + g_assert_true(parse_op_key("Fencing_monitor_60000", &rsc, &ty, &ms)); g_assert_cmpstr(rsc, ==, "Fencing"); g_assert_cmpstr(ty, ==, "monitor"); g_assert_cmpint(ms, ==, 60000); free(rsc); free(ty); } static void colon_in_rsc(void) { char *rsc = NULL; char *ty = NULL; guint ms = 0; - g_assert_cmpint(parse_op_key("ClusterIP:0_start_0", &rsc, &ty, &ms), ==, TRUE); + g_assert_true(parse_op_key("ClusterIP:0_start_0", &rsc, &ty, &ms)); g_assert_cmpstr(rsc, ==, "ClusterIP:0"); g_assert_cmpstr(ty, ==, "start"); g_assert_cmpint(ms, ==, 0); free(rsc); free(ty); - g_assert_cmpint(parse_op_key("imagestoreclone:1_post_notify_stop_0", &rsc, &ty, &ms), ==, TRUE); + g_assert_true(parse_op_key("imagestoreclone:1_post_notify_stop_0", &rsc, &ty, &ms)); g_assert_cmpstr(rsc, ==, "imagestoreclone:1"); g_assert_cmpstr(ty, ==, "post_notify_stop"); g_assert_cmpint(ms, ==, 0); free(rsc); free(ty); } static void dashes_in_rsc(void) { char *rsc = NULL; char *ty = NULL; guint ms = 0; - g_assert_cmpint(parse_op_key("httpd-bundle-0_monitor_30000", &rsc, &ty, &ms), ==, TRUE); + g_assert_true(parse_op_key("httpd-bundle-0_monitor_30000", &rsc, &ty, &ms)); g_assert_cmpstr(rsc, ==, "httpd-bundle-0"); g_assert_cmpstr(ty, ==, "monitor"); g_assert_cmpint(ms, ==, 30000); free(rsc); free(ty); - g_assert_cmpint(parse_op_key("httpd-bundle-ip-192.168.122.132_start_0", &rsc, &ty, &ms), ==, TRUE); + g_assert_true(parse_op_key("httpd-bundle-ip-192.168.122.132_start_0", &rsc, &ty, &ms)); g_assert_cmpstr(rsc, ==, "httpd-bundle-ip-192.168.122.132"); g_assert_cmpstr(ty, ==, "start"); g_assert_cmpint(ms, ==, 0); free(rsc); free(ty); } static void migrate_to_from(void) { char *rsc = NULL; char *ty = NULL; guint ms = 0; - g_assert_cmpint(parse_op_key("vm_migrate_from_0", &rsc, &ty, &ms), ==, TRUE); + g_assert_true(parse_op_key("vm_migrate_from_0", &rsc, &ty, &ms)); g_assert_cmpstr(rsc, ==, "vm"); g_assert_cmpstr(ty, ==, "migrate_from"); g_assert_cmpint(ms, ==, 0); free(rsc); free(ty); - g_assert_cmpint(parse_op_key("vm_migrate_to_0", &rsc, &ty, &ms), ==, TRUE); + g_assert_true(parse_op_key("vm_migrate_to_0", &rsc, &ty, &ms)); g_assert_cmpstr(rsc, ==, "vm"); g_assert_cmpstr(ty, ==, "migrate_to"); g_assert_cmpint(ms, ==, 0); free(rsc); free(ty); - g_assert_cmpint(parse_op_key("vm_idcc_devel_migrate_to_0", &rsc, &ty, &ms), ==, TRUE); + g_assert_true(parse_op_key("vm_idcc_devel_migrate_to_0", &rsc, &ty, &ms)); g_assert_cmpstr(rsc, ==, "vm_idcc_devel"); g_assert_cmpstr(ty, ==, "migrate_to"); g_assert_cmpint(ms, ==, 0); free(rsc); free(ty); } static void pre_post(void) { char *rsc = NULL; char *ty = NULL; guint ms = 0; - g_assert_cmpint(parse_op_key("rsc_drbd_7788:1_post_notify_start_0", &rsc, &ty, &ms), ==, TRUE); + g_assert_true(parse_op_key("rsc_drbd_7788:1_post_notify_start_0", &rsc, &ty, &ms)); g_assert_cmpstr(rsc, ==, "rsc_drbd_7788:1"); g_assert_cmpstr(ty, ==, "post_notify_start"); g_assert_cmpint(ms, ==, 0); free(rsc); free(ty); - g_assert_cmpint(parse_op_key("rabbitmq-bundle-clone_pre_notify_stop_0", &rsc, &ty, &ms), ==, TRUE); + g_assert_true(parse_op_key("rabbitmq-bundle-clone_pre_notify_stop_0", &rsc, &ty, &ms)); g_assert_cmpstr(rsc, ==, "rabbitmq-bundle-clone"); g_assert_cmpstr(ty, ==, "pre_notify_stop"); g_assert_cmpint(ms, ==, 0); free(rsc); free(ty); - g_assert_cmpint(parse_op_key("post_notify_start_0", &rsc, &ty, &ms), ==, TRUE); + g_assert_true(parse_op_key("post_notify_start_0", &rsc, &ty, &ms)); g_assert_cmpstr(rsc, ==, "post_notify"); g_assert_cmpstr(ty, ==, "start"); g_assert_cmpint(ms, ==, 0); free(rsc); free(ty); } static void skip_rsc(void) { char *ty = NULL; guint ms = 0; - g_assert_cmpint(parse_op_key("Fencing_monitor_60000", NULL, &ty, &ms), ==, TRUE); + g_assert_true(parse_op_key("Fencing_monitor_60000", NULL, &ty, &ms)); g_assert_cmpstr(ty, ==, "monitor"); g_assert_cmpint(ms, ==, 60000); free(ty); } static void skip_ty(void) { char *rsc = NULL; guint ms = 0; - g_assert_cmpint(parse_op_key("Fencing_monitor_60000", &rsc, NULL, &ms), ==, TRUE); + g_assert_true(parse_op_key("Fencing_monitor_60000", &rsc, NULL, &ms)); g_assert_cmpstr(rsc, ==, "Fencing"); g_assert_cmpint(ms, ==, 60000); free(rsc); } static void skip_ms(void) { char *rsc = NULL; char *ty = NULL; - g_assert_cmpint(parse_op_key("Fencing_monitor_60000", &rsc, &ty, NULL), ==, TRUE); + g_assert_true(parse_op_key("Fencing_monitor_60000", &rsc, &ty, NULL)); g_assert_cmpstr(rsc, ==, "Fencing"); g_assert_cmpstr(ty, ==, "monitor"); free(rsc); free(ty); } static void empty_input(void) { char *rsc = NULL; char *ty = NULL; guint ms = 0; - g_assert_cmpint(parse_op_key("", &rsc, &ty, &ms), ==, FALSE); - g_assert_cmpint(rsc == NULL, ==, TRUE); - g_assert_cmpint(ty == NULL, ==, TRUE); + g_assert_false(parse_op_key("", &rsc, &ty, &ms)); + g_assert_null(rsc); + g_assert_null(ty); g_assert_cmpint(ms, ==, 0); - g_assert_cmpint(parse_op_key(NULL, &rsc, &ty, &ms), ==, FALSE); - g_assert_cmpint(rsc == NULL, ==, TRUE); - g_assert_cmpint(ty == NULL, ==, TRUE); + g_assert_false(parse_op_key(NULL, &rsc, &ty, &ms)); + g_assert_null(rsc); + g_assert_null(ty); g_assert_cmpint(ms, ==, 0); } static void malformed_input(void) { char *rsc = NULL; char *ty = NULL; guint ms = 0; - g_assert_cmpint(parse_op_key("httpd-bundle-0", &rsc, &ty, &ms), ==, FALSE); - g_assert_cmpint(rsc == NULL, ==, TRUE); - g_assert_cmpint(ty == NULL, ==, TRUE); + g_assert_false(parse_op_key("httpd-bundle-0", &rsc, &ty, &ms)); + g_assert_null(rsc); + g_assert_null(ty); g_assert_cmpint(ms, ==, 0); - g_assert_cmpint(parse_op_key("httpd-bundle-0_monitor", &rsc, &ty, &ms), ==, FALSE); - g_assert_cmpint(rsc == NULL, ==, TRUE); - g_assert_cmpint(ty == NULL, ==, TRUE); + g_assert_false(parse_op_key("httpd-bundle-0_monitor", &rsc, &ty, &ms)); + g_assert_null(rsc); + g_assert_null(ty); g_assert_cmpint(ms, ==, 0); - g_assert_cmpint(parse_op_key("httpd-bundle-0_30000", &rsc, &ty, &ms), ==, FALSE); - g_assert_cmpint(rsc == NULL, ==, TRUE); - g_assert_cmpint(ty == NULL, ==, TRUE); + g_assert_false(parse_op_key("httpd-bundle-0_30000", &rsc, &ty, &ms)); + g_assert_null(rsc); + g_assert_null(ty); g_assert_cmpint(ms, ==, 0); } int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); g_test_add_func("/common/utils/parse_op_key/basic", basic); g_test_add_func("/common/utils/parse_op_key/colon_in_rsc", colon_in_rsc); g_test_add_func("/common/utils/parse_op_key/dashes_in_rsc", dashes_in_rsc); g_test_add_func("/common/utils/parse_op_key/migrate_to_from", migrate_to_from); g_test_add_func("/common/utils/parse_op_key/pre_post", pre_post); g_test_add_func("/common/utils/parse_op_key/skip_rsc", skip_rsc); g_test_add_func("/common/utils/parse_op_key/skip_ty", skip_ty); g_test_add_func("/common/utils/parse_op_key/skip_ms", skip_ms); g_test_add_func("/common/utils/parse_op_key/empty_input", empty_input); g_test_add_func("/common/utils/parse_op_key/malformed_input", malformed_input); return g_test_run(); } diff --git a/lib/common/tests/strings/pcmk__char_in_any_str_test.c b/lib/common/tests/strings/pcmk__char_in_any_str_test.c index 08f5164fc6..4fb315d3ea 100644 --- a/lib/common/tests/strings/pcmk__char_in_any_str_test.c +++ b/lib/common/tests/strings/pcmk__char_in_any_str_test.c @@ -1,46 +1,46 @@ #include #include #include #include static void empty_list(void) { - g_assert_cmpint(pcmk__char_in_any_str('x', NULL), ==, false); - g_assert_cmpint(pcmk__char_in_any_str('\0', NULL), ==, false); + g_assert_false(pcmk__char_in_any_str('x', NULL)); + g_assert_false(pcmk__char_in_any_str('\0', NULL)); } static void null_char(void) { - g_assert_cmpint(pcmk__char_in_any_str('\0', "xxx", "yyy", NULL), ==, true); - g_assert_cmpint(pcmk__char_in_any_str('\0', "", NULL), ==, true); + g_assert_true(pcmk__char_in_any_str('\0', "xxx", "yyy", NULL)); + g_assert_true(pcmk__char_in_any_str('\0', "", NULL)); } static void in_list(void) { - g_assert_cmpint(pcmk__char_in_any_str('x', "aaa", "bbb", "xxx", NULL), ==, true); + g_assert_true(pcmk__char_in_any_str('x', "aaa", "bbb", "xxx", NULL)); } static void not_in_list(void) { - g_assert_cmpint(pcmk__char_in_any_str('x', "aaa", "bbb", NULL), ==, false); - g_assert_cmpint(pcmk__char_in_any_str('A', "aaa", "bbb", NULL), ==, false); - g_assert_cmpint(pcmk__char_in_any_str('x', "", NULL), ==, false); + g_assert_false(pcmk__char_in_any_str('x', "aaa", "bbb", NULL)); + g_assert_false(pcmk__char_in_any_str('A', "aaa", "bbb", NULL)); + g_assert_false(pcmk__char_in_any_str('x', "", NULL)); } int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); g_test_add_func("/common/strings/char_in_any_str/empty_list", empty_list); g_test_add_func("/common/strings/char_in_any_str/null_char", null_char); g_test_add_func("/common/strings/char_in_any_str/in", in_list); g_test_add_func("/common/strings/char_in_any_str/not_in", not_in_list); return g_test_run(); } diff --git a/lib/common/tests/strings/pcmk__str_any_of_test.c b/lib/common/tests/strings/pcmk__str_any_of_test.c index 06596d84d5..2e2147e2d5 100644 --- a/lib/common/tests/strings/pcmk__str_any_of_test.c +++ b/lib/common/tests/strings/pcmk__str_any_of_test.c @@ -1,47 +1,47 @@ #include #include #include #include static void empty_input_list(void) { - g_assert_cmpint(pcmk__strcase_any_of("xxx", NULL), ==, false); - g_assert_cmpint(pcmk__str_any_of("xxx", NULL), ==, false); - g_assert_cmpint(pcmk__strcase_any_of("", NULL), ==, false); - g_assert_cmpint(pcmk__str_any_of("", NULL), ==, false); + g_assert_false(pcmk__strcase_any_of("xxx", NULL)); + g_assert_false(pcmk__str_any_of("xxx", NULL)); + g_assert_false(pcmk__strcase_any_of("", NULL)); + g_assert_false(pcmk__str_any_of("", NULL)); } static void empty_string(void) { - g_assert_cmpint(pcmk__strcase_any_of("", "xxx", "yyy", NULL), ==, false); - g_assert_cmpint(pcmk__str_any_of("", "xxx", "yyy", NULL), ==, false); - g_assert_cmpint(pcmk__strcase_any_of(NULL, "xxx", "yyy", NULL), ==, false); - g_assert_cmpint(pcmk__str_any_of(NULL, "xxx", "yyy", NULL), ==, false); + g_assert_false(pcmk__strcase_any_of("", "xxx", "yyy", NULL)); + g_assert_false(pcmk__str_any_of("", "xxx", "yyy", NULL)); + g_assert_false(pcmk__strcase_any_of(NULL, "xxx", "yyy", NULL)); + g_assert_false(pcmk__str_any_of(NULL, "xxx", "yyy", NULL)); } static void in_list(void) { - g_assert_cmpint(pcmk__strcase_any_of("xxx", "aaa", "bbb", "xxx", NULL), ==, true); - g_assert_cmpint(pcmk__str_any_of("xxx", "aaa", "bbb", "xxx", NULL), ==, true); - g_assert_cmpint(pcmk__strcase_any_of("XXX", "aaa", "bbb", "xxx", NULL), ==, true); + g_assert_true(pcmk__strcase_any_of("xxx", "aaa", "bbb", "xxx", NULL)); + g_assert_true(pcmk__str_any_of("xxx", "aaa", "bbb", "xxx", NULL)); + g_assert_true(pcmk__strcase_any_of("XXX", "aaa", "bbb", "xxx", NULL)); } static void not_in_list(void) { - g_assert_cmpint(pcmk__strcase_any_of("xxx", "aaa", "bbb", NULL), ==, false); - g_assert_cmpint(pcmk__str_any_of("xxx", "aaa", "bbb", NULL), ==, false); - g_assert_cmpint(pcmk__str_any_of("AAA", "aaa", "bbb", NULL), ==, false); + g_assert_false(pcmk__strcase_any_of("xxx", "aaa", "bbb", NULL)); + g_assert_false(pcmk__str_any_of("xxx", "aaa", "bbb", NULL)); + g_assert_false(pcmk__str_any_of("AAA", "aaa", "bbb", NULL)); } int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); g_test_add_func("/common/strings/any_of/empty_list", empty_input_list); g_test_add_func("/common/strings/any_of/empty_string", empty_string); g_test_add_func("/common/strings/any_of/in", in_list); g_test_add_func("/common/strings/any_of/not_in", not_in_list); return g_test_run(); } diff --git a/lib/common/tests/strings/pcmk__strcmp_test.c b/lib/common/tests/strings/pcmk__strcmp_test.c index 5c01fe9808..d23ed7ed6a 100644 --- a/lib/common/tests/strings/pcmk__strcmp_test.c +++ b/lib/common/tests/strings/pcmk__strcmp_test.c @@ -1,78 +1,78 @@ #include #include #include #include static void same_pointer(void) { const char *s1 = "abcd"; const char *s2 = "wxyz"; g_assert_cmpint(pcmk__strcmp(s1, s1, pcmk__str_none), ==, 0); - g_assert_cmpint(pcmk__str_eq(s1, s1, pcmk__str_none), ==, true); + g_assert_true(pcmk__str_eq(s1, s1, pcmk__str_none)); g_assert_cmpint(pcmk__strcmp(s1, s2, pcmk__str_none), !=, 0); - g_assert_cmpint(pcmk__str_eq(s1, s2, pcmk__str_none), ==, false); + g_assert_false(pcmk__str_eq(s1, s2, pcmk__str_none)); g_assert_cmpint(pcmk__strcmp(NULL, NULL, pcmk__str_none), ==, 0); } static void one_is_null(void) { const char *s1 = "abcd"; g_assert_cmpint(pcmk__strcmp(s1, NULL, pcmk__str_null_matches), ==, 0); - g_assert_cmpint(pcmk__str_eq(s1, NULL, pcmk__str_null_matches), ==, true); + g_assert_true(pcmk__str_eq(s1, NULL, pcmk__str_null_matches)); g_assert_cmpint(pcmk__strcmp(NULL, s1, pcmk__str_null_matches), ==, 0); g_assert_cmpint(pcmk__strcmp(s1, NULL, pcmk__str_none), >, 0); - g_assert_cmpint(pcmk__str_eq(s1, NULL, pcmk__str_none), ==, false); + g_assert_false(pcmk__str_eq(s1, NULL, pcmk__str_none)); g_assert_cmpint(pcmk__strcmp(NULL, s1, pcmk__str_none), <, 0); } static void case_matters(void) { const char *s1 = "abcd"; const char *s2 = "ABCD"; g_assert_cmpint(pcmk__strcmp(s1, s2, pcmk__str_none), >, 0); - g_assert_cmpint(pcmk__str_eq(s1, s2, pcmk__str_none), ==, false); + g_assert_false(pcmk__str_eq(s1, s2, pcmk__str_none)); g_assert_cmpint(pcmk__strcmp(s2, s1, pcmk__str_none), <, 0); } static void case_insensitive(void) { const char *s1 = "abcd"; const char *s2 = "ABCD"; g_assert_cmpint(pcmk__strcmp(s1, s2, pcmk__str_casei), ==, 0); - g_assert_cmpint(pcmk__str_eq(s1, s2, pcmk__str_casei), ==, true); + g_assert_true(pcmk__str_eq(s1, s2, pcmk__str_casei)); } static void regex(void) { const char *s1 = "abcd"; const char *s2 = "ABCD"; g_assert_cmpint(pcmk__strcmp(NULL, "a..d", pcmk__str_regex), ==, 1); g_assert_cmpint(pcmk__strcmp(s1, NULL, pcmk__str_regex), ==, 1); g_assert_cmpint(pcmk__strcmp(s1, "a..d", pcmk__str_regex), ==, 0); - g_assert_cmpint(pcmk__str_eq(s1, "a..d", pcmk__str_regex), ==, true); + g_assert_true(pcmk__str_eq(s1, "a..d", pcmk__str_regex)); g_assert_cmpint(pcmk__strcmp(s1, "xxyy", pcmk__str_regex), !=, 0); - g_assert_cmpint(pcmk__str_eq(s1, "xxyy", pcmk__str_regex), ==, false); + g_assert_false(pcmk__str_eq(s1, "xxyy", pcmk__str_regex)); g_assert_cmpint(pcmk__strcmp(s2, "a..d", pcmk__str_regex|pcmk__str_casei), ==, 0); - g_assert_cmpint(pcmk__str_eq(s2, "a..d", pcmk__str_regex|pcmk__str_casei), ==, true); + g_assert_true(pcmk__str_eq(s2, "a..d", pcmk__str_regex|pcmk__str_casei)); g_assert_cmpint(pcmk__strcmp(s2, "a..d", pcmk__str_regex), !=, 0); - g_assert_cmpint(pcmk__str_eq(s2, "a..d", pcmk__str_regex), ==, false); + g_assert_false(pcmk__str_eq(s2, "a..d", pcmk__str_regex)); g_assert_cmpint(pcmk__strcmp(s2, "*ab", pcmk__str_regex), ==, 1); } int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); g_test_add_func("/common/strings/strcmp/same_pointer", same_pointer); g_test_add_func("/common/strings/strcmp/one_is_null", one_is_null); g_test_add_func("/common/strings/strcmp/case_matters", case_matters); g_test_add_func("/common/strings/strcmp/case_insensitive", case_insensitive); g_test_add_func("/common/strings/strcmp/regex", regex); return g_test_run(); } diff --git a/lib/common/tests/utils/pcmk_str_is_infinity_test.c b/lib/common/tests/utils/pcmk_str_is_infinity_test.c index b1216774c4..18362a7208 100644 --- a/lib/common/tests/utils/pcmk_str_is_infinity_test.c +++ b/lib/common/tests/utils/pcmk_str_is_infinity_test.c @@ -1,56 +1,56 @@ #include #include #include #include static void uppercase_str_passes(void) { - g_assert_cmpint(pcmk_str_is_infinity("INFINITY"), ==, true); - g_assert_cmpint(pcmk_str_is_infinity("+INFINITY"), ==, true); + g_assert_true(pcmk_str_is_infinity("INFINITY")); + g_assert_true(pcmk_str_is_infinity("+INFINITY")); } static void mixed_case_str_fails(void) { - g_assert_cmpint(pcmk_str_is_infinity("infinity"), ==, false); - g_assert_cmpint(pcmk_str_is_infinity("+infinity"), ==, false); - g_assert_cmpint(pcmk_str_is_infinity("Infinity"), ==, false); - g_assert_cmpint(pcmk_str_is_infinity("+Infinity"), ==, false); + g_assert_false(pcmk_str_is_infinity("infinity")); + g_assert_false(pcmk_str_is_infinity("+infinity")); + g_assert_false(pcmk_str_is_infinity("Infinity")); + g_assert_false(pcmk_str_is_infinity("+Infinity")); } static void added_whitespace_fails(void) { - g_assert_cmpint(pcmk_str_is_infinity(" INFINITY"), ==, false); - g_assert_cmpint(pcmk_str_is_infinity("INFINITY "), ==, false); - g_assert_cmpint(pcmk_str_is_infinity(" INFINITY "), ==, false); - g_assert_cmpint(pcmk_str_is_infinity("+ INFINITY"), ==, false); + g_assert_false(pcmk_str_is_infinity(" INFINITY")); + g_assert_false(pcmk_str_is_infinity("INFINITY ")); + g_assert_false(pcmk_str_is_infinity(" INFINITY ")); + g_assert_false(pcmk_str_is_infinity("+ INFINITY")); } static void empty_str_fails(void) { - g_assert_cmpint(pcmk_str_is_infinity(NULL), ==, false); - g_assert_cmpint(pcmk_str_is_infinity(""), ==, false); + g_assert_false(pcmk_str_is_infinity(NULL)); + g_assert_false(pcmk_str_is_infinity("")); } static void minus_infinity_fails(void) { - g_assert_cmpint(pcmk_str_is_infinity("-INFINITY"), ==, false); + g_assert_false(pcmk_str_is_infinity("-INFINITY")); } int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); g_test_add_func("/common/utils/infinity/uppercase", uppercase_str_passes); g_test_add_func("/common/utils/infinity/mixed_case", mixed_case_str_fails); g_test_add_func("/common/utils/infinity/whitespace", added_whitespace_fails); g_test_add_func("/common/utils/infinity/empty", empty_str_fails); g_test_add_func("/common/utils/infinity/minus_infinity", minus_infinity_fails); return g_test_run(); } diff --git a/lib/common/tests/utils/pcmk_str_is_minus_infinity_test.c b/lib/common/tests/utils/pcmk_str_is_minus_infinity_test.c index f879da6adf..e58d5121ba 100644 --- a/lib/common/tests/utils/pcmk_str_is_minus_infinity_test.c +++ b/lib/common/tests/utils/pcmk_str_is_minus_infinity_test.c @@ -1,53 +1,53 @@ #include #include #include #include static void uppercase_str_passes(void) { - g_assert_cmpint(pcmk_str_is_minus_infinity("-INFINITY"), ==, true); + g_assert_true(pcmk_str_is_minus_infinity("-INFINITY")); } static void mixed_case_str_fails(void) { - g_assert_cmpint(pcmk_str_is_minus_infinity("-infinity"), ==, false); - g_assert_cmpint(pcmk_str_is_minus_infinity("-Infinity"), ==, false); + g_assert_false(pcmk_str_is_minus_infinity("-infinity")); + g_assert_false(pcmk_str_is_minus_infinity("-Infinity")); } static void added_whitespace_fails(void) { - g_assert_cmpint(pcmk_str_is_minus_infinity(" -INFINITY"), ==, false); - g_assert_cmpint(pcmk_str_is_minus_infinity("-INFINITY "), ==, false); - g_assert_cmpint(pcmk_str_is_minus_infinity(" -INFINITY "), ==, false); - g_assert_cmpint(pcmk_str_is_minus_infinity("- INFINITY"), ==, false); + g_assert_false(pcmk_str_is_minus_infinity(" -INFINITY")); + g_assert_false(pcmk_str_is_minus_infinity("-INFINITY ")); + g_assert_false(pcmk_str_is_minus_infinity(" -INFINITY ")); + g_assert_false(pcmk_str_is_minus_infinity("- INFINITY")); } static void empty_str_fails(void) { - g_assert_cmpint(pcmk_str_is_minus_infinity(NULL), ==, false); - g_assert_cmpint(pcmk_str_is_minus_infinity(""), ==, false); + g_assert_false(pcmk_str_is_minus_infinity(NULL)); + g_assert_false(pcmk_str_is_minus_infinity("")); } static void infinity_fails(void) { - g_assert_cmpint(pcmk_str_is_minus_infinity("INFINITY"), ==, false); + g_assert_false(pcmk_str_is_minus_infinity("INFINITY")); } int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); g_test_add_func("/common/utils/minus_infinity/uppercase", uppercase_str_passes); g_test_add_func("/common/utils/minus_infinity/mixed_case", mixed_case_str_fails); g_test_add_func("/common/utils/minus_infinity/whitespace", added_whitespace_fails); g_test_add_func("/common/utils/minus_infinity/empty", empty_str_fails); g_test_add_func("/common/utils/minus_infinity/infinity", infinity_fails); return g_test_run(); }