glib/tsrc/BC/src/dataset_test.c
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     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 
       
    25 #undef G_DISABLE_ASSERT
       
    26 #undef G_LOG_DOMAIN
       
    27 
       
    28 #include <stdio.h>
       
    29 #include <string.h>
       
    30 #include "glib.h"
       
    31 
       
    32 #ifdef SYMBIAN
       
    33 #include "mrt2_glib2_test.h"
       
    34 #endif /*SYMBIAN*/
       
    35 
       
    36 struct data
       
    37 {
       
    38 	char a[50],b[50],c[50];
       
    39 };
       
    40 
       
    41 void function(GQuark key_id,gpointer data,gpointer user_data)
       
    42 {
       
    43 	int *i = (int *)user_data;
       
    44 	(*i)++;
       
    45 }
       
    46 
       
    47 void dataset_test()
       
    48 {
       
    49 	struct data *d = g_malloc(sizeof(struct data));
       
    50 	gchar *str1,*str2,*str3,*str4,*str5,*str6;
       
    51 	int user_data = 0;
       
    52 	
       
    53 	GQuark q1,q2,q3;
       
    54 	
       
    55 	strcpy(d->a,"test1");
       
    56 	strcpy(d->b,"test2");
       
    57 	strcpy(d->c,"test3");
       
    58 	
       
    59 	q1 = g_quark_from_string(d->a);
       
    60 	q2 = g_quark_from_string(d->b);
       
    61 	q3 = g_quark_from_string(d->c);
       
    62 	
       
    63 	g_dataset_id_set_data_full(d,q1,d->a,NULL);
       
    64 	g_dataset_id_set_data_full(d,q2,d->b,NULL);
       
    65 	g_dataset_id_set_data_full(d,q3,d->c,NULL);
       
    66 	
       
    67 	str1 = g_dataset_id_get_data(d,q1);
       
    68 	str2 = g_dataset_id_get_data(d,q2);
       
    69 	str3 = g_dataset_id_get_data(d,q3);
       
    70 	
       
    71 	// These assertions will check whether g_dataset_id_set_data_full & 
       
    72 	// g_dataset_id_get_data is sucessful or not
       
    73 	g_assert(!strcmp(str1,d->a));
       
    74 	g_assert(!strcmp(str2,d->b));
       
    75 	g_assert(!strcmp(str3,d->c));
       
    76 	
       
    77 	str4 = g_dataset_id_remove_no_notify(d,q1);
       
    78 	str5 = g_dataset_id_get_data(d,q1);
       
    79 	
       
    80 	//This assertion will check if g_dataset_id_remove_no_notify is sucessful or not
       
    81 	g_assert(!strcmp(str4,d->a));
       
    82 	g_assert(str5 == NULL);
       
    83 	
       
    84 	g_dataset_foreach(d,function,&user_data);
       
    85 	
       
    86 	
       
    87 	//This assertion will check if g_dataset_foreach is sucessful or not
       
    88 	g_assert(user_data == 2);
       
    89 	
       
    90 	g_dataset_destroy(d);	
       
    91 	
       
    92 	str6 = g_dataset_id_get_data(d,q2);
       
    93 	
       
    94 	//This assertion will check if g_dataset_destroy is successful or not
       
    95 	g_assert(str5 == NULL);
       
    96 	
       
    97 }
       
    98 
       
    99 
       
   100 int main (int   argc,
       
   101       char *argv[])
       
   102 {
       
   103 	#ifdef SYMBIAN
       
   104 	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);
       
   105 	#endif /*SYMBIAN*/
       
   106 	
       
   107 	dataset_test();
       
   108 	
       
   109 	#if SYMBIAN
       
   110   	testResultXml("dataset_test");
       
   111   	#endif /* EMULATOR */
       
   112 	
       
   113 	return 0;
       
   114 }