os/ossrv/glib/tsrc/BC/src/list_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/list_test.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,138 @@
     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 +
    1.28 +#undef G_DISABLE_ASSERT
    1.29 +#undef G_LOG_DOMAIN
    1.30 +
    1.31 +#include <stdio.h>
    1.32 +#include <string.h>
    1.33 +#include "glib.h"
    1.34 +
    1.35 +#ifdef SYMBIAN
    1.36 +#include "mrt2_glib2_test.h"
    1.37 +#endif /*SYMBIAN*/
    1.38 +
    1.39 +
    1.40 +int main (int   argc,char *argv[])
    1.41 +{
    1.42 +	
    1.43 +	GList *list1 = NULL,*list2 = NULL,*l,*l1,*list3 = NULL;
    1.44 +	int i;
    1.45 +	int *value;
    1.46 +	const char mem_allocator[]  = "mem_allocator";
    1.47 +	GAllocator *allocator;
    1.48 +	
    1.49 +	int num1[] = 
    1.50 +	{
    1.51 +		1,2,3
    1.52 +	};
    1.53 +	
    1.54 +	int num2[] = 
    1.55 +	{
    1.56 +		4,5,6
    1.57 +	};
    1.58 +	
    1.59 +	#ifdef SYMBIAN
    1.60 +	
    1.61 +	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.62 +	#endif /*SYMBIAN*/
    1.63 +	
    1.64 +	allocator = g_allocator_new(mem_allocator,500);
    1.65 +
    1.66 +	for(i=0;i<3;i++)
    1.67 +		list1 = g_list_append (list1, &num1[i]);
    1.68 +		
    1.69 +	for(i=0;i<3;i++)
    1.70 +		list2 = g_list_append (list2, &num2[i]);
    1.71 +	
    1.72 +	
    1.73 +	list1 = g_list_concat(list1,list2);
    1.74 +	
    1.75 +	for(i=0;i<6;i++)
    1.76 +	{
    1.77 +		l = g_list_nth(list1,i);
    1.78 +		g_assert(*(gint *)(l->data) == i+1);
    1.79 +	}
    1.80 +	
    1.81 +	list2 = g_list_copy(list1);
    1.82 +	
    1.83 +	for(i=0;i<3;i++)
    1.84 +	{
    1.85 +		l = g_list_nth(list2,i);
    1.86 +		g_assert(*(gint *)(l->data) == i+1);
    1.87 +	}
    1.88 +	
    1.89 +	l = g_list_first(list2);
    1.90 +	g_assert(*(gint *)(l->data) == 1);
    1.91 +	
    1.92 +	value = (int *)g_list_nth_data(list1,1);
    1.93 +	
    1.94 +	g_assert(*value == 2);
    1.95 +	
    1.96 +	l = g_list_nth(list1,3);
    1.97 +	
    1.98 +	l1 = g_list_nth_prev(l,2);
    1.99 +
   1.100 +	for(i=0;i<5;i++)
   1.101 +	{
   1.102 +		l = g_list_nth(l1,i);
   1.103 +		g_assert(*(gint *)(l->data) == i+2);
   1.104 +	}
   1.105 +	
   1.106 +	g_list_push_allocator(allocator);
   1.107 +	
   1.108 +	list3 = g_list_append(list3,&num1[2]);
   1.109 +	
   1.110 +	g_assert(*(gint *)(list3->data) == 3);
   1.111 +	
   1.112 +	g_list_pop_allocator();
   1.113 +	
   1.114 +	list3 = g_list_append(list3,&num1[0]);
   1.115 +	
   1.116 +	g_assert(*(gint *)(list3->next->data) == 1);
   1.117 +	
   1.118 +	list1 = g_list_append(list1,&num1[0]);
   1.119 +	
   1.120 +	i = g_list_length(list1);
   1.121 +	
   1.122 +	list1 = g_list_remove_all(list1,&num1[0]);
   1.123 +	
   1.124 +	i = g_list_length(list1);
   1.125 +	
   1.126 +	g_assert(g_list_length(list1) == 5); // should be this value as we will remove 2 1's from the list
   1.127 +	
   1.128 +	for(i==0;i<g_list_length(list1);i++)
   1.129 +	{
   1.130 +		l = g_list_nth(list1,i);
   1.131 +		g_assert(*(gint *)(l->data) != 1);
   1.132 +	}
   1.133 +	
   1.134 +	g_allocator_free(allocator);
   1.135 +	
   1.136 +	#ifdef SYMBIAN
   1.137 +  	testResultXml("list_test");
   1.138 +  	#endif /* EMULATOR */
   1.139 +	
   1.140 +	return 0;
   1.141 +}
   1.142 \ No newline at end of file