~vikoadi/elementaryos/os-patch-indicator-session-trusty-fix-lock

« back to all changes in this revision

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

  • Committer: Cody Garver
  • Date: 2014-04-03 17:08:08 UTC
  • Revision ID: cody@elementaryos.org-20140403170808-z56s93rorb1dzvmk
Initial import, version 12.10.5+14.04.20140324-0ubuntu1

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_reboot (IndicatorSessionActions * self G_GNUC_UNUSED)
 
48
{
 
49
  return g_settings_get_boolean (mock_settings, "can-reboot");
 
50
}
 
51
 
 
52
static gboolean
 
53
my_can_switch (IndicatorSessionActions * self G_GNUC_UNUSED)
 
54
{
 
55
  return g_settings_get_boolean (mock_settings, "can-switch-sessions");
 
56
}
 
57
 
 
58
static gboolean
 
59
my_can_suspend (IndicatorSessionActions * self G_GNUC_UNUSED)
 
60
{
 
61
  return g_settings_get_boolean (mock_settings, "can-suspend");
 
62
}
 
63
 
 
64
static gboolean
 
65
my_can_hibernate (IndicatorSessionActions * self G_GNUC_UNUSED)
 
66
{
 
67
  return g_settings_get_boolean (mock_settings, "can-hibernate");
 
68
}
 
69
 
 
70
static void
 
71
my_logout (IndicatorSessionActions * self G_GNUC_UNUSED)
 
72
{
 
73
  g_settings_set_string (mock_settings, "last-command", "logout");
 
74
}
 
75
 
 
76
static void
 
77
my_suspend (IndicatorSessionActions * self G_GNUC_UNUSED)
 
78
{
 
79
  g_settings_set_string (mock_settings, "last-command", "suspend");
 
80
}
 
81
 
 
82
static void
 
83
my_hibernate (IndicatorSessionActions * self G_GNUC_UNUSED)
 
84
{
 
85
  g_settings_set_string (mock_settings, "last-command", "hibernate");
 
86
}
 
87
 
 
88
static void
 
89
my_reboot (IndicatorSessionActions * self G_GNUC_UNUSED)
 
90
{
 
91
  g_settings_set_string (mock_settings, "last-command", "reboot");
 
92
}
 
93
 
 
94
static void
 
95
my_power_off (IndicatorSessionActions * self G_GNUC_UNUSED)
 
96
{
 
97
  g_settings_set_string (mock_settings, "last-command", "power-off");
 
98
}
 
99
 
 
100
static void
 
101
my_switch_to_screensaver (IndicatorSessionActions * self G_GNUC_UNUSED)
 
102
{
 
103
  g_settings_set_string (mock_settings, "last-command", "switch-to-screensaver");
 
104
}
 
105
 
 
106
static void
 
107
my_switch_to_greeter (IndicatorSessionActions * self G_GNUC_UNUSED)
 
108
{
 
109
  g_settings_set_string (mock_settings, "last-command", "switch-to-greeter");
 
110
}
 
111
 
 
112
static void
 
113
my_switch_to_guest (IndicatorSessionActions * self G_GNUC_UNUSED)
 
114
{
 
115
  g_settings_set_string (mock_settings, "last-command", "switch-to-guest");
 
116
}
 
117
 
 
118
static void
 
119
my_switch_to_username (IndicatorSessionActions * self G_GNUC_UNUSED,
 
120
                       const char * username)
 
121
{
 
122
  gchar * str = g_strdup_printf ("switch-to-user::%s", username);
 
123
  g_settings_set_string (mock_settings, "last-command", str);
 
124
}
 
125
 
 
126
static void
 
127
my_help (IndicatorSessionActions * self G_GNUC_UNUSED)
 
128
{
 
129
  g_settings_set_string (mock_settings, "last-command", "help");
 
130
}
 
131
 
 
132
static void
 
133
my_about (IndicatorSessionActions * self G_GNUC_UNUSED)
 
134
{
 
135
  g_settings_set_string (mock_settings, "last-command", "about");
 
136
}
 
137
 
 
138
static void
 
139
my_settings (IndicatorSessionActions * self G_GNUC_UNUSED)
 
140
{
 
141
  g_settings_set_string (mock_settings, "last-command", "settings");
 
142
}
 
143
 
 
144
static void
 
145
my_online_accounts (IndicatorSessionActions * self G_GNUC_UNUSED)
 
146
{
 
147
  g_settings_set_string (mock_settings, "last-command", "online-accounts");
 
148
}
 
149
 
 
150
static gboolean
 
151
my_can_prompt (IndicatorSessionActions * self G_GNUC_UNUSED)
 
