Git init
[framework/location/libslp-location.git] / TC / unit / utc_properties_last_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 #include <tet_api.h>
22 #include <glib.h>
23 #include <location.h>
24
25 static void startup(), cleanup();
26 void (*tet_startup) () = startup;
27 void (*tet_cleanup) () = cleanup;
28
29 static void utc_get_lastpostion();
30
31 struct tet_testlist tet_testlist[] = {
32         {utc_get_lastpostion,1},
33         {NULL,0},
34 };      
35
36
37 static GMainLoop *loop = NULL;
38 int ret;
39 LocationObject* loc;
40
41 static gboolean
42 exit_loop (gpointer data)
43 {
44         g_main_loop_quit (loop);
45         tet_result(TET_FAIL);
46         return FALSE;
47 }
48
49 static void startup()
50 {       
51         location_init();
52         loc = location_new(LOCATION_METHOD_GPS);
53         location_start(loc);
54         loop = g_main_loop_new(NULL,FALSE);     
55         tet_printf("\n TC startup");
56 }
57
58 static void cleanup()
59 {       
60         location_stop(loc);
61         location_free(loc);
62         tet_printf("\n TC End");
63 }
64
65 static void
66 cb_updated (GObject *self,
67                     guint type,
68                     gpointer data,
69                     gpointer accuracy,
70                     gpointer userdata)
71 {
72         LocationPosition *pos = NULL;
73         g_object_get(loc, "last-position", &pos, NULL);
74         if (pos) {
75                 location_position_free (pos);
76                 tet_result(TET_PASS);           
77         } else tet_result(TET_FAIL);
78         g_main_loop_quit (loop);
79 }
80
81 static void
82 utc_get_lastpostion()
83 {
84         g_signal_connect (loc, "service-updated", G_CALLBACK(cb_updated), loc); 
85         g_timeout_add_seconds (60, exit_loop, NULL);
86         g_main_loop_run (loop);
87 }