2
* Copyright (C) 2013 Canonical, Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3, as published
6
* by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License along
14
* with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Author: Pete Woods <pete.woods@canonical.com>
19
#include <testutils/MockHudService.h>
20
#include <common/AppstackModel.h>
21
#include <common/DBusTypes.h>
22
#include <common/ResultsModel.h>
24
using namespace hud::common;
25
using namespace hud::testutils;
26
using namespace QtDBusTest;
27
using namespace QtDBusMock;
29
MockHudService::MockHudService(DBusTestRunner &dbus, DBusMock &mock) :
30
m_dbus(dbus), m_mock(mock) {
31
mock.registerCustomMock(DBusTypes::HUD_SERVICE_DBUS_NAME,
32
DBusTypes::HUD_SERVICE_DBUS_PATH, DBusTypes::HUD_SERVICE_DBUS_NAME,
33
QDBusConnection::SessionBus);
36
const QString MockHudService::QUERY_PATH("/com/canonical/hud/query0");
38
static void addMethod(QList<Method> &methods, const QString &name,
39
const QString &inSig, const QString &outSig, const QString &code) {
42
method.setInSig(inSig);
43
method.setOutSig(outSig);
48
OrgFreedesktopDBusMockInterface & MockHudService::hudInterface() {
49
return m_mock.mockInterface(DBusTypes::HUD_SERVICE_DBUS_NAME,
50
DBusTypes::HUD_SERVICE_DBUS_PATH, DBusTypes::HUD_SERVICE_DBUS_NAME,
51
QDBusConnection::SessionBus);
54
OrgFreedesktopDBusMockInterface & MockHudService::applicationInterface() {
55
return m_mock.mockInterface(DBusTypes::HUD_SERVICE_DBUS_NAME, "/app/object",
56
"com.canonical.hud.Application", QDBusConnection::SessionBus);
59
OrgFreedesktopDBusMockInterface & MockHudService::queryInterface() {
60
return m_mock.mockInterface(DBusTypes::HUD_SERVICE_DBUS_NAME, QUERY_PATH,
61
"com.canonical.hud.query", QDBusConnection::SessionBus);
64
void MockHudService::loadMethods() {
65
OrgFreedesktopDBusMockInterface &hud(hudInterface());
68
QVariantMap properties;
69
properties["ResultsModel"] = "com.canonical.hud.query0.results";
70
properties["AppstackModel"] = "com.canonical.hud.query0.appstack";
71
properties["ToolbarItems"] = QStringList();
73
QList<Method> methods;
74
addMethod(methods, "UpdateQuery", "s", "i", "ret = 1");
75
addMethod(methods, "VoiceQuery", "", "is", "ret = (1, 'voice query')");
76
addMethod(methods, "UpdateApp", "s", "i", "ret = 1");
77
addMethod(methods, "CloseQuery", "", "", "");
78
addMethod(methods, "ExecuteCommand", "vu", "", "");
79
addMethod(methods, "ExecuteParameterized", "vu", "sooi",
80
"ret = ('action', '/action/path', '/model/path', 1)");
81
addMethod(methods, "ExecuteToolbar", "su", "", "");
83
hud.AddObject(QUERY_PATH, "com.canonical.hud.query", properties,
84
methods).waitForFinished();
87
m_results.reset(new ResultsModel(0));
88
m_results->beginChangeset();
89
m_results->addResult(0, "result1", QList<QPair<int, int>>(), "description1",
90
QList<QPair<int, int>>(), "shortcut", 1, false);
91
m_results->endChangeset();
93
m_appstack.reset(new AppstackModel(0));
94
m_appstack->beginChangeset();
95
m_appstack->addApplication("application-id", "icon",
96
AppstackModel::ITEM_TYPE_FOCUSED_APP);
97
m_appstack->endChangeset();
101
QVariantMap properties;
102
QList<Method> methods;
103
addMethod(methods, "AddSources", "a(usso)a(uso)", "", "");
104
hud.AddObject("/app/object", "com.canonical.hud.Application",
105
properties, methods).waitForFinished();
109
hud.AddMethod(DBusTypes::HUD_SERVICE_DBUS_NAME, "CreateQuery", "s", "ossi",
110
"ret = ('/com/canonical/hud/query0', 'com.canonical.hud.query0.results', 'com.canonical.hud.query0.appstack', dbus.Int32(0))").waitForFinished();
113
hud.AddMethod(DBusTypes::HUD_SERVICE_DBUS_NAME, "RegisterApplication", "s",
114
"o", "ret = ('/app/object')").waitForFinished();
117
MockHudService::~MockHudService() {