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