GCC Code Coverage Report


Directory: ./
File: tests/network/cc-test-window.c
Date: 2024-05-04 07:58:27
Exec Total Coverage
Lines: 39 54 72.2%
Functions: 10 13 76.9%
Branches: 15 27 55.6%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2009, 2010 Intel, Inc.
3 * Copyright (c) 2010, 2018 Red Hat, Inc.
4 * Copyright (c) 2016 Endless, Inc.
5 *
6 * The Control Center is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 *
11 * The Control Center is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with the Control Center; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 * Author: Benjamin Berg <bberg@redhat.com>
21 */
22
23 #define G_LOG_DOMAIN "cc-test-window"
24
25 #include <config.h>
26
27 #include "cc-test-window.h"
28
29 #include <gio/gio.h>
30 #include <gtk/gtk.h>
31 #include <gdk/gdkkeysyms.h>
32 #include <string.h>
33
34 #include "shell/cc-panel.h"
35 #include "shell/cc-shell.h"
36 #include "cc-util.h"
37
38
39 struct _CcTestWindow
40 {
41 GtkWindow parent;
42
43 GtkWidget *main_box;
44
45 GtkWidget *header;
46 CcPanel *active_panel;
47 };
48
49 static void cc_shell_iface_init (CcShellInterface *iface);
50
51
6/7
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 32 times.
70 G_DEFINE_TYPE_WITH_CODE (CcTestWindow, cc_test_window, GTK_TYPE_WINDOW,
52 G_IMPLEMENT_INTERFACE (CC_TYPE_SHELL, cc_shell_iface_init))
53
54 enum
55 {
56 PROP_0,
57 PROP_ACTIVE_PANEL
58 };
59
60
61
62 static void
63 11 set_active_panel (CcTestWindow *shell,
64 CcPanel *panel)
65 {
66
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 11 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 11 times.
11 g_assert (CC_IS_SHELL (shell));
67
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
11 g_assert (CC_IS_PANEL (panel));
68
69 /* Only allow setting to a non NULL value once. */
70
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 g_assert (shell->active_panel == NULL);
71
72
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (panel)
73 {
74 11 shell->active_panel = g_object_ref (panel);
75 11 gtk_box_append (GTK_BOX (shell->main_box), GTK_WIDGET (panel));
76 }
77 11 }
78
79 /* CcShell implementation */
80 static gboolean
81 cc_test_window_set_active_panel_from_id (CcShell *shell,
82 const gchar *start_id,
83 GVariant *parameters,
84 GError **error)
85 {
86 /* Not implemented */
87 g_assert_not_reached ();
88 }
89
90 static GtkWidget *
91 cc_test_window_get_toplevel (CcShell *shell)
92 {
93 return GTK_WIDGET (shell);
94 }
95
96 static void
97 1 cc_shell_iface_init (CcShellInterface *iface)
98 {
99 1 iface->set_active_panel_from_id = cc_test_window_set_active_panel_from_id;
100 1 iface->get_toplevel = cc_test_window_get_toplevel;
101 1 }
102
103 /* GObject Implementation */
104 static void
105 cc_test_window_get_property (GObject *object,
106 guint property_id,
107 GValue *value,
108 GParamSpec *pspec)
109 {
110 CcTestWindow *self = CC_TEST_WINDOW (object);
111
112 switch (property_id)
113 {
114 case PROP_ACTIVE_PANEL:
115 g_value_set_object (value, self->active_panel);
116 break;
117
118 default:
119 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
120 }
121 }
122
123 static void
124 11 cc_test_window_set_property (GObject *object,
125 guint property_id,
126 const GValue *value,
127 GParamSpec *pspec)
128 {
129 11 CcTestWindow *shell = CC_TEST_WINDOW (object);
130
131
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 switch (property_id)
132 {
133 11 case PROP_ACTIVE_PANEL:
134 11 set_active_panel (shell, g_value_get_object (value));
135 11 break;
136
137 default:
138 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
139 }
140 11 }
141
142 static void
143 11 cc_test_window_dispose (GObject *object)
144 {
145 11 CcTestWindow *self = CC_TEST_WINDOW (object);
146
147
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 g_clear_object (&self->active_panel);
148
149 11 G_OBJECT_CLASS (cc_test_window_parent_class)->dispose (object);
150 11 }
151
152 static void
153 1 cc_test_window_class_init (CcTestWindowClass *klass)
154 {
155 1 GObjectClass *object_class = G_OBJECT_CLASS (klass);
156
157 1 object_class->get_property = cc_test_window_get_property;
158 1 object_class->set_property = cc_test_window_set_property;
159 1 object_class->dispose = cc_test_window_dispose;
160
161 1 g_object_class_override_property (object_class, PROP_ACTIVE_PANEL, "active-panel");
162 1 }
163
164 static void
165 11 cc_test_window_init (CcTestWindow *self)
166 {
167 11 gtk_widget_set_size_request (GTK_WIDGET (self), 500, 800);
168
169 11 self->main_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
170
171 11 gtk_window_set_child (GTK_WINDOW (self), self->main_box);
172 11 }
173
174 CcTestWindow *
175 11 cc_test_window_new (void)
176 {
177 11 return g_object_new (CC_TYPE_TEST_WINDOW,
178 "resizable", TRUE,
179 "title", "Test Settings",
180 NULL);
181 }
182