From ae39f7001e5603010afc02de29787ade6d48ef14 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 22 Mar 2013 16:34:34 -0500 Subject: port indicator-session to GMenu/cmake. Code coverage increased from 0% to 95.4%. --- tests/backend-dbus/mock-user.cc | 131 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 tests/backend-dbus/mock-user.cc (limited to 'tests/backend-dbus/mock-user.cc') diff --git a/tests/backend-dbus/mock-user.cc b/tests/backend-dbus/mock-user.cc new file mode 100644 index 0000000..abf2e21 --- /dev/null +++ b/tests/backend-dbus/mock-user.cc @@ -0,0 +1,131 @@ +/* + * 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); +} + +#if 0 +bool +MockUser :: system_account() const +{ + return accounts_user_get_system_account (my_skeleton); +} +#endif + +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); +} -- cgit v1.2.3 From 660d7bcbbddf3ea10146b47d3bf5c64899b8b2e0 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 25 Jun 2013 13:53:25 -0500 Subject: copyediting: remove g_messages() added while fixing the tests, remove dead code --- tests/backend-dbus/mock-user.cc | 8 -------- 1 file changed, 8 deletions(-) (limited to 'tests/backend-dbus/mock-user.cc') diff --git a/tests/backend-dbus/mock-user.cc b/tests/backend-dbus/mock-user.cc index abf2e21..f74b5a4 100644 --- a/tests/backend-dbus/mock-user.cc +++ b/tests/backend-dbus/mock-user.cc @@ -54,14 +54,6 @@ MockUser :: login_frequency () const return accounts_user_get_login_frequency (my_skeleton); } -#if 0 -bool -MockUser :: system_account() const -{ - return accounts_user_get_system_account (my_skeleton); -} -#endif - void MockUser :: set_system_account (gboolean b) { -- cgit v1.2.3