about summary refs log tree commit diff stats
path: root/tests/unittests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unittests')
-rw-r--r--tests/unittests/test_roster_list.c265
-rw-r--r--tests/unittests/test_roster_list.h19
-rw-r--r--tests/unittests/unittests.c19
3 files changed, 288 insertions, 15 deletions
diff --git a/tests/unittests/test_roster_list.c b/tests/unittests/test_roster_list.c
index 5b626e74..f12361e4 100644
--- a/tests/unittests/test_roster_list.c
+++ b/tests/unittests/test_roster_list.c
@@ -288,7 +288,7 @@ void find_twice_returns_first_when_two_match_and_reset(void **state)
     roster_free();
 }
 
-void add_contact_with_no_group_returns_no_groups(void **state)
+void add_contact_with_no_group(void **state)
 {
     roster_init();
     roster_add("person@server.org", NULL, NULL, NULL, FALSE);
@@ -301,7 +301,7 @@ void add_contact_with_no_group_returns_no_groups(void **state)
     roster_free();
 }
 
-void add_contact_with_group_returns_group(void **state)
+void add_contact_with_group(void **state)
 {
     roster_init();
 
@@ -321,7 +321,7 @@ void add_contact_with_group_returns_group(void **state)
     roster_free();
 }
 
-void add_contact_with_two_groups_returns_groups(void **state)
+void add_contact_with_two_groups(void **state)
 {
     roster_init();
 
@@ -345,7 +345,7 @@ void add_contact_with_two_groups_returns_groups(void **state)
     roster_free();
 }
 
-void add_contact_with_three_groups_returns_groups(void **state)
+void add_contact_with_three_groups(void **state)
 {
     roster_init();
 
@@ -373,7 +373,7 @@ void add_contact_with_three_groups_returns_groups(void **state)
     roster_free();
 }
 
