Merge lp:~mandel/ubuntu-download-manager/expose-logger into lp:ubuntu-download-manager

Proposed by Manuel de la Peña
Status: Superseded
Proposed branch: lp:~mandel/ubuntu-download-manager/expose-logger
Merge into: lp:ubuntu-download-manager
Prerequisite: lp:~mandel/ubuntu-download-manager/expose-property
Diff against target: 957 lines (+694/-30)
16 files modified
docs/qml/pages/mainpage.qdoc (+1/-0)
src/downloads/qml/CMakeLists.txt (+2/-0)
src/downloads/qml/logger.cpp (+67/-0)
src/downloads/qml/logger.h (+53/-0)
src/downloads/qml/single_download.cpp (+54/-15)
src/downloads/qml/single_download.h (+5/-2)
tests/downloads/CMakeLists.txt (+1/-1)
tests/downloads/daemon/CMakeLists.txt (+1/-1)
tests/downloads/daemon/test_download.cpp (+0/-1)
tests/downloads/qml/CMakeLists.txt (+73/-1)
tests/downloads/qml/download.h (+11/-0)
tests/downloads/qml/error.h (+35/-0)
tests/downloads/qml/manager.h (+2/-2)
tests/downloads/qml/test_single_download.cpp (+328/-4)
tests/downloads/qml/test_single_download.h (+33/-3)
tests/downloads/qml/testable_single_download.h (+28/-0)
To merge this branch: bzr merge lp:~mandel/ubuntu-download-manager/expose-logger
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Ubuntu Phablet Team Pending
Review via email: mp+224987@code.launchpad.net

This proposal has been superseded by a proposal from 2014-07-04.

Commit message

Expose the logger object so that qml developer can provide the logging level and path used by the plugin.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
328. By Manuel de la Peña

Added missing logger files.

329. By Manuel de la Peña

Merged expose-property into expose-logger.

330. By Manuel de la Peña

Merged expose-property into expose-logger.

331. By Manuel de la Peña

Update docs.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
332. By Manuel de la Peña

Improve docs.

333. By Manuel de la Peña

Style.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
334. By Manuel de la Peña

Merged expose-property into expose-logger.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
335. By Manuel de la Peña

Merged expose-property into expose-logger.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
336. By Manuel de la Peña

Merged expose-property into expose-logger.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
337. By Manuel de la Peña

Merged with previous branch.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Unmerged revisions

337. By Manuel de la Peña

Merged with previous branch.

336. By Manuel de la Peña

Merged expose-property into expose-logger.

335. By Manuel de la Peña

Merged expose-property into expose-logger.

334. By Manuel de la Peña

Merged expose-property into expose-logger.

333. By Manuel de la Peña

Style.

332. By Manuel de la Peña

Improve docs.

331. By Manuel de la Peña

Update docs.

330. By Manuel de la Peña

Merged expose-property into expose-logger.

329. By Manuel de la Peña

Merged expose-property into expose-logger.

328. By Manuel de la Peña

