aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend-dbus/org.freedesktop.DisplayManager.Seat (renamed from src/backend-dbus/display-manager.xml)0
-rw-r--r--tests/backend-dbus/CMakeLists.txt14
-rw-r--r--tests/backend-dbus/gtest-mock-dbus-fixture.h28
-rw-r--r--tests/backend-dbus/mock-consolekit-manager.cc156
-rw-r--r--tests/backend-dbus/mock-consolekit-manager.h77
-rw-r--r--tests/backend-dbus/mock-consolekit-seat.cc220
-rw-r--r--tests/backend-dbus/mock-consolekit-seat.h75
-rw-r--r--tests/backend-dbus/mock-consolekit-session.cc113
-rw-r--r--tests/backend-dbus/mock-consolekit-session.h65
-rw-r--r--tests/backend-dbus/mock-display-manager-seat.cc17
-rw-r--r--tests/backend-dbus/mock-display-manager-seat.h6
-rw-r--r--tests/backend-dbus/mock-login1-manager.cc275
-rw-r--r--tests/backend-dbus/mock-login1-manager.h68
-rw-r--r--tests/backend-dbus/mock-login1-seat.cc230
-rw-r--r--tests/backend-dbus/mock-login1-seat.h77
-rw-r--r--tests/backend-dbus/mock-upower.cc103
-rw-r--r--tests/backend-dbus/mock-upower.h72
-rw-r--r--tests/backend-dbus/test-actions.cc137
18 files changed, 726 insertions, 1007 deletions
diff --git a/src/backend-dbus/display-manager.xml b/src/backend-dbus/org.freedesktop.DisplayManager.Seat
index 07b5f29..07b5f29 100644
--- a/src/backend-dbus/display-manager.xml
+++ b/src/backend-dbus/org.freedesktop.DisplayManager.Seat
diff --git a/tests/backend-dbus/CMakeLists.txt b/tests/backend-dbus/CMakeLists.txt
index 7cd7030..ed9c93a 100644
--- a/tests/backend-dbus/CMakeLists.txt
+++ b/tests/backend-dbus/CMakeLists.txt
@@ -5,16 +5,16 @@ add_library (gtest STATIC
set_target_properties (gtest PROPERTIES INCLUDE_DIRECTORIES
${GTEST_INCLUDE_DIR})
+SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
+
# build desktopmock
add_library (desktopmock STATIC
mock-accounts.cc
mock-accounts.h
- mock-consolekit-manager.cc
- mock-consolekit-manager.h
- mock-consolekit-seat.cc
- mock-consolekit-seat.h
- mock-consolekit-session.cc
- mock-consolekit-session.h
+ mock-login1-manager.cc
+ mock-login1-manager.h
+ mock-login1-seat.cc
+ mock-login1-seat.h
mock-display-manager-seat.cc
mock-display-manager-seat.h
mock-end-session-dialog.cc
@@ -25,8 +25,6 @@ add_library (desktopmock STATIC
mock-screen-saver.h
mock-session-manager.cc
mock-session-manager.h
- mock-upower.cc
- mock-upower.h
mock-user.cc
mock-user.h
mock-webcredentials.cc
diff --git a/tests/backend-dbus/gtest-mock-dbus-fixture.h b/tests/backend-dbus/gtest-mock-dbus-fixture.h
index 5c4e312..1b1b895 100644
--- a/tests/backend-dbus/gtest-mock-dbus-fixture.h
+++ b/tests/backend-dbus/gtest-mock-dbus-fixture.h
@@ -20,14 +20,12 @@
#include "gtest-dbus-fixture.h"
#include "mock-accounts.h"
-#include "mock-consolekit-manager.h"
-#include "mock-consolekit-seat.h"
-#include "mock-consolekit-session.h"
+#include "mock-login1-manager.h"
+#include "mock-login1-seat.h"
#include "mock-display-manager-seat.h"
#include "mock-end-session-dialog.h"
#include "mock-screen-saver.h"
#include "mock-session-manager.h"
-#include "mock-upower.h"
#include "mock-user.h"
#include "mock-webcredentials.h"
@@ -47,10 +45,8 @@ class GTestMockDBusFixture: public GTestDBusFixture
MockSessionManager * session_manager;
MockDisplayManagerSeat * dm_seat;
MockAccounts * accounts;
- MockConsoleKitSession * ck_session;
- MockConsoleKitSeat * ck_seat;
- MockConsoleKitManager * ck_manager;
- MockUPower * upower;
+ MockLogin1Manager * login1_manager;
+ MockLogin1Seat * login1_seat;
MockEndSessionDialog * end_session_dialog;
MockWebcredentials * webcredentials;
@@ -64,19 +60,18 @@ class GTestMockDBusFixture: public GTestDBusFixture
end_session_dialog = new MockEndSessionDialog (loop, conn);
session_manager = new MockSessionManager (loop, conn);
screen_saver = new MockScreenSaver (loop, conn);
- upower = new MockUPower (loop, conn);
dm_seat = new MockDisplayManagerSeat (loop, conn);
g_setenv ("XDG_SEAT_PATH", dm_seat->path(), TRUE);
dm_seat->set_guest_allowed (false);
+ login1_manager = new MockLogin1Manager (loop, conn);
+ login1_seat = new MockLogin1Seat (loop, conn, true);
+ login1_manager->add_seat (login1_seat);
accounts = build_accounts_mock ();
- ck_manager = new MockConsoleKitManager (loop, conn);
- ck_seat = new MockConsoleKitSeat (loop, conn, true);
MockUser * user = accounts->find_by_username ("msmith");
- ck_session = ck_seat->add_session_by_user (user);
- ck_manager->add_seat (ck_seat);
- dm_seat->set_consolekit_seat (ck_seat);
+ const int session_tag = login1_manager->add_session (login1_seat, user);
+ dm_seat->set_login1_seat (login1_seat);
dm_seat->switch_to_user (user->username());
- ASSERT_EQ (ck_session, ck_manager->current_session());
+ ASSERT_EQ (session_tag, login1_seat->active_session());
}
protected:
@@ -84,9 +79,8 @@ class GTestMockDBusFixture: public GTestDBusFixture
virtual void TearDown ()
{
delete accounts;
- delete ck_manager;
+ delete login1_manager;
delete dm_seat;
- delete upower;
delete screen_saver;
delete session_manager;
delete end_session_dialog;
diff --git a/tests/backend-dbus/mock-consolekit-manager.cc b/tests/backend-dbus/mock-consolekit-manager.cc
deleted file mode 100644
index 40f9bf9..0000000
--- a/tests/backend-dbus/mock-consolekit-manager.cc
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Copyright 2013 Canonical Ltd.
- *
- * Authors:
- * Charles Kerr <charles.kerr@canonical.com>
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 3, as published
- * by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "mock-consolekit-manager.h"
-#include "mock-consolekit-seat.h"
-#include "mock-consolekit-session.h"
-
-namespace
-{
- const char * CONSOLEKIT_MANAGER_NAME = "org.freedesktop.ConsoleKit";
-
- const char * CONSOLEKIT_MANAGER_PATH = "/org/freedesktop/ConsoleKit/Manager";
-
- void on_active_session_changed (ConsoleKitSeat * o G_GNUC_UNUSED,
- const gchar * new_ssid,
- gpointer ssid)
- {
- *static_cast<std::string*>(ssid) = new_ssid;
- }
-}
-
-/***
-****
-***/
-
-gboolean
-MockConsoleKitManager :: on_get_current_session (ConsoleKitManager * m,
- GDBusMethodInvocation * inv,
- gpointer gself)
-{
- MockConsoleKitManager * self = static_cast<MockConsoleKitManager*>(gself);
- const std::string& ssid = self->my_current_ssid;
- console_kit_manager_complete_get_current_session (m, inv, ssid.c_str());
- return true;
-}
-
-gboolean
-MockConsoleKitManager :: on_get_seats (ConsoleKitManager * m,
- GDBusMethodInvocation * inv,
- gpointer gself)
-{
- int i;
- char ** sids;
- const seats_t& seats = static_cast<MockConsoleKitManager*>(gself)->my_seats;
-
- i = 0;
- sids = g_new0 (char*, seats.size()+1);
- for (seats_t::const_iterator it(seats.begin()),
- end(seats.end()); it!=end; ++it)
- sids[i++] = (char*) (*it)->path();
- console_kit_manager_complete_get_seats (m, inv, sids);
- g_strfreev (sids);
-
- return true;
-}
-
-gboolean
-MockConsoleKitManager :: handle_restart (ConsoleKitManager * ckm,
- GDBusMethodInvocation * inv,
- gpointer gself)
-{
- static_cast<MockConsoleKitManager*>(gself)->my_last_action = Restart;
- console_kit_manager_complete_restart (ckm, inv);
- return true;
-}
-
-gboolean
-MockConsoleKitManager :: handle_stop (ConsoleKitManager * ckm,
- GDBusMethodInvocation * inv,
- gpointer gself)
-{
- static_cast<MockConsoleKitManager*>(gself)->my_last_action = Shutdown;
- console_kit_manager_complete_stop (ckm, inv);
- return true;
-}
-
-/***
-****
-***/
-
-MockConsoleKitSession *
-MockConsoleKitManager :: current_session ()
-{
- MockConsoleKitSession * ret = 0;
-
- for (seats_t::iterator it(my_seats.begin()),
- end(my_seats.end()); it!=end; ++it)
- if ((ret = (*it)->find (my_current_ssid.c_str())))
- break;
-
- return ret;
-}
-
-void
-MockConsoleKitManager :: add_seat (MockConsoleKitSeat * seat)
-{
- g_assert (my_seats.count(seat) == 0);
-
- my_seats.insert (seat);
-
- console_kit_manager_emit_seat_added (my_skeleton, seat->sid());
-
- g_signal_connect (seat->skeleton(), "active-session-changed",
- G_CALLBACK(on_active_session_changed), &my_current_ssid);
-}
-
-/***
-****
-***/
-
-MockConsoleKitManager :: MockConsoleKitManager (GMainLoop * loop,
- GDBusConnection * conn):
- MockObject (loop, conn, CONSOLEKIT_MANAGER_NAME, CONSOLEKIT_MANAGER_PATH),
- my_skeleton (console_kit_manager_skeleton_new ()),
- my_last_action (None)
-{
- g_signal_connect (my_skeleton, "handle-get-current-session",
- G_CALLBACK(on_get_current_session), this);
- g_signal_connect (my_skeleton, "handle-get-seats",
- G_CALLBACK(on_get_seats), this);
- g_signal_connect (my_skeleton, "handle-stop",
- G_CALLBACK(handle_stop), this);
- g_signal_connect (my_skeleton, "handle-restart",
- G_CALLBACK(handle_restart), this);
-
- set_skeleton (G_DBUS_INTERFACE_SKELETON(my_skeleton));
-}
-
-MockConsoleKitManager :: ~MockConsoleKitManager ()
-{
- for (seats_t::iterator it(my_seats.begin()); it!=my_seats.end(); ++it)
- {
- MockConsoleKitSeat * seat = *it;
- g_signal_handlers_disconnect_by_data (seat->skeleton(), &my_current_ssid);
- delete seat;
- }
-
- g_signal_handlers_disconnect_by_data (my_skeleton, this);
- g_clear_object (&my_skeleton);
-}
diff --git a/tests/backend-dbus/mock-consolekit-manager.h b/tests/backend-dbus/mock-consolekit-manager.h
deleted file mode 100644
index c5942b2..0000000
--- a/tests/backend-dbus/mock-consolekit-manager.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright 2013 Canonical Ltd.
- *
- * Authors:
- * Charles Kerr <charles.kerr@canonical.com>
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 3, as published
- * by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef MOCK_CONSOLEKIT_MANAGER_H
-#define MOCK_CONSOLEKIT_MANAGER_H
-
-#include <set>
-#include <string>
-#include "mock-object.h"
-#include "backend-dbus/dbus-consolekit-manager.h"
-
-class MockConsoleKitSession;
-class MockConsoleKitSeat;
-
-class MockConsoleKitManager: public MockObject
-{
- public:
-
- MockConsoleKitManager (GMainLoop * loop,
- GDBusConnection * bus_connection);
- virtual ~MockConsoleKitManager ();
-
- void add_seat (MockConsoleKitSeat * seat);
-
- MockConsoleKitSession * current_session ();
-
- public:
-
- enum Action { None, Shutdown, Restart };
-
- Action last_action () const { return my_last_action; }
-
- void clear_last_action () { my_last_action = None; }
-
- private:
-
- typedef std::set<MockConsoleKitSeat*> seats_t;
- seats_t my_seats;
-
- ConsoleKitManager * my_skeleton;
-
- std::string my_current_ssid;
-
- Action my_last_action;
-
- static gboolean on_get_current_session (ConsoleKitManager *,
- GDBusMethodInvocation *,
- gpointer );
- static gboolean on_get_seats (ConsoleKitManager *,
- GDBusMethodInvocation *,
- gpointer );
- static gboolean handle_restart (ConsoleKitManager *,
- GDBusMethodInvocation *,
- gpointer);
- static gboolean handle_stop (ConsoleKitManager *,
- GDBusMethodInvocation *,
- gpointer);
-
-};
-
-#endif // #ifndef MOCK_CONSOLEKIT_MANAGER_H
diff --git a/tests/backend-dbus/mock-consolekit-seat.cc b/tests/backend-dbus/mock-consolekit-seat.cc
deleted file mode 100644
index ce1fbad..0000000
--- a/tests/backend-dbus/mock-consolekit-seat.cc
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Copyright 2013 Canonical Ltd.
- *
- * Authors:
- * Charles Kerr <charles.kerr@canonical.com>
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 3, as published
- * by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "mock-consolekit-seat.h"
-
-#include "mock-object.h"
-#include "mock-consolekit-session.h"
-#include "mock-user.h"
-
-namespace
-{
- const char * CONSOLEKIT_BUS_NAME = "org.freedesktop.ConsoleKit";
-
- std::string next_unique_sid ()
- {
- static int id = 1;
-
- char * tmp;
- std::string ret;
-
- tmp = g_strdup_printf ("/org/freedesktop/ConsoleKit/Seat%d", id++);
- ret = tmp;
- g_free (tmp);
- return ret;
- }
-}
-
-/***
-****
-***/
-
-void
-MockConsoleKitSeat :: activate_session (MockConsoleKitSession * session)
-{
- g_assert (my_sessions.count(session) == 1);
-
- const char * ssid = session->ssid ();
- if (my_active_ssid != ssid)
- {
- my_active_ssid = ssid;
- console_kit_seat_emit_active_session_changed (my_skeleton, ssid);
- }
-}
-
-void
-MockConsoleKitSeat :: switch_to_guest ()
-{
- for (sessions_t::iterator it(my_sessions.begin()),
- end(my_sessions.end()); it!=end; ++it)
- {
- MockConsoleKitSession * session (*it);
-
- if (session->user()->is_guest())
- {
- activate_session (*it);
- return;
- }
- }
-
- g_warn_if_reached ();
-}
-
-void
-MockConsoleKitSeat :: switch_to_user (const char * username)
-{
- for (sessions_t::iterator it(my_sessions.begin()),
- end(my_sessions.end()); it!=end; ++it)
- {
- MockConsoleKitSession * session (*it);
-
- if (!g_strcmp0 (username, session->user()->username()))
- {
- activate_session (*it);
- return;
- }
- }
-
- g_warn_if_reached ();
-}
-
-/***
-****
-***/
-
-MockConsoleKitSession *
-MockConsoleKitSeat :: add_session_by_user (MockUser * mu)
-{
- g_assert (mu != 0);
-
- MockConsoleKitSession * session;
-
- session = new MockConsoleKitSession (my_loop, my_bus_connection);
- session->set_user (mu);
- add_session (session);
- return session;
-}
-
-void
-MockConsoleKitSeat :: add_session (MockConsoleKitSession * session)
-{
- g_assert (my_sessions.count(session) == 0);
-
- my_sessions.insert (session);
- session->set_sid (path());
- console_kit_seat_emit_session_added (my_skeleton, session->ssid());
-}
-
-void
-MockConsoleKitSeat :: remove_session (MockConsoleKitSession * session)
-{
- g_assert (my_sessions.count(session) == 1);
-
- my_sessions.erase (session);
- session->set_sid ("");
- console_kit_seat_emit_session_removed (my_skeleton, session->ssid());
-}
-
-/***
-**** Handlers
-***/
-
-gboolean
-MockConsoleKitSeat :: on_can_activate_sessions (ConsoleKitSeat * cks,
- GDBusMethodInvocation * inv,
- gpointer gself)
-{
- bool b = static_cast<MockConsoleKitSeat*>(gself)->my_can_activate_sessions;
- console_kit_seat_complete_can_activate_sessions (cks, inv, b);
- return true;
-}
-
-gboolean
-MockConsoleKitSeat :: on_get_active_session (ConsoleKitSeat * cks,
- GDBusMethodInvocation * invoke,
- gpointer gself)
-{
- std::string ssid = static_cast<MockConsoleKitSeat*>(gself)->my_active_ssid;
- console_kit_seat_complete_get_active_session (cks, invoke, ssid.c_str());
- return true;
-}
-
-gboolean
-MockConsoleKitSeat :: on_get_sessions (ConsoleKitSeat * cks,
- GDBusMethodInvocation * inv,
- gpointer gself)
-{
- int i;
- const char ** paths;
- sessions_t& sessions = static_cast<MockConsoleKitSeat*>(gself)->my_sessions;
-
- i = 0;
- paths = g_new0 (const char*, sessions.size() + 1);
- for (sessions_t::iterator it(sessions.begin()),
- end(sessions.end()); it!=end; ++it)
- paths[i++] = (*it)->path();
-
- g_debug ("returning a list of %d sessions", i);
- console_kit_seat_complete_get_sessions (cks, inv, paths);
- g_free (paths);
-
- return true;
-}
-
-MockConsoleKitSession *
-MockConsoleKitSeat :: find (const char * ssid)
-{
- for (sessions_t::iterator it(my_sessions.begin()),
- end(my_sessions.end()); it!=end; ++it)
- if (!g_strcmp0 ((*it)->path(), ssid))
- return *it;
-
- return 0;
-}
-
-/***
-**** Life Cycle
-***/
-
-MockConsoleKitSeat :: MockConsoleKitSeat (GMainLoop * loop,
- GDBusConnection * bus_connection,
- bool can_activate_sessions):
- MockObject (loop, bus_connection, CONSOLEKIT_BUS_NAME, next_unique_sid()),
- my_skeleton (console_kit_seat_skeleton_new ()),
- my_can_activate_sessions (can_activate_sessions)
-{
- g_signal_connect (my_skeleton, "handle-get-active-session",
- G_CALLBACK(on_get_active_session), this);
- g_signal_connect (my_skeleton, "handle-get-sessions",
- G_CALLBACK(on_get_sessions), this);
- g_signal_connect (my_skeleton, "handle-can-activate-sessions",
- G_CALLBACK(on_can_activate_sessions), this);
-
- set_skeleton (G_DBUS_INTERFACE_SKELETON(my_skeleton));
-}
-
-MockConsoleKitSeat :: ~MockConsoleKitSeat ()
-{
- for (sessions_t::iterator it(my_sessions.begin()),
- end(my_sessions.end()); it!=end; ++it)
- delete *it;
-
- g_signal_handlers_disconnect_by_data (my_skeleton, this);
- g_clear_object (&my_skeleton);
-}
diff --git a/tests/backend-dbus/mock-consolekit-seat.h b/tests/backend-dbus/mock-consolekit-seat.h
deleted file mode 100644
index aa52276..0000000
--- a/tests/backend-dbus/mock-consolekit-seat.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2013 Canonical Ltd.
- *
- * Authors:
- * Charles Kerr <charles.kerr@canonical.com>
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 3, as published
- * by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef MOCK_CONSOLEKIT_SEAT_H
-#define MOCK_CONSOLEKIT_SEAT_H
-
-#include <set>
-#include <string>
-#include "backend-dbus/dbus-consolekit-seat.h"
-#include "mock-object.h"
-
-class MockUser;
-class MockConsoleKitSession;
-
-class MockConsoleKitSeat: public MockObject
-{
- public:
-
- MockConsoleKitSeat (GMainLoop * loop,
- GDBusConnection * bus_connection,
- bool can_activate_sessions);
- virtual ~MockConsoleKitSeat ();
-
- const char * sid() { return path(); }
- MockConsoleKitSession * add_session_by_user (MockUser * user);
- void add_session (MockConsoleKitSession * session);
- void remove_session (MockConsoleKitSession * session);
- void activate_session (MockConsoleKitSession * session);
- void switch_to_guest ();
- void switch_to_user (const char * username);
- bool can_activate_sessions () const { return my_can_activate_sessions; }
- MockConsoleKitSession * find (const char * ssid);
-
- private:
-
- static gboolean on_get_active_session (ConsoleKitSeat * cks,
- GDBusMethodInvocation * inv,
- gpointer gself);
- static gboolean on_get_sessions (ConsoleKitSeat * cks,
- GDBusMethodInvocation * inv,
- gpointer gself);
- static gboolean on_can_activate_sessions (ConsoleKitSeat * cks,
- GDBusMethodInvocation * inv,
- gpointer gself);
-
-
- private:
-
- ConsoleKitSeat * my_skeleton;
-
- std::string my_active_ssid;
-
- typedef std::set<MockConsoleKitSession*> sessions_t;
- sessions_t my_sessions;
- bool my_can_activate_sessions;
-
-};
-
-#endif // #ifndef MOCK_CONSOLEKIT_SEAT_H
diff --git a/tests/backend-dbus/mock-consolekit-session.cc b/tests/backend-dbus/mock-consolekit-session.cc
deleted file mode 100644
index 2f39411..0000000
--- a/tests/backend-dbus/mock-consolekit-session.cc
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright 2013 Canonical Ltd.
- *
- * Authors:
- * Charles Kerr <charles.kerr@canonical.com>
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 3, as published
- * by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "mock-consolekit-session.h"
-#include "mock-user.h"
-
-namespace
-{
- const char * const DEFAULT_X11_DISPLAY = ":0:0";
-
- const char * const CONSOLEKIT_NAME = "org.freedesktop.ConsoleKit";
-
- std::string next_unique_ssid ()
- {
- static int id = 333; // arbitrary
-
- char * tmp;
- std::string ret;
-
- tmp = g_strdup_printf ("/org/freedesktop/ConsoleKit/Session%d", id++);
- ret = tmp;
- g_free (tmp);
- return ret;
- }
-}
-
-void
-MockConsoleKitSession :: set_user (MockUser * user)
-{
- my_user = user;
-}
-
-/***
-****
-***/
-
-gboolean
-MockConsoleKitSession :: on_get_seat_id_static (ConsoleKitSession * cks,
- GDBusMethodInvocation * inv,
- gpointer gself)
-{
- const std::string& sid = static_cast<MockConsoleKitSession*>(gself)->my_sid;
- g_debug ("%s %s returning seat id of %s", G_STRLOC, G_STRFUNC, sid.c_str());
- console_kit_session_complete_get_seat_id (cks, inv, sid.c_str());
- return true;
-}
-
-gboolean
-MockConsoleKitSession :: on_get_unix_user_static (ConsoleKitSession * cks,
- GDBusMethodInvocation * inv,
- gpointer gself)
-{
- MockUser * user = static_cast<MockConsoleKitSession*>(gself)->my_user;
- g_debug ("%s %s returning uid of %u", G_STRLOC, G_STRFUNC, user->uid());
- console_kit_session_complete_get_unix_user (cks, inv, user->uid());
- return true;
-}
-
-gboolean
-MockConsoleKitSession :: on_get_x11_display (ConsoleKitSession * cks,
- GDBusMethodInvocation * inv,
- gpointer gself)
-{
- MockConsoleKitSession * self = static_cast<MockConsoleKitSession*>(gself);
- const char * x11 = self->x11_display();
- g_debug ("%s %s returning x11 display '%s'", G_STRLOC, G_STRFUNC, x11);
- console_kit_session_complete_get_x11_display (cks, inv, x11);
- return true;
-}
-
-/***
-****
-***/
-
-MockConsoleKitSession :: MockConsoleKitSession (GMainLoop * loop,
- GDBusConnection * conn):
- MockObject (loop, conn, CONSOLEKIT_NAME, next_unique_ssid ()),
- my_skeleton (console_kit_session_skeleton_new ()),
- my_x11_display (DEFAULT_X11_DISPLAY),
- my_user (0)
-{
- g_signal_connect (my_skeleton, "handle-get-seat-id",
- G_CALLBACK(on_get_seat_id_static), this);
- g_signal_connect (my_skeleton, "handle-get-unix-user",
- G_CALLBACK(on_get_unix_user_static), this);
- g_signal_connect (my_skeleton, "handle-get-x11-display",
- G_CALLBACK(on_get_x11_display), this);
-
- set_skeleton (G_DBUS_INTERFACE_SKELETON(my_skeleton));
-}
-
-MockConsoleKitSession :: ~MockConsoleKitSession ()
-{
- const int n = g_signal_handlers_disconnect_by_data (my_skeleton, this);
- g_assert (n == 3);
- g_clear_object (&my_skeleton);
-}
diff --git a/tests/backend-dbus/mock-consolekit-session.h b/tests/backend-dbus/mock-consolekit-session.h
deleted file mode 100644
index 7759f72..0000000
--- a/tests/backend-dbus/mock-consolekit-session.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 2013 Canonical Ltd.
- *
- * Authors:
- * Charles Kerr <charles.kerr@canonical.com>
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 3, as published
- * by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef MOCK_CONSOLEKIT_SESSION_H
-#define MOCK_CONSOLEKIT_SESSION_H
-
-#include <string>
-#include "mock-object.h"
-#include "backend-dbus/dbus-consolekit-session.h"
-
-class MockUser;
-
-class MockConsoleKitSession: public MockObject
-{
- public:
-
- MockConsoleKitSession (GMainLoop * loop,
- GDBusConnection * bus_connection);
- virtual ~MockConsoleKitSession ();
-
- MockUser * user () { return my_user; }
- void set_user (MockUser * user);
- const char * ssid () { return path(); }
- void set_sid (const std::string& sid) { my_sid = sid; }
- const char * x11_display() { return my_x11_display.c_str(); }
- void set_x11_display (const std::string& x) { my_x11_display = x; }
-
- private:
-
- static gboolean on_get_seat_id_static (ConsoleKitSession *,
- GDBusMethodInvocation *,
- gpointer);
- static gboolean on_get_unix_user_static (ConsoleKitSession *,
- GDBusMethodInvocation *,
- gpointer);
- static gboolean on_get_x11_display (ConsoleKitSession *,
- GDBusMethodInvocation *,
- gpointer);
-
-
- private:
-
- ConsoleKitSession * my_skeleton;
- std::string my_sid;
- std::string my_x11_display;
- MockUser * my_user;
-};
-
-#endif // #ifndef MOCK_CONSOLEKIT_SESSION_H
diff --git a/tests/backend-dbus/mock-display-manager-seat.cc b/tests/backend-dbus/mock-display-manager-seat.cc
index 9f30ae1..c8a4857 100644
--- a/tests/backend-dbus/mock-display-manager-seat.cc
+++ b/tests/backend-dbus/mock-display-manager-seat.cc
@@ -18,7 +18,7 @@
*/
#include "mock-display-manager-seat.h"
-#include "mock-consolekit-seat.h"
+#include "mock-login1-seat.h"
namespace
{
@@ -79,10 +79,10 @@ MockDisplayManagerSeat :: handle_switch_to_guest (DisplayManagerSeat * o,
void
MockDisplayManagerSeat :: switch_to_guest ()
{
- g_assert (my_ck_seat != 0);
+ g_assert (my_login1_seat != 0);
my_last_action = GUEST;
- my_ck_seat->switch_to_guest ();
+ my_login1_seat->switch_to_guest ();
}
gboolean
@@ -100,16 +100,16 @@ MockDisplayManagerSeat :: handle_switch_to_user (DisplayManagerSeat * o,
void
MockDisplayManagerSeat :: switch_to_user (const char * username)
{
- g_assert (my_ck_seat != 0);
+ g_assert (my_login1_seat != 0);
my_last_action = USER;
- my_ck_seat->switch_to_user (username);
+ my_login1_seat->switch_to_user (username);
}
void
-MockDisplayManagerSeat :: set_consolekit_seat (MockConsoleKitSeat * seat)
+MockDisplayManagerSeat :: set_login1_seat (MockLogin1Seat * seat)
{
- my_ck_seat = seat;
+ my_login1_seat = seat;
}
/***
@@ -120,7 +120,6 @@ MockDisplayManagerSeat :: MockDisplayManagerSeat (GMainLoop * loop,
GDBusConnection * connection):
MockObject (loop, connection, DISPLAY_MANAGER_NAME, next_unique_path()),
my_skeleton (display_manager_seat_skeleton_new ()),
- my_ck_seat (0),
my_last_action (NONE)
{
g_signal_connect (my_skeleton, "handle-switch-to-guest",
@@ -135,6 +134,6 @@ MockDisplayManagerSeat :: MockDisplayManagerSeat (GMainLoop * loop,
MockDisplayManagerSeat :: ~MockDisplayManagerSeat ()
{
- g_signal_handlers_disconnect_by_data (my_skeleton, this);
+ //g_signal_handlers_disconnect_by_data (my_skeleton, this);
g_clear_object (&my_skeleton);
}
diff --git a/tests/backend-dbus/mock-display-manager-seat.h b/tests/backend-dbus/mock-display-manager-seat.h
index b0ea415..fcdd17a 100644
--- a/tests/backend-dbus/mock-display-manager-seat.h
+++ b/tests/backend-dbus/mock-display-manager-seat.h
@@ -23,7 +23,7 @@
#include "mock-object.h" // parent class
#include "backend-dbus/dbus-display-manager.h"
-class MockConsoleKitSeat;
+class MockLogin1Seat;
class MockDisplayManagerSeat: public MockObject
{
@@ -35,7 +35,7 @@ class MockDisplayManagerSeat: public MockObject
void set_guest_allowed (bool b);
- void set_consolekit_seat (MockConsoleKitSeat * ck_seat);
+ void set_login1_seat (MockLogin1Seat * login1_seat);
void switch_to_guest ();
@@ -65,7 +65,7 @@ class MockDisplayManagerSeat: public MockObject
gpointer gself);
DisplayManagerSeat * my_skeleton;
- MockConsoleKitSeat * my_ck_seat;
+ MockLogin1Seat * my_login1_seat;
Action my_last_action;
};
diff --git a/tests/backend-dbus/mock-login1-manager.cc b/tests/backend-dbus/mock-login1-manager.cc
new file mode 100644
index 0000000..2d341df
--- /dev/null
+++ b/tests/backend-dbus/mock-login1-manager.cc
@@ -0,0 +1,275 @@
+/*
+ * Copyright 2013 Canonical Ltd.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "mock-login1-manager.h"
+#include "mock-login1-seat.h"
+#include "mock-user.h"
+
+namespace
+{
+ const char * const BUS_NAME = "org.freedesktop.login1";
+
+ const char * const BUS_PATH = "/org/freedesktop/login1";
+
+#if 0
+ void on_active_session_changed (Login1Seat * o G_GNUC_UNUSED,
+ const gchar * new_ssid,
+ gpointer ssid)
+ {
+ *static_cast<std::string*>(ssid) = new_ssid;
+ }
+#endif
+}
+
+/***
+****
+***/
+
+#if 0
+gboolean
+MockLogin1Manager :: on_get_current_session (Login1Manager * m,
+ GDBusMethodInvocation * inv,
+ gpointer gself)
+{
+ MockLogin1Manager * self = static_cast<MockLogin1Manager*>(gself);
+ const std::string& ssid = self->my_current_ssid;
+ console_kit_manager_complete_get_current_session (m, inv, ssid.c_str());
+ return true;
+}
+
+gboolean
+MockLogin1Manager :: on_get_seats (Login1Manager * m,
+ GDBusMethodInvocation * inv,
+ gpointer gself)
+{
+ int i;
+ char ** sids;
+ const seats_t& seats = static_cast<MockLogin1Manager*>(gself)->my_seats;
+
+ i = 0;
+ sids = g_new0 (char*, seats.size()+1);
+ for (seats_t::const_iterator it(seats.begin()),
+ end(seats.end()); it!=end; ++it)
+ sids[i++] = (char*) (*it)->path();
+ console_kit_manager_complete_get_seats (m, inv, sids);
+ g_strfreev (sids);
+
+ return true;
+}
+
+gboolean
+MockLogin1Manager :: handle_restart (Login1Manager * ckm,
+ GDBusMethodInvocation * inv,
+ gpointer gself)
+{
+ static_cast<MockLogin1Manager*>(gself)->my_last_action = Restart;
+ console_kit_manager_complete_restart (ckm, inv);
+ return true;
+}
+
+gboolean
+MockLogin1Manager :: handle_stop (Login1Manager * ckm,
+ GDBusMethodInvocation * inv,
+ gpointer gself)
+{
+ static_cast<MockLogin1Manager*>(gself)->my_last_action = Shutdown;
+ console_kit_manager_complete_stop (ckm, inv);
+ return true;
+}
+#endif
+
+/***
+****
+***/
+
+#if 0
+MockLogin1Session *
+MockLogin1Manager :: current_session ()
+{
+ MockLogin1Session * ret = 0;
+
+ for (seats_t::iterator it(my_seats.begin()),
+ end(my_seats.end()); it!=end; ++it)
+ if ((ret = (*it)->find (my_current_ssid.c_str())))
+ break;
+
+ return ret;
+}
+#endif
+
+void
+MockLogin1Manager :: emit_session_new (MockLogin1Seat * seat, int tag) const
+{
+ std::string id;
+ std::string path;
+
+ 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());
+}
+
+int
+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;
+}
+
+void
+MockLogin1Manager :: add_seat (MockLogin1Seat * seat)
+{
+ g_assert (my_seats.count(seat) == 0);
+
+ my_seats.insert (seat);
+ std::set<int> sessions = seat->sessions ();
+ for (auto tag : sessions)
+ emit_session_new (seat, tag);
+}
+
+/***
+**** Skeleton Handlers
+***/
+
+gboolean
+MockLogin1Manager :: handle_can_suspend (Login1Manager * m,
+ GDBusMethodInvocation * inv,
+ gpointer gself)
+{
+ const std::string& s = static_cast<MockLogin1Manager*>(gself)->can_suspend();
+ login1_manager_complete_can_suspend (m, inv, s.c_str());
+ return true;
+}
+
+gboolean
+MockLogin1Manager :: handle_can_hibernate (Login1Manager * m,
+ GDBusMethodInvocation * inv,
+ gpointer gself)
+{
+ const std::string& s = static_cast<MockLogin1Manager*>(gself)->can_hibernate();
+ login1_manager_complete_can_hibernate (m, inv, s.c_str());
+ return true;
+}
+
+gboolean
+MockLogin1Manager :: handle_reboot (Login1Manager * m,
+ GDBusMethodInvocation * inv,
+ gboolean interactive,
+ gpointer gself)
+{
+ static_cast<MockLogin1Manager*>(gself)->my_last_action = "reboot";
+ login1_manager_complete_reboot (m, inv);
+ return true;
+}
+
+gboolean
+MockLogin1Manager :: handle_power_off (Login1Manager * m,
+ GDBusMethodInvocation * inv,
+ gboolean interactive,
+ gpointer gself)
+{
+ static_cast<MockLogin1Manager*>(gself)->my_last_action = "power-off";
+ login1_manager_complete_power_off (m, inv);
+ return true;
+}
+
+gboolean
+MockLogin1Manager :: handle_suspend (Login1Manager * m,
+ GDBusMethodInvocation * inv,
+ gboolean interactive,
+ gpointer gself)
+{
+ static_cast<MockLogin1Manager*>(gself)->my_last_action = "suspend";
+ login1_manager_complete_suspend (m, inv);
+ return true;
+}
+
+gboolean
+MockLogin1Manager :: handle_hibernate (Login1Manager * m,
+ GDBusMethodInvocation * inv,
+ gboolean interactive,
+ gpointer gself)
+{
+ static_cast<MockLogin1Manager*>(gself)->my_last_action = "hibernate";
+ login1_manager_complete_hibernate (m, inv);
+ return true;
+}
+
+/***
+****
+***/
+
+const std::string&
+MockLogin1Manager :: can_suspend () const
+{
+ return my_can_suspend;
+}
+
+const std::string&
+MockLogin1Manager :: can_hibernate () const
+{
+ return my_can_hibernate;
+}
+
+/***
+****
+***/
+
+MockLogin1Manager :: MockLogin1Manager (GMainLoop * loop,
+ GDBusConnection * conn):
+ MockObject (loop, conn, BUS_NAME, BUS_PATH),
+ my_skeleton (login1_manager_skeleton_new ()),
+ my_can_suspend ("yes"),
+ my_can_hibernate ("yes")
+{
+ g_signal_connect (my_skeleton, "handle-can-suspend",
+ G_CALLBACK(handle_can_suspend), this);
+ g_signal_connect (my_skeleton, "handle-can-hibernate",
+ G_CALLBACK(handle_can_hibernate), this);
+ g_signal_connect (my_skeleton, "handle_reboot",
+ G_CALLBACK(handle_reboot), this);
+ g_signal_connect (my_skeleton, "handle-power-off",
+ G_CALLBACK(handle_power_off), this);
+ g_signal_connect (my_skeleton, "handle-suspend",
+ G_CALLBACK(handle_suspend), this);
+ g_signal_connect (my_skeleton, "handle-hibernate",
+ G_CALLBACK(handle_hibernate), this);
+#if 0
+ g_signal_connect (my_skeleton, "handle-get-seats",
+ G_CALLBACK(on_get_seats), this);
+ g_signal_connect (my_skeleton, "handle-stop",
+ G_CALLBACK(handle_stop), this);
+ g_signal_connect (my_skeleton, "handle-restart",
+ G_CALLBACK(handle_restart), this);
+#endif
+
+ set_skeleton (G_DBUS_INTERFACE_SKELETON(my_skeleton));
+}
+
+MockLogin1Manager :: ~MockLogin1Manager ()
+{
+ for (auto seat : my_seats)
+ delete seat;
+
+ g_signal_handlers_disconnect_by_data (my_skeleton, this);
+ g_clear_object (&my_skeleton);
+}
diff --git a/tests/backend-dbus/mock-login1-manager.h b/tests/backend-dbus/mock-login1-manager.h
new file mode 100644
index 0000000..da05660
--- /dev/null
+++ b/tests/backend-dbus/mock-login1-manager.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2013 Canonical Ltd.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MOCK_LOGIN1_MANAGER_H
+#define MOCK_LOGIN1_MANAGER_H
+
+#include <set>
+#include <string>
+#include "mock-object.h"
+#include "backend-dbus/dbus-login1-manager.h"
+
+class MockLogin1Seat;
+class MockUser;
+
+class MockLogin1Manager: public MockObject
+{
+ public:
+
+ MockLogin1Manager (GMainLoop * loop,
+ GDBusConnection * bus_connection);
+ virtual ~MockLogin1Manager ();
+
+ int add_session (MockLogin1Seat * seat, MockUser * user);
+
+ void add_seat (MockLogin1Seat * seat);
+
+ const std::string& can_suspend () const;
+ const std::string& can_hibernate () const;
+
+ const std::string& last_action () const { return my_last_action; }
+ void clear_last_action () { my_last_action.clear(); }
+
+ private:
+ void emit_session_new (MockLogin1Seat * seat, int tag) const;
+
+ static gboolean handle_can_suspend (Login1Manager *, GDBusMethodInvocation *, gpointer);
+ static gboolean handle_can_hibernate (Login1Manager *, GDBusMethodInvocation *, gpointer);
+ static gboolean handle_reboot (Login1Manager *, GDBusMethodInvocation *, gboolean, gpointer);
+ static gboolean handle_power_off (Login1Manager *, GDBusMethodInvocation *, gboolean, gpointer);
+ static gboolean handle_suspend (Login1Manager *, GDBusMethodInvocation *, gboolean, gpointer);
+ static gboolean handle_hibernate (Login1Manager *, GDBusMethodInvocation *, gboolean, gpointer);
+
+ private:
+
+ Login1Manager * my_skeleton;
+ std::set<MockLogin1Seat*> my_seats;
+ std::string my_can_suspend;
+ std::string my_can_hibernate;
+ std::string my_last_action;
+};
+
+#endif // #ifndef MOCK_LOGIN1_MANAGER_H
diff --git a/tests/backend-dbus/mock-login1-seat.cc b/tests/backend-dbus/mock-login1-seat.cc
new file mode 100644
index 0000000..a95b9e1
--- /dev/null
+++ b/tests/backend-dbus/mock-login1-seat.cc
@@ -0,0 +1,230 @@
+/*
+ * Copyright 2013 Canonical Ltd.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "mock-login1-seat.h"
+
+#include "mock-object.h"
+#include "mock-user.h"
+
+namespace
+{
+ const char * BUS_NAME = "org.freedesktop.login1";
+
+ std::string next_unique_sid ()
+ {
+ static int id = 1;
+
+ char * tmp;
+ std::string ret;
+
+ tmp = g_strdup_printf ("/org/freedesktop/login1/seat/seat%d", id++);
+ ret = tmp;
+ g_free (tmp);
+ return ret;
+ }
+
+ static int next_session_tag = 1;
+}
+
+void
+MockLogin1Seat :: get_session_id_and_path_for_tag (int tag, std::string& id, std::string& path)
+{
+ if (tag)
+ {
+ char tmp[80];
+
+ g_snprintf (tmp, sizeof(tmp), "%d", tag);
+ id = tmp;
+
+ g_snprintf (tmp, sizeof(tmp), "/org/freedesktop/login1/session/%d", tag);
+ path = tmp;
+ }
+ else
+ {
+ id = "";
+ path = "";
+ }
+}
+
+
+/***
+****
+***/
+
+void
+MockLogin1Seat :: update_sessions_property ()
+{
+ GVariantBuilder b;
+
+ g_variant_builder_init (&b, G_VARIANT_TYPE("a(so)"));
+ for (const auto& it : my_sessions)
+ {
+ std::string id, path;
+ get_session_id_and_path_for_tag (it.first, id, path);
+ g_variant_builder_add (&b, "(so)", id.c_str(), path.c_str());
+ }
+
+ GVariant * v = g_variant_builder_end (&b);
+ g_message ("%s %s setting session property to %s", G_STRLOC, G_STRFUNC, g_variant_print (v, true));
+ g_object_set (my_skeleton, "sessions", v, NULL);
+}
+
+void
+MockLogin1Seat :: update_active_session_property ()
+{
+ std::string id;
+ std::string path;
+ get_session_id_and_path_for_tag (my_active_session, id, path);
+
+ GVariant * v = g_variant_new ("(so)", id.c_str(), path.c_str());
+ g_message ("%s %s setting active session property to %s", G_STRLOC, G_STRFUNC, g_variant_print (v, true));
+ g_object_set (my_skeleton, "active-session", v, NULL);
+}
+
+void
+MockLogin1Seat :: update_can_multi_session_property ()
+{
+ g_object_set (my_skeleton, "can-multi-session", my_can_multi_session, NULL);
+}
+
+/***
+****
+***/
+
+/* lists this seat's sessions in the format of Login1Manager::ListSessions() */
+GVariant *
+MockLogin1Seat :: list_sessions ()
+{
+ GVariantBuilder b;
+ g_variant_builder_init (&b, G_VARIANT_TYPE("a(susso)"));
+ for (auto it : my_sessions)
+ {
+ std::string id, path;
+ get_session_id_and_path_for_tag (it.first, id, path);
+ g_variant_builder_add (&b, "(susso)",
+ id.c_str(),
+ uint32_t(it.second->uid()),
+ it.second->username(),
+ seat_id(),
+ path.c_str());
+ }
+
+ return g_variant_builder_end (&b);
+}
+
+/***
+****
+***/
+
+std::set<int>
+MockLogin1Seat :: sessions () const
+{
+ std::set<int> ret;
+
+ for (auto it : my_sessions)
+ ret.insert (it.first);
+
+ return ret;
+}
+
+MockLogin1Seat :: session_tag_t
+MockLogin1Seat :: add_session (MockUser * user)
+{
+ const session_tag_t tag = next_session_tag++;
+
+ my_sessions[tag] = user;
+ update_sessions_property ();
+
+ return tag;
+}
+
+void
+MockLogin1Seat :: remove_session (session_tag_t tag)
+{
+ my_sessions.erase (tag);
+ update_sessions_property ();
+}
+
+/***
+****
+***/
+
+void
+MockLogin1Seat :: activate_session (session_tag_t tag)
+{
+ g_assert (my_sessions.count(tag) == 1);
+
+ if (my_active_session != tag)
+ {
+ my_active_session = tag;
+ update_active_session_property ();
+ }
+}
+
+void
+MockLogin1Seat :: switch_to_guest ()
+{
+ for (const auto& it : my_sessions)
+ {
+ if (it.second->is_guest())
+ {
+ activate_session (it.first);
+ return;
+ }
+ }
+
+ g_warn_if_reached ();
+}
+
+void
+MockLogin1Seat :: switch_to_user (const char * username)
+{
+ for (const auto& it : my_sessions)
+ {
+ if (!g_strcmp0 (username, it.second->username()))
+ {
+ activate_session (it.first);
+ return;
+ }
+ }
+
+ g_warn_if_reached ();
+}
+
+/***
+**** Life Cycle
+***/
+
+MockLogin1Seat :: MockLogin1Seat (GMainLoop * loop,
+ GDBusConnection * bus_connection,
+ bool can_activate_sessions):
+ MockObject (loop, bus_connection, BUS_NAME, next_unique_sid()),
+ my_skeleton (login1_seat_skeleton_new ()),
+ my_can_multi_session (can_activate_sessions),
+ my_active_session (0)
+
+{
+ set_skeleton (G_DBUS_INTERFACE_SKELETON(my_skeleton));
+ update_can_multi_session_property ();
+}
+
+MockLogin1Seat :: ~MockLogin1Seat ()
+{
+ g_clear_object (&my_skeleton);
+}
diff --git a/tests/backend-dbus/mock-login1-seat.h b/tests/backend-dbus/mock-login1-seat.h
new file mode 100644
index 0000000..96ff19c
--- /dev/null
+++ b/tests/backend-dbus/mock-login1-seat.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2013 Canonical Ltd.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MOCK_LOGIN1_SEAT_H
+#define MOCK_LOGIN1_SEAT_H
+
+#include <cstring> /* strrchr */
+#include <map>
+#include <set>
+#include <string>
+#include "backend-dbus/dbus-login1-seat.h"
+#include "mock-object.h"
+
+class MockUser;
+class MockLogin1Session;
+
+class MockLogin1Seat: public MockObject
+{
+ public:
+
+ typedef int session_tag_t;
+
+ MockLogin1Seat (GMainLoop * loop,
+ GDBusConnection * bus_connection,
+ bool can_activate_sessions);
+
+ virtual ~MockLogin1Seat ();
+
+ const char * seat_id() const { return strrchr(path(),'/')+1; }
+
+ session_tag_t add_session (MockUser * user);
+ void remove_session (session_tag_t session);
+ std::set<int> sessions () const;
+ int active_session () const { return my_active_session; }
+
+ bool can_activate_sessions () const { return my_can_multi_session; }
+ void activate_session (session_tag_t session);
+ void switch_to_guest ();
+ void switch_to_user (const char * username);
+
+ //const char * sid() { return path(); }
+ //MockLogin1Session * find (const char * ssid);
+
+ GVariant * list_sessions ();
+
+ static void get_session_id_and_path_for_tag (int tag, std::string& id, std::string& path);
+
+ private:
+ void update_sessions_property ();
+ void update_active_session_property ();
+ void update_can_multi_session_property ();
+
+
+ private:
+ Login1Seat * my_skeleton;
+ std::map<session_tag_t,MockUser*> my_sessions;
+ session_tag_t my_active_session;
+ bool my_can_multi_session;
+};
+
+#endif // #ifndef MOCK_LOGIN1_SEAT_H
diff --git a/tests/backend-dbus/mock-upower.cc b/tests/backend-dbus/mock-upower.cc
deleted file mode 100644
index 65757b3..0000000
--- a/tests/backend-dbus/mock-upower.cc
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright 2013 Canonical Ltd.
- *
- * Authors:
- * Charles Kerr <charles.kerr@canonical.com>
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 3, as published
- * by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "mock-upower.h"
-
-
-gboolean
-MockUPower :: handle_suspend (UPower * upower,
- GDBusMethodInvocation * inv,
- gpointer gself)
-{
- static_cast<MockUPower*>(gself)->my_last_action = Suspend;
- upower_complete_suspend (upower, inv);
- return true;
-}
-
-gboolean
-MockUPower :: handle_hibernate (UPower * upower,
- GDBusMethodInvocation * inv,
- gpointer gself)
-{
- static_cast<MockUPower*>(gself)->my_last_action = Hibernate;
- upower_complete_hibernate (upower, inv);
- return true;
-}
-
-gboolean
-MockUPower :: handle_suspend_allowed (UPower * upower,
- GDBusMethodInvocation * inv,
- gpointer gself)
-{
- const bool allowed = static_cast<MockUPower*>(gself)->my_can_suspend;
- upower_complete_suspend_allowed (upower, inv, allowed);
- return true;
-}
-
-gboolean
-MockUPower :: handle_hibernate_allowed (UPower * upower,
- GDBusMethodInvocation * inv,
- gpointer gself)
-{
- const bool allowed = static_cast<MockUPower*>(gself)->my_can_hibernate;
- upower_complete_hibernate_allowed (upower, inv, allowed);
- return true;
-}
-
-/***
-****
-***/
-
-namespace
-{
- const char * const UPOWER_NAME = "org.freedesktop.UPower";
- const char * const UPOWER_PATH = "/org/freedesktop/UPower";
-
-}
-
-MockUPower :: MockUPower (GMainLoop * loop,
- GDBusConnection * bus_connection):
- MockObject (loop, bus_connection, UPOWER_NAME, UPOWER_PATH),
- my_skeleton (upower_skeleton_new ()),
- my_can_suspend (true),
- my_can_hibernate (true),
- my_suspend_allowed (true),
- my_hibernate_allowed (true),
- my_last_action (None)
-{
- //set_can_hibernate (false);
- //set_can_suspend (true);
-
- g_signal_connect (my_skeleton, "handle-suspend",
- G_CALLBACK(handle_suspend), this);
- g_signal_connect (my_skeleton, "handle-suspend-allowed",
- G_CALLBACK(handle_suspend_allowed), this);
-
- g_signal_connect (my_skeleton, "handle-hibernate",
- G_CALLBACK(handle_hibernate), this);
- g_signal_connect (my_skeleton, "handle-hibernate-allowed",
- G_CALLBACK(handle_hibernate_allowed), this);
-
- set_skeleton (G_DBUS_INTERFACE_SKELETON(my_skeleton));
-}
-
-MockUPower :: ~MockUPower ()
-{
- g_clear_object (&my_skeleton);
-}
diff --git a/tests/backend-dbus/mock-upower.h b/tests/backend-dbus/mock-upower.h
deleted file mode 100644
index 351d0f7..0000000
--- a/tests/backend-dbus/mock-upower.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2013 Canonical Ltd.
- *
- * Authors:
- * Charles Kerr <charles.kerr@canonical.com>
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 3, as published
- * by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef MOCK_UPOWER_H
-#define MOCK_UPOWER_H
-
-#include "mock-object.h" // parent class
-#include "backend-dbus/dbus-upower.h" // UPower
-
-class MockUPower: public MockObject
-{
- public:
-
- MockUPower (GMainLoop * loop,
- GDBusConnection * bus_connection);
- virtual ~MockUPower ();
-
- void set_can_suspend (bool b) { upower_set_can_suspend (my_skeleton, b); }
- void set_can_hibernate (bool b) { upower_set_can_hibernate (my_skeleton, b); }
-
- bool suspend_allowed () const { return my_suspend_allowed; }
- bool hibernate_allowed () const { return my_suspend_allowed; }
- bool can_suspend () const { return upower_get_can_suspend (my_skeleton); }
- bool can_hibernate () const { return upower_get_can_hibernate (my_skeleton); }
-
- public:
-
- enum Action { None, Suspend, Hibernate };
- Action last_action () { return my_last_action; }
-
- private:
-
- UPower * my_skeleton;
- bool my_can_suspend;
- bool my_can_hibernate;
- bool my_suspend_allowed;
- bool my_hibernate_allowed;
- Action my_last_action;
-
- static gboolean handle_suspend_allowed (UPower *,
- GDBusMethodInvocation *,
- gpointer);
- static gboolean handle_suspend (UPower *,
- GDBusMethodInvocation *,
- gpointer);
-
- static gboolean handle_hibernate_allowed (UPower *,
- GDBusMethodInvocation *,
- gpointer);
- static gboolean handle_hibernate (UPower *,
- GDBusMethodInvocation *,
- gpointer);
-
-};
-
-#endif
diff --git a/tests/backend-dbus/test-actions.cc b/tests/backend-dbus/test-actions.cc
index f79c913..410a02a 100644
--- a/tests/backend-dbus/test-actions.cc
+++ b/tests/backend-dbus/test-actions.cc
@@ -90,7 +90,7 @@ TEST_F (Actions, CanSwitch)
bool b;
gboolean b2;
- b = ck_seat->can_activate_sessions() && !g_settings_get_boolean (s, settings_key);
+ b = login1_seat->can_activate_sessions() && !g_settings_get_boolean (s, settings_key);
ASSERT_EQ (b, indicator_session_actions_can_switch (actions));
g_object_get (actions, INDICATOR_SESSION_ACTIONS_PROP_CAN_SWITCH, &b2, NULL);
ASSERT_EQ (b, b2);
@@ -172,130 +172,88 @@ TEST_F (Actions, CanLogout)
TEST_F (Actions, CanSuspend)
{
- bool b;
- bool can;
- bool allowed;
- gboolean b2;
-
- can = upower->can_suspend ();
- allowed = upower->suspend_allowed ();
- b = can && allowed;
-
- ASSERT_EQ (b, indicator_session_actions_can_suspend (actions));
- g_object_get (actions, INDICATOR_SESSION_ACTIONS_PROP_CAN_SUSPEND, &b2, NULL);
- ASSERT_EQ (b, b2);
-
- for (int i=0; i<2; ++i)
- {
- can = !can;
- b = can && allowed;
-
- upower->set_can_suspend (can);
- wait_for_signal (actions, "notify::" INDICATOR_SESSION_ACTIONS_PROP_CAN_SUSPEND);
- ASSERT_EQ (b, indicator_session_actions_can_suspend (actions));
- g_object_get (actions, INDICATOR_SESSION_ACTIONS_PROP_CAN_SUSPEND, &b2, NULL);
- ASSERT_EQ (b, b2);
- }
+ const std::string can_suspend = login1_manager->can_suspend ();
+ gboolean b = indicator_session_actions_can_suspend (actions);
+ ASSERT_EQ (b, can_suspend=="yes" || can_suspend=="challenge");
}
TEST_F (Actions, CanHibernate)
{
- bool b;
- bool can;
- bool allowed;
- gboolean b2;
-
- can = upower->can_hibernate ();
- allowed = upower->hibernate_allowed ();
- b = can && allowed;
-
- ASSERT_EQ (b, indicator_session_actions_can_hibernate (actions));
- g_object_get (actions, INDICATOR_SESSION_ACTIONS_PROP_CAN_HIBERNATE, &b2, NULL);
- ASSERT_EQ (b, b2);
-
-#if 0
- for (int i=0; i<2; ++i)
- {
- b = !b;
- upower->set_can_hibernate (b);
- wait_for_signal (actions, "notify::" INDICATOR_SESSION_ACTIONS_PROP_CAN_HIBERNATE);
- ASSERT_EQ (b, indicator_session_actions_can_hibernate (actions));
- g_object_get (actions, INDICATOR_SESSION_ACTIONS_PROP_CAN_HIBERNATE, &b2, NULL);
- ASSERT_EQ (b, b2);
- }
-#endif
+ const std::string can_hibernate = login1_manager->can_hibernate ();
+ gboolean b = indicator_session_actions_can_hibernate (actions);
+ ASSERT_EQ (b, can_hibernate=="yes" || can_hibernate=="challenge");
}
-TEST_F (Actions, Restart)
+TEST_F (Actions, Reboot)
{
- ASSERT_EQ (MockConsoleKitManager::None, ck_manager->last_action());
+ ASSERT_TRUE (login1_manager->last_action().empty());
// confirm that user is prompted
// and that no action is taken when the user cancels the dialog
- indicator_session_actions_restart (actions);
+ indicator_session_actions_reboot (actions);
wait_msec (50);
ASSERT_TRUE (end_session_dialog->is_open());
end_session_dialog->cancel();
wait_msec (50);
- ASSERT_EQ (MockConsoleKitManager::None, ck_manager->last_action());
+ ASSERT_TRUE (login1_manager->last_action().empty());
// confirm that user is prompted
// and that no action is taken when the user cancels the dialog
- indicator_session_actions_restart (actions);
+ indicator_session_actions_reboot (actions);
wait_msec (50);
ASSERT_TRUE (end_session_dialog->is_open ());
end_session_dialog->confirm_reboot ();
wait_msec (100);
- ASSERT_EQ (MockConsoleKitManager::Restart, ck_manager->last_action());
+ ASSERT_EQ (login1_manager->last_action(), "reboot");
- // confirm that we try to restart w/o prompting
+ // confirm that we try to reboot w/o prompting
// if the EndSessionDialog isn't available
delete end_session_dialog;
end_session_dialog = 0;
- ck_manager->clear_last_action ();
- ASSERT_EQ (MockConsoleKitManager::None, ck_manager->last_action());
+ login1_manager->clear_last_action ();
+ ASSERT_TRUE (login1_manager->last_action().empty());
wait_msec (50);
- indicator_session_actions_restart (actions);
+ indicator_session_actions_reboot (actions);
wait_msec (50);
- ASSERT_EQ (MockConsoleKitManager::Restart, ck_manager->last_action());
+ ASSERT_EQ (login1_manager->last_action(), "reboot");
}
-TEST_F (Actions, Shutdown)
+TEST_F (Actions, PowerOff)
{
- ASSERT_EQ (MockConsoleKitManager::None, ck_manager->last_action());
+ ASSERT_TRUE (login1_manager->last_action().empty());
// confirm that user is prompted
// and that no action is taken when the user cancels the dialog
- indicator_session_actions_shutdown (actions);
+ indicator_session_actions_power_off (actions);
wait_msec (50);
ASSERT_TRUE (end_session_dialog->is_open());
end_session_dialog->cancel();
wait_msec (50);
- ASSERT_EQ (MockConsoleKitManager::None, ck_manager->last_action());
+ ASSERT_TRUE (login1_manager->last_action().empty());
// confirm that user is prompted
// and that no action is taken when the user cancels the dialog
- indicator_session_actions_shutdown (actions);
+ indicator_session_actions_power_off (actions);
wait_msec (50);
ASSERT_TRUE (end_session_dialog->is_open ());
end_session_dialog->confirm_shutdown ();
wait_msec (100);
- ASSERT_EQ (MockConsoleKitManager::Shutdown, ck_manager->last_action());
+ ASSERT_EQ (login1_manager->last_action(), "power-off");
// confirm that we try to shutdown w/o prompting
// if the EndSessionDialog isn't available
delete end_session_dialog;
end_session_dialog = 0;
- ck_manager->clear_last_action ();
+ login1_manager->clear_last_action ();
wait_msec (50);
- indicator_session_actions_shutdown (actions);
+ indicator_session_actions_power_off (actions);
wait_msec (50);
- ASSERT_EQ (MockConsoleKitManager::Shutdown, ck_manager->last_action());
+ ASSERT_EQ (login1_manager->last_action(), "power-off");
}
TEST_F (Actions, Logout)
{
- ASSERT_EQ (MockConsoleKitManager::None, ck_manager->last_action());
+ ASSERT_EQ (MockSessionManager::None, session_manager->last_action ());
// confirm that user is prompted
// and that no action is taken when the user cancels the dialog
@@ -308,7 +266,7 @@ TEST_F (Actions, Logout)
// confirm that user is prompted
// and that no action is taken when the user cancels the dialog
- indicator_session_actions_shutdown (actions);
+ indicator_session_actions_logout (actions);
wait_msec (50);
ASSERT_TRUE (end_session_dialog->is_open ());
end_session_dialog->confirm_logout ();
@@ -327,18 +285,18 @@ TEST_F (Actions, Logout)
TEST_F (Actions, Suspend)
{
- ASSERT_EQ (MockUPower::None, upower->last_action());
+ ASSERT_TRUE (login1_manager->last_action().empty());
indicator_session_actions_suspend (actions);
wait_msec (50);
- ASSERT_EQ (MockUPower::Suspend, upower->last_action());
+ ASSERT_EQ (login1_manager->last_action(), "suspend");
}
TEST_F (Actions, Hibernate)
{
- ASSERT_EQ (MockUPower::None, upower->last_action());
+ ASSERT_TRUE (login1_manager->last_action().empty());
indicator_session_actions_hibernate (actions);
wait_msec (50);
- ASSERT_EQ (MockUPower::Hibernate, upower->last_action());
+ ASSERT_EQ (login1_manager->last_action(), "hibernate");
}
TEST_F (Actions, SwitchToScreensaver)
@@ -362,18 +320,19 @@ TEST_F (Actions, SwitchToGuest)
// allow guests
dm_seat->set_guest_allowed (true);
MockUser * guest_user;
- MockConsoleKitSession * guest_ck_session;
+ //int guest_session_tag;
+// MockConsoleKitSession * guest_ck_session;
// set up a guest
guest_user = new MockUser (loop, conn, "guest-zzbEVV", "Guest", 10);
guest_user->set_system_account (true);
accounts->add_user (guest_user);
- guest_ck_session = ck_seat->add_session_by_user (guest_user);
+ int guest_session_tag = login1_manager->add_session (login1_seat, guest_user);
// try to switch to guest
indicator_session_actions_switch_to_guest (actions);
- wait_for_signal (ck_seat->skeleton(), "active-session-changed");
- ASSERT_EQ (guest_ck_session, ck_manager->current_session());
+ wait_for_signal (login1_seat->skeleton(), "notify::active-session");
+ ASSERT_EQ (guest_session_tag, login1_seat->active_session());
wait_msec (50);
}
@@ -383,28 +342,28 @@ TEST_F (Actions, SwitchToUsername)
const char * const dr2_username = "ptroughton";
MockUser * dr1_user;
MockUser * dr2_user;
- MockConsoleKitSession * dr1_session;
- MockConsoleKitSession * dr2_session;
+ int dr1_session;
+ int dr2_session;
dr1_user = accounts->find_by_username (dr1_username);
- dr1_session = ck_seat->add_session_by_user (dr1_user);
+ dr1_session = login1_manager->add_session (login1_seat, dr1_user);
dr2_user = accounts->find_by_username (dr2_username);
- dr2_session = ck_seat->add_session_by_user (dr2_user);
+ dr2_session = login1_manager->add_session (login1_seat, dr2_user);
indicator_session_actions_switch_to_username (actions, dr1_username);
- wait_for_signal (ck_seat->skeleton(), "active-session-changed");
- ASSERT_EQ (dr1_session, ck_manager->current_session());
+ wait_for_signal (login1_seat->skeleton(), "notify::active-session");
+ ASSERT_EQ (dr1_session, login1_seat->active_session());
wait_msec (50);
indicator_session_actions_switch_to_username (actions, dr2_username);
- wait_for_signal (ck_seat->skeleton(), "active-session-changed");
- ASSERT_EQ (dr2_session, ck_manager->current_session());
+ wait_for_signal (login1_seat->skeleton(), "notify::active-session");
+ ASSERT_EQ (dr2_session, login1_seat->active_session());
wait_msec (50);
indicator_session_actions_switch_to_username (actions, dr1_username);
- wait_for_signal (ck_seat->skeleton(), "active-session-changed");
- ASSERT_EQ (dr1_session, ck_manager->current_session());
+ wait_for_signal (login1_seat->skeleton(), "notify::active-session");
+ ASSERT_EQ (dr1_session, login1_seat->active_session());
wait_msec (50);
}