[evolution-ews] Adapt the API changes into tests.



commit de5bd23619f57784fac28bacb4c37c62b6f5d853
Author: Chenthill Palanisamy <pchenthill novell com>
Date:   Tue May 17 14:29:50 2011 +0530

    Adapt the API changes into tests.

 src/server/tests/Makefile.am       |    3 +-
 src/server/tests/test-connection.c |   94 +++++++++++++++++++++++------------
 src/server/tests/test-libews.c     |    4 +-
 src/server/tests/test-syncfolder.c |   81 +++++++++++--------------------
 4 files changed, 94 insertions(+), 88 deletions(-)
---
diff --git a/src/server/tests/Makefile.am b/src/server/tests/Makefile.am
index 7e8bafd..3551727 100644
--- a/src/server/tests/Makefile.am
+++ b/src/server/tests/Makefile.am
@@ -17,7 +17,8 @@ TESTS = testews
 check_PROGRAMS = testews
 testews_SOURCES = 				\
 		utils.c 			\
-		test-connection.c 		\
+		test-connection.c		\
+		test-syncfolder.c		\
 		test-cuditem.c 			\
 		test-getattachment.c 		\
 		test-autocompletion.c		\
diff --git a/src/server/tests/test-connection.c b/src/server/tests/test-connection.c
index 9b29330..c1c4a71 100644
--- a/src/server/tests/test-connection.c
+++ b/src/server/tests/test-connection.c
@@ -36,7 +36,7 @@ void autodiscovery_tests_run ();
 
 EwsFolderId *inbox_folder_id = NULL;
 GSList *ids = NULL;
-
+GMainLoop *main_loop;
 
 /*Test cases*/
 
@@ -60,15 +60,41 @@ con_test_create_new_connection ()
 	//g_signal_connect (cnc, "shutdown", G_CALLBACK (ews_conn_shutdown), NULL);
 }
 
+struct _cb_data {
+	gboolean positive_case;
+	gboolean quit;
+};
+
+static void
+autodiscover_cb (gchar *uri, gpointer user_data, GError *error)
+{
+	struct _cb_data *data = (struct _cb_data *) user_data;
+	gboolean quit = data->quit;
+
+	if (data->positive_case) {
+		g_assert_cmpstr (uri, !=, NULL);
+	} else
+		g_assert_cmpstr (uri, ==, NULL);
+	
+	if (error)
+		g_print ("Error code:%d desc: %s \n", error->code, error->message);
+	
+	g_clear_error (&error);
+	g_free (data);
+	
+	if (quit)
+		g_main_loop_quit (main_loop);
+}
+
 static void
 con_test_autodiscover()
 {
 	const gchar *username;
 	const gchar *password;
+	const gchar *email;
+//	gchar *wrong_username, *domain;
 	const gchar *uri;
-	const gchar *email, *domain;
-	gchar *wrong_username;
-	GError *error = NULL;
+	struct _cb_data *user_data;
 
 	/* FIXME username not needed here */
 	util_get_login_info_from_env (&username, &password, &uri);
@@ -81,50 +107,54 @@ con_test_autodiscover()
 	g_print("%s %s : email : %s \n", G_STRLOC, G_STRFUNC, email);
 
 	g_print ("Testing postive case... \n");
-	uri = e_ews_autodiscover_ws_url (email, password, &error);
-	if (error) {
-		g_print ("Error code:%d desc: %s \n", error->code, error->message);
-		g_clear_error (&error);
-	}
-	g_assert_cmpstr (uri, !=, NULL);
+	user_data = g_new0 (struct _cb_data, 1);
+	user_data->positive_case = TRUE;
+	user_data->quit = TRUE;
+	e_ews_autodiscover_ws_url (autodiscover_cb, user_data, email, password);
 
 	g_print ("Testing wrong password... \n");
-	uri = e_ews_autodiscover_ws_url (email, "wrongpassword", &error);
-	g_print ("Error code:%d desc: %s \n", error->code, error->message);
-	g_clear_error (&error);
-	g_assert_cmpstr (uri, ==, NULL);
+	user_data = g_new0 (struct _cb_data, 1);
+	e_ews_autodiscover_ws_url (autodiscover_cb, user_data, email, "wrongpassword");
 
 	g_print ("Testing email without domain ... \n");
-	uri = e_ews_autodiscover_ws_url ("wronguseremail", password, &error);
-	g_print ("Error code:%d desc: %s \n", error->code, error->message);
-	g_clear_error (&error);
-	g_assert_cmpstr (uri, ==, NULL);
+	user_data = g_new0 (struct _cb_data, 1);
+	e_ews_autodiscover_ws_url (autodiscover_cb, user_data, "wronguseremail", password);
 
 	g_print ("Testing wrong email address and password... \n");
-	uri = e_ews_autodiscover_ws_url ("godknows donknow com", "wrongpassword", &error);
-	g_print ("Error code:%d desc: %s \n", error->code, error->message);
-	g_clear_error (&error);
-	g_assert_cmpstr (uri, ==, NULL);
+	user_data = g_new0 (struct _cb_data, 1);
+	e_ews_autodiscover_ws_url (autodiscover_cb, user_data, "godknows donknow com", "wrongpassword");
 
 	g_print ("Testing wrong user name ... \n");
 	domain = g_strstr_len (email, -1, "@");
 	wrong_username = g_strconcat ("godknows", domain, NULL);
-	uri = e_ews_autodiscover_ws_url (wrong_username, password, &error);
-	g_print ("Error code:%d desc: %s \n", error->code, error->message);
-	g_clear_error (&error);
+	user_data = g_new0 (struct _cb_data, 1);
+	user_data->quit = TRUE;
+	e_ews_autodiscover_ws_url (autodiscover_cb, user_data, wrong_username, password);
 	g_free (wrong_username);
-	g_assert_cmpstr (uri, ==, NULL);
 }
 
