2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <locations.h>
22 POSITIVE_TC_IDX = 0x01,
26 static void startup(void);
27 static void cleanup(void);
29 void (*tet_startup) (void) = startup;
30 void (*tet_cleanup) (void) = cleanup;
32 static void utc_location_gps_status_get_nmea_p(void);
33 static void utc_location_gps_status_get_nmea_n(void);
34 static void utc_location_gps_status_get_nmea_n_02(void);
35 static void utc_location_gps_status_get_nmea_n_03(void);
36 static void utc_location_gps_status_get_satellite_p(void);
37 static void utc_location_gps_status_get_satellite_n(void);
38 static void utc_location_gps_status_get_satellite_n_02(void);
39 static void utc_location_gps_status_get_satellite_n_03(void);
40 static void utc_location_gps_status_get_satellite_n_04(void);
41 static void utc_location_gps_status_get_satellite_n_05(void);
42 static void utc_location_gps_status_get_satellite_n_06(void);
43 static void utc_location_gps_status_foreach_satellites_in_view_p(void);
44 static void utc_location_gps_status_foreach_satellites_in_view_n(void);
45 static void utc_location_gps_status_foreach_satellites_in_view_n_02(void);
46 static void utc_location_gps_status_foreach_satellites_in_view_n_03(void);
47 static void utc_location_gps_status_foreach_last_satellites_in_view_p(void);
48 static void utc_location_gps_status_foreach_last_satellites_in_view_n(void);
49 static void utc_location_gps_status_foreach_last_satellites_in_view_n_02(void);
50 static void utc_location_gps_status_get_last_satellite_p(void);
51 static void utc_location_gps_status_get_last_satellite_n(void);
52 static void utc_location_gps_status_get_last_satellite_n_02(void);
53 static void utc_location_gps_status_get_last_satellite_n_03(void);
54 static void utc_location_gps_status_get_last_satellite_n_04(void);
58 struct tet_testlist tet_testlist[] = {
59 {utc_location_gps_status_get_nmea_p, POSITIVE_TC_IDX},
60 {utc_location_gps_status_get_nmea_n, NEGATIVE_TC_IDX},
61 {utc_location_gps_status_get_nmea_n_02, NEGATIVE_TC_IDX},
62 // {utc_location_gps_status_get_nmea_n_03, NEGATIVE_TC_IDX}, //Can't check created location_manager_h
63 {utc_location_gps_status_get_satellite_p, POSITIVE_TC_IDX},
64 {utc_location_gps_status_get_satellite_n, NEGATIVE_TC_IDX},
65 {utc_location_gps_status_get_satellite_n_02, NEGATIVE_TC_IDX},
66 // {utc_location_gps_status_get_satellite_n_03, NEGATIVE_TC_IDX}, //Can't check created location_manager_h
67 {utc_location_gps_status_get_satellite_n_04, NEGATIVE_TC_IDX},
68 {utc_location_gps_status_get_satellite_n_05, NEGATIVE_TC_IDX},
69 {utc_location_gps_status_get_satellite_n_06, NEGATIVE_TC_IDX},
70 {utc_location_gps_status_foreach_satellites_in_view_p, POSITIVE_TC_IDX},
71 {utc_location_gps_status_foreach_satellites_in_view_n, NEGATIVE_TC_IDX},
72 {utc_location_gps_status_foreach_satellites_in_view_n_02, NEGATIVE_TC_IDX},
73 // {utc_location_gps_status_foreach_satellites_in_view_n_03, NEGATIVE_TC_IDX }, //Can't check created location_manager_h
74 {utc_location_gps_status_foreach_last_satellites_in_view_p, POSITIVE_TC_IDX},
75 {utc_location_gps_status_foreach_last_satellites_in_view_n, NEGATIVE_TC_IDX},
76 {utc_location_gps_status_foreach_last_satellites_in_view_n_02, NEGATIVE_TC_IDX},
77 {utc_location_gps_status_get_last_satellite_p, POSITIVE_TC_IDX},
78 {utc_location_gps_status_get_last_satellite_n, NEGATIVE_TC_IDX},
79 {utc_location_gps_status_get_last_satellite_n_02, NEGATIVE_TC_IDX},
80 {utc_location_gps_status_get_last_satellite_n_03, NEGATIVE_TC_IDX},
81 {utc_location_gps_status_get_last_satellite_n_04, NEGATIVE_TC_IDX},
85 static GMainLoop *g_mainloop = NULL;
86 static GThread *event_thread;
88 gpointer GmainThread(gpointer data)
90 g_mainloop = g_main_loop_new(NULL, 0);
91 g_main_loop_run(g_mainloop);
96 static bool service_enabled = false;
98 static void validate_and_next(char *api_name, int act_ret, int ext_ret, char *fail_msg)
100 dts_message(api_name, "Actual Result : %d, Expected Result : %d", act_ret, ext_ret);
101 if (act_ret != ext_ret) {
102 dts_message(api_name, "Fail Message: %s", fail_msg);
107 static void validate_eq(char *api_name, int act_ret, int ext_ret)
109 dts_message(api_name, "Actual Result : %d, Expected Result : %d", act_ret, ext_ret);
110 if (act_ret == ext_ret) {
117 static void unprepare(location_manager_h manager)
119 location_manager_unset_service_state_changed_cb(manager);
120 location_manager_destroy(manager);
121 service_enabled = false;
124 static void wait_for_service(char *api_name)
127 for (timeout; timeout < 30; timeout++) {
128 if (service_enabled) {
129 dts_message(api_name, "Location Service Enabled!!!!");
132 dts_message(api_name, "Location Service Disabled!!!!");
138 static void capi_state_changed_cb(location_service_state_e state, void *user_data)
141 case LOCATIONS_SERVICE_ENABLED:
142 service_enabled = true;
144 case LOCATIONS_SERVICE_DISABLED:
145 service_enabled = false;
152 static location_manager_h manager;
154 static void startup(void)
156 g_setenv("PKG_NAME", "com.samsung.capi-location-gps-status-test", 1);
157 g_setenv("LOCATION_TEST_ENABLE", "1", 1);
159 #if !GLIB_CHECK_VERSION (2, 31, 0)
160 if (!g_thread_supported()) {
166 event_thread = g_thread_create(GmainThread, NULL, 1, &gerr);
169 ret = location_manager_create(LOCATIONS_METHOD_GPS, &manager);
170 validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_create() is failed");
173 ret = location_manager_set_service_state_changed_cb(manager, capi_state_changed_cb, NULL);
174 validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_set_service_state_changed_cb() is failed");
177 ret = location_manager_start(manager);
178 validate_and_next(__func__, ret, LOCATIONS_ERROR_NONE, "location_manager_start() is failed");
180 wait_for_service(__func__);
183 static void cleanup(void)
186 g_main_loop_quit(g_mainloop);
187 g_thread_join(event_thread);
190 static void utc_location_gps_status_get_nmea_p(void)
192 int ret = LOCATIONS_ERROR_NONE;
194 ret = gps_status_get_nmea(manager, &nmea);
195 validate_eq(__func__, ret, LOCATIONS_ERROR_NONE);
198 static void utc_location_gps_status_get_nmea_n(void)
200 int ret = LOCATIONS_ERROR_NONE;
201 ret = gps_status_get_nmea(manager, NULL);
202 validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER);
205 static void utc_location_gps_status_get_nmea_n_02(void)
207 int ret = LOCATIONS_ERROR_NONE;
209 ret = gps_status_get_nmea(NULL, &nmea);
210 validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER);
214 static void utc_location_gps_status_get_nmea_n_03(void)
216 int ret = LOCATIONS_ERROR_NONE;
218 location_manager_h manager_02;
219 ret = gps_status_get_nmea(manager_02, &nmea);
220 validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER);
224 static void utc_location_gps_status_get_satellite_p(void)
226 int ret = LOCATIONS_ERROR_NONE;
227 int num_of_active, num_of_inview;
229 ret = gps_status_get_satellite(manager, &num_of_active, &num_of_inview, ×tamp);
230 validate_eq(__func__, ret, LOCATIONS_ERROR_NONE);
233 static void utc_location_gps_status_get_satellite_n(void)
235 int ret = LOCATIONS_ERROR_NONE;
236 ret = gps_status_get_satellite(manager, NULL, NULL, NULL);
237 validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER);
240 static void utc_location_gps_status_get_satellite_n_02(void)
242 int ret = LOCATIONS_ERROR_NONE;
243 int num_of_active, num_of_inview;
245 ret = gps_status_get_satellite(NULL, &num_of_active, &num_of_inview, ×tamp);
246 validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER);
249 static void utc_location_gps_status_get_satellite_n_03(void)
251 int ret = LOCATIONS_ERROR_NONE;
252 int num_of_active, num_of_inview;
254 location_manager_h manager_02;
255 ret = gps_status_get_satellite(manager_02, &num_of_active, &num_of_inview, ×tamp);
256 validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER);
259 static void utc_location_gps_status_get_satellite_n_04(void)
261 int ret = LOCATIONS_ERROR_NONE;
264 ret = gps_status_get_satellite(manager, NULL, &num_of_inview, ×tamp);
265 validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER);
268 static void utc_location_gps_status_get_satellite_n_05(void)
270 int ret = LOCATIONS_ERROR_NONE;
273 ret = gps_status_get_satellite(manager, &num_of_active, NULL, ×tamp);
274 validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER);
277 static void utc_location_gps_status_get_satellite_n_06(void)
279 int ret = LOCATIONS_ERROR_NONE;
280 int num_of_active, num_of_inview;
281 ret = gps_status_get_satellite(manager, &num_of_active, &num_of_inview, NULL);
282 validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER);
285 static bool capi_gps_status_get_satellites_cb(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr,
286 bool is_in_use, void *user_data)
291 static void utc_location_gps_status_foreach_satellites_in_view_p(void)
293 int ret = LOCATIONS_ERROR_NONE;
294 ret = gps_status_foreach_satellites_in_view(manager, capi_gps_status_get_satellites_cb, NULL);
295 validate_eq(__func__, ret, LOCATIONS_ERROR_NONE);
298 static void utc_location_gps_status_foreach_satellites_in_view_n(void)
300 int ret = LOCATIONS_ERROR_NONE;
301 ret = gps_status_foreach_satellites_in_view(manager, NULL, NULL);
302 validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER);
305 static void utc_location_gps_status_foreach_satellites_in_view_n_02(void)
307 int ret = LOCATIONS_ERROR_NONE;
308 ret = gps_status_foreach_satellites_in_view(NULL, capi_gps_status_get_satellites_cb, NULL);
309 validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER);
312 static void utc_location_gps_status_foreach_satellites_in_view_n_03(void)
314 int ret = LOCATIONS_ERROR_NONE;
315 location_manager_h manager_02;
316 ret = gps_status_foreach_satellites_in_view(manager_02, capi_gps_status_get_satellites_cb, NULL);
317 validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER);
320 static bool capi_last_satellites_foreach_cb(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr, bool is_in_use,
323 printf("[Last Satellite information] azimuth : %d, elevation : %d, prn :%d, snr : %d, used: %d\n", azimuth, elevation,
324 prn, snr, is_in_use);
328 static void utc_location_gps_status_foreach_last_satellites_in_view_p(void)
330 int ret = LOCATIONS_ERROR_NONE;
332 ret = gps_status_foreach_last_satellites_in_view(manager, capi_last_satellites_foreach_cb, NULL);
333 validate_eq(__func__, ret, LOCATIONS_ERROR_NONE);
336 static void utc_location_gps_status_foreach_last_satellites_in_view_n(void)
338 int ret = LOCATIONS_ERROR_NONE;
339 ret = gps_status_foreach_last_satellites_in_view(manager, NULL, NULL);
340 validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER);
343 static void utc_location_gps_status_foreach_last_satellites_in_view_n_02(void)
345 int ret = LOCATIONS_ERROR_NONE;
346 ret = gps_status_foreach_last_satellites_in_view(NULL, capi_last_satellites_foreach_cb, NULL);
347 validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER);
350 static void utc_location_gps_status_get_last_satellite_p(void)
352 int ret = LOCATIONS_ERROR_NONE;
355 int num_of_inview, num_of_active;
356 ret = gps_status_get_last_satellite(manager, &num_of_active, &num_of_inview, ×tamp);
357 validate_eq(__func__, ret, LOCATIONS_ERROR_NONE);
360 static void utc_location_gps_status_get_last_satellite_n(void)
362 int ret = LOCATIONS_ERROR_NONE;
365 int num_of_inview, num_of_active;
366 ret = gps_status_get_last_satellite(NULL, &num_of_active, &num_of_inview, ×tamp);
367 validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER);
370 static void utc_location_gps_status_get_last_satellite_n_02(void)
372 int ret = LOCATIONS_ERROR_NONE;
376 ret = gps_status_get_last_satellite(manager, NULL, &num_of_inview, ×tamp);
377 validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER);
380 static void utc_location_gps_status_get_last_satellite_n_03(void)
382 int ret = LOCATIONS_ERROR_NONE;
386 ret = gps_status_get_last_satellite(manager, &num_of_active, NULL, ×tamp);
387 validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER);
390 static void utc_location_gps_status_get_last_satellite_n_04(void)
392 int ret = LOCATIONS_ERROR_NONE;
394 int num_of_inview, num_of_active;
395 ret = gps_status_get_last_satellite(manager, &num_of_active, &num_of_inview, NULL);
396 validate_eq(__func__, ret, LOCATIONS_ERROR_INVALID_PARAMETER);