sl@0: /* sl@0: * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. sl@0: * sl@0: * This library is free software; you can redistribute it and/or sl@0: * modify it under the terms of the GNU Lesser General Public sl@0: * License as published by the Free Software Foundation; either sl@0: * version 2 of the License, or (at your option) any later version. sl@0: * sl@0: * This library is distributed in the hope that it will be useful, sl@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of sl@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU sl@0: * Lesser General Public License for more details. sl@0: * sl@0: * You should have received a copy of the GNU Lesser General Public sl@0: * License along with this library; if not, write to the sl@0: * Free Software Foundation, Inc., 59 Temple Place - Suite 330, sl@0: * Boston, MA 02111-1307, USA. sl@0: * sl@0: * Description: ?Description sl@0: * sl@0: */ sl@0: sl@0: sl@0: #undef G_DISABLE_ASSERT sl@0: #undef G_LOG_DOMAIN sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #ifdef SYMBIAN sl@0: #include "mrt2_glib2_test.h" sl@0: #endif /*SYMBIAN*/ sl@0: sl@0: #define C2P(c) ((gpointer) ((long) (c))) sl@0: #define GINT_TO_POINTER(i) ((gpointer) (i)) sl@0: #define GPOINTER_TO_INT(p) ((gint) (p)) sl@0: #define TESTPASS 1 sl@0: #define TESTFAIL 0 sl@0: sl@0: //Test for g_nullify_pointer sl@0: void tg_nullify_pointer() sl@0: { sl@0: char nullify_pointer[]="abcd"; sl@0: g_nullify_pointer((void*)nullify_pointer); sl@0: g_assert(!strcmp(nullify_pointer,"\0")); sl@0: } sl@0: sl@0: //Ascending sl@0: gint compare_fun_gr(gconstpointer a,gconstpointer b) sl@0: { sl@0: return ((*(int *)a==*(int *)b)?0:((*(int *)a>*(int *)b)?1:-1)); sl@0: } sl@0: sl@0: //Data sl@0: gint compare_fun_gr_data(gconstpointer a,gconstpointer b,gpointer data) sl@0: { sl@0: return ((*(int *)a==*(int *)b)?0:((*(int *)a>*(int *)b)?1:-1)); sl@0: } sl@0: sl@0: sl@0: //Tests for g_ptr_array sl@0: void tg_ptr_array_tests() sl@0: { sl@0: GPtrArray *gparray; sl@0: int i; sl@0: gint str_ds[12]= sl@0: { sl@0: 12,11,10,9,8,7,6,5,4,3,2,1 sl@0: }; sl@0: sl@0: gparray = g_ptr_array_new (); sl@0: for(i=0;i<12;i++) sl@0: { sl@0: g_ptr_array_add (gparray, (gpointer)str_ds[i] ); sl@0: } sl@0: sl@0: g_ptr_array_sort(gparray,compare_fun_gr); sl@0: g_ptr_array_remove_range(gparray,2,4); sl@0: g_ptr_array_sort_with_data(gparray,compare_fun_gr_data,0); sl@0: sl@0: sl@0: } sl@0: sl@0: int cmp_func(gconstpointer a,gconstpointer b) sl@0: { sl@0: if(a==b) sl@0: return 0; sl@0: else sl@0: return -1; sl@0: } sl@0: sl@0: //Test for g_queue_find_custom sl@0: void tg_queue_find_custom() sl@0: { sl@0: GQueue *q; sl@0: GList *node; sl@0: gpointer data; sl@0: gpointer srch_data=GINT_TO_POINTER(5); sl@0: int i; sl@0: int j=10; sl@0: int g_queue_find_custom_pass=TESTFAIL; sl@0: sl@0: q = g_queue_new (); sl@0: for(i=0;i<10;i++) sl@0: { sl@0: g_queue_push_head (q, GINT_TO_POINTER (j)); sl@0: j--; sl@0: } sl@0: g_queue_push_nth(q,GINT_TO_POINTER (5),9); sl@0: sl@0: node= g_queue_find_custom(q,GINT_TO_POINTER (5),cmp_func); sl@0: sl@0: if(node->data==srch_data) sl@0: { sl@0: g_queue_find_custom_pass=TESTPASS; sl@0: } sl@0: sl@0: g_assert(g_queue_find_custom_pass==TESTPASS); sl@0: } sl@0: sl@0: sl@0: //Test for g_timer_reset sl@0: void tg_timer_test() sl@0: { sl@0: int i=0; sl@0: GTimer *timer; sl@0: timer = g_timer_new (); sl@0: g_timer_start (timer); sl@0: do sl@0: { sl@0: while (g_timer_elapsed (timer, NULL) < 1); sl@0: g_timer_reset(timer); sl@0: i++; sl@0: }while(i<3); sl@0: sl@0: g_timer_stop (timer); sl@0: g_timer_destroy (timer); sl@0: sl@0: } sl@0: sl@0: //Test for g_try_malloc0 sl@0: void tg_try_malloc0() sl@0: { sl@0: char* s; sl@0: gpointer try = g_try_malloc0 (sizeof(s)); sl@0: g_assert (try != NULL); sl@0: } sl@0: sl@0: int main (int argc,char *argv[]) sl@0: { sl@0: sl@0: #ifdef SYMBIAN sl@0: sl@0: 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); sl@0: #endif /*SYMBIAN*/ sl@0: sl@0: tg_nullify_pointer(); sl@0: tg_ptr_array_tests(); sl@0: tg_queue_find_custom(); sl@0: tg_timer_test(); sl@0: tg_try_malloc0(); sl@0: sl@0: #ifdef SYMBIAN sl@0: testResultXml("tmisc"); sl@0: #endif /* EMULATOR */ sl@0: return 0; sl@0: }