Git init
[framework/location/libslp-location.git] / TC / unit / stc_gps_position.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_location_init();
31 static void utc_location_new();
32 static void utc_location_start();
33 static void utc_get_method();
34 static void utc_get_devname();
35 static void utc_location_get_position();
36 static void utc_location_svc_updated();
37 static void utc_location_stop();
38 static void utc_get_lastpostion();
39 static void utc_location_free();
40
41
42 struct tet_testlist tet_testlist[] = {
43         {utc_location_init,1},
44         {utc_location_new,1},
45         {utc_location_start,1},
46         {utc_get_method,1},
47         {utc_get_devname,1},
48         {utc_location_get_position,1},
49         {utc_location_svc_updated,1},
50         {utc_location_stop,1},
51         {utc_get_lastpostion,1},
52         {utc_location_free,1},
53         {NULL,0},
54 };      
55
56 static GMainLoop *loop = NULL;
57 int ret;
58 LocationObject* loc;
59
60 static gboolean
61 exit_loop (gpointer data)
62 {
63         g_main_loop_quit (loop);
64         tet_result(TET_FAIL);
65         return FALSE;
66 }
67
68
69 static void startup()
70 {       
71         tet_printf("\n TC startup");    
72         loop = g_main_loop_new (NULL, TRUE);    
73 }
74
75 static void cleanup()
76 {               
77         tet_printf("\n TC End");
78 }
79
80 static void
81 utc_location_init()
82 {
83         ret = location_init();
84         if(ret == LOCATION_ERROR_NONE) tet_result(TET_PASS);
85         else tet_result(TET_FAIL);
86 }
87
88 static void
89 utc_location_new()
90 {
91         loc = location_new(LOCATION_METHOD_GPS);
92         if (loc) tet_result(TET_PASS);
93         else tet_result(TET_FAIL);
94 }
95
96 static void
97 utc_location_start()
98 {
99         ret = location_start(loc);      
100         if (ret == LOCATION_ERROR_NONE) tet_result(TET_PASS);
101         else tet_result(TET_FAIL);
102 }
103
104 static void
105 utc_get_method()
106 {
107         LocationMethod method;  
108         g_object_get(loc, "method", &method, NULL);
109
110         if(LOCATION_METHOD_HYBRID <= method && method<= LOCATION_METHOD_WPS) tet_result(TET_PASS);
111         else tet_result(TET_FAIL);
112 }
113
114 static void
115 utc_get_devname()
116 {
117         char* devname = NULL;
118         g_object_get(loc, "dev-name", &devname, NULL);
119
120         if (devname) {
121                 tet_result(TET_PASS);
122                 g_free(devname);
123         } else tet_result(TET_FAIL);
124 }
125
126 static void
127 utc_get_lastpostion()
128 {
129         LocationPosition *pos = NULL;
130         g_object_get(loc, "last-position", &pos, NULL); 
131
132         if (pos) {
133                 tet_result(TET_PASS);
134                 location_position_free (pos);
135         } else tet_result(TET_FAIL);
136 }
137
138 static void
139 _get_position (GObject *self,
140                                 guint _status,
141                     gpointer userdata)
142 {
143         LocationAccuracy *acc = NULL;
144         LocationPosition *pos = NULL;
145         LocationObject *loc = (LocationObject*)userdata;        
146
147         ret = location_get_position (loc, &pos, &acc);
148         if (ret == LOCATION_ERROR_NONE) tet_result(TET_PASS);
149         else tet_result(TET_FAIL);
150         
151         g_main_loop_quit (loop);
152 }
153
154 static void
155 utc_location_get_position()
156 {
157         g_signal_connect (loc, "service-enabled", G_CALLBACK(_get_position), loc);
158         g_timeout_add_seconds(60, exit_loop, NULL);
159         g_main_loop_run (loop); 
160 }
161
162 static void
163 utc_location_stop()
164 {
165         ret = location_stop(loc);
166         
167         if(ret == LOCATION_ERROR_NONE) tet_result(TET_PASS);
168         else tet_result(TET_FAIL);
169 }
170
171 static void
172 _cb_updated (GObject *self,
173                     guint type,
174                     gpointer data,
175                     gpointer accuracy,
176                     gpointer userdata)
177 {
178         if ( POSITION_UPDATED <= type && type <= REVERSEGEOCODE_UPDATED) tet_result(TET_PASS);
179         else tet_result(TET_FAIL);
180         g_main_loop_quit (loop);
181 }
182
183 static void
184 utc_location_svc_updated()
185 {
186         g_signal_connect (loc, "service-updated", G_CALLBACK(_cb_updated), loc);
187         g_timeout_add_seconds(60, exit_loop, NULL);
188         g_main_loop_run (loop); 
189 }
190
191 static void
192 utc_location_free()
193 {
194         ret = location_free(loc);
195         if (ret == LOCATION_ERROR_NONE) tet_result(TET_PASS);
196         else tet_result(TET_FAIL);
197 }