Sync with 2.4
[platform/core/api/location-manager.git] / test / location_test.c
old mode 100644 (file)
new mode 100755 (executable)
index 841e1a5..bed24cb
@@ -1,18 +1,18 @@
 /*
-* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <glib.h>
 #include <locations.h>
 #include <location_bounds.h>
+#include <location_batch.h>
 
-location_manager_h manager;
+static location_manager_h manager;
+static GMainLoop *g_mainloop = NULL;
+static int menu;
+
+static int repeat_count;
+static void location_cleanup();
+static int location_test();
+static guint test_timer;
+
+static gboolean exit_program(gpointer data)
+{
+       g_main_loop_quit(g_mainloop);
+
+       return FALSE;
+}
+
+static gboolean wait_test()
+{
+       if (test_timer) {
+               g_source_remove(test_timer);
+               test_timer = 0;
+       }
+
+       location_cleanup();
+       location_test();
+
+       return FALSE;
+}
 
+#if 0
 void zone_event_cb(location_boundary_state_e state, double latitude, double longitude, double altitude, time_t timestamp,
-                  void *user_data)
+                   void *user_data)
 {
        if (state == LOCATIONS_BOUNDARY_IN) {
                printf("Entering zone\n");
-       } else                  // state == LOCATIONS_BOUNDARY_OUT
-       {
+       } else {                /* state == LOCATIONS_BOUNDARY_OUT */
                printf("Leaving zone\n");
        }
 
@@ -38,76 +66,17 @@ void zone_event_cb(location_boundary_state_e state, double latitude, double long
        printf("Time: %s\n", ctime(&timestamp));
 }
 
