aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2013-06-25 11:16:34 -0500
committerCharles Kerr <charles.kerr@canonical.com>2013-06-25 11:16:34 -0500
commitb3938a1f14b687d62ad1d6e4e27bac47f58722de (patch)
tree832bacd3527c2e30682938168f0ccfba1267a7ac /tests
parentc572f9940e9c0081e281d13e8f8038dcb1b92c3c (diff)
downloadayatana-indicator-session-b3938a1f14b687d62ad1d6e4e27bac47f58722de.tar.gz
ayatana-indicator-session-b3938a1f14b687d62ad1d6e4e27bac47f58722de.tar.bz2
ayatana-indicator-session-b3938a1f14b687d62ad1d6e4e27bac47f58722de.zip
in IndicatorSessionUsers, use the uid as the user's key. Users.ActivateUser is now green.
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt4
-rw-r--r--tests/backend-dbus/test-users.cc114
-rw-r--r--tests/backend-mock-users.c52
-rw-r--r--tests/backend-mock-users.h3
-rw-r--r--tests/test-service.cc43
5 files changed, 99 insertions, 117 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 45ab69f..f67008e 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -39,13 +39,13 @@ add_library (backendmock STATIC
backend-mock-guest.h
backend-mock-users.c
backend-mock-users.h)
-set_target_properties (backendmock PROPERTIES COMPILE_FLAGS " ${CC_WARNING_ARGS}")
+set_target_properties (backendmock PROPERTIES COMPILE_FLAGS " ${CC_WARNING_ARGS} -std=c++0x -g")
# test-service
add_executable (test-service
test-service.cc
gschemas.compiled)
-set_target_properties (test-service PROPERTIES COMPILE_FLAGS " ${CC_WARNING_ARGS}")
+set_target_properties (test-service PROPERTIES COMPILE_FLAGS " ${CC_WARNING_ARGS} -std=c++0x -g")
add_test (test-service test-service)
add_dependencies (test-service libindicatorsessionservice backendmock)
target_link_libraries (test-service libindicatorsessionservice backendmock gtest ${SERVICE_LIBRARIES} ${GTEST_LIBS})
diff --git a/tests/backend-dbus/test-users.cc b/tests/backend-dbus/test-users.cc
index d477a4f..279796e 100644
--- a/tests/backend-dbus/test-users.cc
+++ b/tests/backend-dbus/test-users.cc
@@ -74,10 +74,18 @@ class Users: public GTestMockDBusFixture
ASSERT_EQ (user_state=="active", isu->is_current_user);
}
- void compare_user (const MockUser * mu, const std::string& key, const std::string& user_state)
+ void compare_user (const MockUser * mu, guint uid, const std::string& user_state)
{
IndicatorSessionUser * isu;
- isu = indicator_session_users_get_user (users, key.c_str());
+ isu = indicator_session_users_get_user (users, uid);
+ compare_user (mu, isu, user_state);
+ indicator_session_user_free (isu);
+ }
+
+ void compare_user (guint uid, const std::string& user_state)
+ {
+ IndicatorSessionUser * isu = indicator_session_users_get_user (users, uid);
+ MockUser * mu = accounts->find_by_uid (uid);
compare_user (mu, isu, user_state);
indicator_session_user_free (isu);
}
@@ -99,12 +107,12 @@ class Users: public GTestMockDBusFixture
static void
wait_for_signals__event (IndicatorSessionUser * u G_GNUC_UNUSED,
- const char * key,
- gpointer gself)
+ guint uid,
+ gpointer gself)
{
Users * self = static_cast<Users*>(gself);
- self->event_keys.push_back (key);
+ self->event_keys.push_back (uid);
if (self->event_keys.size() == self->expected_event_count)
g_main_loop_quit (self->loop);
@@ -112,7 +120,7 @@ class Users: public GTestMockDBusFixture
protected:
- std::vector<std::string> event_keys;
+ std::vector<guint> event_keys;
size_t expected_event_count;
void wait_for_signals (gpointer o, const gchar * name, size_t n)
@@ -150,19 +158,18 @@ TEST_F (Users, HelloWorld)
*/
TEST_F (Users, InitialUsers)
{
- GStrv keys = indicator_session_users_get_keys (users);
+ GList * l;
+ GList * uids = indicator_session_users_get_uids (users);
- ASSERT_EQ (12, g_strv_length (keys));
+ ASSERT_EQ (12, g_list_length (uids));
- for (int i=0; keys && keys[i]; ++i)
+ for (l=uids; l!=NULL; l=l->next)
{
- IndicatorSessionUser * isu = indicator_session_users_get_user (users, keys[i]);
- MockUser * mu = accounts->find_by_uid (isu->uid);
- compare_user (mu, isu, login1_seat->user_state (isu->uid));
- indicator_session_user_free (isu);
+ const guint uid = GPOINTER_TO_UINT (l->data);
+ compare_user (uid, login1_seat->user_state (uid));
}
- g_strfreev (keys);
+ g_list_free (uids);
}
/**
@@ -188,17 +195,10 @@ TEST_F (Users, UserRemoved)
MockUser * mu = accounts->find_by_username ("pdavison");
/* confirm that users knows about pdavison */
- bool found = false;
- GStrv keys = indicator_session_users_get_keys (users);
- ASSERT_EQ (12, g_strv_length (keys));
- for (int i=0; !found && keys && keys[i]; i++)
- {
- IndicatorSessionUser * isu = indicator_session_users_get_user (users, keys[i]);
- found = isu->uid == mu->uid();
- indicator_session_user_free (isu);
- }
- g_strfreev (keys);
- ASSERT_TRUE (found);
+ IndicatorSessionUser * isu = indicator_session_users_get_user (users, mu->uid());
+ ASSERT_TRUE (isu != NULL);
+ compare_user (mu, isu, "offline");
+ g_clear_pointer (&isu, indicator_session_user_free);
/* on the bus, remove pdavison. */
accounts->remove_user (mu);
@@ -208,17 +208,14 @@ TEST_F (Users, UserRemoved)
wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_REMOVED, 1);
ASSERT_EQ (1, event_keys.size());
- /* confirm that users doesn't know about pdavison */
- keys = indicator_session_users_get_keys (users);
- ASSERT_EQ (11, g_strv_length (keys));
- for (int i=0; keys && keys[i]; i++)
- {
- IndicatorSessionUser * isu = indicator_session_users_get_user (users, keys[i]);
- ASSERT_NE (event_keys[0], keys[i]);
- ASSERT_NE (mu->uid(), isu->uid);
- indicator_session_user_free (isu);
- }
- g_strfreev (keys);
+ /* confirm that users won't give us pdavison's info */
+ isu = indicator_session_users_get_user (users, mu->uid());
+ ASSERT_TRUE (isu == NULL);
+
+ /* confirm that users won't give us pdavison's uid */
+ GList * uids = indicator_session_users_get_uids (users);
+ ASSERT_TRUE (g_list_find (uids, GUINT_TO_POINTER(mu->uid())) == NULL);
+ g_list_free (uids);
delete mu;
}
@@ -296,43 +293,42 @@ TEST_F (Users, ActivateSession)
compare_user (msmith, event_keys[1], "active");
}
-#if 0
/**
* Confirm that we can change the active session via users' API.
* This is nearly the same as ActivateSession but uses users' API
*/
TEST_F (Users, ActivateUser)
{
- // The fist doctor logs in.
- // Confirm that 'users' notices.
- MockUser * mu = accounts->find_by_username ("whartnell");
- compare_user (mu->path(), mu, false, false);
- MockConsoleKitSession * session = ck_seat->add_session_by_user (mu);
+ // confirm preconditions: msmith is active, msmith is offline
+ MockUser * const whartnell = accounts->find_by_username ("whartnell");
+ ASSERT_EQ (login1_seat->user_state (whartnell->uid()), "offline");
+ MockUser * const msmith = accounts->find_by_username ("msmith");
+ ASSERT_EQ (login1_seat->user_state (msmith->uid()), "active");
+
+ // whartnell logs in... confirm that 'users' notices
+ login1_manager->add_session (login1_seat, whartnell);
wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED, 1);
- ASSERT_STREQ (mu->path(), event_keys[0].c_str());
- compare_user (mu->path(), mu, true, false);
+ ASSERT_EQ (1, event_keys.size());
+ compare_user (whartnell, event_keys[0], "online");
- // activate the first doctor's session.
- // confirm that 'users' sees he's active and that ck_session isn't.
- // this should come in the form of two 'user-changed' events
- indicator_session_users_activate_user (users, mu->path());
- ck_seat->activate_session (session);
+ // activate whartnell's session... confirm that 'users' sees:
+ // 1. msmith changes from 'active' to 'online'
+ // 2. whartnell changes from 'online' to 'active'
+ indicator_session_users_activate_user (users, whartnell->uid());
wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED, 2);
ASSERT_EQ (2, event_keys.size());
- compare_user (event_keys[0], ck_session->user(), true, false);
- compare_user (event_keys[1], mu, true, true);
-
- // switch back to the previous
- // confirm that 'users' sees it's active and the first doctor's session isn't
- // this should come in the form of two 'user-changed' events
- indicator_session_users_activate_user (users, ck_session->user()->path());
- ck_seat->activate_session (ck_session);
+ compare_user (msmith, event_keys[0], "online");
+ compare_user (whartnell, event_keys[1], "active");
+
+ // reverse the test
+ indicator_session_users_activate_user (users, msmith->uid());
wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED, 2);
ASSERT_EQ (2, event_keys.size());
- compare_user (event_keys[0], mu, true, false);
- compare_user (event_keys[1], ck_session->user(), true, true);
+ compare_user (whartnell, event_keys[0], "online");
+ compare_user (msmith, event_keys[1], "active");
}
+#if 0
/**
* Confirm that adding a Guest doesn't show up in the users list
*/
diff --git a/tests/backend-mock-users.c b/tests/backend-mock-users.c
index d9ab5a8..bae40b6 100644
--- a/tests/backend-mock-users.c
+++ b/tests/backend-mock-users.c
@@ -58,35 +58,21 @@ my_is_live_session (IndicatorSessionUsers * users G_GNUC_UNUSED)
}
static void
-my_activate_user (IndicatorSessionUsers * users, const char * key)
+my_activate_user (IndicatorSessionUsers * users, guint uid)
{
- g_message ("%s %s users %p key %s FIXME", G_STRLOC, G_STRFUNC, (void*)users, key);
+ g_message ("%s %s users %p uid %u FIXME", G_STRLOC, G_STRFUNC, (void*)users, uid);
}
-static GStrv
-my_get_keys (IndicatorSessionUsers * users)
+static GList *
+my_get_uids (IndicatorSessionUsers * users)
{
- int i;
- priv_t * p;
- gchar ** keys;
- GHashTableIter iter;
- gpointer key;
-
g_return_val_if_fail (INDICATOR_IS_SESSION_USERS_MOCK(users), NULL);
- p = INDICATOR_SESSION_USERS_MOCK (users)->priv;
-
- i = 0;
- keys = g_new (gchar*, g_hash_table_size(p->users)+1);
- g_hash_table_iter_init (&iter, p->users);
- while (g_hash_table_iter_next (&iter, &key, NULL))
- keys[i++] = g_strdup (key);
- keys[i] = NULL;
- return keys;
+ return g_hash_table_get_keys (INDICATOR_SESSION_USERS_MOCK(users)->priv->users);
}
static IndicatorSessionUser *
-my_get_user (IndicatorSessionUsers * self, const gchar * key)
+my_get_user (IndicatorSessionUsers * self, guint uid)
{
priv_t * p;
const IndicatorSessionUser * src;
@@ -95,7 +81,7 @@ my_get_user (IndicatorSessionUsers * self, const gchar * key)
g_return_val_if_fail (INDICATOR_IS_SESSION_USERS_MOCK(self), NULL);
p = INDICATOR_SESSION_USERS_MOCK (self)->priv;
- if ((src = g_hash_table_lookup (p->users, key)))
+ if ((src = g_hash_table_lookup (p->users, GUINT_TO_POINTER(uid))))
{
ret = g_new0 (IndicatorSessionUser, 1);
ret->is_current_user = src->is_current_user;
@@ -123,7 +109,7 @@ indicator_session_users_mock_class_init (IndicatorSessionUsersMockClass * klass)
users_class = INDICATOR_SESSION_USERS_CLASS (klass);
users_class->is_live_session = my_is_live_session;
- users_class->get_keys = my_get_keys;
+ users_class->get_uids = my_get_uids;
users_class->get_user = my_get_user;
users_class->activate_user = my_activate_user;
@@ -141,9 +127,9 @@ indicator_session_users_mock_init (IndicatorSessionUsersMock * self)
IndicatorSessionUsersMockPriv);
self->priv = p;
- p->users = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
+ p->users = g_hash_table_new_full (g_direct_hash,
+ g_direct_equal,
+ NULL,
(GDestroyNotify)indicator_session_user_free);
g_signal_connect_swapped (mock_settings, "changed::is-live-session",
@@ -165,25 +151,25 @@ indicator_session_users_mock_new (void)
void
indicator_session_users_mock_add_user (IndicatorSessionUsersMock * self,
- const char * key,
IndicatorSessionUser * user)
{
g_return_if_fail (INDICATOR_IS_SESSION_USERS_MOCK (self));
- g_return_if_fail (key && *key);
g_return_if_fail (user != NULL);
+ g_return_if_fail (user->uid > 0);
+ g_return_if_fail (!g_hash_table_contains (self->priv->users, GUINT_TO_POINTER(user->uid)));
- g_hash_table_insert (self->priv->users, g_strdup(key), user);
- indicator_session_users_added (INDICATOR_SESSION_USERS (self), key);
+ g_hash_table_insert (self->priv->users, GUINT_TO_POINTER(user->uid), user);
+ indicator_session_users_added (INDICATOR_SESSION_USERS (self), user->uid);
}
void
indicator_session_users_mock_remove_user (IndicatorSessionUsersMock * self,
- const char * key)
+ guint uid)
{
g_return_if_fail (INDICATOR_IS_SESSION_USERS_MOCK (self));
- g_return_if_fail (key && *key);
+ g_return_if_fail (uid > 0);
- g_hash_table_remove (self->priv->users, key);
- indicator_session_users_removed (INDICATOR_SESSION_USERS (self), key);
+ g_hash_table_remove (self->priv->users, GUINT_TO_POINTER(uid));
+ indicator_session_users_removed (INDICATOR_SESSION_USERS (self), uid);
}
diff --git a/tests/backend-mock-users.h b/tests/backend-mock-users.h
index c7e11d3..7470ec9 100644
--- a/tests/backend-mock-users.h
+++ b/tests/backend-mock-users.h
@@ -57,11 +57,10 @@ GType indicator_session_users_mock_get_type (void);
IndicatorSessionUsers * indicator_session_users_mock_new (void);
void indicator_session_users_mock_add_user (IndicatorSessionUsersMock * self,
- const char * key,
IndicatorSessionUser * user);
void indicator_session_users_mock_remove_user (IndicatorSessionUsersMock * self,
- const char * key);
+ guint uid);
diff --git a/tests/test-service.cc b/tests/test-service.cc
index 2d81441..996332d 100644
--- a/tests/test-service.cc
+++ b/tests/test-service.cc
@@ -619,23 +619,24 @@ TEST_F (ServiceTest, User)
const char * const error_key = "has-online-account-error";
const char * const show_name_key = "show-real-name-on-panel";
- const struct {
+ struct {
+ guint uid;
guint64 login_frequency;
const gchar * user_name;
const gchar * real_name;
} account_info[] = {
- { 134, "whartnell", "First Doctor" },
- { 119, "ptroughton", "Second Doctor" },
- { 128, "jpertwee", "Third Doctor" },
- { 172, "tbaker", "Fourth Doctor" },
- { 69, "pdavison", "Fifth Doctor" },
- { 31, "cbaker", "Sixth Doctor" },
- { 42, "smccoy", "Seventh Doctor" },
- { 1, "pmcgann", "Eigth Doctor" },
- { 13, "ceccleston", "Ninth Doctor" },
- { 47, "dtennant", "Tenth Doctor" },
- { 34, "msmith", "Eleventh Doctor" },
- { 1, "rhurndall", "First Doctor" }
+ { 101, 134, "whartnell", "First Doctor" },
+ { 102, 119, "ptroughton", "Second Doctor" },
+ { 103, 128, "jpertwee", "Third Doctor" },
+ { 104, 172, "tbaker", "Fourth Doctor" },
+ { 105, 69, "pdavison", "Fifth Doctor" },
+ { 106, 31, "cbaker", "Sixth Doctor" },
+ { 107, 42, "smccoy", "Seventh Doctor" },
+ { 108, 1, "pmcgann", "Eigth Doctor" },
+ { 109, 13, "ceccleston", "Ninth Doctor" },
+ { 110, 47, "dtennant", "Tenth Doctor" },
+ { 111, 34, "msmith", "Eleventh Doctor" },
+ { 201, 1, "rhurndall", "First Doctor" }
};
// Find the switcher menu model.
@@ -656,11 +657,11 @@ TEST_F (ServiceTest, User)
IndicatorSessionUser * u = g_new0 (IndicatorSessionUser, 1);
u->is_current_user = false;
u->is_logged_in = false;
- u->uid = 101 + i;
+ u->uid = account_info[i].uid;
u->login_frequency = account_info[i].login_frequency;
u->user_name = g_strdup (account_info[i].user_name);
u->real_name = g_strdup (account_info[i].real_name);
- indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u->user_name, u);
+ indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
users[i] = u;
}
@@ -679,8 +680,8 @@ TEST_F (ServiceTest, User)
g_clear_object (&switch_menu);
// now remove a couple of 'em
- indicator_session_users_mock_remove_user (INDICATOR_SESSION_USERS_MOCK(mock_users), account_info[3].user_name);
- indicator_session_users_mock_remove_user (INDICATOR_SESSION_USERS_MOCK(mock_users), account_info[4].user_name);
+ indicator_session_users_mock_remove_user (INDICATOR_SESSION_USERS_MOCK(mock_users), account_info[3].uid);
+ indicator_session_users_mock_remove_user (INDICATOR_SESSION_USERS_MOCK(mock_users), account_info[4].uid);
wait_for_menu_resync ();
@@ -697,7 +698,7 @@ TEST_F (ServiceTest, User)
// now let's have the third one be the current user
users[2]->is_current_user = true;
users[2]->is_logged_in = true;
- indicator_session_users_changed (mock_users, users[2]->user_name);
+ indicator_session_users_changed (mock_users, users[2]->uid);
wait_for_menu_resync ();
@@ -749,14 +750,14 @@ TEST_F (ServiceTest, User)
u->login_frequency = account_info[i].login_frequency;
u->user_name = g_strdup (account_info[i].user_name);
u->real_name = g_strdup (account_info[i].real_name);
- indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u->user_name, u);
+ indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
users[i] = u;
}
users[2]->is_current_user = false;
- indicator_session_users_changed (mock_users, users[2]->user_name);
+ indicator_session_users_changed (mock_users, users[2]->uid);
users[10]->is_current_user = true;
users[10]->is_logged_in = true;
- indicator_session_users_changed (mock_users, users[10]->user_name);
+ indicator_session_users_changed (mock_users, users[10]->uid);
wait_for_menu_resync ();
ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-greeter", &switch_menu, &pos));
ASSERT_EQ (0, pos);