|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #undef G_DISABLE_ASSERT |
|
21 #undef G_LOG_DOMAIN |
|
22 |
|
23 |
|
24 #include <stdio.h> |
|
25 #include <string.h> |
|
26 #include <glib.h> |
|
27 #include <fcntl.h> |
|
28 #include <goption.h> |
|
29 |
|
30 #ifdef __SYMBIAN32__ |
|
31 #include "mrt2_glib2_test.h" |
|
32 #endif /*__SYMBIAN32__*/ |
|
33 |
|
34 #define C2P(c) ((gpointer) ((long) (c))) |
|
35 #define GINT_TO_POINTER(i) ((gpointer) (i)) |
|
36 #define GPOINTER_TO_INT(p) ((gint) (p)) |
|
37 #define TESTPASS 1 |
|
38 #define TESTFAIL 0 |
|
39 |
|
40 //Test for g_nullify_pointer |
|
41 void tg_nullify_pointer() |
|
42 { |
|
43 char nullify_pointer[]="abcd"; |
|
44 g_nullify_pointer((void*)nullify_pointer); |
|
45 g_assert(!strcmp(nullify_pointer,"\0")); |
|
46 } |
|
47 |
|
48 //Ascending |
|
49 gint compare_fun_gr(gconstpointer a,gconstpointer b) |
|
50 { |
|
51 return ((*(int *)a==*(int *)b)?0:((*(int *)a>*(int *)b)?1:-1)); |
|
52 } |
|
53 |
|
54 //Data |
|
55 gint compare_fun_gr_data(gconstpointer a,gconstpointer b,gpointer data) |
|
56 { |
|
57 return ((*(int *)a==*(int *)b)?0:((*(int *)a>*(int *)b)?1:-1)); |
|
58 } |
|
59 |
|
60 |
|
61 //Tests for g_ptr_array |
|
62 void tg_ptr_array_tests() |
|
63 { |
|
64 GPtrArray *gparray; |
|
65 int i; |
|
66 gint str_ds[12]= |
|
67 { |
|
68 12,11,10,9,8,7,6,5,4,3,2,1 |
|
69 }; |
|
70 |
|
71 gparray = g_ptr_array_new (); |
|
72 for(i=0;i<12;i++) |
|
73 { |
|
74 g_ptr_array_add (gparray, (gpointer)str_ds[i] ); |
|
75 } |
|
76 |
|
77 g_ptr_array_sort(gparray,compare_fun_gr); |
|
78 g_ptr_array_remove_range(gparray,2,4); |
|
79 g_ptr_array_sort_with_data(gparray,compare_fun_gr_data,0); |
|
80 |
|
81 |
|
82 } |
|
83 |
|
84 int cmp_func(gconstpointer a,gconstpointer b) |
|
85 { |
|
86 if(a==b) |
|
87 return 0; |
|
88 else |
|
89 return -1; |
|
90 } |
|
91 |
|
92 //Test for g_queue_find_custom |
|
93 void tg_queue_find_custom() |
|
94 { |
|
95 GQueue *q; |
|
96 GList *node; |
|
97 gpointer data; |
|
98 gpointer srch_data=GINT_TO_POINTER(5); |
|
99 int i; |
|
100 int j=10; |
|
101 int g_queue_find_custom_pass=TESTFAIL; |
|
102 |
|
103 q = g_queue_new (); |
|
104 for(i=0;i<10;i++) |
|
105 { |
|
106 g_queue_push_head (q, GINT_TO_POINTER (j)); |
|
107 j--; |
|
108 } |
|
109 g_queue_push_nth(q,GINT_TO_POINTER (5),9); |
|
110 |
|
111 node= g_queue_find_custom(q,GINT_TO_POINTER (5),cmp_func); |
|
112 |
|
113 if(node->data==srch_data) |
|
114 { |
|
115 g_queue_find_custom_pass=TESTPASS; |
|
116 } |
|
117 |
|
118 g_assert(g_queue_find_custom_pass==TESTPASS); |
|
119 } |
|
120 |
|
121 |
|
122 //Test for g_timer_reset |
|
123 void tg_timer_test() |
|
124 { |
|
125 int i=0; |
|
126 GTimer *timer; |
|
127 timer = g_timer_new (); |
|
128 g_timer_start (timer); |
|
129 do |
|
130 { |
|
131 while (g_timer_elapsed (timer, NULL) < 1); |
|
132 g_timer_reset(timer); |
|
133 i++; |
|
134 }while(i<3); |
|
135 |
|
136 g_timer_stop (timer); |
|
137 g_timer_destroy (timer); |
|
138 |
|
139 } |
|
140 |
|
141 //Test for g_try_malloc0 |
|
142 void tg_try_malloc0() |
|
143 { |
|
144 char* s; |
|
145 gpointer try = g_try_malloc0 (sizeof(s)); |
|
146 g_assert (try != NULL); |
|
147 } |
|
148 |
|
149 int main (int argc,char *argv[]) |
|
150 { |
|
151 |
|
152 #ifdef __SYMBIAN32__ |
|
153 |
|
154 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); |
|
155 #endif /*__SYMBIAN32__*/ |
|
156 |
|
157 tg_nullify_pointer(); |
|
158 tg_ptr_array_tests(); |
|
159 tg_queue_find_custom(); |
|
160 tg_timer_test(); |
|
161 tg_try_malloc0(); |
|
162 |
|
163 #ifdef __SYMBIAN32__ |
|
164 testResultXml("tmisc"); |
|
165 #endif /* EMULATOR */ |
|
166 return 0; |
|
167 } |