4e5448cef333cb2497dfdd86897fe4af388bceee
[framework/location/maps-service.git] / test / src / api / maps_api_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_api_test.h"
18 #include "maps_service.h"
19 #include <glib.h>
20 #include "maps_address.h"
21 #include "maps_test_utils.h"
22 #include "maps_object.h"
23
24 class test_env
25 {
26         public:
27         maps_service_h m;
28         maps_preference_h p;
29         int rid;
30         bool async;
31         int iterations;
32
33         enum TEST_PLUGIN
34         {
35                 DUMMY,
36                 HERE,
37         };
38         struct test_plugin_info_s
39         {
40                 /* Maps Provider name, returned by the Plugin */
41                 const char* provider;
42                 /* Maps Provider key */
43                 const char* key;
44                 /* Does the Plugin have asynchronous requests */
45                 bool async;
46         };
47         int test_plugin_type;
48         test_plugin_info_s i;
49         GMainLoop* mainloop;
50
51         int last_time;
52
53         private:
54          test_plugin_info_s get_plugin_info(int idx) const
55         {
56                 static test_plugin_info_s info[] = {
57                         /* DUMMY */
58                         { "Maps Provider",
59                                 "test_key",
60                                 false },
61
62                         /* HERE */
63                         { "HERE",
64                                 "gMutJ6Bo9jyMtOfJRGG1/nXvwmBWgoCqp9U5_yslkcw",
65                                 true }
66                 };
67                  return info[idx];
68         }
69         public:
70          test_env():m(NULL), p(NULL), rid(-1), async(false), iterations(0),
71                 mainloop(NULL), last_time(0)
72         {
73
74                 /* Chose the Plugin for testing */
75                 test_plugin_type =
76                         DUMMY   /* Dummy plugin */
77                         /*HERE*/        /* Nokia Here Maps */
78                         ;
79
80                 i = get_plugin_info(test_plugin_type);
81
82                 /* Create an instance of Maps Service */
83                 int error = maps_service_create(i.provider, &m);
84                 async = i.async;
85                 if (error != MAPS_ERROR_NONE)
86                         __utc_print_error_string(error);
87                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
88
89                 error = maps_preference_create(&p);
90                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
91
92                 /* Set up general preferenes for real plugins */
93                 error = maps_service_set_provider_key(m, i.key);
94                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
95
96                 error = maps_preference_set_max_results(p, 4);
97                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
98         }
99         ~test_env() {
100                 int error = maps_service_destroy(m);
101                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
102
103                 error = maps_item_hashtable_destroy(p);
104                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
105         }
106
107         public:
108         void finish_request()
109         {
110                 delete this;
111         }
112         void finish_response()
113         {
114                 /*g_print("\nfinishing response...\n");*/
115                 if (async && mainloop)
116                         test_env::stop_waiting_for_response(this);
117                 /*g_print("\nfinished response...\n");*/
118         }
119         private:
120         static gboolean stop_waiting_for_response(gpointer data)
121         {
122                 /*g_print("\nquite main loop\n");*/
123                 /*int milsec = -1;*/
124                 if (data) {
125                         test_env* e = (test_env*) data;
126                         if (e->mainloop) {
127                                 /*milsec = __get_milli_span(e->last_time);*/
128                                 g_main_loop_unref(e->mainloop);
129                                 g_main_loop_quit(e->mainloop);
130                                 e->mainloop = NULL;
131                         }
132                 }
133                 /*g_print("return from main loop: %d msec\n", milsec);*/
134                 return FALSE;
135         }
136         public:
137         void wait_for_response(void)
138         {
139                 if (!async)
140                         return;
141                 last_time = __get_milli_count();
142                 /*g_print("\nenter main loop\n"); */
143                 mainloop = g_main_loop_new(NULL, FALSE);
144                 const int timeout_id =
145                         g_timeout_add_seconds(15, stop_waiting_for_response,
146                         this);
147                 g_main_loop_run(mainloop);
148                 g_source_remove(timeout_id);
149         }
150 };
151
152 /*----------------------------------------------------------------------------*/
153 /* Create and Destroy */
154 void utc_maps_service_create_destroy_p(void)
155 {
156         test_env e;
157 }
158
159 /*----------------------------------------------------------------------------*/
160 /* Keys and properties */
161 /* */
162
163 /*int maps_service_set_provider_key(maps_service_h maps,
164 * const char* map_key); */
165 /*int maps_service_get_provider_key(const maps_service_h maps,
166 * char** map_key); */
167 void utc_maps_provider_key_p(void)
168 {
169         test_env e;
170
171         int error = maps_service_set_provider_key(e.m, e.i.key);
172         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
173
174         char* obtained_key = NULL;
175         error = maps_service_get_provider_key(e.m, &obtained_key);
176         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
177         g_assert(obtained_key);
178         g_assert_cmpstr(obtained_key, ==, e.i.key);
179         g_free(obtained_key);
180 }
181
182 void utc_maps_provider_key_n(void)
183 {
184         test_env e;
185
186         int error = maps_service_set_provider_key(NULL, "TEST_KEY");
187         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
188
189         error = maps_service_set_provider_key(e.m, NULL);
190         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
191
192         char* obtained_key = NULL;
193         error = maps_service_get_provider_key(NULL, &obtained_key);
194         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
195         g_assert(!obtained_key);
196
197         error = maps_service_get_provider_key(e.m, NULL);
198         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
199         g_assert(!obtained_key);
200 }
201
202 /*int maps_service_get_preference(maps_service_h maps,
203 * maps_preference_h* preference); */
204 /*int maps_service_set_preference(maps_service_h maps,
205 * maps_preference_h preference); */
206 void utc_maps_service_set_preference_p(void)
207 {
208         test_env e;
209
210         int error =
211                 maps_item_hashtable_set_string(e.p, "MAP_SERVICE_PREF_LANGUAGE",
212                 "value");
213
214         /* test start --------------------------------- */
215         error = maps_service_set_preference(e.m, e.p);
216         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
217         /* test finish --------------------------------- */
218 }
219
220 void utc_maps_service_set_preference_n(void)
221 {
222         test_env e;
223
224         int error =
225                 maps_item_hashtable_set_string(e.p, "MAP_SERVICE_PREF_LANGUAGE",
226                 "value");
227
228         /* test start --------------------------------- */
229         error = maps_service_set_preference(NULL, e.p);
230         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
231
232         error = maps_service_set_preference(e.m, NULL);
233         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
234         /* test finish --------------------------------- */
235 }
236
237 /*int maps_service_provider_is_service_supported(const maps_service_h maps, */
238 void utc_maps_service_provider_is_service_supported_p(void)
239 {
240         test_env e;
241
242         bool supported = false;
243         g_assert_cmpint(maps_service_provider_is_service_supported(e.m,
244                         MAPS_SERVICE_GEOCODE, &supported), ==, MAPS_ERROR_NONE);
245         g_assert(supported);
246
247         g_assert_cmpint(maps_service_provider_is_service_supported(e.m,
248                         MAPS_SERVICE_GEOCODE_INSIDE_AREA, &supported), ==,
249                 MAPS_ERROR_NONE);
250         g_assert(supported);
251
252         g_assert_cmpint(maps_service_provider_is_service_supported(e.m,
253                         MAPS_SERVICE_GEOCODE_BY_STRUCTURED_ADDRESS, &supported),
254                 ==, MAPS_ERROR_NONE);
255         g_assert(supported);
256
257         g_assert_cmpint(maps_service_provider_is_service_supported(e.m,
258                         MAPS_SERVICE_REVERSE_GEOCODE, &supported), ==,
259                 MAPS_ERROR_NONE);
260         g_assert(supported);
261
262         g_assert_cmpint(maps_service_provider_is_service_supported(e.m,
263                         MAPS_SERVICE_SEARCH_PLACE, &supported), ==,
264                 MAPS_ERROR_NONE);
265         g_assert(supported);
266
267         g_assert_cmpint(maps_service_provider_is_service_supported(e.m,
268                         MAPS_SERVICE_SEARCH_PLACE_BY_AREA, &supported), ==,
269                 MAPS_ERROR_NONE);
270         g_assert(supported);
271
272         g_assert_cmpint(maps_service_provider_is_service_supported(e.m,
273                         MAPS_SERVICE_SEARCH_PLACE_BY_ADDRESS, &supported), ==,
274                 MAPS_ERROR_NONE);
275         g_assert(supported);
276
277         g_assert_cmpint(maps_service_provider_is_service_supported(e.m,
278                         MAPS_SERVICE_SEARCH_ROUTE, &supported), ==,
279                 MAPS_ERROR_NONE);
280         g_assert(supported);
281
282         g_assert_cmpint(maps_service_provider_is_service_supported(e.m,
283                         MAPS_SERVICE_SEARCH_ROUTE_WAYPOINTS, &supported), ==,
284                 MAPS_ERROR_NONE);
285         g_assert(supported);
286
287         g_assert_cmpint(maps_service_provider_is_service_supported(e.m,
288                         MAPS_SERVICE_CANCEL_REQUEST, &supported), ==,
289                 MAPS_ERROR_NONE);
290         g_assert(supported);
291 }
292
293 void utc_maps_service_provider_is_service_supported_n(void)
294 {
295         test_env e;
296
297         bool supported = false;
298         g_assert_cmpint(maps_service_provider_is_service_supported(NULL,
299                         MAPS_SERVICE_GEOCODE, &supported), ==,
300                 MAPS_ERROR_INVALID_PARAMETER);
301         g_assert(!supported);
302
303         /*g_assert_cmpint(maps_service_provider_is_service_supported(e.m,
304                         (maps_service_e) (-1), &supported), ==,
305                 MAPS_ERROR_NOT_SUPPORTED);*/
306         int error = maps_service_provider_is_service_supported(e.m,
307                         (maps_service_e) (-1), &supported);
308         if (error != MAPS_ERROR_INVALID_PARAMETER)
309                 __utc_print_error_string(error);
310         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
311         g_assert(!supported);
312
313         g_assert_cmpint(maps_service_provider_is_service_supported(e.m,
314                         MAPS_SERVICE_GEOCODE, NULL), ==,
315                 MAPS_ERROR_INVALID_PARAMETER);
316         g_assert(!supported);
317 }
318
319 void utc_maps_service_provider_is_data_supported_p(void)
320 {
321         test_env e;
322
323         bool supported = false;
324
325         g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
326                         MAPS_PLACE_ADDRESS, &supported), ==, MAPS_ERROR_NONE);
327         g_assert(supported);
328
329         g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
330                         MAPS_PLACE_RATING, &supported), ==,
331                 MAPS_ERROR_NONE);
332         g_assert(supported);
333
334         g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
335                         MAPS_PLACE_CATEGORIES, &supported), ==,
336                 MAPS_ERROR_NONE);
337         g_assert(supported);
338
339         g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
340                         MAPS_PLACE_ATTRIBUTES, &supported), ==,
341                 MAPS_ERROR_NONE);
342         g_assert(supported);
343
344         g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
345                         MAPS_PLACE_CONTACTS, &supported), ==,
346                 MAPS_ERROR_NONE);
347         g_assert(supported);
348
349         g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
350                         MAPS_PLACE_EDITORIALS, &supported), ==,
351                 MAPS_ERROR_NONE);
352         g_assert(supported);
353
354         g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
355                         MAPS_PLACE_REVIEWS, &supported), ==,
356                 MAPS_ERROR_NONE);
357         g_assert(supported);
358
359         g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
360                         MAPS_PLACE_IMAGE, &supported), ==,
361                 MAPS_ERROR_NONE);
362         g_assert(supported);
363
364         g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
365                         MAPS_PLACE_SUPPLIER, &supported), ==,
366                 MAPS_ERROR_NONE);
367         g_assert(supported);
368
369         g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
370                         MAPS_PLACE_RELATED, &supported), ==,
371                 MAPS_ERROR_NONE);
372         g_assert(supported);
373
374         g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
375                         MAPS_ROUTE_PATH, &supported), ==, MAPS_ERROR_NONE);
376         g_assert(supported);
377
378         g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
379                         MAPS_ROUTE_SEGMENTS_PATH, &supported), ==,
380                 MAPS_ERROR_NONE);
381         g_assert(supported);
382
383         g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
384                         MAPS_ROUTE_SEGMENTS_MANEUVERS, &supported), ==,
385                 MAPS_ERROR_NONE);
386         g_assert(supported);
387 }
388
389 void utc_maps_service_provider_is_data_supported_n(void)
390 {
391         test_env e;
392
393         bool supported = false;
394         g_assert_cmpint(maps_service_provider_is_data_supported(NULL,
395                         MAPS_PLACE_ADDRESS, &supported), ==,
396                 MAPS_ERROR_INVALID_PARAMETER);
397         g_assert(!supported);
398
399         g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
400                         (maps_service_data_e) (-1), &supported), ==,
401                 MAPS_ERROR_INVALID_PARAMETER);
402         g_assert(!supported);
403
404         g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
405                         MAPS_PLACE_ADDRESS, NULL), ==,
406                 MAPS_ERROR_INVALID_PARAMETER);
407         g_assert(!supported);
408 }
409
410 /*----------------------------------------------------------------------------*/
411 /* Geocode */
412 /* */
413 /* int maps_service_geocode(maps_service_h maps, const char* address,
414 *  maps_service_geocode_cb callback, void* user_data, int* request_id); */
415 /* typedef bool (*maps_service_geocode_cb)(maps_error_e result, int request_id,
416 *  int index, int total_count, maps_coordinates_h coordinates,
417 *  void* user_data); */
418
419 static bool __utc_maps_service_geocode_cb(maps_error_e result, int request_id,
420         int index, int total_count, maps_coordinates_h coordinates,
421         void* user_data)
422 {
423 /*g_print("\n\n__utc_maps_service_geocode_cb [%d of %d]\n\n", index, total_count);*/
424
425         if (result != MAPS_ERROR_NONE)
426                 __utc_print_error_string(result);
427         g_assert_cmpint(result, ==, MAPS_ERROR_NONE);
428
429         test_env* e = (test_env*) user_data;
430         g_assert(e);
431
432         e->iterations++;
433
434         if (e->rid > 0) {
435                 g_assert_cmpint(e->rid, ==, request_id);
436         }
437
438         g_assert(index >= 0);
439         g_assert(total_count > 0);
440
441         g_assert(coordinates);
442
443         double latitude = .0, longitude = .0, altitude = .0;
444         int error = maps_coordinates_get_latitude(coordinates, &latitude);
445         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
446         error = maps_coordinates_get_longitude(coordinates, &longitude);
447         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
448
449         g_assert(latitude > -90 || latitude < 90);
450         g_assert(longitude > -180 || longitude < 180);
451         g_assert(altitude > -100 || altitude < 100);
452
453         error = maps_coordinates_destroy(coordinates);
454         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
455         if (index == (total_count - 1)) {
456                 e->finish_response();
457         }
458         return true;
459 }
460
461 void utc_maps_service_geocode_p(void)
462 {
463         test_env* e = new test_env;
464
465         /* test start --------------------------------- */
466         int error =
467                 maps_service_geocode(e->m, "Seoul", e->p,
468                 __utc_maps_service_geocode_cb, (void*) e, &e->rid);
469         /*int error = maps_service_geocode(e->m, "Berlin", e->p,
470         * __utc_maps_service_geocode_cb, (void*)e, &e->rid); */
471         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
472
473         e->wait_for_response();
474
475         g_assert(e->rid > 0);
476         g_assert(e->iterations > 0);
477         /* test finish --------------------------------- */
478
479         /*if(!e->async) delete e; */
480         /*else e->wait_for_response(); */
481         e->finish_request();
482 }
483
484 void utc_maps_service_geocode_n(void)
485 {
486         test_env e;
487
488         /* test start --------------------------------- */
489         int error =
490                 maps_service_geocode(NULL, "Seoul", e.p,
491                 __utc_maps_service_geocode_cb, NULL, &e.rid);
492         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
493
494         error = maps_service_geocode(e.m, NULL, e.p,
495                 __utc_maps_service_geocode_cb, NULL, &e.rid);
496         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
497
498         /*error = maps_service_geocode(e.m, "Seoul", NULL,
499                 __utc_maps_service_geocode_cb, NULL, &e.rid);
500         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);*/
501
502         error = maps_service_geocode(e.m, "Seoul", e.p, NULL, NULL, &e.rid);
503         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
504
505         error = maps_service_geocode(e.m, "Seoul", e.p,
506                 __utc_maps_service_geocode_cb, NULL, NULL);
507         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
508         /* test finish --------------------------------- */
509 }
510
511 /*int maps_service_geocode_inside_area(maps_service_h maps,
512 * const char* address, maps_area_h bounds, maps_service_geocode_cb callback,
513 * void* user_data, int* request_id); */
514 void utc_maps_service_geocode_inside_area_p(void)
515 {
516         test_env* e = new test_env;
517
518         maps_coordinates_h c1 = NULL;
519         /*int error = maps_coordinates_create(38.0, 127.0, &c1); */
520         int error = maps_coordinates_create(15.665354, 74.311523, &c1);
521         g_assert(c1);
522
523         maps_coordinates_h c2 = NULL;
524         /*error = maps_coordinates_create(37.0, 128.0, &c2); */
525         error = maps_coordinates_create(10.617418, 79.145508, &c2);
526         g_assert(c2);
527
528         maps_area_h bounds = NULL;
529         error = maps_area_create_rectangle(c1, c2, &bounds);
530         g_assert(bounds);
531
532         /* test start --------------------------------- */
533         error = maps_service_geocode_inside_area(e->m,
534                 /*"Seoul", */
535                 "Berlin",
536                 bounds,
537                 e->p, __utc_maps_service_geocode_cb, (void*) e, &e->rid);
538         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
539
540         e->wait_for_response();
541
542         g_assert(e->rid > 0);
543         /* test finish --------------------------------- */
544
545         error = maps_area_destroy(bounds);
546         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
547         error = maps_coordinates_destroy(c1);
548         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
549         error = maps_coordinates_destroy(c2);
550         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
551
552         /*if(!e->async) delete e; */
553         e->finish_request();
554 }
555
556 void utc_maps_service_geocode_inside_area_n(void)
557 {
558         test_env e;
559
560         maps_coordinates_h center = NULL;
561         int error = maps_coordinates_create(11.1, 22.2, &center);
562         g_assert(center);
563
564         maps_area_h bounds = NULL;
565         error = maps_area_create_circle(center, 200, &bounds);
566         g_assert(bounds);
567
568         /* test start --------------------------------- */
569         error = maps_service_geocode_inside_area(NULL, "Seoul", bounds, e.p,
570                 __utc_maps_service_geocode_cb, NULL, &e.rid);
571         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
572
573         error = maps_service_geocode_inside_area(e.m, NULL, bounds, e.p,
574                 __utc_maps_service_geocode_cb, NULL, &e.rid);
575         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
576
577         /*error = maps_service_geocode_inside_area(e.m, "Seoul", bounds, NULL,
578                 __utc_maps_service_geocode_cb, NULL, &e.rid);
579         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);*/
580
581         error = maps_service_geocode_inside_area(e.m, "Seoul", bounds, e.p,
582                 NULL, NULL, &e.rid);
583         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
584
585         error = maps_service_geocode_inside_area(e.m, "Seoul", bounds, e.p,
586                 __utc_maps_service_geocode_cb, NULL, NULL);
587         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
588         /* test finish --------------------------------- */
589
590         error = maps_area_destroy(bounds);
591         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
592         error = maps_coordinates_destroy(center);
593         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
594 }
595
596 void utc_maps_service_geocode_by_structured_address_p(void)
597 {
598         test_env* e = new test_env;
599
600         maps_address_h address = NULL;
601         int error = maps_address_create(&address);
602         g_assert(address);
603         error = maps_address_set_city(address, "Prague");
604         error = maps_address_set_street(address, "Na Bojisti");
605         error = maps_address_set_building_number(address, "1733/12");
606
607         /* test start --------------------------------- */
608         error = maps_service_geocode_by_structured_address(e->m,
609                 address,
610                 e->p, __utc_maps_service_geocode_cb, (void*) e, &e->rid);
611         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
612
613         e->wait_for_response();
614
615         g_assert(e->rid > 0);
616         /* test finish --------------------------------- */
617
618         error = maps_address_destroy(address);
619         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
620
621         /*if(!e->async) delete e; */
622         e->finish_request();
623 }
624
625 void utc_maps_service_geocode_by_structured_address_n(void)
626 {
627         test_env e;
628
629         maps_address_h address = NULL;
630         int error = maps_address_create(&address);
631         g_assert(address);
632
633         /* test start --------------------------------- */
634         error = maps_service_geocode_by_structured_address(NULL, address, e.p,
635                 __utc_maps_service_geocode_cb, NULL, &e.rid);
636         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
637
638         error = maps_service_geocode_by_structured_address(e.m, NULL, e.p,
639                 __utc_maps_service_geocode_cb, NULL, &e.rid);
640         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
641
642         /*error = maps_service_geocode_by_structured_address(e.m, address, NULL,
643                 __utc_maps_service_geocode_cb, NULL, &e.rid);
644         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);*/
645
646         error = maps_service_geocode_by_structured_address(e.m, address, e.p,
647                 NULL, NULL, &e.rid);
648         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
649
650         error = maps_service_geocode_by_structured_address(e.m, address, e.p,
651                 __utc_maps_service_geocode_cb, NULL, NULL);
652         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
653         /* test finish --------------------------------- */
654
655         error = maps_address_destroy(address);
656         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
657 }
658
659 static void __utc_maps_service_reverse_geocode_cb(maps_error_e result,
660         int request_id, int index, int total, maps_address_h address,
661         void* user_data)
662 {
663
664         g_assert_cmpint(result, ==, MAPS_ERROR_NONE);
665
666         g_assert(address);
667
668         int error = 0;
669
670         if (address) {
671                 g_print("[%s] address\n", __FUNCTION__);
672
673                 char *building_number = NULL;
674                 if (maps_address_get_building_number(address,
675                                 &building_number) == MAPS_ERROR_NONE)
676                         g_print("\tbuilding number\t: %s\n", building_number);
677                 g_free(building_number);
678
679                 char *street = NULL;
680                 if (maps_address_get_street(address, &street) == MAPS_ERROR_NONE)
681                         g_print("\tstreet\t: %s\n", street);
682                 g_free(street);
683
684                 char *district = NULL;
685                 if (maps_address_get_district(address,
686                                 &district) == MAPS_ERROR_NONE)
687                         g_print("\tdistrict\t: %s\n", district);
688                 g_free(district);
689
690                 char *city = NULL;
691                 if (maps_address_get_city(address, &city) == MAPS_ERROR_NONE)
692                         g_print("\tcity\t: %s\n", city);
693                 g_free(city);
694
695                 char *state = NULL;
696                 if (maps_address_get_state(address, &state) == MAPS_ERROR_NONE)
697                         g_print("\tstate\t: %s\n", state);
698                 g_free(state);
699
700                 char *country = NULL;
701                 if (maps_address_get_country(address,
702                                 &country) == MAPS_ERROR_NONE)
703                         g_print("\tcountry\t: %s\n", country);
704                 g_free(country);
705
706                 char *country_code = NULL;
707                 if (maps_address_get_country_code(address,
708                                 &country_code) == MAPS_ERROR_NONE)
709                         g_print("\tcountry code\t: %s\n", country_code);
710                 g_free(country_code);
711
712                 char *county = NULL;
713                 if (maps_address_get_county(address, &county) == MAPS_ERROR_NONE)
714                         g_print("\tcounty\t: %s\n", county);
715                 g_free(county);
716
717                 char *postal_code = NULL;
718                 if (maps_address_get_postal_code(address,
719                                 &postal_code) == MAPS_ERROR_NONE)
720                         g_print("\tpostal code\t: %s\n", postal_code);
721                 g_free(postal_code);
722
723                 char *free_text = NULL;
724                 if (maps_address_get_freetext(address,
725                                 &free_text) == MAPS_ERROR_NONE)
726                         g_print("\tfreetext\t: %s\n", free_text);
727                 g_free(free_text);
728
729                 error = maps_address_destroy(address);
730         }
731
732         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
733
734         test_env* e = (test_env*) user_data;
735         g_assert(e);
736
737         if (e->rid > 0) {
738                 g_assert_cmpint(e->rid, ==, request_id);
739         }
740
741         g_assert_cmpint(index, ==, 0);
742         g_assert_cmpint(total, ==, 1);
743
744         /*if(e->async) delete e; */
745         e->finish_response();
746 }
747
748 /*int maps_service_reverse_geocode(maps_service_h maps, double latitude,
749 * double longitude, maps_service_reverse_geocode_cb callback, void* user_data,
750 * int* request_id); */
751 void utc_maps_service_reverse_geocode_p(void)
752 {
753         test_env* e = new test_env;
754
755         /* test start --------------------------------- */
756         int error =
757                 maps_service_reverse_geocode(e->m, 12.944594, 77.554303, e->p,
758                 __utc_maps_service_reverse_geocode_cb, (void*) e, &e->rid);
759         if (error != MAPS_ERROR_NONE)
760                 __utc_print_error_string(error);
761         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
762
763         e->wait_for_response();
764
765         g_assert(e->rid > 0);
766         /* test finish --------------------------------- */
767
768         /*if(!e->async) delete e; */
769         e->finish_request();
770 }
771
772 void utc_maps_service_reverse_geocode_n(void)
773 {
774         test_env e;
775
776         /* test start --------------------------------- */
777         int error =
778                 maps_service_reverse_geocode(NULL, 11.1, 22.2, e.p,
779                 __utc_maps_service_reverse_geocode_cb, NULL, &e.rid);
780         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
781
782         /*error = maps_service_reverse_geocode(e.m, 11.1, 22.2, NULL,
783                 __utc_maps_service_reverse_geocode_cb, NULL, &e.rid);
784         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);*/
785
786         error = maps_service_reverse_geocode(e.m, 11.1, 22.2, e.p,
787                 __utc_maps_service_reverse_geocode_cb, NULL, NULL);
788         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
789         /* test finish --------------------------------- */
790 }
791
792 /*int maps_cancel_geocode(maps_service_h maps, int request_id); */
793 static bool __utc_maps_cancel_geocode_cb(maps_error_e result, int request_id,
794         int index, int total_count, maps_coordinates_h coordinates,
795         void* user_data)
796 {
797         return true;
798 }
799
800 void utc_maps_cancel_geocode_p(void)
801 {
802         test_env e;
803
804         maps_item_hashtable_set_string(e.p, "no_need_callback",
805                 "no_need_callback");
806
807         int error =
808                 maps_service_geocode(e.m, "Seoul", e.p,
809                 __utc_maps_cancel_geocode_cb, (void*) &e, &e.rid);
810         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
811         g_assert(e.rid > 0);
812
813         /*error = maps_cancel_geocode(e.m, e.rid); */
814         error = maps_service_cancel_request(e.m, e.rid);
815         if (error != MAPS_ERROR_NONE)
816                 __utc_print_error_string(error);
817         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
818 }
819
820 void utc_maps_cancel_geocode_p02(void)
821 {
822         test_env e;
823
824         maps_item_hashtable_set_string(e.p, "no_need_callback",
825                 "no_need_callback");
826
827         for (int i = 0; i < 5; i++) {
828                 int error =
829                         maps_service_geocode(e.m, "Seoul", e.p,
830                         __utc_maps_cancel_geocode_cb, (void*) &e, &e.rid);
831                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
832                 g_assert(e.rid > 0);
833
834                 error = maps_service_cancel_request(e.m, e.rid);
835                 if (error != MAPS_ERROR_NONE)
836                         __utc_print_error_string(error);
837                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
838         }
839 }
840
841 void utc_maps_cancel_geocode_n(void)
842 {
843         const int error = maps_service_cancel_request(NULL, 1);
844         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
845 }
846
847 /*int maps_cancel_reverse_geocode(maps_service_h maps, int request_id); */
848 static void __utc_maps_cancel_reverse_geocode_cb(maps_error_e result,
849         int request_id, int index, int total, maps_address_h address,
850         void* user_data)
851 {
852         return;
853 }
854
855 void utc_maps_cancel_reverse_geocode_p(void)
856 {
857         test_env e;
858
859         maps_item_hashtable_set_string(e.p, "no_need_callback",
860                 "no_need_callback");
861
862         int error =
863                 maps_service_reverse_geocode(e.m, 11.1, 22.2, e.p,
864                 __utc_maps_cancel_reverse_geocode_cb, (void*) &e, &e.rid);;
865         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
866         g_assert(e.rid > 0);
867
868         error = maps_service_cancel_request(e.m, e.rid);
869         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
870 }
871
872 void utc_maps_cancel_reverse_geocode_n(void)
873 {
874         const int error = maps_service_cancel_request(NULL, 1);
875         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
876 }
877
878 /*----------------------------------------------------------------------------*/
879 /* Place */
880 static bool __utc_place_contact_cb(int index, int total,
881         maps_place_contact_h contact_h, void* user_data)
882 {
883         if (!contact_h)
884                 return FALSE;
885
886         maps::place_contact contact(contact_h);
887
888         g_print("contact [%d/%d]\n", index + 1, total);
889
890         maps::string_holder label;
891         if (maps_place_contact_get_label(contact, label) == MAPS_ERROR_NONE)
892                 g_print("\tlabel\t: %s\n", label.str);
893
894         maps::string_holder type;
895         if (maps_place_contact_get_type(contact, type) == MAPS_ERROR_NONE)
896                 g_print("\ttype\t: %s\n", type.str);
897
898         maps::string_holder value;
899         if (maps_place_contact_get_value(contact, value) == MAPS_ERROR_NONE)
900                 g_print("\tvalue\t: %s\n", value.str);
901
902         return TRUE;
903 }
904
905 static bool __utc_place_category_cb(int index, int total,
906         maps_place_category_h category_h, void* user_data)
907 {
908         if (!category_h)
909                 return FALSE;
910
911         maps::place_category category(category_h);
912
913         g_print("category [%d/%d]\n", index + 1, total);
914
915         maps::string_holder name;
916         if (maps_place_category_get_name(category, name) == MAPS_ERROR_NONE)
917                 g_print("\tname\t: %s\n", name.str);
918
919         maps::string_holder id;
920         if (maps_place_category_get_id(category, id) == MAPS_ERROR_NONE)
921                 g_print("\tid\t: %s\n", id.str);
922
923         maps::string_holder url;
924         if (maps_place_category_get_url(category, url) == MAPS_ERROR_NONE)
925                 g_print("\turl\t: %s\n", url.str);
926
927         return TRUE;
928 }
929
930 static bool __utc_place_link_object(const char* tag,
931         maps_place_link_object_h link_object_h)
932 {
933         if (!link_object_h)
934                 return FALSE;
935
936         maps::place_link_object link_object(link_object_h);
937
938         maps::string_holder id;
939         if (maps_place_link_object_get_id(link_object, id) == MAPS_ERROR_NONE)
940                 g_print("%sid\t: %s\n", tag, id.str);
941
942         maps::string_holder name;
943         if (maps_place_link_object_get_name(link_object,
944                         name) == MAPS_ERROR_NONE)
945                 g_print("%sname\t: %s\n", tag, name.str);
946
947         maps::string_holder string;
948         if (maps_place_link_object_get_string(link_object,
949                         string) == MAPS_ERROR_NONE)
950                 g_print("%sstring\t: %s\n", tag, string.str);
951
952         maps::string_holder type;
953         if (maps_place_link_object_get_type(link_object,
954                         type) == MAPS_ERROR_NONE)
955                 g_print("%stype\t: %s\n", tag, type.str);
956
957         return TRUE;
958 }
959
960 static bool __utc_place_image_cb(int index, int total,
961         maps_place_image_h image_h, void* user_data)
962 {
963         if (!image_h)
964                 return FALSE;
965
966         g_print("image [%d/%d]\n", index + 1, total);
967
968         maps::place_image image(image_h);
969
970         maps::string_holder url;
971         if (maps_place_image_get_url(image, url) == MAPS_ERROR_NONE)
972                 g_print("\turl\t: %s\n", url.str);
973
974         maps::string_holder id;
975         if (maps_place_image_get_id(image, id) == MAPS_ERROR_NONE)
976                 g_print("\tid\t: %s\n", id.str);
977
978         int nval = 0;
979         if (maps_place_image_get_width(image, &nval) == MAPS_ERROR_NONE
980                 && nval > 0)
981                 g_print("\twidth\t: %d\n", nval);
982
983         if (maps_place_image_get_height(image, &nval) == MAPS_ERROR_NONE
984                 && nval > 0)
985                 g_print("\theight\t: %d\n", nval);
986
987         maps::place_link_object user_link(NULL);
988         if (maps_place_image_get_user_link(image, user_link) ==
989             MAPS_ERROR_NONE) {
990                 g_print("\tuserlink\n");
991                 __utc_place_link_object("\t\t", user_link.clone());
992         }
993
994         maps::place_media media(NULL);
995         if (maps_place_image_get_media(image, media) == MAPS_ERROR_NONE) {
996                 g_print("\tmedia\n");
997                 maps::string_holder attribution;
998                 if (maps_place_media_get_attribution(media,
999                                 attribution) == MAPS_ERROR_NONE)
1000                         g_print("\t\tattribution\t: %s\n", attribution.str);
1001
1002                 maps::place_link_object supplier(NULL);
1003                 if (maps_place_media_get_supplier(media,
1004                                 supplier) == MAPS_ERROR_NONE) {
1005                         g_print("\t\tsupplier link\n");
1006                         __utc_place_link_object("\t\t\t", supplier.clone());
1007                 }
1008
1009                 maps::place_link_object via(NULL);
1010                 if (maps_place_media_get_via(media, via) == MAPS_ERROR_NONE) {
1011                         g_print("\t\tvia\n");
1012                         __utc_place_link_object("\t\t\t", via.clone());
1013                 }
1014         }
1015
1016         return TRUE;
1017 }
1018
1019 static bool __utc_place_editorial_cb(int index, int total,
1020         maps_place_editorial_h editorial_h, void* user_data)
1021 {
1022         /* TODO: */
1023         maps::place_editorial editorial(editorial_h);
1024         return TRUE;
1025 }
1026
1027 static bool __utc_place_review_cb(int index, int total,
1028         maps_place_review_h review_h, void* user_data)
1029 {
1030         /* TODO: */
1031         maps::place_review review(review_h);
1032         return TRUE;
1033 }
1034
1035 static bool __utc_maps_service_search_place_cb(maps_error_e error,
1036         int request_id, int index, int length, maps_place_h place_h,
1037         void* user_data)
1038 {
1039
1040         if((error != MAPS_ERROR_NONE) && (error != MAPS_ERROR_NOT_FOUND)) {
1041                 __utc_print_error_string(error);
1042                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1043         }
1044
1045         test_env* e = (test_env*) user_data;
1046         g_assert(e);
1047
1048         e->iterations++;
1049
1050         if (e->rid > 0) {
1051                 g_assert_cmpint(e->rid, ==, request_id);
1052         }
1053
1054         g_assert(index >= 0);
1055         g_assert(length > 0);
1056
1057         if(error == MAPS_ERROR_NOT_FOUND) {
1058                 g_assert(index == 0);
1059                 g_assert(length == 1);
1060                 e->finish_response();
1061                 return true;
1062         }
1063
1064
1065         g_assert(place_h);
1066
1067         maps::place place(place_h);
1068
1069         /* Parsing Result Data ------------------------------------- */
1070         /*g_print("Search Place [%d/%d]\n", index + 1, length);*/
1071
1072         maps::coordinates coord(NULL);
1073         if (maps_place_get_location(place, coord) == MAPS_ERROR_NONE) {
1074                 g_print("\tposition\t: %f, %f\n", coord.get_latitude(),
1075                         coord.get_longitude());
1076         }
1077
1078         maps::string_holder name;
1079         if (maps_place_get_name(place, name) == MAPS_ERROR_NONE)
1080                 g_print("\ttitle\t: %s\n", name.str);
1081
1082         maps::string_holder uri;
1083         if (maps_place_get_uri(place, uri) == MAPS_ERROR_NONE)
1084                 g_print("\thref\t: %s\n", uri.str);
1085
1086         maps::string_holder id;
1087         if (maps_place_get_id(place, id) == MAPS_ERROR_NONE)
1088                 g_print("\tid\t: %s\n", id.str);
1089
1090         maps::place_rating rating(NULL);
1091         if (maps_place_get_rating(place, rating) == MAPS_ERROR_NONE) {
1092                 int count = 0;
1093                 double value = .0;
1094                 maps_place_rating_get_average(rating, &value);
1095                 maps_place_rating_get_count(rating, &count);
1096                 g_print("\trating\t: %f\n", value);
1097                 g_print("\tcount\t: %d\n", count);
1098         }
1099
1100         maps::address address(NULL);
1101         if (maps_place_get_address(place, address) == MAPS_ERROR_NONE) {
1102                 g_print("address\n");
1103
1104                 maps::string_holder building_number;
1105                 if (maps_address_get_building_number(address,
1106                                 building_number) == MAPS_ERROR_NONE)
1107                         g_print("\tbuilding number\t: %s\n",
1108                                 building_number.str);
1109
1110                 maps::string_holder street;
1111                 if (maps_address_get_street(address, street) == MAPS_ERROR_NONE)
1112                         g_print("\tstreet\t: %s\n", street.str);
1113
1114                 maps::string_holder district;
1115                 if (maps_address_get_district(address,
1116                                 district) == MAPS_ERROR_NONE)
1117                         g_print("\tdistrict\t: %s\n", district.str);
1118
1119                 maps::string_holder city;
1120                 if (maps_address_get_city(address, city) == MAPS_ERROR_NONE)
1121                         g_print("\tcity\t: %s\n", city.str);
1122
1123                 maps::string_holder state;
1124                 if (maps_address_get_state(address, state) == MAPS_ERROR_NONE)
1125                         g_print("\tstate\t: %s\n", state.str);
1126
1127                 maps::string_holder country;
1128                 if (maps_address_get_country(address,
1129                                 country) == MAPS_ERROR_NONE)
1130                         g_print("\tcountry\t: %s\n", country.str);
1131
1132                 maps::string_holder country_code;
1133                 if (maps_address_get_country_code(address,
1134                                 country_code) == MAPS_ERROR_NONE)
1135                         g_print("\tcountry code\t: %s\n", country_code.str);
1136
1137                 maps::string_holder county;
1138                 if (maps_address_get_county(address, county) == MAPS_ERROR_NONE)
1139                         g_print("\tcounty\t: %s\n", county.str);
1140
1141                 maps::string_holder postal_code;
1142                 if (maps_address_get_postal_code(address,
1143                                 postal_code) == MAPS_ERROR_NONE)
1144                         g_print("\tpostal code\t: %s\n", postal_code.str);
1145
1146                 maps::string_holder free_text;
1147                 if (maps_address_get_freetext(address,
1148                                 free_text) == MAPS_ERROR_NONE)
1149                         g_print("\tfreetext\t: %s\n", free_text.str);
1150         }
1151
1152         maps_place_foreach_contact(place, __utc_place_contact_cb, user_data);
1153         maps_place_foreach_category(place, __utc_place_category_cb, user_data);
1154         maps_place_foreach_image(place, __utc_place_image_cb, user_data);
1155         maps_place_foreach_editorial(place, __utc_place_editorial_cb,
1156                 user_data);
1157         maps_place_foreach_review(place, __utc_place_review_cb, user_data);
1158
1159         /*g_print("\n");*/
1160
1161         /* End Parsing Result Data --------------------------------- */
1162
1163         if (index == (length - 1)) {
1164                 /*if(e->async) delete e; */
1165                 e->finish_response();
1166         }
1167
1168         return true;
1169 }
1170
1171 /*int maps_service_search_place(maps_service_h maps,
1172 * maps_coordinates_h position, int distance, maps_place_preference_h preference,
1173 * maps_place_filter_h filter, maps_service_search_place_cb callback,
1174 * void* user_data, int* request_id); */
1175 void utc_maps_service_search_place_p(void)
1176 {
1177         test_env* e = new test_env;
1178
1179         maps::coordinates position(37.7942, -122.4070);
1180         //maps::coordinates position(37.7555302, 127.002253);
1181
1182         maps::place_filter filter;
1183         //int error = maps_place_filter_set_place_name(filter, "Seoul");
1184         int error = maps_place_filter_set_place_name(filter, "San Francisco");
1185         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1186
1187         /* test start --------------------------------- */
1188         /* shlg, 20150716, as recommended by HERE Plugin developer, the distance
1189          * is extended in 10 times to 50000 */
1190         error = maps_service_search_place(e->m, position, 50000, filter, e->p,
1191                 __utc_maps_service_search_place_cb, (void*) e, &e->rid);
1192         if (error != MAPS_ERROR_NONE)
1193                 __utc_print_error_string(error);
1194         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1195         g_assert(e->rid > 0);
1196         /* test finish --------------------------------- */
1197
1198         e->wait_for_response();
1199         e->finish_request();
1200 }
1201
1202 void utc_maps_service_search_place_n(void)
1203 {
1204         test_env e;
1205         /*maps::coordinates position(37.7942, -122.4070);*/
1206         maps::coordinates position(37.7555302, 127.002253);
1207         maps::place_filter filter;
1208
1209         /* test start --------------------------------- */
1210         int error =
1211                 maps_service_search_place(NULL, position, 5000, filter, e.p,
1212                 __utc_maps_service_search_place_cb, &e, &e.rid);
1213         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1214
1215         error = maps_service_search_place(e.m, NULL, 5000, filter, e.p,
1216                 __utc_maps_service_search_place_cb, &e, &e.rid);
1217         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1218
1219         /*error = maps_service_search_place(e.m, position, 5000, filter, NULL,
1220                 __utc_maps_service_search_place_cb, &e, &e.rid);
1221         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);*/
1222
1223         error = maps_service_search_place(e.m, position, 5000, NULL, e.p,
1224                 __utc_maps_service_search_place_cb, &e, &e.rid);
1225         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1226
1227         error = maps_service_search_place(e.m, position, 5000, filter, e.p, NULL,
1228                 &e, &e.rid);
1229         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1230         /* test finish --------------------------------- */
1231 }
1232
1233 /*int maps_service_search_place_by_area(maps_service_h maps,
1234 * maps_area_h boundary , maps_place_preference_h preference,
1235 * maps_place_filter_h filter, maps_service_search_place_cb callback,
1236 * void* user_data, int* request_id); */
1237 void utc_maps_service_search_place_by_area_p(void)
1238 {
1239         test_env* e = new test_env;
1240
1241         maps::place_filter filter;
1242         int error = maps_place_filter_set_place_name(filter, "Seoul");
1243         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1244
1245         maps::place_category category;
1246         //error = maps_place_category_set_id(category, "eat-drink");
1247         error = maps_place_category_set_id(category, "cafe");
1248         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1249         error = maps_place_filter_set_category(filter, category);
1250         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1251
1252         /*maps::area area(37.7942 + 0.2, -122.407 - 0.2,
1253                         37.7942 - 0.2, -122.407 + 0.2);*/
1254         maps::area area(37.7555302 + 0.2, 127.002253 - 0.2,
1255                         37.7555302 - 0.2, 127.002253 + 0.2);
1256
1257         /* test start --------------------------------- */
1258         error = maps_service_search_place_by_area(e->m, area, filter, e->p,
1259                 __utc_maps_service_search_place_cb, (void*) e, &e->rid);
1260         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1261         g_assert(e->rid > 0);
1262         /* test finish --------------------------------- */
1263
1264         e->wait_for_response();
1265         e->finish_request();
1266 }
1267
1268 void utc_maps_service_search_place_by_area_n(void)
1269 {
1270         test_env e;
1271         maps::place_filter filter;
1272         /*maps::area area(37.7942 + 0.2, -122.407 - 0.2, 37.7942 - 0.2,
1273                 -122.407 + 0.2);*/
1274         maps::area area(37.7555302 + 0.2, 127.002253 - 0.2,
1275                         37.7555302 - 0.2, 127.002253 + 0.2);
1276
1277         /* test start --------------------------------- */
1278         int error =
1279                 maps_service_search_place_by_area(NULL, area, filter, e.p,
1280                 __utc_maps_service_search_place_cb, &e, &e.rid);
1281         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1282
1283         error = maps_service_search_place_by_area(e.m, NULL, filter, e.p,
1284                 __utc_maps_service_search_place_cb, &e, &e.rid);
1285         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1286
1287         /*error = maps_service_search_place_by_area(e.m, area, filter, NULL,
1288                 __utc_maps_service_search_place_cb, &e, &e.rid);
1289         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);*/
1290
1291         error = maps_service_search_place_by_area(e.m, area, NULL, e.p,
1292                 __utc_maps_service_search_place_cb, &e, &e.rid);
1293         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1294
1295         error = maps_service_search_place_by_area(e.m, area, filter, e.p, NULL,
1296                 &e, &e.rid);
1297         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1298         /* test finish --------------------------------- */
1299 }
1300
1301 /*int maps_service_search_place_by_address(maps_service_h maps,
1302 * const char* address, maps_area_h boundary, maps_place_preference_h preference,
1303 * maps_place_filter_h filter, maps_service_search_place_cb callback,
1304 * void* user_data, int* request_id); */
1305 void utc_maps_service_search_place_by_address_p(void)
1306 {
1307         test_env* e = new test_env;
1308
1309         maps::place_filter filter;
1310         int error = maps_place_filter_set_place_name(filter, "Seoul");
1311         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1312
1313         maps::area area(37.7942 + 0.2, -122.407 - 0.2,
1314                         37.7942 - 0.2, -122.407 + 0.2);
1315         /*maps::area area(37.7555302 + 0.2, 127.002253 - 0.2,
1316                         37.7555302 - 0.2, 127.002253 + 0.2);*/
1317
1318         /* test start --------------------------------- */
1319         error = maps_service_search_place_by_address(e->m, "Jackson", area,
1320                 filter, e->p, __utc_maps_service_search_place_cb, (void*) e,
1321                 &e->rid);
1322         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1323         g_assert(e->rid > 0);
1324         /* test finish --------------------------------- */
1325
1326         e->wait_for_response();
1327         e->finish_request();
1328 }
1329
1330 void utc_maps_service_search_place_by_address_n(void)
1331 {
1332         test_env e;
1333
1334         maps::place_filter filter;
1335         int error = maps_place_filter_set_place_name(filter, "Seoul");
1336         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1337
1338         /*maps::area area(37.7942 + 0.2, -122.407 - 0.2, 37.7942 - 0.2,
1339                 -122.407 + 0.2);*/
1340         maps::area area(37.7555302 + 0.2, 127.002253 - 0.2,
1341                         37.7555302 - 0.2, 127.002253 + 0.2);
1342
1343         /* test start --------------------------------- */
1344         error = maps_service_search_place_by_address(NULL, "Seoul", area,
1345                 filter, e.p, __utc_maps_service_search_place_cb, &e, &e.rid);
1346         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1347
1348         error = maps_service_search_place_by_address(e.m, NULL, area, filter,
1349                 e.p, __utc_maps_service_search_place_cb, &e, &e.rid);
1350         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1351
1352         /*error = maps_service_search_place_by_address(e.m, "Seoul", filter, NULL,
1353                 filter, __utc_maps_service_search_place_cb, &e, &e.rid);
1354         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);*/
1355
1356         error = maps_service_search_place_by_address(e.m, "Seoul", area, NULL,
1357                 e.p, __utc_maps_service_search_place_cb, &e, &e.rid);
1358         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1359
1360         error = maps_service_search_place_by_address(e.m, "Seoul", area, filter,
1361                 e.p, NULL, &e, &e.rid);
1362         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1363         /* test finish --------------------------------- */
1364 }
1365
1366 /*int maps_cancel_place(maps_service_h maps, int request_id); */
1367 static bool __utc_maps_cancel_place_cb(maps_error_e error, int request_id,
1368         int index, int length, maps_place_h place, void* user_data)
1369 {
1370         return true;
1371 }
1372
1373 void utc_maps_cancel_place_p(void)
1374 {
1375         test_env e;
1376
1377         maps_item_hashtable_set_string(e.p, "no_need_callback",
1378                 "no_need_callback");
1379
1380         maps::coordinates position(37.34, 126.58);
1381
1382         maps::place_filter filter;
1383         int error = maps_place_filter_set_place_name(filter, "Seoul");
1384         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1385
1386         error = maps_service_search_place(e.m, position, 5000, filter, e.p,
1387                 __utc_maps_cancel_place_cb, (void*) &e, &e.rid);
1388         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1389         g_assert(e.rid > 0);
1390
1391         error = maps_service_cancel_request(e.m, e.rid);
1392         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1393
1394         /* TODO: add tests for canceling maps_service_search_place_by_area,
1395         *  maps_service_search_place_by_address APIs */
1396 }
1397
1398 void utc_maps_cancel_place_n(void)
1399 {
1400         const int error = maps_service_cancel_request(NULL, 1);
1401         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1402 }
1403
1404 /*----------------------------------------------------------------------------*/
1405 /* Route */
1406 /*typedef bool(*maps_service_search_route_cb)(maps_error_e error,
1407 * int request_id, int index, int total, maps_route_h route, void* user_data); */
1408 static bool __utc_maps_service_search_route_cb(maps_error_e error,
1409         int request_id, int index, int total, maps_route_h route,
1410         void* user_data)
1411 {
1412         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1413
1414         test_env* e = (test_env*) user_data;
1415         g_assert(e);
1416
1417         e->iterations++;
1418
1419         if (e->rid > 0) {
1420                 g_assert_cmpint(e->rid, ==, request_id);
1421         }
1422
1423         g_assert(index >= 0);
1424         g_assert(total > 0);
1425
1426         g_assert(route);
1427         int err = maps_route_destroy(route);
1428         g_assert_cmpint(err, ==, MAPS_ERROR_NONE);
1429
1430         if (index == (total - 1)) {
1431                 e->finish_response();
1432         }
1433
1434         return true;
1435 }
1436
1437 /*int maps_service_search_route(maps_service_h maps,
1438 * maps_item_hashtable_h preference, maps_coordinates_h origin,
1439 * maps_coordinates_h destination, maps_service_search_route_cb callback,
1440 * void* user_data, int* request_id); */
1441 void utc_maps_service_search_route_p(void)
1442 {
1443         test_env* e = new test_env;
1444
1445         maps_coordinates_h origin = NULL;
1446         int error = maps_coordinates_create(37.34, 126.58, &origin);
1447         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1448
1449         maps_coordinates_h destination = NULL;
1450         error = maps_coordinates_create(37.34, 126.58, &destination);
1451         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1452
1453         /* test start --------------------------------- */
1454         error = maps_service_search_route(e->m, origin, destination, e->p,
1455                 __utc_maps_service_search_route_cb, (void*) e, &e->rid);
1456         if (error != MAPS_ERROR_NONE)
1457                 __utc_print_error_string(error);
1458         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1459         g_assert(e->rid > 0);
1460         /* test finish --------------------------------- */
1461
1462         e->wait_for_response();
1463
1464         error = maps_coordinates_destroy(origin);
1465         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1466
1467         error = maps_coordinates_destroy(destination);
1468         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1469
1470         e->finish_request();
1471 }
1472
1473 void utc_maps_service_search_route_n(void)
1474 {
1475         test_env e;
1476
1477         maps_coordinates_h origin = NULL;
1478         int error = maps_coordinates_create(37.34, 126.58, &origin);
1479         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1480
1481         maps_coordinates_h destination = NULL;
1482         error = maps_coordinates_create(37.34, 126.58, &destination);
1483         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1484
1485         /* test start --------------------------------- */
1486         error = maps_service_search_route(NULL, origin, destination, e.p,
1487                 __utc_maps_service_search_route_cb, &e, &e.rid);
1488         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1489
1490         /*error = maps_service_search_route(e.m, origin, destination, NULL,
1491                 __utc_maps_service_search_route_cb, &e, &e.rid);
1492         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);*/
1493
1494         error = maps_service_search_route(e.m, NULL, destination, e.p,
1495                 __utc_maps_service_search_route_cb, &e, &e.rid);
1496         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1497
1498         error = maps_service_search_route(e.m, origin, NULL, e.p,
1499                 __utc_maps_service_search_route_cb, &e, &e.rid);
1500         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1501
1502         error = maps_service_search_route(e.m, origin, destination, e.p, NULL,
1503                 &e, &e.rid);
1504         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1505
1506         error = maps_service_search_route(e.m, origin, destination, e.p,
1507                 __utc_maps_service_search_route_cb, &e, NULL);
1508         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1509         /* test finish --------------------------------- */
1510
1511         error = maps_coordinates_destroy(origin);
1512         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1513
1514         error = maps_coordinates_destroy(destination);
1515         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1516 }
1517
1518 /*int maps_service_search_route_waypoints(maps_service_h maps,
1519 * maps_item_hashtable_h preference, maps_coordinates_h* waypoint_list,
1520 * int waypoint_num, maps_service_search_route_cb callback, void* user_data,
1521 * int* request_id); */
1522 void utc_maps_service_search_route_waypoints_p(void)
1523 {
1524         test_env* e = new test_env;
1525
1526         maps_coordinates_h origin = NULL;
1527         int error = maps_coordinates_create(37.34, 126.58, &origin);
1528         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1529
1530         maps_coordinates_h destination = NULL;
1531         error = maps_coordinates_create(37.34, 126.58, &destination);
1532         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1533
1534         maps_coordinates_h waypoint_list[2] = { origin, destination };
1535
1536         /* test start --------------------------------- */
1537         error = maps_service_search_route_waypoints(e->m, waypoint_list, 2,
1538                 e->p, __utc_maps_service_search_route_cb, (void*) e, &e->rid);
1539         if (error != MAPS_ERROR_NONE)
1540                 __utc_print_error_string(error);
1541         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1542         g_assert(e->rid > 0);
1543         /* test finish --------------------------------- */
1544
1545         e->wait_for_response();
1546
1547         error = maps_coordinates_destroy(origin);
1548         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1549
1550         error = maps_coordinates_destroy(destination);
1551         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1552
1553         /*if(!e->async) delete e; */
1554         e->finish_request();
1555 }
1556
1557 void utc_maps_service_search_route_waypoints_n(void)
1558 {
1559         test_env e;
1560
1561         maps_coordinates_h origin = NULL;
1562         int error = maps_coordinates_create(37.34, 126.58, &origin);
1563         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1564
1565         maps_coordinates_h destination = NULL;
1566         error = maps_coordinates_create(37.34, 126.58, &destination);
1567         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1568
1569         maps_coordinates_h waypoint_list[2] = { origin, destination };
1570
1571         /* test start --------------------------------- */
1572         error = maps_service_search_route_waypoints(NULL, waypoint_list, 2, e.p,
1573                 __utc_maps_service_search_route_cb, &e, &e.rid);
1574         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1575
1576         /*error = maps_service_search_route_waypoints(e.m, waypoint_list, 2, NULL,
1577                 __utc_maps_service_search_route_cb, &e, &e.rid);
1578         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);*/
1579
1580         error = maps_service_search_route_waypoints(e.m, NULL, 2, e.p,
1581                 __utc_maps_service_search_route_cb, &e, &e.rid);
1582         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1583
1584         error = maps_service_search_route_waypoints(e.m, waypoint_list, 2, e.p,
1585                 NULL, &e, &e.rid);
1586         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1587
1588         error = maps_service_search_route_waypoints(e.m, waypoint_list, 2, e.p,
1589                 __utc_maps_service_search_route_cb, &e, NULL);
1590         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1591         /* test finish --------------------------------- */
1592
1593         error = maps_coordinates_destroy(origin);
1594         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1595
1596         error = maps_coordinates_destroy(destination);
1597         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1598 }
1599
1600 static bool __utc_maps_cancel_search_route_cb(maps_error_e error,
1601         int request_id, int index, int total, maps_route_h route,
1602         void* user_data)
1603 {
1604         return true;
1605 }
1606
1607 /*int maps_cancel_route(maps_service_h maps, int request_id); */
1608 void utc_maps_cancel_route_p(void)
1609 {
1610         test_env e;
1611
1612         maps_item_hashtable_set_string(e.p, "no_need_callback",
1613                 "no_need_callback");
1614
1615         maps_coordinates_h origin = NULL;
1616         int error = maps_coordinates_create(37.34, 126.58, &origin);
1617         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1618
1619         maps_coordinates_h destination = NULL;
1620         error = maps_coordinates_create(37.34, 126.58, &destination);
1621         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1622
1623         /* test start --------------------------------- */
1624         error = maps_service_search_route(e.m, origin, destination, e.p,
1625                 __utc_maps_cancel_search_route_cb, &e, &e.rid);
1626         if (error != MAPS_ERROR_NONE)
1627                 __utc_print_error_string(error);
1628         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1629         g_assert(e.rid > 0);
1630
1631         /*error = maps_cancel_route(e.m, e.rid); */
1632         error = maps_service_cancel_request(e.m, e.rid);
1633         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1634
1635         /* TODO: add tests for canceling
1636         *  maps_service_search_route_waypoints API */
1637         /* test finish --------------------------------- */
1638
1639         error = maps_coordinates_destroy(origin);
1640         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1641
1642         error = maps_coordinates_destroy(destination);
1643         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1644 }
1645
1646 void utc_maps_cancel_route_n(void)
1647 {
1648         /*const int error = maps_cancel_route(NULL, 1); */
1649         const int error = maps_service_cancel_request(NULL, 1);
1650         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1651 }
1652
1653 /*----------------------------------------------------------------------------*/
1654 /* Route Search with realistic input */
1655 static bool __utc_maps_route_segment_maneuver_cb(int index, int total,
1656         maps_route_maneuver_h maneuver, void* user_data)
1657 {
1658         /*g_print(" Maneuver >> %d\n", (index+1)); */
1659
1660         int error = maps_route_maneuver_destroy(maneuver);
1661         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1662
1663         return true;
1664 }
1665
1666 static bool __utc_maps_route_segment_cb(int index, int total,
1667         maps_route_segment_h segment, void* user_data)
1668 {
1669         if (!segment) {
1670                 g_print("critical error : FAILED\n");
1671                 return false;
1672         }
1673
1674         maps_coordinates_h _origin = NULL, _destination = NULL;
1675         double lat = 0.0, lon = 0.0;
1676
1677         int error = maps_route_segment_get_origin(segment, &_origin);
1678         if (error != MAPS_ERROR_NONE)
1679                 __utc_print_error_string(error);
1680         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1681
1682         if (_origin) {
1683                 error = maps_coordinates_get_latitude(_origin, &lat);
1684                 if (error != MAPS_ERROR_NONE)
1685                         __utc_print_error_string(error);
1686                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1687
1688                 error = maps_coordinates_get_longitude(_origin, &lon);
1689                 if (error != MAPS_ERROR_NONE)
1690                         __utc_print_error_string(error);
1691                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1692
1693                 /*g_print("Segment Origin Lat : %f, Lon : %f\n", lat, lon); */
1694
1695                 error = maps_coordinates_destroy(_origin);
1696                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1697         }
1698
1699         error = maps_route_segment_get_destination(segment, &_destination);
1700         if (error != MAPS_ERROR_NONE)
1701                 __utc_print_error_string(error);
1702         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1703
1704         if (_destination) {
1705                 error = maps_coordinates_get_latitude(_destination, &lat);
1706                 if (error != MAPS_ERROR_NONE)
1707                         __utc_print_error_string(error);
1708                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1709
1710                 error = maps_coordinates_get_longitude(_destination, &lon);
1711                 if (error != MAPS_ERROR_NONE)
1712                         __utc_print_error_string(error);
1713                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1714
1715                 /*g_print("Segment Destination Lat : %f, Lon : %f\n", lat,
1716                 * lon); */
1717
1718                 error = maps_coordinates_destroy(_destination);
1719                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1720         }
1721
1722         /*g_print(">>>>>> Parsing segments <<<<<<<<<<\n"); */
1723         error = maps_route_segment_foreach_maneuver(segment,
1724                 __utc_maps_route_segment_maneuver_cb, user_data);
1725         if (error != MAPS_ERROR_NONE)
1726                 __utc_print_error_string(error);
1727         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1728
1729         /*g_print("maneuver is supported, error code :: %d\n", error); */
1730
1731         error = maps_route_segment_destroy(segment);
1732         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1733
1734         return true;
1735 }
1736
1737 /*typedef bool(*maps_service_search_route_cb)(maps_error_e error,
1738 * int request_id, int index, int total, maps_route_h route, void* user_data); */
1739 static bool __utc_maps_service_search_route_real_cb(maps_error_e error,
1740         int request_id, int index, int total, maps_route_h route,
1741         void* user_data)
1742 {
1743         /*g_print("Received route callback [%d of %d]\n\n", index, total);*/
1744         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1745
1746         test_env* e = (test_env*) user_data;
1747         g_assert(e);
1748
1749         g_assert(index >= 0);
1750         g_assert(total > 0);
1751
1752         /*------------------------------------------------------ */
1753         if (error == MAPS_ERROR_NONE) {
1754                 /*g_print("\nDisplaying route result..\n"); */
1755
1756                 double dist = 0.0;
1757                 long duration = 0;
1758                 int err = maps_route_get_total_distance(route, &dist);
1759                 g_assert_cmpint(err, ==, MAPS_ERROR_NONE);
1760
1761                 err = maps_route_get_total_duration(route, &duration);
1762                 g_assert_cmpint(err, ==, MAPS_ERROR_NONE);
1763
1764                 /*g_print("Distance: %f\tDuration: %ld secs\n", dist,
1765                 * duration); */
1766
1767                 /*g_print("Route ptr: %p\n", route); */
1768                 err = maps_route_foreach_segment(route,
1769                         __utc_maps_route_segment_cb, NULL);
1770                 if (err != MAPS_ERROR_NONE)
1771                         __utc_print_error_string(err);
1772                 g_assert_cmpint(err, ==, MAPS_ERROR_NONE);
1773         }
1774         /*------------------------------------------------------ */
1775
1776         g_assert(route);
1777         int err = maps_route_destroy(route);
1778         g_assert_cmpint(err, ==, MAPS_ERROR_NONE);
1779
1780         if (index == (total - 1)) {
1781                 e->finish_response();
1782         }
1783
1784         return true;
1785 }
1786
1787 /*int maps_service_search_route(maps_service_h maps,
1788 * maps_item_hashtable_h preference, maps_coordinates_h origin,
1789 * maps_coordinates_h destination, maps_service_search_route_cb callback,
1790 * void* user_data, int* request_id); */
1791 void utc_maps_service_search_route_real_p(void)
1792 {
1793         test_env* e = new test_env;
1794
1795         /*utc_main_loop_master mlm(&__utc_main_loop); */
1796
1797         double srcLat = 12.733027;
1798         double srcLon = 77.83015999;
1799
1800         double destLat = 12.9165167;
1801         double destLon = 79.1324985999;
1802
1803         /* Creating route preference */
1804         maps_preference_h preference;
1805         int error = maps_preference_create(&preference);
1806         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1807
1808         /* Call Route Search API */
1809         maps_coordinates_h origin = NULL;
1810         maps_coordinates_h destination = NULL;
1811         int request_id = 0;
1812
1813         /* Setting Origin and Destination coordinates */
1814         maps_coordinates_create(srcLat, srcLon, &origin);
1815         maps_coordinates_create(destLat, destLon, &destination);
1816
1817         error = maps_preference_set_route_transport_mode(preference,
1818                 MAPS_ROUTE_TRANSPORT_MODE_CAR);
1819         /*MAPS_ROUTE_TRANSPORT_MODE_PEDESTRIAN); */
1820         /*MAPS_ROUTE_TRANSPORT_MODE_PUBLICTRANSIT); */
1821         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1822
1823         /* Set Route Optimization */
1824         error = maps_preference_set_route_optimization(preference,
1825                 MAPS_ROUTE_TYPE_FASTEST);
1826         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1827
1828         /*g_print("Run Routing Service!\n"); */
1829         error = maps_service_search_route(e->m, origin, destination, preference,
1830                 __utc_maps_service_search_route_real_cb, e, &request_id);
1831         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1832
1833         e->wait_for_response();
1834
1835         error = maps_coordinates_destroy(origin);
1836         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1837
1838         error = maps_coordinates_destroy(destination);
1839         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1840
1841         error = maps_preference_destroy(preference);
1842         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1843
1844         /*if(!e->async) delete e; */
1845         e->finish_request();
1846 }
1847
1848
1849
1850
1851 /*----------------------------------------------------------------------------*/
1852 /* Serial API test */
1853
1854 void utc_maps_service_serial_p(void)
1855 {
1856         test_env *e = new test_env;
1857         const int serial_test_number = 5;
1858
1859         /* Some test parameters */
1860         maps::coordinates berlin_c1(15.665354, 74.311523);
1861         maps::coordinates berlin_c2(10.617418, 79.145508);
1862         maps::area berlin_area(berlin_c1, berlin_c2);
1863
1864         maps::address address;
1865         maps_address_set_city(address, "Prague");
1866         maps_address_set_street(address, "Na Bojisti");
1867         maps_address_set_building_number(address, "1733/12");
1868
1869         maps::coordinates seoul_position(37.7555302, 127.002253);
1870         maps::place_filter filter;
1871         maps_place_filter_set_place_name(filter, "Seoul");
1872         maps::area seoul_area(37.7555302 + 0.2, 127.002253 - 0.2,
1873                               37.7555302 - 0.2, 127.002253 + 0.2);
1874         maps::area sf_area(37.7942 + 0.2, -122.407 - 0.2,
1875                            37.7942 - 0.2, -122.407 + 0.2);
1876
1877
1878         maps::coordinates origin(37.34, 126.58);
1879         maps::coordinates destination(37.34, 126.58);
1880         maps_coordinates_h waypoint_list[2] = { origin, destination };
1881
1882         for(int i = 0; i < serial_test_number; i ++) {
1883                 g_print("\n\n\tIteration: %d**************************\n\n", i);
1884
1885                 /* Geocode */
1886                 g_print("\t * Geocode [%d]\n", i);
1887                 int error = maps_service_geocode(e->m,
1888                                                  "Seoul",
1889                                                  e->p,
1890                                                  __utc_maps_service_geocode_cb,
1891                                                  (void*) e,
1892                                                  &e->rid);
1893                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1894                 e->wait_for_response();
1895                 g_assert(e->rid > 0);
1896                 g_assert(e->iterations > 0);
1897                 e->rid = 0;
1898                 e->iterations = 0;
1899
1900
1901                 g_print("\t * Geocode Inside Area [%d]\n", i);
1902                 error = maps_service_geocode_inside_area(e->m,
1903                                                          "Berlin",
1904                                                          berlin_area,
1905                                                          e->p,
1906                                                  __utc_maps_service_geocode_cb,
1907                                                          (void*) e,
1908                                                          &e->rid);
1909                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1910                 e->wait_for_response();
1911                 g_assert(e->rid > 0);
1912                 g_assert(e->iterations > 0);
1913                 e->rid = 0;
1914                 e->iterations = 0;
1915
1916                 g_print("\t * Geocode by Structured Address [%d]\n", i);
1917                 error = maps_service_geocode_by_structured_address(e->m,
1918                                                                    address,
1919                                                                    e->p,
1920                                                 __utc_maps_service_geocode_cb,
1921                                                                    (void*) e,
1922                                                                    &e->rid);
1923                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1924                 e->wait_for_response();
1925                 g_assert(e->rid > 0);
1926                 g_assert(e->iterations > 0);
1927                 e->rid = 0;
1928                 e->iterations = 0;
1929
1930                 /* Reverse Geocode */
1931                 g_print("\t * Reverse Geocode [%d]\n", i);
1932                 error = maps_service_reverse_geocode(e->m,
1933                                                      12.944594,
1934                                                      77.554303,
1935                                                      e->p,
1936                                         __utc_maps_service_reverse_geocode_cb,
1937                                                      (void*) e,
1938                                                      &e->rid);
1939                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1940                 e->wait_for_response();
1941                 g_assert(e->rid > 0);
1942                 e->rid = 0;
1943                 /* In this request we have only one iteration
1944                  * g_assert(e->iterations > 0);
1945                  * e->iterations = 0;*/
1946
1947                 /* Place */
1948                 g_print("\t * Search Place [%d]\n", i);
1949                 error = maps_service_search_place(e->m,
1950                                                   seoul_position,
1951                                                   50000,
1952                                                   filter,
1953                                                   e->p,
1954                                          __utc_maps_service_search_place_cb,
1955                                                   (void*) e,
1956                                                   &e->rid);
1957                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1958                 e->wait_for_response();
1959                 g_assert(e->rid > 0);
1960                 g_assert(e->iterations > 0);
1961                 e->rid = 0;
1962                 e->iterations = 0;
1963
1964
1965                 g_print("\t * Search Place by Area [%d]\n", i);
1966                 error = maps_service_search_place_by_area(e->m,
1967                                                           seoul_area,
1968                                                           filter,
1969                                                           e->p,
1970                                          __utc_maps_service_search_place_cb,
1971                                                           (void*) e,
1972                                                           &e->rid);
1973                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1974                 e->wait_for_response();
1975                 g_assert(e->rid > 0);
1976                 g_assert(e->iterations > 0);
1977                 e->rid = 0;
1978                 e->iterations = 0;
1979
1980
1981                 g_print("\t * Search Place by Address [%d]\n", i);
1982                 error = maps_service_search_place_by_address(e->m,
1983                                                              "Jackson",
1984                                                              sf_area,
1985                                                              filter,
1986                                                              e->p,
1987                                           __utc_maps_service_search_place_cb,
1988                                                              (void*) e,
1989                                                              &e->rid);
1990                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1991                 e->wait_for_response();
1992                 g_assert(e->rid > 0);
1993                 g_assert(e->iterations > 0);
1994                 e->rid = 0;
1995                 e->iterations = 0;
1996
1997
1998                 /* Route */
1999                 g_print("\t * Search Route [%d]\n", i);
2000                 error = maps_service_search_route(e->m,
2001                                                   origin,
2002                                                   destination,
2003                                                   e->p,
2004                                          __utc_maps_service_search_route_cb,
2005                                                   (void*) e,
2006                                                   &e->rid);
2007                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
2008                 e->wait_for_response();
2009                 g_assert(e->rid > 0);
2010                 g_assert(e->iterations > 0);
2011                 e->rid = 0;
2012                 e->iterations = 0;
2013
2014
2015                 g_print("\t * Search Route by Waypoints [%d]\n", i);
2016                 error = maps_service_search_route_waypoints(e->m,
2017                                                             waypoint_list,
2018                                                             2,
2019                                                             e->p,
2020                                          __utc_maps_service_search_route_cb,
2021                                                             (void*) e,
2022                                                             &e->rid);
2023                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
2024                 e->wait_for_response();
2025                 g_assert(e->rid > 0);
2026                 g_assert(e->iterations > 0);
2027                 e->rid = 0;
2028                 e->iterations = 0;
2029         }
2030
2031         e->finish_request();
2032 }