558a7e391350669d3f31be61afb1d54b9a76be2b
[framework/location/libslp-location.git] / TC / unit / utc_location_get_position_from_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_position_from_address_01();
32 static void utc_location_get_position_from_address_02();
33 static void utc_location_get_position_from_address_03();
34 static void utc_location_get_position_from_address_04();
35
36 struct tet_testlist tet_testlist[] = {
37         {utc_location_get_position_from_address_01,1},
38         {utc_location_get_position_from_address_02,2},
39         {utc_location_get_position_from_address_03,3},
40         {utc_location_get_position_from_address_04,4},
41         {NULL,0},
42 };
43
44 static GMainLoop *loop = NULL;
45 LocationObject* loc;
46 int ret;
47 int isNetStarted = 0;
48
49 #define GCONF_PROXY_MODE            "/system/proxy/mode"
50 #define GCONF_HTTP_PROXY_HOST       "/system/http_proxy/host"
51 #define GCONF_HTTP_PROXY_PORT       "/system/http_proxy/port"
52 #define ENV_HTTP_PROXY              "http_proxy"
53
54 static gboolean
55 exit_loop (gpointer data)
56 {
57         g_main_loop_quit (loop);
58         return FALSE;
59 }
60
61 static void startup()
62 {       
63         location_init();
64         loc = location_new(LOCATION_METHOD_GPS);
65
66         loop = g_main_loop_new(NULL,FALSE);             
67         g_main_loop_run (loop);
68
69         tet_printf("\n TC startup");    
70 }
71
72 static void cleanup()
73 {       
74         location_free(loc);
75         tet_printf("\n TC End");
76 }
77
78 static void
79 utc_location_get_position_from_address_01()
80 {       
81         LocationPosition *pos = NULL;
82         LocationAccuracy *acc = NULL;
83         LocationAddress *addr = location_address_new ("1",  "Post Street", NULL, "san jose", "ca", NULL, "95113");
84         ret = location_get_position_from_address (loc, addr, &pos, &acc);
85         location_address_free(addr);
86         tet_printf("Returned value: %d", ret);
87         if( (ret == LOCATION_ERROR_NONE && 
88                 37.325276 <= pos->latitude &&  pos->latitude <= 37.345276 &&
89                 -121.900059 <= pos->longitude && pos->longitude<= -121.880059) ||
90                 ret == LOCATION_ERROR_CONFIGURATION ) {
91                 location_position_free(pos);
92                 location_accuracy_free(acc);
93                 tet_result(TET_PASS);
94         } else tet_result(TET_FAIL);
95 }
96
97 static void
98 utc_location_get_position_from_address_02()
99 {
100         LocationPosition *pos = NULL;
101         LocationAccuracy *acc = NULL;
102         LocationAddress *addr = location_address_new ("1",  "Post Street", NULL, "san jose", "ca", NULL, "95113");
103         ret = location_get_position_from_address (NULL, addr, &pos, &acc);
104         location_address_free(addr);
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_from_address_03()
112 {
113         LocationPosition *pos = NULL;
114         LocationAccuracy *acc = NULL;
115         ret = location_get_position_from_address(loc, NULL, &pos, &acc);
116         tet_printf("Returned value: %d", ret);
117         if (ret == LOCATION_ERROR_PARAMETER) tet_result(TET_PASS);
118         else tet_result(TET_FAIL);
119 }
120
121 static void
122 utc_location_get_position_from_address_04()
123 {
124         LocationAddress *addr = location_address_new ("1",  "Post Street", NULL, "san jose", "ca", NULL, "95113");;
125         LocationAccuracy *acc = NULL;
126         ret = location_get_position_from_address(loc, addr, NULL, &acc);
127         location_address_free (addr);
128         tet_printf("Returned value: %d", ret);
129         if (ret == LOCATION_ERROR_PARAMETER) tet_result(TET_PASS);
130         else tet_result(TET_FAIL);
131 }