Git init
[framework/location/libslp-location.git] / TC / unit / utc_location_get_address.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 <gconf/gconf-client.h>
25 #include <location.h>
26
27 static void startup(), cleanup();
28 void (*tet_startup) () = startup;
29 void (*tet_cleanup) () = cleanup;
30
31 static void utc_location_get_address_01();
32 static void utc_location_get_address_02();
33 static void utc_location_get_address_03();
34
35 struct tet_testlist tet_testlist[] = {
36         {utc_location_get_address_01,1},
37         {utc_location_get_address_02,2},
38         {utc_location_get_address_03,3},
39         {NULL,0},
40 };
41
42 static GMainLoop *loop = NULL;
43 LocationObject* loc = NULL;
44 int ret = LOCATION_ERROR_NONE;
45 int isNetStarted = 0;
46
47 #define GCONF_PROXY_MODE            "/system/proxy/mode"
48 #define GCONF_HTTP_PROXY_HOST       "/system/http_proxy/host"
49 #define GCONF_HTTP_PROXY_PORT       "/system/http_proxy/port"
50 #define ENV_HTTP_PROXY              "http_proxy"
51
52 static gboolean
53 exit_loop (gpointer data)
54 {
55         g_main_loop_quit (loop);
56         return FALSE;
57 }
58
59 static gboolean
60 exit_loop_fail (gpointer data)
61 {
62         g_main_loop_quit (loop);
63         tet_result(TET_FAIL);
64         return FALSE;
65 }
66
67 static void startup()
68 {       
69         location_init();
70         loc = location_new(LOCATION_METHOD_GPS);
71
72         loop = g_main_loop_new(NULL,FALSE);
73         g_main_loop_run (loop);
74         
75         tet_printf("\n TC startup");    
76 }
77
78 static void cleanup()
79 {       
80         location_stop(loc);
81         location_free(loc);
82         tet_printf("\n TC End");
83 }
84
85 static void
86 _get_address (GObject *self,
87         guint _status,
88         gpointer userdata)
89 {
90         LocationAccuracy *acc = NULL;
91         LocationAddress *addr = NULL;
92
93         ret = location_get_address(loc, &addr, &acc);
94         tet_printf("Returned value: %d", ret);
95         if (ret == LOCATION_ERROR_NONE ||
96                 ret == LOCATION_ERROR_CONFIGURATION) {
97                 location_address_free(addr);
98                 location_accuracy_free(acc);
99                 tet_result(TET_PASS);
100         } else tet_result(TET_FAIL);
101         g_main_loop_quit (loop);
102 }
103
104 static void
105 utc_location_get_address_01()
106 {               
107         g_signal_connect (loc, "service-enabled", G_CALLBACK(_get_address), loc);
108         location_start(loc);
109         g_timeout_add_seconds(60, exit_loop_fail, NULL);
110         g_main_loop_run (loop); 
111 }
112
113         static void
114 utc_location_get_address_02()
115 {
116         LocationAccuracy *acc = NULL;
117         LocationAddress *addr = NULL;
118
119         ret = location_get_address(NULL, &addr, &acc);
120         tet_printf("Returned value: %d", ret);
121         if (ret == LOCATION_ERROR_PARAMETER) tet_result(TET_PASS);
122         else tet_result(TET_FAIL);
123 }
124
125         static void
126 utc_location_get_address_03()
127 {
128         LocationAccuracy *acc = NULL;
129         ret = location_get_address(loc, NULL, &acc);
130         tet_printf("Returned value: %d", ret);
131         if(ret == LOCATION_ERROR_PARAMETER) tet_result(TET_PASS);
132         else tet_result(TET_FAIL);
133 }