Merge lp:~mandel/ubuntu-download-manager/use-standard-dirs into lp:ubuntu-download-manager
- use-standard-dirs
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Manuel de la Peña |
Approved revision: | 134 |
Merged at revision: | 143 |
Proposed branch: | lp:~mandel/ubuntu-download-manager/use-standard-dirs |
Merge into: | lp:ubuntu-download-manager |
Prerequisite: | lp:~mandel/ubuntu-download-manager/remove-tests-qdebug |
Diff against target: |
1257 lines (+138/-657) 28 files modified
libubuntudownloadmanager/apparmor.cpp (+17/-5) libubuntudownloadmanager/downloads_db.cpp (+16/-6) libubuntudownloadmanager/libubuntudownloadmanager.pro (+0/-2) libubuntudownloadmanager/logger.cpp (+11/-4) libubuntudownloadmanager/single_download.cpp (+0/-1) libubuntudownloadmanager/xdg_basedir.cpp (+0/-204) libubuntudownloadmanager/xdg_basedir.h (+0/-57) ubuntu-download-manager-tests/base_testcase.cpp (+51/-1) ubuntu-download-manager-tests/base_testcase.h (+6/-1) ubuntu-download-manager-tests/test_download.cpp (+5/-41) ubuntu-download-manager-tests/test_download.h (+1/-5) ubuntu-download-manager-tests/test_download_daemon.cpp (+3/-1) ubuntu-download-manager-tests/test_download_daemon.h (+1/-1) ubuntu-download-manager-tests/test_download_factory.cpp (+3/-1) ubuntu-download-manager-tests/test_download_factory.h (+1/-1) ubuntu-download-manager-tests/test_download_manager.cpp (+3/-1) ubuntu-download-manager-tests/test_download_manager.h (+1/-1) ubuntu-download-manager-tests/test_download_queue.cpp (+3/-1) ubuntu-download-manager-tests/test_download_queue.h (+1/-1) ubuntu-download-manager-tests/test_downloads_db.cpp (+6/-40) ubuntu-download-manager-tests/test_downloads_db.h (+1/-5) ubuntu-download-manager-tests/test_group_download.cpp (+3/-1) ubuntu-download-manager-tests/test_group_download.h (+1/-1) ubuntu-download-manager-tests/test_network_reply.cpp (+3/-1) ubuntu-download-manager-tests/test_network_reply.h (+1/-1) ubuntu-download-manager-tests/test_xdg_basedir.cpp (+0/-203) ubuntu-download-manager-tests/test_xdg_basedir.h (+0/-68) ubuntu-download-manager-tests/ubuntu-download-manager-tests.pro (+0/-2) |
To merge this branch: | bzr merge lp:~mandel/ubuntu-download-manager/use-standard-dirs |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Approve | |
Alejandro J. Cura (community) | Approve | ||
Diego Sarmentero (community) | Approve | ||
Review via email: mp+187492@code.launchpad.net |
Commit message
Remove the XDG implementation and use the standard paths class found in qt.
Description of the change
Remove the XDG implementation and use the standard paths class found in qt.
PS Jenkins bot (ps-jenkins) wrote : | # |
Diego Sarmentero (diegosarmentero) wrote : | # |
nice branch
Alejandro J. Cura (alecu) wrote : | # |
"simplify" is the word. One of my favorites.
- 133. By Manuel de la Peña
-
Merged remove-tests-qdebug into use-standard-dirs.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:133
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 134. By Manuel de la Peña
-
Merged remove-tests-qdebug into use-standard-dirs.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:134
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'libubuntudownloadmanager/apparmor.cpp' |
2 | --- libubuntudownloadmanager/apparmor.cpp 2013-09-19 12:17:48 +0000 |
3 | +++ libubuntudownloadmanager/apparmor.cpp 2013-09-25 16:08:38 +0000 |
4 | @@ -23,10 +23,11 @@ |
5 | #include <unistd.h> |
6 | #include <QDBusConnection> |
7 | #include <QDebug> |
8 | +#include <QDir> |
9 | #include <QRegExp> |
10 | +#include <QStandardPaths> |
11 | #include "./dbus_proxy.h" |
12 | #include "./uuid_factory.h" |
13 | -#include "./xdg_basedir.h" |
14 | #include "./apparmor.h" |
15 | |
16 | /* |
17 | @@ -79,9 +80,14 @@ |
18 | // as the local path root |
19 | if (getuid() == 0){ |
20 | qDebug() << "Running as system bus using /tmp for downloads"; |
21 | - return QString("/tmp"); |
22 | + return QStandardPaths::writableLocation( |
23 | + QStandardPaths::TempLocation); |
24 | } else { |
25 | + QString dataPath = QStandardPaths::writableLocation( |
26 | + QStandardPaths::DataLocation); |
27 | QStringList pathComponents; |
28 | + pathComponents << dataPath; |
29 | + |
30 | if (!appId.isEmpty()) { |
31 | QStringList appIdInfo = appId.split("_"); |
32 | if (appIdInfo.count() > 0) |
33 | @@ -89,9 +95,15 @@ |
34 | } |
35 | |
36 | pathComponents << "Downloads"; |
37 | - QString localPath = XDGBasedir::saveDataPath(pathComponents); |
38 | - qDebug() << "Local path is" << localPath; |
39 | - return localPath; |
40 | + |
41 | + QString path = pathComponents.join(QDir::separator()); |
42 | + |
43 | + bool wasCreated = QDir().mkpath(path); |
44 | + if (!wasCreated) { |
45 | + qCritical() << "Could not create the data path" << path; |
46 | + } |
47 | + qDebug() << "Local path is" << path; |
48 | + return path; |
49 | } // not root |
50 | } |
51 | |
52 | |
53 | === modified file 'libubuntudownloadmanager/downloads_db.cpp' |
54 | --- libubuntudownloadmanager/downloads_db.cpp 2013-09-04 10:32:18 +0000 |
55 | +++ libubuntudownloadmanager/downloads_db.cpp 2013-09-25 16:08:38 +0000 |
56 | @@ -17,14 +17,15 @@ |
57 | */ |
58 | |
59 | #include <QDebug> |
60 | +#include <QDir> |
61 | #include <QFile> |
62 | #include <QJsonDocument> |
63 | +#include <QStandardPaths> |
64 | #include <QStringList> |
65 | #include <QSqlDatabase> |
66 | #include <QSqlQuery> |
67 | #include <QSqlError> |
68 | #include "./hash_algorithm.h" |
69 | -#include "./xdg_basedir.h" |
70 | #include "./downloads_db.h" |
71 | |
72 | #define SINGLE_DOWNLOAD_TABLE "CREATE TABLE SingleDownload("\ |
73 | @@ -107,9 +108,16 @@ |
74 | } |
75 | |
76 | void internalInit() { |
77 | - QStringList pathComponents; |
78 | - pathComponents << "download_manager"; |
79 | - _dbName = XDGBasedir::saveDataPath(pathComponents) + "/downloads.db"; |
80 | + |
81 | + QString dataPath = QStandardPaths::writableLocation( |
82 | + QStandardPaths::DataLocation); |
83 | + QString path = dataPath + QDir::separator() + "ubuntu-download-manager"; |
84 | + |
85 | + bool wasCreated = QDir().mkpath(path); |
86 | + if (!wasCreated) { |
87 | + qCritical() << "Could not create the data path" << path; |
88 | + } |
89 | + _dbName = path + QDir::separator() + "downloads.db"; |
90 | _db = QSqlDatabase::addDatabase("QSQLITE"); |
91 | _db.setDatabaseName(_dbName); |
92 | qDebug() << "Db file is" << _dbName; |
93 | @@ -239,11 +247,13 @@ |
94 | query.bindValue(":headers", |
95 | headersToString(download->headers())); |
96 | |
97 | - bool successs = query.exec(); |
98 | + bool success = query.exec(); |
99 | + if (!success) |
100 | + qDebug() << query.lastError(); |
101 | |
102 | _db.close(); |
103 | |
104 | - return successs; |
105 | + return success; |
106 | } |
107 | |
108 | private: |
109 | |
110 | === modified file 'libubuntudownloadmanager/libubuntudownloadmanager.pro' |
111 | --- libubuntudownloadmanager/libubuntudownloadmanager.pro 2013-09-09 09:19:11 +0000 |
112 | +++ libubuntudownloadmanager/libubuntudownloadmanager.pro 2013-09-25 16:08:38 +0000 |
113 | @@ -30,7 +30,6 @@ |
114 | system_network_info.cpp \ |
115 | timer.cpp \ |
116 | uuid_factory.cpp \ |
117 | - xdg_basedir.cpp \ |
118 | download_factory.cpp \ |
119 | file_manager.cpp \ |
120 | download_struct.cpp \ |
121 | @@ -62,7 +61,6 @@ |
122 | system_network_info.h \ |
123 | timer.h \ |
124 | uuid_factory.h \ |
125 | - xdg_basedir.h \ |
126 | download_factory.h \ |
127 | file_manager.h \ |
128 | download_struct.h \ |
129 | |
130 | === modified file 'libubuntudownloadmanager/logger.cpp' |
131 | --- libubuntudownloadmanager/logger.cpp 2013-09-23 11:50:04 +0000 |
132 | +++ libubuntudownloadmanager/logger.cpp 2013-09-25 16:08:38 +0000 |
133 | @@ -19,9 +19,9 @@ |
134 | #include <unistd.h> |
135 | #include <sys/types.h> |
136 | #include <QDateTime> |
137 | +#include <QDebug> |
138 | #include <QDir> |
139 | #include <QStandardPaths> |
140 | -#include "./xdg_basedir.h" |
141 | #include "./logger.h" |
142 | |
143 | |
144 | @@ -119,9 +119,16 @@ |
145 | |
146 | QString |
147 | Logger::getLogDir() { |
148 | - QStringList pathComponents; |
149 | - pathComponents << "ubuntu-download-manager"; |
150 | - return XDGBasedir::saveCachePath(pathComponents); |
151 | + QString cachePath = QStandardPaths::writableLocation( |
152 | + QStandardPaths::CacheLocation); |
153 | + QString path = cachePath + QDir::separator() + "ubuntu-download-manager"; |
154 | + qDebug() << "Logging dir is" << path; |
155 | + |
156 | + bool wasCreated = QDir().mkpath(path); |
157 | + if (!wasCreated) { |
158 | + qCritical() << "Could not create the logging path" << path; |
159 | + } |
160 | + return path; |
161 | } |
162 | |
163 | void |
164 | |
165 | === modified file 'libubuntudownloadmanager/single_download.cpp' |
166 | --- libubuntudownloadmanager/single_download.cpp 2013-09-25 16:08:38 +0000 |
167 | +++ libubuntudownloadmanager/single_download.cpp 2013-09-25 16:08:38 +0000 |
168 | @@ -27,7 +27,6 @@ |
169 | #include "./hash_algorithm.h" |
170 | #include "./single_download.h" |
171 | #include "./network_reply.h" |
172 | -#include "./xdg_basedir.h" |
173 | |
174 | #define DATA_FILE_NAME "data.download" |
175 | #define METADATA_FILE_NAME "metadata" |
176 | |
177 | === removed file 'libubuntudownloadmanager/xdg_basedir.cpp' |
178 | --- libubuntudownloadmanager/xdg_basedir.cpp 2013-07-25 21:28:12 +0000 |
179 | +++ libubuntudownloadmanager/xdg_basedir.cpp 1970-01-01 00:00:00 +0000 |
180 | @@ -1,204 +0,0 @@ |
181 | -/* |
182 | - * Copyright 2013 Canonical Ltd. |
183 | - * |
184 | - * This library is free software; you can redistribute it and/or |
185 | - * modify it under the terms of version 3 of the GNU Lesser General Public |
186 | - * License as published by the Free Software Foundation. |
187 | - * |
188 | - * This program is distributed in the hope that it will be useful, |
189 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
190 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
191 | - * General Public License for more details. |
192 | - * |
193 | - * You should have received a copy of the GNU Lesser General Public |
194 | - * License along with this library; if not, write to the |
195 | - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
196 | - * Boston, MA 02110-1301, USA. |
197 | - */ |
198 | - |
199 | -#include <QDebug> |
200 | -#include <QDir> |
201 | -#include <QFile> |
202 | -#include <stdlib.h> |
203 | -#include "./xdg_basedir.h" |
204 | - |
205 | -// definitions of defaults |
206 | -#define DEFAULT_CACHE_HOME ".cache" |
207 | -#define DEFAULT_CONFIG_PATH "/etc/xdg" |
208 | -#define DEFAULT_CONFIG_HOME ".config" |
209 | -#define DEFAULT_DATA_PATH "/usr/local/share:/usr/share" |
210 | -#define DEFAULT_DATA_HOME ".local/share" |
211 | -#define XDG_CACHE_HOME "XDG_CACHE_HOME" |
212 | -#define XDG_CONFIG_HOME "XDG_CONFIG_HOME" |
213 | -#define XDG_DATA_HOME "XDG_DATA_HOME" |
214 | -#define XDG_CONFIG_DIRS "XDG_CONFIG_DIRS" |
215 | -#define XDG_DATA_DIRS "XDG_DATA_DIRS" |
216 | - |
217 | -QString |
218 | -XDGBasedir::cacheHome() { |
219 | - QString env_path = QString::fromUtf8(getenv(XDG_CACHE_HOME)).trimmed(); |
220 | - if (env_path.isEmpty()) { |
221 | - QString defaultValue = QDir(QDir::homePath()).filePath( |
222 | - DEFAULT_CACHE_HOME); |
223 | - return defaultValue; |
224 | - } |
225 | - return env_path; |
226 | -} |
227 | - |
228 | -QString |
229 | -XDGBasedir::configHome() { |
230 | - QString env_path = QString::fromUtf8(getenv(XDG_CONFIG_HOME)).trimmed(); |
231 | - if (env_path.isEmpty()) { |
232 | - QString defaultValue = QDir(QDir::homePath()).filePath( |
233 | - DEFAULT_CONFIG_HOME); |
234 | - return defaultValue; |
235 | - } |
236 | - return env_path; |
237 | -} |
238 | - |
239 | -QString |
240 | -XDGBasedir::dataHome() { |
241 | - QString env_path = QString::fromUtf8(getenv(XDG_DATA_HOME)).trimmed(); |
242 | - if (env_path.isEmpty()) { |
243 | - QString defaultValue = QDir(QDir::homePath()).filePath( |
244 | - DEFAULT_DATA_HOME); |
245 | - return defaultValue; |
246 | - } |
247 | - return env_path; |
248 | -} |
249 | - |
250 | -QList<QString> |
251 | -XDGBasedir::configDirs() { |
252 | - QList<QString> result; |
253 | - result.append(XDGBasedir::configHome()); |
254 | - |
255 | - QString env_path = QString::fromUtf8(getenv(XDG_CONFIG_DIRS)).trimmed(); |
256 | - if (env_path.isEmpty()) { |
257 | - return result; |
258 | - } |
259 | - |
260 | - QStringList paths = env_path.split(":"); |
261 | - result.append(paths); |
262 | - |
263 | - return result; |
264 | -} |
265 | - |
266 | -QList<QString> |
267 | -XDGBasedir::dataDirs() { |
268 | - QList<QString> result; |
269 | - result.append(XDGBasedir::dataHome()); |
270 | - |
271 | - QString env_path = QString::fromUtf8(getenv(XDG_DATA_DIRS)).trimmed(); |
272 | - if (env_path.isEmpty()) { |
273 | - return result; |
274 | - } |
275 | - |
276 | - QStringList paths = env_path.split(":"); |
277 | - result.append(paths); |
278 | - return result; |
279 | -} |
280 | - |
281 | -QList<QString> |
282 | -XDGBasedir::configPaths(QList<QString> resources) { |
283 | - QList<QString> result; |
284 | - QList<QString> configDirs = XDGBasedir::configDirs(); |
285 | - foreach (QString configDir, configDirs) { // NOLINT(whitespace/parens) |
286 | - QStringList pathComponents; |
287 | - pathComponents.append(configDir); |
288 | - pathComponents.append(resources); |
289 | - QString path = pathComponents.join(QDir::separator()); |
290 | - if (QFile::exists(path)) { |
291 | - result.append(path); |
292 | - } |
293 | - } |
294 | - |
295 | - return result; |
296 | -} |
297 | - |
298 | -QList<QString> |
299 | -XDGBasedir::dataPaths(QList<QString> resources) { |
300 | - QList<QString> result; |
301 | - QList<QString> dataDirs = XDGBasedir::dataDirs(); |
302 | - foreach (QString dataDir, dataDirs) { // NOLINT(whitespace/parens) |
303 | - QStringList pathComponents; |
304 | - pathComponents.append(dataDir); |
305 | - pathComponents.append(resources); |
306 | - QString path = pathComponents.join(QDir::separator()); |
307 | - if (QFile::exists(path)) { |
308 | - result.append(path); |
309 | - } |
310 | - } |
311 | - return result; |
312 | -} |
313 | - |
314 | -QString |
315 | -XDGBasedir::loadFirstConfig(QList<QString> resource) { |
316 | - QList<QString> configPaths = XDGBasedir::configPaths(resource); |
317 | - return configPaths.at(0); |
318 | -} |
319 | - |
320 | -QString |
321 | -XDGBasedir::saveCachePath(QList<QString> resources){ |
322 | - QString home = XDGBasedir::cacheHome(); |
323 | - QStringList pathComponents; |
324 | - pathComponents.append(home); |
325 | - pathComponents.append(resources); |
326 | - QString path = pathComponents.join(QDir::separator()); |
327 | - QFileInfo info = QFileInfo(path); |
328 | - if (!info.exists() || !info.isDir()) { |
329 | - QDir dir(home); |
330 | - QStringList child; |
331 | - child.append(resources); |
332 | - bool created = dir.mkpath(child.join(QDir::separator())); |
333 | - if (!created) { |
334 | - qCritical() << "Could not create path:" |
335 | - << child.join(QDir::separator()); |
336 | - return QString(""); |
337 | - } |
338 | - } |
339 | - return path; |
340 | -} |
341 | - |
342 | -QString |
343 | -XDGBasedir::saveConfigPath(QList<QString> resources) { |
344 | - QString home = XDGBasedir::configHome(); |
345 | - QStringList pathComponents; |
346 | - pathComponents.append(home); |
347 | - pathComponents.append(resources); |
348 | - QString path = pathComponents.join(QDir::separator()); |
349 | - QFileInfo info = QFileInfo(path); |
350 | - if (!info.exists() || !info.isDir()) { |
351 | - QDir dir(home); |
352 | - QStringList child; |
353 | - child.append(resources); |
354 | - bool created = dir.mkpath(child.join(QDir::separator())); |
355 | - if (!created) { |
356 | - qCritical() << "Could not create path:" |
357 | - << child.join(QDir::separator()); |
358 | - return QString(""); |
359 | - } |
360 | - } |
361 | - return path; |
362 | -} |
363 | - |
364 | -QString |
365 | -XDGBasedir::saveDataPath(QList<QString> resources) { |
366 | - QString home = XDGBasedir::dataHome(); |
367 | - QStringList pathComponents; |
368 | - pathComponents.append(home); |
369 | - pathComponents.append(resources); |
370 | - QString path = pathComponents.join(QDir::separator()); |
371 | - QFileInfo info = QFileInfo(path); |
372 | - if (!info.exists() || !info.isDir()) { |
373 | - QDir dir(home); |
374 | - QStringList child; |
375 | - child.append(resources); |
376 | - bool created = dir.mkpath(child.join(QDir::separator())); |
377 | - if (!created) { |
378 | - qCritical() << "Could not create path:" |
379 | - << child.join(QDir::separator()); |
380 | - return QString(""); |
381 | - } |
382 | - } |
383 | - return path; |
384 | -} |
385 | |
386 | === removed file 'libubuntudownloadmanager/xdg_basedir.h' |
387 | --- libubuntudownloadmanager/xdg_basedir.h 2013-07-25 21:28:12 +0000 |
388 | +++ libubuntudownloadmanager/xdg_basedir.h 1970-01-01 00:00:00 +0000 |
389 | @@ -1,57 +0,0 @@ |
390 | -/* |
391 | - * Copyright 2013 Canonical Ltd. |
392 | - * |
393 | - * This library is free software; you can redistribute it and/or |
394 | - * modify it under the terms of version 3 of the GNU Lesser General Public |
395 | - * License as published by the Free Software Foundation. |
396 | - * |
397 | - * This program is distributed in the hope that it will be useful, |
398 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
399 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
400 | - * General Public License for more details. |
401 | - * |
402 | - * You should have received a copy of the GNU Lesser General Public |
403 | - * License along with this library; if not, write to the |
404 | - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
405 | - * Boston, MA 02110-1301, USA. |
406 | - */ |
407 | - |
408 | -#ifndef DOWNLOADER_LIB_XDG_BASEDIR_H |
409 | -#define DOWNLOADER_LIB_XDG_BASEDIR_H |
410 | - |
411 | -#include <QList> |
412 | -#include <QObject> |
413 | -#include <QString> |
414 | -#include <stdio.h> |
415 | -#include <string> |
416 | - |
417 | -class XDGBasedir : public QObject { |
418 | - Q_OBJECT |
419 | - |
420 | - public: |
421 | - static QString cacheHome(); |
422 | - static QString configHome(); |
423 | - static QString dataHome(); |
424 | - static QList<QString> configDirs(); |
425 | - static QList<QString> dataDirs(); |
426 | - static QList<QString> configPaths(QList<QString> resource); |
427 | - static QList<QString> dataPaths(QList<QString> resource); |
428 | - static QString loadFirstConfig(QList<QString> resource); |
429 | - static QString saveCachePath(QList<QString> resources); |
430 | - static QString saveConfigPath(QList<QString> resource); |
431 | - static QString saveDataPath(QList<QString> resource); |
432 | - |
433 | - private: |
434 | - static QString DEFAULT_CACHE_HOME; |
435 | - static QString DEFAULT_CONFIG_HOME; |
436 | - static QString DEFAULT_CONFIG_PATH; |
437 | - static QString DEFAULT_DATA_PATH; |
438 | - static QString DEFAULT_DATA_HOME; |
439 | - static std::string XDG_CACHE_HOME; |
440 | - static std::string XDG_CONFIG_HOME; |
441 | - static std::string XDG_DATA_HOME; |
442 | - static std::string XDG_CONFIG_DIRS; |
443 | - static std::string XDG_DATA_DIRS; |
444 | -}; |
445 | - |
446 | -#endif // DOWNLOADER_LIB_XDG_BASEDIR_H |
447 | |
448 | === modified file 'ubuntu-download-manager-tests/base_testcase.cpp' |
449 | --- ubuntu-download-manager-tests/base_testcase.cpp 2013-09-25 16:08:38 +0000 |
450 | +++ ubuntu-download-manager-tests/base_testcase.cpp 2013-09-25 16:08:38 +0000 |
451 | @@ -16,7 +16,9 @@ |
452 | * Boston, MA 02110-1301, USA. |
453 | */ |
454 | |
455 | +#include <QDir> |
456 | #include <QtGlobal> |
457 | +#include <QStandardPaths> |
458 | #include "./base_testcase.h" |
459 | |
460 | void |
461 | @@ -29,11 +31,59 @@ |
462 | // do nothing |
463 | } |
464 | |
465 | -BaseTestCase::BaseTestCase(QObject *parent) |
466 | +BaseTestCase::BaseTestCase(const QString& testName, QObject *parent) |
467 | : QObject(parent) { |
468 | + setObjectName(testName); |
469 | +} |
470 | + |
471 | +QString |
472 | +BaseTestCase::testDirectory() { |
473 | + // return the test directory using the standard paths |
474 | + QString dataPath = QStandardPaths::writableLocation( |
475 | + QStandardPaths::DataLocation); |
476 | + QStringList pathComponents; |
477 | + pathComponents << dataPath << objectName(); |
478 | + QString path = pathComponents.join(QDir::separator()); |
479 | + |
480 | + if (!QDir().exists(path)) |
481 | + QDir().mkpath(path); |
482 | + |
483 | + return path; |
484 | +} |
485 | + |
486 | +bool |
487 | +BaseTestCase::removeDir(const QString& dirName) { |
488 | + bool result = true; |
489 | + QDir dir(dirName); |
490 | + |
491 | + QFlags<QDir::Filter> filter = QDir::NoDotAndDotDot | QDir::System |
492 | + | QDir::Hidden | QDir::AllDirs | QDir::Files; |
493 | + if (dir.exists(dirName)) { |
494 | + foreach(QFileInfo info, dir.entryInfoList(filter, QDir::DirsFirst)) { |
495 | + if (info.isDir()) { |
496 | + result = removeDir(info.absoluteFilePath()); |
497 | + } else { |
498 | + result = QFile::remove(info.absoluteFilePath()); |
499 | + } |
500 | + |
501 | + if (!result) { |
502 | + return result; |
503 | + } |
504 | + } |
505 | + result = dir.rmdir(dirName); |
506 | + } |
507 | + |
508 | + return result; |
509 | } |
510 | |
511 | void |
512 | BaseTestCase::init() { |
513 | qInstallMessageHandler(noMessageOutput); |
514 | + QStandardPaths::enableTestMode(true); |
515 | +} |
516 | + |
517 | +void |
518 | +BaseTestCase::cleanup() { |
519 | + // remove the test dir if exists |
520 | + removeDir(testDirectory()); |
521 | } |
522 | |
523 | === modified file 'ubuntu-download-manager-tests/base_testcase.h' |
524 | --- ubuntu-download-manager-tests/base_testcase.h 2013-09-25 16:08:38 +0000 |
525 | +++ ubuntu-download-manager-tests/base_testcase.h 2013-09-25 16:08:38 +0000 |
526 | @@ -25,12 +25,17 @@ |
527 | { |
528 | Q_OBJECT |
529 | public: |
530 | - explicit BaseTestCase(QObject *parent = 0); |
531 | + BaseTestCase(const QString& testName, QObject *parent = 0); |
532 | |
533 | + QString testDirectory(); |
534 | + |
535 | protected slots: // NOLINT(whitespace/indent) |
536 | |
537 | virtual void init(); |
538 | + virtual void cleanup(); |
539 | |
540 | + private: |
541 | + bool removeDir(const QString& dirName); |
542 | }; |
543 | |
544 | #endif // BASE_TESTCASE_H |
545 | |
546 | === modified file 'ubuntu-download-manager-tests/test_download.cpp' |
547 | --- ubuntu-download-manager-tests/test_download.cpp 2013-09-25 16:08:38 +0000 |
548 | +++ ubuntu-download-manager-tests/test_download.cpp 2013-09-25 16:08:38 +0000 |
549 | @@ -17,7 +17,6 @@ |
550 | */ |
551 | |
552 | #include <QDebug> |
553 | -#include <stdlib.h> |
554 | #include <QNetworkRequest> |
555 | #include <QSignalSpy> |
556 | #include <QSslError> |
557 | @@ -27,50 +26,16 @@ |
558 | #include "./test_download.h" |
559 | |
560 | TestDownload::TestDownload(QObject* parent) |
561 | - : BaseTestCase(parent) { |
562 | -} |
563 | - |
564 | -bool |
565 | -TestDownload::removeDir(const QString& dirName) { |
566 | - bool result = true; |
567 | - QDir dir(dirName); |
568 | - |
569 | - QFlags<QDir::Filter> filter = QDir::NoDotAndDotDot | QDir::System |
570 | - | QDir::Hidden | QDir::AllDirs | QDir::Files; |
571 | - if (dir.exists(dirName)) { |
572 | - foreach(QFileInfo info, dir.entryInfoList(filter, QDir::DirsFirst)) { |
573 | - if (info.isDir()) { |
574 | - result = removeDir(info.absoluteFilePath()); |
575 | - } else { |
576 | - result = QFile::remove(info.absoluteFilePath()); |
577 | - } |
578 | - |
579 | - if (!result) { |
580 | - return result; |
581 | - } |
582 | - } |
583 | - result = dir.rmdir(dirName); |
584 | - } |
585 | - |
586 | - return result; |
587 | + : BaseTestCase("TestDownload", parent) { |
588 | } |
589 | |
590 | void |
591 | TestDownload::init() { |
592 | BaseTestCase::init(); |
593 | - // set the xdg path so that we have control over it |
594 | - _testDir = QDir("./tests"); |
595 | - _testDir.makeAbsolute(); |
596 | - |
597 | - if (!_testDir.exists()) { |
598 | - _testDir.mkpath(_testDir.absolutePath()); |
599 | - } |
600 | - |
601 | - setenv("XDG_DATA_HOME", |
602 | - _testDir.absolutePath().toStdString().c_str(), 1); |
603 | + |
604 | _id = QUuid::createUuid(); |
605 | _isConfined = false; |
606 | - _rootPath = _testDir.absolutePath(); |
607 | + _rootPath = testDirectory(); |
608 | _path = "random path to dbus"; |
609 | _url = QUrl("http://ubuntu.com"); |
610 | _algo = "Sha256"; |
611 | @@ -81,6 +46,8 @@ |
612 | |
613 | void |
614 | TestDownload::cleanup() { |
615 | + BaseTestCase::cleanup(); |
616 | + |
617 | if (_networkInfo) |
618 | delete _networkInfo; |
619 | if (_reqFactory) |
620 | @@ -88,9 +55,6 @@ |
621 | if (_processFactory) |
622 | delete _processFactory; |
623 | |
624 | - // try to remove the test dir |
625 | - removeDir(_testDir.absolutePath()); |
626 | - unsetenv("XDG_DATA_HOME"); |
627 | } |
628 | |
629 | void |
630 | |
631 | === modified file 'ubuntu-download-manager-tests/test_download.h' |
632 | --- ubuntu-download-manager-tests/test_download.h 2013-09-25 16:08:38 +0000 |
633 | +++ ubuntu-download-manager-tests/test_download.h 2013-09-25 16:08:38 +0000 |
634 | @@ -38,7 +38,7 @@ |
635 | private slots: // NOLINT(whitespace/indent) |
636 | |
637 | void init() override; |
638 | - void cleanup(); |
639 | + void cleanup() override; |
640 | |
641 | // constructors tests |
642 | void testNoHashConstructor(); |
643 | @@ -132,10 +132,6 @@ |
644 | void testValidHashAlgorithm(); |
645 | |
646 | private: |
647 | - bool removeDir(const QString& dirName); |
648 | - |
649 | - private: |
650 | - QDir _testDir; |
651 | QUuid _id; |
652 | bool _isConfined; |
653 | QString _rootPath; |
654 | |
655 | === modified file 'ubuntu-download-manager-tests/test_download_daemon.cpp' |
656 | --- ubuntu-download-manager-tests/test_download_daemon.cpp 2013-09-25 16:08:38 +0000 |
657 | +++ ubuntu-download-manager-tests/test_download_daemon.cpp 2013-09-25 16:08:38 +0000 |
658 | @@ -19,7 +19,7 @@ |
659 | #include "./test_download_daemon.h" |
660 | |
661 | TestDownloadDaemon::TestDownloadDaemon(QObject *parent) |
662 | - : BaseTestCase(parent) { |
663 | + : BaseTestCase("TestDownloadDaemon", parent) { |
664 | } |
665 | |
666 | void |
667 | @@ -37,6 +37,8 @@ |
668 | |
669 | void |
670 | TestDownloadDaemon::cleanup() { |
671 | + BaseTestCase::cleanup(); |
672 | + |
673 | if (_app != NULL) |
674 | delete _app; |
675 | if (_conn != NULL) |
676 | |
677 | === modified file 'ubuntu-download-manager-tests/test_download_daemon.h' |
678 | --- ubuntu-download-manager-tests/test_download_daemon.h 2013-09-25 16:08:38 +0000 |
679 | +++ ubuntu-download-manager-tests/test_download_daemon.h 2013-09-25 16:08:38 +0000 |
680 | @@ -37,7 +37,7 @@ |
681 | private slots: // NOLINT(whitespace/indent) |
682 | |
683 | void init() override; |
684 | - void cleanup(); |
685 | + void cleanup() override; |
686 | void testStart(); |
687 | void testStartFailServiceRegister(); |
688 | void testStartFailObjectRegister(); |
689 | |
690 | === modified file 'ubuntu-download-manager-tests/test_download_factory.cpp' |
691 | --- ubuntu-download-manager-tests/test_download_factory.cpp 2013-09-25 16:08:38 +0000 |
692 | +++ ubuntu-download-manager-tests/test_download_factory.cpp 2013-09-25 16:08:38 +0000 |
693 | @@ -21,7 +21,7 @@ |
694 | #include "./test_download_factory.h" |
695 | |
696 | TestDownloadFactory::TestDownloadFactory(QObject *parent) |
697 | - : BaseTestCase(parent) { |
698 | + : BaseTestCase("TestDownloadFactory", parent) { |
699 | } |
700 | |
701 | void |
702 | @@ -40,6 +40,8 @@ |
703 | |
704 | void |
705 | TestDownloadFactory::cleanup() { |
706 | + BaseTestCase::cleanup(); |
707 | + |
708 | if (_downFactory != NULL) |
709 | delete _downFactory; |
710 | } |
711 | |
712 | === modified file 'ubuntu-download-manager-tests/test_download_factory.h' |
713 | --- ubuntu-download-manager-tests/test_download_factory.h 2013-09-25 16:08:38 +0000 |
714 | +++ ubuntu-download-manager-tests/test_download_factory.h 2013-09-25 16:08:38 +0000 |
715 | @@ -38,7 +38,7 @@ |
716 | private slots: // NOLINT(whitespace/indent) |
717 | |
718 | void init() override; |
719 | - void cleanup(); |
720 | + void cleanup() override; |
721 | |
722 | void testCreateDownload(); |
723 | void testCreateDownloadWithHash(); |
724 | |
725 | === modified file 'ubuntu-download-manager-tests/test_download_manager.cpp' |
726 | --- ubuntu-download-manager-tests/test_download_manager.cpp 2013-09-25 16:08:38 +0000 |
727 | +++ ubuntu-download-manager-tests/test_download_manager.cpp 2013-09-25 16:08:38 +0000 |
728 | @@ -24,7 +24,7 @@ |
729 | #include "./test_download_manager.h" |
730 | |
731 | TestDownloadManager::TestDownloadManager(QObject *parent) |
732 | - : BaseTestCase(parent) { |
733 | + : BaseTestCase("TestDownloadManager", parent) { |
734 | } |
735 | |
736 | void |
737 | @@ -51,6 +51,8 @@ |
738 | |
739 | void |
740 | TestDownloadManager::cleanup() { |
741 | + BaseTestCase::cleanup(); |
742 | + |
743 | if (_networkInfo) |
744 | delete _networkInfo; |
745 | if (_q != NULL) |
746 | |
747 | === modified file 'ubuntu-download-manager-tests/test_download_manager.h' |
748 | --- ubuntu-download-manager-tests/test_download_manager.h 2013-09-25 16:08:38 +0000 |
749 | +++ ubuntu-download-manager-tests/test_download_manager.h 2013-09-25 16:08:38 +0000 |
750 | @@ -43,7 +43,7 @@ |
751 | private slots: // NOLINT(whitespace/indent) |
752 | |
753 | void init() override; |
754 | - void cleanup(); |
755 | + void cleanup() override; |
756 | |
757 | // data functions |
758 | void testCreateDownload_data(); |
759 | |
760 | === modified file 'ubuntu-download-manager-tests/test_download_queue.cpp' |
761 | --- ubuntu-download-manager-tests/test_download_queue.cpp 2013-09-25 16:08:38 +0000 |
762 | +++ ubuntu-download-manager-tests/test_download_queue.cpp 2013-09-25 16:08:38 +0000 |
763 | @@ -21,7 +21,7 @@ |
764 | #include "./test_download_queue.h" |
765 | |
766 | TestDownloadQueue::TestDownloadQueue(QObject *parent) |
767 | - : BaseTestCase(parent) { |
768 | + : BaseTestCase("TestDownloadQueue", parent) { |
769 | } |
770 | |
771 | void |
772 | @@ -49,6 +49,8 @@ |
773 | |
774 | void |
775 | TestDownloadQueue::cleanup() { |
776 | + BaseTestCase::cleanup(); |
777 | + |
778 | if (_q != NULL) |
779 | delete _q; |
780 | |
781 | |
782 | === modified file 'ubuntu-download-manager-tests/test_download_queue.h' |
783 | --- ubuntu-download-manager-tests/test_download_queue.h 2013-09-25 16:08:38 +0000 |
784 | +++ ubuntu-download-manager-tests/test_download_queue.h 2013-09-25 16:08:38 +0000 |
785 | @@ -38,7 +38,7 @@ |
786 | private slots: // NOLINT(whitespace/indent) |
787 | |
788 | void init() override; |
789 | - void cleanup(); |
790 | + void cleanup() override; |
791 | |
792 | void testAddDownload(); |
793 | void testStartDownloadWithNoCurrent(); |
794 | |
795 | === modified file 'ubuntu-download-manager-tests/test_downloads_db.cpp' |
796 | --- ubuntu-download-manager-tests/test_downloads_db.cpp 2013-09-25 16:08:38 +0000 |
797 | +++ ubuntu-download-manager-tests/test_downloads_db.cpp 2013-09-25 16:08:38 +0000 |
798 | @@ -38,58 +38,24 @@ |
799 | "FROM SingleDownload WHERE uuid=:uuid;" |
800 | |
801 | TestDownloadsDb::TestDownloadsDb(QObject *parent) |
802 | - : BaseTestCase(parent) { |
803 | -} |
804 | - |
805 | -bool |
806 | -TestDownloadsDb::removeDir(const QString& dirName) { |
807 | - bool result = true; |
808 | - QDir dir(dirName); |
809 | - |
810 | - QFlags<QDir::Filter> filter = QDir::NoDotAndDotDot | QDir::System |
811 | - | QDir::Hidden | QDir::AllDirs | QDir::Files; |
812 | - if (dir.exists(dirName)) { |
813 | - foreach(QFileInfo info, dir.entryInfoList(filter, QDir::DirsFirst)) { |
814 | - qDebug() << "Removing" << info.absoluteFilePath(); |
815 | - if (info.isDir()) { |
816 | - result = removeDir(info.absoluteFilePath()); |
817 | - } else { |
818 | - result = QFile::remove(info.absoluteFilePath()); |
819 | - } |
820 | - |
821 | - if (!result) { |
822 | - return result; |
823 | - } |
824 | - } |
825 | - result = dir.rmdir(dirName); |
826 | - } |
827 | - |
828 | - return result; |
829 | + : BaseTestCase("TestDownloadsDb", parent) { |
830 | } |
831 | |
832 | void |
833 | TestDownloadsDb::init() { |
834 | BaseTestCase::init(); |
835 | - _testDir = QDir("./tests"); |
836 | - _testDir.makeAbsolute(); |
837 | - |
838 | - if (!_testDir.exists()) { |
839 | - _testDir.mkpath(_testDir.absolutePath()); |
840 | - } |
841 | - |
842 | - setenv("XDG_DATA_HOME", |
843 | - _testDir.absolutePath().toStdString().c_str(), 1); |
844 | - |
845 | _db = new DownloadsDb(); |
846 | } |
847 | |
848 | void |
849 | TestDownloadsDb::cleanup() { |
850 | - // try to remove the test dir |
851 | + BaseTestCase::cleanup(); |
852 | + QString dbFile = _db->filename(); |
853 | + |
854 | if (_db != NULL) |
855 | delete _db; |
856 | - removeDir(_testDir.absolutePath()); |
857 | - unsetenv("XDG_DATA_HOME"); |
858 | + |
859 | + QFile::remove(dbFile); |
860 | } |
861 | |
862 | void |
863 | |
864 | === modified file 'ubuntu-download-manager-tests/test_downloads_db.h' |
865 | --- ubuntu-download-manager-tests/test_downloads_db.h 2013-09-25 16:08:38 +0000 |
866 | +++ ubuntu-download-manager-tests/test_downloads_db.h 2013-09-25 16:08:38 +0000 |
867 | @@ -33,7 +33,7 @@ |
868 | private slots: // NOLINT(whitespace/indent) |
869 | |
870 | void init() override; |
871 | - void cleanup(); |
872 | + void cleanup() override; |
873 | |
874 | void testTableCreations_data(); |
875 | void testTableCreations(); |
876 | @@ -44,10 +44,6 @@ |
877 | void testStoreSingleDownloadPresent(); |
878 | |
879 | private: |
880 | - bool removeDir(const QString& dirName); |
881 | - |
882 | - private: |
883 | - QDir _testDir; |
884 | DownloadsDb* _db; |
885 | }; |
886 | |
887 | |
888 | === modified file 'ubuntu-download-manager-tests/test_group_download.cpp' |
889 | --- ubuntu-download-manager-tests/test_group_download.cpp 2013-09-25 16:08:38 +0000 |
890 | +++ ubuntu-download-manager-tests/test_group_download.cpp 2013-09-25 16:08:38 +0000 |
891 | @@ -22,7 +22,7 @@ |
892 | #include "./test_group_download.h" |
893 | |
894 | TestGroupDownload::TestGroupDownload(QObject *parent) |
895 | - : BaseTestCase(parent) { |
896 | + : BaseTestCase("TestGroupDownload", parent) { |
897 | } |
898 | |
899 | void |
900 | @@ -49,6 +49,8 @@ |
901 | |
902 | void |
903 | TestGroupDownload::cleanup() { |
904 | + BaseTestCase::cleanup(); |
905 | + |
906 | if (_networkInfo != NULL) |
907 | delete _networkInfo; |
908 | if (_nam != NULL) |
909 | |
910 | === modified file 'ubuntu-download-manager-tests/test_group_download.h' |
911 | --- ubuntu-download-manager-tests/test_group_download.h 2013-09-25 16:08:38 +0000 |
912 | +++ ubuntu-download-manager-tests/test_group_download.h 2013-09-25 16:08:38 +0000 |
913 | @@ -40,7 +40,7 @@ |
914 | private slots: // NOLINT(whitespace/indent) |
915 | |
916 | void init() override; |
917 | - void cleanup(); |
918 | + void cleanup() override; |
919 | |
920 | void testCancelNoDownloads(); |
921 | void testCancelAllDownloads(); |
922 | |
923 | === modified file 'ubuntu-download-manager-tests/test_network_reply.cpp' |
924 | --- ubuntu-download-manager-tests/test_network_reply.cpp 2013-09-25 16:08:38 +0000 |
925 | +++ ubuntu-download-manager-tests/test_network_reply.cpp 2013-09-25 16:08:38 +0000 |
926 | @@ -22,7 +22,7 @@ |
927 | #include "./fake_qnetwork_reply.h" |
928 | |
929 | TestNetworkReply::TestNetworkReply(QObject *parent) |
930 | - : BaseTestCase(parent) { |
931 | + : BaseTestCase("TestNetworkReply", parent) { |
932 | } |
933 | |
934 | void |
935 | @@ -34,6 +34,8 @@ |
936 | |
937 | void |
938 | TestNetworkReply::cleanup() { |
939 | + BaseTestCase::cleanup(); |
940 | + |
941 | if (_reply != NULL) |
942 | _reply->deleteLater(); |
943 | |
944 | |
945 | === modified file 'ubuntu-download-manager-tests/test_network_reply.h' |
946 | --- ubuntu-download-manager-tests/test_network_reply.h 2013-09-25 16:08:38 +0000 |
947 | +++ ubuntu-download-manager-tests/test_network_reply.h 2013-09-25 16:08:38 +0000 |
948 | @@ -33,7 +33,7 @@ |
949 | private slots: // NOLINT(whitespace/indent) |
950 | |
951 | void init() override; |
952 | - void cleanup(); |
953 | + void cleanup() override; |
954 | |
955 | // data functions used in the tests |
956 | void testDownloadProgressForwarded_data(); |
957 | |
958 | === removed file 'ubuntu-download-manager-tests/test_xdg_basedir.cpp' |
959 | --- ubuntu-download-manager-tests/test_xdg_basedir.cpp 2013-09-25 16:08:38 +0000 |
960 | +++ ubuntu-download-manager-tests/test_xdg_basedir.cpp 1970-01-01 00:00:00 +0000 |
961 | @@ -1,203 +0,0 @@ |
962 | -/* |
963 | - * Copyright 2013 Canonical Ltd. |
964 | - * |
965 | - * This library is free software; you can redistribute it and/or |
966 | - * modify it under the terms of version 3 of the GNU Lesser General Public |
967 | - * License as published by the Free Software Foundation. |
968 | - * |
969 | - * This program is distributed in the hope that it will be useful, |
970 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
971 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
972 | - * General Public License for more details. |
973 | - * |
974 | - * You should have received a copy of the GNU Lesser General Public |
975 | - * License along with this library; if not, write to the |
976 | - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
977 | - * Boston, MA 02110-1301, USA. |
978 | - */ |
979 | - |
980 | - |
981 | -#include <stdlib.h> |
982 | -#include <functional> |
983 | -#include <QDir> |
984 | -#include "./test_xdg_basedir.h" |
985 | - |
986 | - |
987 | -TestXDGBasedir::TestXDGBasedir(QObject *parent) |
988 | - : BaseTestCase(parent) { |
989 | -} |
990 | - |
991 | -void |
992 | -TestXDGBasedir::init() { |
993 | - BaseTestCase::init(); |
994 | - QList<QString> envVars; |
995 | - envVars << "XDG_CACHE_HOME" << "XDG_CONFIG_HOME" << "XDG_DATA_HOME" |
996 | - << "XDG_CONFIG_DIRS" << "XDG_DATA_DIRS"; |
997 | - |
998 | - // load all the env data in the has to be later set |
999 | - foreach(QString var, envVars) { |
1000 | - char* env_path = getenv(var.toStdString().c_str()); |
1001 | - if (env_path == NULL) { |
1002 | - _envData[var] = "NULL"; |
1003 | - } |
1004 | - _envData[var] = QString(env_path); |
1005 | - // clean the data |
1006 | - unsetenv(var.toStdString().c_str()); |
1007 | - } |
1008 | -} |
1009 | - |
1010 | -void |
1011 | -TestXDGBasedir::cleanup() { |
1012 | - // set env data back |
1013 | - QList<QString> keys = _envData.keys(); |
1014 | - foreach(QString key, keys) { |
1015 | - QString data = _envData[key]; |
1016 | - if (data == "NULL") { |
1017 | - unsetenv(key.toStdString().c_str()); |
1018 | - } else { |
1019 | - setenv(key.toStdString().c_str(), data.toStdString().c_str(), 1); |
1020 | - } |
1021 | - } |
1022 | -} |
1023 | - |
1024 | -void |
1025 | -TestXDGBasedir::testDefault(QString envVar, |
1026 | - std::function<QString(void)> callBack, |
1027 | - QString expected) { |
1028 | - unsetenv(envVar.toStdString().c_str()); |
1029 | - QString result = callBack(); |
1030 | - QCOMPARE(expected, result); |
1031 | -} |
1032 | - |
1033 | -void |
1034 | -TestXDGBasedir::testUserSet(QString envVar, |
1035 | - std::function<QString(void)> cb, |
1036 | - QString expected) { |
1037 | - setenv(envVar.toStdString().c_str(), expected.toStdString().c_str(), 1); |
1038 | - QString result = cb(); |
1039 | - QCOMPARE(expected, result); |
1040 | -} |
1041 | - |
1042 | -void |
1043 | -TestXDGBasedir::testCacheHomeDefault() { |
1044 | - QString expected = QDir(QDir::homePath()).filePath(".cache"); |
1045 | - std::function<QString(void)> cb = []() { |
1046 | - return XDGBasedir::cacheHome(); |
1047 | - }; |
1048 | - testDefault(QString("XDG_CACHE_HOME"), cb, expected); |
1049 | -} |
1050 | - |
1051 | -void |
1052 | -TestXDGBasedir::testCacheHomeEnv() { |
1053 | - QString expected = "/path/to/cache"; |
1054 | - std::function<QString(void)> cb = []() { |
1055 | - return XDGBasedir::cacheHome(); |
1056 | - }; |
1057 | - testUserSet(QString("XDG_CACHE_HOME"), cb, expected); |
1058 | -} |
1059 | - |
1060 | -void |
1061 | -TestXDGBasedir::testConfigHomeDefault() { |
1062 | - QString expected = QDir(QDir::homePath()).filePath(".config"); |
1063 | - std::function<QString(void)> cb = []() { |
1064 | - return XDGBasedir::configHome(); |
1065 | - }; |
1066 | - testDefault(QString("XDG_CONFIG_HOME"), cb, expected); |
1067 | -} |
1068 | - |
1069 | -void |
1070 | -TestXDGBasedir::testConfigHomeEnv() { |
1071 | - QString expected = "/path/to/config/home"; |
1072 | - std::function<QString(void)> cb = []() { |
1073 | - return XDGBasedir::configHome(); |
1074 | - }; |
1075 | - testUserSet(QString("XDG_CONFIG_HOME"), cb, expected); |
1076 | -} |
1077 | - |
1078 | -void |
1079 | -TestXDGBasedir::testDataHomeDefault() { |
1080 | - QString expected = QDir(QDir::homePath()).filePath(".local/share"); |
1081 | - std::function<QString(void)> cb = []() { |
1082 | - return XDGBasedir::dataHome(); |
1083 | - }; |
1084 | - testDefault(QString("XDG_DATA_HOME"), cb, expected); |
1085 | -} |
1086 | - |
1087 | -void |
1088 | -TestXDGBasedir::testDataHomeEnv() { |
1089 | - QString expected = "/path/to/data"; |
1090 | - std::function<QString(void)> cb = []() { |
1091 | - return XDGBasedir::dataHome(); |
1092 | - }; |
1093 | - testUserSet(QString("XDG_DATA_HOME"), cb, expected); |
1094 | -} |
1095 | - |
1096 | -void |
1097 | -TestXDGBasedir::testCollectionDefault(QString envVar, |
1098 | - std::function<QList<QString>()> cb, |
1099 | - QString expected) { |
1100 | - unsetenv(envVar.toStdString().c_str()); |
1101 | - QList<QString> dirs = cb(); |
1102 | - QVERIFY(1 == dirs.length()); |
1103 | - QVERIFY(dirs.contains(expected)); |
1104 | -} |
1105 | - |
1106 | -void |
1107 | -TestXDGBasedir::testCollectionEnv(QString envVar, |
1108 | - std::function<QList<QString>()> cb, |
1109 | - QList<QString> expected) { |
1110 | - QStringList list = QStringList(expected); |
1111 | - QString envData = list.join(":"); |
1112 | - setenv(envVar.toStdString().c_str(), envData.toStdString().c_str(), 1); |
1113 | - QList<QString> dirs = cb(); |
1114 | - QCOMPARE(dirs.length(), expected.length() + 1); // add +1 for the default |
1115 | - foreach(QString data, expected) { |
1116 | - QVERIFY(dirs.contains(data)); |
1117 | - } |
1118 | -} |
1119 | - |
1120 | -void |
1121 | -TestXDGBasedir::testConfigDirsDefault() { |
1122 | - QString envVar = "XDG_CONFIG_DIRS"; |
1123 | - std::function<QList<QString>()> cb = []() { |
1124 | - return XDGBasedir::configDirs(); |
1125 | - }; |
1126 | - QString expected = XDGBasedir::configHome(); |
1127 | - testCollectionDefault(envVar, cb, expected); |
1128 | -} |
1129 | - |
1130 | -void |
1131 | -TestXDGBasedir::testConfigEnv() { |
1132 | - QString envVar = "XDG_CONFIG_DIRS"; |
1133 | - std::function<QList<QString>()> cb = []() { |
1134 | - return XDGBasedir::configDirs(); |
1135 | - }; |
1136 | - QList<QString> expected; |
1137 | - expected.append(QString("/path/to/config1")); |
1138 | - expected.append(QString("/path/to/config2")); |
1139 | - expected.append(QString("/path/to/config3")); |
1140 | - testCollectionEnv(envVar, cb, expected); |
1141 | -} |
1142 | - |
1143 | -void |
1144 | -TestXDGBasedir::testDataDirsDefault() { |
1145 | - QString envVar = "XDG_DATA_DIRS"; |
1146 | - std::function<QList<QString>()> cb = []() { |
1147 | - return XDGBasedir::dataDirs(); |
1148 | - }; |
1149 | - QString expected = XDGBasedir::dataHome(); |
1150 | - testCollectionDefault(envVar, cb, expected); |
1151 | -} |
1152 | - |
1153 | -void |
1154 | -TestXDGBasedir::testDataDirsEnv() { |
1155 | - QString envVar = "XDG_DATA_DIRS"; |
1156 | - std::function<QList<QString>()> cb = []() { |
1157 | - return XDGBasedir::dataDirs(); |
1158 | - }; |
1159 | - QList<QString> expected; |
1160 | - expected.append(QString("/path/to/data1")); |
1161 | - expected.append(QString("/path/to/data2")); |
1162 | - expected.append(QString("/path/to/data3")); |
1163 | - testCollectionEnv(envVar, cb, expected); |
1164 | -} |
1165 | |
1166 | === removed file 'ubuntu-download-manager-tests/test_xdg_basedir.h' |
1167 | --- ubuntu-download-manager-tests/test_xdg_basedir.h 2013-09-25 16:08:38 +0000 |
1168 | +++ ubuntu-download-manager-tests/test_xdg_basedir.h 1970-01-01 00:00:00 +0000 |
1169 | @@ -1,68 +0,0 @@ |
1170 | -/* |
1171 | - * Copyright 2013 Canonical Ltd. |
1172 | - * |
1173 | - * This library is free software; you can redistribute it and/or |
1174 | - * modify it under the terms of version 3 of the GNU Lesser General Public |
1175 | - * License as published by the Free Software Foundation. |
1176 | - * |
1177 | - * This program is distributed in the hope that it will be useful, |
1178 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1179 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1180 | - * General Public License for more details. |
1181 | - * |
1182 | - * You should have received a copy of the GNU Lesser General Public |
1183 | - * License along with this library; if not, write to the |
1184 | - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
1185 | - * Boston, MA 02110-1301, USA. |
1186 | - */ |
1187 | - |
1188 | -#ifndef TEST_XDG_BASEDIR_H |
1189 | -#define TEST_XDG_BASEDIR_H |
1190 | - |
1191 | -#include <functional> |
1192 | -#include <QHash> |
1193 | -#include <QObject> |
1194 | -#include "./base_testcase.h" |
1195 | -#include "./xdg_basedir.h" |
1196 | -#include "./test_runner.h" |
1197 | - |
1198 | -class TestXDGBasedir : public BaseTestCase { |
1199 | - Q_OBJECT |
1200 | - |
1201 | - public: |
1202 | - explicit TestXDGBasedir(QObject *parent = 0); |
1203 | - |
1204 | - private slots: // NOLINT(whitespace/indent) |
1205 | - |
1206 | - void init(); |
1207 | - void cleanup(); |
1208 | - void testCacheHomeDefault(); |
1209 | - void testCacheHomeEnv(); |
1210 | - void testConfigHomeDefault(); |
1211 | - void testConfigHomeEnv(); |
1212 | - void testDataHomeDefault(); |
1213 | - void testDataHomeEnv(); |
1214 | - void testConfigDirsDefault(); |
1215 | - void testConfigEnv(); |
1216 | - void testDataDirsDefault(); |
1217 | - void testDataDirsEnv(); |
1218 | - |
1219 | - private: |
1220 | - void testDefault(QString envVar, |
1221 | - std::function<QString(void)> callBack, |
1222 | - QString expected); |
1223 | - void testUserSet(QString envVar, |
1224 | - std::function<QString(void)> cb, |
1225 | - QString expected); |
1226 | - void testCollectionDefault(QString envVar, |
1227 | - std::function<QList<QString>()> cb, |
1228 | - QString expected); |
1229 | - void testCollectionEnv(QString envVar, |
1230 | - std::function<QList<QString>()> cb, |
1231 | - QList<QString> expected); |
1232 | - QHash<QString, QString> _envData; |
1233 | -}; |
1234 | - |
1235 | -DECLARE_TEST(TestXDGBasedir) |
1236 | - |
1237 | -#endif // TEST_XDG_BASEDIR_H |
1238 | |
1239 | === modified file 'ubuntu-download-manager-tests/ubuntu-download-manager-tests.pro' |
1240 | --- ubuntu-download-manager-tests/ubuntu-download-manager-tests.pro 2013-09-25 16:08:38 +0000 |
1241 | +++ ubuntu-download-manager-tests/ubuntu-download-manager-tests.pro 2013-09-25 16:08:38 +0000 |
1242 | @@ -26,7 +26,6 @@ |
1243 | test_download_manager.cpp \ |
1244 | test_download_queue.cpp \ |
1245 | test_network_reply.cpp \ |
1246 | - test_xdg_basedir.cpp \ |
1247 | fake_download_queue.cpp \ |
1248 | fake_uuid_factory.cpp \ |
1249 | fake_system_network_info.cpp \ |
1250 | @@ -56,7 +55,6 @@ |
1251 | test_download_queue.h \ |
1252 | test_network_reply.h \ |
1253 | test_runner.h \ |
1254 | - test_xdg_basedir.h \ |
1255 | fake_download_queue.h \ |
1256 | fake_uuid_factory.h \ |
1257 | fake_system_network_info.h \ |
PASSED: Continuous integration, rev:132 jenkins. qa.ubuntu. com/job/ ubuntu- download- manager- ci/75/ jenkins. qa.ubuntu. com/job/ ubuntu- download- manager- saucy-amd64- ci/75 jenkins. qa.ubuntu. com/job/ ubuntu- download- manager- saucy-armhf- ci/66
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins: 8080/job/ ubuntu- download- manager- ci/75/rebuild
http://