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