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