~ci-train-bot/indicator-session/indicator-session-ubuntu-zesty-2188

« back to all changes in this revision

Viewing changes to tests/backend-mock-actions.c

  • Committer: Charles Kerr
  • Date: 2013-03-22 21:34:34 UTC
  • mto: (384.2.29 ng)
  • mto: This revision was merged to the branch mainline in revision 399.
  • Revision ID: charles.kerr@canonical.com-20130322213434-a85qbob8bi4fvfx2
port indicator-session to GMenu/cmake. Code coverage increased from 0% to 95.4%.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013 Canonical Ltd.
 
3
 *
 
4
 * Authors:
 
5
 *   Charles Kerr <charles.kerr@canonical.com>
 
6
 *
 
7
 * This program is free software: you can redistribute it and/or modify it
 
8
 * under the terms of the GNU General Public License version 3, as published
 
9
 * by the Free Software Foundation.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful, but
 
12
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
13
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
14
 * PURPOSE.  See the GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License along
 
17
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include <glib.h>
 
21
#include <gio/gio.h>
 
22
 
 
23
#include "backend-mock.h"
 
24
#include "backend-mock-actions.h"
 
25
 
 
26
G_DEFINE_TYPE (IndicatorSessionActionsMock,
 
27
               indicator_session_actions_mock,
 
28
               INDICATOR_TYPE_SESSION_ACTIONS)
 
29
 
 
30
/***
 
31
****  Virtual Functions
 
32
***/
 
33
 
 
34
static gboolean
 
35
my_can_lock (IndicatorSessionActions * self G_GNUC_UNUSED)
 
36
{
 
37
  return g_settings_get_boolean (mock_settings, "can-lock");
 
38
}
 
39
 
 
40
static gboolean
 
41
my_can_logout (IndicatorSessionActions * self G_GNUC_UNUSED)
 
42
{
 
43
  return g_settings_get_boolean (mock_settings, "can-logout");
 
44
}
 
45
 
 
46
static gboolean
 
47
my_can_switch (IndicatorSessionActions * self G_GNUC_UNUSED)
 
48
{
 
49
  return g_settings_get_boolean (mock_settings, "can-switch-sessions");
 
50
}
 
51
 
 
52
static gboolean
 
53
my_can_suspend (IndicatorSessionActions * self G_GNUC_UNUSED)
 
54
{
 
55
  return g_settings_get_boolean (mock_settings, "can-suspend");
 
56
}
 
57
 
 
58
static gboolean
 
59
my_can_hibernate (IndicatorSessionActions * self G_GNUC_UNUSED)
 
60
{
 
61
  return g_settings_get_boolean (mock_settings, "can-hibernate");
 
62
}
 
63
 
 
64
static void
 
65
my_logout (IndicatorSessionActions * self G_GNUC_UNUSED)
 
66
{
 
67
  g_settings_set_string (mock_settings, "last-command", "logout");
 
68
}
 
69
 
 
70
static void
 
71
my_suspend (IndicatorSessionActions * self G_GNUC_UNUSED)
 
72
{
 
73
  g_settings_set_string (mock_settings, "last-command", "suspend");
 
74
}
 
75
 
 
76
static void
 
77
my_hibernate (IndicatorSessionActions * self G_GNUC_UNUSED)
 
78
{
 
79
  g_settings_set_string (mock_settings, "last-command", "hibernate");
 
80
}
 
81
 
 
82
static void
 
83
my_restart (IndicatorSessionActions * self G_GNUC_UNUSED)
 
84
{
 
85
  g_settings_set_string (mock_settings, "last-command", "restart");
 
86
}
 
87
 
 
88
static void
 
89
my_shutdown (IndicatorSessionActions * self G_GNUC_UNUSED)
 
90
{
 
91
  g_settings_set_string (mock_settings, "last-command", "shutdown");
 
92
}
 
93
 
 
94
static void
 
95
my_switch_to_screensaver (IndicatorSessionActions * self G_GNUC_UNUSED)
 
96
{
 
97
  g_settings_set_string (mock_settings, "last-command", "switch-to-screensaver");
 
98
}
 
99
 
 
100
static void
 
101
my_switch_to_greeter (IndicatorSessionActions * self G_GNUC_UNUSED)
 
102
{
 
103
  g_settings_set_string (mock_settings, "last-command", "switch-to-greeter");
 
104
}
 
105
 
 
106
static void
 
107
my_switch_to_guest (IndicatorSessionActions * self G_GNUC_UNUSED)
 
108
{
 
109
  g_settings_set_string (mock_settings, "last-command", "switch-to-guest");
 
110
}
 
111
 
 
112
static void
 
113
my_switch_to_username (IndicatorSessionActions * self G_GNUC_UNUSED,
 
114
                       const char * username)
 
115
{
 
116
  gchar * str = g_strdup_printf ("switch-to-user::%s", username);
 
117
  g_settings_set_string (mock_settings, "last-command", str);
 
118
}
 
119
 
 
120
static void
 
121
my_help (IndicatorSessionActions * self G_GNUC_UNUSED)
 
122
{
 
123
  g_settings_set_string (mock_settings, "last-command", "help");
 
124
}
 
