Add LCOV remarkers to increase line coverage rate
[platform/core/api/maps-service.git] / src / api / maps_place_category.cpp
1 /* Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #include <glib.h>
17 #include "maps_error.h"
18 #include "maps_extra_types.h"
19 #include "maps_util.h"
20 #include "maps_place_category.h"
21 #include "maps_condition.h"
22
23 typedef struct _maps_place_category_s
24 {
25         char *name;
26         char *id;
27         char *url;
28 } maps_place_category_s;
29
30 const gsize _MAPS_PLACE_CATEGORY_ID_MAX_LENGTH = MAPS_BASE_ID_MAX_LEN;
31 const gsize _MAPS_PLACE_CATEGORY_NAME_MAX_LENGTH = MAPS_BASE_NAME_MAX_LEN;
32 const gsize _MAPS_PLACE_CATEGORY_URL_MAX_LENGTH = MAPS_BASE_URL_MAX_LEN;
33
34 /*----------------------------------------------------------------------------*/
35
36 EXPORT_API int maps_place_category_create(maps_place_category_h *place)
37 {
38         if (!maps_condition_check_maps_feature())
39                 return MAPS_ERROR_NOT_SUPPORTED;
40         if (!place)
41                 return MAPS_ERROR_INVALID_PARAMETER;
42         *place = g_slice_new0(maps_place_category_s);
43
44         if (*place == NULL) {
45                 //LCOV_EXCL_START
46                 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
47                 return MAPS_ERROR_OUT_OF_MEMORY;
48                 //LCOV_EXCL_STOP
49         }
50
51         return MAPS_ERROR_NONE;
52 }
53
54 EXPORT_API int maps_place_category_destroy(maps_place_category_h place)
55 {
56         if (!maps_condition_check_maps_feature())
57                 return MAPS_ERROR_NOT_SUPPORTED;
58         if (!place)
59                 return MAPS_ERROR_INVALID_PARAMETER;
60         int error = MAPS_ERROR_NONE;
61
62         maps_place_category_s *c = (maps_place_category_s *) place;
63
64         if (c->id)
65                 g_free(c->id);
66         if (c->name)
67                 g_free(c->name);
68         if (c->url)
69                 g_free(c->url);
70
71         g_slice_free(maps_place_category_s, place);
72         return error;
73 }
74
75 EXPORT_API int maps_place_category_clone(const maps_place_category_h origin,
76                                          maps_place_category_h *cloned)
77 {
78         if (!maps_condition_check_maps_feature())
79                 return MAPS_ERROR_NOT_SUPPORTED;
80         if (!cloned || !origin)
81                 return MAPS_ERROR_INVALID_PARAMETER;
82
83         int error = MAPS_ERROR_NONE;
84
85         do {
86                 error = maps_place_category_create(cloned);
87                 if (error != MAPS_ERROR_NONE)
88                         return error;
89
90                 maps_place_category_s *c = (maps_place_category_s *) origin;
91
92                 if (c->id) {
93                         error = maps_place_category_set_id(*cloned, c->id);
94                         if (error != MAPS_ERROR_NONE)
95                                 break;
96                 }
97
98                 if (c->name) {
99                         error = maps_place_category_set_name(*cloned, c->name);
100                         if (error != MAPS_ERROR_NONE)
101                                 break;
102                 }
103
104                 if (c->url) {
105                         error = maps_place_category_set_url(*cloned, c->url);
106                         if (error != MAPS_ERROR_NONE)
107                                 break;
108                 }
109
110                 return MAPS_ERROR_NONE;
111         } while (false);
112
113         //LCOV_EXCL_START
114         maps_place_category_destroy(*cloned);
115         *cloned = NULL;
116         return error;
117         //LCOV_EXCL_STOP
118 }
119
120 /*----------------------------------------------------------------------------*/
121
122 EXPORT_API int maps_place_category_get_name(const maps_place_category_h place, char **name)
123 {
124         if (!maps_condition_check_maps_feature())
125                 return MAPS_ERROR_NOT_SUPPORTED;
126         if (!place || !name)
127                 return MAPS_ERROR_INVALID_PARAMETER;
128         if (!((maps_place_category_s *) place)->name)
129                 return MAPS_ERROR_NOT_FOUND;
130         return maps_get_string(((maps_place_category_s *) place)->name,
131                 _MAPS_PLACE_CATEGORY_NAME_MAX_LENGTH, name);
132 }
133
134 EXPORT_API int maps_place_category_get_id(const maps_place_category_h place, char **id)
135 {
136         if (!maps_condition_check_maps_feature())
137                 return MAPS_ERROR_NOT_SUPPORTED;
138         if (!place || !id)
139                 return MAPS_ERROR_INVALID_PARAMETER;
140         if (!((maps_place_category_s *) place)->id)
141                 return MAPS_ERROR_NOT_FOUND;
142         return maps_get_string(((maps_place_category_s *) place)->id,
143                 _MAPS_PLACE_CATEGORY_ID_MAX_LENGTH, id);
144 }
145
146 EXPORT_API int maps_place_category_get_url(const maps_place_category_h place, char **url)
147 {
148         if (!maps_condition_check_maps_feature())
149                 return MAPS_ERROR_NOT_SUPPORTED;
150         if (!place || !url)
151                 return MAPS_ERROR_INVALID_PARAMETER;
152         if (!((maps_place_category_s *) place)->url)
153                 return MAPS_ERROR_NOT_FOUND;
154         return maps_get_string(((maps_place_category_s *) place)->url,
155                 _MAPS_PLACE_CATEGORY_URL_MAX_LENGTH, url);
156 }
157
158 /*----------------------------------------------------------------------------*/
159
160 EXPORT_API int maps_place_category_set_id(maps_place_category_h place, const char *id)
161 {
162         if (!maps_condition_check_maps_feature())
163                 return MAPS_ERROR_NOT_SUPPORTED;
164         if (!place || !id)
165                 return MAPS_ERROR_INVALID_PARAMETER;
166         return maps_set_string(id, _MAPS_PLACE_CATEGORY_ID_MAX_LENGTH,
167                 &((maps_place_category_s *) place)->id);
168 }
169
170 EXPORT_API int maps_place_category_set_name(maps_place_category_h place, const char *name)
171 {
172         if (!maps_condition_check_maps_feature())
173                 return MAPS_ERROR_NOT_SUPPORTED;
174         if (!place || !name)
175                 return MAPS_ERROR_INVALID_PARAMETER;
176         return maps_set_string(name, _MAPS_PLACE_CATEGORY_NAME_MAX_LENGTH,
177                 &((maps_place_category_s *) place)->name);
178 }
179
180 EXPORT_API int maps_place_category_set_url(maps_place_category_h place, const char *url)
181 {
182         if (!maps_condition_check_maps_feature())
183                 return MAPS_ERROR_NOT_SUPPORTED;
184         if (!place || !url)
185                 return MAPS_ERROR_INVALID_PARAMETER;
186         return maps_set_string(url, _MAPS_PLACE_CATEGORY_URL_MAX_LENGTH,
187                 &((maps_place_category_s *) place)->url);
188 }