From 9cfc9e9da79cabacf1f81e96511d10895992c47d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 24 Jun 2013 17:13:07 -0500 Subject: get all the tests in test-actions passing again. --- tests/backend-dbus/mock-login1-manager.cc | 275 ++++++++++++++++++++++++++++++ 1 file changed, 275 insertions(+) create mode 100644 tests/backend-dbus/mock-login1-manager.cc (limited to 'tests/backend-dbus/mock-login1-manager.cc') 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 + * + * 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 . + */ + +#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(ssid) = new_ssid; + } +#endif +} + +/*** +**** +***/ + +#if 0 +gboolean +MockLogin1Manager :: on_get_current_session (Login1Manager * m, + GDBusMethodInvocation * inv, + gpointer gself) +{ + MockLogin1Manager * self = static_cast(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(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(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(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 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(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(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(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(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(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(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); +} -- cgit v1.2.3