summaryrefslogtreecommitdiff
path: root/TC/unit/stc_gps_zone.c
blob: 39110fc06ff786cd839334a2d27579c39a3f2916 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*
 * libslp-location
 *
 * Copyright (c) 2010-2013 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact: Youngae Kang <youngae.kang@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
 *          Genie Kim <daejins.kim@samsung.com>
 *
 * 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 <tet_api.h>
#include <glib.h>
#include <location.h>

static gboolean g_is_found = FALSE;

static void startup(), cleanup();
void (*tet_startup) () = startup;
void (*tet_cleanup) () = cleanup;

static void utc_location_init();
static void utc_location_new();
static void utc_location_start();
static void utc_get_method();
static void utc_get_devname();
static void utc_location_svc_enabled();
static void utc_set_boundary_in_suwonHQ();
static void utc_get_boundary_in_suwonHQ();
static void utc_zone_in();
static void utc_set_boundary_in_Santorini();
static void utc_get_boundary_in_Santorini();
static void utc_zone_out();
static void utc_location_stop();
static void utc_location_free();


struct tet_testlist tet_testlist[] = {
	{utc_location_init,1},
	{utc_location_new,1},
	{utc_location_start,1},
	{utc_get_method,1},
	{utc_get_devname,1},
	{utc_location_svc_enabled,1},
	{utc_set_boundary_in_suwonHQ,1},
	{utc_get_boundary_in_suwonHQ,1},
	{utc_zone_in,1},
	{utc_set_boundary_in_Santorini,1},
	{utc_get_boundary_in_Santorini,1},
	{utc_zone_out,1},
	{utc_location_stop,1},
	{utc_location_free,1},
	{NULL,0},
};	


static GMainLoop *loop = NULL;
int ret;
LocationObject* loc;

static void comp_boundary(LocationBoundary *bound, gpointer user_data)
{
	LocationBoundary *check_bound = (LocationBoundary *) user_data;

	if(bound && bound->type == check_bound->type) {
		switch(bound->type) {
			case LOCATION_BOUNDARY_RECT:
				if(bound->rect.right_bottom->latitude == check_bound->rect.right_bottom->latitude &&
					bound->rect.right_bottom->longitude == check_bound->rect.right_bottom->longitude &&
					bound->rect.left_top->latitude == check_bound->rect.left_top->latitude &&
					bound->rect.left_top->longitude == check_bound->rect.left_top->longitude ){
						g_is_found = TRUE;
					}
						break;
			default:
				break;
		}
	}
}


static gboolean
exit_loop (gpointer data)
{
	g_main_loop_quit (loop);
	tet_result(TET_FAIL);
	return FALSE;
}

static void startup()
{	
	tet_printf("\n TC startup");
	loop = g_main_loop_new (NULL, TRUE);	
}

static void cleanup()
{		
	tet_printf("\n TC End");
}

static void
utc_location_init()
{
	ret = location_init();
	if(ret == LOCATION_ERROR_NONE) tet_result(TET_PASS);
	else tet_result(TET_FAIL);
}

static void
utc_location_new()
{
	loc = location_new(LOCATION_METHOD_GPS);
	if(loc) tet_result(TET_PASS);
	else tet_result(TET_FAIL);
}

static void
utc_location_start()
{
	ret = location_start(loc);
	
	if (ret == LOCATION_ERROR_NONE) tet_result(TET_PASS);
	else tet_result(TET_FAIL);
}

static void
utc_get_method()
{
	LocationMethod method;	
	g_object_get(loc, "method", &method, NULL);

	if(LOCATION_METHOD_HYBRID <= method && method<= LOCATION_METHOD_WPS) tet_result(TET_PASS);
	else tet_result(TET_FAIL);
}

static void
utc_get_devname()
{
	char* devname = NULL;
	g_object_get(loc, "dev-name", &devname, NULL);

	if(devname){
		tet_result(TET_PASS);
		g_free(devname);
	} else tet_result(TET_FAIL);
}

static void
_cb_svc_enabled (GObject *self,
              			guint _status,
                    gpointer userdata)
{
	if(LOCATION_STATUS_NO_FIX <= _status && _status <= LOCATION_STATUS_3D_FIX) tet_result(TET_PASS);
	else tet_result(TET_FAIL);
	g_main_loop_quit(loop);
}


static void
utc_location_svc_enabled()
{
	g_signal_connect (loc, "service-enabled", G_CALLBACK(_cb_svc_enabled), loc);
	g_timeout_add_seconds(60, exit_loop, NULL);
	g_main_loop_run (loop);	
}

