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