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.
19 * Description: ?Description
24 #undef G_DISABLE_ASSERT
35 #include "mrt2_glib2_test.h"
38 #define C2P(c) ((gpointer) ((long) (c)))
39 #define GINT_TO_POINTER(i) ((gpointer) (i))
40 #define GPOINTER_TO_INT(p) ((gint) (p))
46 gint compare_fun_gr(gconstpointer a,gconstpointer b)
48 return ((*(int *)a==*(int *)b)?0:((*(int *)a>*(int *)b)?1:-1));
52 gint compare_fun_gr_data(gconstpointer a,gconstpointer b,gpointer data)
54 return ((*(int *)a==*(int *)b)?0:((*(int *)a>*(int *)b)?1:-1));
60 GSList *slist,*st,*rem;
61 gint nums[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
64 gint g_slist_insert_data;
65 gint g_slist_insert_before_data;
70 gint g_slist_nth_data_op,g_slist_find_custom_op;
72 //Trying to use the allocators so that even they get tested!
73 GAllocator* alloc = g_allocator_new ("alloc_slist",5000);
74 g_slist_push_allocator (alloc);
78 for (i = 0; i < 10; i++)
79 slist = g_slist_append (slist, &nums[i]);
82 // 0 1 2 3 4 5 6 7 8 9
84 //Test for g_slist_insert....inserted 10 at pos 4
85 g_slist_insert(slist,&ip1,4);
86 st = g_slist_nth (slist,0);
89 g_slist_insert_data = *((gint*) st->data);
90 g_assert(g_slist_insert_data == 10);
92 /* for (i = 0; i < 10; i++)
94 st = g_slist_nth (slist, i);
95 chk_buf[i] = *((gint*) st->data);
99 // 0 1 2 3 10 4 5 6 7 8 9
101 //Test for g_slist_insert_before....inserted 15 at pos 7
102 st = g_slist_nth (slist,7);
103 g_slist_insert_before(slist,st,&ip2);
104 st = g_slist_nth (slist,0);
107 g_slist_insert_before_data = *((gint*) st->data);
108 g_assert(g_slist_insert_before_data == 15);
111 // 0 1 2 3 10 4 5 15 6 7 8 9
113 //Test for g_slist_index....finding 15 at pos 7
114 st = g_slist_nth (slist,0);
115 g_assert(g_slist_index(st,&ip2)==7);
117 //Test for g_slist_nth_data....getting 6 at position 8
118 g_slist_nth_data_op = *((gint*) g_slist_nth_data(slist,8));
119 g_assert(g_slist_nth_data_op == 6) ;
121 //Test for g_slist_position
122 st = g_slist_nth (slist,7);
123 g_assert(g_slist_position (slist,st) == 7);
125 //Test for g_slist_find_custom
126 st = g_slist_find_custom(slist,&ip3,compare_fun_gr);
127 g_slist_find_custom_op = *((gint*) st->data);
128 g_assert(g_slist_find_custom_op == 5);
130 //Test for g_slist_sort_with_data
131 st = g_slist_sort_with_data(slist,compare_fun_gr_data,&ip3);
132 for (i = 0; i < 10; i++)
134 st = g_slist_nth (slist, i);
135 g_assert (*((gint*) st->data) == i);
139 // 0 1 2 3 4 5 6 7 8 9 10 15
141 //Test for g_slist_remove_link
142 st = g_slist_nth (slist, 5);
143 rem = g_slist_remove_link(slist , st);
144 st = g_slist_nth (slist, 5);
145 g_assert (*((gint*) st->data) == 6);
148 // 0 1 2 3 4 6 7 8 9 10 15
150 //Test for g_slist_remove_all
151 g_slist_insert(slist,&ip4,4);
152 g_slist_insert(slist,&ip4,6);
153 g_slist_insert(slist,&ip4,8);
155 // 0 1 2 3 4 12 6 7 12 8 12 9 10 15
156 g_slist_remove_all(slist ,&ip4);
158 g_slist_free (slist);
159 g_slist_pop_allocator ();
163 int main (int argc,char *argv[])
168 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);
173 testResultXml("tslist");
174 #endif /* EMULATOR */