[evolution-data-server] libebook: Add unit test for bulk modification function



commit 5ce82c0588a649fdd226cf15ed00f22c427ea9bb
Author: Christophe Dumez <christophe dumez intel com>
Date:   Thu Oct 6 08:41:21 2011 +0300

    libebook: Add unit test for bulk modification function

 tests/libebook/test-bulk-methods.c |   99 ++++++++++++++++++++++++++++++++++++
 1 files changed, 99 insertions(+), 0 deletions(-)
---
diff --git a/tests/libebook/test-bulk-methods.c b/tests/libebook/test-bulk-methods.c
index e7d2a47..ea392f8 100644
--- a/tests/libebook/test-bulk-methods.c
+++ b/tests/libebook/test-bulk-methods.c
@@ -71,6 +71,101 @@ test_bulk_add_remove (EBookClient *client,
 	return TRUE;
 }
 
+static gboolean
+test_bulk_modify (EBookClient *client,
+                  const gchar *vcard_str,
+                  gint batch_size)
+{
+	gint i;
+	EContact *contact;
+	GSList *contacts = NULL;
+	GSList *added_uids = NULL;
+	const GSList *l, *ll;
+	const gchar *old_first_name = "xyz mix";
+	const gchar *new_first_name = "abc mix";
+
+	for (i = 0; i < batch_size; ++i) {
+		EContact *contact = e_contact_new_from_vcard (vcard_str);
+		contacts = g_slist_append (contacts, contact);
+	}
+
+	g_print ("  * Bulk addition of %d contacts...\n", batch_size);
+	/* Bulk addition */
+	g_return_val_if_fail (e_book_client_add_contacts_sync (client, contacts, &added_uids, NULL, NULL), FALSE);
+	g_return_val_if_fail (added_uids != NULL, FALSE);
+	g_return_val_if_fail (added_uids->data != NULL, FALSE);
+	g_return_val_if_fail (g_slist_length (added_uids) == batch_size, FALSE);
+
+	g_print ("  * Bulk modification of %d contacts...\n", batch_size);
+	ll = added_uids;
+	for (l = contacts; l != NULL; l = l->next) {
+		const gchar* uid = ll->data;
+		contact = E_CONTACT (l->data);
+
+		/* Set contact UID */
+		e_contact_set (contact, E_CONTACT_UID, uid);
+
+		/* Change contact first name */
+		e_contact_set (contact, E_CONTACT_GIVEN_NAME, new_first_name);
+
+		ll = ll->next;
+	}
+	g_return_val_if_fail (e_book_client_modify_contacts_sync (client, contacts, NULL, NULL), FALSE);
+
+	/* Validate */
+	for (ll = added_uids; ll != NULL; ll = ll->next) {
+		const gchar *first_name;
+		const gchar *uid = ll->data;
+		contact = NULL;
+
+		g_return_val_if_fail (e_book_client_get_contact_sync (client, uid, &contact, NULL, NULL), FALSE);
+
+		/* Check contact first name */
+		first_name = e_contact_get_const (contact, E_CONTACT_GIVEN_NAME);
+		g_return_val_if_fail (g_strcmp0 (first_name, new_first_name) == 0, FALSE);
+
+		g_object_unref (contact);
+	}
+
+	/* Test failure case */
+	g_print ("  * Bulk modification of %d contacts (expected failure)...\n", batch_size);
+	contact = E_CONTACT (g_slist_nth_data (contacts, g_slist_length (contacts) - 2));
+	g_return_val_if_fail (e_book_client_remove_contact_sync (client, contact, NULL, NULL), FALSE);
+	for (l = contacts; l != NULL; l = l->next) {
+		contact = E_CONTACT (l->data);
+		/* Change contact first name */
+		e_contact_set (contact, E_CONTACT_GIVEN_NAME, old_first_name);
+	}
+	g_return_val_if_fail (!e_book_client_modify_contacts_sync (client, contacts, NULL, NULL), FALSE);
+
+	/* Remove the UID that no longer exists from the added_uid list */
+	added_uids = g_slist_delete_link (added_uids, g_slist_nth (added_uids, g_slist_length (added_uids) - 2));
+
+	/* Validate */
+	for (ll = added_uids; ll != NULL; ll = ll->next) {
+		const gchar *first_name;
+		const gchar *uid = ll->data;
+		contact = NULL;
+
+		g_return_val_if_fail (e_book_client_get_contact_sync (client, uid, &contact, NULL, NULL), FALSE);
+
+		/* Check contact first name */
+		first_name = e_contact_get_const (contact, E_CONTACT_GIVEN_NAME);
+		g_return_val_if_fail (g_strcmp0 (first_name, new_first_name) == 0, FALSE);
+
+		g_object_unref (contact);
+	}
+
+	g_print ("  * Bulk removal of %d contacts...\n", batch_size);
+
+	/* Bulk removal */
+	g_return_val_if_fail (e_book_client_remove_contacts_sync (client, added_uids, NULL, NULL), FALSE);
+
+	g_slist_free_full (added_uids, g_free);
+	g_slist_free_full (contacts, g_object_unref);
+	return TRUE;
+}
+
 int main (gint argc, gchar **argv)
 {
 	EBookClient *client = NULL;
@@ -96,6 +191,10 @@ int main (gint argc, gchar **argv)
 	g_return_val_if_fail (test_bulk_add_remove (client, test_vcard_str, BATCH_SIZE), 1);
 	g_print ("Passed.\n");
 
+	g_print ("Testing bulk modification...\n");
+	g_return_val_if_fail (test_bulk_modify (client, test_vcard_str, BATCH_SIZE), 1);
+	g_print ("Passed.\n");
+
 	g_object_unref (client);
 
 	return 0;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]