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