aboutsummaryrefslogtreecommitdiff
path: root/tests/backend-dbus/mock-display-manager-seat.cc
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2013-03-22 16:34:34 -0500
committerCharles Kerr <charles.kerr@canonical.com>2013-03-22 16:34:34 -0500
commitae39f7001e5603010afc02de29787ade6d48ef14 (patch)
tree74c303a86603134fc2b86d1c428475a60e455e3f /tests/backend-dbus/mock-display-manager-seat.cc
parente4e327f139dd139a91893fc7f19061a37d4b47e9 (diff)
downloadayatana-indicator-session-ae39f7001e5603010afc02de29787ade6d48ef14.tar.gz
ayatana-indicator-session-ae39f7001e5603010afc02de29787ade6d48ef14.tar.bz2
ayatana-indicator-session-ae39f7001e5603010afc02de29787ade6d48ef14.zip
port indicator-session to GMenu/cmake. Code coverage increased from 0% to 95.4%.
Diffstat (limited to 'tests/backend-dbus/mock-display-manager-seat.cc')
-rw-r--r--tests/backend-dbus/mock-display-manager-seat.cc140
1 files changed, 140 insertions, 0 deletions
diff --git a/tests/backend-dbus/mock-display-manager-seat.cc b/tests/backend-dbus/mock-display-manager-seat.cc
new file mode 100644
index 0000000..9f30ae1
--- /dev/null
+++ b/tests/backend-dbus/mock-display-manager-seat.cc
@@ -0,0 +1,140 @@
+/*
+ * 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-display-manager-seat.h"
+#include "mock-consolekit-seat.h"
+
+namespace
+{
+ const char * const DISPLAY_MANAGER_NAME = "org.freedesktop.DisplayManager";
+
+ std::string
+ next_unique_path ()
+ {
+ static int id = 12; // arbitrary; doesn't matter
+
+ char * tmp;
+ std::string ret;
+
+ tmp = g_strdup_printf ("/org/freedesktop/DisplayManager/Seat%d", id++);
+ ret = tmp;
+ g_free (tmp);
+ return ret;
+ }
+}
+
+/***
+****
+***/
+
+void
+MockDisplayManagerSeat :: switch_to_greeter ()
+{
+ my_last_action = GREETER;
+}
+
+gboolean
+MockDisplayManagerSeat :: handle_switch_to_greeter (DisplayManagerSeat * o,
+ GDBusMethodInvocation * inv,
+ gpointer gself)
+{
+ static_cast<MockDisplayManagerSeat*>(gself)->switch_to_greeter ();
+ display_manager_seat_complete_switch_to_greeter (o, inv);
+ return true;
+}
+
+void
+MockDisplayManagerSeat :: set_guest_allowed (bool b)
+{
+ display_manager_seat_set_has_guest_account (my_skeleton, b);
+}
+
+gboolean
+MockDisplayManagerSeat :: handle_switch_to_guest (DisplayManagerSeat * o,
+ GDBusMethodInvocation * inv,
+ const gchar * session_name G_GNUC_UNUSED,
+ gpointer gself)
+{
+ static_cast<MockDisplayManagerSeat*>(gself)->switch_to_guest ();
+ display_manager_seat_complete_switch_to_guest (o, inv);
+ return true;
+}
+
+void
+MockDisplayManagerSeat :: switch_to_guest ()
+{
+ g_assert (my_ck_seat != 0);
+
+ my_last_action = GUEST;
+ my_ck_seat->switch_to_guest ();
+}
+
+gboolean
+MockDisplayManagerSeat :: handle_switch_to_user (DisplayManagerSeat * o,
+ GDBusMethodInvocation * inv,
+ const gchar * username,
+ const gchar * session_name G_GNUC_UNUSED,
+ gpointer gself)
+{
+ static_cast<MockDisplayManagerSeat*>(gself)->switch_to_user (username);
+ display_manager_seat_complete_switch_to_user (o, inv);
+ return true;
+}
+
+void
+MockDisplayManagerSeat :: switch_to_user (const char * username)
+{
+ g_assert (my_ck_seat != 0);
+
+ my_last_action = USER;
+ my_ck_seat->switch_to_user (username);
+}
+
+void
+MockDisplayManagerSeat :: set_consolekit_seat (MockConsoleKitSeat * seat)
+{
+ my_ck_seat = seat;
+}
+
+/***
+****
+***/
+
+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",
+ G_CALLBACK(handle_switch_to_guest), this);
+ g_signal_connect (my_skeleton, "handle-switch-to-user",
+ G_CALLBACK(handle_switch_to_user), this);
+ g_signal_connect (my_skeleton, "handle-switch-to-greeter",
+ G_CALLBACK(handle_switch_to_greeter), this);
+
+ set_skeleton (G_DBUS_INTERFACE_SKELETON(my_skeleton));
+}
+
+MockDisplayManagerSeat :: ~MockDisplayManagerSeat ()
+{
+ g_signal_handlers_disconnect_by_data (my_skeleton, this);
+ g_clear_object (&my_skeleton);
+}