125
 
 
126
static void
 
127
my_about (IndicatorSessionActions * self G_GNUC_UNUSED)
 
128
{
 
129
  g_settings_set_string (mock_settings, "last-command", "about");
 
130
}
 
131
 
 
132
static void
 
133
my_settings (IndicatorSessionActions * self G_GNUC_UNUSED)
 
134
{
 
135
  g_settings_set_string (mock_settings, "last-command", "settings");
 
136
}
 
137
 
 
138
static gboolean
 
139
my_can_prompt (IndicatorSessionActions * self G_GNUC_UNUSED)
 
140
{
 
141
  return g_settings_get_boolean (mock_settings, "can-prompt");
 
142
}
 
143
 
 
144
static gboolean
 
145
my_has_online_account_error (IndicatorSessionActions * self G_GNUC_UNUSED)
 
146
{
 
147
  return g_settings_get_boolean (mock_settings, "has-online-account-error");
 
148
}
 
149
 
 
150
static void
 
151
my_dispose (GObject * o)
 
152
{
 
153
  G_OBJECT_CLASS (indicator_session_actions_mock_parent_class)->dispose (o);
 
154
}
 
155
 
 
156
static void
 
157
my_finalize (GObject * o)
 
158
{
 
159
  G_OBJECT_CLASS (indicator_session_actions_mock_parent_class)->finalize (o);
 
160
}
 
161
 
 
162
/***
 
163
****  GObject Boilerplate
 
164
***/
 
165
 
 
166
static void
 
167
/* cppcheck-suppress unusedFunction */
 
168
indicator_session_actions_mock_class_init (IndicatorSessionActionsMockClass * klass)
 
169
{
 
170
  GObjectClass * object_class;
 
171
  IndicatorSessionActionsClass * actions_class;
 
172
 
 
173
  object_class = G_OBJECT_CLASS (klass);
 
174
  object_class->dispose = my_dispose;
 
175
  object_class->finalize = my_finalize;
 
176
 
 
177
  actions_class = INDICATOR_SESSION_ACTIONS_CLASS (klass);
 
178
  actions_class->can_lock = my_can_lock;
 
179
  actions_class->can_logout = my_can_logout;
 
180
  actions_class->can_switch = my_can_switch;
 
181
  actions_class->can_suspend = my_can_suspend;
 
182
  actions_class->can_hibernate = my_can_hibernate;
 
183
  actions_class->can_prompt = my_can_prompt;
 
184
  actions_class->has_online_account_error = my_has_online_account_error;
 
185
  actions_class->logout = my_logout;
 
186
  actions_class->suspend = my_suspend;
 
187
  actions_class->hibernate = my_hibernate;
 
188
  actions_class->restart = my_restart;
 
189
  actions_class->shutdown = my_shutdown;
 
190
  actions_class->settings = my_settings;
 
191
  actions_class->help = my_help;
 
192
  actions_class->about = my_about;
 
193
  actions_class->switch_to_screensaver = my_switch_to_screensaver;
 
194
  actions_class->switch_to_greeter = my_switch_to_greeter;
 
195
  actions_class->switch_to_guest = my_switch_to_guest;
 
196
  actions_class->switch_to_username = my_switch_to_username;
 
197
}
 
198
 
 
199
static void
 
200
/* cppcheck-suppress unusedFunction */
 
201
indicator_session_actions_mock_init (IndicatorSessionActionsMock * self)
 
202
{
 
203
  g_signal_connect_swapped (mock_settings, "changed::can-lock",
 
204
                            G_CALLBACK(indicator_session_actions_notify_can_lock), self);
 
205
  g_signal_connect_swapped (mock_settings, "changed::can-logout",
 
206
                            G_CALLBACK(indicator_session_actions_notify_can_logout), self);
 
207
  g_signal_connect_swapped (mock_settings, "changed::can-switch-sessions",
 
208
                            G_CALLBACK(indicator_session_actions_notify_can_switch), self);
 
209
  g_signal_connect_swapped (mock_settings, "changed::can-suspend",
 
210
                            G_CALLBACK(indicator_session_actions_notify_can_suspend), self);
 
211
  g_signal_connect_swapped (mock_settings, "changed::can-hibernate",
 
212
                            G_CALLBACK(indicator_session_actions_notify_can_hibernate), self);
 
213
  g_signal_connect_swapped (mock_settings, "changed::can-prompt",
 
214
                            G_CALLBACK(indicator_session_actions_notify_can_prompt), self);
 
215
  g_signal_connect_swapped (mock_settings, "changed::has-online-account-error",
 
216
                            G_CALLBACK(indicator_session_actions_notify_has_online_account_error), self);
 
217
}
 
218
 
 
219
/***
 
220
****  Public
 
221
***/
 
222
 
 
223
IndicatorSessionActions *
 
224
indicator_session_actions_mock_new (void)
 
225
{
 
226
  gpointer o = g_object_new (INDICATOR_TYPE_SESSION_ACTIONS_MOCK, NULL);
 
227
 
 
228
  return INDICATOR_SESSION_ACTIONS (o);
 
229
}