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 assert_null(pe_find_node_any(NULL, NULL, NULL));
18 assert_null(pe_find_node_any(NULL, NULL, "cluster1"));
19 assert_null(pe_find_node_any(NULL, "id1", NULL));
20 assert_null(pe_find_node_any(NULL, "id1", "cluster1"));
21 }
22
23 static void
24 non_null_list(void **state) {
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 a->details->id = "id1";
33 b->details = pcmk__assert_alloc(1, sizeof(struct pe_node_shared_s));
34 b->details->uname = "cluster2";
35 b->details->id = "id2";
36
37 nodes = g_list_append(nodes, a);
38 nodes = g_list_append(nodes, b);
39
40 assert_ptr_equal(b, pe_find_node_any(nodes, "id2", NULL));
41 assert_ptr_equal(b, pe_find_node_any(nodes, "ID2", NULL));
42
43 assert_ptr_equal(a, pe_find_node_any(nodes, "xyz", "cluster1"));
44 assert_ptr_equal(a, pe_find_node_any(nodes, NULL, "cluster1"));
45
46 assert_null(pe_find_node_any(nodes, "id10", NULL));
47 assert_null(pe_find_node_any(nodes, "nodeid1", NULL));
48 assert_null(pe_find_node_any(nodes, NULL, "cluster10"));
49 assert_null(pe_find_node_any(nodes, NULL, "nodecluster1"));
50 assert_null(pe_find_node_any(nodes, "id3", "cluster3"));
51 assert_null(pe_find_node_any(nodes, NULL, NULL));
52
53 free(a->details);
54 free(a);
55 free(b->details);
56 free(b);
57 g_list_free(nodes);
58 }
59
60 PCMK__UNIT_TEST(NULL, NULL,
61 cmocka_unit_test(empty_list),
62 cmocka_unit_test(non_null_list))