-/*Run tests*/
-void connection_tests_run ()
+static gboolean
+idle_cb (gpointer data)
 {
-	g_printf ("Testing Connection..... \n");
+	g_printf ("Test Connections");
 	con_test_create_new_connection ();
-}
 
-void autodiscovery_tests_run ()
-{
 	g_printf ("Testing Autodiscovery.... \n");
 	con_test_autodiscover();
+	
+	return FALSE;
+}
+
+/*Run tests*/
+void connection_tests_run ()
+{
+	g_type_init ();
+	g_thread_init (NULL);
+
+	main_loop = g_main_loop_new (NULL, TRUE);
+	g_idle_add ((GSourceFunc) idle_cb, NULL);
+	g_main_loop_run (main_loop);
+
+	/* terminate */
+	g_main_loop_unref (main_loop);
 }
diff --git a/src/server/tests/test-libews.c b/src/server/tests/test-libews.c
index d4f1702..bbcd26a 100644
--- a/src/server/tests/test-libews.c
+++ b/src/server/tests/test-libews.c
@@ -8,7 +8,6 @@
 extern EwsFolderId *folder_id;
 
 void connection_tests_run ();
-void autodiscovery_tests_run ();
 void op_tests_run ();
 void cuditem_tests_run ();
 void autocompletion_tests_run ();
@@ -35,9 +34,10 @@ int main (int argc, char *argv[])
 
 	/*Register tests*/
 	g_test_add_func ("/libews/connections", connection_tests_run);
-	g_test_add_func ("/libews/autodiscovery", autodiscovery_tests_run);
 	g_test_add_func ("/libews/autocompletion", autocompletion_tests_run);
 
+	g_test_add_func ("/libews/syncfolder", op_tests_run);
+
 	/* delete folder uses the data from create_folder test. */
 	g_test_add_func ("/libews/createfolder", createfolder_tests_run);
 	g_test_add_data_func ("/libews/deletefolder", &folder_id, deletefolder_tests_run);
