diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/notifications-mock.h | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/tests/notifications-mock.h b/tests/notifications-mock.h index ef5acd4..48da344 100644 --- a/tests/notifications-mock.h +++ b/tests/notifications-mock.h @@ -24,10 +24,18 @@ class NotificationsMock DbusTestDbusMock * mock = nullptr; public: - NotificationsMock () { + NotificationsMock (std::vector<std::string> capabilities = {"body", "body-markup", "icon-static", "image/svg+xml", "x-canonical-private-synchronous", "x-canonical-append", "x-canonical-private-icon-only", "x-canonical-truncation", "private-synchronous", "append", "private-icon-only", "truncation"}) { mock = dbus_test_dbus_mock_new("org.freedesktop.Notifications"); dbus_test_task_set_bus(DBUS_TEST_TASK(mock), DBUS_TEST_SERVICE_BUS_SESSION); - dbus_test_task_set_name(DBUS_TEST_TASK(mock), "Notifications"); + dbus_test_task_set_name(DBUS_TEST_TASK(mock), "Notify"); + + DbusTestDbusMockObject * baseobj =dbus_test_dbus_mock_get_object(mock, "/org/freedesktop/Notifications", "org.freedesktop.Notifications", NULL); + + std::string capspython("ret = "); + capspython += vector2py(capabilities); + dbus_test_dbus_mock_object_add_method(mock, baseobj, + "GetCapabilities", NULL, G_VARIANT_TYPE("as"), + capspython.c_str(), NULL); } ~NotificationsMock () { @@ -35,6 +43,22 @@ class NotificationsMock g_clear_object(&mock); } + std::string vector2py (std::vector<std::string> vect) { + std::string retval("[ "); + + std::for_each(vect.begin(), vect.end() - 1, [&retval](std::string entry) { + retval += "'"; + retval += entry; + retval += "', "; + }); + + retval += "'"; + retval += *(vect.end() - 1); + retval += "']"; + + return retval; + } + operator std::shared_ptr<DbusTestTask> () { std::shared_ptr<DbusTestTask> retval(DBUS_TEST_TASK(g_object_ref(mock)), [](DbusTestTask * task) { g_clear_object(&task); }); return retval; |