1 /* Copyright (c) 2010-2014 Samsung Electronics Co., Ltd. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "maps_api_test.h"
18 #include "maps_service.h"
20 #include "maps_address.h"
21 #include "maps_test_utils.h"
22 #include "maps_object.h"
38 struct test_plugin_info_s
40 /* Maps Provider name, returned by the Plugin */
42 /* Maps Provider key */
44 /* Does the Plugin have asynchronous requests */
54 test_plugin_info_s get_plugin_info(int idx) const
56 static test_plugin_info_s info[] = {
64 "gMutJ6Bo9jyMtOfJRGG1/nXvwmBWgoCqp9U5_yslkcw",
70 test_env():m(NULL), p(NULL), rid(-1), async(false), iterations(0),
71 mainloop(NULL), last_time(0)
74 /* Chose the Plugin for testing */
76 DUMMY /* Dummy plugin */
77 /*HERE*/ /* Nokia Here Maps */
80 i = get_plugin_info(test_plugin_type);
82 /* Create an instance of Maps Service */
83 int error = maps_service_create(i.provider, &m);
85 if (error != MAPS_ERROR_NONE)
86 __utc_print_error_string(error);
87 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
89 error = maps_preference_create(&p);
90 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
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);
96 error = maps_preference_set_max_results(p, 4);
97 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
100 int error = maps_service_destroy(m);
101 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
103 error = maps_item_hashtable_destroy(p);
104 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
108 void finish_request()
112 void finish_response()
114 /*g_print("\nfinishing response...\n");*/
115 if (async && mainloop)
116 test_env::stop_waiting_for_response(this);
117 /*g_print("\nfinished response...\n");*/
120 static gboolean stop_waiting_for_response(gpointer data)
122 /*g_print("\nquite main loop\n");*/
125 test_env* e = (test_env*) data;
127 /*milsec = __get_milli_span(e->last_time);*/
128 g_main_loop_unref(e->mainloop);
129 g_main_loop_quit(e->mainloop);
133 /*g_print("return from main loop: %d msec\n", milsec);*/
137 void wait_for_response(void)
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,
147 g_main_loop_run(mainloop);
148 g_source_remove(timeout_id);
152 /*----------------------------------------------------------------------------*/
153 /* Create and Destroy */
154 void utc_maps_service_create_destroy_p(void)
159 /*----------------------------------------------------------------------------*/
160 /* Keys and properties */
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)
171 int error = maps_service_set_provider_key(e.m, e.i.key);
172 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
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);
182 void utc_maps_provider_key_n(void)
186 int error = maps_service_set_provider_key(NULL, "TEST_KEY");
187 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
189 error = maps_service_set_provider_key(e.m, NULL);
190 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
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);
197 error = maps_service_get_provider_key(e.m, NULL);
198 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
199 g_assert(!obtained_key);
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)
211 maps_item_hashtable_set_string(e.p, "MAP_SERVICE_PREF_LANGUAGE",
214 /* test start --------------------------------- */
215 error = maps_service_set_preference(e.m, e.p);
216 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
217 /* test finish --------------------------------- */
220 void utc_maps_service_set_preference_n(void)
225 maps_item_hashtable_set_string(e.p, "MAP_SERVICE_PREF_LANGUAGE",
228 /* test start --------------------------------- */
229 error = maps_service_set_preference(NULL, e.p);
230 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
232 error = maps_service_set_preference(e.m, NULL);
233 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
234 /* test finish --------------------------------- */
237 /*int maps_service_provider_is_service_supported(const maps_service_h maps, */
238 void utc_maps_service_provider_is_service_supported_p(void)
242 bool supported = false;
243 g_assert_cmpint(maps_service_provider_is_service_supported(e.m,
244 MAPS_SERVICE_GEOCODE, &supported), ==, MAPS_ERROR_NONE);
247 g_assert_cmpint(maps_service_provider_is_service_supported(e.m,
248 MAPS_SERVICE_GEOCODE_INSIDE_AREA, &supported), ==,
252 g_assert_cmpint(maps_service_provider_is_service_supported(e.m,
253 MAPS_SERVICE_GEOCODE_BY_STRUCTURED_ADDRESS, &supported),
254 ==, MAPS_ERROR_NONE);
257 g_assert_cmpint(maps_service_provider_is_service_supported(e.m,
258 MAPS_SERVICE_REVERSE_GEOCODE, &supported), ==,
262 g_assert_cmpint(maps_service_provider_is_service_supported(e.m,
263 MAPS_SERVICE_SEARCH_PLACE, &supported), ==,
267 g_assert_cmpint(maps_service_provider_is_service_supported(e.m,
268 MAPS_SERVICE_SEARCH_PLACE_BY_AREA, &supported), ==,
272 g_assert_cmpint(maps_service_provider_is_service_supported(e.m,
273 MAPS_SERVICE_SEARCH_PLACE_BY_ADDRESS, &supported), ==,
277 g_assert_cmpint(maps_service_provider_is_service_supported(e.m,
278 MAPS_SERVICE_SEARCH_ROUTE, &supported), ==,
282 g_assert_cmpint(maps_service_provider_is_service_supported(e.m,
283 MAPS_SERVICE_SEARCH_ROUTE_WAYPOINTS, &supported), ==,
287 g_assert_cmpint(maps_service_provider_is_service_supported(e.m,
288 MAPS_SERVICE_CANCEL_REQUEST, &supported), ==,
293 void utc_maps_service_provider_is_service_supported_n(void)
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);
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);
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);
319 void utc_maps_service_provider_is_data_supported_p(void)
323 bool supported = false;
325 g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
326 MAPS_PLACE_ADDRESS, &supported), ==, MAPS_ERROR_NONE);
329 g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
330 MAPS_PLACE_RATING, &supported), ==,
334 g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
335 MAPS_PLACE_CATEGORIES, &supported), ==,
339 g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
340 MAPS_PLACE_ATTRIBUTES, &supported), ==,
344 g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
345 MAPS_PLACE_CONTACTS, &supported), ==,
349 g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
350 MAPS_PLACE_EDITORIALS, &supported), ==,
354 g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
355 MAPS_PLACE_REVIEWS, &supported), ==,
359 g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
360 MAPS_PLACE_IMAGE, &supported), ==,
364 g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
365 MAPS_PLACE_SUPPLIER, &supported), ==,
369 g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
370 MAPS_PLACE_RELATED, &supported), ==,
374 g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
375 MAPS_ROUTE_PATH, &supported), ==, MAPS_ERROR_NONE);
378 g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
379 MAPS_ROUTE_SEGMENTS_PATH, &supported), ==,
383 g_assert_cmpint(maps_service_provider_is_data_supported(e.m,
384 MAPS_ROUTE_SEGMENTS_MANEUVERS, &supported), ==,
389 void utc_maps_service_provider_is_data_supported_n(void)
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);
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);
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);
410 /*----------------------------------------------------------------------------*/
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); */
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,
423 /*g_print("\n\n__utc_maps_service_geocode_cb [%d of %d]\n\n", index, total_count);*/
425 if (result != MAPS_ERROR_NONE)
426 __utc_print_error_string(result);
427 g_assert_cmpint(result, ==, MAPS_ERROR_NONE);
429 test_env* e = (test_env*) user_data;
435 g_assert_cmpint(e->rid, ==, request_id);
438 g_assert(index >= 0);
439 g_assert(total_count > 0);
441 g_assert(coordinates);
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);
449 g_assert(latitude > -90 || latitude < 90);
450 g_assert(longitude > -180 || longitude < 180);
451 g_assert(altitude > -100 || altitude < 100);
453 error = maps_coordinates_destroy(coordinates);
454 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
455 if (index == (total_count - 1)) {
456 e->finish_response();
461 void utc_maps_service_geocode_p(void)
463 test_env* e = new test_env;
465 /* test start --------------------------------- */
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);
473 e->wait_for_response();
475 g_assert(e->rid > 0);
476 g_assert(e->iterations > 0);
477 /* test finish --------------------------------- */
479 /*if(!e->async) delete e; */
480 /*else e->wait_for_response(); */
484 void utc_maps_service_geocode_n(void)
488 /* test start --------------------------------- */
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);
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);
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);*/
502 error = maps_service_geocode(e.m, "Seoul", e.p, NULL, NULL, &e.rid);
503 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
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 --------------------------------- */
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)
516 test_env* e = new test_env;
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);
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);
528 maps_area_h bounds = NULL;
529 error = maps_area_create_rectangle(c1, c2, &bounds);
532 /* test start --------------------------------- */
533 error = maps_service_geocode_inside_area(e->m,
537 e->p, __utc_maps_service_geocode_cb, (void*) e, &e->rid);
538 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
540 e->wait_for_response();
542 g_assert(e->rid > 0);
543 /* test finish --------------------------------- */
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);
552 /*if(!e->async) delete e; */
556 void utc_maps_service_geocode_inside_area_n(void)
560 maps_coordinates_h center = NULL;
561 int error = maps_coordinates_create(11.1, 22.2, ¢er);
564 maps_area_h bounds = NULL;
565 error = maps_area_create_circle(center, 200, &bounds);
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);
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);
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);*/
581 error = maps_service_geocode_inside_area(e.m, "Seoul", bounds, e.p,
583 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
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 --------------------------------- */
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);
596 void utc_maps_service_geocode_by_structured_address_p(void)
598 test_env* e = new test_env;
600 maps_address_h address = NULL;
601 int error = maps_address_create(&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");
607 /* test start --------------------------------- */
608 error = maps_service_geocode_by_structured_address(e->m,
610 e->p, __utc_maps_service_geocode_cb, (void*) e, &e->rid);
611 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
613 e->wait_for_response();
615 g_assert(e->rid > 0);
616 /* test finish --------------------------------- */
618 error = maps_address_destroy(address);
619 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
621 /*if(!e->async) delete e; */
625 void utc_maps_service_geocode_by_structured_address_n(void)
629 maps_address_h address = NULL;
630 int error = maps_address_create(&address);
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);
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);
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);*/
646 error = maps_service_geocode_by_structured_address(e.m, address, e.p,
648 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
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 --------------------------------- */
655 error = maps_address_destroy(address);
656 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
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,
664 g_assert_cmpint(result, ==, MAPS_ERROR_NONE);
671 g_print("[%s] address\n", __FUNCTION__);
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);
680 if (maps_address_get_street(address, &street) == MAPS_ERROR_NONE)
681 g_print("\tstreet\t: %s\n", street);
684 char *district = NULL;
685 if (maps_address_get_district(address,
686 &district) == MAPS_ERROR_NONE)
687 g_print("\tdistrict\t: %s\n", district);
691 if (maps_address_get_city(address, &city) == MAPS_ERROR_NONE)
692 g_print("\tcity\t: %s\n", city);
696 if (maps_address_get_state(address, &state) == MAPS_ERROR_NONE)
697 g_print("\tstate\t: %s\n", state);
700 char *country = NULL;
701 if (maps_address_get_country(address,
702 &country) == MAPS_ERROR_NONE)
703 g_print("\tcountry\t: %s\n", country);
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);
713 if (maps_address_get_county(address, &county) == MAPS_ERROR_NONE)
714 g_print("\tcounty\t: %s\n", county);
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);
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);
729 error = maps_address_destroy(address);
732 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
734 test_env* e = (test_env*) user_data;
738 g_assert_cmpint(e->rid, ==, request_id);
741 g_assert_cmpint(index, ==, 0);
742 g_assert_cmpint(total, ==, 1);
744 /*if(e->async) delete e; */
745 e->finish_response();
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)
753 test_env* e = new test_env;
755 /* test start --------------------------------- */
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);
763 e->wait_for_response();
765 g_assert(e->rid > 0);
766 /* test finish --------------------------------- */
768 /*if(!e->async) delete e; */
772 void utc_maps_service_reverse_geocode_n(void)
776 /* test start --------------------------------- */
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);
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);*/
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 --------------------------------- */
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,
800 void utc_maps_cancel_geocode_p(void)
804 maps_item_hashtable_set_string(e.p, "no_need_callback",
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);
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);
820 void utc_maps_cancel_geocode_p02(void)
824 maps_item_hashtable_set_string(e.p, "no_need_callback",
827 for (int i = 0; i < 5; i++) {
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);
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);
841 void utc_maps_cancel_geocode_n(void)
843 const int error = maps_service_cancel_request(NULL, 1);
844 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
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,
855 void utc_maps_cancel_reverse_geocode_p(void)
859 maps_item_hashtable_set_string(e.p, "no_need_callback",
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);
868 error = maps_service_cancel_request(e.m, e.rid);
869 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
872 void utc_maps_cancel_reverse_geocode_n(void)
874 const int error = maps_service_cancel_request(NULL, 1);
875 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
878 /*----------------------------------------------------------------------------*/
880 static bool __utc_place_contact_cb(int index, int total,
881 maps_place_contact_h contact_h, void* user_data)
886 maps::place_contact contact(contact_h);
888 g_print("contact [%d/%d]\n", index + 1, total);
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);
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);
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);
905 static bool __utc_place_category_cb(int index, int total,
906 maps_place_category_h category_h, void* user_data)
911 maps::place_category category(category_h);
913 g_print("category [%d/%d]\n", index + 1, total);
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);
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);
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);
930 static bool __utc_place_link_object(const char* tag,
931 maps_place_link_object_h link_object_h)
936 maps::place_link_object link_object(link_object_h);
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);
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);
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);
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);
960 static bool __utc_place_image_cb(int index, int total,
961 maps_place_image_h image_h, void* user_data)
966 g_print("image [%d/%d]\n", index + 1, total);
968 maps::place_image image(image_h);
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);
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);
979 if (maps_place_image_get_width(image, &nval) == MAPS_ERROR_NONE
981 g_print("\twidth\t: %d\n", nval);
983 if (maps_place_image_get_height(image, &nval) == MAPS_ERROR_NONE
985 g_print("\theight\t: %d\n", nval);
987 maps::place_link_object user_link(NULL);
988 if (maps_place_image_get_user_link(image, user_link) ==
990 g_print("\tuserlink\n");
991 __utc_place_link_object("\t\t", user_link.clone());
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);
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());
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());
1019 static bool __utc_place_editorial_cb(int index, int total,
1020 maps_place_editorial_h editorial_h, void* user_data)
1023 maps::place_editorial editorial(editorial_h);
1027 static bool __utc_place_review_cb(int index, int total,
1028 maps_place_review_h review_h, void* user_data)
1031 maps::place_review review(review_h);
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,
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);
1045 test_env* e = (test_env*) user_data;
1051 g_assert_cmpint(e->rid, ==, request_id);
1054 g_assert(index >= 0);
1055 g_assert(length > 0);
1057 if(error == MAPS_ERROR_NOT_FOUND) {
1058 g_assert(index == 0);
1059 g_assert(length == 1);
1060 e->finish_response();
1067 maps::place place(place_h);
1069 /* Parsing Result Data ------------------------------------- */
1070 /*g_print("Search Place [%d/%d]\n", index + 1, length);*/
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());
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);
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);
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);
1090 maps::place_rating rating(NULL);
1091 if (maps_place_get_rating(place, rating) == MAPS_ERROR_NONE) {
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);
1100 maps::address address(NULL);
1101 if (maps_place_get_address(place, address) == MAPS_ERROR_NONE) {
1102 g_print("address\n");
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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,
1157 maps_place_foreach_review(place, __utc_place_review_cb, user_data);
1161 /* End Parsing Result Data --------------------------------- */
1163 if (index == (length - 1)) {
1164 /*if(e->async) delete e; */
1165 e->finish_response();
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)
1177 test_env* e = new test_env;
1179 maps::coordinates position(37.7942, -122.4070);
1180 //maps::coordinates position(37.7555302, 127.002253);
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);
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 --------------------------------- */
1198 e->wait_for_response();
1199 e->finish_request();
1202 void utc_maps_service_search_place_n(void)
1205 /*maps::coordinates position(37.7942, -122.4070);*/
1206 maps::coordinates position(37.7555302, 127.002253);
1207 maps::place_filter filter;
1209 /* test start --------------------------------- */
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);
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);
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);*/
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);
1227 error = maps_service_search_place(e.m, position, 5000, filter, e.p, NULL,
1229 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1230 /* test finish --------------------------------- */
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)
1239 test_env* e = new test_env;
1241 maps::place_filter filter;
1242 int error = maps_place_filter_set_place_name(filter, "Seoul");
1243 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
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);
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);
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 --------------------------------- */
1264 e->wait_for_response();
1265 e->finish_request();
1268 void utc_maps_service_search_place_by_area_n(void)
1271 maps::place_filter filter;
1272 /*maps::area area(37.7942 + 0.2, -122.407 - 0.2, 37.7942 - 0.2,
1274 maps::area area(37.7555302 + 0.2, 127.002253 - 0.2,
1275 37.7555302 - 0.2, 127.002253 + 0.2);
1277 /* test start --------------------------------- */
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);
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);
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);*/
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);
1295 error = maps_service_search_place_by_area(e.m, area, filter, e.p, NULL,
1297 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1298 /* test finish --------------------------------- */
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)
1307 test_env* e = new test_env;
1309 maps::place_filter filter;
1310 int error = maps_place_filter_set_place_name(filter, "Seoul");
1311 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
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);*/
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,
1322 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1323 g_assert(e->rid > 0);
1324 /* test finish --------------------------------- */
1326 e->wait_for_response();
1327 e->finish_request();
1330 void utc_maps_service_search_place_by_address_n(void)
1334 maps::place_filter filter;
1335 int error = maps_place_filter_set_place_name(filter, "Seoul");
1336 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1338 /*maps::area area(37.7942 + 0.2, -122.407 - 0.2, 37.7942 - 0.2,
1340 maps::area area(37.7555302 + 0.2, 127.002253 - 0.2,
1341 37.7555302 - 0.2, 127.002253 + 0.2);
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);
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);
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);*/
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);
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 --------------------------------- */
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)
1373 void utc_maps_cancel_place_p(void)
1377 maps_item_hashtable_set_string(e.p, "no_need_callback",
1378 "no_need_callback");
1380 maps::coordinates position(37.34, 126.58);
1382 maps::place_filter filter;
1383 int error = maps_place_filter_set_place_name(filter, "Seoul");
1384 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
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);
1391 error = maps_service_cancel_request(e.m, e.rid);
1392 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1394 /* TODO: add tests for canceling maps_service_search_place_by_area,
1395 * maps_service_search_place_by_address APIs */
1398 void utc_maps_cancel_place_n(void)
1400 const int error = maps_service_cancel_request(NULL, 1);
1401 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
1404 /*----------------------------------------------------------------------------*/
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,
1412 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1414 test_env* e = (test_env*) user_data;
1420 g_assert_cmpint(e->rid, ==, request_id);
1423 g_assert(index >= 0);
1424 g_assert(total > 0);
1427 int err = maps_route_destroy(route);
1428 g_assert_cmpint(err, ==, MAPS_ERROR_NONE);
1430 if (index == (total - 1)) {
1431 e->finish_response();
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)
1443 test_env* e = new test_env;
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);
1449 maps_coordinates_h destination = NULL;
1450 error = maps_coordinates_create(37.34, 126.58, &destination);
1451 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
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 --------------------------------- */
1462 e->wait_for_response();
1464 error = maps_coordinates_destroy(origin);
1465 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1467 error = maps_coordinates_destroy(destination);
1468 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1470 e->finish_request();
1473 void utc_maps_service_search_route_n(void)
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);
1481 maps_coordinates_h destination = NULL;
1482 error = maps_coordinates_create(37.34, 126.58, &destination);
1483 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
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);
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);*/
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);
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);
1502 error = maps_service_search_route(e.m, origin, destination, e.p, NULL,
1504 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
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 --------------------------------- */
1511 error = maps_coordinates_destroy(origin);
1512 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1514 error = maps_coordinates_destroy(destination);
1515 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
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)
1524 test_env* e = new test_env;
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);
1530 maps_coordinates_h destination = NULL;
1531 error = maps_coordinates_create(37.34, 126.58, &destination);
1532 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1534 maps_coordinates_h waypoint_list[2] = { origin, destination };
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 --------------------------------- */
1545 e->wait_for_response();
1547 error = maps_coordinates_destroy(origin);
1548 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1550 error = maps_coordinates_destroy(destination);
1551 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1553 /*if(!e->async) delete e; */
1554 e->finish_request();
1557 void utc_maps_service_search_route_waypoints_n(void)
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);
1565 maps_coordinates_h destination = NULL;
1566 error = maps_coordinates_create(37.34, 126.58, &destination);
1567 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1569 maps_coordinates_h waypoint_list[2] = { origin, destination };
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);
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);*/
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);
1584 error = maps_service_search_route_waypoints(e.m, waypoint_list, 2, e.p,
1586 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
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 --------------------------------- */
1593 error = maps_coordinates_destroy(origin);
1594 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1596 error = maps_coordinates_destroy(destination);
1597 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
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,
1607 /*int maps_cancel_route(maps_service_h maps, int request_id); */
1608 void utc_maps_cancel_route_p(void)
1612 maps_item_hashtable_set_string(e.p, "no_need_callback",
1613 "no_need_callback");
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);
1619 maps_coordinates_h destination = NULL;
1620 error = maps_coordinates_create(37.34, 126.58, &destination);
1621 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
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);
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);
1635 /* TODO: add tests for canceling
1636 * maps_service_search_route_waypoints API */
1637 /* test finish --------------------------------- */
1639 error = maps_coordinates_destroy(origin);
1640 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1642 error = maps_coordinates_destroy(destination);
1643 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1646 void utc_maps_cancel_route_n(void)
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);
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)
1658 /*g_print(" Maneuver >> %d\n", (index+1)); */
1660 int error = maps_route_maneuver_destroy(maneuver);
1661 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1666 static bool __utc_maps_route_segment_cb(int index, int total,
1667 maps_route_segment_h segment, void* user_data)
1670 g_print("critical error : FAILED\n");
1674 maps_coordinates_h _origin = NULL, _destination = NULL;
1675 double lat = 0.0, lon = 0.0;
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);
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);
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);
1693 /*g_print("Segment Origin Lat : %f, Lon : %f\n", lat, lon); */
1695 error = maps_coordinates_destroy(_origin);
1696 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
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);
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);
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);
1715 /*g_print("Segment Destination Lat : %f, Lon : %f\n", lat,
1718 error = maps_coordinates_destroy(_destination);
1719 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
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);
1729 /*g_print("maneuver is supported, error code :: %d\n", error); */
1731 error = maps_route_segment_destroy(segment);
1732 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
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,
1743 /*g_print("Received route callback [%d of %d]\n\n", index, total);*/
1744 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1746 test_env* e = (test_env*) user_data;
1749 g_assert(index >= 0);
1750 g_assert(total > 0);
1752 /*------------------------------------------------------ */
1753 if (error == MAPS_ERROR_NONE) {
1754 /*g_print("\nDisplaying route result..\n"); */
1758 int err = maps_route_get_total_distance(route, &dist);
1759 g_assert_cmpint(err, ==, MAPS_ERROR_NONE);
1761 err = maps_route_get_total_duration(route, &duration);
1762 g_assert_cmpint(err, ==, MAPS_ERROR_NONE);
1764 /*g_print("Distance: %f\tDuration: %ld secs\n", dist,
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);
1774 /*------------------------------------------------------ */
1777 int err = maps_route_destroy(route);
1778 g_assert_cmpint(err, ==, MAPS_ERROR_NONE);
1780 if (index == (total - 1)) {
1781 e->finish_response();
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)
1793 test_env* e = new test_env;
1795 /*utc_main_loop_master mlm(&__utc_main_loop); */
1797 double srcLat = 12.733027;
1798 double srcLon = 77.83015999;
1800 double destLat = 12.9165167;
1801 double destLon = 79.1324985999;
1803 /* Creating route preference */
1804 maps_preference_h preference;
1805 int error = maps_preference_create(&preference);
1806 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1808 /* Call Route Search API */
1809 maps_coordinates_h origin = NULL;
1810 maps_coordinates_h destination = NULL;
1813 /* Setting Origin and Destination coordinates */
1814 maps_coordinates_create(srcLat, srcLon, &origin);
1815 maps_coordinates_create(destLat, destLon, &destination);
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);
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);
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);
1833 e->wait_for_response();
1835 error = maps_coordinates_destroy(origin);
1836 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1838 error = maps_coordinates_destroy(destination);
1839 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1841 error = maps_preference_destroy(preference);
1842 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1844 /*if(!e->async) delete e; */
1845 e->finish_request();
1851 /*----------------------------------------------------------------------------*/
1852 /* Serial API test */
1854 void utc_maps_service_serial_p(void)
1856 test_env *e = new test_env;
1857 const int serial_test_number = 5;
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);
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");
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);
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 };
1882 for(int i = 0; i < serial_test_number; i ++) {
1883 g_print("\n\n\tIteration: %d**************************\n\n", i);
1886 g_print("\t * Geocode [%d]\n", i);
1887 int error = maps_service_geocode(e->m,
1890 __utc_maps_service_geocode_cb,
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);
1901 g_print("\t * Geocode Inside Area [%d]\n", i);
1902 error = maps_service_geocode_inside_area(e->m,
1906 __utc_maps_service_geocode_cb,
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);
1916 g_print("\t * Geocode by Structured Address [%d]\n", i);
1917 error = maps_service_geocode_by_structured_address(e->m,
1920 __utc_maps_service_geocode_cb,
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);
1930 /* Reverse Geocode */
1931 g_print("\t * Reverse Geocode [%d]\n", i);
1932 error = maps_service_reverse_geocode(e->m,
1936 __utc_maps_service_reverse_geocode_cb,
1939 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
1940 e->wait_for_response();
1941 g_assert(e->rid > 0);
1943 /* In this request we have only one iteration
1944 * g_assert(e->iterations > 0);
1945 * e->iterations = 0;*/
1948 g_print("\t * Search Place [%d]\n", i);
1949 error = maps_service_search_place(e->m,
1954 __utc_maps_service_search_place_cb,
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);
1965 g_print("\t * Search Place by Area [%d]\n", i);
1966 error = maps_service_search_place_by_area(e->m,
1970 __utc_maps_service_search_place_cb,
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);
1981 g_print("\t * Search Place by Address [%d]\n", i);
1982 error = maps_service_search_place_by_address(e->m,
1987 __utc_maps_service_search_place_cb,
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);
1999 g_print("\t * Search Route [%d]\n", i);
2000 error = maps_service_search_route(e->m,
2004 __utc_maps_service_search_route_cb,
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);
2015 g_print("\t * Search Route by Waypoints [%d]\n", i);
2016 error = maps_service_search_route_waypoints(e->m,
2020 __utc_maps_service_search_route_cb,
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);
2031 e->finish_request();