diff --git a/lib/common/tests/flags/pcmk__clear_flags_as.c b/lib/common/tests/flags/pcmk__clear_flags_as.c index 0f3ffb49aa..a476adf3dd 100644 --- a/lib/common/tests/flags/pcmk__clear_flags_as.c +++ b/lib/common/tests/flags/pcmk__clear_flags_as.c @@ -1,45 +1,45 @@ /* * 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 static void clear_none(void) { - g_assert(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", - "test", 0x0f0, 0x00f, NULL) == 0x0f0); - g_assert(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", - "test", 0x0f0, 0xf0f, NULL) == 0x0f0); + g_assert_cmphex(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", + "test", 0x0f0, 0x00f, NULL), ==, 0x0f0); + g_assert_cmphex(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", + "test", 0x0f0, 0xf0f, NULL), ==, 0x0f0); } static void clear_some(void) { - g_assert(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", - "test", 0x0f0, 0x020, NULL) == 0x0d0); - g_assert(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", - "test", 0x0f0, 0x030, NULL) == 0x0c0); + g_assert_cmphex(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", + "test", 0x0f0, 0x020, NULL), ==, 0x0d0); + g_assert_cmphex(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", + "test", 0x0f0, 0x030, NULL), ==, 0x0c0); } static void clear_all(void) { - g_assert(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", - "test", 0x0f0, 0x0f0, NULL) == 0x000); - g_assert(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", - "test", 0x0f0, 0xfff, NULL) == 0x000); + g_assert_cmphex(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", + "test", 0x0f0, 0x0f0, NULL), ==, 0x000); + g_assert_cmphex(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", + "test", 0x0f0, 0xfff, NULL), ==, 0x000); } int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); g_test_add_func("/common/flags/clear/clear_none", clear_none); g_test_add_func("/common/flags/clear/clear_some", clear_some); g_test_add_func("/common/flags/clear/clear_all", clear_all); return g_test_run(); } diff --git a/lib/common/tests/flags/pcmk__set_flags_as.c b/lib/common/tests/flags/pcmk__set_flags_as.c index e8ae4742df..9a8292cfe8 100644 --- a/lib/common/tests/flags/pcmk__set_flags_as.c +++ b/lib/common/tests/flags/pcmk__set_flags_as.c @@ -1,29 +1,29 @@ /* * 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 static void set_flags(void) { - g_assert(pcmk__set_flags_as(__func__, __LINE__, LOG_TRACE, "Test", - "test", 0x0f0, 0x00f, NULL) == 0x0ff); - g_assert(pcmk__set_flags_as(__func__, __LINE__, LOG_TRACE, "Test", - "test", 0x0f0, 0xf0f, NULL) == 0xfff); - g_assert(pcmk__set_flags_as(__func__, __LINE__, LOG_TRACE, "Test", - "test", 0x0f0, 0xfff, NULL) == 0xfff); + g_assert_cmphex(pcmk__set_flags_as(__func__, __LINE__, LOG_TRACE, "Test", + "test", 0x0f0, 0x00f, NULL), ==, 0x0ff); + g_assert_cmphex(pcmk__set_flags_as(__func__, __LINE__, LOG_TRACE, "Test", + "test", 0x0f0, 0xf0f, NULL), ==, 0xfff); + g_assert_cmphex(pcmk__set_flags_as(__func__, __LINE__, LOG_TRACE, "Test", + "test", 0x0f0, 0xfff, NULL), ==, 0xfff); } int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); g_test_add_func("/common/flags/set/set_flags", set_flags); return g_test_run(); } diff --git a/lib/common/tests/flags/pcmk_all_flags_set.c b/lib/common/tests/flags/pcmk_all_flags_set.c index 222ed10d88..a67239e97a 100644 --- a/lib/common/tests/flags/pcmk_all_flags_set.c +++ b/lib/common/tests/flags/pcmk_all_flags_set.c @@ -1,37 +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(pcmk_all_flags_set(0x000, 0x003) == false); - g_assert(pcmk_all_flags_set(0x00f, 0x003) == true); - g_assert(pcmk_all_flags_set(0x00f, 0x010) == false); - g_assert(pcmk_all_flags_set(0x00f, 0x011) == false); - g_assert(pcmk_all_flags_set(0x000, 0x000) == true); - g_assert(pcmk_all_flags_set(0x00f, 0x000) == true); + 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); } static void one_is_set(void) { // pcmk_is_set() is a simple macro alias for pcmk_all_flags_set() - g_assert(pcmk_is_set(0x00f, 0x001) == true); - g_assert(pcmk_is_set(0x00f, 0x010) == false); + g_assert_cmpint(pcmk_is_set(0x00f, 0x001), ==, true); + g_assert_cmpint(pcmk_is_set(0x00f, 0x010), ==, false); } 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.c b/lib/common/tests/flags/pcmk_any_flags_set.c index f2f468c147..e748aa6455 100644 --- a/lib/common/tests/flags/pcmk_any_flags_set.c +++ b/lib/common/tests/flags/pcmk_any_flags_set.c @@ -1,30 +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(pcmk_any_flags_set(0x000, 0x000) == false); - g_assert(pcmk_any_flags_set(0x000, 0x001) == false); - g_assert(pcmk_any_flags_set(0x00f, 0x001) == true); - g_assert(pcmk_any_flags_set(0x00f, 0x010) == false); - g_assert(pcmk_any_flags_set(0x00f, 0x011) == true); - g_assert(pcmk_any_flags_set(0x000, 0x000) == false); - g_assert(pcmk_any_flags_set(0x00f, 0x000) == false); + 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); } 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.c b/lib/common/tests/operations/parse_op_key.c index f2affed319..a527185c16 100644 --- a/lib/common/tests/operations/parse_op_key.c +++ b/lib/common/tests/operations/parse_op_key.c @@ -1,218 +1,219 @@ +#include #include #include static void basic(void) { char *rsc = NULL; char *ty = NULL; guint ms = 0; - g_assert_true(parse_op_key("Fencing_monitor_60000", &rsc, &ty, &ms)); + g_assert_cmpint(parse_op_key("Fencing_monitor_60000", &rsc, &ty, &ms), ==, TRUE); 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_true(parse_op_key("ClusterIP:0_start_0", &rsc, &ty, &ms)); + g_assert_cmpint(parse_op_key("ClusterIP:0_start_0", &rsc, &ty, &ms), ==, TRUE); g_assert_cmpstr(rsc, ==, "ClusterIP:0"); g_assert_cmpstr(ty, ==, "start"); g_assert_cmpint(ms, ==, 0); free(rsc); free(ty); - g_assert_true(parse_op_key("imagestoreclone:1_post_notify_stop_0", &rsc, &ty, &ms)); + g_assert_cmpint(parse_op_key("imagestoreclone:1_post_notify_stop_0", &rsc, &ty, &ms), ==, TRUE); 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_true(parse_op_key("httpd-bundle-0_monitor_30000", &rsc, &ty, &ms)); + g_assert_cmpint(parse_op_key("httpd-bundle-0_monitor_30000", &rsc, &ty, &ms), ==, TRUE); g_assert_cmpstr(rsc, ==, "httpd-bundle-0"); g_assert_cmpstr(ty, ==, "monitor"); g_assert_cmpint(ms, ==, 30000); free(rsc); free(ty); - g_assert_true(parse_op_key("httpd-bundle-ip-192.168.122.132_start_0", &rsc, &ty, &ms)); + g_assert_cmpint(parse_op_key("httpd-bundle-ip-192.168.122.132_start_0", &rsc, &ty, &ms), ==, TRUE); 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_true(parse_op_key("vm_migrate_from_0", &rsc, &ty, &ms)); + g_assert_cmpint(parse_op_key("vm_migrate_from_0", &rsc, &ty, &ms), ==, TRUE); g_assert_cmpstr(rsc, ==, "vm"); g_assert_cmpstr(ty, ==, "migrate_from"); g_assert_cmpint(ms, ==, 0); free(rsc); free(ty); - g_assert_true(parse_op_key("vm_migrate_to_0", &rsc, &ty, &ms)); + g_assert_cmpint(parse_op_key("vm_migrate_to_0", &rsc, &ty, &ms), ==, TRUE); g_assert_cmpstr(rsc, ==, "vm"); g_assert_cmpstr(ty, ==, "migrate_to"); g_assert_cmpint(ms, ==, 0); free(rsc); free(ty); - g_assert_true(parse_op_key("vm_idcc_devel_migrate_to_0", &rsc, &ty, &ms)); + g_assert_cmpint(parse_op_key("vm_idcc_devel_migrate_to_0", &rsc, &ty, &ms), ==, TRUE); 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_true(parse_op_key("rsc_drbd_7788:1_post_notify_start_0", &rsc, &ty, &ms)); + g_assert_cmpint(parse_op_key("rsc_drbd_7788:1_post_notify_start_0", &rsc, &ty, &ms), ==, TRUE); 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_true(parse_op_key("rabbitmq-bundle-clone_pre_notify_stop_0", &rsc, &ty, &ms)); + g_assert_cmpint(parse_op_key("rabbitmq-bundle-clone_pre_notify_stop_0", &rsc, &ty, &ms), ==, TRUE); 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_true(parse_op_key("post_notify_start_0", &rsc, &ty, &ms)); + g_assert_cmpint(parse_op_key("post_notify_start_0", &rsc, &ty, &ms), ==, TRUE); 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_true(parse_op_key("Fencing_monitor_60000", NULL, &ty, &ms)); + g_assert_cmpint(parse_op_key("Fencing_monitor_60000", NULL, &ty, &ms), ==, TRUE); 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_true(parse_op_key("Fencing_monitor_60000", &rsc, NULL, &ms)); + g_assert_cmpint(parse_op_key("Fencing_monitor_60000", &rsc, NULL, &ms), ==, TRUE); 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_true(parse_op_key("Fencing_monitor_60000", &rsc, &ty, NULL)); + g_assert_cmpint(parse_op_key("Fencing_monitor_60000", &rsc, &ty, NULL), ==, TRUE); 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_false(parse_op_key("", &rsc, &ty, &ms)); - g_assert_true(rsc == NULL); - g_assert_true(ty == NULL); + g_assert_cmpint(parse_op_key("", &rsc, &ty, &ms), ==, FALSE); + g_assert_cmpint(rsc == NULL, ==, TRUE); + g_assert_cmpint(ty == NULL, ==, TRUE); g_assert_cmpint(ms, ==, 0); - g_assert_false(parse_op_key(NULL, &rsc, &ty, &ms)); - g_assert_true(rsc == NULL); - g_assert_true(ty == NULL); + 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_cmpint(ms, ==, 0); } static void malformed_input(void) { char *rsc = NULL; char *ty = NULL; guint ms = 0; - g_assert_false(parse_op_key("httpd-bundle-0", &rsc, &ty, &ms)); - g_assert(rsc == NULL); - g_assert(ty == NULL); + 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_cmpint(ms, ==, 0); - g_assert_false(parse_op_key("httpd-bundle-0_monitor", &rsc, &ty, &ms)); - g_assert(rsc == NULL); - g_assert(ty == NULL); + 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_cmpint(ms, ==, 0); - g_assert_false(parse_op_key("httpd-bundle-0_30000", &rsc, &ty, &ms)); - g_assert(rsc == NULL); - g_assert(ty == NULL); + 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_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__btoa.c b/lib/common/tests/strings/pcmk__btoa.c index 96f25c8702..240cb3aa7e 100644 --- a/lib/common/tests/strings/pcmk__btoa.c +++ b/lib/common/tests/strings/pcmk__btoa.c @@ -1,26 +1,26 @@ /* * 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 static void btoa(void) { - g_assert(strcmp(pcmk__btoa(false), "false") == 0); - g_assert(strcmp(pcmk__btoa(true), "true") == 0); - g_assert(strcmp(pcmk__btoa(1 == 0), "false") == 0); + g_assert_cmpstr(pcmk__btoa(false), ==, "false"); + g_assert_cmpstr(pcmk__btoa(true), ==, "true"); + g_assert_cmpstr(pcmk__btoa(1 == 0), ==, "false"); } int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); g_test_add_func("/common/strings/btoa/btoa", btoa); return g_test_run(); } diff --git a/lib/common/tests/strings/pcmk__char_in_any_str.c b/lib/common/tests/strings/pcmk__char_in_any_str.c index 7bc3d1bdc1..08f5164fc6 100644 --- a/lib/common/tests/strings/pcmk__char_in_any_str.c +++ b/lib/common/tests/strings/pcmk__char_in_any_str.c @@ -1,44 +1,46 @@ +#include +#include #include #include static void empty_list(void) { - g_assert_false(pcmk__char_in_any_str('x', NULL)); - g_assert_false(pcmk__char_in_any_str('\0', NULL)); + g_assert_cmpint(pcmk__char_in_any_str('x', NULL), ==, false); + g_assert_cmpint(pcmk__char_in_any_str('\0', NULL), ==, false); } static void null_char(void) { - g_assert_true(pcmk__char_in_any_str('\0', "xxx", "yyy", NULL)); - g_assert_true(pcmk__char_in_any_str('\0', "", NULL)); + g_assert_cmpint(pcmk__char_in_any_str('\0', "xxx", "yyy", NULL), ==, true); + g_assert_cmpint(pcmk__char_in_any_str('\0', "", NULL), ==, true); } static void in_list(void) { - g_assert_true(pcmk__char_in_any_str('x', "aaa", "bbb", "xxx", NULL)); + g_assert_cmpint(pcmk__char_in_any_str('x', "aaa", "bbb", "xxx", NULL), ==, true); } static void not_in_list(void) { - 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)); + 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); } 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.c b/lib/common/tests/strings/pcmk__str_any_of.c index 0a45638a9d..06596d84d5 100644 --- a/lib/common/tests/strings/pcmk__str_any_of.c +++ b/lib/common/tests/strings/pcmk__str_any_of.c @@ -1,45 +1,47 @@ +#include +#include #include #include static void empty_input_list(void) { - 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)); + 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); } static void empty_string(void) { - 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)); + 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); } static void in_list(void) { - 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)); + 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); } static void not_in_list(void) { - 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)); + 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); } 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.c b/lib/common/tests/strings/pcmk__strcmp.c index 296b1a7952..5c01fe9808 100644 --- a/lib/common/tests/strings/pcmk__strcmp.c +++ b/lib/common/tests/strings/pcmk__strcmp.c @@ -1,76 +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_true(pcmk__str_eq(s1, s1, pcmk__str_none)); + g_assert_cmpint(pcmk__str_eq(s1, s1, pcmk__str_none), ==, true); g_assert_cmpint(pcmk__strcmp(s1, s2, pcmk__str_none), !=, 0); - g_assert_false(pcmk__str_eq(s1, s2, pcmk__str_none)); + g_assert_cmpint(pcmk__str_eq(s1, s2, pcmk__str_none), ==, false); 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_true(pcmk__str_eq(s1, NULL, pcmk__str_null_matches)); + g_assert_cmpint(pcmk__str_eq(s1, NULL, pcmk__str_null_matches), ==, true); 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_false(pcmk__str_eq(s1, NULL, pcmk__str_none)); + g_assert_cmpint(pcmk__str_eq(s1, NULL, pcmk__str_none), ==, false); 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_false(pcmk__str_eq(s1, s2, pcmk__str_none)); + g_assert_cmpint(pcmk__str_eq(s1, s2, pcmk__str_none), ==, false); 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_true(pcmk__str_eq(s1, s2, pcmk__str_casei)); + g_assert_cmpint(pcmk__str_eq(s1, s2, pcmk__str_casei), ==, true); } 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_true(pcmk__str_eq(s1, "a..d", pcmk__str_regex)); + g_assert_cmpint(pcmk__str_eq(s1, "a..d", pcmk__str_regex), ==, true); g_assert_cmpint(pcmk__strcmp(s1, "xxyy", pcmk__str_regex), !=, 0); - g_assert_false(pcmk__str_eq(s1, "xxyy", pcmk__str_regex)); + g_assert_cmpint(pcmk__str_eq(s1, "xxyy", pcmk__str_regex), ==, false); g_assert_cmpint(pcmk__strcmp(s2, "a..d", pcmk__str_regex|pcmk__str_casei), ==, 0); - g_assert_true(pcmk__str_eq(s2, "a..d", pcmk__str_regex|pcmk__str_casei)); + g_assert_cmpint(pcmk__str_eq(s2, "a..d", pcmk__str_regex|pcmk__str_casei), ==, true); g_assert_cmpint(pcmk__strcmp(s2, "a..d", pcmk__str_regex), !=, 0); - g_assert_false(pcmk__str_eq(s2, "a..d", pcmk__str_regex)); + g_assert_cmpint(pcmk__str_eq(s2, "a..d", pcmk__str_regex), ==, false); 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.c b/lib/common/tests/utils/pcmk_str_is_infinity.c index 72e26cb195..b1216774c4 100644 --- a/lib/common/tests/utils/pcmk_str_is_infinity.c +++ b/lib/common/tests/utils/pcmk_str_is_infinity.c @@ -1,54 +1,56 @@ +#include +#include #include #include static void uppercase_str_passes(void) { - g_assert_true(pcmk_str_is_infinity("INFINITY")); - g_assert_true(pcmk_str_is_infinity("+INFINITY")); + g_assert_cmpint(pcmk_str_is_infinity("INFINITY"), ==, true); + g_assert_cmpint(pcmk_str_is_infinity("+INFINITY"), ==, true); } static void mixed_case_str_fails(void) { - 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")); + 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); } static void added_whitespace_fails(void) { - 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")); + 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); } static void empty_str_fails(void) { - g_assert_false(pcmk_str_is_infinity(NULL)); - g_assert_false(pcmk_str_is_infinity("")); + g_assert_cmpint(pcmk_str_is_infinity(NULL), ==, false); + g_assert_cmpint(pcmk_str_is_infinity(""), ==, false); } static void minus_infinity_fails(void) { - g_assert_false(pcmk_str_is_infinity("-INFINITY")); + g_assert_cmpint(pcmk_str_is_infinity("-INFINITY"), ==, false); } 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.c b/lib/common/tests/utils/pcmk_str_is_minus_infinity.c index fe8b080fbe..f879da6adf 100644 --- a/lib/common/tests/utils/pcmk_str_is_minus_infinity.c +++ b/lib/common/tests/utils/pcmk_str_is_minus_infinity.c @@ -1,51 +1,53 @@ +#include +#include #include #include static void uppercase_str_passes(void) { - g_assert_true(pcmk_str_is_minus_infinity("-INFINITY")); + g_assert_cmpint(pcmk_str_is_minus_infinity("-INFINITY"), ==, true); } static void mixed_case_str_fails(void) { - g_assert_false(pcmk_str_is_minus_infinity("-infinity")); - g_assert_false(pcmk_str_is_minus_infinity("-Infinity")); + g_assert_cmpint(pcmk_str_is_minus_infinity("-infinity"), ==, false); + g_assert_cmpint(pcmk_str_is_minus_infinity("-Infinity"), ==, false); } static void added_whitespace_fails(void) { - 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")); + 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); } static void empty_str_fails(void) { - g_assert_false(pcmk_str_is_minus_infinity(NULL)); - g_assert_false(pcmk_str_is_minus_infinity("")); + g_assert_cmpint(pcmk_str_is_minus_infinity(NULL), ==, false); + g_assert_cmpint(pcmk_str_is_minus_infinity(""), ==, false); } static void infinity_fails(void) { - g_assert_false(pcmk_str_is_minus_infinity("INFINITY")); + g_assert_cmpint(pcmk_str_is_minus_infinity("INFINITY"), ==, false); } 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(); }