-void add_contact_with_three_groups_update_adding_two_returns_groups(void **state)
+void add_contact_with_three_groups_update_adding_two(void **state)
 {
     roster_init();
 
@@ -414,3 +414,258 @@ void add_contact_with_three_groups_update_adding_two_returns_groups(void **state
     roster_clear();
     roster_free();
 }
+
+void add_contact_with_three_groups_update_removing_one(void **state)
+{
+    roster_init();
+
+    GSList *groups1 = NULL;
+    groups1 = g_slist_append(groups1, strdup("friends"));
+    groups1 = g_slist_append(groups1, strdup("work"));
+    groups1 = g_slist_append(groups1, strdup("stuff"));
+    roster_add("person@server.org", NULL, groups1, NULL, FALSE);
+
+    GSList *groups2 = NULL;
+    groups2 = g_slist_append(groups2, strdup("friends"));
+    groups2 = g_slist_append(groups2, strdup("stuff"));
+    roster_update("person@server.org", NULL, groups2, NULL, FALSE);
+
+    GSList *groups_res = roster_get_groups();
+    assert_int_equal(g_slist_length(groups_res), 2);
+
+    GSList *found = g_slist_find_custom(groups_res, "friends", g_strcmp0);
+    assert_true(found != NULL);
+    assert_string_equal(found->data, "friends");
+    found = g_slist_find_custom(groups_res, "stuff", g_strcmp0);
+    assert_true(found != NULL);
+    assert_string_equal(found->data, "stuff");
+
+    g_slist_free_full(groups_res, g_free);
+    roster_clear();
+    roster_free();
+}
+
+void add_contact_with_three_groups_update_removing_two(void **state)
+{
+    roster_init();
+
+    GSList *groups1 = NULL;
+    groups1 = g_slist_append(groups1, strdup("friends"));
+    groups1 = g_slist_append(groups1, strdup("work"));
+    groups1 = g_slist_append(groups1, strdup("stuff"));
+    roster_add("person@server.org", NULL, groups1, NULL, FALSE);
+
+    GSList *groups2 = NULL;
+    groups2 = g_slist_append(groups2, strdup("stuff"));
+    roster_update("person@server.org", NULL, groups2, NULL, FALSE);
+
+    GSList *groups_res = roster_get_groups();
+    assert_int_equal(g_slist_length(groups_res), 1);
+
+    GSList *found = g_slist_find_custom(groups_res, "stuff", g_strcmp0);
+    assert_true(found != NULL);
+    assert_string_equal(found->data, "stuff");
+
+    g_slist_free_full(groups_res, g_free);
+    roster_clear();
+    roster_free();
+}
+
+void add_contact_with_three_groups_update_removing_three(void **state)
+{
+    roster_init();
+
+    GSList *groups1 = NULL;
+    groups1 = g_slist_append(groups1, strdup("friends"));
+    groups1 = g_slist_append(groups1, strdup("work"));
+    groups1 = g_slist_append(groups1, strdup("stuff"));
+    roster_add("person@server.org", NULL, groups1, NULL, FALSE);
+
+    roster_update("person@server.org", NULL, NULL, NULL, FALSE);
+
+    GSList *groups_res = roster_get_groups();
+    assert_int_equal(g_slist_length(groups_res), 0);
+
+    g_slist_free_full(groups_res, g_free);
+    roster_clear();
+    roster_free();
+}
+
+void add_contact_with_three_groups_update_two_new(void **state)
+{
+    roster_init();
+
+    GSList *groups1 = NULL;
+    groups1 = g_slist_append(groups1, strdup("friends"));
+    groups1 = g_slist_append(groups1, strdup("work"));
+    groups1 = g_slist_append(groups1, strdup("stuff"));
+    roster_add("person@server.org", NULL, groups1, NULL, FALSE);
+
+    GSList *groups2 = NULL;
+    groups2 = g_slist_append(groups2, strdup("newfriends"));
+    groups2 = g_slist_append(groups2, strdup("somepeople"));
+    roster_update("person@server.org", NULL, groups2, NULL, FALSE);
+
+    GSList *groups_res = roster_get_groups();
+    assert_int_equal(g_slist_length(groups_res), 2);
+
+    GSList *found = g_slist_find_custom(groups_res, "newfriends", g_strcmp0);
+    assert_true(found != NULL);
+    found = g_slist_find_custom(groups_res, "somepeople", g_strcmp0);
+    assert_true(found != NULL);
+
+    g_slist_free_full(groups_res, g_free);
+    roster_clear();
+    roster_free();
+}
+
+void add_remove_contact_groups(void **state)
+{
+    roster_init();
+
+    GSList *groups1 = NULL;
+    groups1 = g_slist_append(groups1, strdup("friends"));
+    groups1 = g_slist_append(groups1, strdup("work"));
+    groups1 = g_slist_append(groups1, strdup("stuff"));
+    roster_add("person@server.org", NULL, groups1, NULL, FALSE);
+
+    roster_remove("person@server.org", "person@server.org");
+
+    GSList *groups_res = roster_get_groups();
+    assert_int_equal(g_slist_length(groups_res), 0);
+
+    g_slist_free_full(groups_res, g_free);
+    roster_clear();
+    roster_free();
+}
+
+void add_contacts_with_different_groups(void **state)
+{
+    roster_init();
+
+    GSList *groups1 = NULL;
+    groups1 = g_slist_append(groups1, strdup("friends"));
+    groups1 = g_slist_append(groups1, strdup("work"));
+    groups1 = g_slist_append(groups1, strdup("stuff"));
+    roster_add("person@server.org", NULL, groups1, NULL, FALSE);
+
+    GSList *groups2 = NULL;
+    groups2 = g_slist_append(groups2, strdup("newfriends"));
+    groups2 = g_slist_append(groups2, strdup("somepeople"));
+    roster_add("bob@server.org", NULL, groups2, NULL, FALSE);
+
+    GSList *groups_res = roster_get_groups();
+    assert_int_equal(g_slist_length(groups_res), 5);
+
+    GSList *found = g_slist_find_custom(groups_res, "friends", g_strcmp0);
+    assert_true(found != NULL);
+    found = g_slist_find_custom(groups_res, "work", g_strcmp0);
+    assert_true(found != NULL);
+    found = g_slist_find_custom(groups_res, "stuff", g_strcmp0);
+    assert_true(found != NULL);
+    found = g_slist_find_custom(groups_res, "newfriends", g_strcmp0);
+    assert_true(found != NULL);
+    found = g_slist_find_custom(groups_res, "somepeople", g_strcmp0);
+    assert_true(found != NULL);
+
+    g_slist_free_full(groups_res, g_free);
+    roster_clear();
+    roster_free();
+}
+
+void add_contacts_with_same_groups(void **state)
+{
+    roster_init();
+
+    GSList *groups1 = NULL;
+    groups1 = g_slist_append(groups1, strdup("friends"));
+    groups1 = g_slist_append(groups1, strdup("work"));
+    groups1 = g_slist_append(groups1, strdup("stuff"));
+    roster_add("person@server.org", NULL, groups1, NULL, FALSE);
+
+    GSList *groups2 = NULL;
+    groups2 = g_slist_append(groups2, strdup("friends"));
+    groups2 = g_slist_append(groups2, strdup("work"));
+    groups2 = g_slist_append(groups2, strdup("stuff"));
+    roster_add("bob@server.org", NULL, groups2, NULL, FALSE);
+
+    GSList *groups_res = roster_get_groups();
+    assert_int_equal(g_slist_length(groups_res), 3);
+
+    GSList *found = g_slist_find_custom(groups_res, "friends", g_strcmp0);
+    assert_true(found != NULL);
+    found = g_slist_find_custom(groups_res, "work", g_strcmp0);
+    assert_true(found != NULL);
+    found = g_slist_find_custom(groups_res, "stuff", g_strcmp0);
+    assert_true(found != NULL);
+
+    g_slist_free_full(groups_res, g_free);
+    roster_clear();
+    roster_free();
+}
+
+void add_contacts_with_overlapping_groups(void **state)
+{
+    roster_init();
+
+    GSList *groups1 = NULL;
+    groups1 = g_slist_append(groups1, strdup("friends"));
+    groups1 = g_slist_append(groups1, strdup("work"));
+    groups1 = g_slist_append(groups1, strdup("stuff"));
+    roster_add("person@server.org", NULL, groups1, NULL, FALSE);
+
+    GSList *groups2 = NULL;
+    groups2 = g_slist_append(groups2, strdup("friends"));
+    groups2 = g_slist_append(groups2, strdup("work"));
+    groups2 = g_slist_append(groups2, strdup("different"));
+    roster_add("bob@server.org", NULL, groups2, NULL, FALSE);
+
+    GSList *groups_res = roster_get_groups();
+    assert_int_equal(g_slist_length(groups_res), 4);
+
+    GSList *found = g_slist_find_custom(groups_res, "friends", g_strcmp0);
+    assert_true(found != NULL);
+    found = g_slist_find_custom(groups_res, "work", g_strcmp0);
+    assert_true(found != NULL);
+    found = g_slist_find_custom(groups_res, "stuff", g_strcmp0);
+    assert_true(found != NULL);
+    found = g_slist_find_custom(groups_res, "different", g_strcmp0);
+    assert_true(found != NULL);
+
+    g_slist_free_full(groups_res, g_free);
+    roster_clear();
+    roster_free();
+}
+
+void remove_contact_with_remaining_in_group(void **state)
+{
+    roster_init();
+
+    GSList *groups1 = NULL;
+    groups1 = g_slist_append(groups1, strdup("friends"));
+    groups1 = g_slist_append(groups1, strdup("work"));
+    groups1 = g_slist_append(groups1, strdup("stuff"));
+    roster_add("person@server.org", NULL, groups1, NULL, FALSE);
+
+    GSList *groups2 = NULL;
+    groups2 = g_slist_append(groups2, strdup("friends"));
+    groups2 = g_slist_append(groups2, strdup("work"));
+    groups2 = g_slist_append(groups2, strdup("different"));
+    roster_add("bob@server.org", NULL, groups2, NULL, FALSE);
+
+    roster_remove("bob@server.org", "bob@server.org");
+
+    GSList *groups_res = roster_get_groups();
+    assert_int_equal(g_slist_length(groups_res), 3);
+
+    GSList *found = g_slist_find_custom(groups_res, "friends", g_strcmp0);
+    assert_true(found != NULL);
+    found = g_slist_find_custom(groups_res, "work", g_strcmp0);
+    assert_true(found != NULL);
+    found = g_slist_find_custom(groups_res, "stuff", g_strcmp0);
+    assert_true(found != NULL);
+
+    g_slist_free_full(groups_res, g_free);
+    roster_clear();
+    roster_free();
+}
diff --git a/tests/unittests/test_roster_list.h b/tests/unittests/test_roster_list.h
index d0da560a..464ecd55 100644
--- a/tests/unittests/test_roster_list.h
+++ b/tests/unittests/test_roster_list.h
@@ -16,8 +16,17 @@ void find_on_empty_returns_null(void **state);
 void find_twice_returns_second_when_two_match(void **state);
 void find_five_times_finds_fifth(void **state);
 void find_twice_returns_first_when_two_match_and_reset(void **state);
-void add_contact_with_no_group_returns_no_groups(void **state);
-void add_contact_with_group_returns_group(void **state);
-void add_contact_with_two_groups_returns_groups(void **state);
-void add_contact_with_three_groups_returns_groups(void **state);
-void add_contact_with_three_groups_update_adding_two_returns_groups(void **state);
+void add_contact_with_no_group(void **state);
+void add_contact_with_group(void **state);
+void add_contact_with_two_groups(void **state);
+void add_contact_with_three_groups(void **state);
+void add_contact_with_three_groups_update_adding_two(void **state);
+void add_contact_with_three_groups_update_removing_one(void **state);
+void add_contact_with_three_groups_update_removing_two(void **state);
+void add_contact_with_three_groups_update_removing_three(void **state);
+void add_contact_with_three_groups_update_two_new(void **state);
+void add_remove_contact_groups(void **state);
+void add_contacts_with_different_groups(void **state);
+void add_contacts_with_same_groups(void **state);
+void add_contacts_with_overlapping_groups(void **state);
+void remove_contact_with_remaining_in_group(void **state);
diff --git a/tests/unittests/unittests.c b/tests/unittests/unittests.c
index 55008b9c..e511df9d 100644
--- a/tests/unittests/unittests.c
+++ b/tests/unittests/unittests.c
@@ -210,11 +210,20 @@ int main(int argc, char* argv[]) {
         unit_test(find_twice_returns_second_when_two_match),
         unit_test(find_five_times_finds_fifth),
         unit_test(find_twice_returns_first_when_two_match_and_reset),
-        unit_test(add_contact_with_no_group_returns_no_groups),
-        unit_test(add_contact_with_group_returns_group),
-        unit_test(add_contact_with_two_groups_returns_groups),
-        unit_test(add_contact_with_three_groups_returns_groups),
-        unit_test(add_contact_with_three_groups_update_adding_two_returns_groups),
+        unit_test(add_contact_with_no_group),
+        unit_test(add_contact_with_group),
+        unit_test(add_contact_with_two_groups),
+        unit_test(add_contact_with_three_groups),
+        unit_test(add_contact_with_three_groups_update_adding_two),
+        unit_test(add_contact_with_three_groups_update_removing_one),
+        unit_test(add_contact_with_three_groups_update_removing_two),
+        unit_test(add_contact_with_three_groups_update_removing_three),
+        unit_test(add_contact_with_three_groups_update_two_new),
+        unit_test(add_remove_contact_groups),
+        unit_test(add_contacts_with_different_groups),
+        unit_test(add_contacts_with_same_groups),
+        unit_test(add_contacts_with_overlapping_groups),
+        unit_test(remove_contact_with_remaining_in_group),
 
         unit_test_setup_teardown(returns_false_when_chat_session_does_not_exist,
             init_chat_sessions,
/install.sh?id=1876fe93dd4a772ba8a6894f0ba0780b0171a5f2'>1876fe93 ^
e4409c40 ^
1876fe93 ^
e4409c40 ^

1876fe93 ^

e4409c40 ^



1876fe93 ^
e4409c40 ^

1876fe93 ^
e4409c40 ^
1876fe93 ^
e4409c40 ^
d83d4af1 ^
e4409c40 ^

1876fe93 ^
e4409c40 ^




1876fe93 ^
e4409c40 ^
1876fe93 ^



e4409c40 ^



0cb11571 ^
e4409c40 ^
1876fe93 ^
e4409c40 ^
1876fe93 ^
e4409c40 ^




0cb11571 ^
e4409c40 ^
1876fe93 ^
e4409c40 ^
d83d4af1 ^
e4409c40 ^

1876fe93 ^
e4409c40 ^

1876fe93 ^
e4409c40 ^
1876fe93 ^
e4409c40 ^
1876fe93 ^

e4409c40 ^
1876fe93 ^


e4409c40 ^






1876fe93 ^






















e4409c40 ^


1876fe93 ^
e4409c40 ^


1876fe93 ^
e4409c40 ^
1876fe93 ^


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294