tizen beta release
[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 <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_from_freeformed_address_01();
31 static void utc_location_get_position_from_freeformed_address_02();
32 static void utc_location_get_position_from_freeformed_address_03();
33 static void utc_location_get_position_from_freeformed_address_04();
34
35 struct tet_testlist tet_testlist[] = {
36         {utc_location_get_position_from_freeformed_address_01,1},
37         {utc_location_get_position_from_freeformed_address_02,2},
38         {utc_location_get_position_from_freeformed_address_03,3},
39         {utc_location_get_position_from_freeformed_address_04,4},
40         {NULL,0},
41 };
42
43 static GMainLoop *loop = NULL;
44 LocationObject* loc;
45 int ret;
46 int isNetStarted = 0;
47 gboolean is_found = FALSE;
48
49 static gboolean
50 exit_loop (gpointer data)
51 {
52         g_main_loop_quit (loop);
53         return FALSE;
54 }
55
56 static void startup()
57 {
58         location_init();
59         loc = location_new(LOCATION_METHOD_GPS);
60
61         loop = g_main_loop_new(NULL,FALSE);
62         tet_printf("\n TC startup");
63 }
64
65 static void cleanup()
66 {
67         location_free(loc);
68         tet_printf("\n TC End");
69 }
70
71 static void comp_position (gpointer data, gpointer user_data)
72 {
73         if (!data) return;
74         LocationPosition *pos = (LocationPosition *)data;
75         if (pos) {
76                 if (37.325276 <= pos->latitude &&  pos->latitude <= 37.345276 &&
77                 -121.900059 <= pos->longitude && pos->longitude<= -121.880059) {
78                         is_found = TRUE;
79                 }
80                 location_position_free (pos);
81         }
82 }
83
84 static void free_accuracy (gpointer data, gpointer user_data)
85 {
86         if (!data) return;
87
88         LocationAccuracy *acc = (LocationAccuracy *)data;
89         if (acc) location_accuracy_free(acc);
90 }
91
92 static void
93 utc_location_get_position_from_freeformed_address_01()
94 {
95         GList *pos_list = NULL;
96         GList *acc_list = NULL;
97         char* addr_str = g_strdup("4 N 2nd Street 95113");
98         ret = location_get_position_from_freeformed_address(loc, addr_str, &pos_list, &acc_list);
99         g_free(addr_str);
100         tet_printf("Returned value: %d", ret);
101         if (ret == LOCATION_ERROR_NONE ) {
102                 g_list_foreach (pos_list, comp_position, NULL);
103                 g_list_foreach (acc_list, free_accuracy, NULL);
104                 if (is_found == TRUE)
105                         tet_result(TET_PASS);
106                 else
107                         tet_result(TET_FAIL);
108         }
109         else
110                 tet_result(TET_FAIL);
111 }
112
113 static void
114 utc_location_get_position_from_freeformed_address_02()
115 {
116         GList *pos_list = NULL;
117         GList *acc_list = NULL;
118         char* addr_str = g_strdup("4 N 2nd Street 95113");
119         ret = location_get_position_from_freeformed_address(NULL, addr_str, &pos_list, &acc_list);
120         g_free(addr_str);
121         tet_printf("Returned value: %d", ret);
122         if (ret == LOCATION_ERROR_PARAMETER) tet_result(TET_PASS);
123         else tet_result(TET_FAIL);
124 }
125
126 static void
127 utc_location_get_position_from_freeformed_address_03()
128 {
129         GList *pos_list = NULL;
130         GList *acc_list = NULL;
131         ret = location_get_position_from_freeformed_address(loc, NULL, &pos_list, &acc_list);
132         tet_printf("Returned value: %d", ret);
133         if (ret == LOCATION_ERROR_PARAMETER) tet_result(TET_PASS);
134         else tet_result(TET_FAIL);
135 }
136
137 static void
138 utc_location_get_position_from_freeformed_address_04()
139 {
140         GList *acc_list = NULL;
141         char* addr_str = g_strdup("4 N 2nd Street 95113");
142         ret = location_get_position_from_freeformed_address(loc, addr_str, NULL, &acc_list);
143         g_free (addr_str);
144         tet_printf("Returned value: %d", ret);
145         if (ret == LOCATION_ERROR_PARAMETER) tet_result(TET_PASS);
146         else tet_result(TET_FAIL);
147 }
148