9576ac96d6d98f24b05d5e499b36324646fa3332
[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,
162 #if _MAPS_COORDS_3D_
163                 33.3,
164 #endif
165                 &coords);
166         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
167
168         /* start test ------------------------------------------------------- */
169         error = maps_route_set_origin(e.h, coords);
170         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
171
172         maps_coordinates_h obtained_coords = NULL;
173         error = maps_route_get_origin(e.h, &obtained_coords);
174         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
175         g_assert(obtained_coords);
176         maps_coordinates_destroy(obtained_coords);
177         /* finish test ------------------------------------------------------ */
178
179         error = maps_coordinates_destroy(coords);
180         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
181 }
182
183 void utc_maps_route_origin_n(void)
184 {
185         test_env e;
186
187         maps_coordinates_h coords = NULL;
188         int error = maps_coordinates_create(11.1, 22.2,
189 #if _MAPS_COORDS_3D_
190                 33.3,
191 #endif
192                 &coords);
193         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
194
195         /* start test ------------------------------------------------------- */
196         error = maps_route_set_origin(NULL, coords);
197         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
198
199         error = maps_route_set_origin(e.h, NULL);
200         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
201
202         maps_coordinates_h obtained_coords = NULL;
203         error = maps_route_get_origin(NULL, &obtained_coords);
204         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
205
206         error = maps_route_get_origin(e.h, NULL);
207         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
208         /* finish test ------------------------------------------------------ */
209
210         error = maps_coordinates_destroy(coords);
211         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
212 }
213
214 /* int maps_route_set_destination(maps_route_h route,
215 *  maps_coordinates_h destination); */
216 /* int maps_route_get_destination(maps_route_h route,
217 *  maps_coordinates_h* destination); */
218 void utc_maps_route_destination_p(void)
219 {
220         test_env e;
221
222         maps_coordinates_h coords = NULL;
223         int error = maps_coordinates_create(11.1, 22.2,
224 #if _MAPS_COORDS_3D_
225                 33.3,
226 #endif
227                 &coords);
228         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
229
230         /* start test ------------------------------------------------------- */
231         error = maps_route_set_destination(e.h, coords);
232         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
233
234         maps_coordinates_h obtained_coords = NULL;
235         error = maps_route_get_destination(e.h, &obtained_coords);
236         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
237         g_assert(obtained_coords);
238         maps_coordinates_destroy(obtained_coords);
239         /* finish test ------------------------------------------------------ */
240
241         error = maps_coordinates_destroy(coords);
242         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
243 }
244
245 void utc_maps_route_destination_n(void)
246 {
247         test_env e;
248
249         maps_coordinates_h coords = NULL;
250         int error = maps_coordinates_create(11.1, 22.2,
251 #if _MAPS_COORDS_3D_
252                 33.3,
253 #endif
254                 &coords);
255         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
256
257         /* start test ------------------------------------------------------- */
258         error = maps_route_set_destination(NULL, coords);
259         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
260
261         error = maps_route_set_destination(e.h, NULL);
262         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
263
264         maps_coordinates_h obtained_coords = NULL;
265         error = maps_route_get_destination(NULL, &obtained_coords);
266         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
267
268         error = maps_route_get_destination(e.h, NULL);
269         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
270         /* finish test ------------------------------------------------------ */
271
272         error = maps_coordinates_destroy(coords);
273         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
274 }
275
276 /* int maps_route_set_bounding_box(maps_route_h route,
277 *  maps_area_h bounding_box); */
278 /* int maps_route_get_bounding_box(maps_route_h route,
279 *  maps_area_h* bounding_box); */
280 void utc_maps_route_bounding_box_p(void)
281 {
282         test_env e;
283
284         maps_coordinates_h coords = NULL;
285         int error = maps_coordinates_create(11.1, 22.2,
286 #if _MAPS_COORDS_3D_
287                 33.3,
288 #endif
289                 &coords);
290         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
291
292         maps_area_h bounding_box = NULL;
293         error = maps_area_create_circle(coords, 123.4, &bounding_box);
294         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
295
296         /* start test ------------------------------------------------------- */
297         error = maps_route_set_bounding_box(e.h, bounding_box);
298         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
299
300         maps_coordinates_h obtained_bounding_box = NULL;
301         error = maps_route_get_bounding_box(e.h, &obtained_bounding_box);
302         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
303         g_assert(obtained_bounding_box);
304         maps_area_destroy(obtained_bounding_box);
305         /* finish test ------------------------------------------------------ */
306
307         error = maps_area_destroy(bounding_box);
308         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
309
310         error = maps_coordinates_destroy(coords);
311         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
312 }
313
314 void utc_maps_route_bounding_box_n(void)
315 {
316         test_env e;
317
318         maps_coordinates_h coords = NULL;
319         int error = maps_coordinates_create(11.1, 22.2,
320 #if _MAPS_COORDS_3D_
321                 33.3,
322 #endif
323                 &coords);
324         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
325
326         maps_area_h bounding_box = NULL;
327         error = maps_area_create_circle(coords, 123.4, &bounding_box);
328         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
329
330         /* start test ------------------------------------------------------- */
331         error = maps_route_set_bounding_box(NULL, bounding_box);
332         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
333
334         error = maps_route_set_bounding_box(e.h, NULL);
335         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
336
337         maps_coordinates_h obtained_bounding_box = NULL;
338         error = maps_route_get_bounding_box(NULL, &obtained_bounding_box);
339         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
340
341         error = maps_route_get_bounding_box(e.h, NULL);
342         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
343         /* finish test ------------------------------------------------------ */
344
345         error = maps_area_destroy(bounding_box);
346         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
347
348         error = maps_coordinates_destroy(coords);
349         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
350 }
351
352 /* int maps_route_set_total_distance(maps_route_h route,
353 *  double total_distance); */
354 /* int maps_route_get_total_distance(maps_route_h route,
355 *  double* total_distance); */
356 void utc_maps_route_total_distance_p(void)
357 {
358         test_env e;
359
360         int error = maps_route_set_total_distance(e.h, 42.0);
361         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
362
363         double ret = .0;
364         error = maps_route_get_total_distance(e.h, &ret);
365         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
366         g_assert_cmpfloat(ret, ==, 42.0);
367 }
368
369 void utc_maps_route_total_distance_n(void)
370 {
371         test_env e;
372
373         int error = maps_route_set_total_distance(NULL, 42.0);
374         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
375
376         double ret = .0;
377         error = maps_route_get_total_distance(NULL, &ret);
378         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
379
380         error = maps_route_get_total_distance(e.h, NULL);
381         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
382 }
383
384 /* int maps_route_set_total_duration(maps_route_h route,
385 *  long total_duration); */
386 /* int maps_route_get_total_duration(maps_route_h route,
387 *  long* total_duration); */
388 void utc_maps_route_total_duration_p(void)
389 {
390         test_env e;
391
392         int error = maps_route_set_total_duration(e.h, 42);
393         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
394
395         long ret = 0;
396         error = maps_route_get_total_duration(e.h, &ret);
397         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
398         g_assert_cmpint(ret, ==, 42);
399 }
400
401 void utc_maps_route_total_duration_n(void)
402 {
403         test_env e;
404
405         int error = maps_route_set_total_duration(NULL, 42);
406         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
407
408         long ret = 0;
409         error = maps_route_get_total_duration(NULL, &ret);
410         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
411
412         error = maps_route_get_total_duration(e.h, NULL);
413         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
414 }
415
416 /* int maps_route_set_transport_mode(maps_route_h route,
417 *  maps_route_transport_mode_e transport_mode); */
418 /* int maps_route_get_transport_mode(const maps_route_h route,
419 *  maps_route_transport_mode_e* transport_mode); */
420 void utc_maps_route_transport_mode_p(void)
421 {
422         test_env e;
423
424         int error =
425                 maps_route_set_transport_mode(e.h,
426                 MAPS_ROUTE_TRANSPORT_MODE_CAR);
427         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
428
429         maps_route_transport_mode_e transport_mode =
430                 MAPS_ROUTE_TRANSPORT_MODE_TRUCK;
431         error = maps_route_get_transport_mode(e.h, &transport_mode);
432         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
433         g_assert_cmpint(transport_mode, ==, MAPS_ROUTE_TRANSPORT_MODE_CAR);
434 }
435
436 void utc_maps_route_transport_mode_n(void)
437 {
438         test_env e;
439
440         int error =
441                 maps_route_set_transport_mode(NULL,
442                 MAPS_ROUTE_TRANSPORT_MODE_CAR);
443         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
444
445         maps_route_transport_mode_e transport_mode =
446                 MAPS_ROUTE_TRANSPORT_MODE_TRUCK;
447         error = maps_route_get_transport_mode(NULL, &transport_mode);
448         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
449
450         error = maps_route_get_transport_mode(e.h, NULL);
451         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
452 }
453
454 /* int maps_route_get_distance_unit(const maps_route_h route,
455 *  maps_distance_unit_e* distance_unit); */
456 /* int maps_route_set_distance_unit(const maps_route_h route,
457 *  const maps_distance_unit_e distance_unit); */
458 void utc_maps_route_distance_unit_p(void)
459 {
460         test_env e;
461
462         int error = maps_route_set_distance_unit(e.h, MAPS_DISTANCE_UNIT_M);
463         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
464
465         maps_distance_unit_e ret = MAPS_DISTANCE_UNIT_YD;
466         error = maps_route_get_distance_unit(e.h, &ret);
467         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
468         g_assert_cmpint(ret, ==, MAPS_DISTANCE_UNIT_M);
469 }
470
471 void utc_maps_route_distance_unit_n(void)
472 {
473         test_env e;
474
475         int error = maps_route_set_distance_unit(NULL, MAPS_DISTANCE_UNIT_M);
476         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
477
478         maps_distance_unit_e ret = MAPS_DISTANCE_UNIT_YD;
479         error = maps_route_get_distance_unit(NULL, &ret);
480         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
481
482         error = maps_route_get_distance_unit(e.h, NULL);
483         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
484 }
485
486 /* typedef bool(*maps_route_properties_cb)(const char* key, const char* value,
487 *  void* user_data); */
488 /* int maps_route_set_properties(maps_route_h route,
489 *  maps_item_hashtable_h properties); */
490 /* int maps_route_foreach_property(maps_route_h route,
491 *  maps_route_properties_cb callback, void* user_data); */
492 static bool __utc_maps_route_properties_cb(int index, int total, char* key,
493         void* value, void* user_data)
494 {
495         g_assert(key);
496         g_assert(value);
497
498         g_assert_cmpstr(key, ==, "key");
499         g_assert_cmpstr((const char*) value, ==, "value");
500
501         g_assert(user_data);
502         test_env* e = (test_env*) user_data;
503
504         e->iterations++;
505
506         g_free(key);
507         g_free(value);
508
509         return true;
510 }
511
512 void utc_maps_route_properties_p(void)
513 {
514         test_env e;
515
516         maps_item_list_h obj = NULL;
517         int error = maps_item_hashtable_create(&obj);
518         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
519
520         error = maps_item_hashtable_set(obj, "key", "value",
521                 maps_item_hashtable_clone_string,
522                 maps_item_hashtable_free_string);
523         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
524
525         /* start test ------------------------------------------------------- */
526         error = maps_route_set_properties(e.h, obj);
527         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
528
529         error = maps_route_foreach_property(e.h, __utc_maps_route_properties_cb,
530                 &e);
531         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
532         g_assert_cmpint(e.iterations, ==, 1);
533         /* finish test ------------------------------------------------------ */
534
535         error = maps_item_hashtable_destroy(obj);
536         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
537 }
538
539 void utc_maps_route_properties_n(void)
540 {
541         test_env e;
542
543         maps_item_list_h obj = NULL;
544         int error = maps_item_hashtable_create(&obj);
545         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
546
547         /* start test ------------------------------------------------------- */
548         error = maps_route_set_properties(NULL, obj);
549         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
550
551         error = maps_route_set_properties(e.h, NULL);
552         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
553
554         error = maps_route_foreach_property(NULL,
555                 __utc_maps_route_properties_cb, &e);
556         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
557
558         error = maps_route_foreach_property(e.h, NULL, NULL);
559         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
560         /* finish test ------------------------------------------------------ */
561
562         error = maps_item_hashtable_destroy(obj);
563         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
564 }
565
566 /* typedef bool(*maps_route_path_cb)(int index, int total,
567 *  maps_coordinates_h coordinates, void* user_data); */
568 /* int maps_route_foreach_path(const maps_route_h route,
569 *  maps_route_path_cb callback, void* user_data); */
570 /* int maps_route_set_path(maps_route_h route, const maps_item_list_h path); */
571 static bool __utc_maps_route_path_cb(int index, int total,
572         maps_coordinates_h coordinates, void* user_data)
573 {
574         test_env* e = (test_env*) user_data;
575         g_assert(e);
576         e->iterations++;
577
578         g_assert(coordinates);
579
580         g_assert_cmpint(index, >=, 0);
581         g_assert_cmpint(total, >=, 1);
582
583         maps_coordinates_destroy(coordinates);
584
585         return true;
586 }
587
588 void utc_maps_route_path_p(void)
589 {
590         test_env e;
591
592         maps_item_list_h path = NULL;
593         int error = maps_item_list_create(&path);
594         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
595
596         maps_coordinates_h obj = NULL;
597         error = maps_coordinates_create(11.1, 22.2, &obj);
598         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
599
600         error = maps_item_list_append(path, obj, maps_coordinates_clone);
601         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
602         maps_coordinates_destroy(obj);
603
604         /* test start --------------------------------- */
605         error = maps_route_set_path(e.h, path);
606         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
607
608         error = maps_route_foreach_path(e.h, __utc_maps_route_path_cb, &e);
609         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
610         g_assert_cmpint(e.iterations, ==, 1);
611         /* test finish --------------------------------- */
612
613         error = maps_item_list_remove_all(path, maps_coordinates_destroy);
614         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
615
616         error = maps_item_list_destroy(path);
617         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
618 }
619
620 void utc_maps_route_path_n(void)
621 {
622         test_env e;
623
624         maps_item_list_h path = NULL;
625         int error = maps_item_list_create(&path);
626         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
627
628         maps_coordinates_h obj = NULL;
629         error = maps_coordinates_create(11.1, 22.2, &obj);
630
631         error = maps_item_list_append(path, obj, maps_coordinates_clone);
632         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
633         maps_coordinates_destroy(obj);
634
635         /* test start --------------------------------- */
636         error = maps_route_set_path(NULL, path);
637         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
638
639         error = maps_route_set_path(e.h, NULL);
640         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
641
642         error = maps_route_foreach_path(NULL, __utc_maps_route_path_cb, &e);
643         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
644         g_assert_cmpint(e.iterations, ==, 0);
645
646         error = maps_route_foreach_path(e.h, NULL, &e);
647         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
648         g_assert_cmpint(e.iterations, ==, 0);
649         /* test finish --------------------------------- */
650
651         /*error = maps_coordinates_destroy(obj); */
652         /*g_assert_cmpint(error, ==, MAPS_ERROR_NONE); */
653
654         error = maps_item_list_remove_all(path, maps_coordinates_destroy);
655         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
656
657         error = maps_item_list_destroy(path);
658         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
659 }
660
661 /* typedef bool(*maps_route_segment_cb)(int index, int total,
662 *  maps_route_segment_h segment, void* user_data); */
663 /* int maps_route_foreach_segment(const maps_route_h route,
664 *  maps_route_segment_cb callback, void* user_data); */
665 /* int maps_route_set_segments(maps_route_h route,
666 *  const maps_item_list_h segments); */
667 static bool __utc_maps_route_segment_cb(int index, int total,
668         maps_route_segment_h segment, void* user_data)
669 {
670         test_env* e = (test_env*) user_data;
671         g_assert(e);
672         e->iterations++;
673
674         g_assert(segment);
675
676         g_assert_cmpint(index, >=, 0);
677         g_assert_cmpint(total, >=, 1);
678
679         maps_route_segment_destroy(segment);
680
681         return true;
682 }
683
684 void utc_maps_route_segments_p(void)
685 {
686         test_env e;
687
688         maps_item_list_h segments = NULL;
689         int error = maps_item_list_create(&segments);
690         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
691
692         maps_route_segment_h obj = NULL;
693         error = maps_route_segment_create(&obj);
694
695         error = maps_item_list_append(segments, obj, maps_route_segment_clone);
696         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
697         maps_route_segment_destroy(obj);
698
699         /* test start --------------------------------- */
700         error = maps_route_set_segments(e.h, segments);
701         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
702
703         error = maps_route_foreach_segment(e.h, __utc_maps_route_segment_cb,
704                 &e);
705         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
706         g_assert_cmpint(e.iterations, ==, 1);
707         /* test finish --------------------------------- */
708
709         error = maps_item_list_remove_all(segments, maps_route_segment_destroy);
710         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
711
712         error = maps_item_list_destroy(segments);
713         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
714 }
715
716 void utc_maps_route_segments_n(void)
717 {
718         test_env e;
719
720         maps_item_list_h segments = NULL;
721         int error = maps_item_list_create(&segments);
722         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
723
724         maps_route_segment_h obj = NULL;
725         error = maps_route_segment_create(&obj);
726
727         error = maps_item_list_append(segments, obj, maps_route_segment_clone);
728         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
729         maps_route_segment_destroy(obj);
730
731         /* test start --------------------------------- */
732         error = maps_route_set_segments(NULL, segments);
733         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
734
735         error = maps_route_set_segments(e.h, NULL);
736         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
737
738         error = maps_route_foreach_segment(NULL, __utc_maps_route_segment_cb,
739                 &e);
740         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
741         g_assert_cmpint(e.iterations, ==, 0);
742
743         error = maps_route_foreach_segment(e.h, NULL, &e);
744         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
745         g_assert_cmpint(e.iterations, ==, 0);
746         /* test finish --------------------------------- */
747
748         error = maps_item_list_remove_all(segments, maps_route_segment_destroy);
749         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
750
751         error = maps_item_list_destroy(segments);
752         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
753 }
754