GCC Code Coverage Report


Directory: src/
File: src/user/msg-user.c
Date: 2024-05-18 00:53:33
Exec Total Coverage
Lines: 20 20 100.0%
Functions: 9 9 100.0%
Branches: 8 9 88.9%

Line Branch Exec Source
1 /* Copyright 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 "user/msg-user.h"
18 #include "msg-error.h"
19 #include "msg-json-utils.h"
20
21 /**
22 * MsgUser:
23 *
24 * Handling of user specific functions.
25 */
26
27 struct _MsgUser {
28 GObject parent_instance;
29
30 char *mail;
31 };
32
33
6/7
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 3 times.
18 G_DEFINE_TYPE (MsgUser, msg_user, G_TYPE_OBJECT);
34
35 static void
36 2 msg_user_finalize (GObject *object)
37 {
38 2 MsgUser *self = MSG_USER (object);
39
40
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 g_clear_pointer (&self->mail, g_free);
41
42 2 G_OBJECT_CLASS (msg_user_parent_class)->finalize (object);
43 2 }
44
45 static void
46 2 msg_user_init (__attribute__ ((unused)) MsgUser *self)
47 {
48 2 }
49
50 static void
51 2 msg_user_class_init (MsgUserClass *class)
52 {
53 2 GObjectClass *object_class = G_OBJECT_CLASS (class);
54
55 2 object_class->finalize = msg_user_finalize;
56 2 }
57
58 /**
59 * msg_user_new:
60 *
61 * Creates a new `MsgUser`.
62 *
63 * Returns: the newly created `MsgUser`
64 */
65 MsgUser *
66 2 msg_user_new (void)
67 {
68 2 return g_object_new (MSG_TYPE_USER, NULL);
69 }
70
71 /**
72 * msg_user_new_from_json:
73 * @json_object: The json object to parse
74 * @error: a #GError
75 *
76 * Creates a new `MsgUser` from json response object.
77 *
78 * Returns: the newly created `MsgUser`
79 */
80 MsgUser *
81 1 msg_user_new_from_json (JsonObject *json_object,
82 __attribute__ ((unused)) GError **error)
83 {
84 MsgUser *self;
85
86 1 self = msg_user_new ();
87 1 self->mail = g_strdup (msg_json_object_get_string (json_object, "mail"));
88
89 1 return self;
90 }
91
92 /**
93 * msg_user_get_mail:
94 * @self: a user
95 *
96 * Returns: (transfer none): mail of user or %NULL if not existing
97 */
98 const char *
99 1 msg_user_get_mail (MsgUser *self)
100 {
101 1 return self->mail;
102 }
103