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