c0d42c90a25ca2318d8e41fa45a92476fa221254
[framework/location/libslp-location.git] / TC / unit / utc_signals_zone_in.c
1 /*
2  * libslp-location
3  *
4  * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Youngae Kang <youngae.kang@samsung.com>, Yunhan Kim <yhan.kim@samsung.com>,
7  *          Genie Kim <daejins.kim@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21
22 #include <tet_api.h>
23 #include <glib.h>
24 #include <location.h>
25
26 static void startup(), cleanup();
27 void (*tet_startup) () = startup;
28 void (*tet_cleanup) () = cleanup;
29
30 static void utc_zone_in();
31
32 struct tet_testlist tet_testlist[] = {
33         {utc_zone_in,1},
34         {NULL,0},
35 };      
36
37 static GMainLoop *loop = NULL;
38 int ret;
39 LocationObject* loc;
40
41 gboolean
42 exit_loop (gpointer data)
43 {
44         g_main_loop_quit (loop);
45         tet_result(TET_FAIL);
46         return FALSE;
47 }
48
49 static void startup()
50 {       
51         location_init();
52         loc = location_new(LOCATION_METHOD_GPS);
53         location_start(loc);
54         loop = g_main_loop_new(NULL,FALSE);     
55
56         LocationPosition *rb = location_position_new(0, 37.254, 127.057, 0, LOCATION_STATUS_2D_FIX);
57         LocationPosition *lt = location_position_new(0, 37.261, 127.050, 0, LOCATION_STATUS_2D_FIX);
58         LocationBoundary* bound = location_boundary_new_for_rect(lt, rb);
59         location_position_free (rb);
60         location_position_free (lt);
61         g_object_set(loc, "boundary", bound, NULL);     
62         location_boundary_free (bound); 
63         tet_printf("\n TC startup");
64 }
65
66 static void cleanup()
67 {       
68         location_stop(loc);
69         location_free(loc);
70         tet_printf("\n TC End");
71 }
72
73 static void
74 cb_zone_in(LocationObject *self,
75             guint type,
76             gpointer position,
77             gpointer accuracy)
78 {
79         LocationPosition *pos = (LocationPosition*) position;
80
81         if( (37.255 <= pos->latitude && pos->latitude <= 37.265) &&
82                 (127.052 <= pos->longitude && pos->longitude <= 127.058)) tet_result(TET_PASS); // I am in Suwon HQ
83         else tet_result(TET_FAIL);
84         g_main_loop_quit(loop);
85 }
86
87 static void
88 utc_zone_in()
89 {
90         g_signal_connect (loc, "zone-in", G_CALLBACK(cb_zone_in), loc);
91         g_timeout_add_seconds(60, exit_loop, NULL);
92         g_main_loop_run (loop); 
93 }