This source file includes following definitions.
- different_lists
- remove_first_item
- remove_middle_item
- remove_last_item
- remove_all_items
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/common/lists_internal.h>
14
15 #include <glib.h>
16
17 static void
18 different_lists(void **state)
19 {
20 GList *from = NULL;
21 GList *items = NULL;
22 GList *result = NULL;
23
24 from = g_list_append(from, strdup("abc"));
25 from = g_list_append(from, strdup("def"));
26 from = g_list_append(from, strdup("ghi"));
27
28 items = g_list_append(items, strdup("123"));
29 items = g_list_append(items, strdup("456"));
30
31 result = pcmk__subtract_lists(from, items, (GCompareFunc) strcmp);
32
33 assert_int_equal(g_list_length(result), 3);
34 assert_string_equal(g_list_nth_data(result, 0), "abc");
35 assert_string_equal(g_list_nth_data(result, 1), "def");
36 assert_string_equal(g_list_nth_data(result, 2), "ghi");
37
38 g_list_free(result);
39 g_list_free_full(from, free);
40 g_list_free_full(items, free);
41 }
42
43 static void
44 remove_first_item(void **state)
45 {
46 GList *from = NULL;
47 GList *items = NULL;
48 GList *result = NULL;
49
50 from = g_list_append(from, strdup("abc"));
51 from = g_list_append(from, strdup("def"));
52 from = g_list_append(from, strdup("ghi"));
53
54 items = g_list_append(items, strdup("abc"));
55
56 result = pcmk__subtract_lists(from, items, (GCompareFunc) strcmp);
57
58 assert_int_equal(g_list_length(result), 2);
59 assert_string_equal(g_list_nth_data(result, 0), "def");
60 assert_string_equal(g_list_nth_data(result, 1), "ghi");
61
62 g_list_free(result);
63 g_list_free_full(from, free);
64 g_list_free_full(items, free);
65 }
66
67 static void
68 remove_middle_item(void **state)
69 {
70 GList *from = NULL;
71 GList *items = NULL;
72 GList *result = NULL;
73
74 from = g_list_append(from, strdup("abc"));
75 from = g_list_append(from, strdup("def"));
76 from = g_list_append(from, strdup("ghi"));
77
78 items = g_list_append(items, strdup("def"));
79
80 result = pcmk__subtract_lists(from, items, (GCompareFunc) strcmp);
81
82 assert_int_equal(g_list_length(result), 2);
83 assert_string_equal(g_list_nth_data(result, 0), "abc");
84 assert_string_equal(g_list_nth_data(result, 1), "ghi");
85
86 g_list_free(result);
87 g_list_free_full(from, free);
88 g_list_free_full(items, free);
89 }
90
91 static void
92 remove_last_item(void **state)
93 {
94 GList *from = NULL;
95 GList *items = NULL;
96 GList *result = NULL;
97
98 from = g_list_append(from, strdup("abc"));
99 from = g_list_append(from, strdup("def"));
100 from = g_list_append(from, strdup("ghi"));
101
102 items = g_list_append(items, strdup("ghi"));
103
104 result = pcmk__subtract_lists(from, items, (GCompareFunc) strcmp);
105
106 assert_int_equal(g_list_length(result), 2);
107 assert_string_equal(g_list_nth_data(result, 0), "abc");
108 assert_string_equal(g_list_nth_data(result, 1), "def");
109
110 g_list_free(result);
111 g_list_free_full(from, free);
112 g_list_free_full(items, free);
113 }
114
115 static void
116 remove_all_items(void **state)
117 {
118 GList *from = NULL;
119 GList *items = NULL;
120 GList *result = NULL;
121
122 from = g_list_append(from, strdup("abc"));
123 from = g_list_append(from, strdup("def"));
124 from = g_list_append(from, strdup("ghi"));
125
126 items = g_list_append(items, strdup("abc"));
127 items = g_list_append(items, strdup("def"));
128 items = g_list_append(items, strdup("ghi"));
129
130 result = pcmk__subtract_lists(from, items, (GCompareFunc) strcmp);
131
132 assert_int_equal(g_list_length(result), 0);
133
134 g_list_free(result);
135 g_list_free_full(from, free);
136 g_list_free_full(items, free);
137 }
138
139 PCMK__UNIT_TEST(NULL, NULL,
140 cmocka_unit_test(different_lists),
141 cmocka_unit_test(remove_first_item),
142 cmocka_unit_test(remove_middle_item),
143 cmocka_unit_test(remove_last_item),
144 cmocka_unit_test(remove_all_items))