pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
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
16static void
17null_input_table(void **state)
18{
19 assert_null(pcmk__str_table_dup(NULL));
20}
21
22static void
23empty_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
35static void
36regular_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
56PCMK__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))
GHashTable * pcmk__str_table_dup(GHashTable *old_table)
Definition strings.c:768
GHashTable * pcmk__strkey_table(GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func)
Definition strings.c:685
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)