Add LCOV remarkers to increase line coverage rate
[platform/core/api/maps-service.git] / src / api / maps_place_rating.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_rating_plugin.h"
19 #include "maps_util.h"
20 #include "maps_condition.h"
21
22 typedef struct _maps_place_rating_s
23 {
24         int count;
25         double average;
26 } maps_place_rating_s;
27
28 /*----------------------------------------------------------------------------*/
29
30 EXPORT_API int maps_place_rating_create(maps_place_rating_h *place)
31 {
32         if (!maps_condition_check_maps_feature())
33                 return MAPS_ERROR_NOT_SUPPORTED;
34         if (!place)
35                 return MAPS_ERROR_INVALID_PARAMETER;
36         *place = (maps_place_rating_h) g_slice_new0(maps_place_rating_s);
37
38         if (*place == NULL) {
39                 //LCOV_EXCL_START
40                 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
41                 return MAPS_ERROR_OUT_OF_MEMORY;
42                 //LCOV_EXCL_STOP
43         }
44
45         return MAPS_ERROR_NONE;
46 }
47
48 EXPORT_API int maps_place_rating_destroy(maps_place_rating_h place)
49 {
50         if (!maps_condition_check_maps_feature())
51                 return MAPS_ERROR_NOT_SUPPORTED;
52         if (!place)
53                 return MAPS_ERROR_INVALID_PARAMETER;
54         g_slice_free(maps_place_rating_s, place);
55         return MAPS_ERROR_NONE;
56 }
57
58 EXPORT_API int maps_place_rating_clone(const maps_place_rating_h origin,
59                                                                 maps_place_rating_h *cloned)
60 {
61         if (!maps_condition_check_maps_feature())
62                 return MAPS_ERROR_NOT_SUPPORTED;
63         if (!cloned || !origin)
64                 return MAPS_ERROR_INVALID_PARAMETER;
65
66         int error = MAPS_ERROR_NONE;
67         do {
68                 error = maps_place_rating_create(cloned);
69                 if (!(*cloned) || (error != MAPS_ERROR_NONE))
70                         break;
71
72                 maps_place_rating_s *r = (maps_place_rating_s *) origin;
73
74                 error = maps_place_rating_set_count(*cloned, r->count);
75                 if (error != MAPS_ERROR_NONE)
76                         break;
77
78                 error = maps_place_rating_set_average(*cloned, r->average);
79                 if (error != MAPS_ERROR_NONE)
80                         break;
81
82                 return MAPS_ERROR_NONE;
83         } while (false);
84
85         //LCOV_EXCL_START
86         maps_place_rating_destroy(*cloned);
87         *cloned = NULL;
88         return error;
89         //LCOV_EXCL_STOP
90 }
91
92 /*----------------------------------------------------------------------------*/
93
94 EXPORT_API int maps_place_rating_get_count(const maps_place_rating_h place,
95                                                                 int *count)
96 {
97         if (!maps_condition_check_maps_feature())
98                 return MAPS_ERROR_NOT_SUPPORTED;
99         if (!place || !count)
100                 return MAPS_ERROR_INVALID_PARAMETER;
101         *count = ((maps_place_rating_s *) place)->count;
102         return MAPS_ERROR_NONE;
103 }
104
105 EXPORT_API int maps_place_rating_get_average(const maps_place_rating_h place,
106                                                                 double *average)
107 {
108         if (!maps_condition_check_maps_feature())
109                 return MAPS_ERROR_NOT_SUPPORTED;
110         if (!place || !average)
111                 return MAPS_ERROR_INVALID_PARAMETER;
112         *average = ((maps_place_rating_s *) place)->average;
113         return MAPS_ERROR_NONE;
114 }
115
116 /*----------------------------------------------------------------------------*/
117
118 EXPORT_API int maps_place_rating_set_count(maps_place_rating_h place,
119                                                                 const int count)
120 {
121         if (!maps_condition_check_maps_feature())
122                 return MAPS_ERROR_NOT_SUPPORTED;
123         if (!place || (count < 0))
124                 return MAPS_ERROR_INVALID_PARAMETER;
125         ((maps_place_rating_s *) place)->count = count;
126         return MAPS_ERROR_NONE;
127 }
128
129 EXPORT_API int maps_place_rating_set_average(maps_place_rating_h place,
130                                                                 const double average)
131 {
132         if (!maps_condition_check_maps_feature())
133                 return MAPS_ERROR_NOT_SUPPORTED;
134         if (!place || (average < 0))
135                 return MAPS_ERROR_INVALID_PARAMETER;
136         ((maps_place_rating_s *) place)->average = average;
137         return MAPS_ERROR_NONE;
138 }