aboutsummaryrefslogtreecommitdiff
path: root/tests/backend-dbus
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2014-04-10 17:11:06 +0200
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2014-04-10 17:11:06 +0200
commite4b9f042a74b471f0b5992b99701231c3052e3ef (patch)
tree03a2be3f49bcf1abf8e93344cb29f1a13f753c20 /tests/backend-dbus
parent700dbeacd2c0377e4f1c9c48565f61e437c40534 (diff)
downloadayatana-indicator-session-e4b9f042a74b471f0b5992b99701231c3052e3ef.tar.gz
ayatana-indicator-session-e4b9f042a74b471f0b5992b99701231c3052e3ef.tar.bz2
ayatana-indicator-session-e4b9f042a74b471f0b5992b99701231c3052e3ef.zip
MockUnitySession: add new mock for unity session, and use it in tests
Diffstat (limited to 'tests/backend-dbus')
-rw-r--r--tests/backend-dbus/CMakeLists.txt2
-rw-r--r--tests/backend-dbus/gtest-mock-dbus-fixture.h4
-rw-r--r--tests/backend-dbus/mock-unity-session.cc71
-rw-r--r--tests/backend-dbus/mock-unity-session.h53
-rw-r--r--tests/backend-dbus/test-actions.cc8
5 files changed, 136 insertions, 2 deletions
diff --git a/tests/backend-dbus/CMakeLists.txt b/tests/backend-dbus/CMakeLists.txt
index e28d8e6..6ef68bd 100644
--- a/tests/backend-dbus/CMakeLists.txt
+++ b/tests/backend-dbus/CMakeLists.txt
@@ -23,6 +23,8 @@ add_library (desktopmock STATIC
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
diff --git a/tests/backend-dbus/gtest-mock-dbus-fixture.h b/tests/backend-dbus/gtest-mock-dbus-fixture.h
index bab82bf..d4f598c 100644
--- a/tests/backend-dbus/gtest-mock-dbus-fixture.h
+++ b/tests/backend-dbus/gtest-mock-dbus-fixture.h
@@ -25,6 +25,7 @@
#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"
@@ -42,6 +43,7 @@ class GTestMockDBusFixture: public GTestDBusFixture
protected:
MockScreenSaver * screen_saver;
+ MockUnitySession * unity_session;
MockSessionManager * session_manager;
MockDisplayManagerSeat * dm_seat;
MockAccounts * accounts;
@@ -60,6 +62,7 @@ class GTestMockDBusFixture: public GTestDBusFixture
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);
@@ -83,6 +86,7 @@ class GTestMockDBusFixture: public GTestDBusFixture
delete login1_manager;
delete dm_seat;
delete screen_saver;
+ delete unity_session;
delete session_manager;
delete end_session_dialog;
delete webcredentials;
diff --git a/tests/backend-dbus/mock-unity-session.cc b/tests/backend-dbus/mock-unity-session.cc
new file mode 100644
index 0000000..c996310
--- /dev/null
+++ b/tests/backend-dbus/mock-unity-session.cc
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2014 Canonical Ltd.
+ *
+ * Authors:
+ * Marco Trevisan <marco.trevisan@canonical.com>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "mock-unity-session.h"
+
+
+gboolean
+MockUnitySession :: handle_lock (UnitySession * us,
+ GDBusMethodInvocation * inv,
+ gpointer gself)
+{
+ static_cast<MockUnitySession*>(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<MockUnitySession*>(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);
+}
diff --git a/tests/backend-dbus/mock-unity-session.h b/tests/backend-dbus/mock-unity-session.h
new file mode 100644
index 0000000..ded246a
--- /dev/null
+++ b/tests/backend-dbus/mock-unity-session.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2014 Canonical Ltd.
+ *
+ * Authors:
+ * Marco Trevisan <marco.trevisan@canonical.com>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#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
diff --git a/tests/backend-dbus/test-actions.cc b/tests/backend-dbus/test-actions.cc
index c0f8517..717509d 100644
--- a/tests/backend-dbus/test-actions.cc
+++ b/tests/backend-dbus/test-actions.cc
@@ -316,17 +316,19 @@ TEST_F (Actions, Hibernate)
TEST_F (Actions, SwitchToScreensaver)
{
- ASSERT_EQ (MockScreenSaver::None, screen_saver->last_action());
+ ASSERT_EQ (MockUnitySession::None, unity_session->last_action());
indicator_session_actions_switch_to_screensaver (actions);
wait_msec (50);
- ASSERT_EQ (MockScreenSaver::Lock, screen_saver->last_action());
+ 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());
}
@@ -346,6 +348,7 @@ TEST_F (Actions, SwitchToGuest)
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)
@@ -367,6 +370,7 @@ TEST_F (Actions, SwitchToUsername)
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");