First public contribution.
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))
44 //Test for g_nullify_pointer
45 void tg_nullify_pointer()
47 char nullify_pointer[]="abcd";
48 g_nullify_pointer((void*)nullify_pointer);
49 g_assert(!strcmp(nullify_pointer,"\0"));
53 gint compare_fun_gr(gconstpointer a,gconstpointer b)
55 return ((*(int *)a==*(int *)b)?0:((*(int *)a>*(int *)b)?1:-1));
59 gint compare_fun_gr_data(gconstpointer a,gconstpointer b,gpointer data)
61 return ((*(int *)a==*(int *)b)?0:((*(int *)a>*(int *)b)?1:-1));
65 //Tests for g_ptr_array
66 void tg_ptr_array_tests()
72 12,11,10,9,8,7,6,5,4,3,2,1
75 gparray = g_ptr_array_new ();
78 g_ptr_array_add (gparray, (gpointer)str_ds[i] );
81 g_ptr_array_sort(gparray,compare_fun_gr);
82 g_ptr_array_remove_range(gparray,2,4);
83 g_ptr_array_sort_with_data(gparray,compare_fun_gr_data,0);
88 int cmp_func(gconstpointer a,gconstpointer b)
96 //Test for g_queue_find_custom
97 void tg_queue_find_custom()
102 gpointer srch_data=GINT_TO_POINTER(5);
105 int g_queue_find_custom_pass=TESTFAIL;
110 g_queue_push_head (q, GINT_TO_POINTER (j));
113 g_queue_push_nth(q,GINT_TO_POINTER (5),9);
115 node= g_queue_find_custom(q,GINT_TO_POINTER (5),cmp_func);
117 if(node->data==srch_data)
119 g_queue_find_custom_pass=TESTPASS;
122 g_assert(g_queue_find_custom_pass==TESTPASS);
126 //Test for g_timer_reset
131 timer = g_timer_new ();
132 g_timer_start (timer);
135 while (g_timer_elapsed (timer, NULL) < 1);
136 g_timer_reset(timer);
140 g_timer_stop (timer);
141 g_timer_destroy (timer);
145 //Test for g_try_malloc0
146 void tg_try_malloc0()
149 gpointer try = g_try_malloc0 (sizeof(s));
150 g_assert (try != NULL);
153 int main (int argc,char *argv[])
158 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);
161 tg_nullify_pointer();
162 tg_ptr_array_tests();
163 tg_queue_find_custom();
168 testResultXml("tmisc");
169 #endif /* EMULATOR */