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