Tizen 2.4.0 rev3 SDK Public Release
[framework/location/maps-service.git] / test / src / api / maps_route_test.cpp
1 /* Copyright (c) 2010-2014 Samsung Electronics Co., Ltd. All rights reserved.
2  *
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "maps_route_test.h"
18 #include "maps_route_plugin.h"
19 #include "maps_route_segment_plugin.h"
20 #include "maps_error.h"
21 #include <glib.h>
22 #include "maps_route_private.h"
23 #include "maps_util.h"
24
25 /* int maps_route_create(maps_route_h* route); */
26 /* int maps_route_destroy(maps_route_h route); */
27 void utc_maps_route_create_p(void)
28 {
29         maps_route_h route = NULL;
30         int error = maps_route_create(&route);
31         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
32         g_assert(route);
33
34         error = maps_route_destroy(route);
35         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
36 }
37
38 void utc_maps_route_create_n(void)
39 {
40         int error = maps_route_create(NULL);
41         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
42
43         error = maps_route_destroy(NULL);
44         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
45 }
46
47 /*----------------------------------------------------------------------------*/
48 static int __utc_put_to_hashtable(const char* feature_str,
49         maps_string_hashtable_h t)
50 {
51         if (!feature_str || !t)
52                 return MAPS_ERROR_INVALID_PARAMETER;
53         return maps_string_hashtable_set(t, feature_str, feature_str);
54 }
55
56 class test_env
57 {
58  public:
59         maps_route_h h;
60         int iterations;
61  public:
62          test_env():h(NULL), iterations(0)
63         {
64                 const int error = maps_route_create(&h);
65                  g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
66                  g_assert(h);
67
68                 maps_string_hashtable_h data_supported = NULL;
69                 if (maps_string_hashtable_create(&data_supported) !=
70                         MAPS_ERROR_NONE)
71                          return;
72
73                  __utc_put_to_hashtable(_S(MAPS_ROUTE_PATH), data_supported);
74                  __utc_put_to_hashtable(_S(MAPS_ROUTE_SEGMENTS_PATH),
75                         data_supported);
76                  __utc_put_to_hashtable(_S(MAPS_ROUTE_SEGMENTS_MANEUVERS),
77                         data_supported);
78
79                  _maps_route_set_supported_data(h, data_supported);
80                  maps_string_hashtable_destroy(data_supported);
81
82         }
83         ~test_env()
84         {
85                 const int error = maps_route_destroy(h);
86                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
87         }
88 };
89
90 /*----------------------------------------------------------------------------*/
91
92 /* int maps_route_clone(const maps_route_h origin, maps_route_h* cloned); */
93 void utc_maps_route_clone_p(void)
94 {
95         test_env e;
96
97         maps_route_h cloned = NULL;
98         int error = maps_route_clone(e.h, &cloned);
99         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
100         g_assert(cloned);
101
102         /* TODO: add checking of other fields */
103
104         error = maps_route_destroy(cloned);
105         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
106 }
107
108 void utc_maps_route_clone_n(void)
109 {
110         test_env e;
111
112         maps_route_h cloned = NULL;
113         int error = maps_route_clone(e.h, NULL);
114         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
115
116         error = maps_route_clone(NULL, &cloned);
117         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
118 }
119
120 /* int maps_route_set_route_id(maps_route_h route, const char* route_id); */
121 /* int maps_route_get_route_id(const maps_route_h route, char** route_id); */
122 void utc_maps_route_route_id_p(void)
123 {
124         test_env e;
125
126         int error = maps_route_set_route_id(e.h, "test_string");
127         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
128
129         char* ret = NULL;
130         error = maps_route_get_route_id(e.h, &ret);
131         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
132         g_assert_cmpstr(ret, ==, "test_string");
133         g_free(ret);
134 }
135
136 void utc_maps_route_route_id_n(void)
137 {
138         test_env e;
139
140         int error = maps_route_set_route_id(NULL, "test_string");
141         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
142
143         error = maps_route_set_route_id(e.h, NULL);
144         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
145
146         char* ret = NULL;
147         error = maps_route_get_route_id(NULL, &ret);
148         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
149
150         error = maps_route_get_route_id(e.h, NULL);
151         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
152 }
153
154 /* int maps_route_set_origin(maps_route_h route, maps_coordinates_h origin); */
155 /* int maps_route_get_origin(maps_route_h route, maps_coordinates_h* origin); */
156 void utc_maps_route_origin_p(void)
157 {
158         test_env e;
159
160         maps_coordinates_h coords = NULL;
161         int error = maps_coordinates_create(11.1, 22.2, &coords);
162         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
163
164         /* start test ------------------------------------------------------- */
165         error = maps_route_set_origin(e.h, coords);
166         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
167
168         maps_coordinates_h obtained_coords = NULL;
169         error = maps_route_get_origin(e.h, &obtained_coords);
170         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
171         g_assert(obtained_coords);
172         maps_coordinates_destroy(obtained_coords);
173         /* finish test ------------------------------------------------------ */
174
175         error = maps_coordinates_destroy(coords);
176         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
177 }
178
179 void utc_maps_route_origin_n(void)
180 {
181         test_env e;
182
183         maps_coordinates_h coords = NULL;
184         int error = maps_coordinates_create(11.1, 22.2, &coords);
185         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
186
187         /* start test ------------------------------------------------------- */
188         error = maps_route_set_origin(NULL, coords);
189         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
190
191         error = maps_route_set_origin(e.h, NULL);
192         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
193
194         maps_coordinates_h obtained_coords = NULL;
195         error = maps_route_get_origin(NULL, &obtained_coords);
196         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
197
198         error = maps_route_get_origin(e.h, NULL);
199         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
200         /* finish test ------------------------------------------------------ */
201
202         error = maps_coordinates_destroy(coords);
203         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
204 }
205
206 /* int maps_route_set_destination(maps_route_h route,
207 *  maps_coordinates_h destination); */
208 /* int maps_route_get_destination(maps_route_h route,
209 *  maps_coordinates_h* destination); */
210 void utc_maps_route_destination_p(void)
211 {
212         test_env e;
213
214         maps_coordinates_h coords = NULL;
215         int error = maps_coordinates_create(11.1, 22.2, &coords);
216         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
217
218         /* start test ------------------------------------------------------- */
219         error = maps_route_set_destination(e.h, coords);
220         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
221
222         maps_coordinates_h obtained_coords = NULL;
223         error = maps_route_get_destination(e.h, &obtained_coords);
224         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
225         g_assert(obtained_coords);
226         maps_coordinates_destroy(obtained_coords);
227         /* finish test ------------------------------------------------------ */
228
229         error = maps_coordinates_destroy(coords);
230         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
231 }
232
233 void utc_maps_route_destination_n(void)
234 {
235         test_env e;
236
237         maps_coordinates_h coords = NULL;
238         int error = maps_coordinates_create(11.1, 22.2, &coords);
239         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
240
241         /* start test ------------------------------------------------------- */
242         error = maps_route_set_destination(NULL, coords);
243         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
244
245         error = maps_route_set_destination(e.h, NULL);
246         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
247
248         maps_coordinates_h obtained_coords = NULL;
249         error = maps_route_get_destination(NULL, &obtained_coords);
250         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
251
252         error = maps_route_get_destination(e.h, NULL);
253         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
254         /* finish test ------------------------------------------------------ */
255
256         error = maps_coordinates_destroy(coords);
257         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
258 }
259
260 /* int maps_route_set_bounding_box(maps_route_h route,
261 *  maps_area_h bounding_box); */
262 /* int maps_route_get_bounding_box(maps_route_h route,
263 *  maps_area_h* bounding_box); */
264 void utc_maps_route_bounding_box_p(void)
265 {
266         test_env e;
267
268         maps_coordinates_h coords = NULL;
269         int error = maps_coordinates_create(11.1, 22.2, &coords);
270         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
271
272         maps_area_h bounding_box = NULL;
273         error = maps_area_create_circle(coords, 123.4, &bounding_box);
274         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
275
276         /* start test ------------------------------------------------------- */
277         error = maps_route_set_bounding_box(e.h, bounding_box);
278         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
279
280         maps_coordinates_h obtained_bounding_box = NULL;
281         error = maps_route_get_bounding_box(e.h, &obtained_bounding_box);
282         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
283         g_assert(obtained_bounding_box);
284         maps_area_destroy(obtained_bounding_box);
285         /* finish test ------------------------------------------------------ */
286
287         error = maps_area_destroy(bounding_box);
288         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
289
290         error = maps_coordinates_destroy(coords);
291         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
292 }
293
294 void utc_maps_route_bounding_box_n(void)
295 {
296         test_env e;
297
298         maps_coordinates_h coords = NULL;
299         int error = maps_coordinates_create(11.1, 22.2, &coords);
300         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
301
302         maps_area_h bounding_box = NULL;
303         error = maps_area_create_circle(coords, 123.4, &bounding_box);
304         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
305
306         /* start test ------------------------------------------------------- */
307         error = maps_route_set_bounding_box(NULL, bounding_box);
308         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
309
310         error = maps_route_set_bounding_box(e.h, NULL);
311         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
312
313         maps_coordinates_h obtained_bounding_box = NULL;
314         error = maps_route_get_bounding_box(NULL, &obtained_bounding_box);
315         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
316
317         error = maps_route_get_bounding_box(e.h, NULL);
318         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
319         /* finish test ------------------------------------------------------ */
320
321         error = maps_area_destroy(bounding_box);
322         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
323
324         error = maps_coordinates_destroy(coords);
325         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
326 }
327
328 /* int maps_route_set_total_distance(maps_route_h route,
329 *  double total_distance); */
330 /* int maps_route_get_total_distance(maps_route_h route,
331 *  double* total_distance); */
332 void utc_maps_route_total_distance_p(void)
333 {
334         test_env e;
335
336         int error = maps_route_set_total_distance(e.h, 42.0);
337         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
338
339         double ret = .0;
340         error = maps_route_get_total_distance(e.h, &ret);
341         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
342         g_assert_cmpfloat(ret, ==, 42.0);
343 }
344
345 void utc_maps_route_total_distance_n(void)
346 {
347         test_env e;
348
349         int error = maps_route_set_total_distance(NULL, 42.0);
350         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
351
352         double ret = .0;
353         error = maps_route_get_total_distance(NULL, &ret);
354         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
355
356         error = maps_route_get_total_distance(e.h, NULL);
357         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
358 }
359
360 /* int maps_route_set_total_duration(maps_route_h route,
361 *  long total_duration); */
362 /* int maps_route_get_total_duration(maps_route_h route,
363 *  long* total_duration); */
364 void utc_maps_route_total_duration_p(void)
365 {
366         test_env e;
367
368         int error = maps_route_set_total_duration(e.h, 42);
369         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
370
371         long ret = 0;
372         error = maps_route_get_total_duration(e.h, &ret);
373         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
374         g_assert_cmpint(ret, ==, 42);
375 }
376
377 void utc_maps_route_total_duration_n(void)
378 {
379         test_env e;
380
381         int error = maps_route_set_total_duration(NULL, 42);
382         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
383
384         long ret = 0;
385         error = maps_route_get_total_duration(NULL, &ret);
386         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
387
388         error = maps_route_get_total_duration(e.h, NULL);
389         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
390 }
391
392 /* int maps_route_set_transport_mode(maps_route_h route,
393 *  maps_route_transport_mode_e transport_mode); */
394 /* int maps_route_get_transport_mode(const maps_route_h route,
395 *  maps_route_transport_mode_e* transport_mode); */
396 void utc_maps_route_transport_mode_p(void)
397 {
398         test_env e;
399
400         int error =
401                 maps_route_set_transport_mode(e.h,
402                 MAPS_ROUTE_TRANSPORT_MODE_CAR);
403         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
404
405         maps_route_transport_mode_e transport_mode =
406                 MAPS_ROUTE_TRANSPORT_MODE_TRUCK;
407         error = maps_route_get_transport_mode(e.h, &transport_mode);
408         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
409         g_assert_cmpint(transport_mode, ==, MAPS_ROUTE_TRANSPORT_MODE_CAR);
410 }
411
412 void utc_maps_route_transport_mode_n(void)
413 {
414         test_env e;
415
416         int error =
417                 maps_route_set_transport_mode(NULL,
418                 MAPS_ROUTE_TRANSPORT_MODE_CAR);
419         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
420
421         maps_route_transport_mode_e transport_mode =
422                 MAPS_ROUTE_TRANSPORT_MODE_TRUCK;
423         error = maps_route_get_transport_mode(NULL, &transport_mode);
424         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
425
426         error = maps_route_get_transport_mode(e.h, NULL);
427         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
428 }
429
430 /* int maps_route_get_distance_unit(const maps_route_h route,
431 *  maps_distance_unit_e* distance_unit); */
432 /* int maps_route_set_distance_unit(const maps_route_h route,
433 *  const maps_distance_unit_e distance_unit); */
434 void utc_maps_route_distance_unit_p(void)
435 {
436         test_env e;
437
438         int error = maps_route_set_distance_unit(e.h, MAPS_DISTANCE_UNIT_M);
439         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
440
441         maps_distance_unit_e ret = MAPS_DISTANCE_UNIT_YD;
442         error = maps_route_get_distance_unit(e.h, &ret);
443         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
444         g_assert_cmpint(ret, ==, MAPS_DISTANCE_UNIT_M);
445 }
446
447 void utc_maps_route_distance_unit_n(void)
448 {
449         test_env e;
450
451         int error = maps_route_set_distance_unit(NULL, MAPS_DISTANCE_UNIT_M);
452         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
453
454         maps_distance_unit_e ret = MAPS_DISTANCE_UNIT_YD;
455         error = maps_route_get_distance_unit(NULL, &ret);
456         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
457
458         error = maps_route_get_distance_unit(e.h, NULL);
459         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
460 }
461
462 /* typedef bool(*maps_route_properties_cb)(const char* key, const char* value,
463 *  void* user_data); */
464 /* int maps_route_set_properties(maps_route_h route,
465 *  maps_item_hashtable_h properties); */
466 /* int maps_route_foreach_property(maps_route_h route,
467 *  maps_route_properties_cb callback, void* user_data); */
468 static bool __utc_maps_route_properties_cb(int index, int total, char* key,
469         void* value, void* user_data)
470 {
471         g_assert(key);
472         g_assert(value);
473
474         g_assert_cmpstr(key, ==, "key");
475         g_assert_cmpstr((const char*) value, ==, "value");
476
477         g_assert(user_data);
478         test_env* e = (test_env*) user_data;
479
480         e->iterations++;
481
482         g_free(key);
483         g_free(value);
484
485         return true;
486 }
487
488 void utc_maps_route_properties_p(void)
489 {
490         test_env e;
491
492         maps_item_list_h obj = NULL;
493         int error = maps_item_hashtable_create(&obj);
494         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
495
496         error = maps_item_hashtable_set(obj, "key", "value",
497                 maps_item_hashtable_clone_string,
498                 maps_item_hashtable_free_string);
499         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
500
501         /* start test ------------------------------------------------------- */
502         error = maps_route_set_properties(e.h, obj);
503         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
504
505         error = maps_route_foreach_property(e.h, __utc_maps_route_properties_cb,
506                 &e);
507         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
508         g_assert_cmpint(e.iterations, ==, 1);
509         /* finish test ------------------------------------------------------ */
510
511         error = maps_item_hashtable_destroy(obj);
512         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
513 }
514
515 void utc_maps_route_properties_n(void)
516 {
517         test_env e;
518
519         maps_item_list_h obj = NULL;
520         int error = maps_item_hashtable_create(&obj);
521         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
522
523         /* start test ------------------------------------------------------- */
524         error = maps_route_set_properties(NULL, obj);
525         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
526
527         error = maps_route_set_properties(e.h, NULL);
528         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
529
530         error = maps_route_foreach_property(NULL,
531                 __utc_maps_route_properties_cb, &e);
532         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
533
534         error = maps_route_foreach_property(e.h, NULL, NULL);
535         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
536         /* finish test ------------------------------------------------------ */
537
538         error = maps_item_hashtable_destroy(obj);
539         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
540 }
541
542 /* typedef bool(*maps_route_path_cb)(int index, int total,
543 *  maps_coordinates_h coordinates, void* user_data); */
544 /* int maps_route_foreach_path(const maps_route_h route,
545 *  maps_route_path_cb callback, void* user_data); */
546 /* int maps_route_set_path(maps_route_h route, const maps_item_list_h path); */
547 static bool __utc_maps_route_path_cb(int index, int total,
548         maps_coordinates_h coordinates, void* user_data)
549 {
550         test_env* e = (test_env*) user_data;
551         g_assert(e);
552         e->iterations++;
553
554         g_assert(coordinates);
555
556         g_assert_cmpint(index, >=, 0);
557         g_assert_cmpint(total, >=, 1);
558
559         maps_coordinates_destroy(coordinates);
560
561         return true;
562 }
563
564 void utc_maps_route_path_p(void)
565 {
566         test_env e;
567
568         maps_item_list_h path = NULL;
569         int error = maps_item_list_create(&path);
570         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
571
572         maps_coordinates_h obj = NULL;
573         error = maps_coordinates_create(11.1, 22.2, &obj);
574         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
575
576         error = maps_item_list_append(path, obj, maps_coordinates_clone);
577         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
578         maps_coordinates_destroy(obj);
579
580         /* test start --------------------------------- */
581         error = maps_route_set_path(e.h, path);
582         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
583
584         error = maps_route_foreach_path(e.h, __utc_maps_route_path_cb, &e);
585         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
586         g_assert_cmpint(e.iterations, ==, 1);
587         /* test finish --------------------------------- */
588
589         error = maps_item_list_remove_all(path, maps_coordinates_destroy);
590         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
591
592         error = maps_item_list_destroy(path);
593         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
594 }
595
596 void utc_maps_route_path_n(void)
597 {
598         test_env e;
599
600         maps_item_list_h path = NULL;
601         int error = maps_item_list_create(&path);
602         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
603
604         maps_coordinates_h obj = NULL;
605         error = maps_coordinates_create(11.1, 22.2, &obj);
606
607         error = maps_item_list_append(path, obj, maps_coordinates_clone);
608         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
609         maps_coordinates_destroy(obj);
610
611         /* test start --------------------------------- */
612         error = maps_route_set_path(NULL, path);
613         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
614
615         error = maps_route_set_path(e.h, NULL);
616         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
617
618         error = maps_route_foreach_path(NULL, __utc_maps_route_path_cb, &e);
619         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
620         g_assert_cmpint(e.iterations, ==, 0);
621
622         error = maps_route_foreach_path(e.h, NULL, &e);
623         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
624         g_assert_cmpint(e.iterations, ==, 0);
625         /* test finish --------------------------------- */
626
627         /*error = maps_coordinates_destroy(obj); */
628         /*g_assert_cmpint(error, ==, MAPS_ERROR_NONE); */
629
630         error = maps_item_list_remove_all(path, maps_coordinates_destroy);
631         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
632
633         error = maps_item_list_destroy(path);
634         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
635 }
636
637 /* typedef bool(*maps_route_segment_cb)(int index, int total,
638 *  maps_route_segment_h segment, void* user_data); */
639 /* int maps_route_foreach_segment(const maps_route_h route,
640 *  maps_route_segment_cb callback, void* user_data); */
641 /* int maps_route_set_segments(maps_route_h route,
642 *  const maps_item_list_h segments); */
643 static bool __utc_maps_route_segment_cb(int index, int total,
644         maps_route_segment_h segment, void* user_data)
645 {
646         test_env* e = (test_env*) user_data;
647         g_assert(e);
648         e->iterations++;
649
650         g_assert(segment);
651
652         g_assert_cmpint(index, >=, 0);
653         g_assert_cmpint(total, >=, 1);
654
655         maps_route_segment_destroy(segment);
656
657         return true;
658 }
659
660 void utc_maps_route_segments_p(void)
661 {
662         test_env e;
663
664         maps_item_list_h segments = NULL;
665         int error = maps_item_list_create(&segments);
666         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
667
668         maps_route_segment_h obj = NULL;
669         error = maps_route_segment_create(&obj);
670
671         error = maps_item_list_append(segments, obj, maps_route_segment_clone);
672         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
673         maps_route_segment_destroy(obj);
674
675         /* test start --------------------------------- */
676         error = maps_route_set_segments(e.h, segments);
677         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
678
679         error = maps_route_foreach_segment(e.h, __utc_maps_route_segment_cb,
680                 &e);
681         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
682         g_assert_cmpint(e.iterations, ==, 1);
683         /* test finish --------------------------------- */
684
685         error = maps_item_list_remove_all(segments, maps_route_segment_destroy);
686         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
687
688         error = maps_item_list_destroy(segments);
689         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
690 }
691
692 void utc_maps_route_segments_n(void)
693 {
694         test_env e;
695
696         maps_item_list_h segments = NULL;
697         int error = maps_item_list_create(&segments);
698         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
699
700         maps_route_segment_h obj = NULL;
701         error = maps_route_segment_create(&obj);
702
703         error = maps_item_list_append(segments, obj, maps_route_segment_clone);
704         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
705         maps_route_segment_destroy(obj);
706
707         /* test start --------------------------------- */
708         error = maps_route_set_segments(NULL, segments);
709         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
710
711         error = maps_route_set_segments(e.h, NULL);
712         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
713
714         error = maps_route_foreach_segment(NULL, __utc_maps_route_segment_cb,
715                 &e);
716         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
717         g_assert_cmpint(e.iterations, ==, 0);
718
719         error = maps_route_foreach_segment(e.h, NULL, &e);
720         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
721         g_assert_cmpint(e.iterations, ==, 0);
722         /* test finish --------------------------------- */
723
724         error = maps_item_list_remove_all(segments, maps_route_segment_destroy);
725         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
726
727         error = maps_item_list_destroy(segments);
728         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
729 }
730