indicator-session-12.10.5+14.04.20140410/0000755000015301777760000000000012321553665017716 5ustar pbusernogroup00000000000000indicator-session-12.10.5+14.04.20140410/cmake/0000755000015301777760000000000012321553665020776 5ustar pbusernogroup00000000000000indicator-session-12.10.5+14.04.20140410/cmake/GCov.cmake0000644000015301777760000000520012321553465022631 0ustar pbusernogroup00000000000000if (CMAKE_BUILD_TYPE MATCHES coverage) set(GCOV_FLAGS "${GCOV_FLAGS} --coverage") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCOV_FLAGS}") set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${GCOV_FLAGS}") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GCOV_FLAGS}") set(GCOV_LIBS ${GCOV_LIBS} gcov) find_program(GCOVR_EXECUTABLE gcovr HINTS ${GCOVR_ROOT} "${GCOVR_ROOT}/bin") if (NOT GCOVR_EXECUTABLE) message(STATUS "Gcovr binary was not found, can not generate XML coverage info.") else () message(STATUS "Gcovr found, can generate XML coverage info.") add_custom_target (coverage-xml WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND "${GCOVR_EXECUTABLE}" --exclude="test.*" -x -r "${CMAKE_SOURCE_DIR}" --object-directory=${CMAKE_BINARY_DIR} -o coverage.xml) endif() find_program(LCOV_EXECUTABLE lcov HINTS ${LCOV_ROOT} "${GCOVR_ROOT}/bin") find_program(GENHTML_EXECUTABLE genhtml HINTS ${GENHTML_ROOT}) if (NOT LCOV_EXECUTABLE) message(STATUS "Lcov binary was not found, can not generate HTML coverage info.") else () if(NOT GENHTML_EXECUTABLE) message(STATUS "Genthml binary not found, can not generate HTML coverage info.") else() message(STATUS "Lcov and genhtml found, can generate HTML coverage info.") add_custom_target (coverage-html WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND "${CMAKE_CTEST_COMMAND}" --force-new-ctest-process --verbose COMMAND "${LCOV_EXECUTABLE}" --directory ${CMAKE_BINARY_DIR} --capture | ${CMAKE_SOURCE_DIR}/trim-lcov.py > dconf-lcov.info COMMAND LANG=C "${GENHTML_EXECUTABLE}" --prefix ${CMAKE_BINARY_DIR} --output-directory lcov-html --legend --show-details dconf-lcov.info COMMAND ${CMAKE_COMMAND} -E echo "" COMMAND ${CMAKE_COMMAND} -E echo "file://${CMAKE_BINARY_DIR}/lcov-html/index.html" COMMAND ${CMAKE_COMMAND} -E echo "") #COMMAND "${LCOV_EXECUTABLE}" --directory ${CMAKE_BINARY_DIR} --capture --output-file coverage.info --no-checksum #COMMAND "${GENHTML_EXECUTABLE}" --prefix ${CMAKE_BINARY_DIR} --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info #COMMAND ${CMAKE_COMMAND} -E echo "\\#define foo \\\"bar\\\"" #) endif() endif() endif() #$(MAKE) $(AM_MAKEFLAGS) check #lcov --directory $(top_builddir) --capture --test-name dconf | $(top_srcdir)/trim-lcov.py > dconf-lcov.info #LANG=C genhtml --prefix $(top_builddir) --output-directory lcov-html --legend --show-details dconf-lcov.info #@echo #@echo " file://$(abs_top_builddir)/lcov-html/index.html" #@echo indicator-session-12.10.5+14.04.20140410/cmake/GdbusCodegen.cmake0000644000015301777760000000246512321553465024336 0ustar pbusernogroup00000000000000cmake_minimum_required(VERSION 2.6) if(POLICY CMP0011) cmake_policy(SET CMP0011 NEW) endif(POLICY CMP0011) find_program(GDBUS_CODEGEN NAMES gdbus-codegen DOC "gdbus-codegen executable") if(NOT GDBUS_CODEGEN) message(FATAL_ERROR "Excutable gdbus-codegen not found") endif() macro(add_gdbus_codegen outfiles name prefix service_xml) add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.h" "${CMAKE_CURRENT_BINARY_DIR}/${name}.c" COMMAND "${GDBUS_CODEGEN}" --interface-prefix "${prefix}" --generate-c-code "${name}" "${service_xml}" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} DEPENDS ${ARGN} "${service_xml}" ) list(APPEND ${outfiles} "${CMAKE_CURRENT_BINARY_DIR}/${name}.c") endmacro(add_gdbus_codegen) macro(add_gdbus_codegen_with_namespace outfiles name prefix namespace service_xml) add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.h" "${CMAKE_CURRENT_BINARY_DIR}/${name}.c" COMMAND "${GDBUS_CODEGEN}" --interface-prefix "${prefix}" --generate-c-code "${name}" --c-namespace "${namespace}" "${service_xml}" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} DEPENDS ${ARGN} "${service_xml}" ) list(APPEND ${outfiles} "${CMAKE_CURRENT_BINARY_DIR}/${name}.c") endmacro(add_gdbus_codegen_with_namespace) indicator-session-12.10.5+14.04.20140410/cmake/Translations.cmake0000644000015301777760000000313612321553465024462 0ustar pbusernogroup00000000000000# Translations.cmake, CMake macros written for Marlin, feel free to re-use them macro(add_translations_directory NLS_PACKAGE) add_custom_target (i18n ALL) find_program (MSGFMT_EXECUTABLE msgfmt) file (GLOB PO_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.po) foreach (PO_INPUT ${PO_FILES}) get_filename_component (PO_INPUT_BASE ${PO_INPUT} NAME_WE) set (MO_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PO_INPUT_BASE}.mo) add_custom_command (TARGET i18n COMMAND ${MSGFMT_EXECUTABLE} -o ${MO_OUTPUT} ${PO_INPUT}) install (FILES ${MO_OUTPUT} DESTINATION ${CMAKE_INSTALL_LOCALEDIR}/LC_MESSAGES RENAME ${NLS_PACKAGE}.mo) endforeach (PO_INPUT ${PO_FILES}) endmacro(add_translations_directory) macro(add_translations_catalog NLS_PACKAGE) add_custom_target (pot COMMENT “Building translation catalog.”) find_program (XGETTEXT_EXECUTABLE xgettext) set(C_SOURCE "") foreach(FILES_INPUT ${ARGN}) file (GLOB_RECURSE SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/${FILES_INPUT}/*.c) foreach(C_FILE ${SOURCE_FILES}) set(C_SOURCE ${C_SOURCE} ${C_FILE}) endforeach() file (GLOB_RECURSE SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/${FILES_INPUT}/*.vala) foreach(C_FILE ${SOURCE_FILES}) set(C_SOURCE ${C_SOURCE} ${C_FILE}) endforeach() endforeach() add_custom_command (TARGET pot COMMAND ${XGETTEXT_EXECUTABLE} -d ${NLS_PACKAGE} -o ${CMAKE_CURRENT_SOURCE_DIR}/${NLS_PACKAGE}.pot ${VALA_SOURCE} ${C_SOURCE} --keyword="_" --keyword="N_" --from-code=UTF-8 ) endmacro() indicator-session-12.10.5+14.04.20140410/cmake/UseGSettings.cmake0000644000015301777760000000210212321553465024355 0ustar pbusernogroup00000000000000# GSettings.cmake, CMake macros written for Marlin, feel free to re-use them. macro(add_schema SCHEMA_NAME) set(PKG_CONFIG_EXECUTABLE pkg-config) set(GSETTINGS_DIR "${CMAKE_INSTALL_FULL_DATAROOTDIR}/glib-2.0/schemas") # Run the validator and error if it fails execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} gio-2.0 --variable glib_compile_schemas OUTPUT_VARIABLE _glib_compile_schemas OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process (COMMAND ${_glib_compile_schemas} --dry-run --schema-file=${SCHEMA_NAME} ERROR_VARIABLE _schemas_invalid OUTPUT_STRIP_TRAILING_WHITESPACE) if (_schemas_invalid) message (SEND_ERROR "Schema validation error: ${_schemas_invalid}") endif (_schemas_invalid) # Actually install and recomple schemas message (STATUS "${GSETTINGS_DIR} is the GSettings install dir") install (FILES ${SCHEMA_NAME} DESTINATION ${GSETTINGS_DIR} OPTIONAL) install (CODE "message (STATUS \"Compiling GSettings schemas\")") install (CODE "execute_process (COMMAND ${_glib_compile_schemas} ${GSETTINGS_DIR})") endmacro() indicator-session-12.10.5+14.04.20140410/tests/0000755000015301777760000000000012321553665021060 5ustar pbusernogroup00000000000000indicator-session-12.10.5+14.04.20140410/tests/org.gnome.desktop.lockdown.gschema.xml0000644000015301777760000000437312321553465030377 0ustar pbusernogroup00000000000000 false Disable command line Prevent the user from accessing the terminal or specifying a command line to be executed. For example, this would disable access to the panel's "Run Application" dialog. false Disable saving files to disk Prevent the user from saving files to disk. For example, this would disable access to all applications' "Save as" dialogs. false Disable printing Prevent the user from printing. For example, this would disable access to all applications' "Print" dialogs. false Disable print setup Prevent the user from modifying print settings. For example, this would disable access to all applications' "Print Setup" dialogs. false Disable user switching Prevent the user from switching to another account while his session is active. false Disable lock screen Prevent the user to lock his screen. false Disable URL and MIME type handlers Prevent running any URL or MIME type handler applications. false Disable log out Prevent the user from logging out. indicator-session-12.10.5+14.04.20140410/tests/backend-mock.c0000644000015301777760000000272712321553465023550 0ustar pbusernogroup00000000000000/* * 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 "backend-mock.h" #include "backend-mock-actions.h" #include "backend-mock-guest.h" #include "backend-mock-users.h" GSettings * mock_settings = NULL; IndicatorSessionActions * mock_actions = NULL; IndicatorSessionUsers * mock_users = NULL; IndicatorSessionGuest * mock_guest = NULL; void backend_get (GCancellable * cancellable G_GNUC_UNUSED, IndicatorSessionActions ** setme_actions, IndicatorSessionUsers ** setme_users, IndicatorSessionGuest ** setme_guest) { if (setme_actions != NULL) *setme_actions = g_object_ref (mock_actions); if (setme_users != NULL) *setme_users = g_object_ref (mock_users); if (setme_guest != NULL) *setme_guest = g_object_ref (mock_guest); } indicator-session-12.10.5+14.04.20140410/tests/indicator-session.service.in0000644000015301777760000000017012321553465026500 0ustar pbusernogroup00000000000000[D-BUS Service] Name=com.canonical.indicator.session-test Exec=${CMAKE_BINARY_DIR}/src/indicator-session-service --mock indicator-session-12.10.5+14.04.20140410/tests/backend-mock-actions.c0000644000015301777760000001635112321553465025204 0ustar pbusernogroup00000000000000/* * 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 #include #include "backend-mock.h" #include "backend-mock-actions.h" G_DEFINE_TYPE (IndicatorSessionActionsMock, indicator_session_actions_mock, INDICATOR_TYPE_SESSION_ACTIONS) /*** **** Virtual Functions ***/ static gboolean my_can_lock (IndicatorSessionActions * self G_GNUC_UNUSED) { return g_settings_get_boolean (mock_settings, "can-lock"); } static gboolean my_can_logout (IndicatorSessionActions * self G_GNUC_UNUSED) { return g_settings_get_boolean (mock_settings, "can-logout"); } static gboolean my_can_reboot (IndicatorSessionActions * self G_GNUC_UNUSED) { return g_settings_get_boolean (mock_settings, "can-reboot"); } static gboolean my_can_switch (IndicatorSessionActions * self G_GNUC_UNUSED) { return g_settings_get_boolean (mock_settings, "can-switch-sessions"); } static gboolean my_can_suspend (IndicatorSessionActions * self G_GNUC_UNUSED) { return g_settings_get_boolean (mock_settings, "can-suspend"); } static gboolean my_can_hibernate (IndicatorSessionActions * self G_GNUC_UNUSED) { return g_settings_get_boolean (mock_settings, "can-hibernate"); } static void my_logout (IndicatorSessionActions * self G_GNUC_UNUSED) { g_settings_set_string (mock_settings, "last-command", "logout"); } static void my_suspend (IndicatorSessionActions * self G_GNUC_UNUSED) { g_settings_set_string (mock_settings, "last-command", "suspend"); } static void my_hibernate (IndicatorSessionActions * self G_GNUC_UNUSED) { g_settings_set_string (mock_settings, "last-command", "hibernate"); } static void my_reboot (IndicatorSessionActions * self G_GNUC_UNUSED) { g_settings_set_string (mock_settings, "last-command", "reboot"); } static void my_power_off (IndicatorSessionActions * self G_GNUC_UNUSED) { g_settings_set_string (mock_settings, "last-command", "power-off"); } static void my_switch_to_screensaver (IndicatorSessionActions * self G_GNUC_UNUSED) { g_settings_set_string (mock_settings, "last-command", "switch-to-screensaver"); } static void my_switch_to_greeter (IndicatorSessionActions * self G_GNUC_UNUSED) { g_settings_set_string (mock_settings, "last-command", "switch-to-greeter"); } static void my_switch_to_guest (IndicatorSessionActions * self G_GNUC_UNUSED) { g_settings_set_string (mock_settings, "last-command", "switch-to-guest"); } static void my_switch_to_username (IndicatorSessionActions * self G_GNUC_UNUSED, const char * username) { gchar * str = g_strdup_printf ("switch-to-user::%s", username); g_settings_set_string (mock_settings, "last-command", str); } static void my_help (IndicatorSessionActions * self G_GNUC_UNUSED) { g_settings_set_string (mock_settings, "last-command", "help"); } static void my_about (IndicatorSessionActions * self G_GNUC_UNUSED) { g_settings_set_string (mock_settings, "last-command", "about"); } static void my_settings (IndicatorSessionActions * self G_GNUC_UNUSED) { g_settings_set_string (mock_settings, "last-command", "settings"); } static void my_online_accounts (IndicatorSessionActions * self G_GNUC_UNUSED) { g_settings_set_string (mock_settings, "last-command", "online-accounts"); } static gboolean my_can_prompt (IndicatorSessionActions * self G_GNUC_UNUSED) { return g_settings_get_boolean (mock_settings, "can-prompt"); } static gboolean my_has_online_account_error (IndicatorSessionActions * self G_GNUC_UNUSED) { return g_settings_get_boolean (mock_settings, "has-online-account-error"); } static void my_dispose (GObject * o) { G_OBJECT_CLASS (indicator_session_actions_mock_parent_class)->dispose (o); } static void my_finalize (GObject * o) { G_OBJECT_CLASS (indicator_session_actions_mock_parent_class)->finalize (o); } /*** **** GObject Boilerplate ***/ static void /* cppcheck-suppress unusedFunction */ indicator_session_actions_mock_class_init (IndicatorSessionActionsMockClass * klass) { GObjectClass * object_class; IndicatorSessionActionsClass * actions_class; object_class = G_OBJECT_CLASS (klass); object_class->dispose = my_dispose; object_class->finalize = my_finalize; actions_class = INDICATOR_SESSION_ACTIONS_CLASS (klass); actions_class->can_lock = my_can_lock; actions_class->can_logout = my_can_logout; actions_class->can_reboot = my_can_reboot; actions_class->can_switch = my_can_switch; actions_class->can_suspend = my_can_suspend; actions_class->can_hibernate = my_can_hibernate; actions_class->can_prompt = my_can_prompt; actions_class->has_online_account_error = my_has_online_account_error; actions_class->logout = my_logout; actions_class->suspend = my_suspend; actions_class->hibernate = my_hibernate; actions_class->reboot = my_reboot; actions_class->power_off = my_power_off; actions_class->settings = my_settings; actions_class->online_accounts = my_online_accounts; actions_class->help = my_help; actions_class->about = my_about; actions_class->switch_to_screensaver = my_switch_to_screensaver; actions_class->switch_to_greeter = my_switch_to_greeter; actions_class->switch_to_guest = my_switch_to_guest; actions_class->switch_to_username = my_switch_to_username; } static void /* cppcheck-suppress unusedFunction */ indicator_session_actions_mock_init (IndicatorSessionActionsMock * self) { g_signal_connect_swapped (mock_settings, "changed::can-lock", G_CALLBACK(indicator_session_actions_notify_can_lock), self); g_signal_connect_swapped (mock_settings, "changed::can-logout", G_CALLBACK(indicator_session_actions_notify_can_logout), self); g_signal_connect_swapped (mock_settings, "changed::can-switch-sessions", G_CALLBACK(indicator_session_actions_notify_can_switch), self); g_signal_connect_swapped (mock_settings, "changed::can-suspend", G_CALLBACK(indicator_session_actions_notify_can_suspend), self); g_signal_connect_swapped (mock_settings, "changed::can-hibernate", G_CALLBACK(indicator_session_actions_notify_can_hibernate), self); g_signal_connect_swapped (mock_settings, "changed::can-prompt", G_CALLBACK(indicator_session_actions_notify_can_prompt), self); g_signal_connect_swapped (mock_settings, "changed::has-online-account-error", G_CALLBACK(indicator_session_actions_notify_has_online_account_error), self); } /*** **** Public ***/ IndicatorSessionActions * indicator_session_actions_mock_new (void) { gpointer o = g_object_new (INDICATOR_TYPE_SESSION_ACTIONS_MOCK, NULL); return INDICATOR_SESSION_ACTIONS (o); } indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/0000755000015301777760000000000012321553665023402 5ustar pbusernogroup00000000000000indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/mock-webcredentials.cc0000644000015301777760000000242412321553465027633 0ustar pbusernogroup00000000000000/* * 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-webcredentials.h" namespace { const char * const MY_NAME = "com.canonical.indicators.webcredentials"; const char * const MY_PATH = "/com/canonical/indicators/webcredentials"; } MockWebcredentials :: MockWebcredentials (GMainLoop * loop, GDBusConnection * bus_connection): MockObject (loop, bus_connection, MY_NAME, MY_PATH), my_skeleton (webcredentials_skeleton_new ()) { set_skeleton (G_DBUS_INTERFACE_SKELETON(my_skeleton)); } MockWebcredentials :: ~MockWebcredentials () { g_clear_object (&my_skeleton); } indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/mock-accounts.h0000644000015301777760000000424012321553465026317 0ustar pbusernogroup00000000000000/* * 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 . */ #ifndef MOCK_ACCOUNTS_H #define MOCK_ACCOUNTS_H #include #include #include #include "mock-object.h" #include "backend-dbus/dbus-accounts.h" // struct Accounts class MockUser; class MockAccounts: public MockObject { public: MockAccounts (GMainLoop * loop, GDBusConnection * bus_connection); virtual ~MockAccounts (); void add_user (MockUser * user); void remove_user (MockUser * user); size_t size() const { return my_users.size(); } MockUser * find_by_uid (guint64 uid); MockUser * find_by_username (const char * username); private: Accounts * my_skeleton; typedef std::set users_t; users_t my_users; typedef std::map uid_to_user_t; uid_to_user_t my_uid_to_user; typedef std::map path_to_user_t; path_to_user_t my_path_to_user; typedef std::map username_to_user_t; username_to_user_t my_username_to_user; private: static gboolean on_find_user_by_id_static (Accounts *, GDBusMethodInvocation *, guint64, gpointer); static gboolean on_list_cached_users_static (Accounts *, GDBusMethodInvocation *, gpointer); }; #endif // #ifndef MOCK_ACCOUNTS_H indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/mock-end-session-dialog.cc0000644000015301777760000000416712321553465030332 0ustar pbusernogroup00000000000000/* * 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-end-session-dialog.h" gboolean MockEndSessionDialog :: handle_open (EndSessionDialog * object, GDBusMethodInvocation * invocation, guint arg_type G_GNUC_UNUSED, guint arg_timestamp G_GNUC_UNUSED, guint arg_seconds_to_stay_open G_GNUC_UNUSED, const gchar * const * inhibitor_paths G_GNUC_UNUSED, gpointer gself) { static_cast(gself)->my_isOpen = true; end_session_dialog_complete_open (object, invocation); return true; } /*** **** ***/ namespace { const char * const MY_NAME = "com.canonical.Unity"; const char * const MY_PATH = "/org/gnome/SessionManager/EndSessionDialog"; } MockEndSessionDialog :: MockEndSessionDialog (GMainLoop * loop, GDBusConnection * bus_connection): MockObject (loop, bus_connection, MY_NAME, MY_PATH), my_skeleton (end_session_dialog_skeleton_new ()), my_isOpen (false) { g_signal_connect (my_skeleton, "handle-open", G_CALLBACK(handle_open), this); set_skeleton (G_DBUS_INTERFACE_SKELETON(my_skeleton)); } MockEndSessionDialog :: ~MockEndSessionDialog () { g_clear_object (&my_skeleton); } indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/mock-screen-saver.h0000644000015301777760000000313312321553465027075 0ustar pbusernogroup00000000000000/* * 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 . */ #ifndef MOCK_SCREENSAVER_H #define MOCK_SCREENSAVER_H #include "mock-object.h" // parent class #include "backend-dbus/gnome-screen-saver.h" // GnomeScreenSaver class MockScreenSaver: public MockObject { public: MockScreenSaver (GMainLoop * loop, GDBusConnection * bus_connection); virtual ~MockScreenSaver (); public: enum Action { None, Lock, UserActivity }; Action last_action () { return my_last_action; } private: GnomeScreenSaver * my_skeleton; Action my_last_action; static gboolean handle_lock (GnomeScreenSaver *, GDBusMethodInvocation *, gpointer); static gboolean handle_simulate_user_activity (GnomeScreenSaver *, GDBusMethodInvocation *, gpointer); }; #endif indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/mock-user.h0000644000015301777760000000305212321553465025456 0ustar pbusernogroup00000000000000/* * 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 . */ #ifndef MOCK_USER_H #define MOCK_USER_H #include "mock-object.h" // parent class #include "backend-dbus/dbus-user.h" // AccountsUser class MockUser: public MockObject { protected: static guint get_next_uid (); public: MockUser (GMainLoop * loop, GDBusConnection * bus_connection, const char * userName, const char * realName, guint64 login_frequency, guint uid = get_next_uid()); virtual ~MockUser (); const char * username () const; const char * realname () const; void set_realname (const char *); guint uid () const; guint64 login_frequency () const; //bool system_account() const; bool is_guest() const; void set_system_account (gboolean b); private: AccountsUser * my_skeleton; }; #endif indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/mock-login1-seat.h0000644000015301777760000000432112321553465026623 0ustar pbusernogroup00000000000000/* * 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 . */ #ifndef MOCK_LOGIN1_SEAT_H #define MOCK_LOGIN1_SEAT_H #include /* strrchr */ #include #include #include #include "backend-dbus/dbus-login1-seat.h" #include "mock-object.h" class MockUser; class MockLogin1Session; class MockLogin1Seat: public MockObject { public: MockLogin1Seat (GMainLoop * loop, GDBusConnection * bus_connection, bool can_activate_sessions); virtual ~MockLogin1Seat (); const char * seat_id() const { return strrchr(path(),'/')+1; } int add_session (MockUser * user); void remove_session (int session_tag); std::set sessions () const; int active_session () const { return my_active_session; } std::string user_state (unsigned int uid) const; bool can_activate_sessions () const { return my_can_multi_session; } void activate_session (int session_tag); 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 my_sessions; int my_active_session; bool my_can_multi_session; }; #endif // #ifndef MOCK_LOGIN1_SEAT_H indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/mock-unity-session.h0000644000015301777760000000313712321553476027337 0ustar pbusernogroup00000000000000/* * Copyright 2014 Canonical Ltd. * * Authors: * Marco Trevisan * * 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 . */ #ifndef MOCK_UNITY_SESSION_H #define MOCK_UNITY_SESSION_H #include "mock-object.h" // parent class #include "backend-dbus/unity-session.h" // Unity Session class MockUnitySession: public MockObject { public: MockUnitySession (GMainLoop * loop, GDBusConnection * bus_connection); virtual ~MockUnitySession (); public: enum Action { None, Lock, PromptLock, RequestLogout, RequestShutdown, RequestReboot }; Action last_action () { return my_last_action; } private: UnitySession * my_skeleton; Action my_last_action; static gboolean handle_lock (UnitySession *, GDBusMethodInvocation *, gpointer); static gboolean handle_prompt_lock (UnitySession *, GDBusMethodInvocation *, gpointer); }; #endif indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/test-actions.cc0000644000015301777760000003201212321553476026324 0ustar pbusernogroup00000000000000/* * 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 "gtest-mock-dbus-fixture.h" #include "backend.h" #include "backend-dbus/backend-dbus.h" #define SUPPRESS_KEY "suppress-logout-restart-shutdown" /*** **** ***/ class Actions: public GTestMockDBusFixture { private: typedef GTestMockDBusFixture super; protected: GCancellable * cancellable; IndicatorSessionActions * actions; GSettings * indicator_settings; virtual void SetUp () { super :: SetUp (); // init 'actions' indicator_settings = g_settings_new ("com.canonical.indicator.session"); cancellable = g_cancellable_new (); actions = 0; backend_get (cancellable, &actions, NULL, NULL); g_assert (actions != 0); wait_msec (300); } virtual void TearDown () { g_cancellable_cancel (cancellable); g_clear_object (&indicator_settings); g_clear_object (&cancellable); g_clear_object (&actions); super :: TearDown (); } }; /*** **** ***/ TEST_F (Actions, HelloWorld) { ASSERT_TRUE (true); } namespace { static gboolean toggle_can_switch (gpointer settings) { const char * key = "disable-user-switching"; gboolean b = g_settings_get_boolean (G_SETTINGS(settings), key); g_settings_set_boolean (G_SETTINGS(settings), key, !b); return G_SOURCE_REMOVE; } } TEST_F (Actions, CanSwitch) { const char * schema_id = "org.gnome.desktop.lockdown"; const char * settings_key = "disable-user-switching"; GSettings * s = g_settings_new (schema_id); for (int i=0; i<3; ++i) { bool b; gboolean b2; 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); g_idle_add (toggle_can_switch, s); wait_for_signal (actions, "notify::" INDICATOR_SESSION_ACTIONS_PROP_CAN_SWITCH); } g_object_unref (s); } namespace { static gboolean toggle_can_lock (gpointer settings) { const char * key = "disable-lock-screen"; gboolean b = g_settings_get_boolean (G_SETTINGS(settings), key); g_settings_set_boolean (G_SETTINGS(settings), key, !b); return G_SOURCE_REMOVE; } } TEST_F (Actions, CanLock) { const char * schema_id = "org.gnome.desktop.lockdown"; const char * settings_key = "disable-lock-screen"; GSettings * s = g_settings_new (schema_id); for (int i=0; i<3; ++i) { bool b; gboolean b2; b = g_settings_get_boolean (s, settings_key); ASSERT_EQ (b, !indicator_session_actions_can_lock (actions)); g_object_get (actions, INDICATOR_SESSION_ACTIONS_PROP_CAN_LOCK, &b2, NULL); ASSERT_EQ (b, !b2); g_idle_add (toggle_can_lock, s); wait_for_signal (actions, "notify::" INDICATOR_SESSION_ACTIONS_PROP_CAN_LOCK); } g_object_unref (s); } namespace { static gboolean toggle_can_logout (gpointer settings) { const char * key = "disable-log-out"; gboolean b = g_settings_get_boolean (G_SETTINGS(settings), key); g_settings_set_boolean (G_SETTINGS(settings), key, !b); return G_SOURCE_REMOVE; } } TEST_F (Actions, CanLogout) { const char * schema_id = "org.gnome.desktop.lockdown"; const char * settings_key = "disable-log-out"; GSettings * s = g_settings_new (schema_id); for (int i=0; i<3; ++i) { bool b; gboolean b2; b = g_settings_get_boolean (s, settings_key); ASSERT_EQ (b, !indicator_session_actions_can_logout (actions)); g_object_get (actions, INDICATOR_SESSION_ACTIONS_PROP_CAN_LOGOUT, &b2, NULL); ASSERT_EQ (b, !b2); g_idle_add (toggle_can_logout, s); wait_for_signal (actions, "notify::" INDICATOR_SESSION_ACTIONS_PROP_CAN_LOGOUT); } g_object_unref (s); } TEST_F (Actions, CanSuspend) { 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) { 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, Reboot) { ASSERT_TRUE (login1_manager->last_action().empty()); ASSERT_FALSE (g_settings_get_boolean (indicator_settings, SUPPRESS_KEY)); // confirm that user is prompted // and that no action is taken when the user cancels the dialog indicator_session_actions_reboot (actions); wait_msec (50); ASSERT_TRUE (end_session_dialog->is_open()); end_session_dialog->cancel(); wait_msec (50); 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_reboot (actions); wait_msec (50); ASSERT_TRUE (end_session_dialog->is_open ()); end_session_dialog->confirm_reboot (); wait_msec (100); ASSERT_EQ (login1_manager->last_action(), "reboot"); // confirm that we try to reboot w/o prompting // if prompting is disabled login1_manager->clear_last_action (); ASSERT_EQ ("", login1_manager->last_action()); g_settings_set_boolean (indicator_settings, SUPPRESS_KEY, TRUE); wait_msec (50); ASSERT_TRUE (login1_manager->last_action().empty()); wait_msec (50); indicator_session_actions_reboot (actions); wait_msec (50); ASSERT_EQ ("reboot", login1_manager->last_action()); g_settings_reset (indicator_settings, SUPPRESS_KEY); } TEST_F (Actions, PowerOff) { 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_power_off (actions); wait_msec (50); ASSERT_TRUE (end_session_dialog->is_open()); end_session_dialog->cancel(); wait_msec (50); 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_power_off (actions); wait_msec (50); ASSERT_TRUE (end_session_dialog->is_open ()); end_session_dialog->confirm_shutdown (); wait_msec (100); ASSERT_EQ (login1_manager->last_action(), "power-off"); // confirm that we try to shutdown w/o prompting // if the EndSessionDialog isn't available // if prompting is disabled login1_manager->clear_last_action (); ASSERT_EQ ("", login1_manager->last_action()); g_settings_set_boolean (indicator_settings, SUPPRESS_KEY, TRUE); wait_msec (50); indicator_session_actions_power_off (actions); wait_msec (50); ASSERT_EQ (login1_manager->last_action(), "power-off"); g_settings_reset (indicator_settings, SUPPRESS_KEY); } TEST_F (Actions, Logout) { 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 indicator_session_actions_logout (actions); wait_msec (50); ASSERT_TRUE (end_session_dialog->is_open()); end_session_dialog->cancel(); wait_msec (50); 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 indicator_session_actions_logout (actions); wait_msec (50); ASSERT_TRUE (end_session_dialog->is_open ()); end_session_dialog->confirm_logout (); wait_msec (100); ASSERT_EQ (MockSessionManager::LogoutQuiet, session_manager->last_action ()); // confirm that we try to call SessionManager::LogoutQuet // when prompts are disabled login1_manager->clear_last_action (); ASSERT_EQ ("", login1_manager->last_action()); g_settings_set_boolean (indicator_settings, SUPPRESS_KEY, TRUE); wait_msec (50); indicator_session_actions_logout (actions); wait_msec (50); ASSERT_EQ (MockSessionManager::LogoutQuiet, session_manager->last_action ()); g_settings_reset (indicator_settings, SUPPRESS_KEY); } TEST_F (Actions, Suspend) { ASSERT_TRUE (login1_manager->last_action().empty()); indicator_session_actions_suspend (actions); wait_msec (50); ASSERT_EQ (login1_manager->last_action(), "suspend"); } TEST_F (Actions, Hibernate) { ASSERT_TRUE (login1_manager->last_action().empty()); indicator_session_actions_hibernate (actions); wait_msec (50); ASSERT_EQ (login1_manager->last_action(), "hibernate"); } TEST_F (Actions, SwitchToScreensaver) { ASSERT_EQ (MockUnitySession::None, unity_session->last_action()); indicator_session_actions_switch_to_screensaver (actions); wait_msec (50); ASSERT_EQ (MockUnitySession::Lock, unity_session->last_action()); } TEST_F (Actions, SwitchToGreeter) { ASSERT_NE (MockDisplayManagerSeat::GREETER, dm_seat->last_action()); ASSERT_EQ (MockUnitySession::None, unity_session->last_action()); indicator_session_actions_switch_to_greeter (actions); wait_msec (50); ASSERT_EQ (MockUnitySession::PromptLock, unity_session->last_action()); ASSERT_EQ (MockDisplayManagerSeat::GREETER, dm_seat->last_action()); } TEST_F (Actions, SwitchToGuest) { // allow guests dm_seat->set_guest_allowed (true); // set up a guest MockUser * guest_user = new MockUser (loop, conn, "guest-zzbEVV", "Guest", 10); guest_user->set_system_account (true); accounts->add_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 (login1_seat->skeleton(), "notify::active-session"); ASSERT_EQ (guest_session_tag, login1_seat->active_session()); wait_msec (50); ASSERT_EQ (MockUnitySession::PromptLock, unity_session->last_action()); } TEST_F (Actions, SwitchToUsername) { const char * const dr1_username = "whartnell"; const char * const dr2_username = "ptroughton"; MockUser * dr1_user; MockUser * dr2_user; int dr1_session; int dr2_session; dr1_user = accounts->find_by_username (dr1_username); dr1_session = login1_manager->add_session (login1_seat, dr1_user); dr2_user = accounts->find_by_username (dr2_username); dr2_session = login1_manager->add_session (login1_seat, dr2_user); indicator_session_actions_switch_to_username (actions, dr1_username); wait_for_signal (login1_seat->skeleton(), "notify::active-session"); ASSERT_EQ (dr1_session, login1_seat->active_session()); wait_msec (50); ASSERT_EQ (MockUnitySession::PromptLock, unity_session->last_action()); indicator_session_actions_switch_to_username (actions, dr2_username); 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 (login1_seat->skeleton(), "notify::active-session"); ASSERT_EQ (dr1_session, login1_seat->active_session()); wait_msec (50); } TEST_F (Actions, HasOnlineAccountError) { bool b; gboolean gb; b = webcredentials->has_error (); ASSERT_EQ (b, indicator_session_actions_has_online_account_error (actions)); g_object_get (actions, INDICATOR_SESSION_ACTIONS_PROP_HAS_ONLINE_ACCOUNT_ERROR, &gb, NULL); ASSERT_EQ (b, gb); b = !b; webcredentials->set_error (b); wait_msec (50); ASSERT_EQ (b, indicator_session_actions_has_online_account_error (actions)); g_object_get (actions, INDICATOR_SESSION_ACTIONS_PROP_HAS_ONLINE_ACCOUNT_ERROR, &gb, NULL); ASSERT_EQ (b, gb); b = !b; webcredentials->set_error (b); wait_msec (50); ASSERT_EQ (b, indicator_session_actions_has_online_account_error (actions)); g_object_get (actions, INDICATOR_SESSION_ACTIONS_PROP_HAS_ONLINE_ACCOUNT_ERROR, &gb, NULL); ASSERT_EQ (b, gb); } namespace { static gboolean toggle_suppress (gpointer settings) { const char * key = SUPPRESS_KEY; gboolean b = g_settings_get_boolean (G_SETTINGS(settings), key); g_settings_set_boolean (G_SETTINGS(settings), key, !b); return G_SOURCE_REMOVE; } } TEST_F (Actions, SuppressPrompts) { for (int i=0; i<3; ++i) { bool b; gboolean b2; b = indicator_session_actions_can_prompt (actions); b2 = !g_settings_get_boolean (indicator_settings, SUPPRESS_KEY); ASSERT_EQ (b, b2); g_idle_add (toggle_suppress, indicator_settings); wait_for_signal (actions, "notify::" INDICATOR_SESSION_ACTIONS_PROP_CAN_PROMPT); } g_settings_reset (indicator_settings, SUPPRESS_KEY); } indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/test-guest.cc0000644000015301777760000001352612321553465026022 0ustar pbusernogroup00000000000000/* * 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 "gtest-mock-dbus-fixture.h" #include "backend.h" #include "backend-dbus/backend-dbus.h" /*** **** ***/ class Guest: public GTestMockDBusFixture { private: typedef GTestMockDBusFixture super; protected: GCancellable * cancellable; IndicatorSessionGuest * guest; virtual void SetUp () { super :: SetUp (); // get the guest-dbus cancellable = g_cancellable_new (); guest = 0; backend_get (cancellable, NULL, NULL, &guest); wait_msec (100); // test the default state ASSERT_TRUE (guest != 0); ASSERT_FALSE (indicator_session_guest_is_allowed (guest)); ASSERT_FALSE (indicator_session_guest_is_logged_in (guest)); ASSERT_FALSE (indicator_session_guest_is_active (guest)); } virtual void TearDown () { g_cancellable_cancel (cancellable); g_clear_object (&cancellable); g_clear_object (&guest); super :: TearDown (); } protected: void add_mock_guest (MockUser *& guest_user, int & guest_session_tag) { guest_user = new MockUser (loop, conn, "guest-jjbEVV", "Guest", 10, 100); accounts->add_user (guest_user); guest_user->set_system_account (true); guest_session_tag = login1_manager->add_session (login1_seat, guest_user); } }; /** * Confirms that the Fixture's SetUp() and TearDown() work */ TEST_F (Guest, HelloWorld) { ASSERT_TRUE (true); } /** * Toggle in the DM whether or not guests are allowed. * Confirm that "guest" reflects the changes. */ TEST_F (Guest, Allowed) { dm_seat->set_guest_allowed (true); wait_for_signal (guest, "notify::guest-is-allowed"); ASSERT_TRUE (indicator_session_guest_is_allowed (guest)); ASSERT_FALSE (indicator_session_guest_is_logged_in (guest)); ASSERT_FALSE (indicator_session_guest_is_active (guest)); dm_seat->set_guest_allowed (false); wait_for_signal (guest, "notify::guest-is-allowed"); ASSERT_FALSE (indicator_session_guest_is_allowed (guest)); ASSERT_FALSE (indicator_session_guest_is_logged_in (guest)); ASSERT_FALSE (indicator_session_guest_is_active (guest)); } /** * Have a guest user log in & out. * Confirm that "guest" reflects the changes. */ TEST_F (Guest, Login) { gboolean b; dm_seat->set_guest_allowed (true); // Log a Guest in // And confirm that guest's is_login changes to true MockUser * guest_user; int session_tag; add_mock_guest (guest_user, session_tag); wait_for_signal (guest, "notify::guest-is-logged-in"); ASSERT_TRUE (indicator_session_guest_is_allowed (guest)); ASSERT_TRUE (indicator_session_guest_is_logged_in (guest)); g_object_get (guest, INDICATOR_SESSION_GUEST_PROPERTY_LOGGED_IN, &b,NULL); ASSERT_TRUE (b); ASSERT_FALSE (indicator_session_guest_is_active (guest)); // Log the Guest User out // and confirm that guest's is_login changes to false login1_manager->remove_session (login1_seat, session_tag); accounts->remove_user (guest_user); delete guest_user; wait_for_signal (guest, "notify::guest-is-logged-in"); ASSERT_TRUE (indicator_session_guest_is_allowed (guest)); ASSERT_FALSE (indicator_session_guest_is_logged_in (guest)); g_object_get (guest, INDICATOR_SESSION_GUEST_PROPERTY_LOGGED_IN, &b,NULL); ASSERT_FALSE (b); ASSERT_FALSE (indicator_session_guest_is_active (guest)); } /** * Activate a Guest session, then activate a different session. * Confirm that "guest" reflects the changes. */ TEST_F (Guest, Active) { gboolean b; const int user_session_tag = login1_seat->active_session(); dm_seat->set_guest_allowed (true); MockUser * guest_user; int guest_session_tag; add_mock_guest (guest_user, guest_session_tag); // Activate the guest session // and confirm that guest's is_active changes to true login1_seat->activate_session (guest_session_tag); wait_for_signal (guest, "notify::guest-is-active-session"); ASSERT_TRUE (indicator_session_guest_is_allowed (guest)); ASSERT_TRUE (indicator_session_guest_is_logged_in (guest)); ASSERT_TRUE (indicator_session_guest_is_active (guest)); g_object_get (guest, INDICATOR_SESSION_GUEST_PROPERTY_ACTIVE, &b,NULL); ASSERT_TRUE (b); // Activate a non-guest session // and confirm that guest's is_active changes to false login1_seat->activate_session (user_session_tag); wait_for_signal (guest, "notify::guest-is-active-session"); ASSERT_TRUE (indicator_session_guest_is_allowed (guest)); ASSERT_TRUE (indicator_session_guest_is_logged_in (guest)); ASSERT_FALSE (indicator_session_guest_is_active (guest)); g_object_get (guest, INDICATOR_SESSION_GUEST_PROPERTY_ACTIVE, &b,NULL); ASSERT_FALSE (b); } /** * Activate a guest session using the "guest" API. * Confirm that the guest session gets activated on the bus. */ TEST_F (Guest, Activate) { dm_seat->set_guest_allowed (true); wait_for_signal (guest, "notify::guest-is-allowed"); MockUser * guest_user; int guest_session_tag; add_mock_guest (guest_user, guest_session_tag); indicator_session_guest_switch_to_guest (guest); wait_for_signal (login1_seat->skeleton(), "notify::active-session"); ASSERT_EQ (guest_session_tag, login1_seat->active_session()); wait_msec (50); } indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/mock-accounts.cc0000644000015301777760000000745112321553465026464 0ustar pbusernogroup00000000000000/* * 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-accounts.h" #include "mock-user.h" namespace { const char * const DBUS_ACCOUNTS_NAME = "org.freedesktop.Accounts"; const char * const DBUS_ACCOUNTS_PATH = "/org/freedesktop/Accounts"; } /*** **** ***/ void MockAccounts :: add_user (MockUser * user) { g_assert (my_users.count(user) == 0); my_users.insert (user); my_uid_to_user[user->uid()] = user; my_path_to_user[user->path()] = user; my_username_to_user[user->username()] = user; accounts_emit_user_added (my_skeleton, user->path()); } void MockAccounts :: remove_user (MockUser * user) { g_assert (my_users.count(user) == 1); my_users.erase (user); my_uid_to_user.erase (user->uid()); my_path_to_user.erase (user->path()); my_username_to_user.erase (user->username()); accounts_emit_user_deleted (my_skeleton, user->path()); } MockUser * MockAccounts :: find_by_uid (guint64 uid) { const uid_to_user_t::iterator it (my_uid_to_user.find(uid)); if (it != my_uid_to_user.end()) return it->second; g_warn_if_reached (); return 0; } MockUser * MockAccounts :: find_by_username (const char * username) { const username_to_user_t::iterator it (my_username_to_user.find(username)); if (it != my_path_to_user.end()) return it->second; g_warn_if_reached (); return 0; } /*** **** ***/ gboolean MockAccounts :: on_find_user_by_id_static (Accounts * a, GDBusMethodInvocation * invocation, guint64 uid, gpointer gself) { MockUser * user = static_cast(gself)->find_by_uid (uid); accounts_complete_find_user_by_id (a, invocation, user ? user->path() : ""); return true; } gboolean MockAccounts :: on_list_cached_users_static (Accounts * a, GDBusMethodInvocation * invocation, gpointer gself) { int i; const char ** paths; const users_t& users = static_cast(gself)->my_users; i = 0; paths = g_new0 (const char*, users.size() + 1); for (auto it : users) paths[i++] = it->path(); accounts_complete_list_cached_users (a, invocation, paths); g_free (paths); return true; } /*** **** ***/ MockAccounts :: MockAccounts (GMainLoop * loop, GDBusConnection * bus_connection): MockObject (loop, bus_connection, DBUS_ACCOUNTS_NAME, DBUS_ACCOUNTS_PATH), my_skeleton (accounts_skeleton_new ()) { g_signal_connect (my_skeleton, "handle-list-cached-users", G_CALLBACK(on_list_cached_users_static), this); g_signal_connect (my_skeleton, "handle-find-user-by-id", G_CALLBACK(on_find_user_by_id_static), this); set_skeleton (G_DBUS_INTERFACE_SKELETON(my_skeleton)); } MockAccounts :: ~MockAccounts () { for (users_t::iterator it(my_users.begin()), end(my_users.end()); it!=end; ++it) delete *it; g_signal_handlers_disconnect_by_data (my_skeleton, this); g_clear_object (&my_skeleton); } indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/mock-webcredentials.h0000644000015301777760000000244112321553465027474 0ustar pbusernogroup00000000000000/* * 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 . */ #ifndef MOCK_WEBCREDENTIALS_H #define MOCK_WEBCREDENTIALS_H #include "mock-object.h" // parent class #include "backend-dbus/dbus-webcredentials.h" // Webcredentials class MockWebcredentials: public MockObject { public: MockWebcredentials (GMainLoop * loop, GDBusConnection * bus_connection); virtual ~MockWebcredentials (); bool has_error () const { return webcredentials_get_error_status (my_skeleton); } void set_error (bool b) const { webcredentials_set_error_status (my_skeleton, b); } private: Webcredentials * my_skeleton; }; #endif indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/mock-login1-manager.h0000644000015301777760000000511512321553465027303 0ustar pbusernogroup00000000000000/* * 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 . */ #ifndef MOCK_LOGIN1_MANAGER_H #define MOCK_LOGIN1_MANAGER_H #include #include #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 remove_session (MockLogin1Seat * seat, int session_tag); 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; void emit_session_removed (MockLogin1Seat * seat, int tag) const; GVariant * list_sessions () const; static gboolean handle_list_sessions (Login1Manager *, GDBusMethodInvocation *, gpointer); 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 my_seats; std::string my_can_suspend; std::string my_can_hibernate; std::string my_last_action; }; #endif // #ifndef MOCK_LOGIN1_MANAGER_H indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/mock-session-manager.cc0000644000015301777760000000405212321553465027732 0ustar pbusernogroup00000000000000/* * 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-session-manager.h" gboolean MockSessionManager :: handle_logout (GnomeSessionManager * gsm, GDBusMethodInvocation * inv, guint arg, gpointer gself) { Action action; switch (arg) { case 0: action = LogoutNormal; break; case 1: action = LogoutQuiet; break; case 2: action = LogoutForce; break; default: action = None; break; } static_cast(gself)->my_last_action = action; gnome_session_manager_complete_logout (gsm, inv); return true; } /*** **** ***/ namespace { const char * const SESSION_MANAGER_NAME = "org.gnome.SessionManager"; const char * const SESSION_MANAGER_PATH = "/org/gnome/SessionManager"; } MockSessionManager :: MockSessionManager (GMainLoop * loop, GDBusConnection * bus_connection): MockObject (loop, bus_connection, SESSION_MANAGER_NAME, SESSION_MANAGER_PATH), my_skeleton (gnome_session_manager_skeleton_new ()), my_last_action (None) { g_signal_connect (my_skeleton, "handle-logout", G_CALLBACK(handle_logout), this); set_skeleton (G_DBUS_INTERFACE_SKELETON(my_skeleton)); } MockSessionManager :: ~MockSessionManager () { g_clear_object (&my_skeleton); } indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/mock-object.cc0000644000015301777760000000727512321553465026117 0ustar pbusernogroup00000000000000/* * 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 #include #include "mock-object.h" namespace { const int TIMEOUT_SECONDS = 5; gboolean on_timeout_reached (gpointer loop) { g_main_loop_quit (static_cast(loop)); return G_SOURCE_REMOVE; } void on_name_acquired (GDBusConnection * connection G_GNUC_UNUSED, const char * name G_GNUC_UNUSED, gpointer loop) { //g_debug ("name '%s' acquired", name); g_main_loop_quit (static_cast(loop)); } void on_name_lost (GDBusConnection * connection G_GNUC_UNUSED, const char * name G_GNUC_UNUSED, gpointer loop) { //g_debug ("name '%s' lost", name); g_main_loop_quit (static_cast(loop)); } } void MockObject :: set_skeleton (GDBusInterfaceSkeleton * skeleton) { g_assert (skeleton != NULL); g_assert (my_skeleton == NULL); g_assert (g_variant_is_object_path (my_object_path.c_str())); g_assert (my_owner_id == 0); my_skeleton = G_DBUS_INTERFACE_SKELETON (g_object_ref (skeleton)); GError * err = NULL; g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON(my_skeleton), my_bus_connection, my_object_path.c_str(), &err); g_assert_no_error (err); my_owner_id = g_bus_own_name_on_connection (my_bus_connection, my_object_name.c_str(), G_BUS_NAME_OWNER_FLAGS_NONE, on_name_acquired, on_name_lost, my_loop, NULL); // wait for the name to be acquired or timeout, whichever comes first const guint timeout_id = g_timeout_add_seconds (TIMEOUT_SECONDS, on_timeout_reached, my_loop); g_main_loop_run (my_loop); g_assert (g_main_context_find_source_by_id (NULL, timeout_id) != NULL); g_source_remove (timeout_id); } /*** **** ***/ MockObject :: MockObject (GMainLoop * loop, GDBusConnection * bus_connection, const std::string & object_name, const std::string & object_path): my_owner_id (0), my_loop (g_main_loop_ref (loop)), my_bus_connection (G_DBUS_CONNECTION (g_object_ref (bus_connection))), my_object_name (object_name), my_object_path (object_path), my_skeleton (0) { } MockObject :: ~MockObject () { g_main_loop_unref (my_loop); if (my_owner_id != 0) { g_bus_unown_name (my_owner_id); my_owner_id = 0; } if (my_skeleton) { g_dbus_interface_skeleton_unexport (my_skeleton); g_clear_object (&my_skeleton); } g_clear_object (&my_bus_connection); } indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/test-users.cc0000644000015301777760000002733112321553465026033 0ustar pbusernogroup00000000000000/* * 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 "gtest-mock-dbus-fixture.h" #include "backend.h" #include "backend-dbus/backend-dbus.h" /*** **** ***/ class Users: public GTestMockDBusFixture { private: typedef GTestMockDBusFixture super; protected: GCancellable * cancellable; IndicatorSessionUsers * users; virtual void SetUp () { super :: SetUp (); init_event_keys (0); // init 'users' cancellable = g_cancellable_new (); users = 0; backend_get (cancellable, NULL, &users, NULL); g_assert (users != 0); // wait for the users added by GTestMockDBusFixture::SetUp() to show up wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_ADDED, 12); init_event_keys (0); } virtual void TearDown () { g_cancellable_cancel (cancellable); g_clear_object (&cancellable); g_clear_object (&users); super :: TearDown (); } protected: void compare_user (const MockUser * mu, const IndicatorSessionUser * isu, const std::string& user_state) { 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 (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 MockUser * mu, guint uid, const std::string& user_state) { IndicatorSessionUser * isu; isu = indicator_session_users_get_user (users, uid); compare_user (mu, isu, user_state); indicator_session_user_free (isu); } void compare_user (guint uid, const std::string& user_state) { IndicatorSessionUser * isu = indicator_session_users_get_user (users, uid); MockUser * mu = accounts->find_by_uid (uid); compare_user (mu, isu, user_state); indicator_session_user_free (isu); } private: void init_event_keys (size_t n) { expected_event_count = n; event_keys.clear(); } static gboolean wait_for_signals__timeout (gpointer name) { g_error ("%s: timed out waiting for signal '%s'", G_STRLOC, (char*)name); return G_SOURCE_REMOVE; } static void wait_for_signals__event (IndicatorSessionUser * u G_GNUC_UNUSED, guint uid, gpointer gself) { Users * self = static_cast(gself); self->event_keys.push_back (uid); if (self->event_keys.size() == self->expected_event_count) g_main_loop_quit (self->loop); } protected: std::vector event_keys; size_t expected_event_count; void wait_for_signals (gpointer o, const gchar * name, size_t n) { const int timeout_seconds = 5; // arbitrary init_event_keys (n); guint handler_id = g_signal_connect (o, name, G_CALLBACK(wait_for_signals__event), this); gulong timeout_id = g_timeout_add_seconds (timeout_seconds, wait_for_signals__timeout, (gpointer)name); g_main_loop_run (loop); g_source_remove (timeout_id); g_signal_handler_disconnect (o, handler_id); } }; /*** **** ***/ /** * Confirm that the fixture's SetUp() and TearDown() work */ TEST_F (Users, HelloWorld) { ASSERT_TRUE (true); } /** * Confirm that 'users' can get the cached users from our Mock Accounts */ TEST_F (Users, InitialUsers) { GList * l; GList * uids = indicator_session_users_get_uids (users); ASSERT_EQ (12, g_list_length (uids)); for (l=uids; l!=NULL; l=l->next) { const guint uid = GPOINTER_TO_UINT (l->data); compare_user (uid, login1_seat->user_state (uid)); } g_list_free (uids); } /** * Confirm that 'users' can tell when a new user is added */ TEST_F (Users, UserAdded) { MockUser * mu; mu = new MockUser (loop, conn, "pcushing", "Peter Cushing", 2); accounts->add_user (mu); ASSERT_EQ (0, event_keys.size()); wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_ADDED, 1); ASSERT_EQ (1, event_keys.size()); compare_user (mu, event_keys[0], "offline"); } /** * Confirm that 'users' can tell when a user is removed */ TEST_F (Users, UserRemoved) { MockUser * mu = accounts->find_by_username ("pdavison"); /* confirm that users knows about pdavison */ IndicatorSessionUser * isu = indicator_session_users_get_user (users, mu->uid()); ASSERT_TRUE (isu != NULL); compare_user (mu, isu, "offline"); g_clear_pointer (&isu, indicator_session_user_free); /* on the bus, remove pdavison. */ accounts->remove_user (mu); /* now, users should emit a 'user removed' signal... */ ASSERT_EQ (0, event_keys.size()); wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_REMOVED, 1); ASSERT_EQ (1, event_keys.size()); /* confirm that users won't give us pdavison's info */ isu = indicator_session_users_get_user (users, mu->uid()); ASSERT_TRUE (isu == NULL); /* confirm that users won't give us pdavison's uid */ GList * uids = indicator_session_users_get_uids (users); ASSERT_TRUE (g_list_find (uids, GUINT_TO_POINTER(mu->uid())) == NULL); g_list_free (uids); delete mu; } /** * Confirm that 'users' notices when a user's real name changes */ TEST_F (Users, RealnameChanged) { MockUser * mu; mu = accounts->find_by_username ("pdavison"); const char * const realname = "Peter M. G. Moffett"; mu->set_realname (realname); ASSERT_NE (mu->realname(), realname); ASSERT_STREQ (mu->realname(), realname); wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED, 1); ASSERT_EQ (1, event_keys.size()); compare_user (mu, event_keys[0], "offline"); } /** * Confirm that 'users' notices when users log in and out */ TEST_F (Users, LogInLogOut) { // The fist doctor logs in. // Confirm that 'users' notices. MockUser * mu = accounts->find_by_username ("whartnell"); 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_EQ (1, event_keys.size()); compare_user (mu, event_keys[0], "online"); // The first doctor logs out. // Confirm that 'users' notices. 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()); compare_user (mu, event_keys[0], "offline"); } /** * Confirm that 'users' notices when the active session changes */ TEST_F (Users, ActivateSession) { // 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_EQ (1, event_keys.size()); compare_user (whartnell, event_keys[0], "online"); // 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 (msmith, event_keys[0], "online"); compare_user (whartnell, event_keys[1], "active"); // 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 (whartnell, event_keys[0], "online"); compare_user (msmith, event_keys[1], "active"); } /** * Confirm that we can change the active session via users' API. * This is nearly the same as ActivateSession but uses users' API */ TEST_F (Users, ActivateUser) { // 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_EQ (1, event_keys.size()); compare_user (whartnell, event_keys[0], "online"); // activate whartnell's session... confirm that 'users' sees: // 1. msmith changes from 'active' to 'online' // 2. whartnell changes from 'online' to 'active' indicator_session_users_activate_user (users, whartnell->uid()); wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED, 2); ASSERT_EQ (2, event_keys.size()); compare_user (msmith, event_keys[0], "online"); compare_user (whartnell, event_keys[1], "active"); // reverse the test indicator_session_users_activate_user (users, msmith->uid()); wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED, 2); ASSERT_EQ (2, event_keys.size()); compare_user (whartnell, event_keys[0], "online"); compare_user (msmith, event_keys[1], "active"); } /** * Confirm that adding a Guest doesn't show up in the users list */ TEST_F (Users, UnwantedGuest) { GList * uids; uids = indicator_session_users_get_uids (users); const size_t n = g_list_length (uids); g_list_free (uids); MockUser * mu = new MockUser (loop, conn, "guest-jjbEVV", "Guest", 1); mu->set_system_account (true); accounts->add_user (mu); wait_msec (50); uids = indicator_session_users_get_uids (users); ASSERT_EQ (n, g_list_length (uids)); g_list_free (uids); } /** * Confirm that we can detect live sessions */ TEST_F (Users, LiveSession) { gboolean b; // not initially a live session ASSERT_FALSE (indicator_session_users_is_live_session (users)); g_object_get (users, INDICATOR_SESSION_USERS_PROP_IS_LIVE_SESSION, &b, NULL); ASSERT_FALSE (b); // now add the criteria for a live session MockUser * live_user = new MockUser (loop, conn, "ubuntu", "Ubuntu", 1, 999); live_user->set_system_account (true); accounts->add_user (live_user); const int session_tag = login1_manager->add_session (login1_seat, live_user); wait_msec (100); login1_seat->activate_session (session_tag); wait_for_signal (users, "notify::" INDICATOR_SESSION_USERS_PROP_IS_LIVE_SESSION); // confirm the backend thinks it's a live session ASSERT_TRUE (indicator_session_users_is_live_session (users)); g_object_get (users, INDICATOR_SESSION_USERS_PROP_IS_LIVE_SESSION, &b, NULL); ASSERT_TRUE (b); } indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/gtest-mock-dbus-fixture.h0000644000015301777760000001001312321553476030242 0ustar pbusernogroup00000000000000/* * 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 "gtest-dbus-fixture.h" #include "mock-accounts.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-unity-session.h" #include "mock-session-manager.h" #include "mock-user.h" #include "mock-webcredentials.h" /*** **** ***/ class GTestMockDBusFixture: public GTestDBusFixture { private: typedef GTestDBusFixture super; protected: MockScreenSaver * screen_saver; MockUnitySession * unity_session; MockSessionManager * session_manager; MockDisplayManagerSeat * dm_seat; MockAccounts * accounts; MockLogin1Manager * login1_manager; MockLogin1Seat * login1_seat; MockEndSessionDialog * end_session_dialog; MockWebcredentials * webcredentials; protected: virtual void SetUp () { super :: SetUp (); webcredentials = new MockWebcredentials (loop, conn); end_session_dialog = new MockEndSessionDialog (loop, conn); session_manager = new MockSessionManager (loop, conn); screen_saver = new MockScreenSaver (loop, conn); unity_session = new MockUnitySession (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); g_setenv ("XDG_SEAT", login1_seat->seat_id(), TRUE); login1_manager->add_seat (login1_seat); accounts = build_accounts_mock (); MockUser * user = accounts->find_by_username ("msmith"); 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 (session_tag, login1_seat->active_session()); } protected: virtual void TearDown () { delete accounts; delete login1_manager; delete dm_seat; delete screen_saver; delete unity_session; delete session_manager; delete end_session_dialog; delete webcredentials; super :: TearDown (); } private: MockAccounts * build_accounts_mock () { struct { guint64 login_frequency; const gchar * user_name; const gchar * real_name; } users[] = { { 134, "whartnell", "First Doctor" }, { 119, "ptroughton", "Second Doctor" }, { 128, "jpertwee", "Third Doctor" }, { 172, "tbaker", "Fourth Doctor" }, { 69, "pdavison", "Fifth Doctor" }, { 31, "cbaker", "Sixth Doctor" }, { 42, "smccoy", "Seventh Doctor" }, { 1, "pmcgann", "Eigth Doctor" }, { 13, "ceccleston", "Ninth Doctor" }, { 47, "dtennant", "Tenth Doctor" }, { 34, "msmith", "Eleventh Doctor" }, { 1, "rhurndall", "First Doctor" } }; MockAccounts * a = new MockAccounts (loop, conn); for (int i=0, n=G_N_ELEMENTS(users); iadd_user (new MockUser (loop, conn, users[i].user_name, users[i].real_name, users[i].login_frequency)); return a; } }; indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/mock-session-manager.h0000644000015301777760000000275512321553465027604 0ustar pbusernogroup00000000000000/* * 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 . */ #ifndef MOCK_SESSION_MANAGER_H #define MOCK_SESSION_MANAGER_H #include "mock-object.h" // parent class #include "backend-dbus/gnome-session-manager.h" // GnomeSessionManager class MockSessionManager: public MockObject { public: MockSessionManager (GMainLoop * loop, GDBusConnection * bus_connection); virtual ~MockSessionManager (); public: enum Action { None, LogoutNormal, LogoutQuiet, LogoutForce }; Action last_action () { return my_last_action; } private: GnomeSessionManager * my_skeleton; Action my_last_action; static gboolean handle_logout (GnomeSessionManager *, GDBusMethodInvocation *, guint, gpointer); }; #endif indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/CMakeLists.txt0000644000015301777760000000441612321553476026147 0ustar pbusernogroup00000000000000# build libgtest add_library (gtest STATIC ${GTEST_SOURCE_DIR}/gtest-all.cc ${GTEST_SOURCE_DIR}/gtest_main.cc) set_target_properties (gtest PROPERTIES INCLUDE_DIRECTORIES ${GTEST_INCLUDE_DIR}) SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -g ${CC_WARNING_ARGS}") # build desktopmock add_library (desktopmock STATIC mock-accounts.cc mock-accounts.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 mock-end-session-dialog.h mock-object.cc mock-object.h mock-screen-saver.cc mock-screen-saver.h mock-unity-session.cc mock-unity-session.h mock-session-manager.cc mock-session-manager.h mock-user.cc mock-user.h mock-webcredentials.cc mock-webcredentials.h) include_directories (${SERVICE_INCLUDE_DIRS}) include_directories (${CMAKE_SOURCE_DIR}/src) include_directories (${CMAKE_BINARY_DIR}/src) include_directories (${CMAKE_SOURCE_DIR}/tests) # test the Actions class add_executable (test-actions test-actions.cc) add_test (test-actions test-actions) set_tests_properties (test-actions PROPERTIES COMPILE_FLAGS "${SERVICE_CFLAGS}") target_link_libraries (test-actions desktopmock backenddbus libindicatorsessionservice gtest ${SERVICE_LDFLAGS} ${GTEST_LIBS} ${GCOV_LIBS}) # test the Guest class add_executable (test-guest test-guest.cc) add_test (test-guest test-guest) set_tests_properties (test-guest PROPERTIES COMPILE_FLAGS "${SERVICE_CFLAGS}") target_link_libraries (test-guest desktopmock backenddbus libindicatorsessionservice gtest ${SERVICE_LDFLAGS} ${GTEST_LIBS} ${GCOV_LIBS}) # test the Users class add_executable (test-users test-users.cc) add_test (test-users test-users) set_tests_properties (test-users PROPERTIES COMPILE_FLAGS "${SERVICE_CFLAGS}") target_link_libraries (test-users desktopmock backenddbus libindicatorsessionservice gtest ${SERVICE_LDFLAGS} ${GTEST_LIBS} ${GCOV_LIBS}) indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/mock-unity-session.cc0000644000015301777760000000426412321553476027477 0ustar pbusernogroup00000000000000/* * Copyright 2014 Canonical Ltd. * * Authors: * Marco Trevisan * * 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-unity-session.h" gboolean MockUnitySession :: handle_lock (UnitySession * us, GDBusMethodInvocation * inv, gpointer gself) { static_cast(gself)->my_last_action = Lock; unity_session_complete_lock (us, inv); return true; } gboolean MockUnitySession :: handle_prompt_lock (UnitySession * us, GDBusMethodInvocation * inv, gpointer gself) { static_cast(gself)->my_last_action = PromptLock; unity_session_complete_prompt_lock (us, inv); return true; } /*** **** ***/ namespace { const char * const UNITY_SESSION_NAME = "com.canonical.Unity"; const char * const UNITY_SESSION_PATH = "/com/canonical/Unity/Session"; } MockUnitySession :: MockUnitySession (GMainLoop * loop, GDBusConnection * bus_connection): MockObject (loop, bus_connection, UNITY_SESSION_NAME, UNITY_SESSION_PATH), my_skeleton (unity_session_skeleton_new ()), my_last_action (None) { g_signal_connect (my_skeleton, "handle-lock", G_CALLBACK(handle_lock), this); g_signal_connect (my_skeleton, "handle-prompt-lock", G_CALLBACK(handle_prompt_lock), this); set_skeleton (G_DBUS_INTERFACE_SKELETON(my_skeleton)); } MockUnitySession :: ~MockUnitySession () { g_clear_object (&my_skeleton); } indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/mock-screen-saver.cc0000644000015301777760000000436012321553465027236 0ustar pbusernogroup00000000000000/* * 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-screen-saver.h" gboolean MockScreenSaver :: handle_lock (GnomeScreenSaver * ss, GDBusMethodInvocation * inv, gpointer gself) { static_cast(gself)->my_last_action = Lock; gnome_screen_saver_complete_lock (ss, inv); return true; } gboolean MockScreenSaver :: handle_simulate_user_activity (GnomeScreenSaver * ss, GDBusMethodInvocation * inv, gpointer gself) { static_cast(gself)->my_last_action = UserActivity; gnome_screen_saver_complete_simulate_user_activity (ss, inv); return true; } /*** **** ***/ namespace { const char * const SCREENSAVER_NAME = "org.gnome.ScreenSaver"; const char * const SCREENSAVER_PATH = "/org/gnome/ScreenSaver"; } MockScreenSaver :: MockScreenSaver (GMainLoop * loop, GDBusConnection * bus_connection): MockObject (loop, bus_connection, SCREENSAVER_NAME, SCREENSAVER_PATH), my_skeleton (gnome_screen_saver_skeleton_new ()), my_last_action (None) { g_signal_connect (my_skeleton, "handle-lock", G_CALLBACK(handle_lock), this); g_signal_connect (my_skeleton, "handle-simulate-user-activity", G_CALLBACK(handle_simulate_user_activity), this); set_skeleton (G_DBUS_INTERFACE_SKELETON(my_skeleton)); } MockScreenSaver :: ~MockScreenSaver () { g_clear_object (&my_skeleton); } indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/mock-display-manager-seat.h0000644000015301777760000000456612321553465030522 0ustar pbusernogroup00000000000000/* * 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 . */ #ifndef MOCK_DISPLAY_MANAGER_SEAT_H #define MOCK_DISPLAY_MANAGER_SEAT_H #include "mock-object.h" // parent class #include "backend-dbus/dbus-display-manager.h" class MockLogin1Seat; class MockDisplayManagerSeat: public MockObject { public: MockDisplayManagerSeat (GMainLoop * loop, GDBusConnection * bus_connection); virtual ~MockDisplayManagerSeat (); void set_guest_allowed (bool b); void set_login1_seat (MockLogin1Seat * login1_seat); void switch_to_guest (); void switch_to_greeter (); void switch_to_user (const char * username); public: enum Action { NONE, GUEST, GREETER, USER }; Action last_action () const { return my_last_action; } private: static gboolean handle_switch_to_greeter (DisplayManagerSeat *o, GDBusMethodInvocation *inv, gpointer gself); static gboolean handle_switch_to_guest (DisplayManagerSeat *o, GDBusMethodInvocation *inv, const gchar *session_name, gpointer gself); static gboolean handle_switch_to_user (DisplayManagerSeat * o, GDBusMethodInvocation * inv, const gchar * username, const gchar * session_name, gpointer gself); DisplayManagerSeat * my_skeleton; MockLogin1Seat * my_login1_seat; Action my_last_action; }; #endif // #ifndef MOCK_DISPLAY_MANAGER_SEAT_H indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/mock-login1-seat.cc0000644000015301777760000001237712321553465026773 0ustar pbusernogroup00000000000000/* * 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-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), "c%d", tag); id = tmp; g_snprintf (tmp, sizeof(tmp), "/org/freedesktop/login1/session/%s", id.c_str()); 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_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_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 MockLogin1Seat :: sessions () const { std::set ret; for (auto it : my_sessions) ret.insert (it.first); return ret; } int MockLogin1Seat :: add_session (MockUser * user) { const int tag = next_session_tag++; my_sessions[tag] = user; update_sessions_property (); return tag; } void MockLogin1Seat :: remove_session (int session_tag) { my_sessions.erase (session_tag); update_sessions_property (); } /*** **** ***/ std::string MockLogin1Seat :: user_state (unsigned int uid) const { for (auto it : my_sessions) if (it.second->uid() == uid) return it.first == my_active_session ? "active" : "online"; return "offline"; // no matching session } void MockLogin1Seat :: activate_session (int session_tag) { g_assert (my_sessions.count(session_tag) == 1); if (my_active_session != session_tag) { std::string id, path; my_active_session = session_tag; get_session_id_and_path_for_tag (session_tag, id, path); g_setenv ("XDG_SESSION_ID", id.c_str(), true); 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_active_session (0), my_can_multi_session (can_activate_sessions) { set_skeleton (G_DBUS_INTERFACE_SKELETON(my_skeleton)); update_can_multi_session_property (); } MockLogin1Seat :: ~MockLogin1Seat () { g_clear_object (&my_skeleton); } indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/mock-object.h0000644000015301777760000000335412321553465025753 0ustar pbusernogroup00000000000000/* * 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 . */ #ifndef MOCK_OBJECT_H #define MOCK_OBJECT_H #include #include #include class MockObject { public: MockObject (GMainLoop * loop, GDBusConnection * bus_connection, const std::string & object_name, const std::string & object_path); virtual ~MockObject (); const char * name() const { return my_object_name.c_str(); } const char * path() const { return my_object_path.c_str(); } GDBusInterfaceSkeleton * skeleton() { return my_skeleton; } protected: guint my_owner_id; GMainLoop * my_loop; GDBusConnection * my_bus_connection; const std::string my_object_name; const std::string my_object_path; GDBusInterfaceSkeleton * my_skeleton; void set_skeleton (GDBusInterfaceSkeleton * skeleton); private: // safeguard to make sure we don't copy-by-value... // this object's holding a handful of pointers MockObject (const MockObject& rhs); MockObject& operator= (const MockObject& rhs); }; #endif indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/mock-display-manager-seat.cc0000644000015301777760000001010112321553465030636 0ustar pbusernogroup00000000000000/* * 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-login1-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_login1_seat != 0); my_last_action = GUEST; my_login1_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_login1_seat != 0); my_last_action = USER; my_login1_seat->switch_to_user (username); } void MockDisplayManagerSeat :: set_login1_seat (MockLogin1Seat * seat) { my_login1_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_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); } indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/mock-end-session-dialog.h0000644000015301777760000000464412321553465030174 0ustar pbusernogroup00000000000000/* * 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 . */ #ifndef MOCK_END_SESSION_DIALOG_H #define MOCK_END_SESSION_DIALOG_H #include "mock-object.h" // parent class #include "backend-dbus/dbus-end-session-dialog.h" // EndSessionDialog class MockEndSessionDialog: public MockObject { public: MockEndSessionDialog (GMainLoop * loop, GDBusConnection * bus_connection); virtual ~MockEndSessionDialog (); bool is_open () const { return my_isOpen; } void cancel () { my_isOpen = false; end_session_dialog_emit_canceled (my_skeleton); } void confirm_logout () { my_isOpen = false; end_session_dialog_emit_confirmed_logout (my_skeleton); } void confirm_reboot () { my_isOpen = false; end_session_dialog_emit_confirmed_reboot (my_skeleton); } void confirm_shutdown () { my_isOpen = false; end_session_dialog_emit_confirmed_shutdown (my_skeleton); } void close () { my_isOpen = false; end_session_dialog_emit_closed (my_skeleton); } private: EndSessionDialog * my_skeleton; bool my_isOpen; static gboolean handle_open (EndSessionDialog *, GDBusMethodInvocation *, guint, guint, guint, const gchar * const *, gpointer); #if 0 static gboolean handle_lock (GnomeScreenSaver *, GDBusMethodInvocation *, gpointer); static gboolean handle_simulate_user_activity (GnomeScreenSaver *, GDBusMethodInvocation *, gpointer); #endif }; #endif indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/mock-user.cc0000644000015301777760000000573612321553465025627 0ustar pbusernogroup00000000000000/* * 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-user.h" /*** **** ***/ const char * MockUser :: username () const { return accounts_user_get_user_name (my_skeleton); } const char * MockUser :: realname () const { return accounts_user_get_real_name (my_skeleton); } void MockUser :: set_realname (const char * realname) { accounts_user_set_real_name (my_skeleton, realname); accounts_user_emit_changed (my_skeleton); } guint MockUser :: uid () const { return accounts_user_get_uid (my_skeleton); } guint64 MockUser :: login_frequency () const { return accounts_user_get_login_frequency (my_skeleton); } void MockUser :: set_system_account (gboolean b) { accounts_user_set_system_account (my_skeleton, b); } bool MockUser :: is_guest () const { // a guest will look like this: // username:[guest-jjbEVV] realname:[Guest] system:[1] return accounts_user_get_system_account (my_skeleton) && !g_ascii_strcasecmp (accounts_user_get_real_name(my_skeleton), "Guest"); } /*** **** ***/ namespace { const char * const DBUS_ACCOUNTS_NAME = "org.freedesktop.Accounts"; static guint next_uid = 1000; std::string path_for_uid (guint uid) { char * tmp; std::string ret; const char * const DBUS_ACCOUNTS_PATH = "/org/freedesktop/Accounts"; tmp = g_strdup_printf ("%s/User%u", DBUS_ACCOUNTS_PATH, uid); ret = tmp; g_free (tmp); return ret; } } guint MockUser :: get_next_uid () { return next_uid++; } MockUser :: MockUser (GMainLoop * loop, GDBusConnection * bus_connection, const char * userName, const char * realName, guint64 login_frequency, guint uid_): MockObject (loop, bus_connection, DBUS_ACCOUNTS_NAME, path_for_uid(uid_)), my_skeleton (accounts_user_skeleton_new ()) { accounts_user_set_uid (my_skeleton, uid_); accounts_user_set_user_name (my_skeleton, userName); accounts_user_set_real_name (my_skeleton, realName); accounts_user_set_login_frequency (my_skeleton, login_frequency); accounts_user_set_system_account (my_skeleton, false); set_skeleton (G_DBUS_INTERFACE_SKELETON(my_skeleton)); } MockUser :: ~MockUser () { g_signal_handlers_disconnect_by_data (my_skeleton, this); g_clear_object (&my_skeleton); } indicator-session-12.10.5+14.04.20140410/tests/backend-dbus/mock-login1-manager.cc0000644000015301777760000001573012321553465027445 0ustar pbusernogroup00000000000000/* * 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"; } /*** **** ***/ 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); 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 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 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); } /*** **** ***/ GVariant * MockLogin1Manager :: list_sessions () const { GVariantBuilder b; g_variant_builder_init (&b, G_VARIANT_TYPE("a(susso)")); for (auto seat : my_seats) { GVariant * seat_sessions = seat->list_sessions (); GVariantIter iter; g_variant_iter_init (&iter, seat_sessions); GVariant * child; while ((child = g_variant_iter_next_value (&iter))) { g_variant_builder_add_value (&b, child); g_variant_unref (child); } } return g_variant_builder_end (&b); } /*** **** Skeleton Handlers ***/ gboolean MockLogin1Manager :: handle_list_sessions (Login1Manager * m, GDBusMethodInvocation * inv, gpointer gself) { GVariant * sessions = static_cast(gself)->list_sessions(); login1_manager_complete_list_sessions (m, inv, sessions); return true; } 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 G_GNUC_UNUSED, 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 G_GNUC_UNUSED, 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 G_GNUC_UNUSED, 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 G_GNUC_UNUSED, 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); g_signal_connect (my_skeleton, "handle-list-sessions", G_CALLBACK(handle_list_sessions), this); 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); } indicator-session-12.10.5+14.04.20140410/tests/test-service.cc0000644000015301777760000007307512321553465024016 0ustar pbusernogroup00000000000000/* Copyright 2012 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 "gtest-dbus-fixture.h" #include "service.h" #include "backend-mock.h" #include "backend-mock-users.h" #include "backend-mock-guest.h" #include "backend-mock-actions.h" /*** **** ***/ #if 0 namespace { void dump_menu_model (GMenuModel * model, int depth) { GString * indent = g_string_new_len (" ", (depth*4)); const int n = g_menu_model_get_n_items (model); g_message ("%s depth[%d] menu model[%p] has %d items", indent->str, depth, (void*)model, n); for (int i=0; istr, depth, (void*)model, i, name, str); g_free (str); g_variant_unref (attribute_value); } g_clear_object (&attribute_iter); GMenuLinkIter * link_iter = g_menu_model_iterate_item_links (model, i); while (g_menu_link_iter_get_next (link_iter, &name, &link_value)) { g_message ("%s depth[%d] menu model[%p] item[%d] attribute key[%s] model[%p]", indent->str, depth, (void*)model, i, name, (void*)link_value); dump_menu_model (link_value, depth+1); g_object_unref (link_value); } g_clear_object (&link_iter); } g_string_free (indent, TRUE); } } #endif /* cppcheck-suppress noConstructor */ class ServiceTest: public GTestDBusFixture { typedef GTestDBusFixture super; enum { TIME_LIMIT_SEC = 10 }; private: static void on_name_appeared (GDBusConnection * connection G_GNUC_UNUSED, const gchar * name G_GNUC_UNUSED, const gchar * name_owner G_GNUC_UNUSED, gpointer gself) { g_main_loop_quit (static_cast(gself)->loop); } GSList * menu_references; gboolean any_item_changed; static void on_items_changed (GMenuModel * model G_GNUC_UNUSED, gint position G_GNUC_UNUSED, gint removed G_GNUC_UNUSED, gint added G_GNUC_UNUSED, gpointer any_item_changed) { *((gboolean*)any_item_changed) = true; } protected: void activate_subtree (GMenuModel * model) { // query the GDBusMenuModel for information to activate it int n = g_menu_model_get_n_items (model); if (!n) { // give the model a moment to populate its info wait_msec (100); n = g_menu_model_get_n_items (model); } // keep a ref so that it stays activated menu_references = g_slist_prepend (menu_references, g_object_ref(model)); g_signal_connect (model, "items-changed", G_CALLBACK(on_items_changed), &any_item_changed); // recurse for (int i=0; i= TIME_LIMIT_SEC; } void wait_for_has_action (const char * name) { while (!g_action_group_has_action (G_ACTION_GROUP(action_group), name) && !times_up()) wait_msec (50); ASSERT_FALSE (times_up()); ASSERT_TRUE (g_action_group_has_action (G_ACTION_GROUP(action_group), name)); } void wait_for_menu_resync (void) { any_item_changed = false; while (!times_up() && !any_item_changed) wait_msec (50); g_warn_if_fail (any_item_changed); sync_menu (); } protected: void check_last_command_is (const char * expected) { char * str = g_settings_get_string (mock_settings, "last-command"); ASSERT_STREQ (expected, str); g_free (str); } void test_simple_action (const char * action_name) { wait_for_has_action (action_name); g_action_group_activate_action (G_ACTION_GROUP (action_group), action_name, NULL); wait_for_signal (mock_settings, "changed::last-command"); check_last_command_is (action_name); } protected: bool find_menu_item_for_action (const char * action_key, GMenuModel ** setme, int * item_index) { bool success = false; for (GSList * l=menu_references; !success && (l!=NULL); l=l->next) { GMenuModel * mm = G_MENU_MODEL (l->data); const int n = g_menu_model_get_n_items (mm); for (int i=0; !success && iis_current_user = false; u->is_logged_in = false; u->uid = account_info[i].uid; u->login_frequency = account_info[i].login_frequency; u->user_name = g_strdup (account_info[i].user_name); u->real_name = g_strdup (account_info[i].real_name); indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u); users[i] = u; } wait_for_menu_resync (); // now there should be 7 menuitems: greeter + guest + the five doctors ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-screensaver", &switch_menu, &pos)); ASSERT_EQ (0, pos); ASSERT_EQ (7, g_menu_model_get_n_items (switch_menu)); // confirm that the doctor names are sorted check_label ("Fifth Doctor", switch_menu, 2); check_label ("First Doctor", switch_menu, 3); check_label ("Fourth Doctor", switch_menu, 4); check_label ("Second Doctor", switch_menu, 5); check_label ("Third Doctor", switch_menu, 6); g_clear_object (&switch_menu); // now remove a couple of 'em indicator_session_users_mock_remove_user (INDICATOR_SESSION_USERS_MOCK(mock_users), account_info[3].uid); indicator_session_users_mock_remove_user (INDICATOR_SESSION_USERS_MOCK(mock_users), account_info[4].uid); wait_for_menu_resync (); // now there should be 5 menuitems: greeter + guest + the three doctors ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-screensaver", &switch_menu, &pos)); ASSERT_EQ (0, pos); ASSERT_EQ (5, g_menu_model_get_n_items (switch_menu)); // confirm that the doctor names are sorted check_label ("First Doctor", switch_menu, 2); check_label ("Second Doctor", switch_menu, 3); check_label ("Third Doctor", switch_menu, 4); g_clear_object (&switch_menu); // now let's have the third one be the current user users[2]->is_current_user = true; users[2]->is_logged_in = true; indicator_session_users_changed (mock_users, users[2]->uid); wait_for_menu_resync (); // now there should be 5 menuitems: greeter + guest + the three doctors ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-screensaver", &switch_menu, &pos)); ASSERT_EQ (0, pos); ASSERT_EQ (5, g_menu_model_get_n_items (switch_menu)); g_clear_object (&switch_menu); // oh hey, while we've got an active user let's check the header ASSERT_FALSE (g_settings_get_boolean (indicator_settings, show_name_key)); ASSERT_FALSE (g_settings_get_boolean (mock_settings, error_key)); check_header ("", "system-devices-panel", "System"); g_settings_set_boolean (indicator_settings, show_name_key, true); wait_for_signal (action_group, "action-state-changed"); check_header ("Third Doctor", "system-devices-panel", "System, Third Doctor"); g_settings_reset (indicator_settings, show_name_key); // try setting the max user count to 2... // since troughton has the fewest logins, he should get culled g_object_set (service, "max-users", 2, NULL); guint max_users; g_object_get (service, "max-users", &max_users, NULL); ASSERT_EQ (2, max_users); wait_for_menu_resync (); ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-screensaver", &switch_menu, &pos)); ASSERT_EQ (0, pos); ASSERT_EQ (4, g_menu_model_get_n_items (switch_menu)); check_label ("First Doctor", switch_menu, 2); check_label ("Third Doctor", switch_menu, 3); g_clear_object (&switch_menu); // add some more, test sorting and culling. // add in all the doctors, but only show 7, and make msmith the current session g_object_set (service, "max-users", 7, NULL); g_object_get (service, "max-users", &max_users, NULL); ASSERT_EQ (7, max_users); for (int i=3; i<12; ++i) { IndicatorSessionUser * u = g_new0 (IndicatorSessionUser, 1); u->is_current_user = false; u->is_logged_in = false; u->uid = 101 + i; u->login_frequency = account_info[i].login_frequency; u->user_name = g_strdup (account_info[i].user_name); u->real_name = g_strdup (account_info[i].real_name); indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u); users[i] = u; } users[2]->is_current_user = false; indicator_session_users_changed (mock_users, users[2]->uid); users[10]->is_current_user = true; users[10]->is_logged_in = true; indicator_session_users_changed (mock_users, users[10]->uid); wait_for_menu_resync (); ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-screensaver", &switch_menu, &pos)); ASSERT_EQ (0, pos); ASSERT_EQ (9, g_menu_model_get_n_items (switch_menu)); check_label ("Eleventh Doctor", switch_menu, 2); check_label ("Fifth Doctor", switch_menu, 3); check_label ("First Doctor", switch_menu, 4); check_label ("Fourth Doctor", switch_menu, 5); check_label ("Second Doctor", switch_menu, 6); check_label ("Tenth Doctor", switch_menu, 7); check_label ("Third Doctor", switch_menu, 8); g_clear_object (&switch_menu); /* Hide the user list */ g_settings_set_boolean (indicator_settings, "user-show-menu", FALSE); wait_for_menu_resync (); // now there should be 2 menuitems: greeter + guest ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-screensaver", &switch_menu, &pos)); ASSERT_EQ (0, pos); ASSERT_EQ (2, g_menu_model_get_n_items (switch_menu)); g_clear_object (&switch_menu); g_settings_set_boolean (indicator_settings, "user-show-menu", TRUE); // now switch to one of the doctors g_action_group_activate_action (G_ACTION_GROUP(action_group), "switch-to-user", g_variant_new_string("tbaker")); wait_for_signal (mock_settings, "changed::last-command"); check_last_command_is ("switch-to-user::tbaker"); } TEST_F (ServiceTest, UserLabels) { int pos = 0; GMenuModel * switch_menu = 0; // Check label uses username when real name is blank IndicatorSessionUser * u = g_new0 (IndicatorSessionUser, 1); u->uid = 100; u->user_name = g_strdup ("blank"); u->real_name = g_strdup (""); indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u); wait_for_menu_resync (); ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-screensaver", &switch_menu, &pos)); check_label ("blank", switch_menu, 2); g_clear_object (&switch_menu); indicator_session_users_mock_remove_user (INDICATOR_SESSION_USERS_MOCK(mock_users), 100); // Check label uses username when real name is all whitespace u = g_new0 (IndicatorSessionUser, 1); u->uid = 100; u->user_name = g_strdup ("whitespace"); u->real_name = g_strdup (" "); indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u); wait_for_menu_resync (); ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-screensaver", &switch_menu, &pos)); check_label ("whitespace", switch_menu, 2); g_clear_object (&switch_menu); indicator_session_users_mock_remove_user (INDICATOR_SESSION_USERS_MOCK(mock_users), 100); } indicator-session-12.10.5+14.04.20140410/tests/gtest-dbus-fixture.h0000644000015301777760000001021112321553465024767 0ustar pbusernogroup00000000000000/* * 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 #include #include /*** **** ***/ class GTestDBusFixture : public ::testing::Test { private: static void on_bus_opened (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gself) { GTestDBusFixture * self = static_cast(gself); GError * err = 0; self->conn = g_bus_get_finish (res, &err); g_assert_no_error (err); g_main_loop_quit (self->loop); } static void on_bus_closed (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gself) { GTestDBusFixture * self = static_cast(gself); GError * err = 0; g_dbus_connection_close_finish (self->conn, res, &err); g_assert_no_error (err); g_main_loop_quit (self->loop); } protected: virtual void SetUp () { conn = 0; test_dbus = 0; loop = 0; g_setenv ("GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, TRUE); g_setenv ("GSETTINGS_BACKEND", "memory", TRUE); g_debug ("SCHEMA_DIR is %s", SCHEMA_DIR); // pull up a test dbus loop = g_main_loop_new (NULL, FALSE); test_dbus = g_test_dbus_new (G_TEST_DBUS_NONE); g_test_dbus_add_service_dir (test_dbus, INDICATOR_SERVICE_DIR); g_debug ("INDICATOR_SERVICE_DIR is %s", INDICATOR_SERVICE_DIR); g_test_dbus_up (test_dbus); const char * address; address = g_test_dbus_get_bus_address (test_dbus); g_setenv ("DBUS_SYSTEM_BUS_ADDRESS", address, TRUE); g_debug ("test_dbus's address is %s", address); // wait for the GDBusConnection before returning g_bus_get (G_BUS_TYPE_SYSTEM, NULL, on_bus_opened, this); g_main_loop_run (loop); } virtual void TearDown() { // close the bus connection g_dbus_connection_close (conn, NULL, on_bus_closed, this); g_main_loop_run (loop); g_clear_object (&conn); // tear down the test dbus g_test_dbus_down (test_dbus); g_clear_object (&test_dbus); g_clear_pointer (&loop, g_main_loop_unref); } private: static gboolean wait_for_signal__timeout(gpointer name) { g_error("%s: timed out waiting for signal '%s'", G_STRLOC, (char*)name); return G_SOURCE_REMOVE; } static gboolean wait_msec__timeout(gpointer loop) { g_main_loop_quit(static_cast(loop)); return G_SOURCE_CONTINUE; } protected: /* convenience func to loop while waiting for a GObject's signal */ void wait_for_signal(gpointer o, const gchar * signal, const int timeout_seconds=5) { // wait for the signal or for timeout, whichever comes first const auto handler_id = g_signal_connect_swapped(o, signal, G_CALLBACK(g_main_loop_quit), loop); const auto timeout_id = g_timeout_add_seconds(timeout_seconds, wait_for_signal__timeout, loop); g_main_loop_run(loop); g_source_remove(timeout_id); g_signal_handler_disconnect(o, handler_id); } /* convenience func to loop for N msec */ void wait_msec(int msec=50) { const auto id = g_timeout_add(msec, wait_msec__timeout, loop); g_main_loop_run(loop); g_source_remove(id); } GMainLoop * loop; GTestDBus * test_dbus; GDBusConnection * conn; }; indicator-session-12.10.5+14.04.20140410/tests/backend-mock-users.h0000644000015301777760000000451112321553465024705 0ustar pbusernogroup00000000000000/* * 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 . */ #ifndef __USERS_MOCK_H__ #define __USERS_MOCK_H__ #include #include #include "users.h" /* parent class */ G_BEGIN_DECLS #define INDICATOR_TYPE_SESSION_USERS_MOCK (indicator_session_users_mock_get_type()) #define INDICATOR_SESSION_USERS_MOCK(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), INDICATOR_TYPE_SESSION_USERS_MOCK, IndicatorSessionUsersMock)) #define INDICATOR_SESSION_USERS_MOCK_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), INDICATOR_TYPE_SESSION_USERS_MOCK, IndicatorSessionUsersMockClass)) #define INDICATOR_IS_SESSION_USERS_MOCK(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), INDICATOR_TYPE_SESSION_USERS_MOCK)) typedef struct _IndicatorSessionUsersMock IndicatorSessionUsersMock; typedef struct _IndicatorSessionUsersMockPriv IndicatorSessionUsersMockPriv; typedef struct _IndicatorSessionUsersMockClass IndicatorSessionUsersMockClass; /** * An implementation of IndicatorSessionUsers that lies about everything. */ struct _IndicatorSessionUsersMock { /*< private >*/ IndicatorSessionUsers parent; IndicatorSessionUsersMockPriv * priv; }; struct _IndicatorSessionUsersMockClass { IndicatorSessionUsersClass parent_class; }; GType indicator_session_users_mock_get_type (void); IndicatorSessionUsers * indicator_session_users_mock_new (void); void indicator_session_users_mock_add_user (IndicatorSessionUsersMock * self, IndicatorSessionUser * user); void indicator_session_users_mock_remove_user (IndicatorSessionUsersMock * self, guint uid); G_END_DECLS #endif indicator-session-12.10.5+14.04.20140410/tests/com.canonical.indicator.session.gschema.xml0000644000015301777760000000334512321553465031354 0ustar pbusernogroup00000000000000 false Suppress the dialog to confirm logout, restart and shutdown action Whether or not to show confirmation dialogs for logout, restart and shutdown actions. false Remove the Log Out item from the session menu Makes it so that the logout button doesn’t show in the session menu. false Remove the Restart item from the session menu Makes it so that the restart button doesn’t show in the session menu. false Remove the shutdown item from the session menu Makes it so that the shutdown button doesn’t show in the session menu. false Determine the visibility of the User's real name on the panel Allow for the Removal of the users name from the panel true Show the list of users Allow for the user menu to be hidden by the user. indicator-session-12.10.5+14.04.20140410/tests/backend-mock-guest.h0000644000015301777760000000400612321553465024672 0ustar pbusernogroup00000000000000/* * 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 . */ #ifndef __GUEST_MOCK_H__ #define __GUEST_MOCK_H__ #include #include #include "guest.h" /* parent class */ G_BEGIN_DECLS #define INDICATOR_TYPE_SESSION_GUEST_MOCK (indicator_session_guest_mock_get_type()) #define INDICATOR_SESSION_GUEST_MOCK(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), INDICATOR_TYPE_SESSION_GUEST_MOCK, IndicatorSessionGuestMock)) #define INDICATOR_SESSION_GUEST_MOCK_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), INDICATOR_TYPE_SESSION_GUEST_MOCK, IndicatorSessionGuestMockClass)) #define INDICATOR_IS_SESSION_GUEST_MOCK(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), INDICATOR_TYPE_SESSION_GUEST_MOCK)) typedef struct _IndicatorSessionGuestMock IndicatorSessionGuestMock; typedef struct _IndicatorSessionGuestMockPriv IndicatorSessionGuestMockPriv; typedef struct _IndicatorSessionGuestMockClass IndicatorSessionGuestMockClass; /** * An implementation of IndicatorSessionGuest that lies about everything. */ struct _IndicatorSessionGuestMock { /*< private >*/ IndicatorSessionGuest parent; IndicatorSessionGuestMockPriv * priv; }; struct _IndicatorSessionGuestMockClass { IndicatorSessionGuestClass parent_class; }; GType indicator_session_guest_mock_get_type (void); IndicatorSessionGuest * indicator_session_guest_mock_new (void); G_END_DECLS #endif ././@LongLink0000000000000000000000000000015000000000000011211 Lustar 00000000000000indicator-session-12.10.5+14.04.20140410/tests/org.gnome.settings-daemon.plugins.media-keys.gschema.xmlindicator-session-12.10.5+14.04.20140410/tests/org.gnome.settings-daemon.plugins.media-keys.gschema.0000644000015301777760000001775312321553465033204 0ustar pbusernogroup00000000000000 true Activation of this plugin Whether this plugin would be activated by gnome-settings-daemon or not [] Custom keybindings List of custom keybindings 'XF86Calculator' Launch calculator Binding to launch the calculator. 'XF86Mail' Launch email client Binding to launch the email client. 'XF86Eject' Eject Binding to eject an optical disc. '' Launch help browser Binding to launch the help browser. 'XF86Explorer' Home folder Binding to open the Home folder. 'XF86AudioMedia' Launch media player Binding to launch the media player. 'XF86AudioNext' Next track Binding to skip to next track. 'XF86AudioPause' Pause playback Binding to pause playback. 'XF86AudioPlay' Play (or play/pause) Binding to start playback (or toggle play/pause). '<Control><Alt>Delete' Log out Binding to log out. 'XF86AudioPrev' Previous track Binding to skip to previous track. 98 Priority to use for this plugin Priority to use for this plugin in gnome-settings-daemon startup queue '<Control><Alt>l' Lock screen Binding to lock the screen. 'XF86Search' Search Binding to launch the search tool. 'XF86AudioStop' Stop playback Binding to stop playback. 'XF86AudioLowerVolume' Volume down Binding to lower the system volume. 'XF86AudioMute' Volume mute Binding to mute the system volume. 'XF86AudioRaiseVolume' Volume up Binding to raise the system volume. 'Print' Take a screenshot Binding to take a screenshot. '<Alt>Print' Take a screenshot of a window Binding to take a screenshot of a window. '<Shift>Print' Take a screenshot of an area Binding to take a screenshot of an area. '<Ctrl>Print' Copy a screenshot to clipboard Binding to copy a screenshot to clipboard. '<Ctrl><Alt>Print' Copy a screenshot of a window to clipboard Binding to copy a screenshot of a window to clipboard. '<Ctrl><Shift>Print' Copy a screenshot of an area to clipboard Binding to copy a screenshot of an area to clipboard. '<Primary><Alt>t' Launch terminal Binding to launch the terminal. 'XF86WWW' Launch web browser Binding to launch the web browser. '' Toggle magnifier Binding to show the screen magnifier '' Toggle screen reader Binding to start the screen reader '' Toggle on-screen keyboard Binding to show the on-screen keyboard '' Increase text size Binding to increase the text size '' Decrease text size Binding to decrease the text size '' Toggle contrast Binding to toggle the interface contrast '' Magnifier zoom in Binding for the magnifier to zoom in '' Magnifier zoom out Binding for the magnifier to zoom out '' Name Name of the custom binding '' Binding Binding for the custom binding '' Command Command to run when the binding is invoked indicator-session-12.10.5+14.04.20140410/tests/backend-mock.h0000644000015301777760000000210212321553465023540 0ustar pbusernogroup00000000000000/* * 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 . */ #ifndef __BACKEND_MOCK_H__ #define __BACKEND_MOCK_H__ #include /* GCancellable */ #include "actions.h" #include "guest.h" #include "users.h" G_BEGIN_DECLS extern GSettings * mock_settings; extern IndicatorSessionActions * mock_actions; extern IndicatorSessionUsers * mock_users; extern IndicatorSessionGuest * mock_guest; G_END_DECLS #endif indicator-session-12.10.5+14.04.20140410/tests/manual0000644000015301777760000000142212321553465022255 0ustar pbusernogroup00000000000000 Test-case indicator-session/unity7-items-check
Log in to a Unity 7 user session
Go to the panel and click on the Session indicator
Ensure there are items in the menu
Test-case indicator-session/unity7-greeter-items-check
Start a system and wait for the greeter or logout of the current user session
Go to the panel and click on the Session indicator
Ensure there are items in the menu
Test-case indicator-session/unity8-items-check
Login to a user session running Unity 8
Pull down the top panel until it sticks open
Navigate through the tabs until "Session" is shown
Session is at the top of the menu
The menu is populated with items
indicator-session-12.10.5+14.04.20140410/tests/CMakeLists.txt0000644000015301777760000000512212321553465023616 0ustar pbusernogroup00000000000000# build the necessary schemas set_directory_properties (PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES gschemas.compiled) set_source_files_properties (gschemas.compiled GENERATED) # GSettings: # compile the schemas our tests use (indicator-session's, lockdown, media-keys) # into a gschemas.compiled file in this directory, and help the tests to find # that file by setting -DSCHEMA_DIR set (SCHEMA_DIR ${CMAKE_CURRENT_BINARY_DIR}) add_definitions(-DSCHEMA_DIR="${SCHEMA_DIR}") execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} gio-2.0 --variable glib_compile_schemas OUTPUT_VARIABLE COMPILE_SCHEMA_EXECUTABLE OUTPUT_STRIP_TRAILING_WHITESPACE) add_custom_command (OUTPUT gschemas.compiled DEPENDS ${CMAKE_BINARY_DIR}/data/com.canonical.indicator.session.gschema.xml ${CMAKE_SOURCE_DIR}/tests/com.canonical.indicator.session.backendmock.gschema.xml ${CMAKE_SOURCE_DIR}/tests/org.gnome.desktop.lockdown.gschema.xml ${CMAKE_SOURCE_DIR}/tests/org.gnome.settings-daemon.plugins.media-keys.gschema.xml COMMAND cp -f ${CMAKE_BINARY_DIR}/data/*gschema.xml ${SCHEMA_DIR} COMMAND cp -f ${CMAKE_SOURCE_DIR}/tests/*gschema.xml ${SCHEMA_DIR} COMMAND ${COMPILE_SCHEMA_EXECUTABLE} ${SCHEMA_DIR}) # DBus Activation configure_file (indicator-session.service.in indicator-session.service) add_definitions(-DINDICATOR_SERVICE_DIR="${CMAKE_CURRENT_BINARY_DIR}") # look for hearder in our src dir, and also in the directories where we autogenerate files... include_directories (${CMAKE_SOURCE_DIR}/src) include_directories (${CMAKE_CURRENT_BINARY_DIR} ${SERVICE_INCLUDE_DIRS}) # backendmock add_library (backendmock STATIC backend-mock-actions.c backend-mock-actions.h backend-mock.c backend-mock.h backend-mock-guest.c backend-mock-guest.h backend-mock-users.c backend-mock-users.h) set_target_properties (backendmock PROPERTIES COMPILE_FLAGS " ${CC_WARNING_ARGS} -g") # test-service add_executable (test-service test-service.cc gschemas.compiled) set_target_properties (test-service PROPERTIES COMPILE_FLAGS " ${CC_WARNING_ARGS} -std=c++0x -g") add_test (test-service test-service) add_dependencies (test-service libindicatorsessionservice backendmock) target_link_libraries (test-service libindicatorsessionservice backendmock gtest ${SERVICE_LIBRARIES} ${GTEST_LIBS}) add_subdirectory (backend-dbus) indicator-session-12.10.5+14.04.20140410/tests/backend-mock-guest.c0000644000015301777760000000641212321553465024670 0ustar pbusernogroup00000000000000/* * 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 #include "backend-mock-guest.h" struct _IndicatorSessionGuestMockPriv { gboolean guest_is_active; gboolean guest_is_logged_in; gboolean guest_is_allowed; }; typedef IndicatorSessionGuestMockPriv priv_t; G_DEFINE_TYPE (IndicatorSessionGuestMock, indicator_session_guest_mock, INDICATOR_TYPE_SESSION_GUEST) /** *** IndicatorSessionGuest virtual functions **/ static gboolean my_is_allowed (IndicatorSessionGuest * self) { return INDICATOR_SESSION_GUEST_MOCK(self)->priv->guest_is_allowed; } static gboolean my_is_logged_in (IndicatorSessionGuest * self) { g_return_val_if_fail (INDICATOR_IS_SESSION_GUEST_MOCK(self), FALSE); return INDICATOR_SESSION_GUEST_MOCK(self)->priv->guest_is_logged_in; } static gboolean my_is_active (IndicatorSessionGuest * self) { return INDICATOR_SESSION_GUEST_MOCK(self)->priv->guest_is_active; } static void my_switch_to_guest (IndicatorSessionGuest * self G_GNUC_UNUSED) { g_message ("%s %s FIXME", G_STRLOC, G_STRFUNC); } /*** **** GObject virtual Functions ***/ static void my_dispose (GObject * o) { G_OBJECT_CLASS (indicator_session_guest_mock_parent_class)->dispose (o); } static void my_finalize (GObject * o) { G_OBJECT_CLASS (indicator_session_guest_mock_parent_class)->finalize (o); } /*** **** GObject Boilerplate ***/ static void /* cppcheck-suppress unusedFunction */ indicator_session_guest_mock_class_init (IndicatorSessionGuestMockClass * klass) { GObjectClass * object_class; IndicatorSessionGuestClass * guest_class; object_class = G_OBJECT_CLASS (klass); object_class->dispose = my_dispose; object_class->finalize = my_finalize; guest_class = INDICATOR_SESSION_GUEST_CLASS (klass); guest_class->is_allowed = my_is_allowed; guest_class->is_logged_in = my_is_logged_in; guest_class->is_active = my_is_active; guest_class->switch_to_guest = my_switch_to_guest; g_type_class_add_private (klass, sizeof (IndicatorSessionGuestMockPriv)); } static void /* cppcheck-suppress unusedFunction */ indicator_session_guest_mock_init (IndicatorSessionGuestMock * self) { priv_t * p; p = G_TYPE_INSTANCE_GET_PRIVATE (self, INDICATOR_TYPE_SESSION_GUEST_MOCK, IndicatorSessionGuestMockPriv); self->priv = p; p->guest_is_allowed = TRUE; p->guest_is_active = FALSE; p->guest_is_logged_in = FALSE; } /*** **** Public ***/ IndicatorSessionGuest * indicator_session_guest_mock_new (void) { gpointer o = g_object_new (INDICATOR_TYPE_SESSION_GUEST_MOCK, NULL); return INDICATOR_SESSION_GUEST (o); } indicator-session-12.10.5+14.04.20140410/tests/backend-mock-users.c0000644000015301777760000001225312321553465024702 0ustar pbusernogroup00000000000000/* * 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 "backend-mock.h" #include "backend-mock-users.h" struct _IndicatorSessionUsersMockPriv { GHashTable * users; }; typedef IndicatorSessionUsersMockPriv priv_t; G_DEFINE_TYPE (IndicatorSessionUsersMock, indicator_session_users_mock, INDICATOR_TYPE_SESSION_USERS) /*** **** IndicatorSessionUsers virtual functions ***/ static gboolean my_is_live_session (IndicatorSessionUsers * users G_GNUC_UNUSED) { return g_settings_get_boolean (mock_settings, "is-live-session"); } static void my_activate_user (IndicatorSessionUsers * users, guint uid) { g_message ("%s %s users %p uid %u FIXME", G_STRLOC, G_STRFUNC, (void*)users, uid); } static GList * my_get_uids (IndicatorSessionUsers * users) { g_return_val_if_fail (INDICATOR_IS_SESSION_USERS_MOCK(users), NULL); return g_hash_table_get_keys (INDICATOR_SESSION_USERS_MOCK(users)->priv->users); } static IndicatorSessionUser * my_get_user (IndicatorSessionUsers * self, guint uid) { priv_t * p; const IndicatorSessionUser * src; IndicatorSessionUser * ret = NULL; g_return_val_if_fail (INDICATOR_IS_SESSION_USERS_MOCK(self), NULL); p = INDICATOR_SESSION_USERS_MOCK (self)->priv; if ((src = g_hash_table_lookup (p->users, GUINT_TO_POINTER(uid)))) { ret = g_new0 (IndicatorSessionUser, 1); ret->is_current_user = src->is_current_user; ret->is_logged_in = src->is_logged_in; ret->uid = src->uid; ret->login_frequency = src->login_frequency; ret->user_name = g_strdup (src->user_name); ret->real_name = g_strdup (src->real_name); ret->icon_file = g_strdup (src->icon_file); } return ret; } /*** **** GObject virtual functions ***/ static void my_dispose (GObject * o) { G_OBJECT_CLASS (indicator_session_users_mock_parent_class)->dispose (o); } static void my_finalize (GObject * o) { priv_t * p = INDICATOR_SESSION_USERS_MOCK (o)->priv; g_hash_table_destroy (p->users); G_OBJECT_CLASS (indicator_session_users_mock_parent_class)->finalize (o); } /*** **** GObject boilerplate ***/ static void /* cppcheck-suppress unusedFunction */ indicator_session_users_mock_class_init (IndicatorSessionUsersMockClass * klass) { GObjectClass * object_class; IndicatorSessionUsersClass * users_class; object_class = G_OBJECT_CLASS (klass); object_class->dispose = my_dispose; object_class->finalize = my_finalize; users_class = INDICATOR_SESSION_USERS_CLASS (klass); users_class->is_live_session = my_is_live_session; users_class->get_uids = my_get_uids; users_class->get_user = my_get_user; users_class->activate_user = my_activate_user; g_type_class_add_private (klass, sizeof (IndicatorSessionUsersMockPriv)); } static void /* cppcheck-suppress unusedFunction */ indicator_session_users_mock_init (IndicatorSessionUsersMock * self) { priv_t * p; p = G_TYPE_INSTANCE_GET_PRIVATE (self, INDICATOR_TYPE_SESSION_USERS_MOCK, IndicatorSessionUsersMockPriv); self->priv = p; p->users = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)indicator_session_user_free); g_signal_connect_swapped (mock_settings, "changed::is-live-session", G_CALLBACK(indicator_session_users_notify_is_live_session), self); } /*** **** Public ***/ IndicatorSessionUsers * indicator_session_users_mock_new (void) { gpointer o = g_object_new (INDICATOR_TYPE_SESSION_USERS_MOCK, NULL); return INDICATOR_SESSION_USERS (o); } void indicator_session_users_mock_add_user (IndicatorSessionUsersMock * self, IndicatorSessionUser * user) { g_return_if_fail (INDICATOR_IS_SESSION_USERS_MOCK (self)); g_return_if_fail (user != NULL); g_return_if_fail (user->uid > 0); g_return_if_fail (!g_hash_table_contains (self->priv->users, GUINT_TO_POINTER(user->uid))); g_hash_table_insert (self->priv->users, GUINT_TO_POINTER(user->uid), user); indicator_session_users_added (INDICATOR_SESSION_USERS (self), user->uid); } void indicator_session_users_mock_remove_user (IndicatorSessionUsersMock * self, guint uid) { g_return_if_fail (INDICATOR_IS_SESSION_USERS_MOCK (self)); g_return_if_fail (uid > 0); g_hash_table_remove (self->priv->users, GUINT_TO_POINTER(uid)); indicator_session_users_removed (INDICATOR_SESSION_USERS (self), uid); } ././@LongLink0000000000000000000000000000014700000000000011217 Lustar 00000000000000indicator-session-12.10.5+14.04.20140410/tests/com.canonical.indicator.session.backendmock.gschema.xmlindicator-session-12.10.5+14.04.20140410/tests/com.canonical.indicator.session.backendmock.gschema.x0000644000015301777760000000307012321553465033256 0ustar pbusernogroup00000000000000 '' The last command activated false Has online account error true Is hibernation allowed? true Is suspending allowed? true Is logging out allowed? true Is rebooting allowed? true Is locking the session allowed? true Is switching sessions allowed? true Do we have a way of prompting for confirmation? false Is this a session running on a live CD? indicator-session-12.10.5+14.04.20140410/tests/backend-mock-actions.h0000644000015301777760000000421512321553465025205 0ustar pbusernogroup00000000000000/* * 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 . */ #ifndef __INDICATOR_SESSION_ACTIONS_MOCK_H__ #define __INDICATOR_SESSION_ACTIONS_MOCK_H__ #include #include #include "actions.h" /* parent class */ G_BEGIN_DECLS #define INDICATOR_TYPE_SESSION_ACTIONS_MOCK (indicator_session_actions_mock_get_type()) #define INDICATOR_SESSION_ACTIONS_MOCK(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), INDICATOR_TYPE_SESSION_ACTIONS_MOCK, IndicatorSessionActionsMock)) #define INDICATOR_SESSION_ACTIONS_MOCK_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), INDICATOR_TYPE_SESSION_ACTIONS_MOCK, IndicatorSessionActionsMockClass)) #define INDICATOR_IS_SESSION_ACTIONS_MOCK(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), INDICATOR_TYPE_SESSION_ACTIONS_MOCK)) typedef struct _IndicatorSessionActionsMock IndicatorSessionActionsMock; typedef struct _IndicatorSessionActionsMockPriv IndicatorSessionActionsMockPriv; typedef struct _IndicatorSessionActionsMockClass IndicatorSessionActionsMockClass; /** * An implementation of IndicatorSessionActions that lies about everything. */ struct _IndicatorSessionActionsMock { /*< private >*/ IndicatorSessionActions parent; IndicatorSessionActionsMockPriv * priv; }; struct _IndicatorSessionActionsMockClass { IndicatorSessionActionsClass parent_class; }; GType indicator_session_actions_mock_get_type (void); IndicatorSessionActions * indicator_session_actions_mock_new (void); G_END_DECLS #endif /* __INDICATOR_SESSION_ACTIONS_MOCK_H__ */ indicator-session-12.10.5+14.04.20140410/build.sh0000755000015301777760000000046112321553465021353 0ustar pbusernogroup00000000000000#! /bin/bash set -e mkdir -p build if [ -f "/usr/bin/ninja" ] ; then EXTRA_ARGS="-G Ninja" BUILD_COMMAND="ninja" else BUILD_COMMAND="make" fi echo "Using $BUILD_COMMAND to build" ( cd build cmake .. $EXTRA_ARGS -DCMAKE_INSTALL_PREFIX=../../install -DCMAKE_BUILD_TYPE=Debug $BUILD_COMMAND ) indicator-session-12.10.5+14.04.20140410/trim-lcov.py0000755000015301777760000000267012321553465022212 0ustar pbusernogroup00000000000000#!/usr/bin/python # This script removes branch and/or line coverage data for lines that # contain a particular substring. # # In the interest of "fairness" it removes all branch or coverage data # when a match is found -- not just negative data. It is therefore # likely that running this script will actually reduce the total number # of lines and branches that are marked as covered (in absolute terms). # # This script intentionally avoids checking for errors. Any exceptions # will trigger make to fail. # # Author: Ryan Lortie import sys line_suppress = ['g_assert_not_reached'] branch_suppress = ['g_assert', 'g_return_if_fail', 'g_clear_object', 'g_clear_pointer', 'g_return_val_if_fail', 'G_DEFINE_TYPE'] def check_suppress(suppressions, source, data): line, _, rest = data.partition(',') line = int(line) - 1 assert line < len(source) for suppression in suppressions: if suppression in source[line]: return True return False source = [] for line in sys.stdin: line = line[:-1] keyword, _, rest = line.partition(':') # Source file if keyword == 'SF': source = file(rest).readlines() # Branch coverage data elif keyword == 'BRDA': if check_suppress(branch_suppress, source, rest): continue # Line coverage data elif keyword == 'DA': if check_suppress(line_suppress, source, rest): continue print line indicator-session-12.10.5+14.04.20140410/data/0000755000015301777760000000000012321553665020627 5ustar pbusernogroup00000000000000indicator-session-12.10.5+14.04.20140410/data/icons/0000755000015301777760000000000012321553665021742 5ustar pbusernogroup00000000000000indicator-session-12.10.5+14.04.20140410/data/icons/22x22/0000755000015301777760000000000012321553665022521 5ustar pbusernogroup00000000000000indicator-session-12.10.5+14.04.20140410/data/icons/22x22/actions/0000755000015301777760000000000012321553665024161 5ustar pbusernogroup00000000000000indicator-session-12.10.5+14.04.20140410/data/icons/22x22/actions/system-restart.png0000644000015301777760000000245412321553465027700 0ustar pbusernogroup00000000000000PNG  IHDRĴl;sBIT|dtEXtSoftwarewww.inkscape.org<IDAT8KlTU9ΝGӖ>kڒB D41XИAR%7Sh 6俹;?bfx"|J>I]CuGqKVD4̸\Tdm̜7T)Wt vE怉@'z<~&G&v]XSɴk grG,+=*$5=vMJR \蚀G0t & Ek+BDHd|NFZ5cSi+(xn8RJ8O+B 03Wϖ芁bZT4\@?tM:5D2E[ͲL\eFǦN;'2hT*p5R $ fZDZiXےy'9'6pvr DFz~﹝ yPWDhR@)5  4~{O]=3qr^۲5Wt`x$%i38[Z<)`}er~; 3/j3J, `-irUV:/uj _iBTg͗T ҼsEhWӾγ f3n=k9u+}}gׁReO k>ΌzLd?^f`0{='w@41×)avҝ7vѼ0)C1h[uժD*x<Ågu Ypl|wip R )B%nx?z_mN^&]jF*`Zdk?8 `2s~ ?o[|yKZڟ*jxn-~$ ] vdf(;s-3wlv ̜S+e^,Iit_բ2;1C1B4bf4@`nAvAy39XKIENDB`indicator-session-12.10.5+14.04.20140410/data/icons/22x22/actions/system-log-out.png0000644000015301777760000000164112321553465027577 0ustar pbusernogroup00000000000000PNG  IHDRĴl;sBIT|dXIDAT8S]lU.Yhmj@ZB '66)_ FD@%HWlHm,A+Vc 3sgСi dnrw`ϘLϛ/Ci緾rltVMSO, Xzc,-51&LVrUWãC•=mCD!WPE -5_7 ")?]_&Rڐ3>10͛]i7|КBm,ᕗ_߻7ڔJ;n?V~k73ϻ ̔oS)L:? [6NomȀ5`?㹏ڎ{9%6oݟkTRK.~R=d3v_حpmAYx 斗b~|H32qҪR,CH.I=DB@3VF:WH,jQn&~7Ν1xw3>ًpR,A,_S^l8ز>33`0XaNUU9o&ۜ7%h.\%4M(0l@8 IR |Խ.]Ӵ |%!n !,-t]GZW[9O)E(2Vh)h4ѦrE4m+ *t:X,d20 IcA2D,ksގqPJ u0>1 M֦&ܦ/7U;R4L!ò,B!]9|4 `!ħ[ Ǎ@4[2ij @Ӽغm+`Aпgbᢅ_v啥o/l r eY, " avVf/>@ @U߼qp$9} Kk>^7\.(p@4BX?GZmBV+6IQ9\ t_4 C; >_; | ggk3sQ=nBXPG@4ͧit:;_}n-ya2PJ&?g/ߟ~[[/K2nYVfzzpܯ4z"TxA^μ^_S:(w! w@"Q0TKdLI5S|AJh(h $o [AzVH|D:^wȏB.BhnB׻2i,99|rⱋa~qVjRKvZ>x/t7ujlK":fRGKManվYdS?1]$@SQk{U ( 2= bTǞU42Sg70M &g@!?%{^485= @*@"lGkc=> z:NU}tBRMe⡶|@%IA䝚Q ݭӚ$"k~h?(IENDB`indicator-session-12.10.5+14.04.20140410/data/icons/16x16/actions/system-shutdown.png0000644000015301777760000000127312321553465030073 0ustar pbusernogroup00000000000000PNG  IHDRabKGDC pHYs B(xtIME / HIDAT8˭MKTq_q+d)8.|Y-fZh#  d!QL0!ji\6})u̝;anl~9±I@7v `eb<|^4v}=xfDD}mkM> O#4%baz. ( NL]Qbrp(V]{n s碈 |u\436E c:#C`y!I iqV|{Y?z I7?2i *( TP 4o{_)RIm44RE o{j]Ji5A h*9$fQeMvY %BK&NѲYk.mvWqf&[B{໚NZvt{dpնmsW,xySQs4\9O|X,]'c"+ܐQ +E2v͑rʋ89N;ȷ۾swvQ gsVrku}`)|>c+^H/H]I#7'RռZ;u "hz!})%O'6Gƺ jJZK;'5Q)e^UQ]U\\g!A ) "f-gfsgң5]m IC|X{"2  @ !yG?$D*kf>^gO`]k ħMuNL ``-#P@Rj)bwnnp!'. ~t sn۲~n-MH1/ WrpBE |A gFcQ>gMgk#7t@XUMMq8g l9\#rx@"gp/{/c Fm՛띘rӒi.@í[M9#)J\0p!y Ap dp PITxFEPO@1nmosgO 4upʌI!a@VƂH x,dCUMbG: \6Xy·yntt 駫NK1Α?;bG3g6H8֚ɓ:~QzIe*mq%$D #pF8[PH8޼4vת(ĺOY%':owJ!%Μ:ys LDJE)ܛ{yveG>hMusX́0"0FG1LL~Ս{C˖.p]9BDCYֽϝ]6);윷uǾq7,_^wU5!4v4" 2jK=֚* 5o$AWî#}?N=+1ܾxן}DfG|楷,!AN1,k3UΨO(_z~nf9@Y|X@1ƺ?pr *rBdGuk6s}M,# ¨j97 s!AT Š"(H'0[~uߺ/U@>0pXirlĞu} 7Dlohٲso}Cb֌jHNM kpKπgVjsWmI-#9ZHO}Fc׎ Ut p0"J!ݽCw崲wg8Ӷ_2O608p,m,<&!PF\o"oImv \ "` `0sr=7z `)Q4&-0Q*ÖiJ[Xk W\`+_xa_پaE.䅔(vkm?Pd#m jRʢbh8ldC)X":4=UAq`2Y}'pOb=;?yE+I#yPX(e*(2s⨬#e4"m& 1%qad_DѯӶa۸.Td3_86ܵ]F^,JSMO*GHYSX(S:STh]4 c F3LOylsY[6kYf(8e.E:YݴfeԹ"iSkcTK)A܁2aB/eHD }4p`"oqGTv>(HĒsܫnXTLYw%HXd@&khT{}G.2 #)sQ6O6s܎.s5Q8{2>IM 0a&2sMϨL]O4 PE<\+UIENDB`indicator-session-12.10.5+14.04.20140410/data/icons/32x32/actions/system-log-out.png0000644000015301777760000000257212321553465027605 0ustar pbusernogroup00000000000000PNG  IHDR szzsBIT|d1IDATXŗoSUǿ]ۍ F ia Ġ&$W0ʠ!&f5!d B"c@a1Ai{{o{n O{s\<7(-crӣ;P2poϯK`oq长)%#MMX_`R ogۥt:#3iL4[\f#qi}\_ٝ @-a\Էq6G>t{ح=^#yq()gkݔӧ݂/1q("e&XNı]3{,ceAA$D矽BYp/o ~0$0p=pvy\6 pn]څ3-!=N7ũ~iӲ ,Ixx1`$X(=MxdUw{n4X@>hY!藕,!@a-~lяcAyuL SwY0 8ևqtDb.c^>u?Mp1F>5@BJ.<-(]P^`Xh+}N;QmHA8W}J`mFIɱ׺FkL kFWj,ߨbtjܩ@A @>3DHҸSw׺$xQem.jV|Ok? ]7.u7L\ q;ۼctFH8 #T}h EF[}>11yYH> iҞ'{Ǜ,C&b:qK'`de nMM'( @LZE ) RW[c.@( &ڞ Z $*<ݯ>H<Tx@OjjشM+&``1s>&0IENDB`indicator-session-12.10.5+14.04.20140410/data/icons/32x32/status/0000755000015301777760000000000012321553665024046 5ustar pbusernogroup00000000000000indicator-session-12.10.5+14.04.20140410/data/icons/32x32/status/account-logged-in.png0000644000015301777760000000413012321553465030047 0ustar pbusernogroup00000000000000PNG  IHDR szzsBIT|d pHYs B(xtEXtSoftwarewww.inkscape.org<IDATXŗ{p\U?ܻfyvҖ4MQ(K~eݾ!@HYA c)wXOuK9g ʅ/>WL* ;Ei1|rL~EO9)%μIDʢ/~0z dZ1zh;B `DqQ =0oY%V]lBB-rBj&F{]%7 c0ڗp%Y5]*Q{)]OVkD!o_ Zp ?|+fނr x /5@)52POPǸ҂mMU}]h0z#n齬l_~յ͍ge$N)(PJqkIG8"$ #$m@"dUp%$Lp˙9 ,|8뺴uξez*2 p12*~[q^mºy7o1k{k0D(P5FQ֟vƙrr9,=^ cEPh)^px`~|?C6eddTfG^g[a i7`Ju05"q[(,>k8:xo=)qJkR|>O:&{Y^xf@Moڱ 0-}x< \r@`w>y)o#JNq_Ol[hqkJ'~_"t&:bXXlMw7uqrNt\P;iXA#KM'hn6(jW;#ՕբUaP)j85O_ǎ=L&IRk ?| eSƬihhIfo)~iu࡚=5:#)h"GA qkٟ31pva3!Ĵ՝jZxъ{}R4NVcLIU)$ڨS{'xY89)wijmfZ" 󮲗D?ԇM;@ܼutqبTƫ>i6Č 9w8\A 4y'-^pwL 'xi mh8Jep\_Ob|+u 9`e@W)&[kN Nevj4|  :DZA:vȥ{ݗ<ΥҾyq Y8*dW‚طE9 3.jGC,IFp" +f͑V]8$|d5 }b@f\9v E͒ͧՀac%߿h~]gbD@3̕oqJ;(KQD])KbA$z ӵYֲ/IENDB`indicator-session-12.10.5+14.04.20140410/data/icons/scalable/0000755000015301777760000000000012321553665023510 5ustar pbusernogroup00000000000000indicator-session-12.10.5+14.04.20140410/data/icons/scalable/actions/0000755000015301777760000000000012321553665025150 5ustar pbusernogroup00000000000000indicator-session-12.10.5+14.04.20140410/data/icons/scalable/actions/system-shutdown.svg0000644000015301777760000002356612321553465031100 0ustar pbusernogroup00000000000000 image/svg+xml Shutdown Jakub Steiner http://jimmac.musichall.cz lock key secure indicator-session-12.10.5+14.04.20140410/data/icons/scalable/actions/system-restart.svg0000644000015301777760000004231012321553465030675 0ustar pbusernogroup00000000000000 image/svg+xml Jakub Steiner http://jimmac.musichall.cz View Refresh reload refresh view Ricardo 'Rick' González indicator-session-12.10.5+14.04.20140410/data/icons/scalable/actions/system-log-out.svg0000644000015301777760000003711112321553465030602 0ustar pbusernogroup00000000000000 image/svg+xml System-log-out 2007-08-27 Lapo Calamandrei Kalle Persson logout exit man sign running indicator-session-12.10.5+14.04.20140410/data/icons/scalable/status/0000755000015301777760000000000012321553665025033 5ustar pbusernogroup00000000000000indicator-session-12.10.5+14.04.20140410/data/icons/scalable/status/account-logged-in.svg0000644000015301777760000002424312321553465031056 0ustar pbusernogroup00000000000000 image/svg+xml Emblem Urgent Jakub Steiner Andreas Nilsson generic indicator-session-12.10.5+14.04.20140410/data/icons/24x24/0000755000015301777760000000000012321553665022525 5ustar pbusernogroup00000000000000indicator-session-12.10.5+14.04.20140410/data/icons/24x24/actions/0000755000015301777760000000000012321553665024165 5ustar pbusernogroup00000000000000indicator-session-12.10.5+14.04.20140410/data/icons/24x24/actions/system-restart.png0000644000015301777760000000246312321553465027704 0ustar pbusernogroup00000000000000PNG  IHDRw=bKGD pHYsHHFk>IDATHS[lTU]{L;NKK;mM!"j Ƙ@hԘA~Dh0Dy#& *5ZBIT }Jy{)ҖIǝܛsZgOm9m'k7~X>M66n o3Q++ 43~RR~Y1 3 O ()֡wF 058ʄztMrR²,LētNo*s@HafQ੝/Rvs[^XIK0 .bͨ1FFCPo VOLVQs7]K3SJI)4!*fqRo P dwf5-uunjcE n'$^#ҊYlyuՉ᎝Vybb2tx4ε>Ƴ%rh V 04Lcӊ͑ s9'0:[Y9G{~빚 ]8tM@)Ulj95ɮœ;w)m=ntip$ͤ;gtY#}*3ClOxj&u-fYI*}xhu \0QBNf7T+/+{%bx/[oq=[ACߩ11&96G:wOċ瀹[uO4iWߟf#7G;w^W@w{K|s2 2M ߜf` {e'gڏ-Tfæ'm,*B649# @at*nzP"ZK_黲=<8OI†U0gcQԃGnBFm\Bk#SG AZ824U͵Zs;46V$ciIċTi]TStz*K7PDca>y7b͊Z}MK;"gKTT>5 ArLeH‘o wwuisSX3Xtr^Ca HɰlTBx63!K&g|O ΁;i_$]]zOq[uw} am4fSR}W;.c= Ff Or;6b\X,X}%;gΖر1AtEXtSoftwarewww.inkscape.org<IENDB`indicator-session-12.10.5+14.04.20140410/data/icons/24x24/actions/system-log-out.png0000644000015301777760000000167412321553465027611 0ustar pbusernogroup00000000000000PNG  IHDRw=bKGD pHYsHHFk>\IDATHǽS]le=.YhmjBRBMM !.}73P}!5VbK nmXcC|3lٶi33; _;=oMKqgMѕ hzrK[y6Gm4oc o1aꍏT@ʥV]^ Y W.x& W?5F8c7)?]_lUM8B%$!k|b Caׄ%1n5:W - /蜓{nKomJSCXdx~B}]Qgkvg8gu B8\))[ߧRCUuxIL`81#[>h;ii3u`pל;.DH.vZ,"Kp2[^D셅]3w5;{+ʕ?.矮duҲ2d ]q5y{5J4և~-yqtlS*4͢;C2l˄$333 6۹4-i"ƶƍǧ|՞Nx@O>d @齾sr#@Z(I_DTj' xEmtpMyv}lv3 Ts&)rz{\ր?5( ؀~C+X@o2>&Y  t 꼳;s|"NNJ3[]ZG|d2 $IeY$&D{z߷{W\ȌmiL @___LƊ7W1Yl$ATo\``/cZ,[ |B(c,bRB?ypanCu9 I,yKa&"[7KF\ȲlT4Tպkx]:4MK&R:X.bX,T*Ռ R)b1 n1BM PV:=m&#Lbhh1HL&Ǜ9hmm((Y:0xrEiMH"@&AOObzzzdH$,sΡip)0]7Uw{'-Łta,|9epa&0 CvW90 ͦ'ć[?׃`0,h0 j5>l۾ \f#mtS-\׮md\<0MiBQ!~߁哃(0;~D#3?~fɒntv̇R8N` (dǨVWI]9/jbv\ k_4@~ N ggk:s13BXP_UUr=^k6]e9!rM~X)O_?Ri¹s?M7l*v%^<á2qKqB"R*\.W}>_=z]iIENDB`indicator-session-12.10.5+14.04.20140410/data/icons/24x24/status/0000755000015301777760000000000012321553665024050 5ustar pbusernogroup00000000000000indicator-session-12.10.5+14.04.20140410/data/icons/24x24/status/account-logged-in.png0000644000015301777760000000251412321553465030055 0ustar pbusernogroup00000000000000PNG  IHDRw=bKGD pHYs B(xtIME 6ZIDATHՖ[lE}{cwKb)P-I!%"D`"Q}0>EI44C-FF `%T(KiKBv]v[,!b$LsΜ7Ɋպx,!X)1p8Xe X *Jf+}dV:n6545 M-J"Xe_y(@j]Cظ]q墾"Wnp3.g*Y(| G䮃'*{+*e뽗Os(@w4]@ '>#?0{6ݹj^'^q{w]󹯩m=.%]e4h9k!~iYwHR6@\G/kj;EKw=BOLA-e1!CLʲuG۽y?ڀ,;hBވ1A .ݥtk. MMPV0+%=ޓ3nj(t]j;%A6!R+ټ>wSsj/\G{bR]\/*33ofB"- ϛO@לضmH)6Ya93uc q %@Ipn6;s,+WtwiDaZ#Y4H[!Bڰ❻ņIk)%DWzdMCHi#ӓ@Zް&Qwiw H[uZ^WRئHl5~9 )-7a{+DbaLz(Pd9ԈmtfX|:Dyջn1MmcV,CΡ1\'A7yt֒43}yY\H@IEmt&?s2}(;nNlC"-(ΛNgGpe TMGoO(vA/~d/9R %;3 WE-C-jS}C" ȨrhI'2~zc= lvMrRT0ܜ\.ţ[翵k5$pt6z_ σBn@#1~l}1 5K@U&JGз3#LyR۝=V4o^-7EZUЛw P>A^tm'LoQJu+۪A =@,-n_61A`X.Hm