d33b750a0db4f306100ccb499f255080d9a60092
[framework/location/libslp-location.git] / TC / unit / utc_location_get_position_from_freeformed_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_freeformed_address_01();
32 static void utc_location_get_position_from_freeformed_address_02();
33 static void utc_location_get_position_from_freeformed_address_03();
34 static void utc_location_get_position_from_freeformed_address_04();
35
36 struct tet_testlist tet_testlist[] = {
37         {utc_location_get_position_from_freeformed_address_01,1},
38         {utc_location_get_position_from_freeformed_address_02,2},
39         {utc_location_get_position_from_freeformed_address_03,3},
40         {utc_location_get_position_from_freeformed_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_freeformed_address_01()
80 {       
81         LocationPosition *pos = NULL;
82         LocationAccuracy *acc = NULL;
83         char* addr_str = g_strdup("4 N 2nd Street 95113");
84         ret = location_get_position_from_freeformed_address(loc, addr_str, &pos, &acc);
85         g_free(addr_str);
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         }
95         else
96                 tet_result(TET_FAIL);
97         
98 }
99
100 static void
101 utc_location_get_position_from_freeformed_address_02()
102 {
103         LocationPosition *pos = NULL;
104         LocationAccuracy *acc = NULL;
105         char* addr_str = g_strdup("4 N 2nd Street 95113");
106         ret = location_get_position_from_freeformed_address(NULL, addr_str, &pos, &acc);
107         g_free(addr_str);
108         tet_printf("Returned value: %d", ret);
109         if (ret == LOCATION_ERROR_PARAMETER) tet_result(TET_PASS);
110         else tet_result(TET_FAIL);
111 }
112
113 static void
114 utc_location_get_position_from_freeformed_address_03()
115 {
116         LocationPosition *pos = NULL;
117         LocationAccuracy *acc = NULL;
118         ret = location_get_position_from_freeformed_address(loc, NULL, &pos, &acc);
119         tet_printf("Returned value: %d", ret);
120         if (ret == LOCATION_ERROR_PARAMETER) tet_result(TET_PASS);
121         else tet_result(TET_FAIL);
122 }
123
124 static void
125 utc_location_get_position_from_freeformed_address_04()
126 {
127         LocationAccuracy *acc = NULL;
128         char* addr_str = g_strdup("4 N 2nd Street 95113");
129         ret = location_get_position_from_freeformed_address(loc, addr_str, NULL, &acc);
130         g_free (addr_str);
131         tet_printf("Returned value: %d", ret);
132         if (ret == LOCATION_ERROR_PARAMETER) tet_result(TET_PASS);
133         else tet_result(TET_FAIL);
134 }
135