os/ossrv/glib/tsrc/BC/src/list_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 
    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 
    37 int main (int   argc,char *argv[])
    38 {
    39 	
    40 	GList *list1 = NULL,*list2 = NULL,*l,*l1,*list3 = NULL;
    41 	int i;
    42 	int *value;
    43 	const char mem_allocator[]  = "mem_allocator";
    44 	GAllocator *allocator;
    45 	
    46 	int num1[] = 
    47 	{
    48 		1,2,3
    49 	};
    50 	
    51 	int num2[] = 
    52 	{
    53 		4,5,6
    54 	};
    55 	
    56 	#ifdef SYMBIAN
    57 	
    58 	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);
    59 	#endif /*SYMBIAN*/
    60 	
    61 	allocator = g_allocator_new(mem_allocator,500);
    62 
    63 	for(i=0;i<3;i++)
    64 		list1 = g_list_append (list1, &num1[i]);
    65 		
    66 	for(i=0;i<3;i++)
    67 		list2 = g_list_append (list2, &num2[i]);
    68 	
    69 	
    70 	list1 = g_list_concat(list1,list2);
    71 	
    72 	for(i=0;i<6;i++)
    73 	{
    74 		l = g_list_nth(list1,i);
    75 		g_assert(*(gint *)(l->data) == i+1);
    76 	}
    77 	
    78 	list2 = g_list_copy(list1);
    79 	
    80 	for(i=0;i<3;i++)
    81 	{
    82 		l = g_list_nth(list2,i);
    83 		g_assert(*(gint *)(l->data) == i+1);
    84 	}
    85 	
    86 	l = g_list_first(list2);
    87 	g_assert(*(gint *)(l->data) == 1);
    88 	
    89 	value = (int *)g_list_nth_data(list1,1);
    90 	
    91 	g_assert(*value == 2);
    92 	
    93 	l = g_list_nth(list1,3);
    94 	
    95 	l1 = g_list_nth_prev(l,2);
    96 
    97 	for(i=0;i<5;i++)
    98 	{
    99 		l = g_list_nth(l1,i);
   100 		g_assert(*(gint *)(l->data) == i+2);
   101 	}
   102 	
   103 	g_list_push_allocator(allocator);
   104 	
   105 	list3 = g_list_append(list3,&num1[2]);
   106 	
   107 	g_assert(*(gint *)(list3->data) == 3);
   108 	
   109 	g_list_pop_allocator();
   110 	
   111 	list3 = g_list_append(list3,&num1[0]);
   112 	
   113 	g_assert(*(gint *)(list3->next->data) == 1);
   114 	
   115 	list1 = g_list_append(list1,&num1[0]);
   116 	
   117 	i = g_list_length(list1);
   118 	
   119 	list1 = g_list_remove_all(list1,&num1[0]);
   120 	
   121 	i = g_list_length(list1);
   122 	
   123 	g_assert(g_list_length(list1) == 5); // should be this value as we will remove 2 1's from the list
   124 	
   125 	for(i==0;i<g_list_length(list1);i++)
   126 	{
   127 		l = g_list_nth(list1,i);
   128 		g_assert(*(gint *)(l->data) != 1);
   129 	}
   130 	
   131 	g_allocator_free(allocator);
   132 	
   133 	#ifdef SYMBIAN
   134   	testResultXml("list_test");
   135   	#endif /* EMULATOR */
   136 	
   137 	return 0;
   138 }