GCC Code Coverage Report


Directory: src/
File: src/contact/msg-contact.c
Date: 2024-07-13 00:54:47
Exec Total Coverage
Lines: 40 40 100.0%
Functions: 14 14 100.0%
Branches: 14 19 73.7%

Line Branch Exec Source
1 /* Copyright 2022-2024 Jan-Michael Brummer <jan-michael.brummer1@volkswagen.de>
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU Lesser General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 #include "contact/msg-contact.h"
18 #include "msg-error.h"
19 #include "msg-json-utils.h"
20
21 /**
22 * MsgContact:
23 *
24 * Handling of contact specific functions.
25 *
26 * Details: https://learn.microsoft.com/en-us/graph/api/resources/contact?view=graph-rest-1.0
27 */
28
29 struct _MsgContact {
30 GObject parent_instance;
31
32 char *id;
33 char *name;
34 char *given_name;
35 char *surname;
36 };
37
38
6/7
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 6 times.
24 G_DEFINE_TYPE (MsgContact, msg_contact, G_TYPE_OBJECT);
39
40 static void
41 2 msg_contact_finalize (GObject *object)
42 {
43 2 MsgContact *self = MSG_CONTACT (object);
44
45
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 g_clear_pointer (&self->id, g_free);
46
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 g_clear_pointer (&self->name, g_free);
47
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 g_clear_pointer (&self->given_name, g_free);
48
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 g_clear_pointer (&self->surname, g_free);
49
50 2 G_OBJECT_CLASS (msg_contact_parent_class)->finalize (object);
51 2 }
52
53 static void
54 3 msg_contact_init (__attribute__ ((unused)) MsgContact *self)
55 {
56 3 }
57
58 static void
59 2 msg_contact_class_init (MsgContactClass *class)
60 {
61 2 GObjectClass *object_class = G_OBJECT_CLASS (class);
62
63 2 object_class->finalize = msg_contact_finalize;
64 2 }
65
66 /**
67 * msg_contact_new:
68 *
69 * Creates a new `MsgContact`.
70 *
71 * Returns: the newly created `MsgContact`
72 */
73 MsgContact *
74 3 msg_contact_new (void)
75 {
76 3 return g_object_new (MSG_TYPE_CONTACT, NULL);
77 }
78
79 /**
80 * msg_contact_new_from_json:
81 * @json_object: The json object to parse
82 * @error: a #GError
83 *
84 * Creates a new `MsgContact` from json response object.
85 *
86 * Returns: the newly created `MsgContact`
87 */
88 MsgContact *
89 2 msg_contact_new_from_json (JsonObject *json_object,
90 __attribute__ ((unused)) GError **error)
91 {
92 MsgContact *self;
93
94 2 self = msg_contact_new ();
95 2 self->name = g_strdup (msg_json_object_get_string (json_object, "displayName"));
96 2 self->given_name = g_strdup (msg_json_object_get_string (json_object, "givenName"));
97 2 self->surname = g_strdup (msg_json_object_get_string (json_object, "surname"));
98 2 self->id = g_strdup (msg_json_object_get_string (json_object, "id"));
99
100 2 return self;
101 }
102
103 /**
104 * msg_contact_get_name:
105 * @self: a contact
106 *
107 * Returns: (transfer none): name of contact
108 */
109 const char *
110 1 msg_contact_get_name (MsgContact *self)
111 {
112 1 return self->name;
113 }
114
115 /**
116 * msg_contact_set_given_name:
117 * @self: a #MsgContact
118 * @given_name: new give name
119 *
120 * Sets contacts given name
121 */
122 void
123 1 msg_contact_set_given_name (MsgContact *self,
124 const char *given_name)
125 {
126
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 g_clear_pointer (&self->given_name, g_free);
127 1 self->given_name = g_strdup (given_name);
128 1 }
129
130 /**
131 * msg_contact_get_given_name:
132 * @self: a #MsgContact
133 *
134 * Gets given name.
135 *
136 * Returns: (transfer none): given name
137 */
138 const char *
139 2 msg_contact_get_given_name (MsgContact *self)
140 {
141 2 return self->given_name;
142 }
143
144 /**
145 * msg_contact_set_surname:
146 * @self: a #MsgContact
147 * @surname: new sirname
148 *
149 * Sets contacts surname
150 */
151 void
152 1 msg_contact_set_surname (MsgContact *self,
153 const char *surname)
154 {
155
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 g_clear_pointer (&self->surname, g_free);
156 1 self->surname = g_strdup (surname);
157 1 }
158
159 /**
160 * msg_contact_get_surname:
161 * @self: a #MsgContact
162 *
163 * Gets surname.
164 *
165 * Returns: (transfer none): surname
166 */
167 const char *
168 2 msg_contact_get_surname (MsgContact *self)
169 {
170 2 return self->surname;
171 }
172
173 /**
174 * msg_contact_get_id:
175 * @self: a #MsgContact
176 *
177 * Gets ID
178 *
179 * Returns: (transfer none): identifier
180 */
181 const char *
182 3 msg_contact_get_id (MsgContact *self)
183 {
184 3 return self->id;
185 }
186