This source file includes following definitions.
- null_input_table
- empty_input_table
- regular_input_table
- main
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <stdarg.h>
13 #include <stddef.h>
14 #include <stdint.h>
15 #include <setjmp.h>
16 #include <cmocka.h>
17
18 #include <glib.h>
19
20 static void
21 null_input_table(void **state)
22 {
23 assert_null(pcmk__str_table_dup(NULL));
24 }
25
26 static void
27 empty_input_table(void **state)
28 {
29 GHashTable *tbl = pcmk__strkey_table(free, free);
30 GHashTable *copy = NULL;
31
32 copy = pcmk__str_table_dup(tbl);
33 assert_int_equal(g_hash_table_size(copy), 0);
34
35 g_hash_table_destroy(tbl);
36 g_hash_table_destroy(copy);
37 }
38
39 static void
40 regular_input_table(void **state)
41 {
42 GHashTable *tbl = pcmk__strkey_table(free, free);
43 GHashTable *copy = NULL;
44
45 g_hash_table_insert(tbl, strdup("abc"), strdup("123"));
46 g_hash_table_insert(tbl, strdup("def"), strdup("456"));
47 g_hash_table_insert(tbl, strdup("ghi"), strdup("789"));
48
49 copy = pcmk__str_table_dup(tbl);
50 assert_int_equal(g_hash_table_size(copy), 3);
51
52 assert_string_equal(g_hash_table_lookup(tbl, "abc"), "123");
53 assert_string_equal(g_hash_table_lookup(tbl, "def"), "456");
54 assert_string_equal(g_hash_table_lookup(tbl, "ghi"), "789");
55
56 g_hash_table_destroy(tbl);
57 g_hash_table_destroy(copy);
58 }
59
60 int main(int argc, char **argv) {
61 const struct CMUnitTest tests[] = {
62 cmocka_unit_test(null_input_table),
63 cmocka_unit_test(empty_input_table),
64 cmocka_unit_test(regular_input_table),
65 };
66
67 cmocka_set_message_output(CM_OUTPUT_TAP);
68 return cmocka_run_group_tests(tests, NULL, NULL);
69 }