-static bool satellites_foreach_cb(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr, bool is_in_use,
-                                 void *user_data)
-{
-       printf("[Satellite information]  azimuth  : %d, elevation : %d, prn :%d, snr : %d, used: %d\n", azimuth, elevation, prn,
-              snr, is_in_use);
-       return true;
-}
-
 static bool last_satellites_foreach_cb(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr, bool is_in_use,
-                                      void *user_data)
+                                       void *user_data)
 {
-       printf("[Last Satellite information]  azimuth  : %d, elevation : %d, prn :%d, snr : %d, used: %d\n", azimuth, elevation,
+       printf("[Last Satellite information]    azimuth : %d, elevation: %d, prn: %d, snr: %d, used: %d\n", azimuth, elevation,
               prn, snr, is_in_use);
        return true;
 }
 
-static void _state_change_cb(location_service_state_e state, void *user_data)
-{
-       fprintf(stderr, "--------------------------state change %d---------\n", state);
-       location_manager_h lm = (location_manager_h) user_data;
-       if (state == LOCATIONS_SERVICE_ENABLED) {
-               int ret;
-               double altitude;
-               double latitude;
-               double longitude;
-               time_t timestamp;
-               ret = location_manager_get_position(lm, &altitude, &latitude, &longitude, &timestamp);
-               if (ret != LOCATIONS_ERROR_NONE) {
-                       printf(" Fail : location_manager_get_position ---> %d \n", ret);
-               } else {
-                       printf("[%ld] alt: %g, lat %g, long %g\n", timestamp, altitude, latitude, longitude);
-               }
-
-               location_accuracy_level_e level;
-               double horizontal;
-               double vertical;
-               ret = location_manager_get_accuracy(lm, &level, &horizontal, &vertical);
-               if (ret != LOCATIONS_ERROR_NONE) {
-                       printf(" Fail : location_manager_get_accuracy ---> %d \n", ret);
-               } else {
-                       printf("Level : %d, horizontal: %g, vertical %g\n", level, horizontal, vertical);
-               }
-
-               char *nmea;
-               ret = gps_status_get_nmea(lm, &nmea);
-               if (ret != LOCATIONS_ERROR_NONE) {
-                       printf(" Fail : gps_status_get_nmea ---> %d \n", ret);
-               } else {
-                       printf("NMEA : %s\n", nmea);
-                       free(nmea);
-               }
-
-               int num_of_view, num_of_active;
-               ret = gps_status_get_satellite(lm, &num_of_active, &num_of_view, &timestamp);
-               if (ret != LOCATIONS_ERROR_NONE) {
-                       printf(" Fail : gps_status_get_satellite_count_in_view ---> %d \n", ret);
-               } else {
-                       printf("[%ld] Satellite number of active : %d, in view : %d\n", timestamp, num_of_active, num_of_view);
-               }
-
-               ret = gps_status_foreach_satellites_in_view(lm, satellites_foreach_cb, user_data);
-               if (ret != LOCATIONS_ERROR_NONE) {
-                       printf(" Fail : gps_status_foreach_satellites_in_view ---> %d \n", ret);
-               }
-       }
-}
-
 static bool __poly_coords_cb(location_coords_s coords, void *user_data)
 {
-       printf("location_bounds_foreach_rect_coords(latitude : %lf, longitude: %lf) \n", coords.latitude, coords.longitude);
+       printf("location_bounds_foreach_rect_coords(latitude: %lf, longitude: %lf) \n", coords.latitude, coords.longitude);
        return TRUE;
 }
 
@@ -122,14 +91,14 @@ static bool __location_bounds_cb(location_bounds_h bounds, void *user_data)
                        location_coords_s center;
                        double radius;
                        location_bounds_get_circle_coords(bounds, &center, &radius);
-                       printf("location_bounds_get_circle_coords(center : %lf, %lf, radius : %lf) \n", center.latitude,
+                       printf("location_bounds_get_circle_coords(center: %lf, %lf, radius: %lf) \n", center.latitude,
                               center.longitude, radius);
 
                } else if (type == LOCATION_BOUNDS_RECT) {
                        location_coords_s left_top;
                        location_coords_s right_bottom;
                        location_bounds_get_rect_coords(bounds, &left_top, &right_bottom);
-                       printf("location_bounds_get_rect_coords(left_top : %lf, %lf - right_bottom : %lf, %lf) \n",
+                       printf("location_bounds_get_rect_coords(left_top: %lf, %lf - right_bottom: %lf, %lf) \n",
                               left_top.latitude, left_top.longitude, right_bottom.latitude, right_bottom.longitude);
                } else if (type == LOCATION_BOUNDS_POLYGON) {
                        location_bounds_foreach_polygon_coords(bounds, __poly_coords_cb, NULL);
@@ -164,10 +133,10 @@ void location_bounds_test()
        if (ret != LOCATIONS_ERROR_NONE) {
                printf("location_bounds_get_circle_coords() failed\n");
        } else
-               printf("location_bounds_get_circle_coords(center : %lf, %lf, radius : %lf) \n", center2.latitude,
+               printf("location_bounds_get_circle_coords(center: %lf, %lf, radius: %lf) \n", center2.latitude,
                       center2.longitude, radius2);
 
-       //Add the rect bounds
+       /*Add the rect bounds */
        location_coords_s left_top;
        left_top.latitude = 30;
        left_top.longitude = 30;
@@ -196,10 +165,10 @@ void location_bounds_test()
        if (ret != LOCATIONS_ERROR_NONE) {
                printf("location_bounds_get_rect_coords() failed\n");
        } else
-               printf("location_bounds_get_rect_coords(left_top : %lf, %lf - right_bottom : %lf, %lf) \n", left_top2.latitude,
+               printf("location_bounds_get_rect_coords(left_top: %lf, %lf - right_bottom: %lf, %lf) \n", left_top2.latitude,
                       left_top2.longitude, right_bottom2.latitude, right_bottom2.longitude);
 
-       //Add the polygon bounds
+       /*Add the polygon bounds */
 
        int poly_size = 3;
        location_coords_s coord_list[poly_size];
@@ -238,7 +207,7 @@ void location_bounds_test()
        else
                printf("location_bounds_contains_coordinates() retrun FALSE \n");
 
-       //print current bounds
+       /*print current bounds */
        ret = location_manager_foreach_boundary(manager, __location_bounds_cb, (void *)manager);
        if (ret != LOCATIONS_ERROR_NONE) {
                printf("location_manager_foreach_boundary() failed\n");
@@ -258,82 +227,403 @@ void location_get_last_information_test()
 
        ret = location_manager_get_last_position(manager, &altitude, &latitude, &longitude, &timestamp);
        if (ret != LOCATIONS_ERROR_NONE) {
-               printf(" Fail : location_manager_get_last_position ---> %d \n", ret);
+               printf(" Fail: location_manager_get_last_position ---> %d \n", ret);
        } else {
                printf("[%ld] alt: %g, lat: %g, long: %g\n", timestamp, altitude, latitude, longitude);
        }
 
        ret = location_manager_get_last_velocity(manager, &climb, &direction, &speed, &timestamp);
        if (ret != LOCATIONS_ERROR_NONE) {
-               printf(" Fail : location_manager_get_last_velocity ---> %d \n", ret);
+               printf(" Fail: location_manager_get_last_velocity ---> %d \n", ret);
        } else {
                printf("climb: %f, direction: %f, speed: %f\n", climb, direction, speed);
        }
 
        ret = location_manager_get_last_accuracy(manager, &level, &horizontal, &vertical);
        if (ret != LOCATIONS_ERROR_NONE) {
-               printf(" Fail : location_manager_get_last_accuracy ---> %d \n", ret);
+               printf(" Fail: location_manager_get_last_accuracy ---> %d \n", ret);
        } else {
-               printf("Level : %d, horizontal: %g, vertical : %g\n", level, horizontal, vertical);
+               printf("Level: %d, horizontal: %g, vertical: %g\n", level, horizontal, vertical);
        }
 
        ret = gps_status_get_last_satellite(manager, &num_of_active, &num_of_inview, &timestamp);
        if (ret != LOCATIONS_ERROR_NONE) {
-               printf(" Fail : gps_status_get_last_satellite_count_in_view ---> %d \n", ret);
+               printf(" Fail: gps_status_get_last_satellite_count_in_view ---> %d \n", ret);
        } else {
-               printf("[%ld] Satellite number of active : %d, in view : %d\n", timestamp, num_of_active, num_of_inview);
+               printf("[%ld] Satellite number of active: %d, in view: %d\n", timestamp, num_of_active, num_of_inview);
        }
 
        ret = gps_status_foreach_last_satellites_in_view(manager, last_satellites_foreach_cb, NULL);
        if (ret != LOCATIONS_ERROR_NONE) {
-               printf(" Fail : gps_status_foreach_last_satellites_in_view ---> %d \n", ret);
+               printf(" Fail: gps_status_foreach_last_satellites_in_view ---> %d \n", ret);
        }
 }
+#endif
 
-int location_test()
+static void _state_change_cb(location_service_state_e state, void *user_data)
 {
-       int ret;
-       ret = location_manager_create(LOCATIONS_METHOD_GPS, &manager);
-       printf("create : %d\n", ret);
+       fprintf(stderr, "--------------------------state change: %d---------\n", state);
+       location_manager_h lm = (location_manager_h) user_data;
+       if (state == LOCATIONS_SERVICE_ENABLED) {
+               int ret;
+               double altitude;
+               double latitude;
+               double longitude;
+               time_t timestamp;
+               ret = location_manager_get_position(lm, &altitude, &latitude, &longitude, &timestamp);
+               if (ret != LOCATIONS_ERROR_NONE) {
+                       printf(" Fail: location_manager_get_position ---> %d \n", ret);
+               } else {
+                       printf("[%ld] alt: %g, lat %g, long %g\n", timestamp, altitude, latitude, longitude);
+               }
 
-       location_bounds_test();
-       location_get_last_information_test();
+               location_accuracy_level_e level;
+               double horizontal;
+               double vertical;
+               ret = location_manager_get_accuracy(lm, &level, &horizontal, &vertical);
+               if (ret != LOCATIONS_ERROR_NONE) {
+                       printf(" Fail: location_manager_get_accuracy ---> %d \n", ret);
+               } else {
+                       printf("Level: %d, horizontal: %g, vertical %g\n", level, horizontal, vertical);
+               }
+#if 0
+               char *nmea;
+               ret = gps_status_get_nmea(lm, &nmea);
+               if (ret != LOCATIONS_ERROR_NONE) {
+                       printf(" Fail: gps_status_get_nmea ---> %d \n", ret);
+               } else {
+                       printf("NMEA: %s\n", nmea);
+                       free(nmea);
+               }
+#endif
+       }
+
+}
 
-       //set zone changed callback
-       ret = location_manager_set_zone_changed_cb(manager, zone_event_cb, (void *)manager);
-       printf("set zone callback : %d\n", ret);
+void _position_updated_cb(double latitude, double longitude, double altitude, time_t timestamp, void *user_data)
+{
+       fprintf(stderr, "-------------------------- position updated --------------------------\n");
+       printf("[%ld] lat[%f] lon[%f] alt[%f]\n", timestamp, latitude, longitude, altitude);
 
-       ret = location_manager_set_service_state_changed_cb(manager, _state_change_cb, (void *)manager);
-       printf("set state callback : %d\n", ret);
+       repeat_count++;
 
-       ret = location_manager_start(manager);
-       printf("start :  %d\n", ret);
-       return 1;
+       if (repeat_count > 2) {
+               test_timer = g_timeout_add_seconds(1, wait_test, NULL);
+       }
 }
 
-static GMainLoop *g_mainloop = NULL;
+void _velocity_updated_cb(double speed, double direction, double climb, time_t timestamp, void *user_data)
+{
+       fprintf(stderr, "-------------------------- velocity updated --------------------------\n");
+       printf("[%ld] speed[%f] direction[%f] climb[%f]\n", timestamp, speed, direction, climb);
+}
 
-static gboolean exit_program(gpointer data)
+void _location_cb(int error, double latitude, double longitude, double altitude, time_t timestamp, double speed, double climb, double direction, void *user_data)
 {
-       if (manager == NULL) {
-               printf("manager == NULL \n");
-       } else {
-               int ret = location_manager_stop(manager);
-               printf("stop :  %d\n", ret);
+       printf("error[%d]\n", error);
+       printf("location_cb: lat[%f] lon[%f] alt[%f]\n", latitude, longitude, altitude);
+       printf("speed[%f] climb[%f] direction[%f]\n", speed, climb, direction);
+
+       test_timer = g_timeout_add_seconds(1, wait_test, NULL);
+}
+
+void _location_changed_cb(double latitude, double longitude, double altitude, double speed, double direction, double horizontal_accuracy, time_t timestamp, void *user_data)
+{
+       fprintf(stderr, "-------------------------- location changed --------------------------\n");
+       printf("[%ld] lat[%f] lon[%f] alt[%f] speed[%lf] direction[%lf], horizontal_accuracy[%lf]\n", timestamp, latitude, longitude, altitude, speed, direction, horizontal_accuracy);
+
+       repeat_count++;
+
+       if (repeat_count > 2) {
+               test_timer = g_timeout_add_seconds(1, wait_test, NULL);
+       }
+}
+
+bool _get_location_cb(double latitude, double longitude, double altitude, double speed, double direction, double horizontal, double vertical, time_t timestamp, void *user_data)
+{
+       fprintf(stderr, "-------------------------- batch: get location --------------------------\n");
+       printf("[%ld] lat[%f] lon[%f] alt[%f] speed[%lf] direction[%lf], horizontal_accuracy[%lf]\n", timestamp, latitude, longitude, altitude, speed, direction, horizontal);
+       return TRUE;
+}
+
+void _location_batch_cb(int num_of_location, void *user_data)
+{
+       fprintf(stderr, "-------------------------- location batch --------------------------\n");
+       printf("num_of_location: [%d]\n", num_of_location);
+
+       location_manager_h manager = user_data;
+
+       if (num_of_location > 0) {
+               location_manager_foreach_location_batch(manager, _get_location_cb, user_data);
+       }
+       repeat_count++;
+
+       if (repeat_count > 1) {
+               test_timer = g_timeout_add_seconds(1, wait_test, NULL);
+       }
+}
+
+static void __setting_cb(location_method_e method, bool enable, void *user_data)
+{
+       printf("method[%d], enable[%d]\n", method, enable);
+}
+
+static void print_location_status()
+{
+       printf("==== LOCATION Setting state =====\n");
+       bool is_enabled = FALSE;
+       location_manager_is_enabled_method(LOCATIONS_METHOD_HYBRID, &is_enabled);
+       printf("hybrid: %d, ", is_enabled);
+
+       location_manager_is_enabled_method(LOCATIONS_METHOD_GPS, &is_enabled);
+       printf("gps: %d, ", is_enabled);
+
+       location_manager_is_enabled_method(LOCATIONS_METHOD_WPS, &is_enabled);
+       printf("wps: %d\n", is_enabled);
+}
+
+static int enable_method(location_method_e method, bool enable)
+{
+       int ret = 0;
+       printf("==== LOCATION Setting changed =====\n");
+
+       location_manager_set_setting_changed_cb(LOCATIONS_METHOD_HYBRID, __setting_cb, NULL);
+
+       printf("method[%d], enable[%d]\n", method, enable);
+       ret = location_manager_enable_method(method, enable);
+
+       location_manager_unset_setting_changed_cb(LOCATIONS_METHOD_HYBRID);
+       return ret;
+}
+
+static void print_menu()
+{
+       printf("============= LOCATION TEST =============\n");
+       printf("[1] Get location: LOCATIONS_METHOD_HYBRID\n");
+       printf("[2] Get location: LOCATIONS_METHOD_GPS\n");
+       printf("[3] Get location: LOCATIONS_METHOD_WPS\n");
+       printf("[4] Single location: LOCATIONS_METHOD_HYBRID\n");
+       printf("[5] Single location: LOCATIONS_METHOD_GPS\n");
+       printf("[6] Single location: LOCATIONS_METHOD_WPS\n\n");
+       printf("[11] Change update interval: LOCATIONS_METHOD_HYBRID\n");
+       printf("[12] Change update interval: LOCATIONS_METHOD_GPS\n\n");
+       printf("[21] Distance based location update: LOCATIONS_METHOD_HYBRID\n");
+       printf("[22] Distance based location update: LOCATIONS_METHOD_GPS\n");
+       printf("[23] Distance based location update: LOCATIONS_METHOD_WPS\n\n");
+       printf("[31] Location batch update: LOCATIONS_METHOD_GPS\n\n");
+       printf("[41] Turn on/off method: LOCATIONS_METHOD_HYBRID\n");
+       printf("[42] Turn on/off method: LOCATIONS_METHOD_GPS\n");
+       printf("[43] Turn on/off method: LOCATIONS_METHOD_WPS\n\n");
+       printf("[51] Boundary Test\n\n");
+       printf("[0] Exit!!!\n\n");
+       printf("Select menu: ");
+
+       if (scanf("%d", &menu) < 0) {
+               printf("Can't read menu !!!\n");
+       }
+}
+
+static int location_test()
+{
+       int ret = LOCATIONS_ERROR_NONE;
+       int basic = 0;
+       int interval = 1;
+       repeat_count = 0;
+
+       print_location_status();
+       print_menu();
+
+       switch (menu) {
+               case 1:
+               case 2:
+               case 3: {
+                       basic = 1;
+
+                       int method = menu - 1;
+                       ret = location_manager_create(method, &manager);
+                       printf("location_manager_create (method: %d): %d\n", method, ret);
+                       ret = location_manager_start(manager);
+                       printf("start: %d\n", ret);
+                       }
+                       break;
+               case 4:
+               case 5:
+               case 6: {
+                       int timeout = 30;
+
+                       printf("\n      Input timeout ==> ");
+                       ret = scanf("%d", &timeout);
+
+                       int method = menu - 4;
+                       ret = location_manager_create(method, &manager);
+                       ret = location_manager_request_single_location(manager, timeout, _location_cb, manager);
+                       printf("request single_location (method: %d): %d\n", method, ret);
+                       break;
+                       }
+               case 11:
+               case 12:
+               case 13: {
+                       int interval = 1;
+
+                       printf("\n      Input position interval ==> ");
+                       ret = scanf("%d", &interval);
+
+                       int method = menu - 11;
+                       ret = location_manager_create(method, &manager);
+                       printf("location_manager_create (method: %d): %d\n", method, ret);
+
+                       ret = location_manager_set_position_updated_cb(manager, _position_updated_cb, interval, (void *)manager);
+                       printf("set_position_updated_cb: %d\n", ret);
+
+                       /*
+                       ret = location_manager_set_velocity_updated_cb(manager, _velocity_updated_cb, interval*2, (void *)manager);
+                       printf("set_velocity_updated_cb: %d\n", ret);
+                       */
+
+                       ret = location_manager_set_location_changed_cb(manager, _location_changed_cb, interval * 2, (void *)manager);
+                       printf("set_location_changed_cb: %d\n", ret);
+
+                       ret = location_manager_start(manager);
+                       printf("start: %d\n", ret);
+                       break;
+                       }
+               case 21:
+               case 22:
+               case 23: {
+                       int interval = 1;
+                       int method = menu - 21;
+
+                       printf("\n      Input position interval ==> ");
+                       ret = scanf("%d", &interval);
+
+                       ret = location_manager_create(method, &manager);
+                       printf("location_manager_create (method : %d)", method);
+
+                       /*ret = location_manager_set_position_updated_cb(manager, _position_updated_cb, interval, (void *)manager); */
+                       /*printf("set position changed callback: %d\n", ret); */
+
+                       ret = location_manager_set_distance_based_location_changed_cb(manager, _location_changed_cb, interval, 30, (void *)manager);
+                       printf("set_distance_based_location_changed_cb: %d\n", ret);
+
+                       ret = location_manager_start(manager);
+                       printf("start: %d\n", ret);
+                       break;
+                       }
+               case 31: {
+                       int interval = 1;
+                       printf("\n      Input batch interval ==> ");
+                       ret = scanf("%d", &interval);
+
+                       int period = 60;
+                       printf("        Input batch period ==> ");
+                       ret = scanf("%d", &period);
+
+
+                       ret = location_manager_create(LOCATIONS_METHOD_GPS, &manager);
+                       printf("location_manager_create (method : %d)\n", LOCATIONS_METHOD_GPS);
+
+                       ret = location_manager_set_location_batch_cb(manager, _location_batch_cb, interval, period, (void *)manager);
+                       printf("set_location_batch_cb: %d\n", ret);
+
+                       ret = location_manager_start_batch(manager);
+                       printf("start_batch: %d\n", ret);
+                       break;
+                       }
+               case 41:
+               case 42:
+               case 43: {
+                       int method = menu - 41;
+                       int onoff = 1;
+
+                       printf("\n      Input ON: 1 or OFF: 0 ==> ");
+                       ret = scanf("%d", &onoff);
+
+                       ret = enable_method(method, onoff);
+                       printf("Enabling method: [%d], ret=%d\n", method, ret);
+                       break;
+                       }
+
+               case 51: {
+                       location_bounds_h hPolyLocationBound = NULL;
+                       bool bIsContained = false;
+                       int nPolySize = 3;
+                       location_coords_s location_coord_list[nPolySize];
+                       location_coord_list[0].latitude = 10;
+                       location_coord_list[0].longitude = 10;
+                       location_coord_list[1].latitude = 20;
+                       location_coord_list[1].longitude = 20;
+                       location_coord_list[2].latitude = 30;
+                       location_coord_list[2].longitude = 10;
+
+                       //Checking coordinates in location boundary
+                       location_coords_s testLocationCoordinates;
+                       testLocationCoordinates.latitude = 20;
+                       testLocationCoordinates.longitude = 12;
+                       location_bound_error_e nRet = location_bounds_create_polygon(location_coord_list, nPolySize, &hPolyLocationBound);
+
+                       printf("location_bounds_create_polygon: %d\n", nRet);
+
+                       bIsContained = location_bounds_contains_coordinates(hPolyLocationBound, testLocationCoordinates);// Target API
+                       printf("bIsContained: %d\n", bIsContained);
+
+                       location_bounds_destroy(hPolyLocationBound);
+                       break;
+                       }
+               case 0:
+                       g_timeout_add_seconds(1, exit_program, NULL);
+                       return 0;
+               default:
+                       printf("Exit!!! Input: %d\n", menu);
+                       g_timeout_add_seconds(1, exit_program, NULL);
+                       return 0;
+       }
+
+       if (ret != LOCATIONS_ERROR_NONE) {
+               printf("Test Failed!!! [%d]\n", ret);
+               g_timeout_add_seconds(1, exit_program, NULL);
+               return 0;
+       }
+
+       if (menu < 40) {
+               ret = location_manager_set_service_state_changed_cb(manager, _state_change_cb, (void *)manager);
+               printf("set_service_state_changed_cb: %d\n", ret);
+
+               if (basic) {
+                       ret = location_manager_set_position_updated_cb(manager, _position_updated_cb, interval, (void *)manager);
+                       printf("set_position_updated_cb: %d\n", ret);
+               }
+       }
+       else {
+               g_timeout_add_seconds(1, wait_test, NULL);
+       }
+
+       return 0;
+}
+
+static void location_cleanup()
+{
+       int ret = 0;
+       if (manager != NULL) {
+               ret = location_manager_stop(manager);
+               printf("stop: %d\n", ret);
+
+               ret = location_manager_unset_service_state_changed_cb(manager);
+               printf("unset_service_state_changed_cb: %d\n", ret);
+
+               ret = location_manager_unset_position_updated_cb(manager);
+               printf("unset_position_updated_cb: %d\n", ret);
+
                ret = location_manager_destroy(manager);
-               printf("destroy :  %d\n", ret);
+               printf("destroy: %d\n", ret);
+               manager = NULL;
        }
-       g_main_loop_quit(g_mainloop);
-       printf("Quit g_main_loop\n");
-       return FALSE;
 }
 
 int main(int argc, char **argv)
 {
-       g_setenv("PKG_NAME", "com.samsung.location-test", 1);
        g_mainloop = g_main_loop_new(NULL, 0);
        location_test();
-       g_timeout_add_seconds(90, exit_program, NULL);
        g_main_loop_run(g_mainloop);
+       location_cleanup();
        return 0;
 }