84 gboolean ret; |
76 gboolean ret; |
85 |
77 |
86 garray = g_array_new (FALSE,FALSE,sizeof(gint)); |
78 garray = g_array_new (FALSE,FALSE,sizeof(gint)); |
87 if(garray == NULL) |
79 if(garray == NULL) |
88 { |
80 { |
89 std_log(LOG_FILENAME_LINE, "Array not created"); |
81 g_print( "Array not created"); |
90 assert_failed = 1; |
82 assert_failed = 1; |
91 return ; |
83 return ; |
92 } |
84 } |
93 |
85 |
94 /*Insert values into array*/ |
86 /*Insert values into array*/ |
95 g_array_insert_vals(garray,0,array,ARRAY_SIZE); |
87 g_array_insert_vals(garray,0,array,ARRAY_SIZE); |
96 |
88 |
97 /* test for deleting single element in an array. Removing the element with index 1*/ |
89 /* test for deleting single element in an array. Removing the element with index 1*/ |
98 std_log(LOG_FILENAME_LINE, "Delete array element at index 1"); |
90 g_print( "Delete array element at index 1"); |
99 garray = g_array_remove_index(garray,1); |
91 garray = g_array_remove_index(garray,1); |
100 |
92 |
101 if(garray == NULL ) |
93 if(garray == NULL ) |
102 { |
94 { |
103 std_log(LOG_FILENAME_LINE, "NULL return by g_array_remove_index"); |
95 g_print( "NULL return by g_array_remove_index"); |
104 assert_failed = 1; |
96 assert_failed = 1; |
105 return ; |
97 return ; |
106 } |
98 } |
107 |
99 |
108 /*Print the array elements after remove*/ |
100 /*Print the array elements after remove*/ |
109 for(i=0; i<garray->len; i++) |
101 for(i=0; i<garray->len; i++) |
110 { |
102 { |
111 std_log(LOG_FILENAME_LINE, "Current array element at index %d is %d", i,g_array_index(garray, gint, i)); |
103 g_print( "Current array element at index %d is %d", i,g_array_index(garray, gint, i)); |
112 } |
104 } |
113 |
105 |
114 /*Check if the array size is now 4 and element at index 1 is not 5 after removal*/ |
106 /*Check if the array size is now 4 and element at index 1 is not 5 after removal*/ |
115 |
107 |
116 ret = compare_array(garray, array_after_remove_index_1, ARRAY_SIZE_AFTER_REMOVE_INDEX); |
108 ret = compare_array(garray, array_after_remove_index_1, ARRAY_SIZE_AFTER_REMOVE_INDEX); |
117 if ( !ret) |
109 if ( !ret) |
118 { |
110 { |
119 std_log(LOG_FILENAME_LINE, "Array Element not properly deleted by g_array_remove_index"); |
111 g_print( "Array Element not properly deleted by g_array_remove_index"); |
120 assert_failed = 1; |
112 assert_failed = 1; |
121 g_array_free(garray,TRUE); |
113 g_array_free(garray,TRUE); |
122 return ; |
114 return ; |
123 } |
115 } |
124 |
116 |
125 |
117 |
126 /* Test to remove index element 2 using g_array_remove_index_fast*/ |
118 /* Test to remove index element 2 using g_array_remove_index_fast*/ |
127 |
119 |
128 std_log(LOG_FILENAME_LINE, "Delete array element at index 2"); |
120 g_print( "Delete array element at index 2"); |
129 garray =g_array_remove_index_fast(garray,2); |
121 garray =g_array_remove_index_fast(garray,2); |
130 if(garray == NULL) |
122 if(garray == NULL) |
131 { |
123 { |
132 std_log(LOG_FILENAME_LINE, "NULL return by g_array_remove_index_fast"); |
124 g_print( "NULL return by g_array_remove_index_fast"); |
133 assert_failed = 1; |
125 assert_failed = 1; |
134 return ; |
126 return ; |
135 } |
127 } |
136 |
128 |
137 for(i=0; i<garray->len; i++) |
129 for(i=0; i<garray->len; i++) |
138 { |
130 { |
139 std_log(LOG_FILENAME_LINE, "Current array element at index %d is %d", i,g_array_index(garray, gint, i)); |
131 g_print( "Current array element at index %d is %d", i,g_array_index(garray, gint, i)); |
140 } |
132 } |
141 |
133 |
142 ret = compare_array(garray, array_after_remove_index_fast_2, ARRAY_SIZE_AFTER_REMOVE_INDEX_FAST); |
134 ret = compare_array(garray, array_after_remove_index_fast_2, ARRAY_SIZE_AFTER_REMOVE_INDEX_FAST); |
143 if ( !ret) |
135 if ( !ret) |
144 { |
136 { |
145 std_log(LOG_FILENAME_LINE, "Array Element not properly deleted by g_array_remove_index_fast"); |
137 g_print( "Array Element not properly deleted by g_array_remove_index_fast"); |
146 assert_failed = 1; |
138 assert_failed = 1; |
147 g_array_free(garray,TRUE); |
139 g_array_free(garray,TRUE); |
148 return; |
140 return; |
149 } |
141 } |
150 g_array_free(garray,TRUE); |
142 g_array_free(garray,TRUE); |
164 int i; |
156 int i; |
165 |
157 |
166 garray = g_array_new (FALSE,FALSE,sizeof(gint)); |
158 garray = g_array_new (FALSE,FALSE,sizeof(gint)); |
167 if(garray == NULL) |
159 if(garray == NULL) |
168 { |
160 { |
169 std_log(LOG_FILENAME_LINE, "Array not created"); |
161 g_print( "Array not created"); |
170 assert_failed = 1; |
162 assert_failed = 1; |
171 return ; |
163 return ; |
172 } |
164 } |
173 |
165 |
174 g_array_insert_vals(garray,0,array,ARRAY_SIZE); |
166 g_array_insert_vals(garray,0,array,ARRAY_SIZE); |
175 for(i=0; i<garray->len;i++) |
167 for(i=0; i<garray->len;i++) |
176 { |
168 { |
177 std_log(LOG_FILENAME_LINE, "Current array elements %d is %d", i,g_array_index(garray, gint, i)); |
169 g_print( "Current array elements %d is %d", i,g_array_index(garray, gint, i)); |
178 } |
170 } |
179 |
171 |
180 garray = g_array_remove_range(garray,3,2); /*remove two elements from index 3 */ |
172 garray = g_array_remove_range(garray,3,2); /*remove two elements from index 3 */ |
181 |
173 |
182 if(garray == NULL) |
174 if(garray == NULL) |
183 { |
175 { |
184 std_log(LOG_FILENAME_LINE,"Elements not deleted properly by g_array_remove_range"); |
176 g_print("Elements not deleted properly by g_array_remove_range"); |
185 assert_failed = 1; |
177 assert_failed = 1; |
186 return ; |
178 return ; |
187 |
179 |
188 } |
180 } |
189 |
181 |
190 /*print the array elements */ |
182 /*print the array elements */ |
191 for(i=0; i<garray->len;i++) |
183 for(i=0; i<garray->len;i++) |
192 { |
184 { |
193 std_log(LOG_FILENAME_LINE, "Curent array element(after deletion) %d is %d", i,g_array_index(garray, gint, i)); |
185 g_print( "Curent array element(after deletion) %d is %d", i,g_array_index(garray, gint, i)); |
194 } |
186 } |
195 |
187 |
196 |
188 |
197 ret = compare_array(garray, array_after_remove_index_range, ARRAY_SIZE_AFTER_REMOVE_INDEX_RANGE); |
189 ret = compare_array(garray, array_after_remove_index_range, ARRAY_SIZE_AFTER_REMOVE_INDEX_RANGE); |
198 if(!ret) |
190 if(!ret) |
199 { |
191 { |
200 std_log(LOG_FILENAME_LINE,"Elements not deleted properly"); |
192 g_print("Elements not deleted properly"); |
201 assert_failed = 1; |
193 assert_failed = 1; |
202 g_array_free(garray,TRUE); |
194 g_array_free(garray,TRUE); |
203 return ; |
195 return ; |
204 } |
196 } |
205 g_array_free(garray,TRUE); |
197 g_array_free(garray,TRUE); |
221 |
213 |
222 garray = g_array_new (FALSE,FALSE,sizeof(gint)); |
214 garray = g_array_new (FALSE,FALSE,sizeof(gint)); |
223 |
215 |
224 if(garray == NULL) |
216 if(garray == NULL) |
225 { |
217 { |
226 std_log(LOG_FILENAME_LINE, "Array not created"); |
218 g_print( "Array not created"); |
227 assert_failed = 1; |
219 assert_failed = 1; |
228 return ; |
220 return ; |
229 } |
221 } |
230 g_array_insert_vals(garray,0,array,ARRAY_SIZE); |
222 g_array_insert_vals(garray,0,array,ARRAY_SIZE); |
231 |
223 |
232 g_array_sort(garray, sort); |
224 g_array_sort(garray, sort); |
233 |
225 |
234 if(garray == NULL) |
226 if(garray == NULL) |
235 { |
227 { |
236 std_log(LOG_FILENAME_LINE, "Array not sorted"); |
228 g_print( "Array not sorted"); |
237 assert_failed = 1; |
229 assert_failed = 1; |
238 return ; |
230 return ; |
239 } |
231 } |
240 |
232 |
241 std_log(LOG_FILENAME_LINE,"SORTED ARRAY"); |
233 g_print("SORTED ARRAY"); |
242 |
234 |
243 for(i=0;i<garray->len;i++) |
235 for(i=0;i<garray->len;i++) |
244 { |
236 { |
245 std_log(LOG_FILENAME_LINE, "Element %d is %d", i,g_array_index(garray, gint, i)); |
237 g_print( "Element %d is %d", i,g_array_index(garray, gint, i)); |
246 } |
238 } |
247 |
239 |
248 ret = compare_array(garray, sort_array, ARRAY_SIZE); |
240 ret = compare_array(garray, sort_array, ARRAY_SIZE); |
249 |
241 |
250 if(!ret) |
242 if(!ret) |
251 { |
243 { |
252 std_log(LOG_FILENAME_LINE, "Array not sorted correctly"); |
244 g_print( "Array not sorted correctly"); |
253 assert_failed = 1; |
245 assert_failed = 1; |
254 return ; |
246 return ; |
255 } |
247 } |
256 |
248 |
257 g_array_free(garray,TRUE); |
249 g_array_free(garray,TRUE); |
258 |
250 |
259 |
251 |
260 garray = g_array_new (FALSE,FALSE,sizeof(gint)); |
252 garray = g_array_new (FALSE,FALSE,sizeof(gint)); |
261 if(garray == NULL) |
253 if(garray == NULL) |
262 { |
254 { |
263 std_log(LOG_FILENAME_LINE, "Array not created"); |
255 g_print( "Array not created"); |
264 return ; |
256 return ; |
265 } |
257 } |
266 g_array_insert_vals(garray,0,array,ARRAY_SIZE); |
258 g_array_insert_vals(garray,0,array,ARRAY_SIZE); |
267 |
259 |
268 g_array_sort_with_data (garray, sort_userdata, NULL); |
260 g_array_sort_with_data (garray, sort_userdata, NULL); |
269 |
261 |
270 if(garray == NULL) |
262 if(garray == NULL) |
271 { |
263 { |
272 std_log(LOG_FILENAME_LINE, "Array not sorted with user data"); |
264 g_print( "Array not sorted with user data"); |
273 assert_failed = 1; |
265 assert_failed = 1; |
274 return ; |
266 return ; |
275 } |
267 } |
276 |
268 |
277 std_log(LOG_FILENAME_LINE,"SORTED ARRAY WITH USERDATA"); |
269 g_print("SORTED ARRAY WITH USERDATA"); |
278 for(i=0;i<garray->len;i++) |
270 for(i=0;i<garray->len;i++) |
279 { |
271 { |
280 std_log(LOG_FILENAME_LINE, "Element %d is %d", i,g_array_index(garray, gint, i)); |
272 g_print( "Element %d is %d", i,g_array_index(garray, gint, i)); |
281 } |
273 } |
282 |
274 |
283 ret = compare_array(garray, sort_array, ARRAY_SIZE); |
275 ret = compare_array(garray, sort_array, ARRAY_SIZE); |
284 if(!ret) |
276 if(!ret) |
285 { |
277 { |
286 std_log(LOG_FILENAME_LINE, "Array not sorted correctly with user data"); |
278 g_print( "Array not sorted correctly with user data"); |
287 assert_failed = 1; |
279 assert_failed = 1; |
288 return ; |
280 return ; |
289 } |
281 } |
290 g_array_free(garray,TRUE); |
282 g_array_free(garray,TRUE); |
291 } |
283 } |
292 |
284 |
293 |
285 |
294 int main (void) |
286 int main (void) |
295 { |
287 { |
296 test_test_remove_array_index_range(); |
288 #ifdef __SYMBIAN32__ |
|
289 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); |
|
290 g_set_print_handler(mrtPrintHandler); |
|
291 #endif /*__SYMBIAN32__*/ |
|
292 |
|
293 g_print("Test array1-test Start"); |
|
294 test_test_remove_array_index_range(); |
297 test_sort_array(); |
295 test_sort_array(); |
298 test_remove_array_index(); |
296 test_remove_array_index(); |
299 |
297 |
300 if(assert_failed) |
298 if(assert_failed) |
301 std_log(LOG_FILENAME_LINE,"Test Failed"); |
299 g_print("Test array1-test Failed"); |
302 else |
300 else |
303 std_log(LOG_FILENAME_LINE,"Test Successful"); |
301 g_print("Test array1-test Successful"); |
304 |
302 |
305 create_xml(0); |
303 #if __SYMBIAN32__ |
|
304 testResultXml("array1-test"); |
|
305 #endif /* EMULATOR */ |
306 return 0; |
306 return 0; |
307 } |
307 } |
308 |
308 |
309 |
309 |