Update test console app
[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()
12 {
13 }
14
15 static void cleanup_callback(int error)
16 {
17         print_result(error);
18         cleanup();
19 }
20
21
22
23 /*
24  *
25  *      callback functions for APIs
26  *
27  */
28
29 static bool __maps_test_geocode_cb(maps_error_e error, int request_id,
30         int index, int total, maps_coordinates_h coord, void *user_data)
31 {
32         LOG_VARIABLES();
33         LOG_START_TITLE("%s [%d/%d] ", (user_data ? (char*)user_data : __FUNCTION__), MIN(index+1, total), total);
34
35         if (error) {
36                 cleanup_callback(error);
37                 return false;
38         }
39
40         log_coordinates("", "Geocoding", coord);
41         maps_coordinates_destroy(coord);
42         LOG_FINISH("");
43
44         if (index == total - 1)
45                 cleanup_callback(error);
46         return true;
47 }
48
49 int maps_test_geocode(maps_service_h maps_svc)
50 {
51         startup();
52         int request_id = 0, error;
53
54         error = maps_service_geocode(maps_svc, "Berlin", maps_pref, __maps_test_geocode_cb, "Geocoding with Berlin", &request_id);
55
56         if (error != MAPS_ERROR_NONE)
57                 cleanup();
58         return error;
59 }
60
61 static void __maps_test_reverse_geocode_cb(maps_error_e error, int request_id,
62         int index, int total, maps_address_h address, void *user_data)
63 {
64         LOG_VARIABLES();
65         LOG_START_TITLE("%s [%d/%d] ", (user_data ? (char*)user_data : __FUNCTION__), MIN(index+1, total), total);
66
67         if (error) {
68                 cleanup_callback(error);
69                 return;
70         }
71
72         log_address("", address);
73         maps_address_destroy(address);
74         LOG_FINISH("");
75
76         if (index == total - 1)
77                 cleanup_callback(error);
78 }
79
80 int maps_test_reverse_geocode(maps_service_h maps_svc)
81 {
82         startup();
83         int request_id = 0, error;
84
85         error = maps_service_reverse_geocode(maps_svc, 12.944594, 77.554303, maps_pref,
86                         __maps_test_reverse_geocode_cb, "Reverse-geocoding with [12.944594, 77.554303]", &request_id);
87
88         if (error != MAPS_ERROR_NONE)
89                 cleanup();
90         return error;
91 }
92
93
94
95
96
97
98
99
100
101 static bool __maps_test_multi_reverse_geocode_cb(maps_error_e error, int request_id, int total,
102         maps_address_list_h address_list, void *user_data)
103 {
104         LOG_VARIABLES();
105
106         LOG_START_TITLE("%s [%d] ", (user_data ? (char*)user_data : __FUNCTION__), total);
107
108         if (error) {
109                 cleanup_callback(error);
110                 return false;
111         }
112
113         log_address("", address_list);
114         maps_address_list_destroy(address_list);
115         LOG_FINISH("");
116
117         cleanup_callback(error);
118         return true;
119 }
120
121 int maps_test_multi_reverse_geocode(maps_service_h maps_svc)
122 {
123         startup();
124         int request_id = 0, error;
125
126         maps_coordinates_h coordinates[3];
127         maps_coordinates_create(52.5309, 13.3845, &coordinates[0]);
128         maps_coordinates_create(50.1618996, 8.5334997, &coordinates[1]);
129         maps_coordinates_create(40.72962607104243, -73.98685008095087, &coordinates[2]);
130
131         maps_coordinates_list_h coordinates_list;
132         maps_coordinates_list_create(&coordinates_list);
133         maps_coordinates_list_append(coordinates_list, coordinates[0]);
134         maps_coordinates_list_append(coordinates_list, coordinates[1]);
135         maps_coordinates_list_append(coordinates_list, coordinates[2]);
136
137         error = maps_service_multi_reverse_geocode(maps_svc, coordinates_list, maps_pref,
138                         __maps_test_multi_reverse_geocode_cb, "Multi-reverse Geocoding", &request_id);
139         maps_coordinates_list_destroy(coordinates_list);
140
141         if (error != MAPS_ERROR_NONE)
142                 cleanup();
143         return error;
144 }
145