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