e86eca23e0d6dd2165a2fc1d218bce96c300d775
[platform/core/api/location-manager.git] / test / location_test.c
1 /*
2  * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd All Rights Reserved
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 <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <glib.h>
21 #include <locations.h>
22 #include <location_bounds.h>
23 #include <location_batch.h>
24 #include <unistd.h>
25
26
27 static location_manager_h manager;
28 static GMainLoop *g_mainloop = NULL;
29 static int menu;
30
31 static int repeat_count;
32 static void location_cleanup();
33 static int location_test();
34 static guint test_timer;
35
36 static gboolean exit_program(gpointer data)
37 {
38         g_main_loop_quit(g_mainloop);
39
40         return FALSE;
41 }
42
43 static gboolean wait_test()
44 {
45         if (test_timer) {
46                 g_source_remove(test_timer);
47                 test_timer = 0;
48         }
49
50         location_cleanup();
51         location_test();
52
53         return FALSE;
54 }
55
56 #if 0
57 void zone_event_cb(location_boundary_state_e state, double latitude, double longitude, double altitude, time_t timestamp, void *user_data)
58 {
59         if (state == LOCATIONS_BOUNDARY_IN) {
60                 fprintf(stderr, "Entering zone\n");
61         } else {                /* state == LOCATIONS_BOUNDARY_OUT */
62                 fprintf(stderr, "Leaving zone\n");
63         }
64
65         fprintf(stderr, "Latitude: %lf, longitude: %lf, altitude: %lf\n", latitude, longitude, altitude);
66
67         fprintf(stderr, "Time: %s\n", ctime(&timestamp));
68 }
69
70 static bool last_satellites_foreach_cb(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr, bool is_in_use, void *user_data)
71 {
72         fprintf(stderr, "[Last Satellite information]   azimuth : %d, elevation: %d, prn: %d, snr: %d, used: %d\n", azimuth, elevation,
73                prn, snr, is_in_use);
74         return true;
75 }
76
77 static bool __poly_coords_cb(location_coords_s coords, void *user_data)
78 {
79         fprintf(stderr, "location_bounds_foreach_rect_coords(latitude: %lf, longitude: %lf) \n", coords.latitude, coords.longitude);
80         return TRUE;
81 }
82
83 static bool __location_bounds_cb(location_bounds_h bounds, void *user_data)
84 {
85         if (bounds == NULL)
86                 fprintf(stderr, "bounds ==NULL\n");
87         else {
88                 location_bounds_type_e type;
89                 location_bounds_get_type(bounds, &type);
90                 if (type == LOCATION_BOUNDS_CIRCLE) {
91                         location_coords_s center;
92                         double radius;
93                         location_bounds_get_circle_coords(bounds, &center, &radius);
94                         fprintf(stderr, "location_bounds_get_circle_coords(center: %lf, %lf, radius: %lf) \n", center.latitude, center.longitude, radius);
95
96                 } else if (type == LOCATION_BOUNDS_RECT) {
97                         location_coords_s left_top;
98                         location_coords_s right_bottom;
99                         location_bounds_get_rect_coords(bounds, &left_top, &right_bottom);
100                         fprintf(stderr, "location_bounds_get_rect_coords(left_top: %lf, %lf - right_bottom: %lf, %lf) \n",
101                                         left_top.latitude, left_top.longitude, right_bottom.latitude, right_bottom.longitude);
102                 } else if (type == LOCATION_BOUNDS_POLYGON) {
103                         location_bounds_foreach_polygon_coords(bounds, __poly_coords_cb, NULL);
104                 }
105         }
106         return TRUE;
107 }
108
109 void location_bounds_test()
110 {
111         int ret;
112         location_coords_s center;
113         center.latitude = 37.258;
114         center.longitude = 127.056;
115         double radius = 30;
116         location_bounds_h bounds_circle;
117         ret = location_bounds_create_circle(center, radius, &bounds_circle);
118         if (ret != LOCATION_BOUNDS_ERROR_NONE)
119                 fprintf(stderr, "location_bounds_create_circle() failed\n");
120         else
121                 fprintf(stderr, "Bounds(circle) has been created successfully.\n");
122
123         ret = location_manager_add_boundary(manager, bounds_circle);
124         if (ret != LOCATIONS_ERROR_NONE)
125                 fprintf(stderr, "Setting boundary failed\n");
126         else
127                 fprintf(stderr, "Boundary set\n");
128
129         location_coords_s center2;
130         double radius2;
131         ret = location_bounds_get_circle_coords(bounds_circle, &center2, &radius2);
132         if (ret != LOCATIONS_ERROR_NONE) {
133                 fprintf(stderr, "location_bounds_get_circle_coords() failed\n");
134         } else
135                 fprintf(stderr, "location_bounds_get_circle_coords(center: %lf, %lf, radius: %lf) \n", center2.latitude,
136                                 center2.longitude, radius2);
137
138         /*Add the rect bounds */
139         location_coords_s left_top;
140         left_top.latitude = 30;
141         left_top.longitude = 30;
142
143         location_coords_s right_bottom;
144         right_bottom.latitude = 10;
145         right_bottom.longitude = 50;
146
147         location_bounds_h bounds_rect;
148         ret = location_bounds_create_rect(left_top, right_bottom, &bounds_rect);
149         if (ret != LOCATION_BOUNDS_ERROR_NONE)
150                 fprintf(stderr, "location_bounds_create_rect() failed\n");
151         else
152                 fprintf(stderr, "Bounds(rect) has been created successfully.\n");
153
154         ret = location_manager_add_boundary(manager, bounds_rect);
155         if (ret != LOCATIONS_ERROR_NONE)
156                 fprintf(stderr, "Setting boundary failed\n");
157         else
158                 fprintf(stderr, "Boundary set\n");
159
160         location_coords_s left_top2;
161         location_coords_s right_bottom2;
162
163         ret = location_bounds_get_rect_coords(bounds_rect, &left_top2, &right_bottom2);
164         if (ret != LOCATIONS_ERROR_NONE) {
165                 fprintf(stderr, "location_bounds_get_rect_coords() failed\n");
166         } else
167                 fprintf(stderr, "location_bounds_get_rect_coords(left_top: %lf, %lf - right_bottom: %lf, %lf) \n", left_top2.latitude,
168                                 left_top2.longitude, right_bottom2.latitude, right_bottom2.longitude);
169
170         /*Add the polygon bounds */
171
172         int poly_size = 3;
173         location_coords_s coord_list[poly_size];
174
175         coord_list[0].latitude = 10;
176         coord_list[0].longitude = 10;
177         coord_list[1].latitude = 20;
178         coord_list[1].longitude = 20;
179         coord_list[2].latitude = 30;
180         coord_list[2].longitude = 30;
181
182         location_bounds_h bounds_poly;
183         ret = location_bounds_create_polygon(coord_list, poly_size, &bounds_poly);
184         if (ret != LOCATION_BOUNDS_ERROR_NONE)
185                 fprintf(stderr, "location_bounds_create_polygon() failed\n");
186         else
187                 fprintf(stderr, "Bounds(polygon) has been created successfully.\n");
188
189         ret = location_manager_add_boundary(manager, bounds_poly);
190         if (ret != LOCATIONS_ERROR_NONE)
191                 fprintf(stderr, "Setting boundary failed\n");
192         else
193                 fprintf(stderr, "Boundary set\n");
194
195         ret = location_bounds_foreach_polygon_coords(bounds_poly, __poly_coords_cb, NULL);
196         if (ret != LOCATIONS_ERROR_NONE)
197                 fprintf(stderr, "location_bounds_get_rect_coords() failed\n");
198
199         location_coords_s test_coords;
200         test_coords.latitude = 12;
201         test_coords.longitude = 12;
202
203         if (location_bounds_contains_coordinates(bounds_poly, test_coords))
204                 fprintf(stderr, "location_bounds_contains_coordinates() retrun TRUE \n");
205         else
206                 fprintf(stderr, "location_bounds_contains_coordinates() retrun FALSE \n");
207
208         /*print current bounds */
209         ret = location_manager_foreach_boundary(manager, __location_bounds_cb, (void *)manager);
210         if (ret != LOCATIONS_ERROR_NONE)
211                 fprintf(stderr, "location_manager_foreach_boundary() failed\n");
212
213 }
214
215 void location_get_last_information_test()
216 {
217         int ret;
218         double altitude, latitude, longitude;
219         double climb, direction, speed;
220         double horizontal, vertical;
221         location_accuracy_level_e level;
222         time_t timestamp;
223         int num_of_inview, num_of_active;
224
225         ret = location_manager_get_last_position(manager, &altitude, &latitude, &longitude, &timestamp);
226         if (ret != LOCATIONS_ERROR_NONE)
227                 fprintf(stderr, " Fail: location_manager_get_last_position ---> %d \n", ret);
228         else
229                 fprintf(stderr, "[%ld] alt: %g, lat: %g, long: %g\n", timestamp, altitude, latitude, longitude);
230
231         ret = location_manager_get_last_velocity(manager, &climb, &direction, &speed, &timestamp);
232         if (ret != LOCATIONS_ERROR_NONE)
233                 fprintf(stderr, " Fail: location_manager_get_last_velocity ---> %d \n", ret);
234         else
235                 fprintf(stderr, "climb: %f, direction: %f, speed: %f\n", climb, direction, speed);
236
237         ret = location_manager_get_last_accuracy(manager, &level, &horizontal, &vertical);
238         if (ret != LOCATIONS_ERROR_NONE)
239                 fprintf(stderr, " Fail: location_manager_get_last_accuracy ---> %d \n", ret);
240         else
241                 fprintf(stderr, "Level: %d, horizontal: %g, vertical: %g\n", level, horizontal, vertical);
242
243         ret = gps_status_get_last_satellite(manager, &num_of_active, &num_of_inview, &timestamp);
244         if (ret != LOCATIONS_ERROR_NONE)
245                 fprintf(stderr, " Fail: gps_status_get_last_satellite_count_in_view ---> %d \n", ret);
246         else
247                 fprintf(stderr, "[%ld] Satellite number of active: %d, in view: %d\n", timestamp, num_of_active, num_of_inview);
248
249         ret = gps_status_foreach_last_satellites_in_view(manager, last_satellites_foreach_cb, NULL);
250         if (ret != LOCATIONS_ERROR_NONE)
251                 fprintf(stderr, " Fail: gps_status_foreach_last_satellites_in_view ---> %d \n", ret);
252 }
253 #endif
254
255 static void _state_change_cb(location_service_state_e state, void *user_data)
256 {
257         fprintf(stderr, "--------------------------state change: %d---------\n", state);
258         location_manager_h lm = (location_manager_h) user_data;
259         if (state == LOCATIONS_SERVICE_ENABLED) {
260                 int ret;
261                 double altitude;
262                 double latitude;
263                 double longitude;
264                 time_t timestamp;
265                 ret = location_manager_get_position(lm, &altitude, &latitude, &longitude, &timestamp);
266                 if (ret != LOCATIONS_ERROR_NONE)
267                         fprintf(stderr, " Fail: location_manager_get_position ---> %d \n", ret);
268                 else
269                         fprintf(stderr, "[%ld] lat: %f, lng: %f, alt: %f\n", timestamp, latitude, longitude, altitude);
270
271                 location_accuracy_level_e level;
272                 double horizontal;
273                 double vertical;
274                 ret = location_manager_get_accuracy(lm, &level, &horizontal, &vertical);
275                 if (ret != LOCATIONS_ERROR_NONE)
276                         fprintf(stderr, " Fail: location_manager_get_accuracy ---> %d \n", ret);
277                 else
278                         fprintf(stderr, "Level: %d, horizontal: %f, vertical %f\n", level, horizontal, vertical);
279 #if 0
280                 char *nmea;
281                 ret = gps_status_get_nmea(lm, &nmea);
282                 if (ret != LOCATIONS_ERROR_NONE) {
283                         fprintf(stderr, " Fail: gps_status_get_nmea ---> %d \n", ret);
284                 } else {
285                         fprintf(stderr, "NMEA: %s\n", nmea);
286                         free(nmea);
287                 }
288 #endif
289         }
290
291 }
292
293 void _position_updated_cb(double latitude, double longitude, double altitude, time_t timestamp, void *user_data)
294 {
295         fprintf(stderr, "-------------------------- position updated --------------------------\n");
296         fprintf(stderr, "[%ld] lat: %f, lng: %f, alt: %f\n", timestamp, latitude, longitude, altitude);
297
298         location_manager_h lm = (location_manager_h) user_data;
299         location_accuracy_level_e level;
300         double horizontal;
301         double vertical;
302         int ret = location_manager_get_accuracy(lm, &level, &horizontal, &vertical);
303         if (ret != LOCATIONS_ERROR_NONE)
304                 fprintf(stderr, " Fail: location_manager_get_accuracy ---> %d \n", ret);
305         else
306                 fprintf(stderr, "Level: %d, horizontal: %f, vertical %f\n", level, horizontal, vertical);
307
308         repeat_count++;
309
310         if (repeat_count > 9)
311                 test_timer = g_timeout_add_seconds(1, wait_test, NULL);
312 }
313
314 void _velocity_updated_cb(double speed, double direction, double climb, time_t timestamp, void *user_data)
315 {
316         fprintf(stderr, "-------------------------- velocity updated --------------------------\n");
317         fprintf(stderr, "[%ld] speed[%f] direction[%f] climb[%f]\n", timestamp, speed, direction, climb);
318 }
319
320 void _location_cb(int error, double latitude, double longitude, double altitude, time_t timestamp, double speed, double climb, double direction, void *user_data)
321 {
322         fprintf(stderr, "error[%d]\n", error);
323         fprintf(stderr, "location_cb: lat[%f] lon[%f] alt[%f]\n", latitude, longitude, altitude);
324         fprintf(stderr, "speed[%f] climb[%f] direction[%f]\n", speed, climb, direction);
325
326         test_timer = g_timeout_add_seconds(1, wait_test, NULL);
327 }
328
329 void _location_changed_cb(double latitude, double longitude, double altitude, double speed, double direction, double horizontal_accuracy, time_t timestamp, void *user_data)
330 {
331         fprintf(stderr, "-------------------------- location changed --------------------------\n");
332         fprintf(stderr, "[%ld] lat[%f] lon[%f] alt[%f] speed[%lf] direction[%lf], horizontal_accuracy[%lf]\n", timestamp, latitude, longitude, altitude, speed, direction, horizontal_accuracy);
333
334         repeat_count++;
335
336         if (repeat_count > 5)
337                 test_timer = g_timeout_add_seconds(1, wait_test, NULL);
338
339 }
340
341 bool _get_location_cb(double latitude, double longitude, double altitude, double speed, double direction, double horizontal, double vertical, time_t timestamp, void *user_data)
342 {
343         fprintf(stderr, "-------------------------- batch: get location --------------------------\n");
344         fprintf(stderr, "[%ld] lat[%f] lon[%f] alt[%f] speed[%lf] direction[%lf], horizontal_accuracy[%lf]\n", timestamp, latitude, longitude, altitude, speed, direction, horizontal);
345         return TRUE;
346 }
347
348 void _location_batch_cb(int num_of_location, void *user_data)
349 {
350         fprintf(stderr, "-------------------------- location batch --------------------------\n");
351         fprintf(stderr, "num_of_location: [%d]\n", num_of_location);
352
353         location_manager_h manager = user_data;
354
355         if (num_of_location > 0)
356                 location_manager_foreach_location_batch(manager, _get_location_cb, user_data);
357
358         repeat_count++;
359
360         if (repeat_count > 1)
361                 test_timer = g_timeout_add_seconds(1, wait_test, NULL);
362 }
363
364 static void _setting_cb(location_method_e method, bool enable, void *user_data)
365 {
366         fprintf(stderr, "method[%d], enable[%d]\n", method, enable);
367 }
368
369 void _satellite_updated_cb(int num_of_active, int num_of_inview, time_t timestamp, void *user_data)
370 {
371         fprintf(stderr, "-------------------------- satellite updated --------------------------\n");
372         fprintf(stderr, "num_of_active[%d] num_of_inview[%d] timestamp[%ld]\n", num_of_active, num_of_inview, timestamp);
373
374         test_timer = g_timeout_add_seconds(1, wait_test, NULL);
375 }
376
377 static void print_location_status()
378 {
379         fprintf(stderr, "==== LOCATION Setting state =====\n");
380         bool is_enabled = FALSE;
381         location_manager_is_enabled_method(LOCATIONS_METHOD_HYBRID, &is_enabled);
382         fprintf(stderr, "hybrid: %d, ", is_enabled);
383
384         location_manager_is_enabled_method(LOCATIONS_METHOD_GPS, &is_enabled);
385         fprintf(stderr, "gps: %d, ", is_enabled);
386
387         location_manager_is_enabled_method(LOCATIONS_METHOD_WPS, &is_enabled);
388         fprintf(stderr, "wps: %d, ", is_enabled);
389
390         /* location_manager_is_test_location_enabled(&is_enabled); */
391         location_manager_is_enabled_method(LOCATIONS_METHOD_MOCK, &is_enabled);
392         fprintf(stderr, "mock: %d\n", is_enabled);
393 }
394
395 static int enable_method(location_method_e method, bool enable)
396 {
397         int ret = 0;
398         fprintf(stderr, "==== LOCATION Setting changed =====\n");
399
400         location_manager_set_setting_changed_cb(LOCATIONS_METHOD_HYBRID, _setting_cb, NULL);
401
402         fprintf(stderr, "method[%d], enable[%d]\n", method, enable);
403         ret = location_manager_enable_method(method, enable);
404
405         location_manager_unset_setting_changed_cb(LOCATIONS_METHOD_HYBRID);
406         return ret;
407 }
408
409 static int test_clear_mock_location(gpointer user_data)
410 {
411         location_manager_h manager = (location_manager_h) user_data;
412         int ret = 0;
413
414         ret = location_manager_clear_mock_location(manager);
415         fprintf(stderr, "\n==== location_manager_clear_mock_location: %d ====\n\n", ret);
416
417         /*
418         int state = 0;
419         ret = location_manager_get_service_state(manager, &state);
420         fprintf(stderr, "the current state: %d, ret = %d\n", state, ret);
421         */
422
423         return FALSE;
424 }
425
426
427 static int test_set_mock_location(gpointer user_data)
428 {
429         location_manager_h manager = (location_manager_h) user_data;
430         int ret = 0;
431
432         /*
433         int state = 0;
434         ret = location_manager_get_service_state(manager, &state);
435         fprintf(stderr, "the current state: %d, ret = %d\n", state, ret);
436         */
437
438         ret = location_manager_set_mock_location(manager, 20, 20, 0, 40, 50, 100);
439         fprintf(stderr, "\n==== location_manager_set_location: %d ====\n\n", ret);
440         if (ret != LOCATIONS_ERROR_NONE)
441                 g_timeout_add_seconds(3, test_clear_mock_location, manager);
442
443         return FALSE;
444 }
445
446 static void print_menu()
447 {
448         fprintf(stderr, "============= LOCATION TEST =============\n");
449         fprintf(stderr, "[1] Get location: LOCATIONS_METHOD_HYBRID\n");
450         fprintf(stderr, "[2] Get location: LOCATIONS_METHOD_GPS\n");
451         fprintf(stderr, "[3] Get location: LOCATIONS_METHOD_WPS\n");
452         fprintf(stderr, "[4] Single location: LOCATIONS_METHOD_HYBRID\n");
453         fprintf(stderr, "[5] Single location: LOCATIONS_METHOD_GPS\n");
454         fprintf(stderr, "[6] Single location: LOCATIONS_METHOD_WPS\n\n");
455         fprintf(stderr, "[11] Change update interval: LOCATIONS_METHOD_HYBRID\n");
456         fprintf(stderr, "[12] Change update interval: LOCATIONS_METHOD_GPS\n\n");
457         fprintf(stderr, "[21] Distance based location update: LOCATIONS_METHOD_HYBRID\n");
458         fprintf(stderr, "[22] Distance based location update: LOCATIONS_METHOD_GPS\n");
459         fprintf(stderr, "[23] Distance based location update: LOCATIONS_METHOD_WPS\n\n");
460         fprintf(stderr, "[31] Location batch update: LOCATIONS_METHOD_GPS\n\n");
461         fprintf(stderr, "[41] Turn on/off mock test: LOCATIONS_METHOD_MOCK\n");
462         fprintf(stderr, "[42] Set & Clear location: LOCATIONS_METHOD_HYBRID\n\n");
463         fprintf(stderr, "[51] Turn on/off method: LOCATIONS_METHOD_HYBRID\n");
464         fprintf(stderr, "[52] Turn on/off method: LOCATIONS_METHOD_GPS\n");
465         fprintf(stderr, "[53] Turn on/off method: LOCATIONS_METHOD_WPS\n\n");
466         fprintf(stderr, "[61] Boundary Test\n\n");
467         fprintf(stderr, "[0] Exit!!!\n\n");
468         fprintf(stderr, "Select menu: ");
469
470         if (scanf("%d", &menu) < 0)
471                 fprintf(stderr, "Can't read menu !!!\n");
472 }
473
474 static int location_test()
475 {
476         int ret = LOCATIONS_ERROR_NONE;
477         int basic = 0;
478         int interval = 1;
479         repeat_count = 0;
480
481         print_location_status();
482         print_menu();
483
484         switch (menu) {
485         case 1:
486         case 2:
487         case 3: {
488                 basic = 1;
489
490                 int method = menu - 1;
491                 ret = location_manager_create(method, &manager);
492                 fprintf(stderr, "location_manager_create (method: %d): %d\n", method, ret);
493
494                 ret = location_manager_start(manager);
495                 fprintf(stderr, "start: %d\n", ret);
496
497                 if (method == LOCATIONS_METHOD_GPS) {
498                         ret = gps_status_set_satellite_updated_cb(manager, _satellite_updated_cb, 1, &manager);
499                         fprintf(stderr, "gps_status_set_satellite_updated_cb: %d\n", ret);
500                 }
501                 break;
502                 }
503         case 4:
504         case 5:
505         case 6: {
506                 int timeout = 30;
507
508                 fprintf(stderr, "\n     Input timeout ==> ");
509                 ret = scanf("%d", &timeout);
510
511                 int method = menu - 4;
512                 ret = location_manager_create(method, &manager);
513                 ret = location_manager_request_single_location(manager, timeout, _location_cb, manager);
514                 fprintf(stderr, "request single_location (method: %d): %d\n", method, ret);
515                 break;
516                 }
517         case 11:
518         case 12:
519         case 13: {
520                 int interval = 1;
521
522                 fprintf(stderr, "\n     Input position interval ==> ");
523                 ret = scanf("%d", &interval);
524
525                 int method = menu - 11;
526                 ret = location_manager_create(method, &manager);
527                 fprintf(stderr, "location_manager_create (method: %d): %d\n", method, ret);
528
529                 ret = location_manager_set_position_updated_cb(manager, _position_updated_cb, interval, (void *)manager);
530                 fprintf(stderr, "set_position_updated_cb: %d\n", ret);
531
532                 /*
533                 ret = location_manager_set_velocity_updated_cb(manager, _velocity_updated_cb, interval*2, (void *)manager);
534                 fprintf(stderr, "set_velocity_updated_cb: %d\n", ret);
535                 */
536
537                 ret = location_manager_set_location_changed_cb(manager, _location_changed_cb, interval * 2, (void *)manager);
538                 fprintf(stderr, "set_location_changed_cb: %d\n", ret);
539
540                 ret = location_manager_start(manager);
541                 fprintf(stderr, "start: %d\n", ret);
542                 break;
543                 }
544         case 21:
545         case 22:
546         case 23: {
547                 int interval = 1;
548                 int method = menu - 21;
549
550                 fprintf(stderr, "\n     Input position interval ==> ");
551                 ret = scanf("%d", &interval);
552
553                 ret = location_manager_create(method, &manager);
554                 fprintf(stderr, "location_manager_create (method : %d)", method);
555
556                 /*ret = location_manager_set_position_updated_cb(manager, _position_updated_cb, interval, (void *)manager); */
557                 /*fprintf(stderr, "set position changed callback: %d\n", ret); */
558
559                 ret = location_manager_set_distance_based_location_changed_cb(manager, _location_changed_cb, interval, 30, (void *)manager);
560                 fprintf(stderr, "set_distance_based_location_changed_cb: %d\n", ret);
561
562                 ret = location_manager_start(manager);
563                 fprintf(stderr, "start: %d\n", ret);
564                 break;
565                 }
566         case 31: {
567                 int interval = 1;
568                 fprintf(stderr, "\n     Input batch interval ==> ");
569                 ret = scanf("%d", &interval);
570
571                 int period = 60;
572                 fprintf(stderr, "       Input batch period ==> ");
573                 ret = scanf("%d", &period);
574
575                 ret = location_manager_create(LOCATIONS_METHOD_GPS, &manager);
576                 fprintf(stderr, "location_manager_create (method : %d)\n", LOCATIONS_METHOD_GPS);
577
578                 ret = location_manager_set_location_batch_cb(manager, _location_batch_cb, interval, period, (void *)manager);
579                 fprintf(stderr, "set_location_batch_cb: %d\n", ret);
580
581                 ret = location_manager_start_batch(manager);
582                 fprintf(stderr, "start_batch: %d\n", ret);
583                 break;
584                 }
585         case 41: {
586                 basic = 1;
587                 int onoff = 1;
588
589                 fprintf(stderr, "\n     Mock Location (ON: 1 or OFF: 0) Input ==> ");
590                 ret = scanf("%d", &onoff);
591
592                 ret = location_manager_enable_mock_location(onoff);
593                 fprintf(stderr, "Enabling mock test: ret=%d\n", ret);
594
595                 ret = location_manager_create(LOCATIONS_METHOD_MOCK, &manager);
596                 fprintf(stderr, "location_manager_create (method: %d): %d\n", LOCATIONS_METHOD_MOCK, ret);
597
598                 ret = location_manager_set_mock_location(manager, 10, 20, 0, 40, 50, 100);
599                 fprintf(stderr, "location_manager_set_mock_location: %d\n", ret);
600                 if (ret == LOCATIONS_ERROR_SETTING_OFF) {
601                         fprintf(stderr, "Setting for Mock Location is turned OFF!!!\n");
602                         break;
603                 }
604
605                 ret = location_manager_start(manager);
606                 fprintf(stderr, "start: %d\n", ret);
607
608                 g_timeout_add_seconds(3, test_clear_mock_location, manager);
609                 g_timeout_add_seconds(10, wait_test, NULL);
610
611                 break;
612                 }
613         case 42: {
614                 basic = 1;
615
616                 ret = location_manager_create(LOCATIONS_METHOD_HYBRID, &manager);
617                 fprintf(stderr, "location_manager_create (method: %d): %d\n", LOCATIONS_METHOD_HYBRID, ret);
618
619                 ret = location_manager_start(manager);
620                 fprintf(stderr, "start: %d\n", ret);
621
622                 /*
623                 int state = 0;
624                 ret = location_manager_get_service_state(manager, &state);
625                 fprintf(stderr, "the current state: %d, ret = %d\n", state, ret);
626                 */
627
628                 g_timeout_add_seconds(5, test_set_mock_location, manager);
629
630                 break;
631         }
632         case 51:
633         case 52:
634         case 53: {
635                 int method = menu - 51;
636                 int onoff = 1;
637
638                 fprintf(stderr, "\n     Input ON: 1 or OFF: 0 ==> ");
639                 ret = scanf("%d", &onoff);
640
641                 if (onoff == 0 || onoff == 1) {
642                         ret = enable_method(method, onoff);
643                         fprintf(stderr, "Enabling method: [%d], ret=%d\n", method, ret);
644                 }
645                 break;
646                 }
647         case 61: {
648                 location_bounds_h hPolyLocationBound = NULL;
649                 bool bIsContained = false;
650                 int nPolySize = 3;
651                 location_coords_s location_coord_list[nPolySize];
652                 location_coord_list[0].latitude = 10;
653                 location_coord_list[0].longitude = 10;
654                 location_coord_list[1].latitude = 20;
655                 location_coord_list[1].longitude = 20;
656                 location_coord_list[2].latitude = 30;
657                 location_coord_list[2].longitude = 10;
658
659                 /* Checking coordinates in location boundary */
660                 location_coords_s testLocationCoordinates;
661                 testLocationCoordinates.latitude = 20;
662                 testLocationCoordinates.longitude = 12;
663                 location_bound_error_e nRet = location_bounds_create_polygon(location_coord_list, nPolySize, &hPolyLocationBound);
664
665                 fprintf(stderr, "location_bounds_create_polygon: %d\n", nRet);
666
667                 bIsContained = location_bounds_contains_coordinates(hPolyLocationBound, testLocationCoordinates);
668                 fprintf(stderr, "bIsContained: %d\n", bIsContained);
669
670                 location_bounds_destroy(hPolyLocationBound);
671                 break;
672                 }
673         case 0:
674                 g_timeout_add_seconds(1, exit_program, NULL);
675                 return 0;
676         default:
677                 fprintf(stderr, "Exit!!! Input: %d\n", menu);
678                 g_timeout_add_seconds(1, exit_program, NULL);
679                 return 0;
680         }
681
682         if (ret != LOCATIONS_ERROR_NONE) {
683                 fprintf(stderr, "Test Failed!!! [%d]\n", ret);
684                 g_timeout_add_seconds(1, exit_program, NULL);
685                 return 0;
686         }
687
688         if (menu > 0 && menu < 50) {
689                 ret = location_manager_set_service_state_changed_cb(manager, _state_change_cb, (void *)manager);
690                 fprintf(stderr, "set_service_state_changed_cb: %d\n", ret);
691
692                 if (basic) {
693                         ret = location_manager_set_position_updated_cb(manager, _position_updated_cb, interval, (void *)manager);
694                         fprintf(stderr, "set_position_updated_cb: %d\n", ret);
695                 }
696         } else {
697                 test_timer = g_timeout_add_seconds(1, wait_test, NULL);
698         }
699
700         return 0;
701 }
702
703 static void location_cleanup()
704 {
705         int ret = 0;
706         if (manager != NULL) {
707                 ret = location_manager_stop(manager);
708                 fprintf(stderr, "stop: %d\n", ret);
709
710                 ret = location_manager_unset_service_state_changed_cb(manager);
711                 fprintf(stderr, "unset_service_state_changed_cb: %d\n", ret);
712
713                 ret = location_manager_unset_position_updated_cb(manager);
714                 fprintf(stderr, "unset_position_updated_cb: %d\n", ret);
715
716                 ret = gps_status_unset_satellite_updated_cb(manager);
717                 fprintf(stderr, "gps_status_unset_satellite_updated_cb: %d\n", ret);
718
719                 ret = location_manager_destroy(manager);
720                 fprintf(stderr, "destroy: %d\n", ret);
721                 manager = NULL;
722         }
723 }
724
725 int main(int argc, char **argv)
726 {
727         g_mainloop = g_main_loop_new(NULL, 0);
728         location_test();
729         g_main_loop_run(g_mainloop);
730         location_cleanup();
731         return 0;
732 }