os/ossrv/glib/tsrc/BC/src/datalist_test.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
     3 *
     4 * This library is free software; you can redistribute it and/or
     5 * modify it under the terms of the GNU Lesser General Public
     6 * License as published by the Free Software Foundation; either
     7 * version 2 of the License, or (at your option) any later version.
     8 *
     9 * This library is distributed in the hope that it will be useful,
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    12 * Lesser General Public License for more details.
    13 *
    14 * You should have received a copy of the GNU Lesser General Public
    15 * License along with this library; if not, write to the
    16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    17 * Boston, MA 02111-1307, USA.
    18 *
    19 * Description:
    20 *
    21 */
    22 
    23 
    24 #undef G_DISABLE_ASSERT
    25 #undef G_LOG_DOMAIN
    26 
    27 #include <stdio.h>
    28 #include <glib.h>
    29 
    30 #ifdef SYMBIAN
    31 #include "mrt2_glib2_test.h"
    32 #endif /*SYMBIAN*/
    33 
    34 void func(GQuark key_id,gpointer data,gpointer user_data)
    35 {
    36 	gint *udata = (int *)user_data;
    37 	(*udata)++;
    38 }
    39 
    40 void datalist_test()
    41 {
    42 	GData *datalist;
    43 	GQuark q1,q2;
    44 	gchar *str1 = "test1",*str2 = "test2",*str3,*str4;
    45 	int user_data = 0;
    46 	int flags;
    47 	
    48 	g_datalist_init(&datalist);
    49 	
    50 	//check for g_datalist_init.
    51 	g_assert(datalist == NULL);
    52 	
    53 	q1 = g_quark_from_string(str1);
    54 	q2 = g_quark_from_string(str2);
    55 	
    56 	g_datalist_id_set_data_full(&datalist,q1,str1,NULL);
    57 	g_datalist_id_set_data_full(&datalist,q2,str2,NULL);
    58 	
    59 	str3 = g_datalist_id_get_data(&datalist,q1);
    60 	str4 = g_datalist_id_get_data(&datalist,q2);
    61 	
    62 	//checks g_datalist_id_set_data_full and g_datalist_id_get_data
    63 	g_assert(!strcmp(str1,str3) && !strcmp(str2,str4));
    64 	
    65 	str3 = g_datalist_id_get_data(&datalist,5);
    66 	
    67 	g_assert(str3 == NULL);
    68 	
    69 	g_datalist_foreach(&datalist,func,&user_data);
    70 	
    71 	// checks g_datalist_foreach. user_data should become 2 as the function will be called twice for
    72 	// 2 data elements
    73 	g_assert(user_data == 2);
    74 	
    75 	g_datalist_set_flags(&datalist,0x0);
    76 	
    77 	flags = g_datalist_get_flags(&datalist);
    78 	
    79 	//checks g_datalist_set_flags and g_datalist_set_flags
    80 	g_assert(flags == 0);
    81 	
    82 }
    83 
    84 int
    85 main (int   argc,
    86       char *argv[])
    87 {
    88   
    89 	#ifdef SYMBIAN
    90 	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);
    91 	g_set_print_handler(mrtPrintHandler);
    92 	#endif /*SYMBIAN*/
    93 	
    94 	datalist_test();
    95 	
    96 	#if SYMBIAN
    97 	testResultXml("datalist_test");
    98   	#endif /* EMULATOR */
    99   
   100 	return 0;
   101 }