Merge lp:~michael-sheldon/ubuntu-download-manager/qml-api-improvements into lp:ubuntu-download-manager
- qml-api-improvements
- Merge into trunk
Status: | Merged | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Approved by: | Jonas G. Drange | ||||||||||||
Approved revision: | 365 | ||||||||||||
Merged at revision: | 364 | ||||||||||||
Proposed branch: | lp:~michael-sheldon/ubuntu-download-manager/qml-api-improvements | ||||||||||||
Merge into: | lp:ubuntu-download-manager | ||||||||||||
Diff against target: |
739 lines (+404/-33) 12 files modified
src/common/public/ubuntu/transfers/metadata.cpp (+35/-4) src/common/public/ubuntu/transfers/metadata.h (+7/-2) src/downloads/qml/metadata.cpp (+39/-0) src/downloads/qml/metadata.h (+10/-0) src/downloads/qml/single_download.cpp (+49/-3) src/downloads/qml/single_download.h (+10/-0) tests/downloads/daemon/test_metadata.cpp (+59/-18) tests/downloads/daemon/test_metadata.h (+10/-6) tests/downloads/qml/test_metadata.cpp (+51/-0) tests/downloads/qml/test_metadata.h (+6/-0) tests/downloads/qml/test_single_download.cpp (+122/-0) tests/downloads/qml/test_single_download.h (+6/-0) |
||||||||||||
To merge this branch: | bzr merge lp:~michael-sheldon/ubuntu-download-manager/qml-api-improvements | ||||||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
system-apps-ci-bot | continuous-integration | Needs Fixing | |
Jonas G. Drange (community) | Needs Information | ||
PS Jenkins bot | continuous-integration | Approve | |
Review via email: mp+291894@code.launchpad.net |
Commit message
Expose post-processing command to unconfined clients via QML, expose hashing support via QML and allow clients to set custom metadata.
Description of the change
Expose post-processing command to unconfined clients via QML, expose hashing support via QML and allow clients to set custom metadata.
PS Jenkins bot (ps-jenkins) wrote : | # |
- 363. By Michael Sheldon
-
Merge from trunk
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:363
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 364. By Michael Sheldon
-
Add tests for new QML API and custom metadata
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:364
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Jonas G. Drange (jonas-drange) wrote : | # |
I've encountered a couple of issues in using this new qml feature that might be caused by ignorance on my part, please bear with me.
First, when I create a SingleDownload and add a Metadata object to it, no matter what values I set on the Metadata object, it is ignored. E.g., I do:
Component { id: sdl; SingleDownload {} }
Component { id: mdt; Metadata {} }
var singleDownloadObj = sdl.createObjec
"hash": hash,
"headers": headers // A QVariantMap of headers
});
var metadataObj = mdt.createObjec
singleDownl
singleDownl
What I get in the downloads.sql database is:
sqlite> select * from SingleDownload;
a634b6f8888
"app-id": "/usr/bin/
}
|{
}
This seems to happen because in qml/single_
SingleDownl
…
Metadata metadata;
QMap<QString, QString> headers;
DownloadStruct dstruct(url, m_hash, m_algorithm, metadata.map(), headers);
m_manager-
I.e. m_metadata and m_headers are ignored. Am I not supposed to call SingleDownload.
Secondly, even though the sqlite output from above have “app-id” set to “/usr/bin/
system-apps-ci-bot (system-apps-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:364
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
- 365. By Michael Sheldon
-
Invalidate internal download object when an error occurs as the remote end will have removed the download, and always keep a copy of metadata available for reading after an error or when a download has finished
system-apps-ci-bot (system-apps-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:365
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
Preview Diff
1 | === modified file 'src/common/public/ubuntu/transfers/metadata.cpp' |
2 | --- src/common/public/ubuntu/transfers/metadata.cpp 2015-12-10 20:39:48 +0000 |
3 | +++ src/common/public/ubuntu/transfers/metadata.cpp 2016-07-12 13:11:29 +0000 |
4 | @@ -18,7 +18,6 @@ |
5 | |
6 | #include <QProcessEnvironment> |
7 | #include <QCoreApplication> |
8 | -#include <QDebug> |
9 | |
10 | #include "metadata.h" |
11 | |
12 | @@ -35,6 +34,7 @@ |
13 | const QString Metadata::CLICK_PACKAGE_KEY = "click-package"; |
14 | const QString Metadata::DEFLATE_KEY = "deflate"; |
15 | const QString Metadata::EXTRACT_KEY = "extract"; |
16 | +const QString Metadata::CUSTOM_PREFIX = "custom_"; |
17 | const QString Metadata::APP_ID = "app-id"; |
18 | |
19 | namespace { |
20 | @@ -63,14 +63,14 @@ |
21 | } |
22 | } |
23 | |
24 | -QString |
25 | +QStringList |
26 | Metadata::command() const { |
27 | return (contains(Metadata::COMMAND_KEY))? |
28 | - value(Metadata::COMMAND_KEY).toString():""; |
29 | + value(Metadata::COMMAND_KEY).toStringList():QStringList(); |
30 | } |
31 | |
32 | void |
33 | -Metadata::setCommand(const QString& command) { |
34 | +Metadata::setCommand(const QStringList& command) { |
35 | insert(Metadata::COMMAND_KEY, command); |
36 | } |
37 | |
38 | @@ -207,6 +207,37 @@ |
39 | return contains(Metadata::APP_ID); |
40 | } |
41 | |
42 | +QVariantMap |
43 | +Metadata::custom() const { |
44 | + QVariantMap custom; |
45 | + foreach(QString key, keys()) { |
46 | + if (key.startsWith(CUSTOM_PREFIX)) { |
47 | + QString customKey = key; |
48 | + customKey.replace(CUSTOM_PREFIX, ""); |
49 | + custom.insert(customKey, values(key)[0]); |
50 | + } |
51 | + } |
52 | + return custom; |
53 | +} |
54 | + |
55 | +void |
56 | +Metadata::setCustom(QVariantMap custom) { |
57 | + // We can't send nested QVariantMaps over dbus, so flatten to one map |
58 | + foreach(QString key, custom.keys()) { |
59 | + insert(Metadata::CUSTOM_PREFIX + key, custom[key]); |
60 | + } |
61 | +} |
62 | + |
63 | +bool |
64 | +Metadata::hasCustom() const { |
65 | + foreach(QString key, keys()) { |
66 | + if (key.startsWith(CUSTOM_PREFIX)) { |
67 | + return true; |
68 | + } |
69 | + } |
70 | + return false; |
71 | +} |
72 | + |
73 | } // DownloadManager |
74 | |
75 | } // Ubuntu |
76 | |
77 | === modified file 'src/common/public/ubuntu/transfers/metadata.h' |
78 | --- src/common/public/ubuntu/transfers/metadata.h 2015-12-10 20:47:34 +0000 |
79 | +++ src/common/public/ubuntu/transfers/metadata.h 2016-07-12 13:11:29 +0000 |
80 | @@ -41,11 +41,12 @@ |
81 | static const QString CLICK_PACKAGE_KEY; |
82 | static const QString DEFLATE_KEY; |
83 | static const QString EXTRACT_KEY; |
84 | + static const QString CUSTOM_PREFIX; |
85 | static const QString APP_ID; |
86 | |
87 | // accessors to simplify the use of the metadata |
88 | - QString command() const; |
89 | - void setCommand(const QString& command); |
90 | + QStringList command() const; |
91 | + void setCommand(const QStringList& command); |
92 | bool hasCommand() const; |
93 | |
94 | QString localPath() const; |
95 | @@ -79,6 +80,10 @@ |
96 | QString destinationApp() const; |
97 | void setOwner(const QString &id); |
98 | bool hasOwner() const; |
99 | + |
100 | + QVariantMap custom() const; |
101 | + void setCustom(const QVariantMap custom); |
102 | + bool hasCustom() const; |
103 | }; |
104 | |
105 | } // DownloadManager |
106 | |
107 | === modified file 'src/downloads/qml/metadata.cpp' |
108 | --- src/downloads/qml/metadata.cpp 2016-03-16 16:03:39 +0000 |
109 | +++ src/downloads/qml/metadata.cpp 2016-07-12 13:11:29 +0000 |
110 | @@ -153,6 +153,31 @@ |
111 | } |
112 | } |
113 | |
114 | +QStringList |
115 | +Metadata::command() const { |
116 | + return _metadata.command(); |
117 | +} |
118 | + |
119 | +void |
120 | +Metadata::setCommand(QStringList command) { |
121 | + if (command != _metadata.command()) { |
122 | + _metadata.setCommand(command); |
123 | + emit commandChanged(); |
124 | + } |
125 | +} |
126 | + |
127 | +QVariantMap |
128 | +Metadata::custom() const { |
129 | + return _metadata.custom(); |
130 | +} |
131 | + |
132 | +void Metadata::setCustom(QVariantMap custom) { |
133 | + if (custom != _metadata.custom()) { |
134 | + _metadata.setCustom(custom); |
135 | + emit customChanged(); |
136 | + } |
137 | +} |
138 | + |
139 | QVariantMap |
140 | Metadata::map() const { |
141 | return QVariantMap(_metadata); |
142 | @@ -182,6 +207,20 @@ |
143 | to False. |
144 | */ |
145 | |
146 | +/*! |
147 | + \qmlproperty list Metadata::command |
148 | + \internal |
149 | + |
150 | + A command to run on the file immediately following completion of the |
151 | + download. |
152 | +*/ |
153 | + |
154 | +/*! |
155 | + \qmlproperty array Metadata::custom |
156 | + |
157 | + Metadata specific to your application that you wish to associate with |
158 | + this download. This metadata will persist across application restarts. |
159 | +*/ |
160 | } |
161 | |
162 | } |
163 | |
164 | === modified file 'src/downloads/qml/metadata.h' |
165 | --- src/downloads/qml/metadata.h 2014-10-09 09:52:34 +0000 |
166 | +++ src/downloads/qml/metadata.h 2016-07-12 13:11:29 +0000 |
167 | @@ -30,6 +30,8 @@ |
168 | Q_PROPERTY(bool showInIndicator READ showInIndicator WRITE setShowInIndicator NOTIFY showIndicatorChanged) |
169 | Q_PROPERTY(bool deflate READ deflate WRITE setDeflate NOTIFY deflateChanged) |
170 | Q_PROPERTY(bool extract READ extract WRITE setExtract NOTIFY extractChanged) |
171 | + Q_PROPERTY(QStringList command READ command WRITE setCommand NOTIFY commandChanged) |
172 | + Q_PROPERTY(QVariantMap custom READ custom WRITE setCustom NOTIFY customChanged) |
173 | |
174 | public: |
175 | explicit Metadata(QObject* parent=0); |
176 | @@ -47,6 +49,12 @@ |
177 | bool extract() const; |
178 | void setExtract(bool extract); |
179 | |
180 | + QStringList command() const; |
181 | + void setCommand(QStringList command); |
182 | + |
183 | + QVariantMap custom() const; |
184 | + void setCustom(QVariantMap custom); |
185 | + |
186 | QVariantMap map() const; |
187 | |
188 | signals: |
189 | @@ -54,6 +62,8 @@ |
190 | void showIndicatorChanged(); |
191 | void deflateChanged(); |
192 | void extractChanged(); |
193 | + void commandChanged(); |
194 | + void customChanged(); |
195 | |
196 | private: |
197 | Transfers::Metadata _metadata; |
198 | |
199 | === modified file 'src/downloads/qml/single_download.cpp' |
200 | --- src/downloads/qml/single_download.cpp 2016-03-17 16:32:25 +0000 |
201 | +++ src/downloads/qml/single_download.cpp 2016-07-12 13:11:29 +0000 |
202 | @@ -231,7 +231,7 @@ |
203 | } |
204 | Metadata metadata; |
205 | QMap<QString, QString> headers; |
206 | - DownloadStruct dstruct(url, metadata.map(), headers); |
207 | + DownloadStruct dstruct(url, m_hash, m_algorithm, metadata.map(), headers); |
208 | m_manager->createDownload(dstruct); |
209 | } else if (url.isEmpty()) { |
210 | m_error.setMessage("No URL specified"); |
211 | @@ -306,6 +306,7 @@ |
212 | SingleDownload::registerError(Error* error) |
213 | { |
214 | m_error.setMessage(error->errorString()); |
215 | + m_download = nullptr; |
216 | emit errorFound(m_error); |
217 | emit errorChanged(); |
218 | } |
219 | @@ -459,6 +460,16 @@ |
220 | } |
221 | } |
222 | |
223 | +QString |
224 | +SingleDownload::hash() const { |
225 | + return m_hash; |
226 | +} |
227 | + |
228 | +QString |
229 | +SingleDownload::algorithm() const { |
230 | + return m_algorithm; |
231 | +} |
232 | + |
233 | void |
234 | SingleDownload::setHeaders(QVariantMap headers) { |
235 | if (m_download == nullptr) { |
236 | @@ -504,9 +515,9 @@ |
237 | return; |
238 | } |
239 | |
240 | + m_metadata = metadata; |
241 | if (m_download == nullptr) { |
242 | m_dirty = true; |
243 | - m_metadata = metadata; |
244 | } else { |
245 | m_download->setMetadata(metadata->map()); |
246 | if (m_download->isError()) { |
247 | @@ -522,6 +533,16 @@ |
248 | } |
249 | } |
250 | |
251 | +void |
252 | +SingleDownload::setHash(QString hash) { |
253 | + m_hash = hash; |
254 | +} |
255 | + |
256 | +void |
257 | +SingleDownload::setAlgorithm(QString algorithm) { |
258 | + m_algorithm = algorithm; |
259 | +} |
260 | + |
261 | /*! |
262 | \qmlproperty bool SingleDownload::autoStart |
263 | |
264 | @@ -598,6 +619,32 @@ |
265 | */ |
266 | |
267 | /*! |
268 | + \qmlproperty string SingleDownload::hash |
269 | + \since Ubuntu.DownloadManager 1.3 |
270 | + |
271 | + This property specifies a hash to check against the downloaded file. |
272 | + If used, this should be set prior to calling the download() method. |
273 | +*/ |
274 | + |
275 | +/*! |
276 | + \qmlproperty string SingleDownload::algorithm |
277 | + \since Ubuntu.DownloadManager 1.3 |
278 | + |
279 | + This property indicates the algorithm to use when verifying a hash. |
280 | + The algorithm can be of one of the following string values: |
281 | + |
282 | + - "md5" |
283 | + - "sha1" |
284 | + - "sha224" |
285 | + - "sha256" |
286 | + - "sha384" |
287 | + - "sha512" |
288 | + |
289 | + If no value is specified md5 will be used. |
290 | + If used, this should be set prior to calling the download() method. |
291 | +*/ |
292 | + |
293 | +/*! |
294 | \qmlsignal SingleDownload::finished(QString path) |
295 | |
296 | This signal is emitted when a download has finished. The downloaded file |
297 | @@ -605,6 +652,5 @@ |
298 | \c onFinished |
299 | */ |
300 | |
301 | - |
302 | } |
303 | } |
304 | |
305 | === modified file 'src/downloads/qml/single_download.h' |
306 | --- src/downloads/qml/single_download.h 2015-10-23 16:09:48 +0000 |
307 | +++ src/downloads/qml/single_download.h 2016-07-12 13:11:29 +0000 |
308 | @@ -44,6 +44,8 @@ |
309 | Q_PROPERTY(QString downloadId READ downloadId NOTIFY downloadIdChanged) |
310 | Q_PROPERTY(QVariantMap headers READ headers WRITE setHeaders NOTIFY headersChanged) |
311 | Q_PROPERTY(Ubuntu::DownloadManager::Metadata* metadata READ metadata WRITE setMetadata NOTIFY metadataChanged) |
312 | + Q_PROPERTY(QString hash READ hash WRITE setHash NOTIFY hashChanged) |
313 | + Q_PROPERTY(QString algorithm READ algorithm WRITE setAlgorithm NOTIFY algorithmChanged) |
314 | |
315 | public: |
316 | explicit SingleDownload(QObject *parent = 0); |
317 | @@ -92,12 +94,16 @@ |
318 | QString downloadId() const; |
319 | QVariantMap headers() const; |
320 | Metadata* metadata() const; |
321 | + QString hash() const; |
322 | + QString algorithm() const; |
323 | |
324 | // setters |
325 | void setAllowMobileDownload(bool value); |
326 | void setThrottle(qulonglong value); |
327 | void setHeaders(QVariantMap headers); |
328 | void setMetadata(Metadata* metadata); |
329 | + void setHash(QString hash); |
330 | + void setAlgorithm(QString algorithm); |
331 | |
332 | // only property that does not access the download obj |
333 | void setAutoStart(bool value) { |
334 | @@ -127,6 +133,8 @@ |
335 | void started(bool success); |
336 | void errorFound(DownloadError& error); |
337 | void errorChanged(); |
338 | + void hashChanged(); |
339 | + void algorithmChanged(); |
340 | |
341 | public slots: |
342 | void registerError(Error* error); |
343 | @@ -172,6 +180,8 @@ |
344 | Download* m_download = nullptr; |
345 | Manager* m_manager = nullptr; |
346 | QString m_downloadId; |
347 | + QString m_hash; |
348 | + QString m_algorithm; |
349 | |
350 | }; |
351 | |
352 | |
353 | === modified file 'tests/downloads/daemon/test_metadata.cpp' |
354 | --- tests/downloads/daemon/test_metadata.cpp 2015-09-21 08:24:55 +0000 |
355 | +++ tests/downloads/daemon/test_metadata.cpp 2016-07-12 13:11:29 +0000 |
356 | @@ -19,23 +19,24 @@ |
357 | #include <stdlib.h> |
358 | |
359 | #include <QProcessEnvironment> |
360 | +#include <QStringList> |
361 | |
362 | #include "test_metadata.h" |
363 | |
364 | using namespace Ubuntu::Transfers; |
365 | |
366 | void |
367 | -TestMetadata::testCommnad_data() { |
368 | - QTest::addColumn<QString>("command"); |
369 | +TestMetadata::testCommand_data() { |
370 | + QTest::addColumn<QStringList>("command"); |
371 | |
372 | - QTest::newRow("mkdir") << "mkdir test"; |
373 | - QTest::newRow("cd") << "cd test"; |
374 | - QTest::newRow("ls") << "ls -la"; |
375 | + QTest::newRow("mkdir") << (QStringList() << "mkdir" << "test"); |
376 | + QTest::newRow("cd") << (QStringList() << "cd" << "test"); |
377 | + QTest::newRow("ls") << (QStringList() << "ls" << "-la"); |
378 | } |
379 | |
380 | void |
381 | -TestMetadata::testCommnad() { |
382 | - QFETCH(QString, command); |
383 | +TestMetadata::testCommand() { |
384 | + QFETCH(QStringList, command); |
385 | |
386 | Metadata metadata; |
387 | metadata[Metadata::COMMAND_KEY] = command; |
388 | @@ -43,33 +44,33 @@ |
389 | } |
390 | |
391 | void |
392 | -TestMetadata::testSetCommnad_data() { |
393 | - QTest::addColumn<QString>("command"); |
394 | +TestMetadata::testSetCommand_data() { |
395 | + QTest::addColumn<QStringList>("command"); |
396 | |
397 | - QTest::newRow("mkdir") << "mkdir test"; |
398 | - QTest::newRow("cd") << "cd test"; |
399 | - QTest::newRow("ls") << "ls -la"; |
400 | + QTest::newRow("mkdir") << (QStringList() << "mkdir" << "test"); |
401 | + QTest::newRow("cd") << (QStringList() << "cd" << "test"); |
402 | + QTest::newRow("ls") << (QStringList() << "ls" << "-la"); |
403 | } |
404 | |
405 | void |
406 | -TestMetadata::testSetCommnad() { |
407 | - QFETCH(QString, command); |
408 | +TestMetadata::testSetCommand() { |
409 | + QFETCH(QStringList, command); |
410 | |
411 | Metadata metadata; |
412 | metadata.setCommand(command); |
413 | - QCOMPARE(metadata[Metadata::COMMAND_KEY].toString(), command); |
414 | + QCOMPARE(metadata[Metadata::COMMAND_KEY].toStringList(), command); |
415 | } |
416 | |
417 | void |
418 | -TestMetadata::testHasCommnadTrue() { |
419 | +TestMetadata::testHasCommandTrue() { |
420 | Metadata metadata; |
421 | - metadata.setCommand("command"); |
422 | + metadata.setCommand(QStringList("command")); |
423 | |
424 | QVERIFY(metadata.hasCommand()); |
425 | } |
426 | |
427 | void |
428 | -TestMetadata::testHasCommnadFalse() { |
429 | +TestMetadata::testHasCommandFalse() { |
430 | Metadata metadata; |
431 | QVERIFY(!metadata.hasCommand()); |
432 | } |
433 | @@ -438,5 +439,45 @@ |
434 | QCOMPARE(metadata.destinationApp(), appid); |
435 | } |
436 | |
437 | +void |
438 | +TestMetadata::testCustom_data() { |
439 | + QTest::addColumn<QVariantMap>("custom"); |
440 | + |
441 | + QVariantMap first; |
442 | + QVariantMap second; |
443 | + first.insert("test1", "Test"); |
444 | + second.insert("test2", "Testing"); |
445 | + second.insert("test3", "Further testing"); |
446 | + |
447 | + QTest::newRow("first") << first; |
448 | + QTest::newRow("second") << second; |
449 | +} |
450 | + |
451 | +void |
452 | +TestMetadata::testCustom() { |
453 | + QFETCH(QVariantMap, custom); |
454 | + |
455 | + Metadata metadata; |
456 | + metadata.setCustom(custom); |
457 | + QCOMPARE(custom, metadata.custom()); |
458 | +} |
459 | + |
460 | +void |
461 | +TestMetadata::testHasCustomTrue() { |
462 | + Metadata metadata; |
463 | + QVariantMap custom; |
464 | + custom.insert("test1", "Test"); |
465 | + custom.insert("test2", "Test"); |
466 | + metadata.setCustom(custom); |
467 | + |
468 | + QVERIFY(metadata.hasCustom()); |
469 | +} |
470 | + |
471 | +void |
472 | +TestMetadata::testHasCustomFalse() { |
473 | + Metadata metadata; |
474 | + QVERIFY(!metadata.hasCustom()); |
475 | +} |
476 | + |
477 | QTEST_MAIN(TestMetadata) |
478 | #include "moc_test_metadata.cpp" |
479 | |
480 | === modified file 'tests/downloads/daemon/test_metadata.h' |
481 | --- tests/downloads/daemon/test_metadata.h 2015-12-10 20:47:34 +0000 |
482 | +++ tests/downloads/daemon/test_metadata.h 2016-07-12 13:11:29 +0000 |
483 | @@ -31,12 +31,12 @@ |
484 | : BaseTestCase("TestMetadata", parent) { } |
485 | |
486 | private slots: // NOLINT(whitespace/indent) |
487 | - void testCommnad_data(); |
488 | - void testCommnad(); |
489 | - void testSetCommnad_data(); |
490 | - void testSetCommnad(); |
491 | - void testHasCommnadTrue(); |
492 | - void testHasCommnadFalse(); |
493 | + void testCommand_data(); |
494 | + void testCommand(); |
495 | + void testSetCommand_data(); |
496 | + void testSetCommand(); |
497 | + void testHasCommandTrue(); |
498 | + void testHasCommandFalse(); |
499 | void testLocalPath_data(); |
500 | void testLocalPath(); |
501 | void testSetLocalPath_data(); |
502 | @@ -80,6 +80,10 @@ |
503 | void testDestinationAppIsPickedFromEnv_data(); |
504 | void testDestinationAppIsPickedFromEnv(); |
505 | void testDestinationAppIsAlreadyPresent(); |
506 | + void testCustom_data(); |
507 | + void testCustom(); |
508 | + void testHasCustomTrue(); |
509 | + void testHasCustomFalse(); |
510 | }; |
511 | |
512 | #endif |
513 | |
514 | === modified file 'tests/downloads/qml/test_metadata.cpp' |
515 | --- tests/downloads/qml/test_metadata.cpp 2014-09-18 13:22:31 +0000 |
516 | +++ tests/downloads/qml/test_metadata.cpp 2016-07-12 13:11:29 +0000 |
517 | @@ -70,5 +70,56 @@ |
518 | QCOMPARE(metadata->showInIndicator(), show); |
519 | } |
520 | |
521 | +void |
522 | +TestMetadata::testGetCommandEmpty() { |
523 | + QScopedPointer<Metadata> metadata(new Metadata()); |
524 | + QVERIFY(metadata->command()); |
525 | +} |
526 | + |
527 | +void |
528 | +TestMetadata::testGetCommandPresent_data() { |
529 | + QTest::addColumn<QStringList>("command"); |
530 | + |
531 | + QTest::newRow("First") << QStringList("/bin/ls", "/tmp/"); |
532 | + QTest::newRow("Second") << QStringList("/bin/true"); |
533 | +} |
534 | + |
535 | +void |
536 | +TestMetadata::testGetCommandPresent() { |
537 | + QFETCH(QStringList, command); |
538 | + QScopedPointer<Metadata> metadata(new Metadata()); |
539 | + metadata->setCommand(command); |
540 | + QCOMPARE(metadata->command(), command); |
541 | +} |
542 | + |
543 | +void |
544 | +TestMetadata::testGetCustomEmpty() { |
545 | + QScopedPointer<Metadata> metadata(new Metadata()); |
546 | + QVERIFY(metadata->custom()); |
547 | +} |
548 | + |
549 | +void |
550 | +TestMetadata::testGetCustomPresent_data() { |
551 | + QTest::addColumn<QVariantMap>("custom"); |
552 | + |
553 | + QVariantMap first; |
554 | + QVariantMap second; |
555 | + |
556 | + first.insert("test1", "Testing"); |
557 | + first.insert("test2", "Testing2"); |
558 | + second.insert("test", "Test"); |
559 | + |
560 | + QTest::newRow("First") << first; |
561 | + QTest::newRow("Second") << second; |
562 | +} |
563 | + |
564 | +void |
565 | +TestMetadata::testGetCustomPresent() { |
566 | + QFETCH(QVariantMap, custom); |
567 | + QScopedPointer<Metadata> metadata(new Metadata()); |
568 | + metadata->setCustom(custom); |
569 | + QCOMPARE(metadata->custom(), custom); |
570 | +} |
571 | + |
572 | QTEST_MAIN(TestMetadata) |
573 | #include "moc_test_metadata.cpp" |
574 | |
575 | === modified file 'tests/downloads/qml/test_metadata.h' |
576 | --- tests/downloads/qml/test_metadata.h 2014-09-18 13:22:31 +0000 |
577 | +++ tests/downloads/qml/test_metadata.h 2016-07-12 13:11:29 +0000 |
578 | @@ -35,6 +35,12 @@ |
579 | void testGetShowInIndicatorEmpty(); |
580 | void testGetShowInIndicatorPresent_data(); |
581 | void testGetShowInIndicatorPresent(); |
582 | + void testGetCommandEmpty(); |
583 | + void testGetCommandPresent_data(); |
584 | + void testGetCommandPresent(); |
585 | + void testGetCustomEmpty(); |
586 | + void testGetCustomPresent_data(); |
587 | + void testGetCustomPresent(); |
588 | }; |
589 | |
590 | #endif |
591 | |
592 | === modified file 'tests/downloads/qml/test_single_download.cpp' |
593 | --- tests/downloads/qml/test_single_download.cpp 2014-09-18 13:22:31 +0000 |
594 | +++ tests/downloads/qml/test_single_download.cpp 2016-07-12 13:11:29 +0000 |
595 | @@ -429,5 +429,127 @@ |
596 | verifyMocks(); |
597 | } |
598 | |
599 | +void |
600 | +TestSingleDownload::testSetHashNullptr() { |
601 | + QScopedPointer<TestableSingleDownload> singleDownload( |
602 | + new TestableSingleDownload(nullptr, _man)); |
603 | + |
604 | + singleDownload->setHash("c4e5f7fcbcef75924b2abde2b2e75f3f"); |
605 | + // ensure that the mocks are not called and we do not crash |
606 | + verifyMocks(); |
607 | +} |
608 | + |
609 | +void |
610 | +TestSingleDownload::testSetHashError() { |
611 | + QScopedPointer<MockError> err(new MockError(Error::DBus)); |
612 | + QScopedPointer<TestableSingleDownload> singleDownload( |
613 | + new TestableSingleDownload(_down, _man)); |
614 | + |
615 | + EXPECT_CALL(*_down, setHash("c4e5f7fcbcef75924b2abde2b2e75f3f")) |
616 | + .Times(1); |
617 | + |
618 | + EXPECT_CALL(*_down, isError()) |
619 | + .Times(1) |
620 | + .WillOnce(Return(true)); |
621 | + |
622 | + EXPECT_CALL(*_down, error()) |
623 | + .Times(1) |
624 | + .WillOnce(Return(err.data())); |
625 | + |
626 | + EXPECT_CALL(*err.data(), errorString()) |
627 | + .Times(1) |
628 | + .WillOnce(Return(QString("My error"))); |
629 | + |
630 | + // ensure that the diff signals are emitted |
631 | + SignalBarrier spy(singleDownload.data(), SIGNAL(errorChanged())); |
632 | + |
633 | + singleDownload->setHash("c4e5f7fcbcef75924b2abde2b2e75f3f"); |
634 | + |
635 | + QVERIFY(spy.ensureSignalEmitted()); |
636 | + verifyMocks(); |
637 | +} |
638 | + |
639 | +void |
640 | +TestSingleDownload::testSetHashSuccess() { |
641 | + QScopedPointer<TestableSingleDownload> singleDownload( |
642 | + new TestableSingleDownload(_down, _man)); |
643 | + |
644 | + EXPECT_CALL(*_down, setHash("c4e5f7fcbcef75924b2abde2b2e75f3f")) |
645 | + .Times(1); |
646 | + |
647 | + EXPECT_CALL(*_down, isError()) |
648 | + .Times(1) |
649 | + .WillOnce(Return(false)); |
650 | + |
651 | + // ensure that the diff signals are emitted |
652 | + SignalBarrier spy(singleDownload.data(), SIGNAL(hashChanged())); |
653 | + |
654 | + singleDownload->setHash("c4e5f7fcbcef75924b2abde2b2e75f3f"); |
655 | + |
656 | + QVERIFY(spy.ensureSignalEmitted()); |
657 | + verifyMocks(); |
658 | +} |
659 | + |
660 | +void |
661 | +TestSingleDownload::testSetAlgorithmNullptr() { |
662 | + QScopedPointer<TestableSingleDownload> singleDownload( |
663 | + new TestableSingleDownload(nullptr, _man)); |
664 | + |
665 | + singleDownload->setAlgorithm("sha1"); |
666 | + // ensure that the mocks are not called and we do not crash |
667 | + verifyMocks(); |
668 | +} |
669 | + |
670 | +void |
671 | +TestSingleDownload::testSetAlgorithmError() { |
672 | + QScopedPointer<MockError> err(new MockError(Error::DBus)); |
673 | + QScopedPointer<TestableSingleDownload> singleDownload( |
674 | + new TestableSingleDownload(_down, _man)); |
675 | + |
676 | + EXPECT_CALL(*_down, setAlgorithm("sha1")) |
677 | + .Times(1); |
678 | + |
679 | + EXPECT_CALL(*_down, isError()) |
680 | + .Times(1) |
681 | + .WillOnce(Return(true)); |
682 | + |
683 | + EXPECT_CALL(*_down, error()) |
684 | + .Times(1) |
685 | + .WillOnce(Return(err.data())); |
686 | + |
687 | + EXPECT_CALL(*err.data(), errorString()) |
688 | + .Times(1) |
689 | + .WillOnce(Return(QString("My error"))); |
690 | + |
691 | + // ensure that the diff signals are emitted |
692 | + SignalBarrier spy(singleDownload.data(), SIGNAL(errorChanged())); |
693 | + |
694 | + singleDownload->setAlgorithm("sha1"); |
695 | + |
696 | + QVERIFY(spy.ensureSignalEmitted()); |
697 | + verifyMocks(); |
698 | +} |
699 | + |
700 | +void |
701 | +TestSingleDownload::testSetAlgorithmSuccess() { |
702 | + QScopedPointer<TestableSingleDownload> singleDownload( |
703 | + new TestableSingleDownload(_down, _man)); |
704 | + |
705 | + EXPECT_CALL(*_down, setAlgorithm("sha1")) |
706 | + .Times(1); |
707 | + |
708 | + EXPECT_CALL(*_down, isError()) |
709 | + .Times(1) |
710 | + .WillOnce(Return(false)); |
711 | + |
712 | + // ensure that the diff signals are emitted |
713 | + SignalBarrier spy(singleDownload.data(), SIGNAL(algorithmChanged())); |
714 | + |
715 | + singleDownload->setAlgorithm("sha1"); |
716 | + |
717 | + QVERIFY(spy.ensureSignalEmitted()); |
718 | + verifyMocks(); |
719 | +} |
720 | + |
721 | QTEST_MAIN(TestSingleDownload) |
722 | #include "moc_test_single_download.cpp" |
723 | |
724 | === modified file 'tests/downloads/qml/test_single_download.h' |
725 | --- tests/downloads/qml/test_single_download.h 2014-09-18 13:22:31 +0000 |
726 | +++ tests/downloads/qml/test_single_download.h 2016-07-12 13:11:29 +0000 |
727 | @@ -78,6 +78,12 @@ |
728 | void testSetMetadataToNullptr(); |
729 | void testSetMetadataError(); |
730 | void testSetMetadataSuccess(); |
731 | + void testSetHashNullptr(); |
732 | + void testSetHashError(); |
733 | + void testSetHashSuccess(); |
734 | + void testSetAlgorithmNullptr(); |
735 | + void testSetAlgorithmError(); |
736 | + void testSetAlgorithmSuccess(); |
737 | |
738 | private: |
739 | void verifyMocks(); |
FAILED: Continuous integration, rev:362 jenkins. qa.ubuntu. com/job/ ubuntu- download- manager- ci/803/ jenkins. qa.ubuntu. com/job/ ubuntu- download- manager- wily-amd64- ci/34/console jenkins. qa.ubuntu. com/job/ ubuntu- download- manager- wily-armhf- ci/33/console
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/ubuntu- download- manager- ci/803/ rebuild
http://