os/ossrv/glib/tsrc/BC/src/datalist_test.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/glib/tsrc/BC/src/datalist_test.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,101 @@
     1.4 +/*
     1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
     1.6 +*
     1.7 +* This library is free software; you can redistribute it and/or
     1.8 +* modify it under the terms of the GNU Lesser General Public
     1.9 +* License as published by the Free Software Foundation; either
    1.10 +* version 2 of the License, or (at your option) any later version.
    1.11 +*
    1.12 +* This library is distributed in the hope that it will be useful,
    1.13 +* but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.15 +* Lesser General Public License for more details.
    1.16 +*
    1.17 +* You should have received a copy of the GNU Lesser General Public
    1.18 +* License along with this library; if not, write to the
    1.19 +* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    1.20 +* Boston, MA 02111-1307, USA.
    1.21 +*
    1.22 +* Description:
    1.23 +*
    1.24 +*/
    1.25 +
    1.26 +
    1.27 +#undef G_DISABLE_ASSERT
    1.28 +#undef G_LOG_DOMAIN
    1.29 +
    1.30 +#include <stdio.h>
    1.31 +#include <glib.h>
    1.32 +
    1.33 +#ifdef SYMBIAN
    1.34 +#include "mrt2_glib2_test.h"
    1.35 +#endif /*SYMBIAN*/
    1.36 +
    1.37 +void func(GQuark key_id,gpointer data,gpointer user_data)
    1.38 +{
    1.39 +	gint *udata = (int *)user_data;
    1.40 +	(*udata)++;
    1.41 +}
    1.42 +
    1.43 +void datalist_test()
    1.44 +{
    1.45 +	GData *datalist;
    1.46 +	GQuark q1,q2;
    1.47 +	gchar *str1 = "test1",*str2 = "test2",*str3,*str4;
    1.48 +	int user_data = 0;
    1.49 +	int flags;
    1.50 +	
    1.51 +	g_datalist_init(&datalist);
    1.52 +	
    1.53 +	//check for g_datalist_init.
    1.54 +	g_assert(datalist == NULL);
    1.55 +	
    1.56 +	q1 = g_quark_from_string(str1);
    1.57 +	q2 = g_quark_from_string(str2);
    1.58 +	
    1.59 +	g_datalist_id_set_data_full(&datalist,q1,str1,NULL);
    1.60 +	g_datalist_id_set_data_full(&datalist,q2,str2,NULL);
    1.61 +	
    1.62 +	str3 = g_datalist_id_get_data(&datalist,q1);
    1.63 +	str4 = g_datalist_id_get_data(&datalist,q2);
    1.64 +	
    1.65 +	//checks g_datalist_id_set_data_full and g_datalist_id_get_data
    1.66 +	g_assert(!strcmp(str1,str3) && !strcmp(str2,str4));
    1.67 +	
    1.68 +	str3 = g_datalist_id_get_data(&datalist,5);
    1.69 +	
    1.70 +	g_assert(str3 == NULL);
    1.71 +	
    1.72 +	g_datalist_foreach(&datalist,func,&user_data);
    1.73 +	
    1.74 +	// checks g_datalist_foreach. user_data should become 2 as the function will be called twice for
    1.75 +	// 2 data elements
    1.76 +	g_assert(user_data == 2);
    1.77 +	
    1.78 +	g_datalist_set_flags(&datalist,0x0);
    1.79 +	
    1.80 +	flags = g_datalist_get_flags(&datalist);
    1.81 +	
    1.82 +	//checks g_datalist_set_flags and g_datalist_set_flags
    1.83 +	g_assert(flags == 0);
    1.84 +	
    1.85 +}
    1.86 +
    1.87 +int
    1.88 +main (int   argc,
    1.89 +      char *argv[])
    1.90 +{
    1.91 +  
    1.92 +	#ifdef SYMBIAN
    1.93 +	g_log_set_handler (NULL,  G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL);
    1.94 +	g_set_print_handler(mrtPrintHandler);
    1.95 +	#endif /*SYMBIAN*/
    1.96 +	
    1.97 +	datalist_test();
    1.98 +	
    1.99 +	#if SYMBIAN
   1.100 +	testResultXml("datalist_test");
   1.101 +  	#endif /* EMULATOR */
   1.102 +  
   1.103 +	return 0;
   1.104 +}
   1.105 \ No newline at end of file