libtelepathy/tsrc/src/telepathygabbleadddeletecontact.cpp
changeset 10 59927b2d3b75
parent 0 d0f3a028347a
equal deleted inserted replaced
0:d0f3a028347a 10:59927b2d3b75
     1 /*
       
     2 * Copyright (c) 2008 - 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    Used for Contact management(add/delete etc) related Test Cases
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 //Include files
       
    22 #include <e32err.h>
       
    23 #include <e32const.h>
       
    24 #include <e32base.h>
       
    25 #include <glib.h>
       
    26 #include <StifLogger.h>
       
    27 
       
    28 #include "telepathygabbleutils.h"
       
    29 #include "telepathygabbleadddeletecontact.h"
       
    30 #include "telepathygabblelogintest.h"
       
    31 
       
    32 
       
    33 
       
    34 //-----------------------------------------------------------------------------
       
    35 // function_name	: CTelepathyGabbleAddDeleteContact
       
    36 // description     	: constructor
       
    37 //----------------------------------------------------------------------------- 
       
    38 CTelepathyGabbleAddDeleteContact::CTelepathyGabbleAddDeleteContact()
       
    39 {
       
    40 }
       
    41 
       
    42 //-----------------------------------------------------------------------------
       
    43 // function_name	: ConstructL
       
    44 // description     	: constructor
       
    45 //----------------------------------------------------------------------------- 
       
    46 void CTelepathyGabbleAddDeleteContact::ConstructL()
       
    47 {
       
    48 	//do nothing
       
    49 }
       
    50 
       
    51 //-----------------------------------------------------------------------------
       
    52 // function_name	: NewL
       
    53 // description     	: constructor
       
    54 //----------------------------------------------------------------------------- 
       
    55 CTelepathyGabbleAddDeleteContact* CTelepathyGabbleAddDeleteContact::NewL()
       
    56 {
       
    57 	CTelepathyGabbleAddDeleteContact* self = new(ELeave) CTelepathyGabbleAddDeleteContact;
       
    58     CleanupStack::PushL( self );
       
    59     self->ConstructL();    
       
    60     CleanupStack::Pop();
       
    61     return self;
       
    62 }
       
    63 
       
    64 // Destructor
       
    65 //-----------------------------------------------------------------------------
       
    66 // function_name	: ~CTelepathyGabbleAddDeleteContact
       
    67 // description     	: Destructor
       
    68 //----------------------------------------------------------------------------- 
       
    69 CTelepathyGabbleAddDeleteContact::~CTelepathyGabbleAddDeleteContact()
       
    70 {
       
    71     	
       
    72 }
       
    73 
       
    74 //-----------------------------------------------------------------------------
       
    75 // function_name	: add_contact
       
    76 // description     	: adding a contact
       
    77 //----------------------------------------------------------------------------- 
       
    78 TInt CTelepathyGabbleAddDeleteContact::add_contact ( const gchar  *contact_id, 
       
    79 													 const gchar *message,
       
    80 													 CTestData* aTestData )
       
    81 {
       
    82   	guint     handle;
       
    83 	GArray    *handles = NULL;
       
    84 	//gpointer userdata = (gpointer)contact_id;
       
    85 	
       
    86 	//first check the contact_id.
       
    87 	if( contact_id == NULL )
       
    88 	{
       
    89 		return CTestData::EADD_FAIL;
       
    90 	}
       
    91 	
       
    92 	aTestData->SetAddDeleteContactStatus(CTestData::EADD_FAIL);
       
    93 	
       
    94 	//acess the utils class function to get the contact handle.	
       
    95 	handle = CTelepathyGabbleUtils::get_handle_from_contact ( contact_id, aTestData );
       
    96 
       
    97 	if ( handle == KErrNotFound )
       
    98 		{
       
    99 		return CTestData::EADD_FAIL;	
       
   100 		}
       
   101 
       
   102 	handles = g_array_new (FALSE, FALSE, sizeof (guint));
       
   103 	
       
   104 	g_array_append_val (handles, handle);
       
   105 	
       
   106 	DBusGProxy *group_iface_subscribe = aTestData->GetGroupSubscribeInterface();
       
   107 	DBusGProxy *group_iface_publish = aTestData->GetGroupPublishInterface();
       
   108 	DBusGProxy *group_iface_known = aTestData->GetGroupKnownInterface();
       
   109 	
       
   110 	
       
   111 	//register the callback, commented for now.
       
   112 	dbus_g_proxy_connect_signal (group_iface_subscribe, "MembersChanged",
       
   113 					     G_CALLBACK (roster_members_changed_cb ),
       
   114 					     aTestData, NULL); 
       
   115 	
       
   116 	dbus_g_proxy_connect_signal (group_iface_publish, "MembersChanged",
       
   117 					     G_CALLBACK (roster_members_changed_cb ),
       
   118 					     aTestData, NULL); 
       
   119 					     
       
   120 
       
   121 	dbus_g_proxy_connect_signal (group_iface_known, "MembersChanged",
       
   122 					     G_CALLBACK (roster_members_changed_cb ),
       
   123 					     aTestData, NULL); 					     
       
   124 	
       
   125 	
       
   126 	tp_chan_iface_group_add_members_async ( group_iface_subscribe, handles, message, add_contact_cb, aTestData );
       
   127 	
       
   128 	//Start the main loop
       
   129 	g_main_loop_run (aTestData->GetMainLoop());
       
   130 
       
   131 	g_array_free (handles, TRUE);
       
   132 	
       
   133 	//return the status was updated in the callback.
       
   134 	return aTestData->GetAddDeleteContactStatus(); 
       
   135 }
       
   136 
       
   137 
       
   138 //-----------------------------------------------------------------------------
       
   139 // function_name	: remove_contact
       
   140 // description     	: remove the contact.
       
   141 //----------------------------------------------------------------------------- 
       
   142 TInt CTelepathyGabbleAddDeleteContact::remove_contact ( const gchar  *contact_id, 
       
   143 														const gchar *message,
       
   144 													    CTestData* aTestData
       
   145 													  )
       
   146 {
       
   147 
       
   148 	guint     handle;
       
   149 	GArray    *handles = NULL;
       
   150 
       
   151 	//first check the contact_id.
       
   152 	if( contact_id == NULL )
       
   153 	{
       
   154 		return CTestData::EDELETE_FAIL;
       
   155 	}
       
   156 	
       
   157 	aTestData->SetAddDeleteContactStatus( CTestData::EDELETE_FAIL );
       
   158 	
       
   159 	handle = CTelepathyGabbleUtils::get_handle_from_contact ( contact_id, aTestData);
       
   160 	
       
   161 	if ( handle == KErrNotFound )
       
   162 		{
       
   163 		return CTestData::EDELETE_FAIL;	
       
   164 		}
       
   165 
       
   166 
       
   167 	DBusGProxy *group_iface_known = aTestData->GetGroupKnownInterface();
       
   168 	
       
   169 	handles = g_array_new (FALSE, FALSE, sizeof (guint));
       
   170 	
       
   171 	g_array_append_val (handles, handle);
       
   172 	
       
   173 	tp_chan_iface_group_remove_members_async ( group_iface_known, handles, message, remove_contact_cb, aTestData );
       
   174 
       
   175 	//Start the main loop
       
   176 	g_main_loop_run (aTestData->GetMainLoop());
       
   177 	
       
   178 	g_array_free (handles, TRUE);
       
   179 	
       
   180 	return (aTestData->GetAddDeleteContactStatus());
       
   181 }
       
   182 
       
   183 
       
   184 //-----------------------------------------------------------------------------
       
   185 // function_name	: add_contact_cb
       
   186 // description     	:Callback for add contact
       
   187 //----------------------------------------------------------------------------- 
       
   188 void CTelepathyGabbleAddDeleteContact::add_contact_cb( DBusGProxy* /*proxy*/, GError* error, gpointer userdata )
       
   189 {
       
   190 		CTestData* testdata = static_cast<CTestData*> (userdata);
       
   191 		if ( !error )
       
   192 		{
       
   193 			testdata->SetAddDeleteContactStatus(CTestData::EADD_SUCCESS);
       
   194 		}
       
   195 		else
       
   196 		{
       
   197 			testdata->SetAddDeleteContactStatus(CTestData::EADD_FAIL);
       
   198 				
       
   199 		}
       
   200 		
       
   201 		//Quit the main loop
       
   202 		g_main_loop_quit(testdata->GetMainLoop());
       
   203 			     	
       
   204 }
       
   205 
       
   206 //-----------------------------------------------------------------------------
       
   207 // function_name	: remove_contact_cb
       
   208 // description     	: Callback for remove contact.
       
   209 //----------------------------------------------------------------------------- 
       
   210 	
       
   211 void CTelepathyGabbleAddDeleteContact::remove_contact_cb( DBusGProxy* proxy, GError *error, gpointer userdata )
       
   212 {
       
   213 		
       
   214 		CTestData* testdata = static_cast<CTestData*> (userdata);
       
   215 		if ( error )
       
   216 		{
       
   217 		testdata->GetStifLogger()->Log( _L("CTelepathyGabbleTest::deleting already removed contact,it should give some error \n") );
       
   218 		testdata->SetAddDeleteContactStatus( CTestData::EDELETE_FAIL );
       
   219 		}
       
   220 		else
       
   221 		{
       
   222 		testdata->GetStifLogger()->Log( _L("CTelepathyGabbleTest::deleted successfully \n") );
       
   223 		testdata->SetAddDeleteContactStatus( CTestData::EDELETE_SUCCESS );
       
   224 		}
       
   225 	  //Quit the main loop started in Delete contact.
       
   226 	  g_main_loop_quit(testdata->GetMainLoop());
       
   227 }
       
   228 
       
   229 //-----------------------------------------------------------------------------
       
   230 // function_name	: roster_members_changed_cb
       
   231 // description     	: Callback for change in the contacts.
       
   232 //----------------------------------------------------------------------------- 
       
   233 
       
   234 void CTelepathyGabbleAddDeleteContact::roster_members_changed_cb (DBusGProxy*   /*group_iface*/,
       
   235 									    gchar*                /*message */,
       
   236 									    GArray               *added,
       
   237 									    GArray               *removed,
       
   238 									    GArray               *local_pending,
       
   239 									    GArray               *remote_pending,
       
   240 									    guint                 /*actor*/,
       
   241 									    guint                 /*reason*/,
       
   242 									    gpointer  			  userdata)
       
   243 {
       
   244 
       
   245 	gchar **contact_name = NULL;
       
   246 
       
   247 
       
   248 
       
   249 	CTestData* atestData = static_cast<CTestData*> (userdata);
       
   250 	
       
   251 	//TInt return_value = KErrNone;
       
   252 	
       
   253 
       
   254 	
       
   255 	if (added->len > 0)
       
   256 	{
       
   257 		
       
   258 		//this is not working, use async api later
       
   259 	    /*tp_conn_inspect_handles( DBUS_G_PROXY(atestData->GetTpConn()),
       
   260 						       TP_CONN_HANDLE_TYPE_CONTACT ,added,
       
   261 						       &contact_name,NULL);*/
       
   262 		if(contact_name)				       
       
   263 		{
       
   264 			//The contact has been added.
       
   265 			// Must verify this against the contact_name for which the request was sent?
       
   266 			// This will depend on whether we will hit callback for one contact at a time
       
   267 			// or multiple callbacks for all contacts at a single time. ?
       
   268 			//return_value = KErrNone;
       
   269 			//atestData->SetAddDeleteContactStatus(CTestData::EADD_SUCCESS);
       
   270 			
       
   271 		}
       
   272 	}
       
   273 	if (removed->len > 0)
       
   274 	{
       
   275 		/*tp_conn_inspect_handles( DBUS_G_PROXY(atestData->GetTpConn()),
       
   276 						       TP_CONN_HANDLE_TYPE_CONTACT ,removed,
       
   277 						       &contact_name,NULL);*/
       
   278 		if(contact_name)					       
       
   279 		{
       
   280 			//The contact_name was deleted
       
   281 			//Must verify this against the contact_name for which the request was sent?
       
   282 			//return_value == KErrNone;
       
   283 		}
       
   284 	}
       
   285 	if (local_pending->len > 0) 
       
   286 	{
       
   287 		/*tp_conn_inspect_handles( DBUS_G_PROXY(atestData->GetTpConn()),
       
   288 						       TP_CONN_HANDLE_TYPE_CONTACT ,local_pending,
       
   289 						       &contact_name,NULL);*/
       
   290 		if(contact_name)				       
       
   291 		{
       
   292 			//what should be tested here ? 
       
   293 			//like what is next action expected ?
       
   294 			//since the contact is still local_pending, is the test case failed ?
       
   295 			//return_value = KErrNone;	
       
   296 			//atestData->GetAddDeleteContactStatus();
       
   297 		}
       
   298 		
       
   299 	}
       
   300 	if (remote_pending->len > 0) 
       
   301 	{
       
   302 		/*tp_conn_inspect_handles( DBUS_G_PROXY(atestData->GetTpConn()),
       
   303 						       TP_CONN_HANDLE_TYPE_CONTACT ,remote_pending,
       
   304 						       &contact_name,NULL);*/
       
   305 		if(contact_name)					       
       
   306 		{
       
   307 			//return_value = KErrNone;		
       
   308 			//atestData->GetAddDeleteContactStatus();
       
   309 		}
       
   310 		
       
   311 	}
       
   312 	
       
   313 	//dont quit from here right now.
       
   314 }
       
   315 
       
   316 //  End of File