GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 10.1% 7 / 0 / 69
Functions: 25.0% 3 / 0 / 12
Branches: 31.2% 5 / 0 / 16

shumate/shumate-inspector-page.c
Line Branch Exec Source
1 /*
2 * Copyright (C) 2023 James Westman <james@jwestman.net>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
16 */
17
18 #include <glib/gi18n.h>
19
20 #include "shumate-inspector-page-private.h"
21 #include "shumate-inspector-settings-private.h"
22
23 struct _ShumateInspectorPage {
24 GtkBox parent_instance;
25
26 GObject *object;
27 };
28
29
2/6
shumate_inspector_page_class_intern_init:
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
shumate_inspector_page_get_type:
✓ Branch 2 → 3 taken 1 time.
✗ Branch 2 → 7 not taken.
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 7 not taken.
2 G_DEFINE_FINAL_TYPE(ShumateInspectorPage, shumate_inspector_page, GTK_TYPE_BOX)
30
31 enum {
32 PROP_0,
33 PROP_TITLE,
34 PROP_OBJECT,
35 PROP_SETTINGS,
36 N_PROPS
37 };
38
39 static GParamSpec *props[N_PROPS];
40
41 static void
42 ✗ shumate_inspector_page_dispose (GObject *object)
43 {
44 /* When the inspector is closed, reset all the debug settings */
45 ✗ shumate_inspector_settings_reset (shumate_inspector_settings_get_default ());
46
47 ✗ G_OBJECT_CLASS (shumate_inspector_page_parent_class)->dispose (object);
48 ✗ }
49
50 static void
51 ✗ shumate_inspector_get_property (GObject *object,
52 guint prop_id,
53 GValue *value,
54 GParamSpec *pspec)
55 {
56 ✗ ShumateInspectorPage *self = SHUMATE_INSPECTOR_PAGE (object);
57
58 ✗ switch (prop_id)
59 {
60 ✗ case PROP_TITLE:
61 ✗ g_value_set_string (value, _("Shumate"));
62 ✗ break;
63 ✗ case PROP_OBJECT:
64 ✗ g_value_set_object (value, self->object);
65 ✗ break;
66 ✗ case PROP_SETTINGS:
67 ✗ g_value_set_object (value, shumate_inspector_settings_get_default ());
68 ✗ break;
69 ✗ default:
70 ✗ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
71 }
72 ✗ }
73
74 static void
75 ✗ shumate_inspector_set_property (GObject *object,
76 guint prop_id,
77 const GValue *value,
78 GParamSpec *pspec)
79 {
80 ✗ ShumateInspectorPage *self = SHUMATE_INSPECTOR_PAGE (object);
81
82 ✗ switch (prop_id)
83 {
84 ✗ case PROP_OBJECT:
85 ✗ g_set_object (&self->object, g_value_get_object (value));
86 ✗ break;
87 ✗ default:
88 ✗ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
89 }
90 ✗ }
91
92 static void
93 ✗ on_show_debug_overlay (ShumateInspectorPage *self,
94 GParamSpec *pspec,
95 GtkSwitch *widget)
96 {
97 ✗ ShumateInspectorSettings *settings = shumate_inspector_settings_get_default ();
98 ✗ shumate_inspector_settings_set_show_debug_overlay (settings, gtk_switch_get_active (widget));
99 ✗ }
100
101 static void
102 ✗ on_show_tile_bounds (ShumateInspectorPage *self,
103 GParamSpec *pspec,
104 GtkSwitch *widget)
105 {
106 ✗ ShumateInspectorSettings *settings = shumate_inspector_settings_get_default ();
107 ✗ shumate_inspector_settings_set_show_tile_bounds (settings, gtk_switch_get_active (widget));
108 ✗ }
109
110 static void
111 ✗ on_show_collision_boxes (ShumateInspectorPage *self,
112 GParamSpec *pspec,
113 GtkSwitch *widget)
114 {
115 ✗ ShumateInspectorSettings *settings = shumate_inspector_settings_get_default ();
116 ✗ shumate_inspector_settings_set_show_collision_boxes (settings, gtk_switch_get_active (widget));
117 ✗ }
118
119 static void
120 ✗ shumate_inspector_page_class_init (ShumateInspectorPageClass *klass)
121 {
122 ✗ GObjectClass *object_class = G_OBJECT_CLASS (klass);
123 ✗ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
124
125 ✗ object_class->dispose = shumate_inspector_page_dispose;
126 ✗ object_class->get_property = shumate_inspector_get_property;
127 ✗ object_class->set_property = shumate_inspector_set_property;
128
129 ✗ props[PROP_TITLE] =
130 ✗ g_param_spec_string ("title", NULL, NULL,
131 NULL,
132 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
133
134 ✗ props[PROP_OBJECT] =
135 ✗ g_param_spec_object ("object", NULL, NULL,
136 G_TYPE_OBJECT,
137 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
138
139 ✗ props[PROP_SETTINGS] =
140 ✗ g_param_spec_object ("settings", NULL, NULL,
141 SHUMATE_TYPE_INSPECTOR_SETTINGS,
142 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
143
144 ✗ g_object_class_install_properties (object_class, N_PROPS, props);
145
146 ✗ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/shumate/shumate-inspector-page.ui");
147 ✗ gtk_widget_class_bind_template_callback (widget_class, on_show_debug_overlay);
148 ✗ gtk_widget_class_bind_template_callback (widget_class, on_show_tile_bounds);
149 ✗ gtk_widget_class_bind_template_callback (widget_class, on_show_collision_boxes);
150 ✗ }
151
152 void
153 ✗ shumate_inspector_page_init (ShumateInspectorPage *self)
154 {
155 ✗ gtk_widget_init_template (GTK_WIDGET (self));
156 ✗ }
157
158 static gboolean registered = FALSE;
159
160 void
161 2 shumate_inspector_page_ensure_registered (void)
162 {
163
1/2
✓ Branch 2 → 3 taken 2 times.
✗ Branch 2 → 8 not taken.
2 if (registered)
164 return;
165
166
2/2
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 7 taken 1 time.
2 if (g_io_extension_point_lookup ("gtk-inspector-page"))
167 1 g_io_extension_point_implement ("gtk-inspector-page",
168 SHUMATE_TYPE_INSPECTOR_PAGE,
169 "libshumate",
170 10);
171
172 2 registered = TRUE;
173 }
174