GCC Code Coverage Report


Directory: src/
File: src/message/msg-message.c
Date: 2024-07-13 00:54:47
Exec Total Coverage
Lines: 37 37 100.0%
Functions: 13 13 100.0%
Branches: 16 19 84.2%

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 "message/msg-message.h"
18 #include "msg-error.h"
19 #include "msg-json-utils.h"
20
21 /**
22 * MsgMessage:
23 *
24 * Handling of message specific functions.
25 *
26 * Details: https://learn.microsoft.com/en-us/graph/api/resources/message?view=graph-rest-1.0
27 */
28
29 struct _MsgMessage {
30 GObject parent_instance;
31
32 char *id;
33 char *subject;
34 char *body_preview;
35 char *body;
36 };
37
38
6/7
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 8 times.
28 G_DEFINE_TYPE (MsgMessage, msg_message, G_TYPE_OBJECT);
39
40 static void
41 3 msg_message_finalize (GObject *object)
42 {
43 3 MsgMessage *self = MSG_MESSAGE (object);
44
45
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 g_clear_pointer (&self->subject, g_free);
46
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 g_clear_pointer (&self->body_preview, g_free);
47
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 g_clear_pointer (&self->body, g_free);
48
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 g_clear_pointer (&self->id, g_free);
49
50 3 G_OBJECT_CLASS (msg_message_parent_class)->finalize (object);
51 3 }
52
53 static void
54 4 msg_message_init (__attribute__ ((unused)) MsgMessage *self)
55 {
56 4 }
57
58 static void
59 2 msg_message_class_init (MsgMessageClass *class)
60 {
61 2 GObjectClass *object_class = G_OBJECT_CLASS (class);
62
63 2 object_class->finalize = msg_message_finalize;
64 2 }
65
66 /**
67 * msg_message_new:
68 *
69 * Creates a new `MsgMessage`.
70 *
71 * Returns: the newly created `MsgMessage`
72 */
73 MsgMessage *
74 4 msg_message_new (void)
75 {
76 4 return g_object_new (MSG_TYPE_MESSAGE, NULL);
77 }
78
79 /**
80 * msg_message_new_from_json:
81 * @json_object: The json object to parse
82 * @error: a #GError
83 *
84 * Creates a new `MsgMessage` from json response object.
85 *
86 * Returns: the newly created `MsgMessage`
87 */
88 MsgMessage *
89 2 msg_message_new_from_json (JsonObject *json_object,
90 __attribute__ ((unused)) GError **error)
91 {
92 MsgMessage *self;
93
94 2 self = msg_message_new ();
95 2 self->subject = g_strdup (msg_json_object_get_string (json_object, "subject"));
96 2 self->body_preview = g_strdup (msg_json_object_get_string (json_object, "bodyPreview"));
97 2 self->id = g_strdup (msg_json_object_get_string (json_object, "id"));
98
99 2 return self;
100 }
101
102 /**
103 * msg_message_get_subject:
104 * @self: a message
105 *
106 * Returns: (transfer none): subject of message
107 */
108 const char *
109 2 msg_message_get_subject (MsgMessage *self)
110 {
111 2 return self->subject;
112 }
113
114 /**
115 * msg_message_get_body_preview:
116 * @self: a message
117 *
118 * Returns: (transfer none): body preview of message
119 */
120 const char *
121 1 msg_message_get_body_preview (MsgMessage *self)
122 {
123 1 return self->body_preview;
124 }
125
126 gboolean
127 1 msg_message_set_body (MsgMessage *self,
128 const char *body)
129 {
130
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 g_clear_pointer (&self->body, g_free);
131 1 self->body = g_strdup (body);
132 1 return TRUE;
133 }
134
135 gboolean
136 1 msg_message_set_subject (MsgMessage *self,
137 const char *subject)
138 {
139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 g_clear_pointer (&self->subject, g_free);
140 1 self->subject = g_strdup (subject);
141 1 return TRUE;
142 }
143
144 const char *
145 3 msg_message_get_id (MsgMessage *self)
146 {
147 3 return self->id;
148 }
149