improve line coverage
[platform/core/pim/contacts-service.git] / common / ipc / ctsvc_ipc_simple_contact.c
1 /*
2  * Contacts Service
3  *
4  * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19 #include "ctsvc_internal.h"
20 #include "ctsvc_ipc_marshal.h"
21
22
23 static int __ctsvc_ipc_unmarshal_simple_contact(pims_ipc_data_h ipc_data,
24                 const char *view_uri, contacts_record_h record)
25 {
26         ctsvc_simple_contact_s *pcontact = (ctsvc_simple_contact_s*)record;
27
28         RETV_IF(NULL == ipc_data, CONTACTS_ERROR_NO_DATA);
29         RETV_IF(NULL == record, CONTACTS_ERROR_NO_DATA);
30
31         do {
32                 if (ctsvc_ipc_unmarshal_bool(ipc_data, &pcontact->is_favorite) != CONTACTS_ERROR_NONE)
33                         break;
34                 if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->changed_time) != CONTACTS_ERROR_NONE)
35                         break;
36                 if (ctsvc_ipc_unmarshal_bool(ipc_data, &pcontact->has_phonenumber) != CONTACTS_ERROR_NONE)
37                         break;
38                 if (ctsvc_ipc_unmarshal_bool(ipc_data, &pcontact->has_email) != CONTACTS_ERROR_NONE)
39                         break;
40                 if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->person_id) != CONTACTS_ERROR_NONE)
41                         break;
42                 if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->contact_id) != CONTACTS_ERROR_NONE)
43                         break;
44                 if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->addressbook_id) != CONTACTS_ERROR_NONE)
45                         break;
46                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->image_thumbnail_path) != CONTACTS_ERROR_NONE)
47                         break;
48                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->ringtone_path) != CONTACTS_ERROR_NONE)
49                         break;
50                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->vibration) != CONTACTS_ERROR_NONE)
51                         break;
52                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->message_alert) != CONTACTS_ERROR_NONE)
53                         break;
54                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->display_name) != CONTACTS_ERROR_NONE)
55                         break;
56                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->uid) != CONTACTS_ERROR_NONE)
57                         break;
58                 if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->display_source_type) != CONTACTS_ERROR_NONE)
59                         break;
60
61                 return CONTACTS_ERROR_NONE;
62         } while (0);
63         /* LCOV_EXCL_START */
64         ERR("__ctsvc_ipc_unmarshal_simple_contact() Fail");
65         return CONTACTS_ERROR_INVALID_PARAMETER;
66         /* LCOV_EXCL_STOP */
67 }
68
69 static int __ctsvc_ipc_marshal_simple_contact(const contacts_record_h record,
70                 pims_ipc_data_h ipc_data)
71 {
72         ctsvc_simple_contact_s *pcontact = (ctsvc_simple_contact_s*)record;
73
74         RETV_IF(NULL == ipc_data, CONTACTS_ERROR_NO_DATA);
75         RETV_IF(NULL == pcontact, CONTACTS_ERROR_NO_DATA);
76
77         do {
78                 if (ctsvc_ipc_marshal_bool((pcontact->is_favorite), ipc_data) != CONTACTS_ERROR_NONE)
79                         break;
80                 if (ctsvc_ipc_marshal_int((pcontact->changed_time), ipc_data) != CONTACTS_ERROR_NONE)
81                         break;
82                 if (ctsvc_ipc_marshal_bool((pcontact->has_phonenumber), ipc_data) != CONTACTS_ERROR_NONE)
83                         break;
84                 if (ctsvc_ipc_marshal_bool((pcontact->has_email), ipc_data) != CONTACTS_ERROR_NONE)
85                         break;
86                 if (ctsvc_ipc_marshal_int((pcontact->person_id), ipc_data) != CONTACTS_ERROR_NONE)
87                         break;
88                 if (ctsvc_ipc_marshal_int((pcontact->contact_id), ipc_data) != CONTACTS_ERROR_NONE)
89                         break;
90                 if (ctsvc_ipc_marshal_int((pcontact->addressbook_id), ipc_data) != CONTACTS_ERROR_NONE)
91                         break;
92                 if (ctsvc_ipc_marshal_string((pcontact->image_thumbnail_path), ipc_data) != CONTACTS_ERROR_NONE)
93                         break;
94                 if (ctsvc_ipc_marshal_string((pcontact->ringtone_path), ipc_data) != CONTACTS_ERROR_NONE)
95                         break;
96                 if (ctsvc_ipc_marshal_string((pcontact->vibration), ipc_data) != CONTACTS_ERROR_NONE)
97                         break;
98                 if (ctsvc_ipc_marshal_string((pcontact->message_alert), ipc_data) != CONTACTS_ERROR_NONE)
99                         break;
100                 if (ctsvc_ipc_marshal_string((pcontact->display_name), ipc_data) != CONTACTS_ERROR_NONE)
101                         break;
102                 if (ctsvc_ipc_marshal_string((pcontact->uid), ipc_data) != CONTACTS_ERROR_NONE)
103                         break;
104                 if (ctsvc_ipc_marshal_int((pcontact->display_source_type), ipc_data) != CONTACTS_ERROR_NONE)
105                         break;
106
107                 return CONTACTS_ERROR_NONE;
108         } while (0);
109         /* LCOV_EXCL_START */
110         ERR("_ctsvc_ipc_marshal() Fail");
111         return CONTACTS_ERROR_INVALID_PARAMETER;
112         /* LCOV_EXCL_STOP */
113 }
114
115 ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_simple_contact_plugin_cb = {
116         .unmarshal_record = __ctsvc_ipc_unmarshal_simple_contact,
117         .marshal_record = __ctsvc_ipc_marshal_simple_contact
118 };
119