Merge lp:~mandel/ubuntu-download-manager/execute-post-download into lp:ubuntu-download-manager
- execute-post-download
- Merge into trunk
Proposed by
Manuel de la Peña
Status: | Merged | ||||||||
---|---|---|---|---|---|---|---|---|---|
Merged at revision: | 81 | ||||||||
Proposed branch: | lp:~mandel/ubuntu-download-manager/execute-post-download | ||||||||
Merge into: | lp:ubuntu-download-manager | ||||||||
Diff against target: |
1620 lines (+834/-89) 23 files modified
libubuntudownloadmanager/download.cpp (+103/-21) libubuntudownloadmanager/download.h (+9/-2) libubuntudownloadmanager/download_manager.cpp (+5/-2) libubuntudownloadmanager/libubuntudownloadmanager.pro (+5/-1) libubuntudownloadmanager/process.cpp (+95/-0) libubuntudownloadmanager/process.h (+49/-0) libubuntudownloadmanager/process_factory.cpp (+63/-0) libubuntudownloadmanager/process_factory.h (+41/-0) ubuntu-download-manager-tests/fake.cpp (+21/-0) ubuntu-download-manager-tests/fake.h (+15/-0) ubuntu-download-manager-tests/fake_download.cpp (+5/-4) ubuntu-download-manager-tests/fake_download.h (+3/-2) ubuntu-download-manager-tests/fake_network_reply.cpp (+5/-0) ubuntu-download-manager-tests/fake_network_reply.h (+1/-0) ubuntu-download-manager-tests/fake_process.cpp (+57/-0) ubuntu-download-manager-tests/fake_process.h (+50/-0) ubuntu-download-manager-tests/fake_process_factory.cpp (+48/-0) ubuntu-download-manager-tests/fake_process_factory.h (+36/-0) ubuntu-download-manager-tests/test_download.cpp (+200/-33) ubuntu-download-manager-tests/test_download.h (+10/-0) ubuntu-download-manager-tests/test_download_queue.cpp (+5/-22) ubuntu-download-manager-tests/test_download_queue.h (+2/-0) ubuntu-download-manager-tests/ubuntu-download-manager-tests.pro (+6/-2) |
||||||||
To merge this branch: | bzr merge lp:~mandel/ubuntu-download-manager/execute-post-download | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Manuel de la Peña (community) | Approve | ||
Alejandro J. Cura (community) | Approve | ||
PS Jenkins bot | continuous-integration | Needs Fixing | |
Review via email: mp+176072@code.launchpad.net |
Commit message
Allow process execution after download.
Fix broken tests.
Description of the change
Allow process execution after download.
Fix broken tests.
To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : | # |
review:
Needs Fixing
(continuous-integration)
Revision history for this message
Manuel de la Peña (mandel) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'libubuntudownloadmanager/download.cpp' |
2 | --- libubuntudownloadmanager/download.cpp 2013-07-20 18:26:02 +0000 |
3 | +++ libubuntudownloadmanager/download.cpp 2013-07-21 19:10:31 +0000 |
4 | @@ -41,6 +41,8 @@ |
5 | #define ALGO "algo" |
6 | #define DATA_FILE_NAME "data" |
7 | #define METADATA_FILE_NAME "metadata" |
8 | +#define METADATA_COMMAND_KEY "post-download-command" |
9 | +#define METADATA_COMMAND_FILE_KEY "$file" |
10 | |
11 | |
12 | /** |
13 | @@ -52,10 +54,11 @@ |
14 | Q_DECLARE_PUBLIC(Download) |
15 | public: |
16 | explicit DownloadPrivate(const QUuid& id, const QString& path, const QUrl& url, const QVariantMap& metadata, |
17 | - const QMap<QString, QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, Download* parent); |
18 | + const QMap<QString, QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, ProcessFactory* processFactory, |
19 | + Download* parent); |
20 | explicit DownloadPrivate(const QUuid& id, const QString& path, const QUrl& url, const QString& hash, |
21 | QCryptographicHash::Algorithm algo, const QVariantMap& metadata, const QMap<QString, QString>& headers, |
22 | - SystemNetworkInfo* networkInfo, RequestFactory* nam, |
23 | + SystemNetworkInfo* networkInfo, RequestFactory* nam, ProcessFactory* processFactory, |
24 | Download* parent); |
25 | ~DownloadPrivate(); |
26 | |
27 | @@ -97,6 +100,10 @@ |
28 | void onFinished(); |
29 | void onSslErrors(const QList<QSslError>& errors); |
30 | |
31 | + // slots executed to keep track of the post download process |
32 | + void onProcessError(QProcess::ProcessError error); |
33 | + void onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus); |
34 | + |
35 | private: |
36 | void init(); |
37 | void connectToReplySignals(); |
38 | @@ -123,6 +130,7 @@ |
39 | QMap<QString, QString> _headers; |
40 | SystemNetworkInfo* _networkInfo; |
41 | RequestFactory* _requestFactory; |
42 | + ProcessFactory* _processFactory; |
43 | NetworkReply* _reply; |
44 | QFile* _currentData; |
45 | Download* q_ptr; |
46 | @@ -130,7 +138,8 @@ |
47 | }; |
48 | |
49 | DownloadPrivate::DownloadPrivate(const QUuid& id, const QString& path, const QUrl& url, const QVariantMap& metadata, |
50 | - const QMap<QString, QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, Download* parent): |
51 | + const QMap<QString, QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, ProcessFactory* processFactory, |
52 | + Download* parent): |
53 | _id(id), |
54 | _totalSize(0), |
55 | _throttle(0), |
56 | @@ -144,6 +153,7 @@ |
57 | _headers(headers), |
58 | _networkInfo(networkInfo), |
59 | _requestFactory(nam), |
60 | + _processFactory(processFactory), |
61 | q_ptr(parent) |
62 | { |
63 | init(); |
64 | @@ -151,7 +161,7 @@ |
65 | |
66 | DownloadPrivate::DownloadPrivate(const QUuid& id, const QString& path, const QUrl& url, const QString& hash, |
67 | QCryptographicHash::Algorithm algo, const QVariantMap& metadata, const QMap<QString, QString>& headers, |
68 | - SystemNetworkInfo* networkInfo, RequestFactory* nam, Download* parent): |
69 | + SystemNetworkInfo* networkInfo, RequestFactory* nam, ProcessFactory* processFactory, Download* parent): |
70 | _id(id), |
71 | _totalSize(0), |
72 | _throttle(0), |
73 | @@ -165,6 +175,7 @@ |
74 | _headers(headers), |
75 | _networkInfo(networkInfo), |
76 | _requestFactory(nam), |
77 | + _processFactory(processFactory), |
78 | q_ptr(parent) |
79 | { |
80 | init(); |
81 | @@ -496,7 +507,6 @@ |
82 | |
83 | qDebug() << "Starting download."; |
84 | // create file that will be used to mantain the state of the download when resumed. |
85 | - // TODO: Use a better name |
86 | _currentData = new QFile(saveFileName()); |
87 | _currentData->open(QIODevice::ReadWrite | QFile::Append); |
88 | |
89 | @@ -655,23 +665,94 @@ |
90 | return; |
91 | } |
92 | } |
93 | + |
94 | + // there are two possible cases, the first, we do no have the metadata info to execute a |
95 | + // commnad once the download was finished and that means we are done here else we execute the |
96 | + // command AND raise the finish signals once the command was done (or an error ocurred in the |
97 | + // command execution. |
98 | + if (_metadata.contains(METADATA_COMMAND_KEY)) |
99 | + { |
100 | + // toStringList will return an empty list if it cannot be converted |
101 | + QStringList commandData = _metadata[METADATA_COMMAND_KEY].toStringList(); |
102 | + if (commandData.count() == 0) |
103 | + { |
104 | + // raise error, command metadata was passed without the commnad |
105 | + qCritical() << "COMMAND DATA MISSING"; |
106 | + _state = Download::FINISHED; |
107 | + emit q->stateChanged(); |
108 | + emit q->error("COMMAND ERROR"); |
109 | + return; |
110 | + } |
111 | + else |
112 | + { |
113 | + // first item of the string list is the commnad, rest is the arguments |
114 | + QString command = commandData.at(0); |
115 | + commandData.removeAt(0); |
116 | + QStringList args; |
117 | + |
118 | + foreach(const QString& arg, commandData) |
119 | + { |
120 | + if (arg == METADATA_COMMAND_FILE_KEY) |
121 | + args << filePath(); |
122 | + else |
123 | + args << arg; |
124 | + } |
125 | + |
126 | + Process* postDownloadProcess = _processFactory->createProcess(); |
127 | + |
128 | + // connect to signals so that we can tell the clients that the operation succeed |
129 | + |
130 | + q->connect(postDownloadProcess, SIGNAL(finished(int, QProcess::ExitStatus)), |
131 | + q, SLOT(onProcessFinished(int, QProcess::ExitStatus))); |
132 | + q->connect(postDownloadProcess, SIGNAL(error(QProcess::ProcessError)), |
133 | + q, SLOT(onProcessError(QProcess::ProcessError))); |
134 | + |
135 | + qDebug() << "Executing" << command << args; |
136 | + postDownloadProcess->start(command, args); |
137 | + return; |
138 | + } |
139 | + } |
140 | + else |
141 | + { |
142 | + _state = Download::FINISHED; |
143 | + qDebug() << "EMIT stateChanged"; |
144 | + emit q->stateChanged(); |
145 | + qDebug() << "EMIT finished" << filePath(); |
146 | + emit q->finished(filePath()); |
147 | + } |
148 | + |
149 | + // clean the reply |
150 | + _reply->deleteLater(); |
151 | + _reply = NULL; |
152 | +} |
153 | + |
154 | +void DownloadPrivate::onSslErrors(const QList<QSslError>& errors) |
155 | +{ |
156 | + qDebug() << __FUNCTION__ << _url; |
157 | + // TODO: emit ssl errors signal? |
158 | + Q_UNUSED(errors); |
159 | + Q_Q(Download); |
160 | + emit q->error("SSL ERROR"); |
161 | +} |
162 | + |
163 | +void DownloadPrivate::onProcessError(QProcess::ProcessError error) |
164 | +{ |
165 | + // TODO: better error fowarding |
166 | + Q_UNUSED(error); |
167 | + Q_Q(Download); |
168 | + emit q->error("COMMAND ERROR"); |
169 | +} |
170 | + |
171 | +void DownloadPrivate::onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) |
172 | +{ |
173 | + qDebug() << __FUNCTION__ << exitCode << exitStatus; |
174 | + // TODO: send the command exit code and status |
175 | + Q_Q(Download); |
176 | _state = Download::FINISHED; |
177 | qDebug() << "EMIT stateChanged"; |
178 | emit q->stateChanged(); |
179 | qDebug() << "EMIT finished" << filePath(); |
180 | emit q->finished(filePath()); |
181 | - _reply->deleteLater(); |
182 | - _reply = NULL; |
183 | - |
184 | -} |
185 | - |
186 | -void DownloadPrivate::onSslErrors(const QList<QSslError>& errors) |
187 | -{ |
188 | - qDebug() << __FUNCTION__ << _url; |
189 | - // TODO: emit ssl errors signal? |
190 | - Q_UNUSED(errors); |
191 | - Q_Q(Download); |
192 | - emit q->error("SSL ERROR"); |
193 | } |
194 | |
195 | /** |
196 | @@ -679,16 +760,17 @@ |
197 | */ |
198 | |
199 | Download::Download(const QUuid& id, const QString& path, const QUrl& url, const QVariantMap& metadata, |
200 | - const QMap<QString, QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, QObject* parent): |
201 | + const QMap<QString, QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, ProcessFactory* processFactory, QObject* parent): |
202 | QObject(parent), |
203 | - d_ptr(new DownloadPrivate(id, path, url, metadata, headers, networkInfo, nam, this)) |
204 | + d_ptr(new DownloadPrivate(id, path, url, metadata, headers, networkInfo, nam, processFactory, this)) |
205 | { |
206 | } |
207 | |
208 | Download::Download(const QUuid& id, const QString& path, const QUrl& url, const QString& hash, QCryptographicHash::Algorithm algo, |
209 | - const QVariantMap& metadata, const QMap<QString, QString> &headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, QObject* parent): |
210 | + const QVariantMap& metadata, const QMap<QString, QString> &headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, |
211 | + ProcessFactory* processFactory, QObject* parent): |
212 | QObject(parent), |
213 | - d_ptr(new DownloadPrivate(id, path, url, hash, algo, metadata, headers, networkInfo, nam, this)) |
214 | + d_ptr(new DownloadPrivate(id, path, url, hash, algo, metadata, headers, networkInfo, nam, processFactory, this)) |
215 | { |
216 | } |
217 | |
218 | |
219 | === modified file 'libubuntudownloadmanager/download.h' |
220 | --- libubuntudownloadmanager/download.h 2013-07-20 18:26:02 +0000 |
221 | +++ libubuntudownloadmanager/download.h 2013-07-21 19:10:31 +0000 |
222 | @@ -24,9 +24,11 @@ |
223 | #include <QBuffer> |
224 | #include <QCryptographicHash> |
225 | #include <QNetworkReply> |
226 | +#include <QProcess> |
227 | #include <QUrl> |
228 | #include <QUuid> |
229 | #include "system_network_info.h" |
230 | +#include "process_factory.h" |
231 | #include "request_factory.h" |
232 | #include "app-downloader-lib_global.h" |
233 | |
234 | @@ -48,10 +50,10 @@ |
235 | }; |
236 | |
237 | explicit Download(const QUuid& id, const QString& path, const QUrl& url, const QVariantMap& metadata, |
238 | - const QMap<QString, QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, QObject* parent=0); |
239 | + const QMap<QString, QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, ProcessFactory* processFactory, QObject* parent=0); |
240 | explicit Download(const QUuid& id, const QString& path, const QUrl& url, const QString& hash, QCryptographicHash::Algorithm algo, |
241 | const QVariantMap& metadata, const QMap<QString, QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, |
242 | - QObject* parent=0); |
243 | + ProcessFactory* processFactory, QObject* parent=0); |
244 | |
245 | // gets for internal state |
246 | QUuid downloadId(); |
247 | @@ -110,6 +112,11 @@ |
248 | Q_PRIVATE_SLOT(d_func(), void onFinished()) |
249 | Q_PRIVATE_SLOT(d_func(), void onSslErrors(const QList<QSslError>&)) |
250 | |
251 | + // private slots used to keep track of the post download command |
252 | + |
253 | + Q_PRIVATE_SLOT(d_func(), void onProcessError(QProcess::ProcessError error)) |
254 | + Q_PRIVATE_SLOT(d_func(), void onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)) |
255 | + |
256 | private: |
257 | // use pimpl so that we can mantains ABI compatibility |
258 | DownloadPrivate* d_ptr; |
259 | |
260 | === modified file 'libubuntudownloadmanager/download_manager.cpp' |
261 | --- libubuntudownloadmanager/download_manager.cpp 2013-07-20 18:26:02 +0000 |
262 | +++ libubuntudownloadmanager/download_manager.cpp 2013-07-21 19:10:31 +0000 |
263 | @@ -18,6 +18,7 @@ |
264 | |
265 | #include <QRegExp> |
266 | #include "request_factory.h" |
267 | +#include "process_factory.h" |
268 | #include "download_adaptor.h" |
269 | #include "download_queue.h" |
270 | #include "download_manager.h" |
271 | @@ -58,6 +59,7 @@ |
272 | DownloadQueue* _downloadsQueue; |
273 | DBusConnection* _conn; |
274 | RequestFactory* _reqFactory; |
275 | + ProcessFactory* _processFactory; |
276 | UuidFactory* _uuidFactory; |
277 | DownloadManager* q_ptr; |
278 | }; |
279 | @@ -98,6 +100,7 @@ |
280 | q, SLOT(onDownloadRemoved(QString))); |
281 | |
282 | _reqFactory = new RequestFactory(); |
283 | + _processFactory = new ProcessFactory(); |
284 | } |
285 | |
286 | void DownloadManagerPrivate::addDownload(Download* download) |
287 | @@ -141,9 +144,9 @@ |
288 | { |
289 | Download* download; |
290 | if (hash.isEmpty()) |
291 | - download = new Download(id, path, url, metadata, headers, _networkInfo, _reqFactory); |
292 | + download = new Download(id, path, url, metadata, headers, _networkInfo, _reqFactory, _processFactory); |
293 | else |
294 | - download = new Download(id, path, url, hash, algo, metadata, headers, _networkInfo, _reqFactory); |
295 | + download = new Download(id, path, url, hash, algo, metadata, headers, _networkInfo, _reqFactory, _processFactory); |
296 | |
297 | download->setThrottle(_throttle); |
298 | DownloadAdaptor* adaptor = new DownloadAdaptor(download); |
299 | |
300 | === modified file 'libubuntudownloadmanager/libubuntudownloadmanager.pro' |
301 | --- libubuntudownloadmanager/libubuntudownloadmanager.pro 2013-07-20 14:08:52 +0000 |
302 | +++ libubuntudownloadmanager/libubuntudownloadmanager.pro 2013-07-21 19:10:31 +0000 |
303 | @@ -19,7 +19,9 @@ |
304 | request_factory.cpp \ |
305 | system_network_info.cpp \ |
306 | uuid_factory.cpp \ |
307 | - xdg_basedir.cpp |
308 | + xdg_basedir.cpp \ |
309 | + process.cpp \ |
310 | + process_factory.cpp |
311 | |
312 | HEADERS +=\ |
313 | app-downloader-lib_global.h \ |
314 | @@ -35,6 +37,8 @@ |
315 | system_network_info.h \ |
316 | uuid_factory.h \ |
317 | xdg_basedir.h \ |
318 | + process.h \ |
319 | + process_factory.h \ |
320 | metatypes.h |
321 | |
322 | OTHER_FILES += \ |
323 | |
324 | === added file 'libubuntudownloadmanager/process.cpp' |
325 | --- libubuntudownloadmanager/process.cpp 1970-01-01 00:00:00 +0000 |
326 | +++ libubuntudownloadmanager/process.cpp 2013-07-21 19:10:31 +0000 |
327 | @@ -0,0 +1,95 @@ |
328 | +/* |
329 | + * Copyright 2013 2013 Canonical Ltd. |
330 | + * |
331 | + * This library is free software; you can redistribute it and/or |
332 | + * modify it under the terms of version 3 of the GNU Lesser General Public |
333 | + * License as published by the Free Software Foundation. |
334 | + * |
335 | + * This program is distributed in the hope that it will be useful, |
336 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
337 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
338 | + * General Public License for more details. |
339 | + * |
340 | + * You should have received a copy of the GNU Lesser General Public |
341 | + * License along with this library; if not, write to the |
342 | + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
343 | + * Boston, MA 02110-1301, USA. |
344 | + */ |
345 | + |
346 | +#include <QProcess> |
347 | +#include "process.h" |
348 | + |
349 | +/* |
350 | + * PRIVATE IMPLEMENTATION |
351 | + */ |
352 | + |
353 | +class ProcessPrivate |
354 | +{ |
355 | + Q_DECLARE_PUBLIC(Process) |
356 | +public: |
357 | + explicit ProcessPrivate(Process* parent); |
358 | + ~ProcessPrivate(); |
359 | + |
360 | + void start(const QString& program, const QStringList& arguments, QProcess::OpenMode mode = QProcess::ReadWrite); |
361 | + |
362 | + void onError(QProcess::ProcessError error); |
363 | + void onFinished(int exitCode, QProcess::ExitStatus exitStatus); |
364 | + |
365 | +private: |
366 | + QProcess* _process; |
367 | + Process* q_ptr; |
368 | + |
369 | +}; |
370 | + |
371 | +ProcessPrivate::ProcessPrivate(Process* parent) : |
372 | + q_ptr(parent) |
373 | +{ |
374 | + Q_Q(Process); |
375 | + _process = new QProcess(); |
376 | + |
377 | + q->connect(_process, SIGNAL(finished(int, QProcess::ExitStatus)), |
378 | + q, SLOT(onFinished(int, QProcess::ExitStatus))); |
379 | + q->connect(_process, SIGNAL(error(QProcess::ProcessError)), |
380 | + q, SLOT(onError(QProcess::ProcessError))); |
381 | +} |
382 | + |
383 | +ProcessPrivate::~ProcessPrivate() |
384 | +{ |
385 | + if (_process != NULL) |
386 | + delete _process; |
387 | +} |
388 | + |
389 | +void ProcessPrivate::start(const QString& program, const QStringList& arguments, QProcess::OpenMode mode) |
390 | +{ |
391 | + _process->start(program, arguments, mode); |
392 | +} |
393 | + |
394 | +void ProcessPrivate::onError(QProcess::ProcessError error) |
395 | +{ |
396 | + Q_Q(Process); |
397 | + emit q->error(error); |
398 | +} |
399 | + |
400 | +void ProcessPrivate::onFinished(int exitCode, QProcess::ExitStatus exitStatus) |
401 | +{ |
402 | + Q_Q(Process); |
403 | + emit q->finished(exitCode, exitStatus); |
404 | +} |
405 | + |
406 | +/* |
407 | + * PUBLIC IMPLEMENTATION |
408 | + */ |
409 | + |
410 | +Process::Process(QObject *parent) : |
411 | + QObject(parent), |
412 | + d_ptr(new ProcessPrivate(this)) |
413 | +{ |
414 | +} |
415 | + |
416 | +void Process::start(const QString& program, const QStringList& arguments, QProcess::OpenMode mode) |
417 | +{ |
418 | + Q_D(Process); |
419 | + d->start(program, arguments, mode); |
420 | +} |
421 | + |
422 | +#include "moc_process.cpp" |
423 | |
424 | === added file 'libubuntudownloadmanager/process.h' |
425 | --- libubuntudownloadmanager/process.h 1970-01-01 00:00:00 +0000 |
426 | +++ libubuntudownloadmanager/process.h 2013-07-21 19:10:31 +0000 |
427 | @@ -0,0 +1,49 @@ |
428 | +/* |
429 | + * Copyright 2013 2013 Canonical Ltd. |
430 | + * |
431 | + * This library is free software; you can redistribute it and/or |
432 | + * modify it under the terms of version 3 of the GNU Lesser General Public |
433 | + * License as published by the Free Software Foundation. |
434 | + * |
435 | + * This program is distributed in the hope that it will be useful, |
436 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
437 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
438 | + * General Public License for more details. |
439 | + * |
440 | + * You should have received a copy of the GNU Lesser General Public |
441 | + * License along with this library; if not, write to the |
442 | + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
443 | + * Boston, MA 02110-1301, USA. |
444 | + */ |
445 | + |
446 | +#ifndef DOWNLOADER_LIB_PROCESS_H |
447 | +#define DOWNLOADER_LIB_PROCESS_H |
448 | + |
449 | +#include <QObject> |
450 | +#include <QProcess> |
451 | + |
452 | +class ProcessPrivate; |
453 | +class Process : public QObject |
454 | +{ |
455 | + Q_OBJECT |
456 | + Q_DECLARE_PRIVATE(Process) |
457 | + |
458 | +public: |
459 | + explicit Process(QObject *parent = 0); |
460 | + |
461 | + virtual void start(const QString& program, const QStringList& arguments, QProcess::OpenMode mode = QProcess::ReadWrite); |
462 | + |
463 | +signals: |
464 | + void error(QProcess::ProcessError error); |
465 | + void finished(int exitCode, QProcess::ExitStatus exitStatus); |
466 | + |
467 | +private: |
468 | + Q_PRIVATE_SLOT(d_func(), void onError(QProcess::ProcessError error)) |
469 | + Q_PRIVATE_SLOT(d_func(), void onFinished(int exitCode, QProcess::ExitStatus exitStatus)) |
470 | + |
471 | +private: |
472 | + // use pimpl so that we can mantains ABI compatibility |
473 | + ProcessPrivate* d_ptr; |
474 | +}; |
475 | + |
476 | +#endif // PROCESS_H |
477 | |
478 | === added file 'libubuntudownloadmanager/process_factory.cpp' |
479 | --- libubuntudownloadmanager/process_factory.cpp 1970-01-01 00:00:00 +0000 |
480 | +++ libubuntudownloadmanager/process_factory.cpp 2013-07-21 19:10:31 +0000 |
481 | @@ -0,0 +1,63 @@ |
482 | +/* |
483 | + * Copyright 2013 2013 Canonical Ltd. |
484 | + * |
485 | + * This library is free software; you can redistribute it and/or |
486 | + * modify it under the terms of version 3 of the GNU Lesser General Public |
487 | + * License as published by the Free Software Foundation. |
488 | + * |
489 | + * This program is distributed in the hope that it will be useful, |
490 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
491 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
492 | + * General Public License for more details. |
493 | + * |
494 | + * You should have received a copy of the GNU Lesser General Public |
495 | + * License along with this library; if not, write to the |
496 | + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
497 | + * Boston, MA 02110-1301, USA. |
498 | + */ |
499 | + |
500 | +#include "process_factory.h" |
501 | + |
502 | +/* |
503 | + * PRIVATE IMPLEMENTATION |
504 | + */ |
505 | + |
506 | +class ProcessFactoryPrivate |
507 | +{ |
508 | + Q_DECLARE_PUBLIC(ProcessFactory) |
509 | +public: |
510 | + explicit ProcessFactoryPrivate(ProcessFactory* parent); |
511 | + |
512 | + Process* createProcess(); |
513 | + |
514 | +private: |
515 | + ProcessFactory* q_ptr; |
516 | + |
517 | +}; |
518 | + |
519 | + |
520 | +ProcessFactoryPrivate::ProcessFactoryPrivate(ProcessFactory* parent): |
521 | + q_ptr(parent) |
522 | +{ |
523 | +} |
524 | + |
525 | +Process* ProcessFactoryPrivate::createProcess() |
526 | +{ |
527 | + return new Process(); |
528 | +} |
529 | + |
530 | +/* |
531 | + * PUBLIC IMPLEMENTATION |
532 | + */ |
533 | + |
534 | +ProcessFactory::ProcessFactory(QObject *parent) : |
535 | + QObject(parent), |
536 | + d_ptr(new ProcessFactoryPrivate(this)) |
537 | +{ |
538 | +} |
539 | + |
540 | +Process* ProcessFactory::createProcess() |
541 | +{ |
542 | + Q_D(ProcessFactory); |
543 | + return d->createProcess(); |
544 | +} |
545 | |
546 | === added file 'libubuntudownloadmanager/process_factory.h' |
547 | --- libubuntudownloadmanager/process_factory.h 1970-01-01 00:00:00 +0000 |
548 | +++ libubuntudownloadmanager/process_factory.h 2013-07-21 19:10:31 +0000 |
549 | @@ -0,0 +1,41 @@ |
550 | +/* |
551 | + * Copyright 2013 2013 Canonical Ltd. |
552 | + * |
553 | + * This library is free software; you can redistribute it and/or |
554 | + * modify it under the terms of version 3 of the GNU Lesser General Public |
555 | + * License as published by the Free Software Foundation. |
556 | + * |
557 | + * This program is distributed in the hope that it will be useful, |
558 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
559 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
560 | + * General Public License for more details. |
561 | + * |
562 | + * You should have received a copy of the GNU Lesser General Public |
563 | + * License along with this library; if not, write to the |
564 | + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
565 | + * Boston, MA 02110-1301, USA. |
566 | + */ |
567 | + |
568 | +#ifndef DOWNLOADER_LIB_PROCESS_FACTORY_H |
569 | +#define DOWNLOADER_LIB_PROCESS_FACTORY_H |
570 | + |
571 | +#include <QObject> |
572 | +#include "process.h" |
573 | + |
574 | +class ProcessFactoryPrivate; |
575 | +class ProcessFactory : public QObject |
576 | +{ |
577 | + Q_OBJECT |
578 | + Q_DECLARE_PRIVATE(ProcessFactory) |
579 | + |
580 | +public: |
581 | + explicit ProcessFactory(QObject *parent = 0); |
582 | + |
583 | + virtual Process* createProcess(); |
584 | + |
585 | +private: |
586 | + // use pimpl so that we can mantains ABI compatibility |
587 | + ProcessFactoryPrivate* d_ptr; |
588 | +}; |
589 | + |
590 | +#endif |
591 | |
592 | === modified file 'ubuntu-download-manager-tests/fake.cpp' |
593 | --- ubuntu-download-manager-tests/fake.cpp 2013-07-08 16:46:16 +0000 |
594 | +++ ubuntu-download-manager-tests/fake.cpp 2013-07-21 19:10:31 +0000 |
595 | @@ -60,6 +60,27 @@ |
596 | } |
597 | |
598 | /* |
599 | + * STRING LIST WRAPPER |
600 | + */ |
601 | + |
602 | + |
603 | +StringListWrapper::StringListWrapper(const QStringList& list, QObject* parent) : |
604 | + QObject(parent) |
605 | +{ |
606 | + _value = list; |
607 | +} |
608 | + |
609 | +QStringList StringListWrapper::value() |
610 | +{ |
611 | + return _value; |
612 | +} |
613 | + |
614 | +void StringListWrapper::setValue(const QStringList& value) |
615 | +{ |
616 | + _value = value; |
617 | +} |
618 | + |
619 | +/* |
620 | * UINT WRAPPER |
621 | */ |
622 | |
623 | |
624 | === modified file 'ubuntu-download-manager-tests/fake.h' |
625 | --- ubuntu-download-manager-tests/fake.h 2013-07-08 16:46:16 +0000 |
626 | +++ ubuntu-download-manager-tests/fake.h 2013-07-21 19:10:31 +0000 |
627 | @@ -22,6 +22,7 @@ |
628 | #include <QList> |
629 | #include <QObject> |
630 | #include <QPair> |
631 | +#include <QStringList> |
632 | |
633 | |
634 | class BoolWrapper : public QObject |
635 | @@ -52,6 +53,20 @@ |
636 | }; |
637 | |
638 | |
639 | +class StringListWrapper : public QObject |
640 | +{ |
641 | + Q_OBJECT |
642 | + |
643 | +public: |
644 | + StringListWrapper(const QStringList& list, QObject* parent=0); |
645 | + |
646 | + QStringList value(); |
647 | + void setValue(const QStringList& value); |
648 | + |
649 | +private: |
650 | + QStringList _value; |
651 | +}; |
652 | + |
653 | class UintWrapper : public QObject |
654 | { |
655 | Q_OBJECT |
656 | |
657 | === modified file 'ubuntu-download-manager-tests/fake_download.cpp' |
658 | --- ubuntu-download-manager-tests/fake_download.cpp 2013-07-20 18:26:02 +0000 |
659 | +++ ubuntu-download-manager-tests/fake_download.cpp 2013-07-21 19:10:31 +0000 |
660 | @@ -19,15 +19,16 @@ |
661 | #include "fake_download.h" |
662 | |
663 | FakeDownload::FakeDownload(const QUuid& id, const QString& path, const QUrl& url, const QVariantMap& metadata, |
664 | - const QMap<QString, QString> &headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, QObject* parent): |
665 | - Download(id, path, url, metadata, headers, networkInfo, nam, parent), |
666 | + const QMap<QString, QString> &headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, ProcessFactory* processFactory, QObject* parent): |
667 | + Download(id, path, url, metadata, headers, networkInfo, nam, processFactory, parent), |
668 | _canDownload(true) |
669 | { |
670 | } |
671 | |
672 | FakeDownload::FakeDownload(const QUuid& id, const QString& path, const QUrl& url, const QString& hash, QCryptographicHash::Algorithm algo, |
673 | - const QVariantMap& metadata, const QMap<QString ,QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, QObject* parent) : |
674 | - Download(id, path, url, hash, algo, metadata, headers, networkInfo, nam, parent), |
675 | + const QVariantMap& metadata, const QMap<QString ,QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, |
676 | + ProcessFactory* processFactory, QObject* parent) : |
677 | + Download(id, path, url, hash, algo, metadata, headers, networkInfo, nam, processFactory, parent), |
678 | _canDownload(true) |
679 | { |
680 | } |
681 | |
682 | === modified file 'ubuntu-download-manager-tests/fake_download.h' |
683 | --- ubuntu-download-manager-tests/fake_download.h 2013-07-20 18:26:02 +0000 |
684 | +++ ubuntu-download-manager-tests/fake_download.h 2013-07-21 19:10:31 +0000 |
685 | @@ -28,10 +28,11 @@ |
686 | Q_OBJECT |
687 | public: |
688 | explicit FakeDownload(const QUuid& id, const QString& path, const QUrl& url, const QVariantMap& metadata, |
689 | - const QMap<QString, QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, QObject* parent=0); |
690 | + const QMap<QString, QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, ProcessFactory* processFactory, |
691 | + QObject* parent=0); |
692 | explicit FakeDownload(const QUuid& id, const QString& path, const QUrl& url, const QString& hash, |
693 | QCryptographicHash::Algorithm algo, const QVariantMap& metadata, const QMap<QString, QString> &headers, |
694 | - SystemNetworkInfo* networkInfo, RequestFactory* nam, QObject* parent=0); |
695 | + SystemNetworkInfo* networkInfo, RequestFactory* nam, ProcessFactory* processFactory, QObject* parent=0); |
696 | |
697 | bool canDownload() override; |
698 | void setCanDownload(bool canDownload); |
699 | |
700 | === modified file 'ubuntu-download-manager-tests/fake_network_reply.cpp' |
701 | --- ubuntu-download-manager-tests/fake_network_reply.cpp 2013-07-08 16:46:16 +0000 |
702 | +++ ubuntu-download-manager-tests/fake_network_reply.cpp 2013-07-21 19:10:31 +0000 |
703 | @@ -69,3 +69,8 @@ |
704 | _called.append(methodData); |
705 | } |
706 | } |
707 | + |
708 | +void FakeNetworkReply::emitFinished() |
709 | +{ |
710 | + emit finished(); |
711 | +} |
712 | |
713 | === modified file 'ubuntu-download-manager-tests/fake_network_reply.h' |
714 | --- ubuntu-download-manager-tests/fake_network_reply.h 2013-07-08 16:46:16 +0000 |
715 | +++ ubuntu-download-manager-tests/fake_network_reply.h 2013-07-21 19:10:31 +0000 |
716 | @@ -38,6 +38,7 @@ |
717 | QByteArray readAll() override; |
718 | void abort() override; |
719 | void setReadBufferSize(uint size) override; |
720 | + void emitFinished(); |
721 | |
722 | private: |
723 | QByteArray _data; |
724 | |
725 | === added file 'ubuntu-download-manager-tests/fake_process.cpp' |
726 | --- ubuntu-download-manager-tests/fake_process.cpp 1970-01-01 00:00:00 +0000 |
727 | +++ ubuntu-download-manager-tests/fake_process.cpp 2013-07-21 19:10:31 +0000 |
728 | @@ -0,0 +1,57 @@ |
729 | +/* |
730 | + * Copyright 2013 2013 Canonical Ltd. |
731 | + * |
732 | + * This library is free software; you can redistribute it and/or |
733 | + * modify it under the terms of version 3 of the GNU Lesser General Public |
734 | + * License as published by the Free Software Foundation. |
735 | + * |
736 | + * This program is distributed in the hope that it will be useful, |
737 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
738 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
739 | + * General Public License for more details. |
740 | + * |
741 | + * You should have received a copy of the GNU Lesser General Public |
742 | + * License along with this library; if not, write to the |
743 | + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
744 | + * Boston, MA 02110-1301, USA. |
745 | + */ |
746 | + |
747 | +#include "fake_process.h" |
748 | + |
749 | +OpenModeWrapper::OpenModeWrapper(QProcess::OpenMode mode, QObject* parent) : |
750 | + QObject(parent) |
751 | +{ |
752 | + _value = mode; |
753 | +} |
754 | + |
755 | +QProcess::OpenMode OpenModeWrapper::value() |
756 | +{ |
757 | + return _value; |
758 | +} |
759 | + |
760 | +void OpenModeWrapper::setValue(QProcess::OpenMode value) |
761 | +{ |
762 | + _value = value; |
763 | +} |
764 | + |
765 | +FakeProcess::FakeProcess(QObject *parent) : |
766 | + Process(parent), |
767 | + Fake() |
768 | +{ |
769 | +} |
770 | + |
771 | +void FakeProcess::start(const QString& program, const QStringList& arguments, QProcess::OpenMode mode) |
772 | +{ |
773 | + if (_recording) |
774 | + { |
775 | + QList<QObject*> inParams; |
776 | + inParams.append(new StringWrapper(program)); |
777 | + inParams.append(new StringListWrapper(arguments)); |
778 | + inParams.append(new OpenModeWrapper(mode)); |
779 | + |
780 | + QList<QObject*> outParams; |
781 | + MethodParams params(inParams, outParams); |
782 | + MethodData methodData("start", params); |
783 | + _called.append(methodData); |
784 | + } |
785 | +} |
786 | |
787 | === added file 'ubuntu-download-manager-tests/fake_process.h' |
788 | --- ubuntu-download-manager-tests/fake_process.h 1970-01-01 00:00:00 +0000 |
789 | +++ ubuntu-download-manager-tests/fake_process.h 2013-07-21 19:10:31 +0000 |
790 | @@ -0,0 +1,50 @@ |
791 | +/* |
792 | + * Copyright 2013 2013 Canonical Ltd. |
793 | + * |
794 | + * This library is free software; you can redistribute it and/or |
795 | + * modify it under the terms of version 3 of the GNU Lesser General Public |
796 | + * License as published by the Free Software Foundation. |
797 | + * |
798 | + * This program is distributed in the hope that it will be useful, |
799 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
800 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
801 | + * General Public License for more details. |
802 | + * |
803 | + * You should have received a copy of the GNU Lesser General Public |
804 | + * License along with this library; if not, write to the |
805 | + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
806 | + * Boston, MA 02110-1301, USA. |
807 | + */ |
808 | + |
809 | +#ifndef FAKE_PROCESS_H |
810 | +#define FAKE_PROCESS_H |
811 | + |
812 | +#include <QObject> |
813 | +#include <process.h> |
814 | +#include "fake.h" |
815 | + |
816 | +class OpenModeWrapper: public QObject |
817 | +{ |
818 | + Q_OBJECT |
819 | + |
820 | +public: |
821 | + OpenModeWrapper(QProcess::OpenMode mode, QObject* parent=0); |
822 | + |
823 | + QProcess::OpenMode value(); |
824 | + void setValue(QProcess::OpenMode value); |
825 | + |
826 | +private: |
827 | + QProcess::OpenMode _value; |
828 | +}; |
829 | + |
830 | +class FakeProcess : public Process, public Fake |
831 | +{ |
832 | + Q_OBJECT |
833 | +public: |
834 | + explicit FakeProcess(QObject *parent = 0); |
835 | + |
836 | + void start(const QString& program, const QStringList& arguments, QProcess::OpenMode mode = QProcess::ReadWrite) override; |
837 | + |
838 | +}; |
839 | + |
840 | +#endif // FAKE_PROCESS_H |
841 | |
842 | === added file 'ubuntu-download-manager-tests/fake_process_factory.cpp' |
843 | --- ubuntu-download-manager-tests/fake_process_factory.cpp 1970-01-01 00:00:00 +0000 |
844 | +++ ubuntu-download-manager-tests/fake_process_factory.cpp 2013-07-21 19:10:31 +0000 |
845 | @@ -0,0 +1,48 @@ |
846 | +/* |
847 | + * Copyright 2013 2013 Canonical Ltd. |
848 | + * |
849 | + * This library is free software; you can redistribute it and/or |
850 | + * modify it under the terms of version 3 of the GNU Lesser General Public |
851 | + * License as published by the Free Software Foundation. |
852 | + * |
853 | + * This program is distributed in the hope that it will be useful, |
854 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
855 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
856 | + * General Public License for more details. |
857 | + * |
858 | + * You should have received a copy of the GNU Lesser General Public |
859 | + * License along with this library; if not, write to the |
860 | + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
861 | + * Boston, MA 02110-1301, USA. |
862 | + */ |
863 | + |
864 | +#include "fake_process_factory.h" |
865 | +#include "fake_process.h" |
866 | + |
867 | +FakeProcessFactory::FakeProcessFactory(QObject *parent) : |
868 | + ProcessFactory(parent), |
869 | + Fake() |
870 | +{ |
871 | +} |
872 | + |
873 | +Process* FakeProcessFactory::createProcess() |
874 | +{ |
875 | + |
876 | + FakeProcess* process = new FakeProcess(); |
877 | + |
878 | + if (_recording) |
879 | + { |
880 | + QList<QObject*> inParams; |
881 | + |
882 | + QList<QObject*> outParams; |
883 | + outParams.append(process); |
884 | + MethodParams params(inParams, outParams); |
885 | + |
886 | + MethodData methodData("createProcess", params); |
887 | + _called.append(methodData); |
888 | + |
889 | + // if we are recording we do set the recording of the returned process |
890 | + process->record(); |
891 | + } |
892 | + return process; |
893 | +} |
894 | |
895 | === added file 'ubuntu-download-manager-tests/fake_process_factory.h' |
896 | --- ubuntu-download-manager-tests/fake_process_factory.h 1970-01-01 00:00:00 +0000 |
897 | +++ ubuntu-download-manager-tests/fake_process_factory.h 2013-07-21 19:10:31 +0000 |
898 | @@ -0,0 +1,36 @@ |
899 | +/* |
900 | + * Copyright 2013 2013 Canonical Ltd. |
901 | + * |
902 | + * This library is free software; you can redistribute it and/or |
903 | + * modify it under the terms of version 3 of the GNU Lesser General Public |
904 | + * License as published by the Free Software Foundation. |
905 | + * |
906 | + * This program is distributed in the hope that it will be useful, |
907 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
908 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
909 | + * General Public License for more details. |
910 | + * |
911 | + * You should have received a copy of the GNU Lesser General Public |
912 | + * License along with this library; if not, write to the |
913 | + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
914 | + * Boston, MA 02110-1301, USA. |
915 | + */ |
916 | + |
917 | +#ifndef FAKE_PROCESS_FACTORY_H |
918 | +#define FAKE_PROCESS_FACTORY_H |
919 | + |
920 | +#include <QObject> |
921 | +#include <process_factory.h> |
922 | +#include "fake.h" |
923 | + |
924 | +class FakeProcessFactory : public ProcessFactory, public Fake |
925 | +{ |
926 | + Q_OBJECT |
927 | +public: |
928 | + explicit FakeProcessFactory(QObject *parent = 0); |
929 | + |
930 | + Process* createProcess() override; |
931 | + |
932 | +}; |
933 | + |
934 | +#endif // FAKE_PROCESS_FACTORY_H |
935 | |
936 | === modified file 'ubuntu-download-manager-tests/test_download.cpp' |
937 | --- ubuntu-download-manager-tests/test_download.cpp 2013-07-20 18:26:02 +0000 |
938 | +++ ubuntu-download-manager-tests/test_download.cpp 2013-07-21 19:10:31 +0000 |
939 | @@ -22,6 +22,7 @@ |
940 | #include <QSignalSpy> |
941 | #include <QSslError> |
942 | #include "fake_network_reply.h" |
943 | +#include "fake_process.h" |
944 | #include "test_download.h" |
945 | |
946 | TestDownload::TestDownload(QObject* parent) : |
947 | @@ -73,6 +74,7 @@ |
948 | _algo = QCryptographicHash::Sha256; |
949 | _networkInfo = new FakeSystemNetworkInfo(); |
950 | _reqFactory = new FakeRequestFactory(); |
951 | + _processFactory = new FakeProcessFactory(); |
952 | } |
953 | |
954 | void TestDownload::cleanup() |
955 | @@ -81,6 +83,8 @@ |
956 | delete _networkInfo; |
957 | if (_reqFactory) |
958 | delete _reqFactory; |
959 | + if (_processFactory) |
960 | + delete _processFactory; |
961 | |
962 | // try to remove the test dir |
963 | removeDir(_testDir.absolutePath()); |
964 | @@ -105,7 +109,7 @@ |
965 | QFETCH(QString, path); |
966 | QFETCH(QUrl, url); |
967 | |
968 | - Download* download = new Download(id, path, url, _metadata, _headers, _networkInfo, _reqFactory); |
969 | + Download* download = new Download(id, path, url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
970 | |
971 | // assert that we did set the intial state correctly |
972 | // gets for internal state |
973 | @@ -147,7 +151,7 @@ |
974 | QFETCH(int, algo); |
975 | |
976 | Download* download = new Download(id, path, url, hash, (QCryptographicHash::Algorithm)algo, _metadata, _headers, _networkInfo, |
977 | - _reqFactory); |
978 | + _reqFactory, _processFactory); |
979 | |
980 | QCOMPARE(download->downloadId(), id); |
981 | QCOMPARE(download->path(), path); |
982 | @@ -176,7 +180,7 @@ |
983 | { |
984 | // create an app download and assert that the returned data is correct |
985 | QFETCH(QString, path); |
986 | - Download* download = new Download(_id, path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
987 | + Download* download = new Download(_id, path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
988 | QCOMPARE(download->path(), path); |
989 | } |
990 | |
991 | @@ -195,7 +199,7 @@ |
992 | { |
993 | // create an app download and assert that the returned data is correct |
994 | QFETCH(QUrl, url); |
995 | - Download* download = new Download(_id, _path, url, _metadata, _headers, _networkInfo, _reqFactory); |
996 | + Download* download = new Download(_id, _path, url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
997 | QCOMPARE(download->url(), url); |
998 | delete download; |
999 | } |
1000 | @@ -219,7 +223,7 @@ |
1001 | QFETCH(qulonglong, total); |
1002 | |
1003 | _reqFactory->record(); |
1004 | - Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
1005 | + Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1006 | QSignalSpy spy(download , SIGNAL(progress(qulonglong, qulonglong))); |
1007 | |
1008 | // start the download so that we do have access to the reply |
1009 | @@ -248,7 +252,7 @@ |
1010 | |
1011 | // assert that the total size is just set once by emitting two signals with diff sizes |
1012 | _reqFactory->record(); |
1013 | - Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
1014 | + Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1015 | QSignalSpy spy(download , SIGNAL(progress(qulonglong, qulonglong))); |
1016 | |
1017 | // start the download so that we do have access to the reply |
1018 | @@ -267,7 +271,7 @@ |
1019 | |
1020 | void TestDownload::testTotalSizeNoProgress() |
1021 | { |
1022 | - Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
1023 | + Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1024 | QCOMPARE(0ULL, download->totalSize()); |
1025 | delete download; |
1026 | } |
1027 | @@ -285,7 +289,7 @@ |
1028 | void TestDownload::testSetThrottleNoReply() |
1029 | { |
1030 | QFETCH(qulonglong, speed); |
1031 | - Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
1032 | + Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1033 | download->setThrottle(speed); |
1034 | QCOMPARE(speed, download->throttle()); |
1035 | } |
1036 | @@ -305,7 +309,7 @@ |
1037 | QFETCH(uint, speed); |
1038 | |
1039 | _reqFactory->record(); |
1040 | - Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
1041 | + Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1042 | download->setThrottle(speed); |
1043 | |
1044 | download->start(); // change state |
1045 | @@ -332,7 +336,7 @@ |
1046 | { |
1047 | QFETCH(bool, value); |
1048 | |
1049 | - Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
1050 | + Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1051 | download->allowGSMDownload(value); |
1052 | QSignalSpy spy(download , SIGNAL(stateChanged())); |
1053 | |
1054 | @@ -354,7 +358,7 @@ |
1055 | QFETCH(bool, oldValue); |
1056 | QFETCH(bool, newValue); |
1057 | |
1058 | - Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
1059 | + Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1060 | download->allowGSMDownload(oldValue); |
1061 | QSignalSpy spy(download , SIGNAL(stateChanged())); |
1062 | |
1063 | @@ -395,7 +399,7 @@ |
1064 | _networkInfo->setMode(mode.value<QNetworkInfo::NetworkMode>()); |
1065 | _networkInfo->record(); |
1066 | |
1067 | - Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
1068 | + Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1069 | download->allowGSMDownload(true); |
1070 | QVERIFY(download->canDownload()); |
1071 | QList<MethodData> calledMethods = _networkInfo->calledMethods(); |
1072 | @@ -439,7 +443,7 @@ |
1073 | _networkInfo->setMode(mode.value<QNetworkInfo::NetworkMode>()); |
1074 | _networkInfo->record(); |
1075 | |
1076 | - Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
1077 | + Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1078 | download->allowGSMDownload(false); |
1079 | |
1080 | QCOMPARE(result, download->canDownload()); |
1081 | @@ -449,7 +453,7 @@ |
1082 | |
1083 | void TestDownload::testCancel() |
1084 | { |
1085 | - Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
1086 | + Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1087 | QSignalSpy spy(download , SIGNAL(stateChanged())); |
1088 | download->cancel(); |
1089 | |
1090 | @@ -460,7 +464,7 @@ |
1091 | |
1092 | void TestDownload::testPause() |
1093 | { |
1094 | - Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
1095 | + Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1096 | QSignalSpy spy(download , SIGNAL(stateChanged())); |
1097 | download->pause(); |
1098 | |
1099 | @@ -471,7 +475,7 @@ |
1100 | |
1101 | void TestDownload::testResume() |
1102 | { |
1103 | - Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
1104 | + Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1105 | QSignalSpy spy(download , SIGNAL(stateChanged())); |
1106 | download->resume(); |
1107 | |
1108 | @@ -482,7 +486,7 @@ |
1109 | |
1110 | void TestDownload::testStart() |
1111 | { |
1112 | - Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
1113 | + Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1114 | QSignalSpy spy(download , SIGNAL(stateChanged())); |
1115 | download->start(); |
1116 | |
1117 | @@ -496,7 +500,7 @@ |
1118 | // tell the fake nam to record so that we can access the reply |
1119 | |
1120 | _reqFactory->record(); |
1121 | - Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
1122 | + Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1123 | QSignalSpy spy(download , SIGNAL(canceled(bool))); |
1124 | |
1125 | download->start(); // change state |
1126 | @@ -526,7 +530,7 @@ |
1127 | void TestDownload::testCancelDownloadNotStarted() |
1128 | { |
1129 | _reqFactory->record(); |
1130 | - Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
1131 | + Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1132 | QSignalSpy spy(download , SIGNAL(canceled(bool))); |
1133 | |
1134 | download->cancel(); // change state |
1135 | @@ -545,7 +549,7 @@ |
1136 | void TestDownload::testPauseDownload() |
1137 | { |
1138 | _reqFactory->record(); |
1139 | - Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
1140 | + Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1141 | QSignalSpy spy(download , SIGNAL(paused(bool))); |
1142 | |
1143 | download->start(); // change state |
1144 | @@ -579,7 +583,7 @@ |
1145 | |
1146 | void TestDownload::testPauseDownloadNotStarted() |
1147 | { |
1148 | - Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
1149 | + Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1150 | QSignalSpy spy(download , SIGNAL(paused(bool))); |
1151 | |
1152 | download->pause(); |
1153 | @@ -594,7 +598,7 @@ |
1154 | |
1155 | void TestDownload::testResumeRunning() |
1156 | { |
1157 | - Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
1158 | + Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1159 | QSignalSpy spy(download , SIGNAL(resumed(bool))); |
1160 | |
1161 | download->start(); |
1162 | @@ -612,7 +616,7 @@ |
1163 | void TestDownload::testResumeDownload() |
1164 | { |
1165 | _reqFactory->record(); |
1166 | - Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
1167 | + Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1168 | QSignalSpy spy(download , SIGNAL(paused(bool))); |
1169 | |
1170 | download->start(); // change state |
1171 | @@ -645,7 +649,7 @@ |
1172 | void TestDownload::testStartDownload() |
1173 | { |
1174 | _reqFactory->record(); |
1175 | - Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
1176 | + Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1177 | QSignalSpy spy(download , SIGNAL(started(bool))); |
1178 | |
1179 | download->start(); // change state |
1180 | @@ -665,7 +669,7 @@ |
1181 | void TestDownload::testStartDownloadAlreadyStarted() |
1182 | { |
1183 | _reqFactory->record(); |
1184 | - Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
1185 | + Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1186 | QSignalSpy spy(download , SIGNAL(started(bool))); |
1187 | |
1188 | download->start(); // change state |
1189 | @@ -686,7 +690,7 @@ |
1190 | void TestDownload::testOnSuccessNoHash() |
1191 | { |
1192 | _reqFactory->record(); |
1193 | - Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
1194 | + Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1195 | QSignalSpy spy(download , SIGNAL(finished(QString))); |
1196 | |
1197 | download->start(); // change state |
1198 | @@ -706,7 +710,7 @@ |
1199 | { |
1200 | _reqFactory->record(); |
1201 | Download* download = new Download(_id, _path, _url, "imposible-hash-is-not-hex", _algo, _metadata, _headers, |
1202 | - _networkInfo, _reqFactory); |
1203 | + _networkInfo, _reqFactory, _processFactory); |
1204 | QSignalSpy spy(download , SIGNAL(error(QString))); |
1205 | |
1206 | download->start(); // change state |
1207 | @@ -763,7 +767,8 @@ |
1208 | QFETCH(QString, hash); |
1209 | |
1210 | _reqFactory->record(); |
1211 | - Download* download = new Download(_id, _path, _url, hash, _algo, _metadata, _headers, _networkInfo, _reqFactory); |
1212 | + Download* download = new Download(_id, _path, _url, hash, _algo, _metadata, _headers, _networkInfo, _reqFactory, |
1213 | + _processFactory); |
1214 | QSignalSpy spy(download , SIGNAL(finished(QString))); |
1215 | |
1216 | download->start(); // change state |
1217 | @@ -797,7 +802,7 @@ |
1218 | void TestDownload::testOnHttpError() |
1219 | { |
1220 | _reqFactory->record(); |
1221 | - Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory); |
1222 | + Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1223 | QSignalSpy spy(download , SIGNAL(error(QString))); |
1224 | |
1225 | download->start(); // change state |
1226 | @@ -845,7 +850,7 @@ |
1227 | { |
1228 | QFETCH(StringMap, headers); |
1229 | _reqFactory->record(); |
1230 | - Download* download = new Download(_id, _path, _url, _metadata, headers, _networkInfo, _reqFactory); |
1231 | + Download* download = new Download(_id, _path, _url, _metadata, headers, _networkInfo, _reqFactory, _processFactory); |
1232 | |
1233 | download->start(); // change state |
1234 | download->startDownload(); |
1235 | @@ -898,7 +903,7 @@ |
1236 | // similar to the previous test but we want to ensure that range is not set |
1237 | QFETCH(StringMap, headers); |
1238 | _reqFactory->record(); |
1239 | - Download* download = new Download(_id, _path, _url, _metadata, headers, _networkInfo, _reqFactory); |
1240 | + Download* download = new Download(_id, _path, _url, _metadata, headers, _networkInfo, _reqFactory, _processFactory); |
1241 | |
1242 | download->start(); // change state |
1243 | download->startDownload(); |
1244 | @@ -943,7 +948,7 @@ |
1245 | QFETCH(StringMap, headers); |
1246 | |
1247 | _reqFactory->record(); |
1248 | - Download* download = new Download(_id, _path, _url, _metadata, headers, _networkInfo, _reqFactory); |
1249 | + Download* download = new Download(_id, _path, _url, _metadata, headers, _networkInfo, _reqFactory, _processFactory); |
1250 | QSignalSpy spy(download , SIGNAL(paused(bool))); |
1251 | |
1252 | download->start(); // change state |
1253 | @@ -1017,7 +1022,7 @@ |
1254 | QFETCH(StringMap, headers); |
1255 | |
1256 | _reqFactory->record(); |
1257 | - Download* download = new Download(_id, _path, _url, _metadata, headers, _networkInfo, _reqFactory); |
1258 | + Download* download = new Download(_id, _path, _url, _metadata, headers, _networkInfo, _reqFactory, _processFactory); |
1259 | QSignalSpy spy(download , SIGNAL(paused(bool))); |
1260 | |
1261 | download->start(); // change state |
1262 | @@ -1047,3 +1052,165 @@ |
1263 | QByteArray rangeHeaderValue = "bytes=" + QByteArray::number(reply->data().size()) + "-"; |
1264 | QCOMPARE(rangeHeaderValue, request.rawHeader("Range")); |
1265 | } |
1266 | + |
1267 | +void TestDownload::testProcessExecutedNoParams_data() |
1268 | +{ |
1269 | + QTest::addColumn<QString>("command"); |
1270 | + QTest::addColumn<QVariantMap>("metadata"); |
1271 | + QVariantMap first, second, third; |
1272 | + QStringList firstCommand, secondCommand, thirdCommand; |
1273 | + |
1274 | + firstCommand << "touch"; |
1275 | + first["post-download-command"] = firstCommand; |
1276 | + |
1277 | + QTest::newRow("First row") << firstCommand[0] << first; |
1278 | + |
1279 | + secondCommand << "sudo"; |
1280 | + second["post-download-command"] = secondCommand; |
1281 | + |
1282 | + QTest::newRow("Second row") << secondCommand[0] << second; |
1283 | + |
1284 | + thirdCommand << "grep"; |
1285 | + third["post-download-command"] = thirdCommand; |
1286 | + |
1287 | + QTest::newRow("Third row") << thirdCommand[0] << third; |
1288 | +} |
1289 | + |
1290 | +void TestDownload::testProcessExecutedNoParams() |
1291 | +{ |
1292 | + QFETCH(QString, command); |
1293 | + QFETCH(QVariantMap, metadata); |
1294 | + |
1295 | + _processFactory->record(); |
1296 | + _reqFactory->record(); |
1297 | + Download* download = new Download(_id, _path, _url, metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1298 | + |
1299 | + download->start(); // change state |
1300 | + download->startDownload(); |
1301 | + |
1302 | + // we need to set the data before we pause!!! |
1303 | + QList<MethodData> calledMethods = _reqFactory->calledMethods(); |
1304 | + QCOMPARE(1, calledMethods.count()); |
1305 | + FakeNetworkReply* reply = (FakeNetworkReply*) calledMethods[0].params().outParams()[0]; |
1306 | + |
1307 | + // makes the process to be executed |
1308 | + reply->emitFinished(); |
1309 | + |
1310 | + calledMethods = _processFactory->calledMethods(); |
1311 | + QCOMPARE(1, calledMethods.count()); |
1312 | + FakeProcess* process = (FakeProcess*) calledMethods[0].params().outParams()[0]; |
1313 | + |
1314 | + calledMethods = process->calledMethods(); |
1315 | + QString processCommand = ((StringWrapper*)calledMethods[0].params().inParams()[0])->value(); |
1316 | + QStringList processArgs = ((StringListWrapper*)calledMethods[0].params().inParams()[1])->value(); |
1317 | + QCOMPARE(processCommand, command); |
1318 | + QCOMPARE(0, processArgs.count()); |
1319 | +} |
1320 | + |
1321 | +void TestDownload::testProcessExecutedWithParams_data() |
1322 | +{ |
1323 | + QTest::addColumn<QString>("command"); |
1324 | + QTest::addColumn<QVariantMap>("metadata"); |
1325 | + QVariantMap first, second, third; |
1326 | + QStringList firstCommand, secondCommand, thirdCommand; |
1327 | + |
1328 | + firstCommand << "touch" << "test-file"; |
1329 | + first["post-download-command"] = firstCommand; |
1330 | + |
1331 | + QTest::newRow("First row") << firstCommand[0] << first; |
1332 | + |
1333 | + secondCommand << "sudo" << "apt-get" << "install" << "click"; |
1334 | + second["post-download-command"] = secondCommand; |
1335 | + |
1336 | + QTest::newRow("Second row") << secondCommand[0] << second; |
1337 | + |
1338 | + thirdCommand << "grep" << "." << "-Rn"; |
1339 | + third["post-download-command"] = thirdCommand; |
1340 | + |
1341 | + QTest::newRow("Third row") << thirdCommand[0] << third; |
1342 | +} |
1343 | + |
1344 | +void TestDownload::testProcessExecutedWithParams() |
1345 | +{ |
1346 | + QFETCH(QString, command); |
1347 | + QFETCH(QVariantMap, metadata); |
1348 | + |
1349 | + _processFactory->record(); |
1350 | + _reqFactory->record(); |
1351 | + Download* download = new Download(_id, _path, _url, metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1352 | + |
1353 | + download->start(); // change state |
1354 | + download->startDownload(); |
1355 | + |
1356 | + // we need to set the data before we pause!!! |
1357 | + QList<MethodData> calledMethods = _reqFactory->calledMethods(); |
1358 | + QCOMPARE(1, calledMethods.count()); |
1359 | + FakeNetworkReply* reply = (FakeNetworkReply*) calledMethods[0].params().outParams()[0]; |
1360 | + |
1361 | + // makes the process to be executed |
1362 | + reply->emitFinished(); |
1363 | + |
1364 | + calledMethods = _processFactory->calledMethods(); |
1365 | + QCOMPARE(1, calledMethods.count()); |
1366 | + FakeProcess* process = (FakeProcess*) calledMethods[0].params().outParams()[0]; |
1367 | + |
1368 | + calledMethods = process->calledMethods(); |
1369 | + QString processCommand = ((StringWrapper*)calledMethods[0].params().inParams()[0])->value(); |
1370 | + QStringList processArgs = ((StringListWrapper*)calledMethods[0].params().inParams()[1])->value(); |
1371 | + QCOMPARE(processCommand, command); |
1372 | + QVERIFY(0 != processArgs.count()); |
1373 | +} |
1374 | + |
1375 | +void TestDownload::testProcessExecutedWithParamsFile_data() |
1376 | +{ |
1377 | + QTest::addColumn<QString>("command"); |
1378 | + QTest::addColumn<QVariantMap>("metadata"); |
1379 | + QVariantMap first, second, third; |
1380 | + QStringList firstCommand, secondCommand, thirdCommand; |
1381 | + |
1382 | + firstCommand << "touch" << "$file"; |
1383 | + first["post-download-command"] = firstCommand; |
1384 | + |
1385 | + QTest::newRow("First row") << firstCommand[0] << first; |
1386 | + |
1387 | + secondCommand << "sudo" << "apt-get" << "install" << "$file"; |
1388 | + second["post-download-command"] = secondCommand; |
1389 | + |
1390 | + QTest::newRow("Second row") << secondCommand[0] << second; |
1391 | + |
1392 | + thirdCommand << "grep" << "$file" << "-Rn"; |
1393 | + third["post-download-command"] = thirdCommand; |
1394 | + |
1395 | + QTest::newRow("Third row") << thirdCommand[0] << third; |
1396 | +} |
1397 | + |
1398 | +void TestDownload::testProcessExecutedWithParamsFile() |
1399 | +{ |
1400 | + QFETCH(QString, command); |
1401 | + QFETCH(QVariantMap, metadata); |
1402 | + |
1403 | + _processFactory->record(); |
1404 | + _reqFactory->record(); |
1405 | + Download* download = new Download(_id, _path, _url, metadata, _headers, _networkInfo, _reqFactory, _processFactory); |
1406 | + |
1407 | + download->start(); // change state |
1408 | + download->startDownload(); |
1409 | + |
1410 | + // we need to set the data before we pause!!! |
1411 | + QList<MethodData> calledMethods = _reqFactory->calledMethods(); |
1412 | + QCOMPARE(1, calledMethods.count()); |
1413 | + FakeNetworkReply* reply = (FakeNetworkReply*) calledMethods[0].params().outParams()[0]; |
1414 | + |
1415 | + // makes the process to be executed |
1416 | + reply->emitFinished(); |
1417 | + |
1418 | + calledMethods = _processFactory->calledMethods(); |
1419 | + QCOMPARE(1, calledMethods.count()); |
1420 | + FakeProcess* process = (FakeProcess*) calledMethods[0].params().outParams()[0]; |
1421 | + |
1422 | + calledMethods = process->calledMethods(); |
1423 | + QString processCommand = ((StringWrapper*)calledMethods[0].params().inParams()[0])->value(); |
1424 | + QStringList processArgs = ((StringListWrapper*)calledMethods[0].params().inParams()[1])->value(); |
1425 | + QCOMPARE(processCommand, command); |
1426 | + QVERIFY(processArgs.contains(download->filePath())); |
1427 | +} |
1428 | |
1429 | === modified file 'ubuntu-download-manager-tests/test_download.h' |
1430 | --- ubuntu-download-manager-tests/test_download.h 2013-07-20 14:08:52 +0000 |
1431 | +++ ubuntu-download-manager-tests/test_download.h 2013-07-21 19:10:31 +0000 |
1432 | @@ -25,6 +25,7 @@ |
1433 | #include <metatypes.h> |
1434 | #include "fake_system_network_info.h" |
1435 | #include "fake_request_factory.h" |
1436 | +#include "fake_process_factory.h" |
1437 | #include "test_runner.h" |
1438 | |
1439 | class TestDownload: public QObject |
1440 | @@ -59,6 +60,9 @@ |
1441 | void testSetGSMDownloadDiff_data(); |
1442 | void testCanDownloadGSM_data(); |
1443 | void testCanDownloadNoGSM_data(); |
1444 | + void testProcessExecutedNoParams_data(); |
1445 | + void testProcessExecutedWithParams_data(); |
1446 | + void testProcessExecutedWithParamsFile_data(); |
1447 | |
1448 | // accessor methods |
1449 | void testPath(); |
1450 | @@ -97,6 +101,11 @@ |
1451 | void testSetRawHeadersResume(); |
1452 | void testSetRawHeadersWithRangeResume(); |
1453 | |
1454 | + // process related tests |
1455 | + void testProcessExecutedNoParams(); |
1456 | + void testProcessExecutedWithParams(); |
1457 | + void testProcessExecutedWithParamsFile(); |
1458 | + |
1459 | private: |
1460 | bool removeDir(const QString& dirName); |
1461 | |
1462 | @@ -110,6 +119,7 @@ |
1463 | QCryptographicHash::Algorithm _algo; |
1464 | FakeSystemNetworkInfo* _networkInfo; |
1465 | FakeRequestFactory* _reqFactory; |
1466 | + FakeProcessFactory* _processFactory; |
1467 | |
1468 | }; |
1469 | |
1470 | |
1471 | === modified file 'ubuntu-download-manager-tests/test_download_queue.cpp' |
1472 | --- ubuntu-download-manager-tests/test_download_queue.cpp 2013-07-20 15:53:38 +0000 |
1473 | +++ ubuntu-download-manager-tests/test_download_queue.cpp 2013-07-21 19:10:31 +0000 |
1474 | @@ -29,9 +29,12 @@ |
1475 | { |
1476 | _networkInfo = new FakeSystemNetworkInfo(); |
1477 | _reqFactory = new FakeRequestFactory(); |
1478 | - _first = new FakeDownload(QUuid::createUuid(), "first-path", QUrl(), QVariantMap(), QMap<QString, QString>(), _networkInfo, _reqFactory); |
1479 | + _processFactory = new FakeProcessFactory(); |
1480 | + _first = new FakeDownload(QUuid::createUuid(), "first-path", QUrl(), QVariantMap(), QMap<QString, QString>(), _networkInfo, |
1481 | + _reqFactory, _processFactory); |
1482 | _firstAdaptor = new DownloadAdaptor(_first); |
1483 | - _second = new FakeDownload(QUuid::createUuid(), "second-path", QUrl(), QVariantMap(), QMap<QString, QString>(), _networkInfo, _reqFactory); |
1484 | + _second = new FakeDownload(QUuid::createUuid(), "second-path", QUrl(), QVariantMap(), QMap<QString, QString>(), _networkInfo, |
1485 | + _reqFactory, _processFactory); |
1486 | _secondAdaptor = new DownloadAdaptor(_second); |
1487 | _q = new DownloadQueue(_networkInfo); |
1488 | } |
1489 | @@ -339,7 +342,6 @@ |
1490 | // cancel the download and expect it to be done |
1491 | _first->record(); |
1492 | QSignalSpy changedSpy(_q, SIGNAL(currentChanged(QString))); |
1493 | - QSignalSpy removedSpy(_q, SIGNAL(downloadRemoved(QString))); |
1494 | _q->add(_first, _firstAdaptor); |
1495 | |
1496 | QVERIFY(_q->currentDownload().isEmpty()); |
1497 | @@ -349,16 +351,12 @@ |
1498 | QVERIFY(_q->currentDownload().isEmpty()); |
1499 | |
1500 | QCOMPARE(changedSpy.count(), 2); |
1501 | - QCOMPARE(removedSpy.count(), 1); |
1502 | |
1503 | QList<QVariant> arguments = changedSpy.takeFirst(); |
1504 | QCOMPARE(arguments.at(0).toString(), _first->path()); |
1505 | arguments = changedSpy.takeFirst(); |
1506 | QVERIFY(arguments.at(0).toString().isEmpty()); |
1507 | |
1508 | - arguments = removedSpy.takeFirst(); |
1509 | - QCOMPARE(arguments.at(0).toString(), _first->path()); |
1510 | - |
1511 | QList<MethodData> calledMethods = _first->calledMethods(); |
1512 | QCOMPARE(3, calledMethods.count()); |
1513 | QCOMPARE(QString("canDownload"), calledMethods[0].methodName()); |
1514 | @@ -373,7 +371,6 @@ |
1515 | _second->record(); |
1516 | |
1517 | QSignalSpy changedSpy(_q, SIGNAL(currentChanged(QString))); |
1518 | - QSignalSpy removedSpy(_q, SIGNAL(downloadRemoved(QString))); |
1519 | _q->add(_first, _firstAdaptor); |
1520 | _q->add(_second, _firstAdaptor); |
1521 | |
1522 | @@ -386,16 +383,12 @@ |
1523 | QCOMPARE(_q->currentDownload(), _second->path()); |
1524 | |
1525 | QCOMPARE(changedSpy.count(), 2); |
1526 | - QCOMPARE(removedSpy.count(), 1); |
1527 | |
1528 | QList<QVariant> arguments = changedSpy.takeFirst(); |
1529 | QCOMPARE(arguments.at(0).toString(), _first->path()); |
1530 | arguments = changedSpy.takeFirst(); |
1531 | QCOMPARE(arguments.at(0).toString(), _second->path()); |
1532 | |
1533 | - arguments = removedSpy.takeFirst(); |
1534 | - QCOMPARE(arguments.at(0).toString(), _first->path()); |
1535 | - |
1536 | QList<MethodData> calledMethods = _first->calledMethods(); |
1537 | QCOMPARE(3, calledMethods.count()); |
1538 | QCOMPARE(QString("canDownload"), calledMethods[0].methodName()); |
1539 | @@ -416,7 +409,6 @@ |
1540 | _second->record(); |
1541 | |
1542 | QSignalSpy changedSpy(_q, SIGNAL(currentChanged(QString))); |
1543 | - QSignalSpy removedSpy(_q, SIGNAL(downloadRemoved(QString))); |
1544 | _q->add(_first, _firstAdaptor); |
1545 | _q->add(_second, _firstAdaptor); |
1546 | |
1547 | @@ -429,16 +421,12 @@ |
1548 | QCOMPARE(_q->currentDownload(), QString("")); |
1549 | |
1550 | QCOMPARE(changedSpy.count(), 2); |
1551 | - QCOMPARE(removedSpy.count(), 1); |
1552 | |
1553 | QList<QVariant> arguments = changedSpy.takeFirst(); |
1554 | QCOMPARE(arguments.at(0).toString(), _first->path()); |
1555 | arguments = changedSpy.takeFirst(); |
1556 | QCOMPARE(arguments.at(0).toString(), QString("")); |
1557 | |
1558 | - arguments = removedSpy.takeFirst(); |
1559 | - QCOMPARE(arguments.at(0).toString(), _first->path()); |
1560 | - |
1561 | QList<MethodData> calledMethods = _first->calledMethods(); |
1562 | QCOMPARE(3, calledMethods.count()); |
1563 | QCOMPARE(QString("canDownload"), calledMethods[0].methodName()); |
1564 | @@ -461,11 +449,6 @@ |
1565 | |
1566 | _first->cancel(); |
1567 | QVERIFY(_q->currentDownload().isEmpty()); |
1568 | - |
1569 | - QCOMPARE(removedSpy.count(), 1); |
1570 | - |
1571 | - QList<QVariant> arguments = removedSpy.takeFirst(); |
1572 | - QCOMPARE(arguments.at(0).toString(), _first->path()); |
1573 | } |
1574 | |
1575 | void TestDownloadQueue::testDownloads() |
1576 | |
1577 | === modified file 'ubuntu-download-manager-tests/test_download_queue.h' |
1578 | --- ubuntu-download-manager-tests/test_download_queue.h 2013-07-20 15:53:38 +0000 |
1579 | +++ ubuntu-download-manager-tests/test_download_queue.h 2013-07-21 19:10:31 +0000 |
1580 | @@ -25,6 +25,7 @@ |
1581 | #include "test_runner.h" |
1582 | #include "fake_download.h" |
1583 | #include "fake_request_factory.h" |
1584 | +#include "fake_process_factory.h" |
1585 | #include "fake_system_network_info.h" |
1586 | |
1587 | class TestDownloadQueue : public QObject |
1588 | @@ -57,6 +58,7 @@ |
1589 | private: |
1590 | FakeSystemNetworkInfo* _networkInfo; |
1591 | FakeRequestFactory* _reqFactory; |
1592 | + FakeProcessFactory* _processFactory; |
1593 | FakeDownload* _first; |
1594 | DownloadAdaptor* _firstAdaptor; |
1595 | FakeDownload* _second; |
1596 | |
1597 | === modified file 'ubuntu-download-manager-tests/ubuntu-download-manager-tests.pro' |
1598 | --- ubuntu-download-manager-tests/ubuntu-download-manager-tests.pro 2013-07-18 20:37:08 +0000 |
1599 | +++ ubuntu-download-manager-tests/ubuntu-download-manager-tests.pro 2013-07-21 19:10:31 +0000 |
1600 | @@ -29,7 +29,9 @@ |
1601 | test_xdg_basedir.cpp \ |
1602 | fake_download_queue.cpp \ |
1603 | fake_uuid_factory.cpp \ |
1604 | - fake_system_network_info.cpp |
1605 | + fake_system_network_info.cpp \ |
1606 | + fake_process.cpp \ |
1607 | + fake_process_factory.cpp |
1608 | |
1609 | HEADERS += \ |
1610 | fake.h \ |
1611 | @@ -47,7 +49,9 @@ |
1612 | test_xdg_basedir.h \ |
1613 | fake_download_queue.h \ |
1614 | fake_uuid_factory.h \ |
1615 | - fake_system_network_info.h |
1616 | + fake_system_network_info.h \ |
1617 | + fake_process.h \ |
1618 | + fake_process_factory.h |
1619 | |
1620 | LIBS += -L$$OUT_PWD/../libubuntudownloadmanager/ -lubuntudownloadmanager |
1621 |
FAILED: Continuous integration, rev:75 jenkins. qa.ubuntu. com/job/ ubuntu- download- manager- ci/6/ jenkins. qa.ubuntu. com/job/ ubuntu- download- manager- saucy-amd64- ci/6 jenkins. qa.ubuntu. com/job/ ubuntu- download- manager- saucy-armfh- ci/6/console
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins: 8080/job/ ubuntu- download- manager- ci/6/rebuild
http://