Merge lp:~mandel/ubuntu-download-manager/set-download-dir into lp:ubuntu-download-manager
- set-download-dir
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 280 |
Proposed branch: | lp:~mandel/ubuntu-download-manager/set-download-dir |
Merge into: | lp:ubuntu-download-manager |
Prerequisite: | lp:~mandel/ubuntu-download-manager/second-reorg |
Diff against target: |
587 lines (+287/-10) 17 files modified
docs/com.canonical.applications.download.xml (+4/-0) src/downloads/client/ubuntu/download_manager/download.h (+9/-0) src/downloads/client/ubuntu/download_manager/download_impl.cpp (+11/-0) src/downloads/client/ubuntu/download_manager/download_impl.h (+2/-0) src/downloads/client/ubuntu/download_manager/download_interface.h (+7/-0) src/downloads/client/ubuntu/download_manager/manager.h (+9/-0) src/downloads/client/ubuntu/download_manager/manager_impl.cpp (+7/-0) src/downloads/client/ubuntu/download_manager/manager_impl.h (+1/-0) src/downloads/priv/ubuntu/downloads/download_adaptor.cpp (+6/-0) src/downloads/priv/ubuntu/downloads/download_adaptor.h (+4/-0) src/downloads/priv/ubuntu/downloads/file_download.cpp (+70/-4) src/downloads/priv/ubuntu/downloads/file_download.h (+4/-1) src/downloads/test-daemon/testing_file_download.h (+1/-1) tests/test_client_download.cpp (+51/-3) tests/test_client_download.h (+7/-0) tests/test_download.cpp (+87/-1) tests/test_download.h (+7/-0) |
To merge this branch: | bzr merge lp:~mandel/ubuntu-download-manager/set-download-dir |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Approve | |
Ubuntu One hackers | Pending | ||
Review via email:
|
Commit message
Allow the clients to change the destination directory of the download.
Description of the change
- 335. By Manuel de la Peña
-
Link bug.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:335
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 336. By Manuel de la Peña
-
Merged second-reorg into set-download-dir.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:336
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 337. By Manuel de la Peña
-
Merged second-reorg into set-download-dir.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:337
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 338. By Manuel de la Peña
-
Merged second-reorg into set-download-dir.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:338
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 339. By Manuel de la Peña
-
Merged second-reorg into set-download-dir.
- 340. By Manuel de la Peña
-
Merged second-reorg into set-download-dir.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:340
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 341. By Manuel de la Peña
-
Merged second-reorg into set-download-dir.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:341
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 342. By Manuel de la Peña
-
Merged second-reorg into set-download-dir.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:342
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 343. By Manuel de la Peña
-
Fixed merge issues.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:343
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 344. By Manuel de la Peña
-
Merged second-reorg into set-download-dir.
- 345. By Manuel de la Peña
-
Merged second-reorg into set-download-dir.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:344
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:345
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 346. By Manuel de la Peña
-
Merged second-reorg into set-download-dir.
- 347. By Manuel de la Peña
-
Merged second-reorg into set-download-dir.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:347
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 348. By Manuel de la Peña
-
Merged second-reorg into set-download-dir.
- 349. By Manuel de la Peña
-
Merged second-reorg into set-download-dir.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:349
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'docs/com.canonical.applications.download.xml' |
2 | --- docs/com.canonical.applications.download.xml 2014-02-11 15:35:52 +0000 |
3 | +++ docs/com.canonical.applications.download.xml 2014-04-15 15:31:42 +0000 |
4 | @@ -22,6 +22,10 @@ |
5 | <arg name="speed" type="t" direction="out"/> |
6 | </method> |
7 | |
8 | + <method name="setDestinationDir"> |
9 | + <arg name="path" type="s" direction="in"/> |
10 | + </method> |
11 | + |
12 | <method name="allowGSMDownload"> |
13 | <arg name="allowed" type="b" direction="in"/> |
14 | </method> |
15 | |
16 | === modified file 'src/downloads/client/ubuntu/download_manager/download.h' |
17 | --- src/downloads/client/ubuntu/download_manager/download.h 2014-04-15 15:31:41 +0000 |
18 | +++ src/downloads/client/ubuntu/download_manager/download.h 2014-04-15 15:31:42 +0000 |
19 | @@ -114,6 +114,15 @@ |
20 | virtual bool isMobileDownloadAllowed() = 0; |
21 | |
22 | /*! |
23 | + \fn void setDestinationDir(const QString& path); |
24 | + |
25 | + Notifies the download manager that the local path of the download |
26 | + must be a different one. This call can only be performed if the |
27 | + download was not started else it will result in an error. |
28 | + */ |
29 | + virtual void setDestinationDir(const QString& path) = 0; |
30 | + |
31 | + /*! |
32 | \fn void setThrottle(qulonglong speed) |
33 | |
34 | Notifies the download manager that the download represented by this |
35 | |
36 | === modified file 'src/downloads/client/ubuntu/download_manager/download_impl.cpp' |
37 | --- src/downloads/client/ubuntu/download_manager/download_impl.cpp 2014-04-15 15:31:41 +0000 |
38 | +++ src/downloads/client/ubuntu/download_manager/download_impl.cpp 2014-04-15 15:31:42 +0000 |
39 | @@ -155,6 +155,17 @@ |
40 | } |
41 | |
42 | void |
43 | +DownloadImpl::setDestinationDir(const QString& path) { |
44 | + QDBusPendingReply<> reply = |
45 | + _dbusInterface->setDestinationDir(path); |
46 | + // block, the call should be fast enough |
47 | + reply.waitForFinished(); |
48 | + if (reply.isError()) { |
49 | + setLastError(reply.error()); |
50 | + } |
51 | +} |
52 | + |
53 | +void |
54 | DownloadImpl::setThrottle(qulonglong speed) { |
55 | QDBusPendingReply<> reply = |
56 | _dbusInterface->setThrottle(speed); |
57 | |
58 | === modified file 'src/downloads/client/ubuntu/download_manager/download_impl.h' |
59 | --- src/downloads/client/ubuntu/download_manager/download_impl.h 2014-04-15 15:31:41 +0000 |
60 | +++ src/downloads/client/ubuntu/download_manager/download_impl.h 2014-04-15 15:31:42 +0000 |
61 | @@ -43,6 +43,7 @@ |
62 | Q_OBJECT |
63 | |
64 | // allow the manager to create downloads |
65 | + friend class ManagerImpl; |
66 | friend class DownloadPendingCallWatcher; |
67 | friend class DownloadManagerPendingCallWatcher; |
68 | |
69 | @@ -57,6 +58,7 @@ |
70 | void allowMobileDownload(bool allowed); |
71 | bool isMobileDownloadAllowed(); |
72 | |
73 | + void setDestinationDir(const QString& path); |
74 | void setThrottle(qulonglong speed); |
75 | qulonglong throttle(); |
76 | |
77 | |
78 | === modified file 'src/downloads/client/ubuntu/download_manager/download_interface.h' |
79 | --- src/downloads/client/ubuntu/download_manager/download_interface.h 2014-02-11 19:57:39 +0000 |
80 | +++ src/downloads/client/ubuntu/download_manager/download_interface.h 2014-04-15 15:31:42 +0000 |
81 | @@ -80,6 +80,13 @@ |
82 | return asyncCallWithArgumentList(QLatin1String("resume"), argumentList); |
83 | } |
84 | |
85 | + inline QDBusPendingReply<> setDestinationDir(const QString &path) |
86 | + { |
87 | + QList<QVariant> argumentList; |
88 | + argumentList << QVariant::fromValue(path); |
89 | + return asyncCallWithArgumentList(QLatin1String("setDestinationDir"), argumentList); |
90 | + } |
91 | + |
92 | inline QDBusPendingReply<> setThrottle(qulonglong speed) |
93 | { |
94 | QList<QVariant> argumentList; |
95 | |
96 | === modified file 'src/downloads/client/ubuntu/download_manager/manager.h' |
97 | --- src/downloads/client/ubuntu/download_manager/manager.h 2014-04-15 15:31:41 +0000 |
98 | +++ src/downloads/client/ubuntu/download_manager/manager.h 2014-04-15 15:31:42 +0000 |
99 | @@ -74,6 +74,15 @@ |
100 | : QObject(parent) {} |
101 | |
102 | /*! |
103 | + \fn void getDownloadForId(const QString& id); |
104 | + |
105 | + Returns a download object for the download with the given id. The |
106 | + id most be valid else the returned download will be in an unknown |
107 | + state meaning that most of the download operations will fail. |
108 | + */ |
109 | + virtual Download* getDownloadForId(const QString& id) = 0; |
110 | + |
111 | + /*! |
112 | \fn void createDownload(DownloadStruct downStruct) |
113 | |
114 | Creates a new download using the data found in the structure. |
115 | |
116 | === modified file 'src/downloads/client/ubuntu/download_manager/manager_impl.cpp' |
117 | --- src/downloads/client/ubuntu/download_manager/manager_impl.cpp 2014-04-15 15:31:41 +0000 |
118 | +++ src/downloads/client/ubuntu/download_manager/manager_impl.cpp 2014-04-15 15:31:42 +0000 |
119 | @@ -18,6 +18,7 @@ |
120 | |
121 | #include <QDebug> |
122 | #include <glog/logging.h> |
123 | +#include "download_impl.h" |
124 | #include "manager_impl.h" |
125 | |
126 | namespace { |
127 | @@ -75,6 +76,12 @@ |
128 | qDBusRegisterMetaType<ProcessErrorStruct>(); |
129 | } |
130 | |
131 | +Download* |
132 | +ManagerImpl::getDownloadForId(const QString& id) { |
133 | + auto down = new DownloadImpl(_conn, _servicePath, QDBusObjectPath(id)); |
134 | + return down; |
135 | +} |
136 | + |
137 | void |
138 | ManagerImpl::createDownload(DownloadStruct downStruct) { |
139 | QDBusPendingCall call = |
140 | |
141 | === modified file 'src/downloads/client/ubuntu/download_manager/manager_impl.h' |
142 | --- src/downloads/client/ubuntu/download_manager/manager_impl.h 2014-04-15 15:31:41 +0000 |
143 | +++ src/downloads/client/ubuntu/download_manager/manager_impl.h 2014-04-15 15:31:42 +0000 |
144 | @@ -51,6 +51,7 @@ |
145 | |
146 | public: |
147 | virtual ~ManagerImpl(); |
148 | + virtual Download* getDownloadForId(const QString& id); |
149 | virtual void createDownload(DownloadStruct downStruct); |
150 | virtual void createDownload(DownloadStruct downStruct, |
151 | DownloadCb cb, |
152 | |
153 | === modified file 'src/downloads/priv/ubuntu/downloads/download_adaptor.cpp' |
154 | --- src/downloads/priv/ubuntu/downloads/download_adaptor.cpp 2014-04-15 15:31:41 +0000 |
155 | +++ src/downloads/priv/ubuntu/downloads/download_adaptor.cpp 2014-04-15 15:31:42 +0000 |
156 | @@ -81,6 +81,12 @@ |
157 | QMetaObject::invokeMethod(parent(), "resume"); |
158 | } |
159 | |
160 | +void DownloadAdaptor::setDestinationDir(const QString &path) |
161 | +{ |
162 | + // handle method call com.canonical.applications.Download.setDestinationDir |
163 | + QMetaObject::invokeMethod(parent(), "setDestinationDir", Q_ARG(QString, path)); |
164 | +} |
165 | + |
166 | void DownloadAdaptor::setThrottle(qulonglong speed) |
167 | { |
168 | // handle method call com.canonical.applications.Download.setThrottle |
169 | |
170 | === modified file 'src/downloads/priv/ubuntu/downloads/download_adaptor.h' |
171 | --- src/downloads/priv/ubuntu/downloads/download_adaptor.h 2014-02-11 15:35:52 +0000 |
172 | +++ src/downloads/priv/ubuntu/downloads/download_adaptor.h 2014-04-15 15:31:42 +0000 |
173 | @@ -50,6 +50,9 @@ |
174 | " <method name=\"throttle\">\n" |
175 | " <arg direction=\"out\" type=\"t\" name=\"speed\"/>\n" |
176 | " </method>\n" |
177 | +" <method name=\"setDestinationDir\">\n" |
178 | +" <arg direction=\"in\" type=\"s\" name=\"path\"/>\n" |
179 | +" </method>\n" |
180 | " <method name=\"allowGSMDownload\">\n" |
181 | " <arg direction=\"in\" type=\"b\" name=\"allowed\"/>\n" |
182 | " </method>\n" |
183 | @@ -116,6 +119,7 @@ |
184 | void pause(); |
185 | qulonglong progress(); |
186 | void resume(); |
187 | + void setDestinationDir(const QString &path); |
188 | void setThrottle(qulonglong speed); |
189 | void start(); |
190 | qulonglong throttle(); |
191 | |
192 | === modified file 'src/downloads/priv/ubuntu/downloads/file_download.cpp' |
193 | --- src/downloads/priv/ubuntu/downloads/file_download.cpp 2014-04-15 15:31:41 +0000 |
194 | +++ src/downloads/priv/ubuntu/downloads/file_download.cpp 2014-04-15 15:31:42 +0000 |
195 | @@ -29,6 +29,8 @@ |
196 | #include <ubuntu/transfers/system/logger.h> |
197 | #include <ubuntu/transfers/system/network_reply.h> |
198 | #include <ubuntu/transfers/system/filename_mutex.h> |
199 | +#include <ubuntu/transfers/system/uuid_factory.h> |
200 | +#include <ubuntu/transfers/system/uuid_utils.h> |
201 | #include "file_download.h" |
202 | |
203 | #define DOWN_LOG(LEVEL) LOG(LEVEL) << ((parent() != nullptr)?"GroupDownload {" + parent()->objectName() + " } ":"") << "Download ID{" << objectName() << " } " |
204 | @@ -63,6 +65,7 @@ |
205 | const QMap<QString, QString>& headers, |
206 | QObject* parent) |
207 | : Download(id, path, isConfined, rootPath, metadata, headers, parent), |
208 | + QDBusContext(), |
209 | _totalSize(0), |
210 | _url(url), |
211 | _hash(""), |
212 | @@ -81,6 +84,7 @@ |
213 | const QMap<QString, QString> &headers, |
214 | QObject* parent) |
215 | : Download(id, path, isConfined, rootPath, metadata, headers, parent), |
216 | + QDBusContext(), |
217 | _totalSize(0), |
218 | _url(url), |
219 | _hash(hash) { |
220 | @@ -237,6 +241,66 @@ |
221 | } |
222 | |
223 | void |
224 | +FileDownload::setDestinationDir(const QString& path) { |
225 | + // we have to perform several checks to ensure the integrity |
226 | + // of the download |
227 | + // 1. Trust apparmor that it will bock the call of this method |
228 | + // from not confined apps |
229 | + // 2. Ensure that the path is an absolute path. |
230 | + // 3. Ensure that the path does exist. |
231 | + // 4. Ensure that the path is a dir. |
232 | + // 5. Ensure that the download was not started |
233 | + QFileInfo info(path); |
234 | + if (!info.isAbsolute()) { |
235 | + DOWN_LOG(WARNING) << "Trying to set destination dir to '" |
236 | + << path << "' when the path is not absolute."; |
237 | + if (calledFromDBus()) { |
238 | + sendErrorReply(QDBusError::InvalidArgs, |
239 | + "The destination dir must be an absolute path."); |
240 | + } |
241 | + return; |
242 | + } |
243 | + |
244 | + if (!info.exists()) { |
245 | + DOWN_LOG(WARNING) << "Trying to set destination dir to '" |
246 | + << path << "' when the path does not exists."; |
247 | + if (calledFromDBus()) { |
248 | + sendErrorReply(QDBusError::InvalidArgs, |
249 | + "The destination dir must be already present in the system."); |
250 | + } |
251 | + return; |
252 | + } |
253 | + |
254 | + if (!info.isDir()) { |
255 | + DOWN_LOG(WARNING) << "Trying to set destination dir to '" |
256 | + << path << "' when the path is not a dir."; |
257 | + if (calledFromDBus()) { |
258 | + sendErrorReply(QDBusError::InvalidArgs, |
259 | + "The destination dir must be a dir and a file was found."); |
260 | + } |
261 | + return; |
262 | + } |
263 | + |
264 | + if (state() == Download::IDLE) { |
265 | + // calculate the new path before we unlock the old one |
266 | + auto desiredPath = path; |
267 | + if (!desiredPath.endsWith(QDir::separator())) { |
268 | + desiredPath += QDir::separator(); |
269 | + } |
270 | + desiredPath += _basename; |
271 | + desiredPath = _fileNameMutex->lockFileName(desiredPath); |
272 | + _tempFilePath = desiredPath + TEMP_EXTENSION; |
273 | + _fileNameMutex->unlockFileName(_filePath); |
274 | + _filePath = desiredPath; |
275 | + } else { |
276 | + if (calledFromDBus()) { |
277 | + sendErrorReply(QDBusError::NotSupported, |
278 | + "The path cannot be changed in a started download."); |
279 | + } |
280 | + } |
281 | +} |
282 | + |
283 | +void |
284 | FileDownload::onDownloadProgress(qint64 currentProgress, qint64 bytesTotal) { |
285 | TRACE << _url << currentProgress << bytesTotal; |
286 | |
287 | @@ -603,10 +667,12 @@ |
288 | // the mutex will ensure that we do not have race conditions about |
289 | // the file names in the download manager |
290 | QString path = _url.path(); |
291 | - QString basename = QFileInfo(path).fileName(); |
292 | + _basename = QFileInfo(path).fileName(); |
293 | |
294 | - if (basename.isEmpty()) |
295 | - basename = DATA_FILE_NAME; |
296 | + if (_basename.isEmpty()) { |
297 | + QScopedPointer<UuidFactory> uuidFactory(new UuidFactory()); |
298 | + _basename = UuidUtils::getDBusString(uuidFactory->createUuid()); |
299 | + } |
300 | |
301 | auto metadataMap = metadata(); |
302 | |
303 | @@ -624,7 +690,7 @@ |
304 | _filePath)); |
305 | } |
306 | } else { |
307 | - auto desiredPath = rootPath() + QDir::separator() + basename; |
308 | + auto desiredPath = rootPath() + QDir::separator() + _basename; |
309 | _filePath = _fileNameMutex->lockFileName(desiredPath); |
310 | _tempFilePath = _filePath + TEMP_EXTENSION; |
311 | } |
312 | |
313 | === modified file 'src/downloads/priv/ubuntu/downloads/file_download.h' |
314 | --- src/downloads/priv/ubuntu/downloads/file_download.h 2014-04-15 15:31:41 +0000 |
315 | +++ src/downloads/priv/ubuntu/downloads/file_download.h 2014-04-15 15:31:42 +0000 |
316 | @@ -19,6 +19,7 @@ |
317 | #ifndef DOWNLOADER_LIB_SINGLE_DOWNLOAD_H |
318 | #define DOWNLOADER_LIB_SINGLE_DOWNLOAD_H |
319 | |
320 | +#include <QtDBus/QDBusContext> |
321 | #include <QFile> |
322 | #include <QNetworkReply> |
323 | #include <QProcess> |
324 | @@ -41,7 +42,7 @@ |
325 | |
326 | namespace Daemon { |
327 | |
328 | -class FileDownload : public Download { |
329 | +class FileDownload : public Download, public QDBusContext { |
330 | Q_OBJECT |
331 | |
332 | public: |
333 | @@ -92,6 +93,7 @@ |
334 | qulonglong progress() override; |
335 | qulonglong totalSize() override; |
336 | virtual void setThrottle(qulonglong speed) override; |
337 | + virtual void setDestinationDir(const QString& path); |
338 | |
339 | signals: |
340 | void finished(const QString& path); |
341 | @@ -132,6 +134,7 @@ |
342 | bool _connected = false; |
343 | qulonglong _totalSize = 0; |
344 | QUrl _url; |
345 | + QString _basename; |
346 | QString _filePath; |
347 | QString _tempFilePath; |
348 | QString _hash; |
349 | |
350 | === modified file 'src/downloads/test-daemon/testing_file_download.h' |
351 | --- src/downloads/test-daemon/testing_file_download.h 2014-04-15 15:31:41 +0000 |
352 | +++ src/downloads/test-daemon/testing_file_download.h 2014-04-15 15:31:42 +0000 |
353 | @@ -26,7 +26,7 @@ |
354 | |
355 | using namespace Ubuntu::DownloadManager::Daemon; |
356 | |
357 | -class TestingFileDownload : public FileDownload, public QDBusContext { |
358 | +class TestingFileDownload : public FileDownload { |
359 | Q_OBJECT |
360 | |
361 | public: |
362 | |
363 | === modified file 'tests/test_client_download.cpp' |
364 | --- tests/test_client_download.cpp 2014-04-15 15:31:41 +0000 |
365 | +++ tests/test_client_download.cpp 2014-04-15 15:31:42 +0000 |
366 | @@ -16,6 +16,7 @@ |
367 | * Boston, MA 02110-1301, USA. |
368 | */ |
369 | |
370 | +#include <QDir> |
371 | #include <QNetworkReply> |
372 | #include <ubuntu/download_manager/error.h> |
373 | #include "test_client_download.h" |
374 | @@ -252,11 +253,11 @@ |
375 | QTest::addColumn<QString>("standardError"); |
376 | |
377 | QTest::newRow("Failed To Start") << 0 << "Failed To Start" |
378 | - << -1 << "" << ""; |
379 | + << -1 << "" << ""; |
380 | QTest::newRow("Crashed") << 1 << "Crashed" << -1 << "Calculating.." |
381 | - << "NULL pointer"; |
382 | + << "NULL pointer"; |
383 | QTest::newRow("Timedout") << 2 << "Timedout" << -1 << "stdout" |
384 | - << ""; |
385 | + << ""; |
386 | } |
387 | |
388 | void |
389 | @@ -289,4 +290,51 @@ |
390 | QCOMPARE(standardError, processError->standardError()); |
391 | } |
392 | |
393 | +void |
394 | +TestDownload::testSetLocalDirectory() { |
395 | + auto path = testDirectory(); |
396 | + _down->setDestinationDir(path); |
397 | + QVERIFY(!_down->isError()); |
398 | + QVERIFY(_down->error() == nullptr); |
399 | +} |
400 | + |
401 | +void |
402 | +TestDownload::testSetLocalDirectoryNotAbsolute() { |
403 | + _down->setDestinationDir("./test"); |
404 | + QVERIFY(_down->isError()); |
405 | + QVERIFY(_down->error() != nullptr); |
406 | + QCOMPARE(Error::DBus, _down->error()->type()); |
407 | +} |
408 | + |
409 | +void |
410 | +TestDownload::testSetLocalDirectoryNotPresent() { |
411 | + _down->setDestinationDir("/etc/test"); |
412 | + QVERIFY(_down->isError()); |
413 | + QVERIFY(_down->error() != nullptr); |
414 | + QCOMPARE(Error::DBus, _down->error()->type()); |
415 | +} |
416 | + |
417 | +void |
418 | +TestDownload::testSetLocalDirectoryNotDir() { |
419 | + auto path = testDirectory() + QDir::separator() + "test"; |
420 | + QFile file(path); |
421 | + file.open(QIODevice::ReadWrite | QFile::Append); |
422 | + file.write(QByteArray(100, 'w')); |
423 | + file.close(); |
424 | + _down->setDestinationDir(path); |
425 | + QVERIFY(_down->isError()); |
426 | + QVERIFY(_down->error() != nullptr); |
427 | + QCOMPARE(Error::DBus, _down->error()->type()); |
428 | +} |
429 | + |
430 | +void |
431 | +TestDownload::testSetLocalDirectoryStarted() { |
432 | + auto path = testDirectory(); |
433 | + _down->start(); |
434 | + _down->setDestinationDir(path); |
435 | + QVERIFY(_down->isError()); |
436 | + QVERIFY(_down->error() != nullptr); |
437 | + QCOMPARE(Error::DBus, _down->error()->type()); |
438 | +} |
439 | + |
440 | QTEST_MAIN(TestDownload) |
441 | |
442 | === modified file 'tests/test_client_download.h' |
443 | --- tests/test_client_download.h 2014-04-15 15:31:41 +0000 |
444 | +++ tests/test_client_download.h 2014-04-15 15:31:42 +0000 |
445 | @@ -55,6 +55,13 @@ |
446 | void testProcessErrorRaised_data(); |
447 | void testProcessErrorRaised(); |
448 | |
449 | + // set local dir tests |
450 | + void testSetLocalDirectory(); |
451 | + void testSetLocalDirectoryNotAbsolute(); |
452 | + void testSetLocalDirectoryNotPresent(); |
453 | + void testSetLocalDirectoryNotDir(); |
454 | + void testSetLocalDirectoryStarted(); |
455 | + |
456 | private: |
457 | QString _url; |
458 | QVariantMap _metadata; |
459 | |
460 | === modified file 'tests/test_download.cpp' |
461 | --- tests/test_download.cpp 2014-04-15 15:31:41 +0000 |
462 | +++ tests/test_download.cpp 2014-04-15 15:31:42 +0000 |
463 | @@ -16,6 +16,7 @@ |
464 | * Boston, MA 02110-1301, USA. |
465 | */ |
466 | |
467 | +#include <QDir> |
468 | #include <QNetworkRequest> |
469 | #include <QSslError> |
470 | #include <ubuntu/download_manager/metatypes.h> |
471 | @@ -46,7 +47,7 @@ |
472 | _isConfined = false; |
473 | _rootPath = testDirectory(); |
474 | _path = "random path to dbus"; |
475 | - _url = QUrl("http://ubuntu.com"); |
476 | + _url = QUrl("http://ubuntu.com/data.txt"); |
477 | _algo = "Sha256"; |
478 | _networkInfo = new MockSystemNetworkInfo(); |
479 | SystemNetworkInfo::setInstance(_networkInfo); |
480 | @@ -3691,4 +3692,89 @@ |
481 | FileNameMutex::deleteInstance(); |
482 | } |
483 | |
484 | +void |
485 | +TestDownload::testSetLocalDirectory() { |
486 | + auto path = testDirectory() + QDir::separator() + "test"; |
487 | + QDir().mkpath(path); |
488 | + |
489 | + EXPECT_CALL(*_networkInfo, isOnline()) |
490 | + .WillRepeatedly(Return(true)); |
491 | + |
492 | + QScopedPointer<FileDownload> download(new FileDownload(_id, _path, |
493 | + _isConfined, _rootPath, _url, _metadata, _headers)); |
494 | + auto original = download->filePath(); |
495 | + download->setDestinationDir(path); |
496 | + QVERIFY(original != download->filePath()); |
497 | + QVERIFY(download->filePath().startsWith(path)); |
498 | + verifyMocks(); |
499 | +} |
500 | + |
501 | +void |
502 | +TestDownload::testSetLocalDirectoryNotAbsolute() { |
503 | + auto path = QString("./path"); |
504 | + EXPECT_CALL(*_networkInfo, isOnline()) |
505 | + .WillRepeatedly(Return(true)); |
506 | + |
507 | + QScopedPointer<FileDownload> download(new FileDownload(_id, _path, |
508 | + _isConfined, _rootPath, _url, _metadata, _headers)); |
509 | + |
510 | + auto original = download->filePath(); |
511 | + download->setDestinationDir(path); |
512 | + QCOMPARE(original, download->filePath()); |
513 | + verifyMocks(); |
514 | +} |
515 | + |
516 | +void |
517 | +TestDownload::testSetLocalDirectoryNotPresent() { |
518 | + auto path = QString("/not/present/path"); |
519 | + EXPECT_CALL(*_networkInfo, isOnline()) |
520 | + .WillRepeatedly(Return(true)); |
521 | + |
522 | + QScopedPointer<FileDownload> download(new FileDownload(_id, _path, |
523 | + _isConfined, _rootPath, _url, _metadata, _headers)); |
524 | + |
525 | + auto original = download->filePath(); |
526 | + download->setDestinationDir(path); |
527 | + QCOMPARE(original, download->filePath()); |
528 | + verifyMocks(); |
529 | +} |
530 | + |
531 | +void |
532 | +TestDownload::testSetLocalDirectoryNotDir() { |
533 | + auto path = testDirectory() + QDir::separator() + "test"; |
534 | + QFile file(path); |
535 | + file.open(QIODevice::ReadWrite | QFile::Append); |
536 | + file.write(QByteArray(100, 'w')); |
537 | + file.close(); |
538 | + |
539 | + EXPECT_CALL(*_networkInfo, isOnline()) |
540 | + .WillRepeatedly(Return(true)); |
541 | + |
542 | + QScopedPointer<FileDownload> download(new FileDownload(_id, _path, |
543 | + _isConfined, _rootPath, _url, _metadata, _headers)); |
544 | + |
545 | + auto original = download->filePath(); |
546 | + download->setDestinationDir(path); |
547 | + QCOMPARE(original, download->filePath()); |
548 | + verifyMocks(); |
549 | +} |
550 | + |
551 | +void |
552 | +TestDownload::testSetLocalDirectoryStarted() { |
553 | + auto path = testDirectory() + QDir::separator() + "test"; |
554 | + QDir().mkpath(path); |
555 | + |
556 | + EXPECT_CALL(*_networkInfo, isOnline()) |
557 | + .WillRepeatedly(Return(true)); |
558 | + |
559 | + QScopedPointer<FileDownload> download(new FileDownload(_id, _path, |
560 | + _isConfined, _rootPath, _url, _metadata, _headers)); |
561 | + |
562 | + auto original = download->filePath(); |
563 | + download->start(); // change state |
564 | + download->setDestinationDir(path); |
565 | + QCOMPARE(original, download->filePath()); |
566 | + verifyMocks(); |
567 | +} |
568 | + |
569 | QTEST_MAIN(TestDownload) |
570 | |
571 | === modified file 'tests/test_download.h' |
572 | --- tests/test_download.h 2014-04-15 15:31:41 +0000 |
573 | +++ tests/test_download.h 2014-04-15 15:31:42 +0000 |
574 | @@ -171,6 +171,13 @@ |
575 | void testErrorUnlocksPath(); |
576 | void testLockCustomLocalPath(); |
577 | |
578 | + // tests related to setting the dir |
579 | + void testSetLocalDirectory(); |
580 | + void testSetLocalDirectoryNotAbsolute(); |
581 | + void testSetLocalDirectoryNotPresent(); |
582 | + void testSetLocalDirectoryNotDir(); |
583 | + void testSetLocalDirectoryStarted(); |
584 | + |
585 | private: |
586 | QString _id; |
587 | bool _isConfined; |
FAILED: Continuous integration, rev:334 jenkins. qa.ubuntu. com/job/ ubuntu- download- manager- ci/489/ jenkins. qa.ubuntu. com/job/ ubuntu- download- manager- trusty- amd64-ci/ 378 jenkins. qa.ubuntu. com/job/ ubuntu- download- manager- trusty- armhf-ci/ 378/console
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/ubuntu- download- manager- ci/489/ rebuild
http://