Add LCOV remarkers to increase line coverage rate
[platform/core/api/maps-service.git] / src / api / maps_place_url.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_url_plugin.h"
19 #include "maps_util.h"
20 #include "maps_condition.h"
21
22 typedef struct _maps_place_url_s
23 {
24         char *path;
25         char *desc;
26 } maps_place_url_s;
27
28 const gsize _MAPS_PLACE_URL_PATH_MAX_LENGTH = MAPS_BASE_URL_MAX_LEN;
29 const gsize _MAPS_PLACE_URL_DESC_MAX_LENGTH = MAPS_BASE_DESC_MAX_LEN;
30
31 /*----------------------------------------------------------------------------*/
32
33 EXPORT_API int maps_place_url_create(maps_place_url_h *place)
34 {
35         if (!maps_condition_check_maps_feature())
36                 return MAPS_ERROR_NOT_SUPPORTED;
37         if (!place)
38                 return MAPS_ERROR_INVALID_PARAMETER;
39
40         *place = (maps_place_url_h) g_slice_new0(maps_place_url_s);
41         if (*place == NULL) {
42                 //LCOV_EXCL_START
43                 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
44                 return MAPS_ERROR_OUT_OF_MEMORY;
45                 //LCOV_EXCL_STOP
46         }
47
48         return MAPS_ERROR_NONE;
49 }
50
51 EXPORT_API int maps_place_url_destroy(maps_place_url_h place)
52 {
53         if (!maps_condition_check_maps_feature())
54                 return MAPS_ERROR_NOT_SUPPORTED;
55         if (!place)
56                 return MAPS_ERROR_INVALID_PARAMETER;
57
58         maps_place_url_s *u = (maps_place_url_s *) place;
59
60         if (u->path)
61                 g_free(u->path);
62         if (u->desc)
63                 g_free(u->desc);
64
65         g_slice_free(maps_place_url_s, place);
66         return MAPS_ERROR_NONE;
67 }
68
69 EXPORT_API int maps_place_url_clone(const maps_place_url_h origin,
70                                                                 maps_place_url_h *cloned)
71 {
72         if (!maps_condition_check_maps_feature())
73                 return MAPS_ERROR_NOT_SUPPORTED;
74         if (!cloned || !origin)
75                 return MAPS_ERROR_INVALID_PARAMETER;
76
77         int error = MAPS_ERROR_NONE;
78         do {
79                 error = maps_place_url_create(cloned);
80                 if (!(*cloned) || (error != MAPS_ERROR_NONE))
81                         break;
82
83                 maps_place_url_s* u = (maps_place_url_s*) origin;
84
85                 if (u->path) {
86                         error = maps_place_url_set_path(*cloned, u->path);
87                         if (error != MAPS_ERROR_NONE)
88                                 break;
89                 }
90
91                 if (u->desc) {
92                         error = maps_place_url_set_description(*cloned,
93                                 u->desc);
94                         if (error != MAPS_ERROR_NONE)
95                                 break;
96                 }
97
98                 return MAPS_ERROR_NONE;
99         } while (false);
100
101         //LCOV_EXCL_START
102         maps_place_url_destroy(*cloned);
103         *cloned = NULL;
104         return error;
105         //LCOV_EXCL_STOP
106 }
107
108 /*----------------------------------------------------------------------------*/
109
110 EXPORT_API int maps_place_url_get_path(const maps_place_url_h place, char **path)
111 {
112         if (!maps_condition_check_maps_feature())
113                 return MAPS_ERROR_NOT_SUPPORTED;
114         if (!place || !path)
115                 return MAPS_ERROR_INVALID_PARAMETER;
116         if (!((maps_place_url_s *) place)->path)
117                 return MAPS_ERROR_NOT_FOUND;
118         return maps_get_string(((maps_place_url_s *) place)->path,
119                 _MAPS_PLACE_URL_PATH_MAX_LENGTH, path);
120 }
121
122 EXPORT_API int maps_place_url_get_description(const maps_place_url_h place, char **desc)
123 {
124         if (!maps_condition_check_maps_feature())
125                 return MAPS_ERROR_NOT_SUPPORTED;
126         if (!place || !desc)
127                 return MAPS_ERROR_INVALID_PARAMETER;
128         if (!((maps_place_url_s *) place)->desc)
129                 return MAPS_ERROR_NOT_FOUND;
130         return maps_get_string(((maps_place_url_s *) place)->desc,
131                 _MAPS_PLACE_URL_DESC_MAX_LENGTH, desc);
132 }
133
134 /*----------------------------------------------------------------------------*/
135
136 EXPORT_API int maps_place_url_set_path(maps_place_url_h place, const char *path)
137 {
138         if (!maps_condition_check_maps_feature())
139                 return MAPS_ERROR_NOT_SUPPORTED;
140         if (!place || !path)
141                 return MAPS_ERROR_INVALID_PARAMETER;
142         return maps_set_string(path, _MAPS_PLACE_URL_PATH_MAX_LENGTH,
143                 &((maps_place_url_s *) place)->path);
144 }
145
146 EXPORT_API int maps_place_url_set_description(maps_place_url_h place,
147                                                                 const char *desc)
148 {
149         if (!maps_condition_check_maps_feature())
150                 return MAPS_ERROR_NOT_SUPPORTED;
151         if (!place || !desc)
152                 return MAPS_ERROR_INVALID_PARAMETER;
153         return maps_set_string(desc, _MAPS_PLACE_URL_DESC_MAX_LENGTH,
154                 &((maps_place_url_s *) place)->desc);
155 }