aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2015-03-06 16:19:41 -0600
committerTed Gould <ted@gould.cx>2015-03-06 16:19:41 -0600
commit4bef5575c83bd34e467c4aa043e9bec221354feb (patch)
tree0d3521be603a8db032411c1c089ece31f1e0c1c1 /tests
parentbb83669a1a1cdf3cc4949a13a6b6977b336cd178 (diff)
downloadayatana-indicator-messages-4bef5575c83bd34e467c4aa043e9bec221354feb.tar.gz
ayatana-indicator-messages-4bef5575c83bd34e467c4aa043e9bec221354feb.tar.bz2
ayatana-indicator-messages-4bef5575c83bd34e467c4aa043e9bec221354feb.zip
Bringing in AS mock and getting a base test of the root action going
Diffstat (limited to 'tests')
-rw-r--r--tests/accounts-service-mock.h122
-rw-r--r--tests/indicator-fixture.h4
-rw-r--r--tests/indicator-test.cpp16
3 files changed, 138 insertions, 4 deletions
diff --git a/tests/accounts-service-mock.h b/tests/accounts-service-mock.h
new file mode 100644
index 0000000..1d0c1fe
--- /dev/null
+++ b/tests/accounts-service-mock.h
@@ -0,0 +1,122 @@
+/*
+ * 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 <memory>
+#include <libdbustest/dbus-test.h>
+
+class AccountsServiceMock
+{
+ DbusTestDbusMock * mock = nullptr;
+ DbusTestDbusMockObject * soundobj = nullptr;
+ DbusTestDbusMockObject * userobj = nullptr;
+ DbusTestDbusMockObject * syssoundobj = nullptr;
+
+ public:
+ AccountsServiceMock () {
+ mock = dbus_test_dbus_mock_new("org.freedesktop.Accounts");
+
+ dbus_test_task_set_bus(DBUS_TEST_TASK(mock), DBUS_TEST_SERVICE_BUS_SYSTEM);
+
+ 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);
+
+ 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);
+
+ 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);
+
+ syssoundobj = dbus_test_dbus_mock_get_object(mock, "/user", "com.ubuntu.touch.AccountsService.Sound", NULL);
+ dbus_test_dbus_mock_object_add_property(mock, syssoundobj,
+ "SilentMode", G_VARIANT_TYPE_BOOLEAN,
+ g_variant_new_boolean(FALSE), NULL);
+ }
+
+ ~AccountsServiceMock () {
+ g_debug("Destroying the Accounts Service Mock");
+ g_clear_object(&mock);
+ }
+
+ void setSilentMode (bool modeValue) {
+ dbus_test_dbus_mock_object_update_property(mock, syssoundobj,
+ "SilentMode", g_variant_new_boolean(modeValue ? TRUE : FALSE),
+ NULL);
+ }
+
+ operator std::shared_ptr<DbusTestTask> () {
+ return std::shared_ptr<DbusTestTask>(
+ DBUS_TEST_TASK(g_object_ref(mock)),
+ [](DbusTestTask * task) { g_clear_object(&task); });
+ }
+
+ operator DbusTestTask* () {
+ return DBUS_TEST_TASK(mock);
+ }
+
+ operator DbusTestDbusMock* () {
+ return mock;
+ }
+
+ DbusTestDbusMockObject * get_sound () {
+ return soundobj;
+ }
+};
diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h
index e725a50..aa191ae 100644
--- a/tests/indicator-fixture.h
+++ b/tests/indicator-fixture.h
@@ -272,9 +272,9 @@ class IndicatorFixture : public ::testing::Test
return result;
}
- template <typename... Args> testing::AssertionResult expectEventuallyActionStateExists (Args&& ... args) {
+ template <typename... Args> testing::AssertionResult expectEventuallyActionExists (Args&& ... args) {
std::function<testing::AssertionResult(void)> func = [&]() {
- return expectActionStateExists(std::forward<Args>(args)...);
+ return expectActionExists(std::forward<Args>(args)...);
};
return expectEventually(func);
}
diff --git a/tests/indicator-test.cpp b/tests/indicator-test.cpp
index 1aef466..3a5ef6d 100644
--- a/tests/indicator-test.cpp
+++ b/tests/indicator-test.cpp
@@ -21,6 +21,7 @@
#include <gio/gio.h>
#include "indicator-fixture.h"
+#include "accounts-service-mock.h"
class IndicatorTest : public IndicatorFixture
{
@@ -30,24 +31,35 @@ protected:
{
}
+ std::shared_ptr<AccountsServiceMock> as;
+
virtual void SetUp() override
{
g_setenv("GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, TRUE);
g_setenv("GSETTINGS_BACKEND", "memory", TRUE);
+ as = std::make_shared<AccountsServiceMock>();
+ addMock(*as);
+
IndicatorFixture::SetUp();
}
virtual void TearDown() override
{
+ as.reset();
+
IndicatorFixture::TearDown();
}
};
-TEST_F(IndicatorTest, PhoneMenu) {
- setMenu("/com/canonical/indicator/messages/phone");
+TEST_F(IndicatorTest, RootAction) {
+ setActions("/com/canonical/indicator/messages");
+
+ EXPECT_EVENTUALLY_ACTION_EXISTS("messages");
+ EXPECT_ACTION_STATE_TYPE("messages", G_VARIANT_TYPE("a{sv}"));
+ EXPECT_ACTION_STATE("messages", g_variant_new_parsed("{'icon': <('themed', <['indicator-messages-offline', 'indicator-messages', 'indicator']>)>, 'title': <'Notifications'>, 'accessible-desc': <'Messages'>, 'visible': <false>}"));
}