on xenial help sign in
adding DownloadDaemonListener mock
commit9ec527657c946f6c67b34c8626c1fdc4f6e43a15 authorDiego Sarmentero <diego.sarmentero@gmail.com> dateMon 5 Aug 2013, 11:52 (13 years ago) parente06be4d
11 files changed+224−2
Dash/Apps/AppPreview.qml+1 plugins/Ubuntu/DownloadDaemonListener/download_tracker.cpp+16−1 plugins/Ubuntu/DownloadDaemonListener/download_tracker.h+5 tests/mocks/Ubuntu/CMakeLists.txt+1 tests/mocks/Ubuntu/DownloadDaemonListener/CMakeLists.txt+24 tests/mocks/Ubuntu/DownloadDaemonListener/download_tracker.cpp+55 tests/mocks/Ubuntu/DownloadDaemonListener/download_tracker.h+60 tests/mocks/Ubuntu/DownloadDaemonListener/plugin.cpp+28 tests/mocks/Ubuntu/DownloadDaemonListener/plugin.h+30 tests/mocks/Ubuntu/DownloadDaemonListener/qmldir+2 tests/qmltests/Dash/Apps/tst_AppPreview.qml+2−1
Dash/Apps/AppPreview.qml+1
@@ -117,6 +117,7 @@ DashPreview {
117117 }
118118
119119 DownloadTracker {
120+ service: "com.canonical.applications.Downloader"
120121 dbusPath: root.previewData.infoMap["progressbar_source"] ? root.previewData.infoMap["progressbar_source"].value : ""
121122
122123 onProgress: {
plugins/Ubuntu/DownloadDaemonListener/download_tracker.cpp+16−1
@@ -41,7 +41,22 @@ void DownloadTracker::setDbusPath(QString& path)
4141{
4242 if(path != ""){
4343 this->m_dbusPath = path;
44− this->adaptor = new DownloadTrackerAdaptor("com.canonical.applications.Downloader", this->m_dbusPath, QDBusConnection::sessionBus(), 0);
44+ this->startService();
45+ }
46+}
47+
48+void DownloadTracker::setService(QString& service)
49+{
50+ if(service != ""){
51+ this->m_service = service;
52+ this->startService();
53+ }
54+}
55+
56+void DownloadTracker::startService()
57+{
58+ if(!this->m_service.isEmpty() && !this->m_dbusPath.isEmpty()) {
59+ this->adaptor = new DownloadTrackerAdaptor(this->m_service, this->m_dbusPath, QDBusConnection::sessionBus(), 0);
4560
4661 this->connect(this->adaptor, SIGNAL(canceled(bool)), this, SIGNAL(canceled(bool)));
4762 this->connect(this->adaptor, SIGNAL(error(const QString &)), this, SIGNAL(error(const QString &)));
plugins/Ubuntu/DownloadDaemonListener/download_tracker.h+5
@@ -31,6 +31,7 @@ class DownloadTracker : public QObject
3131{
3232 Q_OBJECT
3333 Q_DISABLE_COPY(DownloadTracker)
34+ Q_PROPERTY(QString service WRITE setService)
3435 Q_PROPERTY(QString dbusPath WRITE setDbusPath)
3536 Q_PROPERTY(bool serviceReady READ isServiceReady)
3637
@@ -38,6 +39,7 @@ public:
3839 explicit DownloadTracker(QObject *parent = 0);
3940
4041 void setDbusPath(QString& path);
42+ void setService(QString& service);
4143 bool isServiceReady();
4244
4345Q_SIGNALS:
@@ -51,7 +53,10 @@ Q_SIGNALS:
5153
5254private:
5355 QString m_dbusPath;
56+ QString m_service;
5457 DownloadTrackerAdaptor* adaptor;
58+
59+ void startService();
5560};
5661
5762#endif // MYTYPE_H
tests/mocks/Ubuntu/CMakeLists.txt+1
@@ -1 +1,2 @@
11add_subdirectory(Application)
2+add_subdirectory(DownloadDaemonListener)
tests/mocks/Ubuntu/DownloadDaemonListener/CMakeLists.txtnew file+24
@@ -0,0 +1,24 @@
1+set(CMAKE_AUTOMOC ON)
2+
3+include(FindPkgConfig)
4+find_package(Qt5Core REQUIRED)
5+find_package(Qt5Quick REQUIRED)
6+
7+set(FakeUbuntuDownloadDaemonListenerQml_SOURCES
8+ plugin.cpp
9+ download_tracker.cpp
10+)
11+
12+add_library(FakeUbuntuDownloadDaemonListenerQml MODULE ${FakeUbuntuDownloadDaemonListenerQml_SOURCES})
13+
14+qt5_use_modules(FakeUbuntuDownloadDaemonListenerQml Core Quick)
15+
16+# copy files into build directory for shadow builds
17+add_custom_target(UbuntuDownloadQmlDirFile ALL
18+ COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/qmldir" ${CMAKE_CURRENT_BINARY_DIR}
19+ DEPENDS qmldir
20+)
21+
22+install(TARGETS FakeUbuntuDownloadDaemonListenerQml
23+ DESTINATION ${SHELL_PRIVATE_LIBDIR}/qml/mocks/Ubuntu/DownloadDaemonListener
24+ )
tests/mocks/Ubuntu/DownloadDaemonListener/download_tracker.cppnew file+55
@@ -0,0 +1,55 @@
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 Lesser General Public License, as
6+ * published by the Free Software Foundation; either version 2.1 or 3.0
7+ * of the License.
8+ *
9+ * This program is distributed in the hope that it will be useful, but
10+ * WITHOUT ANY WARRANTY; without even the implied warranties of
11+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12+ * PURPOSE. See the applicable version of the GNU Lesser General Public
13+ * License for more details.
14+ *
15+ * You should have received a copy of both the GNU Lesser General Public
16+ * License along with this program. If not, see <http://www.gnu.org/licenses/>
17+ *
18+ * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
19+ */
20+
21+
22+#include "download_tracker.h"
23+
24+DownloadTracker::DownloadTracker(QObject *parent) :
25+ QObject(parent)
26+{
27+}
28+
29+bool DownloadTracker::isServiceReady()
30+{
31+ return active;
32+}
33+
34+void DownloadTracker::setDbusPath(QString& path)
35+{
36+ if(path != ""){
37+ this->m_dbusPath = path;
38+ this->startService();
39+ }
40+}
41+
42+void DownloadTracker::setService(QString& service)
43+{
44+ if(service != ""){
45+ this->m_service = service;
46+ this->startService();
47+ }
48+}
49+
50+void DownloadTracker::startService()
51+{
52+ if(!this->m_service.isEmpty() && !this->m_dbusPath.isEmpty()) {
53+ this->active = true;
54+ }
55+}
tests/mocks/Ubuntu/DownloadDaemonListener/download_tracker.hnew file+60
@@ -0,0 +1,60 @@
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 Lesser General Public License, as
6+ * published by the Free Software Foundation; either version 2.1 or 3.0
7+ * of the License.
8+ *
9+ * This program is distributed in the hope that it will be useful, but
10+ * WITHOUT ANY WARRANTY; without even the implied warranties of
11+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12+ * PURPOSE. See the applicable version of the GNU Lesser General Public
13+ * License for more details.
14+ *
15+ * You should have received a copy of both the GNU Lesser General Public
16+ * License along with this program. If not, see <http://www.gnu.org/licenses/>
17+ *
18+ * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
19+ */
20+
21+
22+#ifndef MYTYPE_H
23+#define MYTYPE_H
24+
25+#include <QObject>
26+#include <QList>
27+
28+class DownloadTracker : public QObject
29+{
30+ Q_OBJECT
31+ Q_DISABLE_COPY(DownloadTracker)
32+ Q_PROPERTY(QString service WRITE setService)
33+ Q_PROPERTY(QString dbusPath WRITE setDbusPath)
34+ Q_PROPERTY(bool serviceReady READ isServiceReady)
35+
36+public:
37+ explicit DownloadTracker(QObject *parent = 0);
38+
39+ void setDbusPath(QString& path);
40+ void setService(QString& service);
41+ bool isServiceReady();
42+
43+Q_SIGNALS:
44+ void canceled(bool success);
45+ void error(const QString &error);
46+ void finished(const QString &path);
47+ void paused(bool success);
48+ void progress(qulonglong received, qulonglong total);
49+ void resumed(bool success);
50+ void started(bool success);
51+
52+private:
53+ QString m_dbusPath;
54+ QString m_service;
55+ bool active = false;
56+
57+ void startService();
58+};
59+
60+#endif // MYTYPE_H
tests/mocks/Ubuntu/DownloadDaemonListener/plugin.cppnew file+28
@@ -0,0 +1,28 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "plugin.h"
18+#include "download_tracker.h"
19+
20+#include <QtQml>
21+#include <QtQml/QQmlContext>
22+#include <qqml.h>
23+
24+
25+void FakeUbuntuDownloadDaemonListenerQmlPlugin::registerTypes(const char *uri)
26+{
27+ qmlRegisterType<DownloadTracker>(uri, 0, 1, "DownloadTracker");
28+}
tests/mocks/Ubuntu/DownloadDaemonListener/plugin.hnew file+30
@@ -0,0 +1,30 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef PLUGIN_H
18+#define PLUGIN_H
19+
20+#include <QQmlExtensionPlugin>
21+
22+class FakeUbuntuDownloadDaemonListenerQmlPlugin : public QQmlExtensionPlugin
23+{
24+ Q_OBJECT
25+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
26+public:
27+ void registerTypes(const char *uri);
28+};
29+
30+#endif
tests/mocks/Ubuntu/DownloadDaemonListener/qmldirnew file+2
@@ -0,0 +1,2 @@
1+module Ubuntu.DownloadDaemonListener
2+plugin FakeUbuntuDownloadDaemonListenerQml
tests/qmltests/Dash/Apps/tst_AppPreview.qml+2−1
@@ -99,7 +99,8 @@ Item {
9999 when: windowShown
100100
101101 function cleanup() {
102− sendReviewSpy.clear();
102+ sendPreviewSpy.clear();
103+ var reviewField = findChild(appPreview, "reviewField");
103104 reviewField.focus = false;
104105 reviewField.text = "";
105106 }