diff --git a/src/server/tests/test-syncfolder.c b/src/server/tests/test-syncfolder.c
index d93e568..870fe0f 100644
--- a/src/server/tests/test-syncfolder.c
+++ b/src/server/tests/test-syncfolder.c
@@ -26,12 +26,18 @@
 #include <ctype.h>
 #include <glib.h>
 #include <glib/gprintf.h>
+#include "utils.h"
+#include <e-ews-connection.h>
 #include <e-ews-folder.h>
 #include <e-ews-item.h>
 
 static void op_test_get_item ();
 void op_tests_run ();
 
+GSList *ids;
+EwsFolderId *folder_id;
+GMainLoop *main_loop;
+
 static void
 folder_items_ready_callback (GObject *object, GAsyncResult *res, gpointer user_data)
 {
@@ -39,10 +45,11 @@ folder_items_ready_callback (GObject *object, GAsyncResult *res, gpointer user_d
 	GSList *items_created = NULL, *items_updated = NULL;
 	GSList *items_deleted = NULL, *l;
 	gchar *sync_state = NULL;
+	gboolean last_in_range = FALSE;
 	GError *error = NULL;
 
 	/* Only for test program */
-	e_ews_connection_sync_folder_items_finish	(cnc, res, &sync_state,
+	e_ews_connection_sync_folder_items_finish	(cnc, res, &sync_state, &last_in_range,
 							 &items_created, &items_updated,
 							 &items_deleted, &error);
 
@@ -93,8 +100,8 @@ op_test_sync_folder_items ()
 	g_assert (cnc != NULL);
 
 	e_ews_connection_sync_folder_items_start	(cnc, EWS_PRIORITY_MEDIUM,
-							 NULL, inbox_folder_id->id,
-							 "Default", NULL,
+							 NULL, folder_id->id,
+							 "Default", "",
 							 500, folder_items_ready_callback,
 							 cancellable, NULL);
 }
@@ -105,10 +112,11 @@ folder_hierarchy_ready_callback (GObject *object, GAsyncResult *res, gpointer us
 	GSList *folders_created = NULL, *folders_updated = NULL;
 	GSList *folders_deleted = NULL, *l;
 	EEwsConnection *cnc = E_EWS_CONNECTION (object);
+	gboolean last_in_range = FALSE;
 	gchar *sync_state = NULL;
 	GError *error = NULL;
 
-	e_ews_connection_sync_folder_hierarchy_finish	(cnc, res, &sync_state,
+	e_ews_connection_sync_folder_hierarchy_finish	(cnc, res, &sync_state, &last_in_range,
 							 &folders_created, &folders_updated,
 							 &folders_deleted, &error);
 
@@ -125,10 +133,10 @@ folder_hierarchy_ready_callback (GObject *object, GAsyncResult *res, gpointer us
 		const EwsFolderId *fid = e_ews_folder_get_id (folder);
 
 		g_print ("Name: %s \n Id: %s  \n ChangeKey: %s \n\n", e_ews_folder_get_name (folder), fid->id, fid->change_key);
-		if (!strcmp (e_ews_folder_get_name (folder), "Inbox")) {
-			inbox_folder_id = g_new0 (EwsFolderId, 1);
-			inbox_folder_id->id = g_strdup (fid->id);
-			inbox_folder_id->change_key = g_strdup (fid->change_key);
+		if (!strcmp (e_ews_folder_get_name (folder), "Contacts")) {
+			folder_id = g_new0 (EwsFolderId, 1);
+			folder_id->id = g_strdup (fid->id);
+			folder_id->change_key = g_strdup (fid->change_key);
 		}
 		g_object_unref (folder);
 	}
@@ -158,19 +166,13 @@ op_test_sync_folder_hierarchy ()
 	g_assert_cmpstr (password, !=, NULL);
 	g_assert_cmpstr (uri, !=, NULL);
 
-	cnc = e_ews_connection_new (uri, username, password, NULL);
+	cnc = e_ews_connection_new (uri, username, password, NULL, NULL, NULL);
 	g_assert (cnc != NULL);
 
 	e_ews_connection_sync_folder_hierarchy_start	(cnc, EWS_PRIORITY_MEDIUM,
 							 NULL, folder_hierarchy_ready_callback,
 							 cancellable, NULL);
 
-	/* FIXME Have a separate test for cancel without disrupting sync_hierarchy test
-	thread = g_thread_create ((GThreadFunc) cancel_sync_folder_hierarchy, cancellable, FALSE, &error);
-	if (error || !thread) {
-		g_warning ("%s: Creation of the thread failed with error: %s", G_STRFUNC, error->message);
-		g_error_free (error);
-	} */
 }
 
 static void
@@ -187,16 +189,16 @@ get_item_ready_callback (GObject *object, GAsyncResult *res, gpointer user_data)
 		return;
 	}
 
-	g_print ("\nMime content of first item is:\n%s\n", e_ews_item_get_mime_content (items->data));
-
 	for (l = items; l != NULL; l = g_slist_next (l)) {
 		EEwsItem *item = l->data;
+		const EwsId *id = e_ews_item_get_id (item);
 
-		g_print ("GetItem: Subject is %s \n", e_ews_item_get_subject (item));
+		g_print ("GetItem: Id is %s \n", id->id);
 	}
 
 	g_slist_foreach (items, (GFunc) g_object_unref, NULL);
 	g_slist_free (items);
+	g_main_loop_quit (main_loop);
 }
 
 static void
@@ -215,40 +217,27 @@ op_test_get_item ()
 	g_assert_cmpstr (password, !=, NULL);
 	g_assert_cmpstr (uri, !=, NULL);
 
-	cnc = e_ews_connection_new (uri, username, password, NULL);
+	cnc = e_ews_connection_new (uri, username, password, NULL, NULL, NULL);
 	g_assert (cnc != NULL);
 
 	ids = g_slist_reverse (ids);
 	e_ews_connection_get_items_start		(cnc, EWS_PRIORITY_MEDIUM,
-						 g_slist_last (ids), "IdOnly", "item:Subject item:DateTimeReceived item:DateTimeSent item:DateTimeCreated item:Size item:HasAttachments message:InternetMessageId message:From message:Sender message:ToRecipients message:CcRecipients message:BccRecipients message:IsRead item:MimeContent item:Importance", FALSE,
-						 get_item_ready_callback,
+						 g_slist_last (ids), "IdOnly", NULL, FALSE, NULL,
+						 get_item_ready_callback, NULL, NULL,
 						 cancellable, NULL);
 
 	g_slist_foreach (ids, (GFunc) g_free, NULL);
 	g_slist_free (ids);
 }
 
-static void
-op_test_find_item ()
+static gboolean
+idle_cb (gpointer data)
 {
-	const gchar *username;
-	const gchar *password;
-	const gchar *uri;
-	EEwsConnection *cnc;
-	GCancellable *cancellable;
-
-	cancellable = g_cancellable_new ();
 
-	util_get_login_info_from_env (&username, &password, &uri);
-	g_assert_cmpstr (username, !=, NULL);
-	g_assert_cmpstr (password, !=, NULL);
-	g_assert_cmpstr (uri, !=, NULL);
-
-	cnc = e_ews_connection_new (uri, username, password, NULL);
-	g_assert (cnc != NULL);
+	g_print ("\nTesting the sync_hierarchy... \n");
+	op_test_sync_folder_hierarchy ();
 
-	/* FIXME api fix
-	e_ews_connection_find_item (cnc, "contacts", cancellable); */
+	return FALSE;
 }
 
 void op_tests_run ()
@@ -265,17 +254,3 @@ void op_tests_run ()
 	/* terminate */
 	g_main_loop_unref (main_loop);
 }
-
-static gboolean
-idle_cb (gpointer data)
-{
-
-	g_print ("\nTesting the sync_hierarchy... \n");
-	op_test_sync_folder_hierarchy ();
-
-	g_print ("\nTesting find item... \n");
-	op_test_find_item ();
-
-	return FALSE;
-}
-



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