From ae39f7001e5603010afc02de29787ade6d48ef14 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 22 Mar 2013 16:34:34 -0500 Subject: port indicator-session to GMenu/cmake. Code coverage increased from 0% to 95.4%. --- tests/backend-dbus/mock-display-manager-seat.cc | 140 ++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 tests/backend-dbus/mock-display-manager-seat.cc (limited to 'tests/backend-dbus/mock-display-manager-seat.cc') 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 + * + * 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-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(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(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(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); +} -- cgit v1.2.3 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-display-manager-seat.cc | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'tests/backend-dbus/mock-display-manager-seat.cc') 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); } -- cgit v1.2.3