Add LCOV remarkers to increase line coverage rate
[platform/core/api/maps-service.git] / src / api / maps_place_review.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_place_review_plugin.h"
19 #include "maps_place_media_plugin.h"
20 #include "maps_place_link_object_plugin.h"
21 #include "maps_util.h"
22 #include "maps_condition.h"
23
24 typedef struct _maps_place_review_s
25 {
26         char *date;
27         char *title;
28         double rating;
29         char *description;
30         char *language;
31         maps_place_media_h media;
32         maps_place_link_object_h user;
33 } maps_place_review_s;
34
35 const gsize _MAPS_PLACE_REVIEW_DATE_MAX_LENGTH = MAPS_BASE_DATE_MAX_LEN;
36 const gsize _MAPS_PLACE_REVIEW_TITLE_MAX_LENGTH = MAPS_BASE_NAME_MAX_LEN;
37 const gsize _MAPS_PLACE_REVIEW_DESCRIPTION_MAX_LENGTH = MAPS_BASE_DESC_MAX_LEN;
38 const gsize _MAPS_PLACE_REVIEW_LANGUAGE_MAX_LENGTH = MAPS_BASE_TYPE_MAX_LEN;
39
40 /*----------------------------------------------------------------------------*/
41
42 EXPORT_API int maps_place_review_create(maps_place_review_h *place)
43 {
44         if (!maps_condition_check_maps_feature())
45                 return MAPS_ERROR_NOT_SUPPORTED;
46         if (!place)
47                 return MAPS_ERROR_INVALID_PARAMETER;
48         *place = (maps_place_review_h) g_slice_new0(maps_place_review_s);
49
50         if (*place == NULL) {
51                 //LCOV_EXCL_START
52                 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
53                 return MAPS_ERROR_OUT_OF_MEMORY;
54                 //LCOV_EXCL_STOP
55         }
56
57         return MAPS_ERROR_NONE;
58 }
59
60 EXPORT_API int maps_place_review_destroy(maps_place_review_h place)
61 {
62         if (!maps_condition_check_maps_feature())
63                 return MAPS_ERROR_NOT_SUPPORTED;
64         if (!place)
65                 return MAPS_ERROR_INVALID_PARAMETER;
66
67         maps_place_review_s *r = (maps_place_review_s *) place;
68
69         if (r->date)
70                 g_free(r->date);
71         if (r->title)
72                 g_free(r->title);
73         if (r->description)
74                 g_free(r->description);
75         if (r->language)
76                 g_free(r->language);
77
78         if (r->media)
79                 maps_place_media_destroy(r->media);
80         if (r->user)
81                 maps_place_link_object_destroy(r->user);
82
83         g_slice_free(maps_place_review_s, place);
84         return MAPS_ERROR_NONE;
85 }
86
87 EXPORT_API int maps_place_review_clone(const maps_place_review_h origin,
88                                        maps_place_review_h *cloned)
89 {
90         if (!maps_condition_check_maps_feature())
91                 return MAPS_ERROR_NOT_SUPPORTED;
92         if (!cloned || !origin)
93                 return MAPS_ERROR_INVALID_PARAMETER;
94
95         int error = MAPS_ERROR_NONE;
96         do {
97                 error = maps_place_review_create(cloned);
98                 if (!(*cloned) || (error != MAPS_ERROR_NONE))
99                         break;
100
101                 maps_place_review_s *r = (maps_place_review_s *) origin;
102
103                 if (r->date) {
104                         error = maps_place_review_set_date(*cloned, r->date);
105                         if (error != MAPS_ERROR_NONE)
106                                 break;
107                 }
108
109                 if (r->title) {
110                         error = maps_place_review_set_title(*cloned, r->title);
111                         if (error != MAPS_ERROR_NONE)
112                                 break;
113                 }
114
115                 ((maps_place_review_s *) (*cloned))->rating = r->rating;
116
117                 if (r->description) {
118                         error = maps_place_review_set_description(*cloned, r->description);
119                         if (error != MAPS_ERROR_NONE)
120                                 break;
121                 }
122                 if (r->language) {
123                         error = maps_place_review_set_language(*cloned, r->language);
124                         if (error != MAPS_ERROR_NONE)
125                                 break;
126                 }
127                 if (r->media) {
128                         error = maps_place_review_set_media(*cloned, r->media);
129                         if (error != MAPS_ERROR_NONE)
130                                 break;
131                 }
132                 if (r->user) {
133                         error = maps_place_review_set_user_link(*cloned, r->user);
134                         if (error != MAPS_ERROR_NONE)
135                                 break;
136                 }
137
138                 return MAPS_ERROR_NONE;
139         } while (false);
140
141         //LCOV_EXCL_START
142         maps_place_review_destroy(*cloned);
143         *cloned = NULL;
144         return error;
145         //LCOV_EXCL_STOP
146 }
147
148 /*----------------------------------------------------------------------------*/
149
150 EXPORT_API int maps_place_review_get_date(const maps_place_review_h place,
151                                                                 char **date)
152 {
153         if (!maps_condition_check_maps_feature())
154                 return MAPS_ERROR_NOT_SUPPORTED;
155         if (!place || !date)
156                 return MAPS_ERROR_INVALID_PARAMETER;
157         if (!((maps_place_review_s *) place)->date)
158                 return MAPS_ERROR_NOT_FOUND;
159         return maps_get_string(((maps_place_review_s *) place)->date,
160                 _MAPS_PLACE_REVIEW_DATE_MAX_LENGTH, date);
161 }
162
163 EXPORT_API int maps_place_review_get_title(const maps_place_review_h place,
164                                                                 char **title)
165 {
166         if (!maps_condition_check_maps_feature())
167                 return MAPS_ERROR_NOT_SUPPORTED;
168         if (!place || !title)
169                 return MAPS_ERROR_INVALID_PARAMETER;
170         if (!((maps_place_review_s *) place)->title)
171                 return MAPS_ERROR_NOT_FOUND;
172         return maps_get_string(((maps_place_review_s *) place)->title,
173                 _MAPS_PLACE_REVIEW_TITLE_MAX_LENGTH, title);
174 }
175
176 EXPORT_API int maps_place_review_get_rating(const maps_place_review_h place,
177                                                                 double *rating)
178 {
179         if (!maps_condition_check_maps_feature())
180                 return MAPS_ERROR_NOT_SUPPORTED;
181         if (!place || !rating)
182                 return MAPS_ERROR_INVALID_PARAMETER;
183         if (!((maps_place_review_s *) place)->rating)
184                 return MAPS_ERROR_NOT_FOUND;
185         *rating = ((maps_place_review_s *) place)->rating;
186         return MAPS_ERROR_NONE;
187 }
188
189 EXPORT_API int maps_place_review_get_description(const maps_place_review_h place,
190                                                                 char **description)
191 {
192         if (!maps_condition_check_maps_feature())
193                 return MAPS_ERROR_NOT_SUPPORTED;
194         if (!place || !description)
195                 return MAPS_ERROR_INVALID_PARAMETER;
196         if (!((maps_place_review_s *) place)->description)
197                 return MAPS_ERROR_NOT_FOUND;
198         return maps_get_string(((maps_place_review_s *) place)->description,
199                 _MAPS_PLACE_REVIEW_DESCRIPTION_MAX_LENGTH, description);
200 }
201
202 EXPORT_API int maps_place_review_get_language(const maps_place_review_h place,
203                                                                 char ** language)
204 {
205         if (!maps_condition_check_maps_feature())
206                 return MAPS_ERROR_NOT_SUPPORTED;
207         if (!place || !language)
208                 return MAPS_ERROR_INVALID_PARAMETER;
209         if (!((maps_place_review_s *) place)->language)
210                 return MAPS_ERROR_NOT_FOUND;
211         return maps_get_string(((maps_place_review_s *) place)->language,
212                 _MAPS_PLACE_REVIEW_LANGUAGE_MAX_LENGTH, language);
213 }
214
215 EXPORT_API int maps_place_review_get_media(const maps_place_review_h place,
216                                                                 maps_place_media_h *media)
217 {
218         if (!maps_condition_check_maps_feature())
219                 return MAPS_ERROR_NOT_SUPPORTED;
220         if (!place || !media)
221                 return MAPS_ERROR_INVALID_PARAMETER;
222         if (!((maps_place_review_s *) place)->media)
223                 return MAPS_ERROR_NOT_FOUND;
224         return maps_place_media_clone(((maps_place_review_s *) place)->media,
225                 media);
226 }
227
228 EXPORT_API int maps_place_review_get_user_link(const maps_place_review_h place,
229                                                                 maps_place_link_object_h *user)
230 {
231         if (!maps_condition_check_maps_feature())
232                 return MAPS_ERROR_NOT_SUPPORTED;
233         if (!place || !user)
234                 return MAPS_ERROR_INVALID_PARAMETER;
235         if (!((maps_place_review_s *) place)->user)
236                 return MAPS_ERROR_NOT_FOUND;
237         return maps_place_link_object_clone(((maps_place_review_s *) place)->user, user);
238 }
239
240 /*----------------------------------------------------------------------------*/
241
242 EXPORT_API int maps_place_review_set_date(maps_place_review_h place,
243                                                                 const char *date)
244 {
245         if (!maps_condition_check_maps_feature())
246                 return MAPS_ERROR_NOT_SUPPORTED;
247         if (!place || !date)
248                 return MAPS_ERROR_INVALID_PARAMETER;
249         return maps_set_string(date, _MAPS_PLACE_REVIEW_DATE_MAX_LENGTH,
250                 &((maps_place_review_s *) place)->date);
251 }
252
253 EXPORT_API int maps_place_review_set_title(maps_place_review_h place,
254                                                                 const char *title)
255 {
256         if (!maps_condition_check_maps_feature())
257                 return MAPS_ERROR_NOT_SUPPORTED;
258         if (!place || !title)
259                 return MAPS_ERROR_INVALID_PARAMETER;
260         return maps_set_string(title, _MAPS_PLACE_REVIEW_TITLE_MAX_LENGTH,
261                 &((maps_place_review_s *) place)->title);
262 }
263
264 EXPORT_API int maps_place_review_set_rating(maps_place_review_h place,
265                                                                 const double rating)
266 {
267         if (!maps_condition_check_maps_feature())
268                 return MAPS_ERROR_NOT_SUPPORTED;
269         if (!place)
270                 return MAPS_ERROR_INVALID_PARAMETER;
271         ((maps_place_review_s *) place)->rating = rating;
272         return MAPS_ERROR_NONE;
273 }
274
275 EXPORT_API int maps_place_review_set_description(maps_place_review_h place,
276                                                                 const char *description)
277 {
278         if (!maps_condition_check_maps_feature())
279                 return MAPS_ERROR_NOT_SUPPORTED;
280         if (!place || !description)
281                 return MAPS_ERROR_INVALID_PARAMETER;
282         return maps_set_string(description,
283                 _MAPS_PLACE_REVIEW_DESCRIPTION_MAX_LENGTH,
284                 &((maps_place_review_s *) place)->description);
285 }
286
287 EXPORT_API int maps_place_review_set_language(maps_place_review_h place,
288                                                                 const char *language)
289 {
290         if (!maps_condition_check_maps_feature())
291                 return MAPS_ERROR_NOT_SUPPORTED;
292         if (!place || !language)
293                 return MAPS_ERROR_INVALID_PARAMETER;
294         return maps_set_string(language, _MAPS_PLACE_REVIEW_LANGUAGE_MAX_LENGTH,
295                 &((maps_place_review_s *) place)->language);
296 }
297
298 EXPORT_API int maps_place_review_set_media(maps_place_review_h place,
299                                                                 const maps_place_media_h media)
300 {
301         if (!maps_condition_check_maps_feature())
302                 return MAPS_ERROR_NOT_SUPPORTED;
303         if (!place || !media)
304                 return MAPS_ERROR_INVALID_PARAMETER;
305         maps_place_review_s *r = (maps_place_review_s *) place;
306         if (r->media)
307                 maps_place_media_destroy(r->media);
308         return maps_place_media_clone(media, &r->media);
309 }
310
311 EXPORT_API int maps_place_review_set_user_link(maps_place_review_h place,
312                                                                 const maps_place_link_object_h user)
313 {
314         if (!maps_condition_check_maps_feature())
315                 return MAPS_ERROR_NOT_SUPPORTED;
316         if (!place || !user)
317                 return MAPS_ERROR_INVALID_PARAMETER;
318         maps_place_review_s *r = (maps_place_review_s *) place;
319         if (r->user)
320                 maps_place_link_object_destroy(r->user);
321         return maps_place_link_object_clone(user, &r->user);
322 }