1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/glib/tsrc/BC/src/tmisc.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,171 @@
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 +//Test for g_nullify_pointer
1.48 +void tg_nullify_pointer()
1.49 +{
1.50 + char nullify_pointer[]="abcd";
1.51 + g_nullify_pointer((void*)nullify_pointer);
1.52 + g_assert(!strcmp(nullify_pointer,"\0"));
1.53 +}
1.54 +
1.55 +//Ascending
1.56 +gint compare_fun_gr(gconstpointer a,gconstpointer b)
1.57 +{
1.58 + return ((*(int *)a==*(int *)b)?0:((*(int *)a>*(int *)b)?1:-1));
1.59 +}
1.60 +
1.61 +//Data
1.62 +gint compare_fun_gr_data(gconstpointer a,gconstpointer b,gpointer data)
1.63 +{
1.64 + return ((*(int *)a==*(int *)b)?0:((*(int *)a>*(int *)b)?1:-1));
1.65 +}
1.66 +
1.67 +
1.68 +//Tests for g_ptr_array
1.69 +void tg_ptr_array_tests()
1.70 +{
1.71 + GPtrArray *gparray;
1.72 + int i;
1.73 + gint str_ds[12]=
1.74 + {
1.75 + 12,11,10,9,8,7,6,5,4,3,2,1
1.76 + };
1.77 +
1.78 + gparray = g_ptr_array_new ();
1.79 + for(i=0;i<12;i++)
1.80 + {
1.81 + g_ptr_array_add (gparray, (gpointer)str_ds[i] );
1.82 + }
1.83 +
1.84 + g_ptr_array_sort(gparray,compare_fun_gr);
1.85 + g_ptr_array_remove_range(gparray,2,4);
1.86 + g_ptr_array_sort_with_data(gparray,compare_fun_gr_data,0);
1.87 +
1.88 +
1.89 +}
1.90 +
1.91 +int cmp_func(gconstpointer a,gconstpointer b)
1.92 +{
1.93 + if(a==b)
1.94 + return 0;
1.95 + else
1.96 + return -1;
1.97 +}
1.98 +
1.99 +//Test for g_queue_find_custom
1.100 +void tg_queue_find_custom()
1.101 +{
1.102 + GQueue *q;
1.103 + GList *node;
1.104 + gpointer data;
1.105 + gpointer srch_data=GINT_TO_POINTER(5);
1.106 + int i;
1.107 + int j=10;
1.108 + int g_queue_find_custom_pass=TESTFAIL;
1.109 +
1.110 + q = g_queue_new ();
1.111 + for(i=0;i<10;i++)
1.112 + {
1.113 + g_queue_push_head (q, GINT_TO_POINTER (j));
1.114 + j--;
1.115 + }
1.116 + g_queue_push_nth(q,GINT_TO_POINTER (5),9);
1.117 +
1.118 + node= g_queue_find_custom(q,GINT_TO_POINTER (5),cmp_func);
1.119 +
1.120 + if(node->data==srch_data)
1.121 + {
1.122 + g_queue_find_custom_pass=TESTPASS;
1.123 + }
1.124 +
1.125 + g_assert(g_queue_find_custom_pass==TESTPASS);
1.126 +}
1.127 +
1.128 +
1.129 +//Test for g_timer_reset
1.130 +void tg_timer_test()
1.131 +{
1.132 + int i=0;
1.133 + GTimer *timer;
1.134 + timer = g_timer_new ();
1.135 + g_timer_start (timer);
1.136 + do
1.137 + {
1.138 + while (g_timer_elapsed (timer, NULL) < 1);
1.139 + g_timer_reset(timer);
1.140 + i++;
1.141 + }while(i<3);
1.142 +
1.143 + g_timer_stop (timer);
1.144 + g_timer_destroy (timer);
1.145 +
1.146 +}
1.147 +
1.148 +//Test for g_try_malloc0
1.149 +void tg_try_malloc0()
1.150 +{
1.151 + char* s;
1.152 + gpointer try = g_try_malloc0 (sizeof(s));
1.153 + g_assert (try != NULL);
1.154 +}
1.155 +
1.156 +int main (int argc,char *argv[])
1.157 +{
1.158 +
1.159 + #ifdef SYMBIAN
1.160 +
1.161 + 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.162 + #endif /*SYMBIAN*/
1.163 +
1.164 + tg_nullify_pointer();
1.165 + tg_ptr_array_tests();
1.166 + tg_queue_find_custom();
1.167 + tg_timer_test();
1.168 + tg_try_malloc0();
1.169 +
1.170 +#ifdef SYMBIAN
1.171 + testResultXml("tmisc");
1.172 +#endif /* EMULATOR */
1.173 + return 0;
1.174 +}
1.175 \ No newline at end of file