Update contrib.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
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.
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.
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.
25 #undef G_DISABLE_ASSERT
33 #include "mrt2_glib2_test.h"
37 int main (int argc,char *argv[])
40 GList *list1 = NULL,*list2 = NULL,*l,*l1,*list3 = NULL;
43 const char mem_allocator[] = "mem_allocator";
44 GAllocator *allocator;
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);
61 allocator = g_allocator_new(mem_allocator,500);
64 list1 = g_list_append (list1, &num1[i]);
67 list2 = g_list_append (list2, &num2[i]);
70 list1 = g_list_concat(list1,list2);
74 l = g_list_nth(list1,i);
75 g_assert(*(gint *)(l->data) == i+1);
78 list2 = g_list_copy(list1);
82 l = g_list_nth(list2,i);
83 g_assert(*(gint *)(l->data) == i+1);
86 l = g_list_first(list2);
87 g_assert(*(gint *)(l->data) == 1);
89 value = (int *)g_list_nth_data(list1,1);
91 g_assert(*value == 2);
93 l = g_list_nth(list1,3);
95 l1 = g_list_nth_prev(l,2);
100 g_assert(*(gint *)(l->data) == i+2);
103 g_list_push_allocator(allocator);
105 list3 = g_list_append(list3,&num1[2]);
107 g_assert(*(gint *)(list3->data) == 3);
109 g_list_pop_allocator();
111 list3 = g_list_append(list3,&num1[0]);
113 g_assert(*(gint *)(list3->next->data) == 1);
115 list1 = g_list_append(list1,&num1[0]);
117 i = g_list_length(list1);
119 list1 = g_list_remove_all(list1,&num1[0]);
121 i = g_list_length(list1);
123 g_assert(g_list_length(list1) == 5); // should be this value as we will remove 2 1's from the list
125 for(i==0;i<g_list_length(list1);i++)
127 l = g_list_nth(list1,i);
128 g_assert(*(gint *)(l->data) != 1);
131 g_allocator_free(allocator);
134 testResultXml("list_test");
135 #endif /* EMULATOR */