Added missing logger files.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'docs/qml/pages/mainpage.qdoc'
2--- docs/qml/pages/mainpage.qdoc 2014-06-20 10:10:50 +0000
3+++ docs/qml/pages/mainpage.qdoc 2014-07-04 15:21:46 +0000
4@@ -41,6 +41,7 @@
5 \list
6 \li \l {DownloadManager}
7 \li \l {SingleDownload}
8+ \li \l {Logger}
9 \endlist
10
11 \section1 Example usage - Downloading a file
12
13=== modified file 'src/downloads/qml/CMakeLists.txt'
14--- src/downloads/qml/CMakeLists.txt 2014-07-04 15:21:46 +0000
15+++ src/downloads/qml/CMakeLists.txt 2014-07-04 15:21:46 +0000
16@@ -4,6 +4,7 @@
17 set(plugin_SRCS
18 backend.cpp
19 download_error.cpp
20+ logger.cpp
21 single_download.cpp
22 ubuntu_download_manager.cpp
23 )
24@@ -11,6 +12,7 @@
25 set(plugin_HDRS
26 backend.h
27 download_error.h
28+ logger.h
29 single_download.h
30 ubuntu_download_manager.h
31 )
32
33=== added file 'src/downloads/qml/logger.cpp'
34--- src/downloads/qml/logger.cpp 1970-01-01 00:00:00 +0000
35+++ src/downloads/qml/logger.cpp 2014-07-04 15:21:46 +0000
36@@ -0,0 +1,67 @@
37+/*
38+ * Copyright 2014 Canonical Ltd.
39+ *
40+ * This library is free software; you can redistribute it and/or
41+ * modify it under the terms of version 3 of the GNU Lesser General Public
42+ * License as published by the Free Software Foundation.
43+ *
44+ * This program is distributed in the hope that it will be useful,
45+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
46+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
47+ * General Public License for more details.
48+ *
49+ * You should have received a copy of the GNU Lesser General Public
50+ * License along with this library; if not, write to the
51+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
52+ * Boston, MA 02110-1301, USA.
53+ */
54+
55+#include <ubuntu/download_manager/logging/logger.h>
56+
57+#include "logger.h"
58+
59+namespace Ubuntu {
60+
61+namespace DownloadManager {
62+
63+/*!
64+ \qmltype Logger
65+ \instantiates Logger
66+ \inqmlmodule Ubuntu.DownloadManager 0.1
67+ \ingroup download
68+ \brief Allows to set the logging level used by the plugin.
69+
70+ The logger object allows to set the logging level that will be used
71+ by the plugin to allow better debugging. All logging performed by the
72+ library is thread safe and can be used to determine the different operations
73+ that are taken per download using the download id to indentify them.
74+*/
75+
76+Logger::Logger(QObject* parent)
77+ : QObject(parent) {
78+}
79+
80+/*!
81+ \qmlmethod void Logger::init(Logger::Level lvl, QString path)
82+
83+ Initializes the logging service of the plugin with the given level and will
84+ write the logs in the passed full path. If the path does not exist it will
85+ be created.
86+*/
87+void
88+Logger::init(Logger::Level lvl, QString path) {
89+ // cast the level to the logging level and init
90+ auto lgLvl = static_cast<Ubuntu::DownloadManager::Logging::Logger::Level>(lvl);
91+ Ubuntu::DownloadManager::Logging::Logger::init(lgLvl, path);
92+}
93+
94+/*!
95+ \enum Logger::Level
96+
97+ The level to be used when writing the logs.
98+*/
99+
100+} // DownloadManager
101+
102+} // Ubuntu
103+
104
105=== added file 'src/downloads/qml/logger.h'
106--- src/downloads/qml/logger.h 1970-01-01 00:00:00 +0000
107+++ src/downloads/qml/logger.h 2014-07-04 15:21:46 +0000
108@@ -0,0 +1,53 @@
109+/*
110+ * Copyright 2014 Canonical Ltd.
111+ *
112+ * This library is free software; you can redistribute it and/or
113+ * modify it under the terms of version 3 of the GNU Lesser General Public
114+ * License as published by the Free Software Foundation.
115+ *
116+ * This program is distributed in the hope that it will be useful,
117+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
118+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
119+ * General Public License for more details.
120+ *
121+ * You should have received a copy of the GNU Lesser General Public
122+ * License along with this library; if not, write to the
123+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
124+ * Boston, MA 02110-1301, USA.
125+ */
126+
127+#ifndef DOWNLOAD_QML_LOGGER_H
128+#define DOWNLOAD_QML_LOGGER_H
129+
130+namespace Ubuntu {
131+
132+namespace DownloadManager {
133+
134+class Logger : public QObject {
135+ Q_OBJECT
136+ Q_ENUMS(Level)
137+
138+ public:
139+
140+ enum Level {
141+ Debug,
142+ Normal,
143+ Notification,
144+ Warning,
145+ Error,
146+ Critical
147+ };
148+
149+ explicit Logger(QObject* parent=0);
150+
151+ Q_INVOKABLE void init(Level lvl, QString path);
152+
153+ private:
154+ QString m_path; // path used to log
155+};
156+
157+} // DownloadManager
158+
159+} // Ubuntu
160+
161+#endif // DOWNLOAD_QML_LOGGER_H
162
163=== modified file 'src/downloads/qml/single_download.cpp'
164--- src/downloads/qml/single_download.cpp 2014-07-04 15:21:46 +0000
165+++ src/downloads/qml/single_download.cpp 2014-07-04 15:21:46 +0000
166@@ -1,7 +1,26 @@
167-#include "single_download.h"
168+/*
169+ * Copyright 2014 Canonical Ltd.
170+ *
171+ * This library is free software; you can redistribute it and/or
172+ * modify it under the terms of version 3 of the GNU Lesser General Public
173+ * License as published by the Free Software Foundation.
174+ *
175+ * This program is distributed in the hope that it will be useful,
176+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
177+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
178+ * General Public License for more details.
179+ *
180+ * You should have received a copy of the GNU Lesser General Public
181+ * License along with this library; if not, write to the
182+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
183+ * Boston, MA 02110-1301, USA.
184+ */
185+
186 #include <glog/logging.h>
187 #include <ubuntu/download_manager/download_struct.h>
188
189+#include "single_download.h"
190+
191 namespace Ubuntu {
192
193 namespace DownloadManager {
194@@ -69,17 +88,31 @@
195 \sa {DownloadManager}
196 */
197
198-SingleDownload::SingleDownload(QObject *parent) :
199- QObject(parent),
200- m_autoStart(true),
201- m_completed(false),
202- m_downloading(false),
203- m_downloadInProgress(false),
204- m_progress(0),
205- m_error(this),
206- m_download(nullptr),
207- m_manager(nullptr)
208-{
209+SingleDownload::SingleDownload(QObject *parent)
210+ : QObject(parent),
211+ m_autoStart(true),
212+ m_completed(false),
213+ m_downloading(false),
214+ m_downloadInProgress(false),
215+ m_progress(0),
216+ m_error(this),
217+ m_download(nullptr),
218+ m_manager(nullptr) {
219+}
220+
221+// constructor that is simple provided for testing purposes
222+SingleDownload::SingleDownload(Download* down, Manager* man, QObject *parent)
223+ : QObject(parent),
224+ m_autoStart(false),
225+ m_completed(false),
226+ m_downloading(false),
227+ m_downloadInProgress(false),
228+ m_progress(0),
229+ m_error(this),
230+ m_download(down),
231+ m_manager(man) {
232+ if (m_download != nullptr)
233+ bindDownload(m_download);
234 }
235
236 void
237@@ -108,6 +141,9 @@
238 &SingleDownload::onPaused))
239 << "Could not connect to signal";
240
241+ CHECK(connect(m_download, &Download::processing, this,
242+ &SingleDownload::processing)) << "Could not connect to signal";
243+
244 CHECK(connect(m_download, &Download::resumed, this,
245 &SingleDownload::onResumed))
246 << "Could not connect to signal";
247@@ -157,6 +193,9 @@
248 &SingleDownload::onPaused))
249 << "Could not connect to signal";
250
251+ CHECK(disconnect(m_download, &Download::processing, this,
252+ &SingleDownload::processing)) << "Could not connect to signal";
253+
254 CHECK(disconnect(download, &Download::resumed, this,
255 &SingleDownload::onResumed))
256 << "Could not connect to signal";
257@@ -294,7 +333,7 @@
258 SingleDownload::onStarted(bool wasStarted)
259 {
260 m_downloading = true;
261- emit resumed(wasStarted);
262+ emit started(wasStarted);
263 }
264
265 void
266@@ -349,7 +388,7 @@
267 }
268 }
269
270-void
271+void
272 SingleDownload::setThrottle(qulonglong value) {
273 if (m_download == nullptr) {
274 m_dirty = true;
275@@ -416,7 +455,7 @@
276 return;
277 }
278 }
279-
280+
281 m_download->setHeaders(stringMap);
282 if (m_download->isError()) {
283 // set the error details and emit the signals
284
285=== modified file 'src/downloads/qml/single_download.h'
286--- src/downloads/qml/single_download.h 2014-07-04 15:21:46 +0000
287+++ src/downloads/qml/single_download.h 2014-07-04 15:21:46 +0000
288@@ -43,7 +43,7 @@
289 Q_PROPERTY(QString downloadId READ downloadId NOTIFY downloadIdChanged)
290 Q_PROPERTY(QVariantMap headers READ headers WRITE setHeaders NOTIFY headersChanged)
291
292-public:
293+ public:
294 explicit SingleDownload(QObject *parent = 0);
295
296 Q_INVOKABLE void start();
297@@ -100,7 +100,10 @@
298 m_autoStart = value;
299 }
300
301-signals:
302+ protected:
303+ SingleDownload(Download* down, Manager* man, QObject *parent = 0);
304+
305+ signals:
306 void isCompletedChanged();
307 void allowMobileDownloadChanged();
308 void throttleChanged();
309
310=== modified file 'tests/downloads/CMakeLists.txt'
311--- tests/downloads/CMakeLists.txt 2014-07-04 15:21:46 +0000
312+++ tests/downloads/CMakeLists.txt 2014-07-04 15:21:46 +0000
313@@ -16,4 +16,4 @@
314
315 add_subdirectory(client)
316 add_subdirectory(daemon)
317-#add_subdirectory(qml)
318+add_subdirectory(qml)
319
320=== modified file 'tests/downloads/daemon/CMakeLists.txt'
321--- tests/downloads/daemon/CMakeLists.txt 2014-07-04 15:21:46 +0000
322+++ tests/downloads/daemon/CMakeLists.txt 2014-07-04 15:21:46 +0000
323@@ -124,6 +124,6 @@
324 )
325
326
327- ADD_TEST(NAME daemon_${test} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${test}_daemon)
328+ADD_TEST(NAME daemon_${test} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${test}_daemon)
329 endforeach(test)
330
331
332=== modified file 'tests/downloads/daemon/test_download.cpp'
333--- tests/downloads/daemon/test_download.cpp 2014-04-15 12:37:16 +0000
334+++ tests/downloads/daemon/test_download.cpp 2014-07-04 15:21:46 +0000
335@@ -32,7 +32,6 @@
336 using ::testing::Mock;
337 using ::testing::AnyNumber;
338 using ::testing::Return;
339-using ::testing::Return;
340 using ::testing::AnyOf;
341
342 using namespace Ubuntu::Transfers::Tests;
343
344=== modified file 'tests/downloads/qml/CMakeLists.txt'
345--- tests/downloads/qml/CMakeLists.txt 2014-07-04 15:21:46 +0000
346+++ tests/downloads/qml/CMakeLists.txt 2014-07-04 15:21:46 +0000
347@@ -1,14 +1,86 @@
348+# Copyright © 2014 Canonical Ltd.
349+#
350+# This program is free software: you can redistribute it and/or modify
351+# it under the terms of the GNU General Public License version 3 as
352+# published by the Free Software Foundation.
353+#
354+# This program is distributed in the hope that it will be useful,
355+# but WITHOUT ANY WARRANTY; without even the implied warranty of
356+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
357+# GNU General Public License for more details.
358+#
359+# You should have received a copy of the GNU General Public License
360+# along with this program. If not, see <http://www.gnu.org/licenses/>.
361+#
362+# Authored by: Manuel de la Peña <manuel.delapena@canonical.com>
363+
364 set(QML_TESTS
365+ test_single_download
366 )
367
368-foreach(test ${DAEMON_TESTS})
369+foreach(test ${QML_TESTS})
370 # set the sources per test
371 set(${test}_QML_SOURCES
372 ${test}.cpp
373 )
374
375 set(${test}_QML_HEADERS
376+ download.h
377+ error.h
378+ manager.h
379+ testable_single_download.h
380 ${test}.h
381 )
382
383 endforeach(test)
384+
385+include_directories(${Qt5Core_INCLUDE_DIRS})
386+include_directories(${Qt5SystemInfo_INCLUDE_DIRS})
387+include_directories(${Qt5DBus_INCLUDE_DIRS})
388+include_directories(${Qt5Network_INCLUDE_DIRS})
389+include_directories(${Qt5Test_INCLUDE_DIRS})
390+include_directories(${Qt5Sql_INCLUDE_DIRS})
391+include_directories(${DBUS_INCLUDE_DIRS})
392+include_directories(${GTEST_INCLUDE_DIRS})
393+include_directories(${GMOCK_INCLUDE_DIRS})
394+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
395+include_directories(${CMAKE_CURRENT_BINARY_DIR})
396+include_directories(${CMAKE_SOURCE_DIR}/src/common/public)
397+include_directories(${CMAKE_SOURCE_DIR}/src/downloads/common)
398+include_directories(${CMAKE_SOURCE_DIR}/src/downloads/client)
399+include_directories(${CMAKE_SOURCE_DIR}/src/downloads/qml)
400+include_directories(${CMAKE_SOURCE_DIR}/tests/common)
401+
402+link_directories(${NIH_DBUS_LIBDIR})
403+link_directories(${GLOG_DBUS_LIBDIR})
404+
405+set(QML_TESTS_LIBS
406+ ${NIH_DBUS_LIBRARIES}
407+ ${GLOG_LIBRARIES}
408+ ${Qt5Core_LIBRARIES}
409+ ${Qt5Sql_LIBRARIES}
410+ ${Qt5DBus_LIBRARIES}
411+ ${Qt5Test_LIBRARIES}
412+ ${GMOCK_LIBRARY}
413+ ${GTEST_BOTH_LIBRARIES}
414+ udm-common
415+ ubuntu-download-manager-common
416+ ubuntu-download-manager-test-lib
417+ UbuntuDownloadManager
418+)
419+
420+foreach(test ${QML_TESTS})
421+ # set targets, linked libs and test
422+ add_executable(${test}_qml
423+ ${${test}_QML_SOURCES}
424+ ${${test}_QML_HEADERS}
425+ )
426+
427+ target_link_libraries(${test}_qml
428+ ${QML_TESTS_LIBS}
429+ )
430+
431+
432+ ADD_TEST(NAME qml_${test} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${test}_qml)
433+endforeach(test)
434+
435
436=== modified file 'tests/downloads/qml/download.h'
437--- tests/downloads/qml/download.h 2014-07-04 15:21:46 +0000
438+++ tests/downloads/qml/download.h 2014-07-04 15:21:46 +0000
439@@ -48,6 +48,17 @@
440 MOCK_METHOD0(totalSize, qulonglong());
441 MOCK_CONST_METHOD0(isError, bool());
442 MOCK_CONST_METHOD0(error, Error*());
443+
444+ // expose the signals so that they can emitted by external objects
445+
446+ using Download::canceled;
447+ using Download::error;
448+ using Download::finished;
449+ using Download::paused;
450+ using Download::processing;
451+ using Download::progress;
452+ using Download::resumed;
453+ using Download::started;
454 };
455
456 #endif
457
458=== added file 'tests/downloads/qml/error.h'
459--- tests/downloads/qml/error.h 1970-01-01 00:00:00 +0000
460+++ tests/downloads/qml/error.h 2014-07-04 15:21:46 +0000
461@@ -0,0 +1,35 @@
462+/*
463+ * Copyright 2014 Canonical Ltd.
464+ *
465+ * This library is free software; you can redistribute it and/or
466+ * modify it under the terms of version 3 of the GNU Lesser General Public
467+ * License as published by the Free Software Foundation.
468+ *
469+ * This program is distributed in the hope that it will be useful,
470+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
471+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
472+ * General Public License for more details.
473+ *
474+ * You should have received a copy of the GNU Lesser General Public
475+ * License along with this library; if not, write to the
476+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
477+ * Boston, MA 02110-1301, USA.
478+ */
479+
480+#ifndef FAKE_CLIENT_ERROR_H
481+#define FAKE_CLIENT_ERROR_H
482+
483+#include <ubuntu/download_manager/error.h>
484+#include <gmock/gmock.h>
485+
486+using namespace Ubuntu::DownloadManager;
487+
488+class MockError : public Error {
489+ public:
490+ MockError(Type type, QObject* parent = 0)
491+ : Error(type, parent) {}
492+
493+ MOCK_METHOD0(errorString, QString());
494+};
495+
496+#endif
497
498=== modified file 'tests/downloads/qml/manager.h'
499--- tests/downloads/qml/manager.h 2014-07-04 15:21:46 +0000
500+++ tests/downloads/qml/manager.h 2014-07-04 15:21:46 +0000
501@@ -33,7 +33,7 @@
502 MOCK_METHOD1(getDownloadForId, Download*(const QString&));
503 MOCK_METHOD1(createDownload, void(DownloadStruct));
504 MOCK_METHOD3(createDownload, void(DownloadStruct, DownloadCb, DownloadCb));
505- MOCK_METHOD4(createDownload, void(StructList downs, const QString&, bool,
506+ MOCK_METHOD5(createDownload, void(StructList, const QString&, bool,
507 const QVariantMap&, StringMap));
508 MOCK_METHOD7(createDownload, void(StructList, const QString&, bool,
509 const QVariantMap&, StringMap, GroupCb, GroupCb));
510@@ -41,7 +41,7 @@
511 MOCK_METHOD2(getAllDownloads, void(DownloadsListCb, DownloadsListCb));
512 MOCK_METHOD2(getAllDownloadsWithMetadata, void(const QString&,
513 const QString&));
514- MOCK_METHOD2(getAllDownloadsWithMetadata, void(const QString&,
515+ MOCK_METHOD4(getAllDownloadsWithMetadata, void(const QString&,
516 const QString&, MetadataDownloadsListCb, MetadataDownloadsListCb));
517 MOCK_CONST_METHOD0(isError, bool());
518 MOCK_CONST_METHOD0(lastError, Error*());
519
520=== modified file 'tests/downloads/qml/test_single_download.cpp'
521--- tests/downloads/qml/test_single_download.cpp 2014-07-04 15:21:46 +0000
522+++ tests/downloads/qml/test_single_download.cpp 2014-07-04 15:21:46 +0000
523@@ -16,16 +16,340 @@
524 * Boston, MA 02110-1301, USA.
525 */
526
527+#include <QScopedPointer>
528+
529+#include <gmock/gmock.h>
530+
531+#include <matchers.h>
532+#include "error.h"
533+#include "test_single_download.h"
534+
535+using ::testing::_;
536+using ::testing::Mock;
537+using ::testing::Return;
538+
539 TestSingleDownload::TestSingleDownload(QObject *parent)
540- : LocalTreeTestCase("TestSingleDownload", parent) {
541+ : BaseTestCase("TestSingleDownload", parent) {
542 }
543
544 void
545 TestSingleDownload::init() {
546- LocalTreeTestCase::init();
547+ BaseTestCase::init();
548+
549+ _metadata["my-string"] = "canonical";
550+ _metadata["your-string"] = "developer";
551+ _headers["test"] = "test";
552+ _headers["my test"] = "my test";
553+ _url = "http://example.com";
554+
555+ _down = new MockDownload();
556+ _man = new MockManager();
557 }
558
559 void
560 TestSingleDownload::cleanup() {
561- LocalTreeTestCase::cleanup();
562-}
563+ BaseTestCase::cleanup();
564+ delete _down;
565+ delete _man;
566+}
567+
568+void
569+TestSingleDownload::verifyMocks() {
570+ QVERIFY(Mock::VerifyAndClearExpectations(_down));
571+ QVERIFY(Mock::VerifyAndClearExpectations(_man));
572+}
573+
574+void
575+TestSingleDownload::testCanceledSignalFwd() {
576+ QScopedPointer<TestableSingleDownload> singleDownload(
577+ new TestableSingleDownload(_down, _man));
578+
579+ SignalBarrier spy(singleDownload.data(), SIGNAL(canceled(bool)));
580+ _down->canceled(true);
581+
582+ QVERIFY(spy.ensureSignalEmitted());
583+
584+ verifyMocks();
585+}
586+
587+void
588+TestSingleDownload::testFinishedSingalFwd() {
589+ QScopedPointer<TestableSingleDownload> singleDownload(
590+ new TestableSingleDownload(_down, _man));
591+
592+ SignalBarrier spy(singleDownload.data(), SIGNAL(finished(const QString&)));
593+ _down->finished(QString("TEST"));
594+
595+ QVERIFY(spy.ensureSignalEmitted());
596+
597+ verifyMocks();
598+}
599+
600+void
601+TestSingleDownload::testPausedSignalFwd() {
602+ QScopedPointer<TestableSingleDownload> singleDownload(
603+ new TestableSingleDownload(_down, _man));
604+
605+ SignalBarrier spy(singleDownload.data(), SIGNAL(paused(bool)));
606+ _down->paused(true);
607+
608+ QVERIFY(spy.ensureSignalEmitted());
609+
610+ verifyMocks();
611+}
612+
613+void
614+TestSingleDownload::testProcessingSignalFwd() {
615+ QScopedPointer<TestableSingleDownload> singleDownload(
616+ new TestableSingleDownload(_down, _man));
617+
618+ SignalBarrier spy(singleDownload.data(), SIGNAL(processing(const QString&)));
619+ _down->processing(QString("TEST"));
620+
621+ QVERIFY(spy.ensureSignalEmitted());
622+
623+ verifyMocks();
624+}
625+
626+void
627+TestSingleDownload::testProgressSignalFwd() {
628+ QScopedPointer<TestableSingleDownload> singleDownload(
629+ new TestableSingleDownload(_down, _man));
630+
631+ SignalBarrier spy(singleDownload.data(),
632+ SIGNAL(progressReceived(qulonglong, qulonglong)));
633+ _down->progress(30, 700);
634+
635+ QVERIFY(spy.ensureSignalEmitted());
636+
637+ verifyMocks();
638+}
639+
640+void
641+TestSingleDownload::testResumedSignalFwd() {
642+ QScopedPointer<TestableSingleDownload> singleDownload(
643+ new TestableSingleDownload(_down, _man));
644+
645+ SignalBarrier spy(singleDownload.data(), SIGNAL(resumed(bool)));
646+ _down->resumed(true);
647+
648+ QVERIFY(spy.ensureSignalEmitted());
649+
650+ verifyMocks();
651+}
652+
653+void
654+TestSingleDownload::testStartedSignalFwd() {
655+ QScopedPointer<TestableSingleDownload> singleDownload(
656+ new TestableSingleDownload(_down, _man));
657+
658+ SignalBarrier spy(singleDownload.data(), SIGNAL(started(bool)));
659+ _down->started(true);
660+
661+ QVERIFY(spy.ensureSignalEmitted());
662+
663+ verifyMocks();
664+}
665+
666+void
667+TestSingleDownload::testSetAllowMobileDataNullptr() {
668+ QScopedPointer<TestableSingleDownload> singleDownload(
669+ new TestableSingleDownload(nullptr, _man));
670+
671+ // ensure that the mocks are not called and we do not crash
672+ singleDownload->setAllowMobileDownload(true);
673+ verifyMocks();
674+}
675+
676+void
677+TestSingleDownload::testSetAllowMobileDataError() {
678+ QScopedPointer<MockError> err(new MockError(Error::DBus));
679+ QScopedPointer<TestableSingleDownload> singleDownload(
680+ new TestableSingleDownload(_down, _man));
681+
682+ EXPECT_CALL(*_down, allowMobileDownload(true))
683+ .Times(1);
684+
685+ EXPECT_CALL(*_down, isError())
686+ .Times(1)
687+ .WillOnce(Return(true));
688+
689+ EXPECT_CALL(*_down, error())
690+ .Times(1)
691+ .WillOnce(Return(err.data()));
692+
693+ EXPECT_CALL(*err.data(), errorString())
694+ .Times(1)
695+ .WillOnce(Return(QString("My error")));
696+
697+ // ensure that the diff signals are emitted
698+ SignalBarrier spy(singleDownload.data(), SIGNAL(errorChanged()));
699+
700+ singleDownload->setAllowMobileDownload(true);
701+
702+ QVERIFY(spy.ensureSignalEmitted());
703+ verifyMocks();
704+}
705+
706+void
707+TestSingleDownload::testSetAllowMobileDataSuccess() {
708+ QScopedPointer<TestableSingleDownload> singleDownload(
709+ new TestableSingleDownload(_down, _man));
710+
711+ EXPECT_CALL(*_down, allowMobileDownload(true))
712+ .Times(1);
713+
714+ EXPECT_CALL(*_down, isError())
715+ .Times(1)
716+ .WillOnce(Return(false));
717+
718+ // ensure that the diff signals are emitted
719+ SignalBarrier spy(singleDownload.data(), SIGNAL(allowMobileDownloadChanged()));
720+
721+ singleDownload->setAllowMobileDownload(true);
722+
723+ QVERIFY(spy.ensureSignalEmitted());
724+ verifyMocks();
725+}
726+
727+void
728+TestSingleDownload::testSetThrottleNullptr() {
729+ QScopedPointer<TestableSingleDownload> singleDownload(
730+ new TestableSingleDownload(nullptr, _man));
731+
732+ singleDownload->setThrottle(3);
733+ // ensure that the mocks are not called and we do not crash
734+ verifyMocks();
735+}
736+
737+void
738+TestSingleDownload::testSetThrottleError() {
739+ QScopedPointer<MockError> err(new MockError(Error::DBus));
740+ QScopedPointer<TestableSingleDownload> singleDownload(
741+ new TestableSingleDownload(_down, _man));
742+
743+ EXPECT_CALL(*_down, setThrottle(9))
744+ .Times(1);
745+
746+ EXPECT_CALL(*_down, isError())
747+ .Times(1)
748+ .WillOnce(Return(true));
749+
750+ EXPECT_CALL(*_down, error())
751+ .Times(1)
752+ .WillOnce(Return(err.data()));
753+
754+ EXPECT_CALL(*err.data(), errorString())
755+ .Times(1)
756+ .WillOnce(Return(QString("My error")));
757+
758+ // ensure that the diff signals are emitted
759+ SignalBarrier spy(singleDownload.data(), SIGNAL(errorChanged()));
760+
761+ singleDownload->setThrottle(9);
762+
763+ QVERIFY(spy.ensureSignalEmitted());
764+ verifyMocks();
765+}
766+
767+void
768+TestSingleDownload::testSetThrottleSuccess() {
769+ QScopedPointer<TestableSingleDownload> singleDownload(
770+ new TestableSingleDownload(_down, _man));
771+
772+ EXPECT_CALL(*_down, setThrottle(9))
773+ .Times(1);
774+
775+ EXPECT_CALL(*_down, isError())
776+ .Times(1)
777+ .WillOnce(Return(false));
778+
779+ // ensure that the diff signals are emitted
780+ SignalBarrier spy(singleDownload.data(), SIGNAL(throttleChanged()));
781+
782+ singleDownload->setThrottle(9);
783+
784+ QVERIFY(spy.ensureSignalEmitted());
785+ verifyMocks();
786+}
787+
788+void
789+TestSingleDownload::testSetHeadersNullptr() {
790+ QScopedPointer<TestableSingleDownload> singleDownload(
791+ new TestableSingleDownload(nullptr, _man));
792+ QVariantMap map;
793+
794+ // ensure we do not crash
795+ singleDownload->setHeaders(map);
796+ verifyMocks();
797+}
798+
799+void
800+TestSingleDownload::testSetHeadersError() {
801+ QScopedPointer<MockError> err(new MockError(Error::DBus));
802+ QScopedPointer<TestableSingleDownload> singleDownload(
803+ new TestableSingleDownload(_down, _man));
804+
805+ QVariantMap map;
806+
807+ EXPECT_CALL(*_down, setHeaders(_))
808+ .Times(1);
809+
810+ EXPECT_CALL(*_down, isError())
811+ .Times(1)
812+ .WillOnce(Return(true));
813+
814+ EXPECT_CALL(*_down, error())
815+ .Times(1)
816+ .WillOnce(Return(err.data()));
817+
818+ EXPECT_CALL(*err.data(), errorString())
819+ .Times(1)
820+ .WillOnce(Return(QString("My error")));
821+
822+ // ensure that the diff signals are emitted
823+ SignalBarrier spy(singleDownload.data(), SIGNAL(errorChanged()));
824+
825+ singleDownload->setHeaders(map);
826+
827+ QVERIFY(spy.ensureSignalEmitted());
828+ verifyMocks();
829+}
830+
831+void
832+TestSingleDownload::testSetHeadersSuccess() {
833+ QString header1, value1, header2, value2;
834+ header1 = "my-first-header";
835+ value1 = "first";
836+ header2 = "second-header";
837+ value2 = "second";
838+
839+ QVariantMap map;
840+ map[header1] = value1;
841+ map[header2] = value2;
842+
843+ QMap<QString, QString> headers;
844+ headers[header1] = value1;
845+ headers[header2] = value2;
846+
847+ QScopedPointer<TestableSingleDownload> singleDownload(
848+ new TestableSingleDownload(_down, _man));
849+
850+ EXPECT_CALL(*_down, setHeaders(QStringMapEq(headers)))
851+ .Times(1);
852+
853+ EXPECT_CALL(*_down, isError())
854+ .Times(1)
855+ .WillOnce(Return(false));
856+
857+ // ensure that the diff signals are emitted
858+ SignalBarrier spy(singleDownload.data(), SIGNAL(headersChanged()));
859+
860+ singleDownload->setHeaders(map);
861+
862+ QVERIFY(spy.ensureSignalEmitted());
863+ verifyMocks();
864+}
865+
866+QTEST_MAIN(TestSingleDownload)
867+#include "moc_test_single_download.cpp"
868
869=== modified file 'tests/downloads/qml/test_single_download.h'
870--- tests/downloads/qml/test_single_download.h 2014-07-04 15:21:46 +0000
871+++ tests/downloads/qml/test_single_download.h 2014-07-04 15:21:46 +0000
872@@ -20,12 +20,14 @@
873 #define TEST_DOWNLOAD_H
874
875 #include <QObject>
876-#include <singled_download.h>
877-#include <local_tree_testcase.h>
878+#include <base_testcase.h>
879+#include "download.h"
880+#include "manager.h"
881+#include "testable_single_download.h"
882
883 using namespace Ubuntu::DownloadManager;
884
885-class TestSingleDownload : public LocalTreeTestCase {
886+class TestSingleDownload : public BaseTestCase {
887 Q_OBJECT
888
889 public:
890@@ -33,6 +35,34 @@
891
892 void init() override;
893 void cleanup() override;
894+
895+ private slots: // NOLINT(whitespace/indent)
896+ void testCanceledSignalFwd();
897+ void testFinishedSingalFwd();
898+ void testPausedSignalFwd();
899+ void testProcessingSignalFwd();
900+ void testProgressSignalFwd();
901+ void testResumedSignalFwd();
902+ void testStartedSignalFwd();
903+ void testSetAllowMobileDataNullptr();
904+ void testSetAllowMobileDataError();
905+ void testSetAllowMobileDataSuccess();
906+ void testSetThrottleNullptr();
907+ void testSetThrottleError();
908+ void testSetThrottleSuccess();
909+ void testSetHeadersNullptr();
910+ void testSetHeadersError();
911+ void testSetHeadersSuccess();
912+
913+ private:
914+ void verifyMocks();
915+
916+ private:
917+ QString _url;
918+ QVariantMap _metadata;
919+ QMap<QString, QString> _headers;
920+ MockDownload* _down;
921+ MockManager* _man;
922 };
923
924 #endif
925
926=== added file 'tests/downloads/qml/testable_single_download.h'
927--- tests/downloads/qml/testable_single_download.h 1970-01-01 00:00:00 +0000
928+++ tests/downloads/qml/testable_single_download.h 2014-07-04 15:21:46 +0000
929@@ -0,0 +1,28 @@
930+/*
931+ * Copyright 2014 Canonical Ltd.
932+ *
933+ * This library is free software; you can redistribute it and/or
934+ * modify it under the terms of version 3 of the GNU Lesser General Public
935+ * License as published by the Free Software Foundation.
936+ *
937+ * This program is distributed in the hope that it will be useful,
938+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
939+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
940+ * General Public License for more details.
941+ *
942+ * You should have received a copy of the GNU Lesser General Public
943+ * License along with this library; if not, write to the
944+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
945+ * Boston, MA 02110-1301, USA.
946+ */
947+
948+#include <single_download.h>
949+
950+
951+class TestableSingleDownload : public SingleDownload {
952+ public:
953+ TestableSingleDownload(Download* down, Manager* man, QObject* parent = 0)
954+ : SingleDownload(down, man, parent) {
955+ }
956+
957+};

Subscribers

People subscribed via source and target branches