This source file includes following definitions.
- null_input_table
- empty_input_table
- regular_input_table
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/common/unittest_internal.h>
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))