152
{
 
153
  return g_settings_get_boolean (mock_settings, "can-prompt");
 
154
}
 
155
 
 
156
static gboolean
 
157
my_has_online_account_error (IndicatorSessionActions * self G_GNUC_UNUSED)
 
158
{
 
159
  return g_settings_get_boolean (mock_settings, "has-online-account-error");
 
160
}
 
161
 
 
162
static void
 
163
my_dispose (GObject * o)
 
164
{
 
165
  G_OBJECT_CLASS (indicator_session_actions_mock_parent_class)->dispose (o);
 
166
}
 
167
 
 
168
static void
 
169
my_finalize (GObject * o)
 
170
{
 
171
  G_OBJECT_CLASS (indicator_session_actions_mock_parent_class)->finalize (o);
 
172
}
 
173
 
 
174
/***
 
175
****  GObject Boilerplate
 
176
***/
 
177
 
 
178
static void
 
179
/* cppcheck-suppress unusedFunction */
 
180
indicator_session_actions_mock_class_init (IndicatorSessionActionsMockClass * klass)
 
181
{
 
182
  GObjectClass * object_class;
 
183
  IndicatorSessionActionsClass * actions_class;
 
184
 
 
185
  object_class = G_OBJECT_CLASS (klass);
 
186
  object_class->dispose = my_dispose;
 
187
  object_class->finalize = my_finalize;
 
188
 
 
189
  actions_class = INDICATOR_SESSION_ACTIONS_CLASS (klass);
 
190
  actions_class->can_lock = my_can_lock;
 
191
  actions_class->can_logout = my_can_logout;
 
192
  actions_class->can_reboot = my_can_reboot;
 
193
  actions_class->can_switch = my_can_switch;
 
194
  actions_class->can_suspend = my_can_suspend;
 
195
  actions_class->can_hibernate = my_can_hibernate;
 
196
  actions_class->can_prompt = my_can_prompt;
 
197
  actions_class->has_online_account_error = my_has_online_account_error;
 
198
  actions_class->logout = my_logout;
 
199
  actions_class->suspend = my_suspend;
 
200
  actions_class->hibernate = my_hibernate;
 
201
  actions_class->reboot = my_reboot;
 
202
  actions_class->power_off = my_power_off;
 
203
  actions_class->settings = my_settings;
 
204
  actions_class->online_accounts = my_online_accounts;
 
205
  actions_class->help = my_help;
 
206
  actions_class->about = my_about;
 
207
  actions_class->switch_to_screensaver = my_switch_to_screensaver;
 
208
  actions_class->switch_to_greeter = my_switch_to_greeter;
 
209
  actions_class->switch_to_guest = my_switch_to_guest;
 
210
  actions_class->switch_to_username = my_switch_to_username;
 
211
}
 
212
 
 
213
static void
 
214
/* cppcheck-suppress unusedFunction */
 
215
indicator_session_actions_mock_init (IndicatorSessionActionsMock * self)
 
216
{
 
217
  g_signal_connect_swapped (mock_settings, "changed::can-lock",
 
218
                            G_CALLBACK(indicator_session_actions_notify_can_lock), self);
 
219
  g_signal_connect_swapped (mock_settings, "changed::can-logout",
 
220
                            G_CALLBACK(indicator_session_actions_notify_can_logout), self);
 
221
  g_signal_connect_swapped (mock_settings, "changed::can-switch-sessions",
 
222
                            G_CALLBACK(indicator_session_actions_notify_can_switch), self);
 
223
  g_signal_connect_swapped (mock_settings, "changed::can-suspend",
 
224
                            G_CALLBACK(indicator_session_actions_notify_can_suspend), self);
 
225
  g_signal_connect_swapped (mock_settings, "changed::can-hibernate",
 
226
                            G_CALLBACK(indicator_session_actions_notify_can_hibernate), self);
 
227
  g_signal_connect_swapped (mock_settings, "changed::can-prompt",
 
228
                            G_CALLBACK(indicator_session_actions_notify_can_prompt), self);
 
229
  g_signal_connect_swapped (mock_settings, "changed::has-online-account-error",
 
230
                            G_CALLBACK(indicator_session_actions_notify_has_online_account_error), self);
 
231
}
 
232
 
 
233
/***
 
234
****  Public
 
235
***/
 
236
 
 
237
IndicatorSessionActions *
 
238
indicator_session_actions_mock_new (void)
 
239
{
 
240
  gpointer o = g_object_new (INDICATOR_TYPE_SESSION_ACTIONS_MOCK, NULL);
 
241
 
 
242
  return INDICATOR_SESSION_ACTIONS (o);
 
243
}