Git init
[framework/location/libslp-location.git] / TC / unit / stc_gps_satellite.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_satellite();
36 static void utc_location_svc_disabled();
37 static void utc_location_free();
38
39
40 struct tet_testlist tet_testlist[] = {
41         {utc_location_init,1},
42         {utc_location_new,1},
43         {utc_location_start,1},
44         {utc_get_method,1},
45         {utc_get_devname,1},
46         {utc_location_get_satellite,1},
47         {utc_location_svc_disabled,1},
48         {utc_location_free,1},
49         {NULL,0},
50 };      
51
52
53
54 static GMainLoop *loop = NULL;
55 int ret;
56 LocationObject* loc;
57
58 gboolean
59 exit_loop (gpointer data)
60 {
61         g_main_loop_quit (loop);
62         tet_result(TET_FAIL);
63         return FALSE;
64 }
65
66 static void startup()
67 {
68         tet_printf("\n TC startup");
69 }
70
71 static void cleanup()
72 {               
73         tet_printf("\n TC End");
74 }
75
76 static void
77 utc_location_init()
78 {
79         ret = location_init();
80         if(ret == LOCATION_ERROR_NONE) tet_result(TET_PASS);
81         else tet_result(TET_FAIL);
82 }
83
84 static void
85 utc_location_new()
86 {
87         loc = location_new(LOCATION_METHOD_GPS);
88         if(loc) tet_result(TET_PASS);
89         else tet_result(TET_FAIL);
90 }
91
92 static void
93 utc_location_start()
94 {
95         ret = location_start(loc);      
96         if(ret == LOCATION_ERROR_NONE) tet_result(TET_PASS);
97         else tet_result(TET_FAIL);
98 }
99
100 static void
101 utc_get_method()
102 {
103         LocationMethod method;  
104         g_object_get(loc, "method", &method, NULL);
105         if (LOCATION_METHOD_HYBRID <= method && method<= LOCATION_METHOD_WPS) tet_result(TET_PASS);
106         else tet_result(TET_FAIL);
107 }
108
109 static void
110 utc_get_devname()
111 {
112         char* devname = NULL;
113         g_object_get(loc, "dev-name", &devname, NULL);
114         if (devname) {
115                 tet_result(TET_PASS);
116                 g_free(devname);
117         } else tet_result(TET_FAIL);
118 }
119
120 static void
121 _get_satellite (GObject *self,
122                                 guint _status,
123                     gpointer userdata)
124 {
125         LocationSatellite *sat = NULL;
126         g_object_get (loc, "satellite", &sat, NULL);
127         if (sat) {
128                 tet_result(TET_PASS);
129                 location_satellite_free (sat);
130         } else tet_result(TET_FAIL);
131         g_main_loop_quit (loop);
132 }
133
134 static void
135 utc_location_get_satellite()
136 {
137         loop = g_main_loop_new (NULL, TRUE);    
138         g_signal_connect (loc, "service-enabled", G_CALLBACK(_get_satellite), loc);
139         g_timeout_add_seconds(60, exit_loop, NULL);
140         g_main_loop_run (loop); 
141 }
142
143 static void
144 _cb_disabled (GObject *self,
145                                 guint _status,
146                                 gpointer userdata)
147 {
148         if( LOCATION_STATUS_NO_FIX <= _status && _status <= LOCATION_STATUS_3D_FIX) tet_result(TET_PASS);
149         else tet_result(TET_FAIL);
150         g_main_loop_quit (loop);
151 }
152
153 gboolean
154 _stop_location()
155 {
156         location_stop(loc);
157         return FALSE;
158 }
159
160 static void
161 utc_location_svc_disabled()
162 {
163         g_signal_connect (loc, "service-disabled", G_CALLBACK(_cb_disabled), loc);
164         g_timeout_add_seconds(1, _stop_location, NULL); 
165         g_timeout_add_seconds(60, exit_loop, NULL);
166         g_main_loop_run (loop);
167 }
168
169 static void
170 utc_location_free()
171 {
172         ret = location_free(loc);
173         if(ret == LOCATION_ERROR_NONE) tet_result(TET_PASS);
174         else tet_result(TET_FAIL);
175 }