aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/backend-dbus/mock-accounts.cc5
-rw-r--r--tests/backend-dbus/mock-login1-manager.cc25
-rw-r--r--tests/backend-dbus/mock-login1-manager.h2
-rw-r--r--tests/backend-dbus/mock-login1-seat.cc22
-rw-r--r--tests/backend-dbus/mock-login1-seat.h5
-rw-r--r--tests/backend-dbus/test-users.cc95
6 files changed, 69 insertions, 85 deletions
diff --git a/tests/backend-dbus/mock-accounts.cc b/tests/backend-dbus/mock-accounts.cc
index c753c79..16e37d2 100644
--- a/tests/backend-dbus/mock-accounts.cc
+++ b/tests/backend-dbus/mock-accounts.cc
@@ -107,9 +107,8 @@ MockAccounts :: on_list_cached_users_static (Accounts * a,
i = 0;
paths = g_new0 (const char*, users.size() + 1);
- for (users_t::iterator it(users.begin()),
- end(users.end()); it!=end; ++it)
- paths[i++] = (*it)->path();
+ for (auto it : users)
+ paths[i++] = it->path();
accounts_complete_list_cached_users (a, invocation, paths);
g_free (paths);
diff --git a/tests/backend-dbus/mock-login1-manager.cc b/tests/backend-dbus/mock-login1-manager.cc
index 0c1acc9..3bd652b 100644
--- a/tests/backend-dbus/mock-login1-manager.cc
+++ b/tests/backend-dbus/mock-login1-manager.cc
@@ -121,7 +121,6 @@ MockLogin1Manager :: emit_session_new (MockLogin1Seat * seat, int tag) const
seat->get_session_id_and_path_for_tag (tag, id, path);
-g_message ("%s %s emitting session-new [%s][%s]", G_STRLOC, G_STRFUNC, id.c_str(), path.c_str());
login1_manager_emit_session_new (my_skeleton, id.c_str(), path.c_str());
}
@@ -130,9 +129,27 @@ MockLogin1Manager :: add_session (MockLogin1Seat * seat, MockUser * user)
{
g_assert (my_seats.count(seat) == 1);
- const int tag = seat->add_session (user);
- emit_session_new (seat, tag);
- return tag;
+ const int session_tag = seat->add_session (user);
+ emit_session_new (seat, session_tag);
+ return session_tag;
+}
+
+void
+MockLogin1Manager :: emit_session_removed (MockLogin1Seat * seat, int tag) const
+{
+ std::string id;
+ std::string path;
+
+ seat->get_session_id_and_path_for_tag (tag, id, path);
+
+ login1_manager_emit_session_removed (my_skeleton, id.c_str(), path.c_str());
+}
+
+void
+MockLogin1Manager :: remove_session (MockLogin1Seat * seat, int session_tag)
+{
+ seat->remove_session (session_tag);
+ emit_session_removed (seat, session_tag);
}
void
diff --git a/tests/backend-dbus/mock-login1-manager.h b/tests/backend-dbus/mock-login1-manager.h
index a093f7f..f630329 100644
--- a/tests/backend-dbus/mock-login1-manager.h
+++ b/tests/backend-dbus/mock-login1-manager.h
@@ -37,6 +37,7 @@ class MockLogin1Manager: public MockObject
virtual ~MockLogin1Manager ();
int add_session (MockLogin1Seat * seat, MockUser * user);
+ void remove_session (MockLogin1Seat * seat, int session_tag);
void add_seat (MockLogin1Seat * seat);
@@ -49,6 +50,7 @@ class MockLogin1Manager: public MockObject
private:
void emit_session_new (MockLogin1Seat * seat, int tag) const;
+ void emit_session_removed (MockLogin1Seat * seat, int tag) const;
GVariant * list_sessions () const;
diff --git a/tests/backend-dbus/mock-login1-seat.cc b/tests/backend-dbus/mock-login1-seat.cc
index 08a18dc..46dc5f9 100644
--- a/tests/backend-dbus/mock-login1-seat.cc
+++ b/tests/backend-dbus/mock-login1-seat.cc
@@ -165,28 +165,14 @@ MockLogin1Seat :: remove_session (int session_tag)
****
***/
-MockUser *
-MockLogin1Seat :: active_user ()
-{
- auto it = my_sessions.find (active_session());
- return it == my_sessions.end() ? NULL : it->second;
-}
-
-const MockUser *
-MockLogin1Seat :: active_user () const
-{
- auto it = my_sessions.find (active_session());
- return it == my_sessions.end() ? NULL : it->second;
-}
-
-int
-MockLogin1Seat :: find_session_for_user (guint uid) const
+std::string
+MockLogin1Seat :: user_state (unsigned int uid) const
{
for (auto it : my_sessions)
if (it.second->uid() == uid)
- return it.first;
+ return it.first == my_active_session ? "active" : "online";
- return 0;
+ return "offline"; // no matching session
}
void
diff --git a/tests/backend-dbus/mock-login1-seat.h b/tests/backend-dbus/mock-login1-seat.h
index 473d21a..254ebe9 100644
--- a/tests/backend-dbus/mock-login1-seat.h
+++ b/tests/backend-dbus/mock-login1-seat.h
@@ -46,9 +46,8 @@ class MockLogin1Seat: public MockObject
void remove_session (int session_tag);
std::set<int> sessions () const;
int active_session () const { return my_active_session; }
- MockUser * active_user ();
- const MockUser * active_user () const;
- int find_session_for_user (guint uid) const;
+
+ std::string user_state (unsigned int uid) const;
bool can_activate_sessions () const { return my_can_multi_session; }
void activate_session (int session_tag);
diff --git a/tests/backend-dbus/test-users.cc b/tests/backend-dbus/test-users.cc
index fa52df3..d477a4f 100644
--- a/tests/backend-dbus/test-users.cc
+++ b/tests/backend-dbus/test-users.cc
@@ -62,31 +62,23 @@ class Users: public GTestMockDBusFixture
protected:
- void compare_user (const IndicatorSessionUser * isu,
- MockUser * mu,
- bool is_logged_in,
- bool is_current_user)
+ void compare_user (const MockUser * mu, const IndicatorSessionUser * isu, const std::string& user_state)
{
- ASSERT_TRUE (isu != 0);
- ASSERT_TRUE (mu != 0);
-
+ ASSERT_EQ (user_state, login1_seat->user_state (mu->uid()));
ASSERT_EQ (mu->uid(), isu->uid);
ASSERT_EQ (mu->login_frequency(), isu->login_frequency);
ASSERT_STREQ (mu->username(), isu->user_name);
ASSERT_STREQ (mu->realname(), isu->real_name);
- ASSERT_EQ (is_logged_in, isu->is_logged_in);
- ASSERT_EQ (is_current_user, isu->is_current_user);
- // FIXME: test icon file?
+ ASSERT_EQ (mu->uid(), isu->uid);
+ ASSERT_EQ (user_state!="offline", isu->is_logged_in);
+ ASSERT_EQ (user_state=="active", isu->is_current_user);
}
- void compare_user (const std::string & key,
- MockUser * mu,
- bool is_logged_in,
- bool is_current_user)
+ void compare_user (const MockUser * mu, const std::string& key, const std::string& user_state)
{
IndicatorSessionUser * isu;
isu = indicator_session_users_get_user (users, key.c_str());
- compare_user (isu, mu, is_logged_in, is_current_user);
+ compare_user (mu, isu, user_state);
indicator_session_user_free (isu);
}
@@ -159,7 +151,6 @@ TEST_F (Users, HelloWorld)
TEST_F (Users, InitialUsers)
{
GStrv keys = indicator_session_users_get_keys (users);
- const MockUser * active_user = login1_seat->active_user ();
ASSERT_EQ (12, g_strv_length (keys));
@@ -167,10 +158,7 @@ TEST_F (Users, InitialUsers)
{
IndicatorSessionUser * isu = indicator_session_users_get_user (users, keys[i]);
MockUser * mu = accounts->find_by_uid (isu->uid);
- const bool is_logged_in = login1_seat->find_session_for_user (isu->uid) != 0;
- const bool is_active = active_user && (active_user->uid() == isu->uid);
- compare_user (isu, mu, is_logged_in, is_active);
-
+ compare_user (mu, isu, login1_seat->user_state (isu->uid));
indicator_session_user_free (isu);
}
@@ -189,11 +177,7 @@ TEST_F (Users, UserAdded)
ASSERT_EQ (0, event_keys.size());
wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_ADDED, 1);
ASSERT_EQ (1, event_keys.size());
- IndicatorSessionUser * isu = indicator_session_users_get_user (users, event_keys[0].c_str());
- ASSERT_EQ (mu->uid(), isu->uid);
- indicator_session_user_free (isu);
-
- compare_user (event_keys[0], mu, false, false);
+ compare_user (mu, event_keys[0], "offline");
}
/**
@@ -239,7 +223,6 @@ TEST_F (Users, UserRemoved)
delete mu;
}
-#if 0
/**
* Confirm that 'users' notices when a user's real name changes
*/
@@ -254,8 +237,7 @@ TEST_F (Users, RealnameChanged)
ASSERT_STREQ (mu->realname(), realname);
wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED, 1);
ASSERT_EQ (1, event_keys.size());
- ASSERT_STREQ (mu->path(), event_keys[0].c_str());
- compare_user (mu->path(), mu, false, false);
+ compare_user (mu, event_keys[0], "offline");
}
/**
@@ -266,21 +248,18 @@ TEST_F (Users, LogInLogOut)
// 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);
+ ASSERT_EQ (login1_seat->user_state (mu->uid()), "offline");
+ const int session_tag = login1_manager->add_session (login1_seat, mu);
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 (mu, event_keys[0], "online");
- // The fist doctor logs out.
+ // The first doctor logs out.
// Confirm that 'users' notices.
- ck_seat->remove_session (session);
+ login1_manager->remove_session (login1_seat, session_tag);
wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED, 1);
ASSERT_EQ (1, event_keys.size());
- ASSERT_STREQ (mu->path(), event_keys[0].c_str());
- compare_user (event_keys[0], mu, false, false);
-
- delete session;
+ compare_user (mu, event_keys[0], "offline");
}
/**
@@ -288,34 +267,36 @@ TEST_F (Users, LogInLogOut)
*/
TEST_F (Users, ActivateSession)
{
- // 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
- 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'
+ login1_seat->switch_to_user (whartnell->username());
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);
+ compare_user (msmith, event_keys[0], "online");
+ compare_user (whartnell, event_keys[1], "active");
- // 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
- ck_seat->activate_session (ck_session);
+ // reverse the test
+ login1_seat->switch_to_user (msmith->username());
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 we can change the active session via users' API.
* This is nearly the same as ActivateSession but uses users' API