pacemaker  2.1.4-dc6eb4362
Scalable High-Availability cluster resource manager
crm_meta_value_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2022 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 #include <crm/msg_xml.h>
12 
13 #include <stdarg.h>
14 #include <stddef.h>
15 #include <stdint.h>
16 #include <setjmp.h>
17 #include <cmocka.h>
18 
19 #include <glib.h>
20 
21 static void
22 empty_params(void **state)
23 {
24  GHashTable *tbl = pcmk__strkey_table(free, free);
25 
26  assert_null(crm_meta_value(NULL, NULL));
27  assert_null(crm_meta_value(tbl, NULL));
28 
29  g_hash_table_destroy(tbl);
30 }
31 
32 static void
33 key_not_in_table(void **state)
34 {
35  GHashTable *tbl = pcmk__strkey_table(free, free);
36 
37  assert_null(crm_meta_value(tbl, XML_RSC_ATTR_NOTIFY));
38  assert_null(crm_meta_value(tbl, XML_RSC_ATTR_STICKINESS));
39 
40  g_hash_table_destroy(tbl);
41 }
42 
43 static void
44 key_in_table(void **state)
45 {
46  GHashTable *tbl = pcmk__strkey_table(free, free);
47 
48  g_hash_table_insert(tbl, crm_meta_name(XML_RSC_ATTR_NOTIFY), strdup("1"));
49  g_hash_table_insert(tbl, crm_meta_name(XML_RSC_ATTR_STICKINESS), strdup("2"));
50 
51  assert_string_equal(crm_meta_value(tbl, XML_RSC_ATTR_NOTIFY), "1");
52  assert_string_equal(crm_meta_value(tbl, XML_RSC_ATTR_STICKINESS), "2");
53 
54  g_hash_table_destroy(tbl);
55 }
56 
57 int main(int argc, char **argv)
58 {
59  const struct CMUnitTest tests[] = {
60  cmocka_unit_test(empty_params),
61  cmocka_unit_test(key_not_in_table),
62  cmocka_unit_test(key_in_table),
63  };
64 
65  cmocka_set_message_output(CM_OUTPUT_TAP);
66  return cmocka_run_group_tests(tests, NULL, NULL);
67 }
const char * crm_meta_value(GHashTable *hash, const char *field)
Definition: utils.c:461
#define XML_RSC_ATTR_STICKINESS
Definition: msg_xml.h:242
char * crm_meta_name(const char *field)
Definition: utils.c:439
int main(int argc, char **argv)
#define XML_RSC_ATTR_NOTIFY
Definition: msg_xml.h:241
GHashTable * pcmk__strkey_table(GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func)
Definition: strings.c:611