Git init
[framework/location/libslp-location.git] / TC / unit / utc_location_get_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_get_position_01();
31 static void utc_location_get_position_02();
32 static void utc_location_get_position_03();
33 static void utc_location_get_position_04();
34
35 struct tet_testlist tet_testlist[] = {
36         {utc_location_get_position_01,1},
37         {utc_location_get_position_02,2},
38         {utc_location_get_position_03,3},
39         {utc_location_get_position_04,4},
40         {NULL,0},
41 };
42
43 static GMainLoop *loop = NULL;
44 int ret;
45 LocationObject* loc;
46
47 static gboolean
48 exit_loop (gpointer data)
49 {
50         g_main_loop_quit (loop);
51         tet_result(TET_FAIL);
52         return FALSE;
53 }
54
55 static void startup()
56 {       
57         location_init();
58         loc = location_new(LOCATION_METHOD_GPS);
59         location_start(loc);    
60         loop = g_main_loop_new(NULL,FALSE);     
61         tet_printf("\n TC startup");    
62 }
63
64 static void cleanup()
65 {       
66         location_stop(loc);
67         location_free(loc);
68         tet_printf("\n TC End");
69 }
70
71 static void
72 _get_position (GObject *self,
73                                 guint _status,
74                     gpointer userdata)
75 {
76         LocationAccuracy *acc = NULL;
77         LocationPosition *pos = NULL;
78         LocationObject *loc = (LocationObject*)userdata;        
79
80         ret = location_get_position (loc, &pos, &acc);
81         tet_printf("Returned value: %d", ret);
82         if (ret == LOCATION_ERROR_NONE) {
83                 location_position_free (pos);
84                 location_accuracy_free (acc);
85                 tet_result(TET_PASS);
86         } else tet_result(TET_FAIL);
87         g_main_loop_quit (loop);
88 }
89
90 static void
91 utc_location_get_position_01()
92 {       
93         g_signal_connect (loc, "service-enabled", G_CALLBACK(_get_position), loc);
94         g_timeout_add_seconds(60, exit_loop, NULL);
95         g_main_loop_run (loop); 
96 }
97
98 static void
99 utc_location_get_position_02()
100 {
101         LocationAccuracy *acc = NULL;
102         LocationPosition *pos = NULL;
103
104         ret = location_get_position (NULL, &pos, &acc);
105         tet_printf("Returned value: %d", ret);
106         if (ret == LOCATION_ERROR_PARAMETER) tet_result(TET_PASS);
107         else tet_result(TET_FAIL);
108 }
109
110 static void
111 utc_location_get_position_03()
112 {
113         LocationAccuracy *acc = NULL;
114         ret = location_get_position (loc, NULL, &acc);
115         tet_printf("Returned value: %d", ret);
116         if (ret == LOCATION_ERROR_PARAMETER) tet_result(TET_PASS);
117         else tet_result(TET_FAIL);
118 }
119
120 static void
121 utc_location_get_position_04()
122 {
123         LocationPosition *pos = NULL;
124         ret = location_get_position (loc, &pos, NULL);
125         tet_printf("Returned value: %d", ret);
126         if (ret == LOCATION_ERROR_PARAMETER) tet_result(TET_PASS);
127         else tet_result(TET_FAIL);
128 }