GCC Code Coverage Report


Directory: src/
File: src/drive/msg-drive-item-file.c
Date: 2024-05-18 00:53:33
Exec Total Coverage
Lines: 31 31 100.0%
Functions: 10 10 100.0%
Branches: 14 15 93.3%

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 "drive/msg-drive-item-file.h"
18 #include "msg-error.h"
19 #include "msg-json-utils.h"
20
21 struct _MsgDriveItemFile {
22 MsgDriveItem parent_instance;
23 char *mime_type;
24 char *thumbnail_uri;
25 };
26
27
6/7
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 52 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 52 times.
116 G_DEFINE_TYPE (MsgDriveItemFile, msg_drive_item_file, MSG_TYPE_DRIVE_ITEM);
28
29 static void
30 24 msg_drive_item_file_finalize (GObject *_self)
31 {
32 24 MsgDriveItemFile *self = MSG_DRIVE_ITEM_FILE (_self);
33
34
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 7 times.
24 g_clear_pointer (&self->mime_type, g_free);
35
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 23 times.
24 g_clear_pointer (&self->thumbnail_uri, g_free);
36
37 24 G_OBJECT_CLASS (msg_drive_item_file_parent_class)->finalize (_self);
38 24 }
39
40 static void
41 25 msg_drive_item_file_init (__attribute__ ((unused)) MsgDriveItemFile *self)
42 {
43 25 }
44
45 static void
46 2 msg_drive_item_file_class_init (MsgDriveItemFileClass *klass)
47 {
48 2 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
49
50 2 gobject_class->finalize = msg_drive_item_file_finalize;
51 2 }
52
53 /**
54 * msg_drive_item_file_new:
55 *
56 * Creates a new `MsgDriveItemFile`.
57 *
58 * Returns: the newly created `MsgDriveItemFile`
59 */
60 MsgDriveItemFile *
61 25 msg_drive_item_file_new (void)
62 {
63 25 return g_object_new (MSG_TYPE_DRIVE_ITEM_FILE, NULL);
64 }
65
66 /**
67 * msg_drive_item_file_new_from_json:
68 * @object: The json object to parse
69 *
70 * Creates a new `MsgDriveItemFile` from json response object.
71 *
72 * Returns: the newly created `MsgDriveItemFile`
73 */
74 MsgDriveItemFile *
75 18 msg_drive_item_file_new_from_json (JsonObject *object)
76 {
77 18 MsgDriveItemFile *self = msg_drive_item_file_new ();
78 18 JsonObject *file = json_object_get_object_member (object, "file");
79
80 18 self->mime_type = g_strdup (msg_json_object_get_string (file, "mimeType"));
81
82
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 16 times.
18 if (json_object_has_member (object, "thumbnails")) {
83 JsonArray *array;
84 guint array_length;
85 guint index;
86
87 2 array = json_object_get_array_member (object, "thumbnails");
88 2 array_length = json_array_get_length (array);
89
90
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 for (index = 0; index < array_length; index++) {
91 JsonObject *item_object;
92 JsonObject *small;
93
94 /* TODO: Extract best thumbnail */
95 1 item_object = json_array_get_object_element (array, index);
96 1 small = json_object_get_object_member (item_object, "small");
97
98 2 self->thumbnail_uri = g_strdup (msg_json_object_get_string (small, "url"));
99 }
100 }
101
102 18 return self;
103 }
104
105 /**
106 * msg_drive_item_file_get_mime_type:
107 * @self: a drive item file
108 *
109 * Gets mime type of drive item file.
110 *
111 * Returns: (transfer none): mime type of drive item file
112 */
113 const char *
114 1 msg_drive_item_file_get_mime_type (MsgDriveItemFile *self)
115 {
116 1 return self->mime_type;
117 }
118
119 /**
120 * msg_drive_item_file_get_thumbnail_uri:
121 * @self: a drive item file
122 *
123 * Gets thumbnail uri of drive item file.
124 *
125 * Returns: (transfer none): thumbnail uri of drive item file
126 */
127 const char *
128 1 msg_drive_item_file_get_thumbnail_uri (MsgDriveItemFile *self)
129 {
130 1 return self->thumbnail_uri;
131 }
132