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