static void
utc_set_boundary_in_suwonHQ()
{
	int ret = 0;
	LocationPosition *rb = location_position_new(0, 37.253, 127.058, 0, LOCATION_STATUS_2D_FIX);
	LocationPosition *lt = location_position_new(0, 37.261, 127.052, 0, LOCATION_STATUS_2D_FIX);
	LocationBoundary *bound = location_boundary_new_for_rect(lt, rb);
	location_position_free (rb);
	location_position_free (lt);
	ret = location_boundary_add(loc, bound);
	if (!ret) tet_result(TET_PASS);
	else tet_result(TET_FAIL);

	location_boundary_free (bound);
}

static void
utc_get_boundary_in_suwonHQ()
{
	LocationPosition *rb = location_position_new(0, 37.253, 127.058, 0, LOCATION_STATUS_2D_FIX);
	LocationPosition *lt = location_position_new(0, 37.261, 127.052, 0, LOCATION_STATUS_2D_FIX);
	LocationBoundary *bound = location_boundary_new_for_rect(lt, rb);
	location_position_free (rb);
	location_position_free (lt);

	g_is_found = FALSE;
	location_boundary_foreach(loc, comp_boundary, bound);
	if(g_is_found) tet_result(TET_PASS);
	else tet_result(TET_FAIL);

	location_boundary_free (bound);
}

static void
_cb_zone_in(LocationObject *self,
            guint type,
            gpointer position,
            gpointer accuracy)
{
	LocationPosition *pos = (LocationPosition*) position;
	if( (37.253 <= pos->latitude && pos->latitude <= 37.261) &&
		(127.052 <= pos->longitude && pos->longitude <= 127.058) ) {
		tet_result(TET_PASS);	// I am in Suwon HQ
	} else tet_result(TET_FAIL);

	g_main_loop_quit(loop);
}

static void
utc_zone_in()
{
	g_signal_connect (loc, "zone-in", G_CALLBACK(_cb_zone_in), loc);
	g_timeout_add_seconds(60, exit_loop, NULL);
	g_main_loop_run (loop);	
}

static void
utc_set_boundary_in_Santorini()
{
	int ret = 0;
	LocationPosition *rb = location_position_new(0, 36.395, 25.41, 0, LOCATION_STATUS_2D_FIX);
	LocationPosition *lt = location_position_new(0, 36.413, 25.388, 0, LOCATION_STATUS_2D_FIX);
	LocationBoundary* bound = location_boundary_new_for_rect(lt, rb);
	location_position_free (rb);
	location_position_free (lt);

	ret = location_boundary_add(loc, bound);
	if (!ret) tet_result(TET_PASS);
	else tet_result(TET_FAIL);

	location_boundary_free (bound);
}

static void
utc_get_boundary_in_Santorini()
{
	LocationPosition *rb = location_position_new(0, 36.395, 25.41, 0, LOCATION_STATUS_2D_FIX);
	LocationPosition *lt = location_position_new(0, 36.413, 25.388, 0, LOCATION_STATUS_2D_FIX);
	LocationBoundary* bound = location_boundary_new_for_rect(lt, rb);
	location_position_free (rb);
	location_position_free (lt);

	g_is_found = FALSE;
	location_boundary_foreach(loc, comp_boundary, bound);
	if(g_is_found) tet_result(TET_PASS);
	else tet_result(TET_FAIL);

	location_boundary_free (bound);
}

static void
_cb_zone_out(LocationObject *self,
            guint type,
            gpointer position,
            gpointer accuracy)
{
	LocationPosition *pos = (LocationPosition*) position;

	if( (37.253 <= pos->latitude && pos->latitude <= 37.261) &&
		(27.052 <= pos->longitude && pos->longitude <= 127.058) ) {
		tet_result(TET_PASS);	// I am in Suwon HQ
	} else tet_result(TET_FAIL);
	g_main_loop_quit(loop);
}


static void
utc_zone_out()
{
	g_signal_connect (loc, "zone-out", G_CALLBACK(_cb_zone_out), loc);
	g_timeout_add_seconds(60, exit_loop, NULL);
	g_main_loop_run (loop);	
}

static void
utc_location_stop()
{
	ret = location_stop(loc);
	
	if(ret == LOCATION_ERROR_NONE) tet_result(TET_PASS);
	else tet_result(TET_FAIL);
}

static void
utc_location_free()
{
	ret = location_free(loc);
	if(ret == LOCATION_ERROR_NONE) tet_result(TET_PASS);
	else tet_result(TET_FAIL);
}