aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2014-03-03 14:50:52 -0600
committerTed Gould <ted@gould.cx>2014-03-03 14:50:52 -0600
commit88dbefac5c013ed65619ed37b991f35535ef85ee (patch)
treeffe7ef18fc956117628a1df0ea5f12f63751f17d
parent69231381cb7656b551d860c441b8d9750f9f5bc2 (diff)
downloadayatana-indicator-sound-88dbefac5c013ed65619ed37b991f35535ef85ee.tar.gz
ayatana-indicator-sound-88dbefac5c013ed65619ed37b991f35535ef85ee.tar.bz2
ayatana-indicator-sound-88dbefac5c013ed65619ed37b991f35535ef85ee.zip
Put the accounts service mock into a class
-rw-r--r--tests/accounts-service-mock.h90
-rw-r--r--tests/accounts-service-user.cc60
2 files changed, 95 insertions, 55 deletions
diff --git a/tests/accounts-service-mock.h b/tests/accounts-service-mock.h
new file mode 100644
index 0000000..225d7b5
--- /dev/null
+++ b/tests/accounts-service-mock.h
@@ -0,0 +1,90 @@
+/*
+ * Copyright © 2014 Canonical Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY 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/>.
+ *
+ * Authors:
+ * Ted Gould <ted@canonical.com>
+ */
+
+#include <libdbustest/dbus-test.h>
+
+class AccountsServiceMock
+{
+ DbusTestDbusMock * mock = nullptr;
+
+ public:
+ AccountsServiceMock () {
+ mock = dbus_test_dbus_mock_new("org.freedesktop.Accounts");
+
+ DbusTestDbusMockObject * baseobj = dbus_test_dbus_mock_get_object(mock, "/org/freedesktop/Accounts", "org.freedesktop.Accounts", NULL);
+
+ dbus_test_dbus_mock_object_add_method(mock, baseobj,
+ "CacheUser", G_VARIANT_TYPE_STRING, G_VARIANT_TYPE_OBJECT_PATH,
+ "ret = dbus.ObjectPath('/user')\n", NULL);
+ dbus_test_dbus_mock_object_add_method(mock, baseobj,
+ "FindUserById", G_VARIANT_TYPE_INT64, G_VARIANT_TYPE_OBJECT_PATH,
+ "ret = dbus.ObjectPath('/user')\n", NULL);
+ dbus_test_dbus_mock_object_add_method(mock, baseobj,
+ "FindUserByName", G_VARIANT_TYPE_STRING, G_VARIANT_TYPE_OBJECT_PATH,
+ "ret = dbus.ObjectPath('/user')\n", NULL);
+ dbus_test_dbus_mock_object_add_method(mock, baseobj,
+ "ListCachedUsers", NULL, G_VARIANT_TYPE_OBJECT_PATH_ARRAY,
+ "ret = [ dbus.ObjectPath('/user') ]\n", NULL);
+ dbus_test_dbus_mock_object_add_method(mock, baseobj,
+ "UncacheUser", G_VARIANT_TYPE_STRING, NULL,
+ "", NULL);
+
+ DbusTestDbusMockObject * userobj = dbus_test_dbus_mock_get_object(mock, "/user", "org.freedesktop.Accounts.User", NULL);
+ dbus_test_dbus_mock_object_add_property(mock, userobj,
+ "UserName", G_VARIANT_TYPE_STRING,
+ g_variant_new_string(g_get_user_name()), NULL);
+
+ DbusTestDbusMockObject * soundobj = dbus_test_dbus_mock_get_object(mock, "/user", "com.canonical.indicator.sound.AccountsService", NULL);
+ dbus_test_dbus_mock_object_add_property(mock, soundobj,
+ "Timestamp", G_VARIANT_TYPE_UINT64,
+ g_variant_new_uint64(0), NULL);
+ dbus_test_dbus_mock_object_add_property(mock, soundobj,
+ "PlayerName", G_VARIANT_TYPE_STRING,
+ g_variant_new_string(""), NULL);
+ dbus_test_dbus_mock_object_add_property(mock, soundobj,
+ "PlayerIcon", G_VARIANT_TYPE_VARIANT,
+ g_variant_new_variant(g_variant_new_string("")), NULL);
+ dbus_test_dbus_mock_object_add_property(mock, soundobj,
+ "Running", G_VARIANT_TYPE_BOOLEAN,
+ g_variant_new_boolean(FALSE), NULL);
+ dbus_test_dbus_mock_object_add_property(mock, soundobj,
+ "State", G_VARIANT_TYPE_STRING,
+ g_variant_new_string(""), NULL);
+ dbus_test_dbus_mock_object_add_property(mock, soundobj,
+ "Title", G_VARIANT_TYPE_STRING,
+ g_variant_new_string(""), NULL);
+ dbus_test_dbus_mock_object_add_property(mock, soundobj,
+ "Artist", G_VARIANT_TYPE_STRING,
+ g_variant_new_string(""), NULL);
+ dbus_test_dbus_mock_object_add_property(mock, soundobj,
+ "Album", G_VARIANT_TYPE_STRING,
+ g_variant_new_string(""), NULL);
+ dbus_test_dbus_mock_object_add_property(mock, soundobj,
+ "ArtUrl", G_VARIANT_TYPE_STRING,
+ g_variant_new_string(""), NULL);
+ }
+
+ ~AccountsServiceMock () {
+ g_clear_object(&mock);
+ }
+
+ operator DbusTestTask* () {
+ return DBUS_TEST_TASK(mock);
+ }
+};
diff --git a/tests/accounts-service-user.cc b/tests/accounts-service-user.cc
index 522bec9..b39b546 100644
--- a/tests/accounts-service-user.cc
+++ b/tests/accounts-service-user.cc
@@ -22,6 +22,8 @@
#include <libdbustest/dbus-test.h>
#include <act/act.h>
+#include "accounts-service-mock.h"
+
extern "C" {
#include "indicator-sound-service.h"
#include "vala-mocks.h"
@@ -41,61 +43,9 @@ class AccountsServiceUserTest : public ::testing::Test
virtual void SetUp() {
service = dbus_test_service_new(NULL);
- mock = dbus_test_dbus_mock_new("org.freedesktop.Accounts");
-
- DbusTestDbusMockObject * baseobj = dbus_test_dbus_mock_get_object(mock, "/org/freedesktop/Accounts", "org.freedesktop.Accounts", NULL);
-
- dbus_test_dbus_mock_object_add_method(mock, baseobj,
- "CacheUser", G_VARIANT_TYPE_STRING, G_VARIANT_TYPE_OBJECT_PATH,
- "ret = dbus.ObjectPath('/user')\n", NULL);
- dbus_test_dbus_mock_object_add_method(mock, baseobj,
- "FindUserById", G_VARIANT_TYPE_INT64, G_VARIANT_TYPE_OBJECT_PATH,
- "ret = dbus.ObjectPath('/user')\n", NULL);
- dbus_test_dbus_mock_object_add_method(mock, baseobj,
- "FindUserByName", G_VARIANT_TYPE_STRING, G_VARIANT_TYPE_OBJECT_PATH,
- "ret = dbus.ObjectPath('/user')\n", NULL);
- dbus_test_dbus_mock_object_add_method(mock, baseobj,
- "ListCachedUsers", NULL, G_VARIANT_TYPE_OBJECT_PATH_ARRAY,
- "ret = [ dbus.ObjectPath('/user') ]\n", NULL);
- dbus_test_dbus_mock_object_add_method(mock, baseobj,
- "UncacheUser", G_VARIANT_TYPE_STRING, NULL,
- "", NULL);
-
- DbusTestDbusMockObject * userobj = dbus_test_dbus_mock_get_object(mock, "/user", "org.freedesktop.Accounts.User", NULL);
- dbus_test_dbus_mock_object_add_property(mock, userobj,
- "UserName", G_VARIANT_TYPE_STRING,
- g_variant_new_string(g_get_user_name()), NULL);
-
- DbusTestDbusMockObject * soundobj = dbus_test_dbus_mock_get_object(mock, "/user", "com.canonical.indicator.sound.AccountsService", NULL);
- dbus_test_dbus_mock_object_add_property(mock, soundobj,
- "Timestamp", G_VARIANT_TYPE_UINT64,
- g_variant_new_uint64(0), NULL);
- dbus_test_dbus_mock_object_add_property(mock, soundobj,
- "PlayerName", G_VARIANT_TYPE_STRING,
- g_variant_new_string(""), NULL);
- dbus_test_dbus_mock_object_add_property(mock, soundobj,
- "PlayerIcon", G_VARIANT_TYPE_VARIANT,
- g_variant_new_variant(g_variant_new_string("")), NULL);
- dbus_test_dbus_mock_object_add_property(mock, soundobj,
- "Running", G_VARIANT_TYPE_BOOLEAN,
- g_variant_new_boolean(FALSE), NULL);
- dbus_test_dbus_mock_object_add_property(mock, soundobj,
- "State", G_VARIANT_TYPE_STRING,
- g_variant_new_string(""), NULL);
- dbus_test_dbus_mock_object_add_property(mock, soundobj,
- "Title", G_VARIANT_TYPE_STRING,
- g_variant_new_string(""), NULL);
- dbus_test_dbus_mock_object_add_property(mock, soundobj,
- "Artist", G_VARIANT_TYPE_STRING,
- g_variant_new_string(""), NULL);
- dbus_test_dbus_mock_object_add_property(mock, soundobj,
- "Album", G_VARIANT_TYPE_STRING,
- g_variant_new_string(""), NULL);
- dbus_test_dbus_mock_object_add_property(mock, soundobj,
- "ArtUrl", G_VARIANT_TYPE_STRING,
- g_variant_new_string(""), NULL);
-
- dbus_test_service_add_task(service, DBUS_TEST_TASK(mock));
+ AccountsServiceMock service_mock;
+
+ dbus_test_service_add_task(service, (DbusTestTask*)service_mock);
dbus_test_service_start_tasks(service);
g_setenv("DBUS_SYSTEM_BUS_ADDRESS", g_getenv("DBUS_SESSION_BUS_ADDRESS"), TRUE);