This source file includes following definitions.
- empty_list
- non_null_list
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/common/unittest_internal.h>
13 #include <crm/pengine/internal.h>
14
15 static void
16 empty_list(void **state)
17 {
18 assert_null(pcmk__find_node_in_list(NULL, NULL));
19 assert_null(pcmk__find_node_in_list(NULL, "cluster1"));
20 }
21
22 static void
23 non_null_list(void **state)
24 {
25 GList *nodes = NULL;
26
27 pcmk_node_t *a = pcmk__assert_alloc(1, sizeof(pcmk_node_t));
28 pcmk_node_t *b = pcmk__assert_alloc(1, sizeof(pcmk_node_t));
29
30 a->details = pcmk__assert_alloc(1, sizeof(struct pe_node_shared_s));
31 a->details->uname = "cluster1";
32 b->details = pcmk__assert_alloc(1, sizeof(struct pe_node_shared_s));
33 b->details->uname = "cluster2";
34
35 nodes = g_list_append(nodes, a);
36 nodes = g_list_append(nodes, b);
37
38 assert_ptr_equal(a, pcmk__find_node_in_list(nodes, "cluster1"));
39 assert_null(pcmk__find_node_in_list(nodes, "cluster10"));
40 assert_null(pcmk__find_node_in_list(nodes, "nodecluster1"));
41 assert_ptr_equal(b, pcmk__find_node_in_list(nodes, "CLUSTER2"));
42 assert_null(pcmk__find_node_in_list(nodes, "xyz"));
43
44 free(a->details);
45 free(a);
46 free(b->details);
47 free(b);
48 g_list_free(nodes);
49 }
50
51 PCMK__UNIT_TEST(NULL, NULL,
52 cmocka_unit_test(empty_list),
53 cmocka_unit_test(non_null_list))