Mon, 28 Nov 2022 23:48:33 -0600
Split PurpleContactInfo out of PurpleContact
This change separates all of the data away from the runtime information which
makes it easier to store contacts with everything.
Testing Done:
Ran the unit tests and sent a few messages with ircv3 and demo protocols.
Reviewed at https://reviews.imfreedom.org/r/2091/
| 41749 | 1 | /* |
| 2 | * Purple - Internet Messaging Library | |
| 3 | * Copyright (C) Pidgin Developers <devel@pidgin.im> | |
| 4 | * | |
| 5 | * This library is free software; you can redistribute it and/or | |
| 6 | * modify it under the terms of the GNU Lesser General Public | |
| 7 | * License as published by the Free Software Foundation; either | |
| 8 | * version 2 of the License, or (at your option) any later version. | |
| 9 | * | |
| 10 | * This library is distributed in the hope that it will be useful, | |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | * Lesser General Public License for more details. | |
| 14 | * | |
| 15 | * You should have received a copy of the GNU Lesser General Public | |
| 16 | * License along with this library; if not, see <https://www.gnu.org/licenses/>. | |
| 17 | */ | |
| 18 | ||
| 19 | #include <glib.h> | |
| 20 | ||
| 21 | #include <purple.h> | |
| 22 | ||
| 23 | #include "test_ui.h" | |
| 24 | ||
| 25 | /****************************************************************************** | |
| 26 | * Callbacks | |
| 27 | *****************************************************************************/ | |
| 28 | static void | |
| 29 | test_purple_person_items_changed_cb(G_GNUC_UNUSED GListModel *model, | |
| 30 | G_GNUC_UNUSED guint position, | |
| 31 | G_GNUC_UNUSED guint removed, | |
| 32 | G_GNUC_UNUSED guint added, | |
| 33 | gpointer data) | |
| 34 | { | |
| 35 | gboolean *called = data; | |
| 36 | ||
| 37 | *called = TRUE; | |
| 38 | } | |
| 39 | ||
| 40 | static void | |
| 41 | test_purple_person_notify_cb(G_GNUC_UNUSED GObject *obj, | |
| 42 | G_GNUC_UNUSED GParamSpec *pspec, | |
| 43 | gpointer data) | |
| 44 | { | |
| 45 | gboolean *called = data; | |
| 46 | ||
| 47 | *called = TRUE; | |
| 48 | } | |
| 49 | ||
| 50 | /****************************************************************************** | |
| 51 | * Tests | |
| 52 | *****************************************************************************/ | |
| 53 | static void | |
| 54 | test_purple_person_new(void) { | |
| 55 | PurplePerson *person = NULL; | |
| 56 | ||
| 57 | person = purple_person_new(); | |
| 58 | ||
| 59 | g_assert_true(PURPLE_IS_PERSON(person)); | |
| 60 | ||
| 61 | g_clear_object(&person); | |
| 62 | } | |
| 63 | ||
| 64 | static void | |
| 65 | test_purple_person_properties(void) { | |
| 66 | PurpleContact *person = NULL; | |
| 67 | PurpleTags *tags = NULL; | |
| 68 | GdkPixbuf *avatar = NULL; | |
| 69 | GdkPixbuf *avatar1 = NULL; | |
| 70 | gchar *id = NULL; | |
| 71 | gchar *alias = NULL; | |
| 72 | ||
| 73 | /* Create our avatar for testing. */ | |
| 74 | avatar = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 1, 1); | |
| 75 | ||
| 76 | /* Use g_object_new so we can test setting properties by name. All of them | |
| 77 | * call the setter methods, so by doing it this way we exercise more of the | |
| 78 | * code. | |
| 79 | */ | |
| 80 | person = g_object_new( | |
| 81 | PURPLE_TYPE_PERSON, | |
| 82 | "alias", "alias", | |
| 83 | "avatar", avatar, | |
| 84 | NULL); | |
| 85 | ||
| 86 | /* Now use g_object_get to read all of the properties. */ | |
| 87 | g_object_get(person, | |
| 88 | "id", &id, | |
| 89 | "alias", &alias, | |
| 90 | "avatar", &avatar1, | |
| 91 | "tags", &tags, | |
| 92 | NULL); | |
| 93 | ||
| 94 | /* Compare all the things. */ | |
| 95 | g_assert_nonnull(id); | |
| 96 | g_assert_cmpstr(alias, ==, "alias"); | |
| 97 | g_assert_true(avatar1 == avatar); | |
| 98 | g_assert_nonnull(tags); | |
| 99 | ||
| 100 | /* Free/unref all the things. */ | |
| 101 | g_clear_pointer(&id, g_free); | |
| 102 | g_clear_pointer(&alias, g_free); | |
| 103 | g_clear_object(&avatar1); | |
| 104 | g_clear_object(&tags); | |
| 105 | ||
| 106 | g_clear_object(&avatar); | |
| 107 | g_clear_object(&person); | |
| 108 | } | |
| 109 | ||
| 110 | static void | |
| 111 | test_purple_person_contacts_single(void) { | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
112 | PurpleContactInfo *info = NULL; |
| 41749 | 113 | PurplePerson *person = NULL; |
|
41761
9dc5d28fca99
When a Contact is added to a Person set the Contact's Person to that Person.
Gary Kramlich <grim@reaperworld.com>
parents:
41749
diff
changeset
|
114 | PurplePerson *person1 = NULL; |
| 41749 | 115 | guint n_items = 0; |
| 116 | gboolean removed = FALSE; | |
| 117 | gboolean changed = FALSE; | |
| 118 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
119 | info = purple_contact_info_new("id"); |
| 41749 | 120 | person = purple_person_new(); |
| 121 | g_signal_connect(person, "items-changed", | |
| 122 | G_CALLBACK(test_purple_person_items_changed_cb), &changed); | |
| 123 | ||
| 124 | n_items = g_list_model_get_n_items(G_LIST_MODEL(person)); | |
| 125 | g_assert_cmpuint(n_items, ==, 0); | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
126 | purple_person_add_contact_info(person, info); |
| 41749 | 127 | n_items = g_list_model_get_n_items(G_LIST_MODEL(person)); |
| 128 | g_assert_cmpuint(n_items, ==, 1); | |
| 129 | g_assert_true(changed); | |
| 130 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
131 | person1 = purple_contact_info_get_person(info); |
|
41761
9dc5d28fca99
When a Contact is added to a Person set the Contact's Person to that Person.
Gary Kramlich <grim@reaperworld.com>
parents:
41749
diff
changeset
|
132 | g_assert_true(person1 == person); |
|
9dc5d28fca99
When a Contact is added to a Person set the Contact's Person to that Person.
Gary Kramlich <grim@reaperworld.com>
parents:
41749
diff
changeset
|
133 | |
| 41749 | 134 | changed = FALSE; |
| 135 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
136 | removed = purple_person_remove_contact_info(person, info); |
| 41749 | 137 | g_assert_true(removed); |
| 138 | n_items = g_list_model_get_n_items(G_LIST_MODEL(person)); | |
| 139 | g_assert_cmpuint(n_items, ==, 0); | |
| 140 | g_assert_true(changed); | |
| 141 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
142 | person1 = purple_contact_info_get_person(info); |
|
41761
9dc5d28fca99
When a Contact is added to a Person set the Contact's Person to that Person.
Gary Kramlich <grim@reaperworld.com>
parents:
41749
diff
changeset
|
143 | g_assert_null(person1); |
|
9dc5d28fca99
When a Contact is added to a Person set the Contact's Person to that Person.
Gary Kramlich <grim@reaperworld.com>
parents:
41749
diff
changeset
|
144 | |
| 41749 | 145 | g_clear_object(&person); |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
146 | g_clear_object(&info); |
| 41749 | 147 | } |
| 148 | ||
| 149 | static void | |
| 150 | test_purple_person_contacts_multiple(void) { | |
| 151 | PurplePerson *person = NULL; | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
152 | GPtrArray *infos = NULL; |
| 41749 | 153 | guint n_items = 0; |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
154 | const gint n_infos = 5; |
| 41749 | 155 | gboolean changed = FALSE; |
| 156 | ||
| 157 | person = purple_person_new(); | |
| 158 | g_signal_connect(person, "items-changed", | |
| 159 | G_CALLBACK(test_purple_person_items_changed_cb), &changed); | |
| 160 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
161 | infos = g_ptr_array_new_full(n_infos, g_object_unref); |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
162 | for(gint i = 0; i < n_infos; i++) { |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
163 | PurpleContactInfo *info = NULL; |
| 41749 | 164 | gchar *username = NULL; |
| 165 | ||
| 166 | changed = FALSE; | |
| 167 | ||
| 168 | n_items = g_list_model_get_n_items(G_LIST_MODEL(person)); | |
| 169 | g_assert_cmpuint(n_items, ==, i); | |
| 170 | ||
| 171 | username = g_strdup_printf("username%d", i); | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
172 | info = purple_contact_info_new(NULL); |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
173 | purple_contact_info_set_username(info, username); |
| 41749 | 174 | g_free(username); |
| 175 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
176 | /* Add the contact info to the ptr array so we can remove it below. */ |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
177 | g_ptr_array_add(infos, info); |
| 41749 | 178 | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
179 | /* Add the contact info to the person and make sure that all the magic |
| 41749 | 180 | * happened. |
| 181 | */ | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
182 | purple_person_add_contact_info(person, info); |
| 41749 | 183 | n_items = g_list_model_get_n_items(G_LIST_MODEL(person)); |
| 184 | g_assert_cmpuint(n_items, ==, i + 1); | |
| 185 | g_assert_true(changed); | |
| 186 | } | |
| 187 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
188 | for(gint i = 0; i < n_infos; i++) { |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
189 | PurpleContactInfo *info = g_ptr_array_index(infos, i); |
| 41749 | 190 | gboolean removed = FALSE; |
| 191 | ||
| 192 | changed = FALSE; | |
| 193 | ||
| 194 | n_items = g_list_model_get_n_items(G_LIST_MODEL(person)); | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
195 | g_assert_cmpuint(n_items, ==, n_infos - i); |
| 41749 | 196 | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
197 | removed = purple_person_remove_contact_info(person, info); |
| 41749 | 198 | g_assert_true(removed); |
| 199 | ||
| 200 | n_items = g_list_model_get_n_items(G_LIST_MODEL(person)); | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
201 | g_assert_cmpuint(n_items, ==, n_infos - (i + 1)); |
| 41749 | 202 | |
| 203 | g_assert_true(changed); | |
| 204 | } | |
| 205 | ||
| 206 | /* Final sanity check that the person has no more contacts. */ | |
| 207 | n_items = g_list_model_get_n_items(G_LIST_MODEL(person)); | |
| 208 | g_assert_cmpuint(n_items, ==, 0); | |
| 209 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
210 | g_ptr_array_free(infos, TRUE); |
| 41749 | 211 | |
| 212 | g_clear_object(&person); | |
| 213 | } | |
| 214 | ||
| 215 | static void | |
| 216 | test_purple_person_priority_single(void) { | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
217 | PurpleContactInfo *info = NULL; |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
218 | PurpleContactInfo *priority = NULL; |
| 41749 | 219 | PurplePerson *person = NULL; |
| 220 | PurplePresence *presence = NULL; | |
| 221 | PurpleStatus *status = NULL; | |
| 222 | PurpleStatusType *status_type = NULL; | |
| 223 | gboolean called = FALSE; | |
| 224 | ||
| 225 | person = purple_person_new(); | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
226 | g_signal_connect(person, "notify::priority-contact-info", |
| 41749 | 227 | G_CALLBACK(test_purple_person_notify_cb), &called); |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
228 | priority = purple_person_get_priority_contact_info(person); |
| 41749 | 229 | g_assert_null(priority); |
| 230 | ||
|
41771
c5877e2c93f2
Create and add PurpleContacts to the manager when purple_buddy_new is called
Gary Kramlich <grim@reaperworld.com>
parents:
41761
diff
changeset
|
231 | /* Now create a real contact. */ |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
232 | info = purple_contact_info_new(NULL); |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
233 | purple_person_add_contact_info(person, info); |
|
41771
c5877e2c93f2
Create and add PurpleContacts to the manager when purple_buddy_new is called
Gary Kramlich <grim@reaperworld.com>
parents:
41761
diff
changeset
|
234 | |
|
c5877e2c93f2
Create and add PurpleContacts to the manager when purple_buddy_new is called
Gary Kramlich <grim@reaperworld.com>
parents:
41761
diff
changeset
|
235 | /* Set the status of the contact. */ |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
236 | presence = purple_contact_info_get_presence(info); |
| 41749 | 237 | status_type = purple_status_type_new(PURPLE_STATUS_AVAILABLE, "available", |
| 238 | "Available", FALSE); | |
| 239 | status = purple_status_new(status_type, presence); | |
| 240 | g_object_set(G_OBJECT(presence), "active-status", status, NULL); | |
| 241 | g_clear_object(&status); | |
| 242 | ||
| 243 | g_assert_true(called); | |
| 244 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
245 | priority = purple_person_get_priority_contact_info(person); |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
246 | g_assert_true(priority == info); |
| 41749 | 247 | |
| 248 | purple_status_type_destroy(status_type); | |
| 249 | g_clear_object(&person); | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
250 | g_clear_object(&info); |
| 41749 | 251 | g_clear_object(&presence); |
| 252 | } | |
| 253 | ||
| 254 | static void | |
| 255 | test_purple_person_priority_multiple_with_change(void) { | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
256 | PurpleContactInfo *priority = NULL; |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
257 | PurpleContactInfo *first = NULL; |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
258 | PurpleContactInfo *sorted_contact = NULL; |
| 41749 | 259 | PurplePerson *person = NULL; |
| 260 | PurplePresence *sorted_presence = NULL; | |
| 261 | PurpleStatus *status = NULL; | |
| 262 | PurpleStatusType *available = NULL; | |
| 263 | PurpleStatusType *offline = NULL; | |
| 264 | gboolean changed = FALSE; | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
265 | gint n_infos = 5; |
| 41749 | 266 | guint n_items = 0; |
| 267 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
268 | /* This unit test is a bit complicated, but it adds 5 contact infos to a |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
269 | * person all whose presences are set to offline. After adding all the |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
270 | * contact infos, we verify that the first contact info we added is the |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
271 | * priority contact info. Then we flip the active status of the n_infos - 2 |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
272 | * infos to available. This should make it the priority contact info which |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
273 | * we then assert. |
| 41749 | 274 | */ |
| 275 | ||
| 276 | /* Create our status types. */ | |
| 277 | available = purple_status_type_new(PURPLE_STATUS_AVAILABLE, "available", | |
| 278 | "Available", FALSE); | |
| 279 | offline = purple_status_type_new(PURPLE_STATUS_OFFLINE, "offline", | |
| 280 | "Offline", FALSE); | |
| 281 | ||
| 282 | /* Create the person and connected to the notify signal for the | |
| 283 | * priority-contact property. | |
| 284 | */ | |
| 285 | person = purple_person_new(); | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
286 | g_signal_connect(person, "notify::priority-contact-info", |
| 41749 | 287 | G_CALLBACK(test_purple_person_notify_cb), &changed); |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
288 | priority = purple_person_get_priority_contact_info(person); |
| 41749 | 289 | g_assert_null(priority); |
| 290 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
291 | /* Create and add all contact infos. */ |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
292 | for(gint i = 0; i < n_infos; i++) { |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
293 | PurpleContactInfo *info = NULL; |
| 41749 | 294 | PurplePresence *presence = NULL; |
| 295 | gchar *username = NULL; | |
| 296 | ||
| 297 | /* Set changed to false as it shouldn't be changed. */ | |
| 298 | changed = FALSE; | |
| 299 | ||
| 300 | /* Now create a real contact. */ | |
| 301 | username = g_strdup_printf("username%d", i + 1); | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
302 | info = purple_contact_info_new(NULL); |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
303 | purple_contact_info_set_username(info, username); |
| 41749 | 304 | g_free(username); |
|
41771
c5877e2c93f2
Create and add PurpleContacts to the manager when purple_buddy_new is called
Gary Kramlich <grim@reaperworld.com>
parents:
41761
diff
changeset
|
305 | |
|
c5877e2c93f2
Create and add PurpleContacts to the manager when purple_buddy_new is called
Gary Kramlich <grim@reaperworld.com>
parents:
41761
diff
changeset
|
306 | /* Set the status for the contact. */ |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
307 | presence = purple_contact_info_get_presence(info); |
|
41771
c5877e2c93f2
Create and add PurpleContacts to the manager when purple_buddy_new is called
Gary Kramlich <grim@reaperworld.com>
parents:
41761
diff
changeset
|
308 | status = purple_status_new(offline, presence); |
|
c5877e2c93f2
Create and add PurpleContacts to the manager when purple_buddy_new is called
Gary Kramlich <grim@reaperworld.com>
parents:
41761
diff
changeset
|
309 | g_object_set(G_OBJECT(presence), "active-status", status, NULL); |
|
c5877e2c93f2
Create and add PurpleContacts to the manager when purple_buddy_new is called
Gary Kramlich <grim@reaperworld.com>
parents:
41761
diff
changeset
|
310 | g_clear_object(&status); |
| 41749 | 311 | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
312 | purple_person_add_contact_info(person, info); |
| 41749 | 313 | |
| 314 | if(i == 0) { | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
315 | first = g_object_ref(info); |
| 41749 | 316 | g_assert_true(changed); |
| 317 | } else { | |
| 318 | g_assert_false(changed); | |
| 319 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
320 | if(i == n_infos - 2) { |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
321 | sorted_contact = g_object_ref(info); |
| 41749 | 322 | sorted_presence = g_object_ref(presence); |
| 323 | } | |
| 324 | } | |
| 325 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
326 | g_clear_object(&info); |
| 41749 | 327 | } |
| 328 | ||
| 329 | n_items = g_list_model_get_n_items(G_LIST_MODEL(person)); | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
330 | g_assert_cmpuint(n_items, ==, n_infos); |
| 41749 | 331 | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
332 | priority = purple_person_get_priority_contact_info(person); |
| 41749 | 333 | g_assert_true(priority == first); |
| 334 | g_clear_object(&first); | |
| 335 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
336 | /* Now set the second from the last contact info's status to available, and |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
337 | * verify that that contact info is now the priority contact info. |
| 41749 | 338 | */ |
| 339 | changed = FALSE; | |
| 340 | status = purple_status_new(available, sorted_presence); | |
| 341 | g_object_set(G_OBJECT(sorted_presence), "active-status", status, NULL); | |
| 342 | g_clear_object(&status); | |
| 343 | g_assert_true(changed); | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
344 | priority = purple_person_get_priority_contact_info(person); |
| 41749 | 345 | g_assert_true(priority == sorted_contact); |
| 346 | ||
| 347 | /* Cleanup. */ | |
| 348 | purple_status_type_destroy(offline); | |
| 349 | purple_status_type_destroy(available); | |
| 350 | ||
| 351 | g_clear_object(&sorted_contact); | |
| 352 | g_clear_object(&sorted_presence); | |
| 353 | ||
| 354 | g_clear_object(&person); | |
| 355 | } | |
| 356 | ||
| 357 | /****************************************************************************** | |
| 358 | * Main | |
| 359 | *****************************************************************************/ | |
| 360 | gint | |
| 361 | main(gint argc, gchar *argv[]) { | |
| 362 | g_test_init(&argc, &argv, NULL); | |
| 363 | ||
| 364 | test_ui_purple_init(); | |
| 365 | ||
| 366 | g_test_add_func("/person/new", | |
| 367 | test_purple_person_new); | |
| 368 | g_test_add_func("/person/properties", | |
| 369 | test_purple_person_properties); | |
| 370 | g_test_add_func("/person/contacts/single", | |
| 371 | test_purple_person_contacts_single); | |
| 372 | g_test_add_func("/person/contacts/multiple", | |
| 373 | test_purple_person_contacts_multiple); | |
| 374 | ||
| 375 | g_test_add_func("/person/priority/single", | |
| 376 | test_purple_person_priority_single); | |
| 377 | g_test_add_func("/person/priority/multiple-with-change", | |
| 378 | test_purple_person_priority_multiple_with_change); | |
| 379 | ||
| 380 | return g_test_run(); | |
| 381 | } |