~ubuntu-branches/ubuntu/trusty/hud/trusty-updates

« back to all changes in this revision

Viewing changes to tests/testutils/MockHudService.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-01-20 19:43:59 UTC
  • mfrom: (1.1.26)
  • Revision ID: package-import@ubuntu.com-20140120194359-jxxxqtd4ql9elvpf
Tags: 13.10.1+14.04.20140120-0ubuntu1
* New rebuild forced
* Automatic snapshot from revision 362

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Canonical, Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 * Author: Pete Woods <pete.woods@canonical.com>
 
17
 */
 
18
 
 
19
#include <testutils/MockHudService.h>
 
20
#include <common/AppstackModel.h>
 
21
#include <common/DBusTypes.h>
 
22
#include <common/ResultsModel.h>
 
23
 
 
24
using namespace hud::common;
 
25
using namespace hud::testutils;
 
26
using namespace QtDBusTest;
 
27
using namespace QtDBusMock;
 
28
 
 
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);
 
34
}
 
35
 
 
36
const QString MockHudService::QUERY_PATH("/com/canonical/hud/query0");
 
37
 
 
38
static void addMethod(QList<Method> &methods, const QString &name,
 
39
                const QString &inSig, const QString &outSig, const QString &code) {
 
40
        Method method;
 
41
        method.setName(name);
 
42
        method.setInSig(inSig);
 
43
        method.setOutSig(outSig);
 
44
        method.setCode(code);
 
45
        methods << method;
 
46
}
 
47
 
 
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);
 
52
}
 
53
 
 
54
OrgFreedesktopDBusMockInterface & MockHudService::applicationInterface() {
 
55
        return m_mock.mockInterface(DBusTypes::HUD_SERVICE_DBUS_NAME, "/app/object",
 
56
                        "com.canonical.hud.Application", QDBusConnection::SessionBus);
 
57
}
 
58
 
 
59
OrgFreedesktopDBusMockInterface & MockHudService::queryInterface() {
 
60
        return m_mock.mockInterface(DBusTypes::HUD_SERVICE_DBUS_NAME, QUERY_PATH,
 
61
                        "com.canonical.hud.query", QDBusConnection::SessionBus);
 
62
}
 
63
 
 
64
void MockHudService::loadMethods() {
 
65
        OrgFreedesktopDBusMockInterface &hud(hudInterface());
 
66
 
 
67
        {
 
68
                QVariantMap properties;
 
69
                properties["ResultsModel"] = "com.canonical.hud.query0.results";
 
70
                properties["AppstackModel"] = "com.canonical.hud.query0.appstack";
 
71
                properties["ToolbarItems"] = QStringList();
 
72
 
 
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", "", "");
 
82
 
 
83
                hud.AddObject(QUERY_PATH, "com.canonical.hud.query", properties,
 
84
                                methods).waitForFinished();
 
85
        }
 
86
 
 
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();
 
92
 
 
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();
 
98
 
 
99
        // Mock application
 
100
        {
 
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();
 
106
        }
 
107
 
 
108
        /* query */
 
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();
 
111
 
 
112
        /* id */
 
113
        hud.AddMethod(DBusTypes::HUD_SERVICE_DBUS_NAME, "RegisterApplication", "s",
 
114
                        "o", "ret = ('/app/object')").waitForFinished();
 
115
}
 
116
 
 
117
MockHudService::~MockHudService() {
 
118
}
 
119