1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/glib/tsrc/BC/src/tslist.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,176 @@
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: ?Description
1.23 +*
1.24 +*/
1.25 +
1.26 +
1.27 +#undef G_DISABLE_ASSERT
1.28 +#undef G_LOG_DOMAIN
1.29 +
1.30 +
1.31 +#include <stdio.h>
1.32 +#include <string.h>
1.33 +#include <glib.h>
1.34 +#include <fcntl.h>
1.35 +#include <goption.h>
1.36 +
1.37 +#ifdef SYMBIAN
1.38 +#include "mrt2_glib2_test.h"
1.39 +#endif /*SYMBIAN*/
1.40 +
1.41 +#define C2P(c) ((gpointer) ((long) (c)))
1.42 +#define GINT_TO_POINTER(i) ((gpointer) (i))
1.43 +#define GPOINTER_TO_INT(p) ((gint) (p))
1.44 +#define TESTPASS 1
1.45 +#define TESTFAIL 0
1.46 +
1.47 +
1.48 +//Ascending
1.49 +gint compare_fun_gr(gconstpointer a,gconstpointer b)
1.50 +{
1.51 + return ((*(int *)a==*(int *)b)?0:((*(int *)a>*(int *)b)?1:-1));
1.52 +}
1.53 +
1.54 +//Data
1.55 +gint compare_fun_gr_data(gconstpointer a,gconstpointer b,gpointer data)
1.56 +{
1.57 + return ((*(int *)a==*(int *)b)?0:((*(int *)a>*(int *)b)?1:-1));
1.58 +}
1.59 +
1.60 +// Tests for slist
1.61 +void tg_slist_tests()
1.62 +{
1.63 + GSList *slist,*st,*rem;
1.64 + gint nums[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
1.65 + gint chk_buf[20];
1.66 + gint i;
1.67 + gint g_slist_insert_data;
1.68 + gint g_slist_insert_before_data;
1.69 + gint ip1 = 10;
1.70 + gint ip2 = 15;
1.71 + gint ip3 = 5;
1.72 + gint ip4 = 12;
1.73 + gint g_slist_nth_data_op,g_slist_find_custom_op;
1.74 +
1.75 + //Trying to use the allocators so that even they get tested!
1.76 + GAllocator* alloc = g_allocator_new ("alloc_slist",5000);
1.77 + g_slist_push_allocator (alloc);
1.78 +
1.79 +
1.80 + slist = NULL;
1.81 + for (i = 0; i < 10; i++)
1.82 + slist = g_slist_append (slist, &nums[i]);
1.83 +
1.84 + //List looks like:
1.85 + // 0 1 2 3 4 5 6 7 8 9
1.86 +
1.87 + //Test for g_slist_insert....inserted 10 at pos 4
1.88 + g_slist_insert(slist,&ip1,4);
1.89 + st = g_slist_nth (slist,0);
1.90 + for(i = 0;i < 4;i++)
1.91 + st = st->next;
1.92 + g_slist_insert_data = *((gint*) st->data);
1.93 + g_assert(g_slist_insert_data == 10);
1.94 +
1.95 +/* for (i = 0; i < 10; i++)
1.96 + {
1.97 + st = g_slist_nth (slist, i);
1.98 + chk_buf[i] = *((gint*) st->data);
1.99 + }*/
1.100 +
1.101 + //List looks like:
1.102 + // 0 1 2 3 10 4 5 6 7 8 9
1.103 +
1.104 + //Test for g_slist_insert_before....inserted 15 at pos 7
1.105 + st = g_slist_nth (slist,7);
1.106 + g_slist_insert_before(slist,st,&ip2);
1.107 + st = g_slist_nth (slist,0);
1.108 + for(i = 0;i < 7;i++)
1.109 + st = st->next;
1.110 + g_slist_insert_before_data = *((gint*) st->data);
1.111 + g_assert(g_slist_insert_before_data == 15);
1.112 +
1.113 + //List looks like:
1.114 + // 0 1 2 3 10 4 5 15 6 7 8 9
1.115 +
1.116 + //Test for g_slist_index....finding 15 at pos 7
1.117 + st = g_slist_nth (slist,0);
1.118 + g_assert(g_slist_index(st,&ip2)==7);
1.119 +
1.120 + //Test for g_slist_nth_data....getting 6 at position 8
1.121 + g_slist_nth_data_op = *((gint*) g_slist_nth_data(slist,8));
1.122 + g_assert(g_slist_nth_data_op == 6) ;
1.123 +
1.124 + //Test for g_slist_position
1.125 + st = g_slist_nth (slist,7);
1.126 + g_assert(g_slist_position (slist,st) == 7);
1.127 +
1.128 + //Test for g_slist_find_custom
1.129 + st = g_slist_find_custom(slist,&ip3,compare_fun_gr);
1.130 + g_slist_find_custom_op = *((gint*) st->data);
1.131 + g_assert(g_slist_find_custom_op == 5);
1.132 +
1.133 + //Test for g_slist_sort_with_data
1.134 + st = g_slist_sort_with_data(slist,compare_fun_gr_data,&ip3);
1.135 + for (i = 0; i < 10; i++)
1.136 + {
1.137 + st = g_slist_nth (slist, i);
1.138 + g_assert (*((gint*) st->data) == i);
1.139 + }
1.140 +
1.141 + //List looks like:
1.142 + // 0 1 2 3 4 5 6 7 8 9 10 15
1.143 +
1.144 + //Test for g_slist_remove_link
1.145 + st = g_slist_nth (slist, 5);
1.146 + rem = g_slist_remove_link(slist , st);
1.147 + st = g_slist_nth (slist, 5);
1.148 + g_assert (*((gint*) st->data) == 6);
1.149 +
1.150 + //List looks like:
1.151 + // 0 1 2 3 4 6 7 8 9 10 15
1.152 +
1.153 + //Test for g_slist_remove_all
1.154 + g_slist_insert(slist,&ip4,4);
1.155 + g_slist_insert(slist,&ip4,6);
1.156 + g_slist_insert(slist,&ip4,8);
1.157 + //List looks like:
1.158 + // 0 1 2 3 4 12 6 7 12 8 12 9 10 15
1.159 + g_slist_remove_all(slist ,&ip4);
1.160 +
1.161 + g_slist_free (slist);
1.162 + g_slist_pop_allocator ();
1.163 +}
1.164 +
1.165 +
1.166 +int main (int argc,char *argv[])
1.167 +{
1.168 +
1.169 + #ifdef SYMBIAN
1.170 +
1.171 + 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.172 + #endif /*SYMBIAN*/
1.173 +
1.174 + tg_slist_tests();
1.175 + #ifdef SYMBIAN
1.176 + testResultXml("tslist");
1.177 +#endif /* EMULATOR */
1.178 + return 0;
1.179 +}
1.180 \ No newline at end of file