1176e694b35495325fc90fe836c822025d14efe0
[platform/core/api/maps-service.git] / test / maps_test_geocode.c
1 #include "maps_test.h"
2 #include "maps_test_geocode.h"
3 #include "maps_test_log.h"
4 #include "maps_test_util.h"
5
6
7 static void startup()
8 {
9 }
10
11 static void cleanup(bool result)
12 {
13         print_result(result);
14 }
15
16
17 /*
18  *
19  *      callback functions for APIs
20  *
21  */
22
23 static bool __maps_test_geocode_cb(maps_error_e error, int request_id,
24         int index, int total, maps_coordinates_h coord, void *user_data)
25 {
26         LOG_VARIABLES();
27         LOG_START_TITLE("%s [%d/%d] ", (user_data ? (char*)user_data : __FUNCTION__), MIN(index+1, total), total);
28
29         if (error) {
30                 LOGD("error=%d", error);
31                 cleanup(false);
32                 return false;
33         }
34
35         log_coordinates("", "Geocoding", coord);
36         maps_coordinates_destroy(coord);
37         LOG_FINISH("");
38
39         if (index == total - 1)
40                 cleanup(true);
41         return true;
42 }
43
44 int maps_test_geocode(maps_service_h maps_svc)
45 {
46         startup();
47         int request_id = 0, error;
48
49         error = maps_service_geocode(maps_svc, "Berlin", maps_pref, __maps_test_geocode_cb, "Geocoding with Berlin", &request_id);
50
51         if (error != MAPS_ERROR_NONE)
52                 cleanup(false);
53         return error;
54 }
55
56 static void __maps_test_reverse_geocode_cb(maps_error_e error, int request_id,
57         int index, int total, maps_address_h address, void *user_data)
58 {
59         LOG_VARIABLES();
60         LOG_START_TITLE("%s [%d/%d] ", (user_data ? (char*)user_data : __FUNCTION__), MIN(index+1, total), total);
61
62         if (error) {
63                 LOGD("error=%d", error);
64                 cleanup(false);
65                 return;
66         }
67
68         log_address("", address);
69         maps_address_destroy(address);
70         LOG_FINISH("");
71
72         if (index == total - 1)
73                 cleanup(true);
74 }
75
76 int maps_test_reverse_geocode(maps_service_h maps_svc)
77 {
78         startup();
79         int request_id = 0, error;
80
81         error = maps_service_reverse_geocode(maps_svc, 12.944594, 77.554303, maps_pref,
82                         __maps_test_reverse_geocode_cb, "Reverse-geocoding with [12.944594, 77.554303]", &request_id);
83
84         if (error != MAPS_ERROR_NONE)
85                 cleanup(false);
86         return error;
87 }
88