~codygarver/+junk/ind-sess

« back to all changes in this revision

Viewing changes to tests/backend-mock-users.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 "backend-mock.h"
 
21
#include "backend-mock-users.h"
 
22
 
 
23
struct _IndicatorSessionUsersMockPriv
 
24
{
 
25
  GHashTable * users;
 
26
};
 
27
 
 
28
typedef IndicatorSessionUsersMockPriv priv_t;
 
29
 
 
30
G_DEFINE_TYPE (IndicatorSessionUsersMock,
 
31
               indicator_session_users_mock,
 
32
               INDICATOR_TYPE_SESSION_USERS)
 
33
 
 
34
/***
 
35
****  IndicatorSessionUsers virtual functions
 
36
***/
 
37
 
 
38
static gboolean
 
39
my_is_live_session (IndicatorSessionUsers * users G_GNUC_UNUSED)
 
40
{
 
41
  return g_settings_get_boolean (mock_settings, "is-live-session");
 
42
}
 
43
 
 
44
static void
 
45
my_activate_user (IndicatorSessionUsers * users, guint uid)
 
46
{
 
47
  g_message ("%s %s users %p uid %u FIXME", G_STRLOC, G_STRFUNC, (void*)users, uid);
 
48
}
 
49
 
 
50
static GList *
 
51
my_get_uids (IndicatorSessionUsers * users)
 
52
{
 
53
  g_return_val_if_fail (INDICATOR_IS_SESSION_USERS_MOCK(users), NULL);
 
54
 
 
55
  return g_hash_table_get_keys (INDICATOR_SESSION_USERS_MOCK(users)->priv->users);
 
56
}
 
57
 
 
58
static IndicatorSessionUser *
 
59
my_get_user (IndicatorSessionUsers * self, guint uid)
 
60
{
 
61
  priv_t * p;
 
62
  const IndicatorSessionUser * src;
 
63
  IndicatorSessionUser * ret = NULL;
 
64
 
 
65
  g_return_val_if_fail (INDICATOR_IS_SESSION_USERS_MOCK(self), NULL);
 
66
  p = INDICATOR_SESSION_USERS_MOCK (self)->priv;
 
67
 
 
68
  if ((src = g_hash_table_lookup (p->users, GUINT_TO_POINTER(uid))))
 
69
    {
 
70
      ret = g_new0 (IndicatorSessionUser, 1);
 
71
      ret->is_current_user = src->is_current_user;
 
72
      ret->is_logged_in = src->is_logged_in;
 
73
      ret->uid = src->uid;
 
74
      ret->login_frequency = src->login_frequency;
 
75
      ret->user_name = g_strdup (src->user_name);
 
76
      ret->real_name = g_strdup (src->real_name);
 
77
      ret->icon_file = g_strdup (src->icon_file);
 
78
    }
 
79
 
 
80
  return ret;
 
81
}
 
82
 
 
83
/***
 
84
****  GObject virtual functions
 
85
***/
 
86
 
 
87
static void
 
88
my_dispose (GObject * o)
 
89
{
 
90
  G_OBJECT_CLASS (indicator_session_users_mock_parent_class)->dispose (o);
 
91
}
 
92
 
 
93
static void
 
94
my_finalize (GObject * o)
 
95
{
 
96
  priv_t * p = INDICATOR_SESSION_USERS_MOCK (o)->priv;
 
97
 
 
98
  g_hash_table_destroy (p->users);
 
99
 
 
100
  G_OBJECT_CLASS (indicator_session_users_mock_parent_class)->finalize (o);
 
101
}
 
102
 
 
103
/***
 
104
****  GObject boilerplate
 
105
***/
 
106
 
 
107
static void
 
108
/* cppcheck-suppress unusedFunction */
 
109
indicator_session_users_mock_class_init (IndicatorSessionUsersMockClass * klass)
 
110
{
 
111
  GObjectClass * object_class;
 
112
  IndicatorSessionUsersClass * users_class;
 
113
 
 
114
  object_class = G_OBJECT_CLASS (klass);
 
115
  object_class->dispose = my_dispose;
 
116
  object_class->finalize = my_finalize;
 
117
 
 
118
  users_class = INDICATOR_SESSION_USERS_CLASS (klass);
 
119
  users_class->is_live_session = my_is_live_session;
 
120
  users_class->get_uids = my_get_uids;
 
121
  users_class->get_user = my_get_user;
 
122
  users_class->activate_user = my_activate_user;
 
123
 
 
124
  g_type_class_add_private (klass, sizeof (IndicatorSessionUsersMockPriv));
 
125
}
 
126
 
 
127
static void
 
128
/* cppcheck-suppress unusedFunction */
 
129
indicator_session_users_mock_init (IndicatorSessionUsersMock * self)
 
130
{
 
131
  priv_t * p;
 
132
 
 
133
  p = G_TYPE_INSTANCE_GET_PRIVATE (self,
 
134
                                   INDICATOR_TYPE_SESSION_USERS_MOCK,
 
135
                                   IndicatorSessionUsersMockPriv);
 
136
  self->priv = p;
 
137
 
 
138
  p->users = g_hash_table_new_full (g_direct_hash,
 
139
                                    g_direct_equal,
 
140
                                    NULL,
 
141
                                    (GDestroyNotify)indicator_session_user_free);
 
142
 
 
143
  g_signal_connect_swapped (mock_settings, "changed::is-live-session",
 
144
                            G_CALLBACK(indicator_session_users_notify_is_live_session), self);
 
145
}
 
146
 
 
147
/***
 
148
****  Public
 
149
***/
 
150
 
 
151
IndicatorSessionUsers *
 
152
indicator_session_users_mock_new (void)
 
153
{
 
154
  gpointer o = g_object_new (INDICATOR_TYPE_SESSION_USERS_MOCK, NULL);
 
155
 
 
156
  return INDICATOR_SESSION_USERS (o);
 
157
}
 
158
 
 
159
 
 
160
void
 
161
indicator_session_users_mock_add_user (IndicatorSessionUsersMock * self,
 
162
                                       IndicatorSessionUser      * user)
 
163
{
 
164
  g_return_if_fail (INDICATOR_IS_SESSION_USERS_MOCK (self));
 
165
  g_return_if_fail (user != NULL);
 
166
  g_return_if_fail (user->uid > 0);
 
167
  g_return_if_fail (!g_hash_table_contains (self->priv->users, GUINT_TO_POINTER(user->uid)));
 
168
 
 
169
  g_hash_table_insert (self->priv->users, GUINT_TO_POINTER(user->uid), user);
 
170
  indicator_session_users_added (INDICATOR_SESSION_USERS (self), user->uid);
 
171
}
 
172
 
 
173
void
 
174
indicator_session_users_mock_remove_user (IndicatorSessionUsersMock * self,
 
175
                                          guint                       uid)
 
176
{
 
177
  g_return_if_fail (INDICATOR_IS_SESSION_USERS_MOCK (self));
 
178
  g_return_if_fail (uid > 0);
 
179
 
 
180
  g_hash_table_remove (self->priv->users, GUINT_TO_POINTER(uid));
 
181
  indicator_session_users_removed (INDICATOR_SESSION_USERS (self), uid);
 
182
}
 
183