pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
pcmk__str_table_dup_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 General Public License version 2
7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
13 
14 #include <glib.h>
15 
16 static void
17 null_input_table(void **state)
18 {
19  assert_null(pcmk__str_table_dup(NULL));
20 }
21 
22 static void
23 empty_input_table(void **state)
24 {
25  GHashTable *tbl = pcmk__strkey_table(free, free);
26  GHashTable *copy = NULL;
27 
28  copy = pcmk__str_table_dup(tbl);
29  assert_int_equal(g_hash_table_size(copy), 0);
30 
31  g_hash_table_destroy(tbl);
32  g_hash_table_destroy(copy);
33 }
34 
35 static void
36 regular_input_table(void **state)
37 {
38  GHashTable *tbl = pcmk__strkey_table(free, free);
39  GHashTable *copy = NULL;
40 
41  g_hash_table_insert(tbl, strdup("abc"), strdup("123"));
42  g_hash_table_insert(tbl, strdup("def"), strdup("456"));
43  g_hash_table_insert(tbl, strdup("ghi"), strdup("789"));
44 
45  copy = pcmk__str_table_dup(tbl);
46  assert_int_equal(g_hash_table_size(copy), 3);
47 
48  assert_string_equal(g_hash_table_lookup(tbl, "abc"), "123");
49  assert_string_equal(g_hash_table_lookup(tbl, "def"), "456");
50  assert_string_equal(g_hash_table_lookup(tbl, "ghi"), "789");
51 
52  g_hash_table_destroy(tbl);
53  g_hash_table_destroy(copy);
54 }
55 
56 PCMK__UNIT_TEST(NULL, NULL,
57  cmocka_unit_test(null_input_table),
58  cmocka_unit_test(empty_input_table),
59  cmocka_unit_test(regular_input_table))
PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(bad_input), cmocka_unit_test(not_found), cmocka_unit_test(find_attrB), cmocka_unit_test(find_attrA_matching))
GHashTable * pcmk__strkey_table(GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func)
Definition: strings.c:608
GHashTable * pcmk__str_table_dup(GHashTable *old_table)
Definition: strings.c:672