ofdbus/dbus-glib/tsrc/testapps/stif_glib_2/src/stif_glib_2Blocks.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /*
       
     2 * Copyright (c) 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 "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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 // [INCLUDE FILES] - do not remove
       
    23 #include <e32svr.h>
       
    24 #include <StifParser.h>
       
    25 #include <Stiftestinterface.h>
       
    26 #include "stif_glib_2.h"
       
    27 
       
    28 #include <string.h>
       
    29 #include <stdio.h>
       
    30 #include <stdlib.h>
       
    31 
       
    32 #include <glib/gtypes.h>
       
    33 #include <glib/gerror.h>
       
    34 #include <dbus/dbus-glib.h>
       
    35 #include <pthread.h>
       
    36 
       
    37 int result = 1;
       
    38 
       
    39 _LIT(KSuccess, "Test Successful");
       
    40 
       
    41 // ============================ MEMBER FUNCTIONS ===============================
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // Cstif_glib_2::Delete
       
    45 // Delete here all resources allocated and opened from test methods. 
       
    46 // Called from destructor. 
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 void Cstif_glib_2::Delete() 
       
    50     {
       
    51 
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // Cstif_glib_2::RunMethodL
       
    56 // Run specified method. Contains also table of test mothods and their names.
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 TInt Cstif_glib_2::RunMethodL( 
       
    60     CStifItemParser& aItem ) 
       
    61     {
       
    62 
       
    63     static TStifFunctionInfo const KFunctions[] =
       
    64         {  
       
    65         // Copy this line for every implemented function.
       
    66         // First string is the function name used in TestScripter script file.
       
    67         // Second is the actual implementation member function. 
       
    68         ENTRY( "stif_g_proxy_interface0", Cstif_glib_2::stif_Proxy_Interface0 ),
       
    69         ENTRY( "stif_g_proxy_path0", Cstif_glib_2::stif_Proxy_Path0 ),
       
    70         ENTRY( "stif_g_type_struct0", Cstif_glib_2::stif_Type_Struct0 ),
       
    71         ENTRY( "stif_g_type_map0", Cstif_glib_2::stif_Type_Map0 ),
       
    72         ENTRY("stif_g_Proxy_get_bus_name0", Cstif_glib_2::stif_Proxy_get_bus_name0),
       
    73         ENTRY("stif_g_Proxy_get_bus_name1", Cstif_glib_2::stif_Proxy_get_bus_name1),
       
    74         ENTRY("stif_Proxy_new_proxy0", Cstif_glib_2::stif_Proxy_new_proxy0),
       
    75         ENTRY("stif_dbus_connection_get_g_type0",Cstif_glib_2::stif_dbus_connection_get_g_type0),
       
    76         //ADD NEW ENTRY HERE
       
    77         // [test cases entries] - Do not remove
       
    78 
       
    79         };
       
    80 
       
    81     const TInt count = sizeof( KFunctions ) / 
       
    82                         sizeof( TStifFunctionInfo );
       
    83 
       
    84     return RunInternalL( KFunctions, count, aItem );
       
    85 
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // Cstif_glib_2::ExampleL
       
    90 // Example test method function.
       
    91 // (other items were commented in a header).
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 int iface_flag = 0;
       
    95 
       
    96 static void* set_iface(void* data)
       
    97 	{
       
    98 	const char* iface1 = "Test.Proxy.Interface1";
       
    99 	DBusGProxy* proxy = (DBusGProxy* )data;
       
   100 	
       
   101 	dbus_g_proxy_set_interface(proxy, iface1); 
       
   102 	
       
   103 	if(strcmp(iface1, dbus_g_proxy_get_interface(proxy)))
       
   104 		{
       
   105 		printf("Fail to check interface %s", iface1);
       
   106 		}
       
   107 	iface_flag = 1;
       
   108 	return NULL;
       
   109 	}
       
   110 
       
   111 
       
   112 TInt Cstif_glib_2::stif_Proxy_Interface0( CStifItemParser& aItem )
       
   113 {
       
   114 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); 
       
   115 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles );  
       
   116 
       
   117 	DBusGConnection* connection;
       
   118 	DBusGProxy* proxy;
       
   119 	DBusGProxy* proxy1 ;//=NULL;
       
   120 	GError* error = NULL;
       
   121 	
       
   122 	pthread_t thr_id;
       
   123 	void* thrPtr;
       
   124 	
       
   125 	char* iface = "Test.Proxy.Interface";
       
   126 	char* iface1 = "Test.Proxy.Interface1";
       
   127 	
       
   128 	g_type_init();
       
   129 	
       
   130 	connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
       
   131 	if (connection == NULL)
       
   132 		{
       
   133 		  g_printerr ("Failed to open connection to bus: %s\n",
       
   134 		              error->message);
       
   135 		  g_error_free (error);
       
   136 		  return 1;
       
   137 		}
       
   138 	
       
   139 	proxy = dbus_g_proxy_new_for_name(connection, "Test.Glib.Proxy.Interface", "/Test/Proxy/Interface", iface);
       
   140 	proxy1 = dbus_g_proxy_new_for_name(connection, "Test.Glib.Proxy.Interface", "/Test/Proxy/Interface", iface1);
       
   141 	
       
   142 	if(strcmp(iface, dbus_g_proxy_get_interface(proxy)))
       
   143 		{
       
   144 		iLog->Log(_L8("Fail to check interface %s"), iface);
       
   145 		return 1;
       
   146 		}
       
   147 	
       
   148 	pthread_create(&thr_id, NULL, &set_iface, proxy);
       
   149 	pthread_join(thr_id, &thrPtr);
       
   150 	
       
   151 	if(strcmp(iface1, dbus_g_proxy_get_interface(proxy)))
       
   152 		{
       
   153 		iLog->Log(_L8("Fail to check interface %s"), iface1);
       
   154 		return 1;
       
   155 		}
       
   156 	if(!iface_flag)
       
   157 		{
       
   158 		iLog->Log(_L8("Something wrong happens in thread."));
       
   159 		return 1;
       
   160 		}
       
   161 	
       
   162 	iLog->Log(KSuccess);
       
   163     return KErrNone;
       
   164 }
       
   165 
       
   166 TInt Cstif_glib_2::stif_Proxy_Path0( CStifItemParser& aItem )
       
   167 {
       
   168 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); 
       
   169 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles );  
       
   170 
       
   171 	DBusGConnection* connection;
       
   172 	DBusGProxy* proxy;
       
   173 	GError* error = NULL;
       
   174 	
       
   175 	char* path = "/Test/Proxy/Path";
       
   176 	
       
   177 	g_type_init();
       
   178 	
       
   179 	connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
       
   180 	if (connection == NULL)
       
   181 		{
       
   182 		  g_printerr ("Failed to open connection to bus: %s\n",
       
   183 		              error->message);
       
   184 		  g_error_free (error);
       
   185 		  return 1;
       
   186 		}
       
   187 	
       
   188 	proxy = dbus_g_proxy_new_for_name(connection, "Test.Glib.Proxy.Path", path, "Test.Proxy.Interface");
       
   189 	
       
   190 	if(strcmp(path, dbus_g_proxy_get_path(proxy)))
       
   191 		{
       
   192 		iLog->Log(_L8("Fail to check interface %s"), path);
       
   193 		return 1;
       
   194 		}
       
   195 	
       
   196 	iLog->Log(KSuccess);
       
   197     return KErrNone;
       
   198 }
       
   199 
       
   200 gboolean get_member(GType type, gpointer instance, guint member, GValue *ret_value)
       
   201 	{	
       
   202 	GValueArray *va = (GValueArray*) instance;
       
   203 	  const GValue *val;
       
   204 	  if (member < dbus_g_type_get_struct_size (type))
       
   205 	    {
       
   206 	      val = g_value_array_get_nth (va, member);
       
   207 	      g_value_copy (val, ret_value);
       
   208 	      return TRUE;
       
   209 	    }
       
   210 	  else
       
   211 	    return FALSE;
       
   212 	}
       
   213 	
       
   214 gboolean set_member(GType type, gpointer instance, guint member, const GValue *new_value)
       
   215 	{
       
   216 	GValueArray *va = (GValueArray*) instance;
       
   217 	  GValue *vp;
       
   218 	  if (member < dbus_g_type_get_struct_size (type))
       
   219 	    {
       
   220 	      vp = g_value_array_get_nth (va, member);
       
   221 	      g_value_copy (new_value, vp);
       
   222 	      return TRUE;
       
   223 	    }
       
   224 	  else
       
   225 	    return FALSE;
       
   226 	}
       
   227 
       
   228 gpointer  construct_struct(GType type)
       
   229 	{
       
   230 	  GValueArray *ret;
       
   231 	  guint size = dbus_g_type_get_struct_size (type);
       
   232 	  guint i;
       
   233 	  ret = g_value_array_new (size);
       
   234 	  for (i=0; i < size; i++)
       
   235 	    {
       
   236 	      GValue val = {0,};
       
   237 	      g_value_init (&val, dbus_g_type_get_struct_member_type (type, i));
       
   238 	      g_value_array_append(ret, &val);
       
   239 	    }
       
   240 	  return (gpointer)ret;
       
   241 	}
       
   242 
       
   243 TInt Cstif_glib_2::stif_Type_Struct0( CStifItemParser& aItem )
       
   244 {
       
   245 	GValue* val1 = NULL;
       
   246 	GType struct_type;
       
   247 	
       
   248 	gint num1, num = 25;
       
   249 	gchar* str = "Glib Testing";
       
   250 	gchar *str1 = (gchar *)malloc(20);
       
   251 	gchar ch1, ch = 'M';
       
   252 	gboolean bl1, bl = TRUE;
       
   253 	guint num_u1, num_u = 1234;
       
   254 	glong num_l1, num_l = -12345;
       
   255 	gulong num_ul1, num_ul = 123456;
       
   256 	gint64 num_641, num_64 = 1234567;
       
   257 	guint64 num_u641, num_u64 = -1234567;
       
   258 	gdouble dbl1, dbl = 1.2345;
       
   259 	
       
   260 	DBusGTypeSpecializedStructVtable ds_vtable;
       
   261 	DBusGTypeSpecializedVtable base_vtable;
       
   262 	
       
   263 	base_vtable.constructor = construct_struct;
       
   264 	base_vtable.copy_func = NULL;
       
   265 	base_vtable.free_func = NULL;
       
   266 	base_vtable.simple_free_func = NULL;
       
   267 	
       
   268 	ds_vtable.base_vtable = base_vtable;
       
   269 	ds_vtable.get_member = get_member;
       
   270 	ds_vtable.set_member = set_member;
       
   271 	
       
   272 	g_type_init();
       
   273 	dbus_g_type_specialized_init();
       
   274 	
       
   275 	dbus_g_type_register_struct("struct_type", &ds_vtable, 0);
       
   276 	
       
   277 	struct_type = dbus_g_type_get_struct("struct_type", G_TYPE_INT, G_TYPE_STRING, G_TYPE_CHAR, G_TYPE_BOOLEAN, G_TYPE_UINT, G_TYPE_LONG, G_TYPE_ULONG, G_TYPE_INT64, G_TYPE_UINT64, G_TYPE_DOUBLE, G_TYPE_INVALID);
       
   278 	
       
   279 	val1 = g_new0 (GValue, 1);
       
   280 	g_value_init(val1, struct_type);
       
   281 	g_value_take_boxed(val1, dbus_g_type_specialized_construct(struct_type));
       
   282 	
       
   283 	if(!dbus_g_type_is_struct(struct_type))
       
   284 		{
       
   285 		iLog->Log(_L8("dbus_g_type_is_struct() failed."));
       
   286 		return 1;
       
   287 		}
       
   288 		
       
   289 	if(!dbus_g_type_struct_set(val1, 0, num, 1, str, 2, ch, 3, bl, 4, num_u, 5, num_l, 6, num_ul, 7, num_64, 8, num_u64, 9, dbl, G_MAXUINT))
       
   290 		{
       
   291 		iLog->Log(_L8("Fail in dbus_g_type_struct_set()"));
       
   292 		return 1;
       
   293 		}
       
   294 
       
   295 	if(!dbus_g_type_struct_get(val1, 0, &num1, 1, &str1, 2, &ch1, 3, &bl1, 4, &num_u1, 5, &num_l1, 6, &num_ul1, 7, &num_641, 8, &num_u641, 9, &dbl1, G_MAXUINT))
       
   296 		{
       
   297 		iLog->Log(_L8("Fail in dbus_g_type_struct_get()"));
       
   298 		return 1;
       
   299 		}
       
   300 	else
       
   301 		if(num!=num1 || strcmp(str, str1) || ch!=ch1 || bl!=bl1 || num_u!=num_u1 || num_l!=num_l1 || num_ul!=num_ul1 || num_64!=num_641 || num_u64!=num_u641 || dbl!=dbl1)
       
   302 			{
       
   303 			iLog->Log(_L8("num1 = %d, str = %s, ch1 = %c, bl1 = %d, num_u1 = %u, num_l1 = %d, num_ul1 = %u, num_641 = %ld, num_u641 = %u, dbl1 = %lf"), num1, str1, ch1, bl1, num_u1, num_l1, num_ul1, num_641, num_u641, dbl1);
       
   304 			return 1;
       
   305 			}
       
   306 	iLog->Log(KSuccess);
       
   307 	return KErrNone;
       
   308 }
       
   309 
       
   310 
       
   311 void call_iterator_for_hash_table(gpointer key, gpointer value, gpointer data)
       
   312 	{
       
   313 		GValue* key_val = (GValue*)key;
       
   314 		GValue* value_val = (GValue*)value;
       
   315 		DBusGTypeSpecializedMapIterator iter = (DBusGTypeSpecializedMapIterator)data;
       
   316 		
       
   317 		iter(key_val, value_val, NULL);
       
   318 	}
       
   319 
       
   320 void map_iterator_fun (GType type, gpointer instance, DBusGTypeSpecializedMapIterator iterator, gpointer user_data)
       
   321 {
       
   322 	GHashTable* hash_table = (GHashTable *)instance;
       
   323 	
       
   324 	g_hash_table_foreach(hash_table, call_iterator_for_hash_table, (gpointer)iterator);
       
   325 }
       
   326 
       
   327 void map_append_fun (DBusGTypeSpecializedAppendContext *ctx, GValue *key, GValue *val)
       
   328 {
       
   329 	GHashTable *hashTable = (GHashTable*)g_value_get_boxed(ctx->val);
       
   330 	g_hash_table_insert(hashTable, key, val);
       
   331 }
       
   332 
       
   333 void  simple_free_fun  (gpointer       data)
       
   334 {
       
   335 
       
   336 }
       
   337 
       
   338 gpointer  construct_map(GType type)
       
   339 	{
       
   340 	  GHashTable *ret;
       
   341 	  
       
   342 	  ret = g_hash_table_new(NULL, NULL);
       
   343 	  return ret;
       
   344 	}
       
   345 
       
   346 void  iterator_map(const GValue *key_val, const GValue *value_val, gpointer user_data)
       
   347 	{
       
   348 		const char *key;
       
   349 		const char* val;
       
   350 		int age_val;
       
   351 		GValue* temp;
       
   352 		
       
   353 		FILE* fp = fopen("c:\\map.txt", "a+");
       
   354 		if(!fp)
       
   355 			printf("Not able to open map.txt");
       
   356 		
       
   357 		key = g_value_get_string(key_val);
       
   358 		fprintf(fp, "%s  =  ", key);
       
   359 		
       
   360 		if(strcmp("age", key))
       
   361 			{
       
   362 			temp = (GValue *)g_value_get_boxed(value_val);
       
   363 			val = g_value_get_string(temp);
       
   364 			fprintf(fp, "%s\n", val);
       
   365 			if(!strcmp("firstname", key))
       
   366 				if(strcmp("Joe", val))
       
   367 					result = 0;
       
   368 			if(!strcmp("lastname", key))
       
   369 				if(strcmp("Average", val))
       
   370 					result = 0;
       
   371 			}
       
   372 		else
       
   373 			{
       
   374 			temp = (GValue *)g_value_get_boxed(value_val);
       
   375 			age_val = g_value_get_int(temp);
       
   376 			fprintf(fp, "%d\n", age_val);
       
   377 			if(age_val != 35)
       
   378 				result = 0;
       
   379 			}
       
   380 		fclose(fp);
       
   381 	}
       
   382 
       
   383 TInt Cstif_glib_2::stif_Type_Map0( CStifItemParser& aItem )
       
   384 {
       
   385 	DBusGTypeSpecializedAppendContext  ctx;
       
   386 	GValue                            *key       = NULL;
       
   387 	GValue                            *value     = NULL;
       
   388 	GValue                            *realValue = NULL;
       
   389 	
       
   390 	GValue* data;
       
   391 	GType  map_type;
       
   392 	GType key_type;
       
   393 	GType val_type;
       
   394 	
       
   395 	DBusGTypeSpecializedMapVtable map_vtable;
       
   396 	DBusGTypeSpecializedVtable base_vtable;
       
   397 	
       
   398 	base_vtable.constructor = construct_map;
       
   399 	base_vtable.copy_func = NULL;
       
   400 	base_vtable.free_func = NULL;
       
   401 	base_vtable.simple_free_func = simple_free_fun;
       
   402 	
       
   403 	map_vtable.base_vtable = base_vtable;
       
   404 	map_vtable.append_func = map_append_fun;
       
   405 	map_vtable.iterator = map_iterator_fun;
       
   406 	
       
   407 	g_type_init();
       
   408 	dbus_g_type_specialized_init();
       
   409 	
       
   410 	dbus_g_type_register_map("GHashTable", &map_vtable, 0);
       
   411 	map_type = dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE);
       
   412 	 
       
   413 	data = g_new0(GValue, 1);
       
   414 	
       
   415 	//init our map
       
   416 	g_value_init (data, map_type);
       
   417 	g_value_take_boxed (data, dbus_g_type_specialized_construct (map_type));
       
   418 	
       
   419 	key_type = dbus_g_type_get_map_key_specialization(map_type);
       
   420 	if(key_type != G_TYPE_STRING)
       
   421 		{
       
   422 		iLog->Log(_L8("key_type is not matching its %d"), key_type);
       
   423 		return 1;
       
   424 		}
       
   425 	val_type = dbus_g_type_get_map_value_specialization(map_type);
       
   426 	if(val_type != G_TYPE_VALUE)
       
   427 		{
       
   428 		iLog->Log(_L8("value_type is not matching its %d"), val_type);
       
   429 		return 1;
       
   430 		}
       
   431 	
       
   432 	//prepare to add key/value pairs to our map
       
   433 	dbus_g_type_specialized_init_append (data, &ctx);
       
   434 	for(int i=0; i<5; i++)
       
   435 		{
       
   436 		//prepare and add the first key/value pair (firstName => Joe)
       
   437 		key       = g_new0(GValue, 1);
       
   438 		value     = g_new0(GValue, 1);
       
   439 		realValue = g_new0(GValue, 1);
       
   440 		g_value_init (key,       G_TYPE_STRING);
       
   441 		g_value_init (value,     G_TYPE_VALUE);
       
   442 		g_value_init (realValue, G_TYPE_STRING);
       
   443 		g_value_set_string (key,       "firstName");
       
   444 		g_value_set_string (realValue, "Joe");
       
   445 		g_value_set_boxed  (value,     realValue);
       
   446 		dbus_g_type_specialized_map_append(&ctx, key, value);
       
   447 		 
       
   448 		//prepare and add the second key/value pair (lastName => Average)
       
   449 		key       = g_new0(GValue, 1);
       
   450 		value     = g_new0(GValue, 1);
       
   451 		realValue = g_new0(GValue, 1);
       
   452 		g_value_init (key,       G_TYPE_STRING);
       
   453 		g_value_init (value,     G_TYPE_VALUE);
       
   454 		g_value_init (realValue, G_TYPE_STRING);
       
   455 		g_value_set_string (key,       "lastName");
       
   456 		g_value_set_string (realValue, "Average");
       
   457 		g_value_set_boxed  (value,     realValue);
       
   458 		dbus_g_type_specialized_map_append(&ctx, key, value);
       
   459 		 
       
   460 		//prepare and add the third key/value pair (age => 35)
       
   461 		key       = g_new0(GValue, 1);
       
   462 		value     = g_new0(GValue, 1);
       
   463 		realValue = g_new0(GValue, 1);
       
   464 		g_value_init (key,       G_TYPE_STRING);
       
   465 		g_value_init (value,     G_TYPE_VALUE);
       
   466 		g_value_init (realValue, G_TYPE_INT);
       
   467 		g_value_set_string (key,       "age");
       
   468 		g_value_set_int    (realValue, 35);
       
   469 		g_value_set_boxed  (value,     realValue);
       
   470 		dbus_g_type_specialized_map_append(&ctx, key, value);
       
   471 		}
       
   472 	dbus_g_type_map_value_iterate(data, iterator_map, NULL);
       
   473 	
       
   474 	if(result == 0)
       
   475 		{
       
   476 		iLog->Log(_L8("Expected values not coming while iterating"));
       
   477 		return 1;
       
   478 		}
       
   479 	iLog->Log(KSuccess);
       
   480 	return KErrNone;
       
   481 }
       
   482 
       
   483 TInt Cstif_glib_2::stif_Proxy_get_bus_name0( CStifItemParser& aItem )
       
   484 	{
       
   485 	TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); 
       
   486 	TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles );  
       
   487 
       
   488 		DBusGConnection* connection;
       
   489 		DBusGProxy* proxy;
       
   490 		GError* error = NULL;
       
   491 		const char*     proxy_get_name;
       
   492 		
       
   493 		char* path = "/Test/Proxy/Path";
       
   494 		
       
   495 		const char* name_bus = "Test.Glib.Proxy.Path1";
       
   496 		int compare =0;
       
   497 		g_type_init();
       
   498 		 
       
   499 		connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
       
   500 		if (connection == NULL)
       
   501 			{
       
   502 			  g_printerr ("Failed to open connection to bus: %s\n",
       
   503 			              error->message);
       
   504 			  g_error_free (error);
       
   505 			  return 1;
       
   506 			}
       
   507 		
       
   508 		proxy = dbus_g_proxy_new_for_name(connection, "Test.Glib.Proxy.Path1", path, "Test.Proxy.Interface");
       
   509 		
       
   510 		proxy_get_name = dbus_g_proxy_get_bus_name (proxy);
       
   511 		if(proxy_get_name != NULL)
       
   512 		{
       
   513 			
       
   514 			iLog->Log(_L8("name_bus:%s"),proxy_get_name);
       
   515 		}
       
   516 		
       
   517 			compare = strcmp(name_bus,proxy_get_name);
       
   518 	
       
   519 		if(compare == 0)
       
   520 			{
       
   521 			iLog->Log(_L8(" the bus name : %s"),proxy_get_name); 
       
   522 			iLog->Log(KSuccess); 
       
   523 			g_object_unref(proxy);
       
   524 		    return KErrNone;
       
   525 			}
       
   526 		iLog->Log(_L8("FAIL")); 
       
   527 		g_object_unref(proxy);
       
   528 		return 1;
       
   529 		
       
   530 		
       
   531 		
       
   532 	}
       
   533 
       
   534 
       
   535 TInt Cstif_glib_2::stif_Proxy_get_bus_name1( CStifItemParser& aItem )
       
   536 	{
       
   537 	TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); 
       
   538 	TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles );  
       
   539 
       
   540 		DBusGConnection* connection;
       
   541 		DBusGProxy* proxy;
       
   542 		GError* error = NULL;
       
   543 		const char*     proxy_get_name;
       
   544 		
       
   545 		char* path = "/Test/Proxy/Path";
       
   546 		
       
   547 		//const char* name_bus = "Test.Glib.Proxy.Path1";
       
   548 		int compare =0;
       
   549 		g_type_init();
       
   550 		 
       
   551 		connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
       
   552 		if (connection == NULL)
       
   553 			{
       
   554 			  g_printerr ("Failed to open connection to bus: %s\n",
       
   555 			              error->message);
       
   556 			  g_error_free (error);
       
   557 			  return 1;
       
   558 			}
       
   559 		
       
   560 		proxy = dbus_g_proxy_new_for_peer(connection, "Test.Glib.Proxy.Path", "Test.Proxy.Interface");
       
   561 		
       
   562 		proxy_get_name = dbus_g_proxy_get_bus_name (proxy);
       
   563 		if(proxy_get_name == NULL)
       
   564 			{
       
   565 			iLog->Log(_L8("Proxy_get_name returns NULL as the proxy is obtained by dbus_g_proxy_new_for_peer"));
       
   566 
       
   567 			iLog->Log(KSuccess);
       
   568 			g_object_unref(proxy);
       
   569 		    return KErrNone;
       
   570 			}
       
   571 		else 
       
   572 			iLog->Log(_L8("FAIL"));
       
   573 			g_object_unref(proxy);
       
   574 			return 1;  
       
   575 			
       
   576 		
       
   577 		
       
   578 	}
       
   579 
       
   580 TInt Cstif_glib_2::stif_Proxy_new_proxy0( CStifItemParser& aItem )
       
   581 	{
       
   582 	TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); 
       
   583 	TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles );  
       
   584 
       
   585 		DBusGConnection* connection;
       
   586 		DBusGProxy* proxy;
       
   587 		DBusGProxy* New_proxy;
       
   588 		GError* error = NULL;
       
   589 		
       
   590 		char* path = "/Test/Proxy/Path";
       
   591 		
       
   592 		g_type_init();
       
   593 		 
       
   594 		connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
       
   595 		if (connection == NULL)
       
   596 			{
       
   597 			  g_printerr ("Failed to open connection to bus: %s\n",
       
   598 			              error->message);
       
   599 			  g_error_free (error);
       
   600 			  return 1;
       
   601 			}
       
   602 		proxy = dbus_g_proxy_new_for_name(connection, "Test.Glib.Proxy.Path1", path, "T   est.Proxy.Interface");
       
   603 		
       
   604 		
       
   605 		New_proxy = dbus_g_proxy_new_from_proxy (proxy,"Test.Proxy.Interface",path);
       
   606 		
       
   607 		if(New_proxy==NULL)
       
   608 			{
       
   609 
       
   610 			iLog->Log(_L8("FAIL")); 
       
   611 			return 1;
       
   612 			}
       
   613 		
       
   614 		iLog->Log(_L8("New proxy is been created from the existing proxy"));
       
   615 		
       
   616 		
       
   617 	g_object_unref(New_proxy);
       
   618 	g_object_unref(proxy);
       
   619 
       
   620 			iLog->Log(KSuccess);
       
   621 		    return KErrNone;
       
   622 		    
       
   623 	}
       
   624 
       
   625 
       
   626 TInt Cstif_glib_2::stif_dbus_connection_get_g_type0( CStifItemParser& aItem )
       
   627 	{
       
   628 	TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); 
       
   629 	TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles );  
       
   630 
       
   631 		DBusGConnection* connection;
       
   632 		DBusGProxy* proxy;
       
   633 		GError* error = NULL;
       
   634 		GType message_get;
       
   635 		
       
   636 		g_type_init();
       
   637 		 
       
   638 		connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
       
   639 		if (connection == NULL)
       
   640 			{
       
   641 			  g_printerr ("Failed to open connection to bus: %s\n",error->message);
       
   642 			  g_error_free (error);
       
   643 			  return 1; 
       
   644 			}
       
   645 		message_get=dbus_g_connection_get_g_type();
       
   646 		if(message_get == NULL)
       
   647 			{
       
   648 				iLog->Log(_L8("Fail"));
       
   649 				g_object_unref(proxy);
       
   650 				return 1;
       
   651 			}
       
   652 				
       
   653 				iLog->Log(_L8("%ld"),message_get);
       
   654 				iLog->Log(KSuccess);
       
   655 			
       
   656 			    return KErrNone;
       
   657 			
       
   658 	 }
       
   659 	 
       
   660