75d69c7dcbd2550b87dfaf174b019bd2d6b46929
[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         repeat_count++;
375         if (repeat_count > 60)
376                 test_timer = g_timeout_add_seconds(1, wait_test, NULL);
377 }
378
379 static void print_location_status()
380 {
381         fprintf(stderr, "==== LOCATION Setting state =====\n");
382         bool is_enabled = FALSE;
383         location_manager_is_enabled_method(LOCATIONS_METHOD_HYBRID, &is_enabled);
384         fprintf(stderr, "hybrid: %d, ", is_enabled);
385
386         location_manager_is_enabled_method(LOCATIONS_METHOD_GPS, &is_enabled);
387         fprintf(stderr, "gps: %d, ", is_enabled);
388
389         location_manager_is_enabled_method(LOCATIONS_METHOD_WPS, &is_enabled);
390         fprintf(stderr, "wps: %d, ", is_enabled);
391 }
392
393 static int enable_method(location_method_e method, bool enable)
394 {
395         int ret = 0;
396         fprintf(stderr, "==== LOCATION Setting changed =====\n");
397
398         location_manager_set_setting_changed_cb(LOCATIONS_METHOD_HYBRID, _setting_cb, NULL);
399
400         fprintf(stderr, "method[%d], enable[%d]\n", method, enable);
401         ret = location_manager_enable_method(method, enable);
402
403         location_manager_unset_setting_changed_cb(LOCATIONS_METHOD_HYBRID);
404         return ret;
405 }
406
407 static int test_clear_mock_location(gpointer user_data)
408 {
409         location_manager_h manager = (location_manager_h) user_data;
410         int ret = 0;
411
412         ret = location_manager_clear_mock_location(manager);
413         fprintf(stderr, "\n==== location_manager_clear_mock_location: %d ====\n\n", ret);
414
415         /*
416         int state = 0;
417         ret = location_manager_get_service_state(manager, &state);
418         fprintf(stderr, "the current state: %d, ret = %d\n", state, ret);
419         */
420
421         return FALSE;
422 }
423
424
425 static int test_set_mock_location(gpointer user_data)
426 {
427         location_manager_h manager = (location_manager_h) user_data;
428         int ret = 0;
429
430         /*
431         int state = 0;
432         ret = location_manager_get_service_state(manager, &state);
433         fprintf(stderr, "the current state: %d, ret = %d\n", state, ret);
434         */
435
436         ret = location_manager_set_mock_location(manager, 20, 20, 0, 40, 50, 100);
437         fprintf(stderr, "\n==== location_manager_set_location: %d ====\n\n", ret);
438         if (ret != LOCATIONS_ERROR_NONE)
439                 g_timeout_add_seconds(3, test_clear_mock_location, manager);
440
441         return FALSE;
442 }
443
444 static void print_menu()
445 {
446         fprintf(stderr, "============= LOCATION TEST =============\n");
447         fprintf(stderr, "[1] Get location: LOCATIONS_METHOD_HYBRID\n");
448         fprintf(stderr, "[2] Get location: LOCATIONS_METHOD_GPS\n");
449         fprintf(stderr, "[3] Get location: LOCATIONS_METHOD_WPS\n");
450         fprintf(stderr, "[4] Single location: LOCATIONS_METHOD_HYBRID\n");
451         fprintf(stderr, "[5] Single location: LOCATIONS_METHOD_GPS\n");
452         fprintf(stderr, "[6] Single location: LOCATIONS_METHOD_WPS\n\n");
453         fprintf(stderr, "[11] Change update interval: LOCATIONS_METHOD_HYBRID\n");
454         fprintf(stderr, "[12] Change update interval: LOCATIONS_METHOD_GPS\n\n");
455         fprintf(stderr, "[21] Distance based location update: LOCATIONS_METHOD_HYBRID\n");
456         fprintf(stderr, "[22] Distance based location update: LOCATIONS_METHOD_GPS\n");
457         fprintf(stderr, "[23] Distance based location update: LOCATIONS_METHOD_WPS\n\n");
458         fprintf(stderr, "[31] Location batch update: LOCATIONS_METHOD_GPS\n\n");
459         fprintf(stderr, "[41] Turn on/off mock test: LOCATIONS_METHOD_MOCK\n");
460         fprintf(stderr, "[42] Set & Clear location: LOCATIONS_METHOD_HYBRID\n\n");
461         fprintf(stderr, "[51] Turn on/off method: LOCATIONS_METHOD_HYBRID\n");
462         fprintf(stderr, "[52] Turn on/off method: LOCATIONS_METHOD_GPS\n");
463         fprintf(stderr, "[53] Turn on/off method: LOCATIONS_METHOD_WPS\n\n");
464         fprintf(stderr, "[61] Boundary Test\n\n");
465         fprintf(stderr, "[0] Exit!!!\n\n");
466         fprintf(stderr, "Select menu: ");
467
468         if (scanf("%d", &menu) < 0)
469                 fprintf(stderr, "Can't read menu !!!\n");
470 }
471
472 static int location_test()
473 {
474         int ret = LOCATIONS_ERROR_NONE;
475         int basic = 0;
476         int interval = 1;
477         repeat_count = 0;
478
479         print_location_status();
480         print_menu();
481
482         switch (menu) {
483         case 1:
484         case 2:
485         case 3: {
486                 basic = 1;
487
488                 int method = menu - 1;
489                 ret = location_manager_create(method, &manager);
490                 fprintf(stderr, "location_manager_create (method: %d): %d\n", method, ret);
491
492                 ret = location_manager_start(manager);
493                 fprintf(stderr, "start: %d\n", ret);
494
495                 if (method == LOCATIONS_METHOD_GPS) {
496                         ret = gps_status_set_satellite_updated_cb(manager, _satellite_updated_cb, 1, &manager);
497                         fprintf(stderr, "gps_status_set_satellite_updated_cb: %d\n", ret);
498                 }
499                 break;
500         }
501         case 4:
502         case 5:
503         case 6: {
504                 int timeout = 60;
505
506                 fprintf(stderr, "\n     Input timeout ==> ");
507                 ret = scanf("%d", &timeout);
508
509                 int method = menu - 4;
510                 ret = location_manager_create(method, &manager);
511                 ret = location_manager_request_single_location(manager, timeout, _location_cb, manager);
512                 fprintf(stderr, "request single_location (method: %d): %d\n", method, ret);
513                 break;
514         }
515         case 11:
516         case 12:
517         case 13: {
518                 int interval = 1;
519
520                 fprintf(stderr, "\n     Input position interval ==> ");
521                 ret = scanf("%d", &interval);
522
523                 int method = menu - 11;
524                 ret = location_manager_create(method, &manager);
525                 fprintf(stderr, "location_manager_create (method: %d): %d\n", method, ret);
526
527                 ret = location_manager_set_position_updated_cb(manager, _position_updated_cb, interval, (void *)manager);
528                 fprintf(stderr, "set_position_updated_cb: %d\n", ret);
529
530                 /*
531                 ret = location_manager_set_velocity_updated_cb(manager, _velocity_updated_cb, interval*2, (void *)manager);
532                 fprintf(stderr, "set_velocity_updated_cb: %d\n", ret);
533                 */
534
535                 ret = location_manager_set_location_changed_cb(manager, _location_changed_cb, interval * 2, (void *)manager);
536                 fprintf(stderr, "set_location_changed_cb: %d\n", ret);
537
538                 ret = location_manager_start(manager);
539                 fprintf(stderr, "start: %d\n", ret);
540                 break;
541                 }
542         case 21:
543         case 22:
544         case 23: {
545                 int interval = 1;
546                 int method = menu - 21;
547
548                 fprintf(stderr, "\n     Input position interval ==> ");
549                 ret = scanf("%d", &interval);
550
551                 ret = location_manager_create(method, &manager);
552                 fprintf(stderr, "location_manager_create (method : %d)", method);
553
554                 /*ret = location_manager_set_position_updated_cb(manager, _position_updated_cb, interval, (void *)manager); */
555                 /*fprintf(stderr, "set position changed callback: %d\n", ret); */
556
557                 ret = location_manager_set_distance_based_location_changed_cb(manager, _location_changed_cb, interval, 30, (void *)manager);
558                 fprintf(stderr, "set_distance_based_location_changed_cb: %d\n", ret);
559
560                 ret = location_manager_start(manager);
561                 fprintf(stderr, "start: %d\n", ret);
562                 break;
563                 }
564         case 31: {
565                 int interval = 1;
566                 fprintf(stderr, "\n     Input batch interval ==> ");
567                 ret = scanf("%d", &interval);
568
569                 int period = 60;
570                 fprintf(stderr, "       Input batch period ==> ");
571                 ret = scanf("%d", &period);
572
573                 ret = location_manager_create(LOCATIONS_METHOD_GPS, &manager);
574                 fprintf(stderr, "location_manager_create (method : %d)\n", LOCATIONS_METHOD_GPS);
575
576                 ret = location_manager_set_location_batch_cb(manager, _location_batch_cb, interval, period, (void *)manager);
577                 fprintf(stderr, "set_location_batch_cb: %d\n", ret);
578
579                 ret = location_manager_start_batch(manager);
580                 fprintf(stderr, "start_batch: %d\n", ret);
581                 break;
582                 }
583         case 41: {
584                 basic = 1;
585                 int onoff = 1;
586
587                 fprintf(stderr, "\n     Mock Location (ON: 1 or OFF: 0) Input ==> ");
588                 ret = scanf("%d", &onoff);
589
590                 ret = location_manager_enable_mock_location(onoff);
591                 fprintf(stderr, "Enabling mock test: ret=%d\n", ret);
592
593                 ret = location_manager_create(LOCATIONS_METHOD_GPS, &manager);
594                 fprintf(stderr, "location_manager_create (method: %d - mock): %d\n", LOCATIONS_METHOD_GPS, ret);
595
596                 ret = location_manager_set_mock_location(manager, 10, 20, 0, 40, 50, 100);
597                 fprintf(stderr, "location_manager_set_mock_location: %d\n", ret);
598                 if (ret == LOCATIONS_ERROR_SETTING_OFF) {
599                         fprintf(stderr, "Setting for Mock Location is turned OFF!!!\n");
600                         break;
601                 }
602
603                 ret = location_manager_start(manager);
604                 fprintf(stderr, "start: %d\n", ret);
605
606                 g_timeout_add_seconds(3, test_clear_mock_location, manager);
607                 g_timeout_add_seconds(10, wait_test, NULL);
608
609                 break;
610                 }
611         case 42: {
612                 basic = 1;
613
614                 ret = location_manager_create(LOCATIONS_METHOD_HYBRID, &manager);
615                 fprintf(stderr, "location_manager_create (method: %d): %d\n", LOCATIONS_METHOD_HYBRID, ret);
616
617                 ret = location_manager_start(manager);
618                 fprintf(stderr, "start: %d\n", ret);
619
620                 /*
621                 int state = 0;
622                 ret = location_manager_get_service_state(manager, &state);
623                 fprintf(stderr, "the current state: %d, ret = %d\n", state, ret);
624                 */
625
626                 g_timeout_add_seconds(5, test_set_mock_location, manager);
627
628                 break;
629         }
630         case 51:
631         case 52:
632         case 53: {
633                 int method = menu - 51;
634                 int onoff = 1;
635
636                 fprintf(stderr, "\n     Input ON: 1 or OFF: 0 ==> ");
637                 ret = scanf("%d", &onoff);
638
639                 if (onoff == 0 || onoff == 1) {
640                         ret = enable_method(method, onoff);
641                         fprintf(stderr, "Enabling method: [%d], ret=%d\n", method, ret);
642                 }
643                 break;
644                 }
645         case 61: {
646                 location_bounds_h hPolyLocationBound = NULL;
647                 bool bIsContained = false;
648                 int nPolySize = 3;
649                 location_coords_s location_coord_list[nPolySize];
650                 location_coord_list[0].latitude = 10;
651                 location_coord_list[0].longitude = 10;
652                 location_coord_list[1].latitude = 20;
653                 location_coord_list[1].longitude = 20;
654                 location_coord_list[2].latitude = 30;
655                 location_coord_list[2].longitude = 10;
656
657                 /* Checking coordinates in location boundary */
658                 location_coords_s testLocationCoordinates;
659                 testLocationCoordinates.latitude = 20;
660                 testLocationCoordinates.longitude = 12;
661                 location_bound_error_e nRet = location_bounds_create_polygon(location_coord_list, nPolySize, &hPolyLocationBound);
662
663                 fprintf(stderr, "location_bounds_create_polygon: %d\n", nRet);
664
665                 bIsContained = location_bounds_contains_coordinates(hPolyLocationBound, testLocationCoordinates);
666                 fprintf(stderr, "bIsContained: %d\n", bIsContained);
667
668                 location_bounds_destroy(hPolyLocationBound);
669                 break;
670                 }
671         case 0:
672                 g_timeout_add_seconds(1, exit_program, NULL);
673                 return 0;
674         default:
675                 fprintf(stderr, "Exit!!! Input: %d\n", menu);
676                 g_timeout_add_seconds(1, exit_program, NULL);
677                 return 0;
678         }
679
680         if (ret != LOCATIONS_ERROR_NONE) {
681                 fprintf(stderr, "Test Failed!!! [%d]\n", ret);
682                 g_timeout_add_seconds(1, exit_program, NULL);
683                 return 0;
684         }
685
686         if (menu > 0 && menu < 50) {
687                 ret = location_manager_set_service_state_changed_cb(manager, _state_change_cb, (void *)manager);
688                 fprintf(stderr, "set_service_state_changed_cb: %d\n", ret);
689
690                 if (basic) {
691                         ret = location_manager_set_position_updated_cb(manager, _position_updated_cb, interval, (void *)manager);
692                         fprintf(stderr, "set_position_updated_cb: %d\n", ret);
693                 }
694         } else {
695                 test_timer = g_timeout_add_seconds(1, wait_test, NULL);
696         }
697
698         return 0;
699 }
700
701 static void location_cleanup()
702 {
703         int ret = 0;
704         if (manager != NULL) {
705                 ret = location_manager_stop(manager);
706                 fprintf(stderr, "stop: %d\n", ret);
707
708                 ret = location_manager_unset_service_state_changed_cb(manager);
709                 fprintf(stderr, "unset_service_state_changed_cb: %d\n", ret);
710
711                 ret = location_manager_unset_position_updated_cb(manager);
712                 fprintf(stderr, "unset_position_updated_cb: %d\n", ret);
713
714                 ret = gps_status_unset_satellite_updated_cb(manager);
715                 fprintf(stderr, "gps_status_unset_satellite_updated_cb: %d\n", ret);
716
717                 ret = location_manager_destroy(manager);
718                 fprintf(stderr, "destroy: %d\n", ret);
719                 manager = NULL;
720         }
721 }
722
723 int main(int argc, char **argv)
724 {
725         g_mainloop = g_main_loop_new(NULL, 0);
726         location_test();
727         g_main_loop_run(g_mainloop);
728         location_cleanup();
729         return 0;
730 }