void contact_not_in_group(void **state) { GSList *groups = NULL; groups = g_slist_append(groups, strdup("somegroup")); PContact contact = p_contact_new("*****@*****.**", "bob", groups, "both", "is offline", FALSE); gboolean result = p_contact_in_group(contact, "othergroup"); assert_false(result); p_contact_free(contact); // g_slist_free(groups); }
void roster_update(const char *const barejid, const char *const name, GSList *groups, const char *const subscription, gboolean pending_out) { assert(roster != NULL); PContact contact = roster_get_contact(barejid); assert(contact != NULL); p_contact_set_subscription(contact, subscription); p_contact_set_pending_out(contact, pending_out); const char * const new_name = name; const char * current_name = NULL; if (p_contact_name(contact)) { current_name = strdup(p_contact_name(contact)); } p_contact_set_name(contact, new_name); _replace_name(current_name, new_name, barejid); GSList *curr_new_group = groups; while (curr_new_group) { char *new_group = curr_new_group->data; // contact added to group if (!p_contact_in_group(contact, new_group)) { // group doesn't yet exist if (!g_hash_table_contains(roster->group_count, new_group)) { g_hash_table_insert(roster->group_count, strdup(new_group), GINT_TO_POINTER(1)); autocomplete_add(roster->groups_ac, curr_new_group->data); // increment count } else { int count = GPOINTER_TO_INT(g_hash_table_lookup(roster->group_count, new_group)); g_hash_table_insert(roster->group_count, strdup(new_group), GINT_TO_POINTER(count + 1)); } } curr_new_group = g_slist_next(curr_new_group); } GSList *old_groups = p_contact_groups(contact); GSList *curr_old_group = old_groups; while (curr_old_group) { char *old_group = curr_old_group->data; // removed from group if (!g_slist_find_custom(groups, old_group, (GCompareFunc)g_strcmp0)) { if (g_hash_table_contains(roster->group_count, old_group)) { int count = GPOINTER_TO_INT(g_hash_table_lookup(roster->group_count, old_group)); count--; if (count < 1) { g_hash_table_remove(roster->group_count, old_group); autocomplete_remove(roster->groups_ac, old_group); } else { g_hash_table_insert(roster->group_count, strdup(old_group), GINT_TO_POINTER(count)); } } } curr_old_group = g_slist_next(curr_old_group); } p_contact_set_groups(contact, groups); }