Merge lp:~mandel/ubuntu-download-manager/use-standard-dirs into lp:ubuntu-download-manager

Proposed by Manuel de la Peña
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
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.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

nice branch

review: Approve
Revision history for this message
Alejandro J. Cura (alecu) wrote :

"simplify" is the word. One of my favorites.

review: Approve
133. By Manuel de la Peña

Merged remove-tests-qdebug into use-standard-dirs.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
134. By Manuel de la Peña

Merged remove-tests-qdebug into use-standard-dirs.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'libubuntudownloadmanager/apparmor.cpp'
--- libubuntudownloadmanager/apparmor.cpp 2013-09-19 12:17:48 +0000
+++ libubuntudownloadmanager/apparmor.cpp 2013-09-25 16:08:38 +0000
@@ -23,10 +23,11 @@
23#include <unistd.h>23#include <unistd.h>
24#include <QDBusConnection>24#include <QDBusConnection>
25#include <QDebug>25#include <QDebug>
26#include <QDir>
26#include <QRegExp>27#include <QRegExp>
28#include <QStandardPaths>
27#include "./dbus_proxy.h"29#include "./dbus_proxy.h"
28#include "./uuid_factory.h"30#include "./uuid_factory.h"
29#include "./xdg_basedir.h"
30#include "./apparmor.h"31#include "./apparmor.h"
3132
32/*33/*
@@ -79,9 +80,14 @@
79 // as the local path root80 // as the local path root
80 if (getuid() == 0){81 if (getuid() == 0){
81 qDebug() << "Running as system bus using /tmp for downloads";82 qDebug() << "Running as system bus using /tmp for downloads";
82 return QString("/tmp");83 return QStandardPaths::writableLocation(
84 QStandardPaths::TempLocation);
83 } else {85 } else {
86 QString dataPath = QStandardPaths::writableLocation(
87 QStandardPaths::DataLocation);
84 QStringList pathComponents;88 QStringList pathComponents;
89 pathComponents << dataPath;
90
85 if (!appId.isEmpty()) {91 if (!appId.isEmpty()) {
86 QStringList appIdInfo = appId.split("_");92 QStringList appIdInfo = appId.split("_");
87 if (appIdInfo.count() > 0)93 if (appIdInfo.count() > 0)
@@ -89,9 +95,15 @@
89 }95 }
9096
91 pathComponents << "Downloads";97 pathComponents << "Downloads";
92 QString localPath = XDGBasedir::saveDataPath(pathComponents);98
93 qDebug() << "Local path is" << localPath;99 QString path = pathComponents.join(QDir::separator());
94 return localPath;100
101 bool wasCreated = QDir().mkpath(path);
102 if (!wasCreated) {
103 qCritical() << "Could not create the data path" << path;
104 }
105 qDebug() << "Local path is" << path;
106 return path;
95 } // not root107 } // not root
96 }108 }
97109
98110
=== modified file 'libubuntudownloadmanager/downloads_db.cpp'
--- libubuntudownloadmanager/downloads_db.cpp 2013-09-04 10:32:18 +0000
+++ libubuntudownloadmanager/downloads_db.cpp 2013-09-25 16:08:38 +0000
@@ -17,14 +17,15 @@
17 */17 */
1818
19#include <QDebug>19#include <QDebug>
20#include <QDir>
20#include <QFile>21#include <QFile>
21#include <QJsonDocument>22#include <QJsonDocument>
23#include <QStandardPaths>
22#include <QStringList>24#include <QStringList>
23#include <QSqlDatabase>25#include <QSqlDatabase>
24#include <QSqlQuery>26#include <QSqlQuery>
25#include <QSqlError>27#include <QSqlError>
26#include "./hash_algorithm.h"28#include "./hash_algorithm.h"
27#include "./xdg_basedir.h"
28#include "./downloads_db.h"29#include "./downloads_db.h"
2930
30#define SINGLE_DOWNLOAD_TABLE "CREATE TABLE SingleDownload("\31#define SINGLE_DOWNLOAD_TABLE "CREATE TABLE SingleDownload("\
@@ -107,9 +108,16 @@
107 }108 }
108109
109 void internalInit() {110 void internalInit() {
110 QStringList pathComponents;111
111 pathComponents << "download_manager";112 QString dataPath = QStandardPaths::writableLocation(
112 _dbName = XDGBasedir::saveDataPath(pathComponents) + "/downloads.db";113 QStandardPaths::DataLocation);
114 QString path = dataPath + QDir::separator() + "ubuntu-download-manager";
115
116 bool wasCreated = QDir().mkpath(path);
117 if (!wasCreated) {
118 qCritical() << "Could not create the data path" << path;
119 }
120 _dbName = path + QDir::separator() + "downloads.db";
113 _db = QSqlDatabase::addDatabase("QSQLITE");121 _db = QSqlDatabase::addDatabase("QSQLITE");
114 _db.setDatabaseName(_dbName);122 _db.setDatabaseName(_dbName);
115 qDebug() << "Db file is" << _dbName;123 qDebug() << "Db file is" << _dbName;
@@ -239,11 +247,13 @@
239 query.bindValue(":headers",247 query.bindValue(":headers",
240 headersToString(download->headers()));248 headersToString(download->headers()));
241249
242 bool successs = query.exec();250 bool success = query.exec();
251 if (!success)
252 qDebug() << query.lastError();
243253
244 _db.close();254 _db.close();
245255
246 return successs;256 return success;
247 }257 }
248258
249 private:259 private:
250260
=== modified file 'libubuntudownloadmanager/libubuntudownloadmanager.pro'
--- libubuntudownloadmanager/libubuntudownloadmanager.pro 2013-09-09 09:19:11 +0000
+++ libubuntudownloadmanager/libubuntudownloadmanager.pro 2013-09-25 16:08:38 +0000
@@ -30,7 +30,6 @@
30 system_network_info.cpp \30 system_network_info.cpp \
31 timer.cpp \31 timer.cpp \
32 uuid_factory.cpp \32 uuid_factory.cpp \
33 xdg_basedir.cpp \
34 download_factory.cpp \33 download_factory.cpp \
35 file_manager.cpp \34 file_manager.cpp \
36 download_struct.cpp \35 download_struct.cpp \
@@ -62,7 +61,6 @@
62 system_network_info.h \61 system_network_info.h \
63 timer.h \62 timer.h \
64 uuid_factory.h \63 uuid_factory.h \
65 xdg_basedir.h \
66 download_factory.h \64 download_factory.h \
67 file_manager.h \65 file_manager.h \
68 download_struct.h \66 download_struct.h \
6967
=== modified file 'libubuntudownloadmanager/logger.cpp'
--- libubuntudownloadmanager/logger.cpp 2013-09-23 11:50:04 +0000
+++ libubuntudownloadmanager/logger.cpp 2013-09-25 16:08:38 +0000
@@ -19,9 +19,9 @@
19#include <unistd.h>19#include <unistd.h>
20#include <sys/types.h>20#include <sys/types.h>
21#include <QDateTime>21#include <QDateTime>
22#include <QDebug>
22#include <QDir>23#include <QDir>
23#include <QStandardPaths>24#include <QStandardPaths>
24#include "./xdg_basedir.h"
25#include "./logger.h"25#include "./logger.h"
2626
2727
@@ -119,9 +119,16 @@
119119
120QString120QString
121Logger::getLogDir() {121Logger::getLogDir() {
122 QStringList pathComponents;122 QString cachePath = QStandardPaths::writableLocation(
123 pathComponents << "ubuntu-download-manager";123 QStandardPaths::CacheLocation);
124 return XDGBasedir::saveCachePath(pathComponents);124 QString path = cachePath + QDir::separator() + "ubuntu-download-manager";
125 qDebug() << "Logging dir is" << path;
126
127 bool wasCreated = QDir().mkpath(path);
128 if (!wasCreated) {
129 qCritical() << "Could not create the logging path" << path;
130 }
131 return path;
125}132}
126133
127void134void
128135
=== modified file 'libubuntudownloadmanager/single_download.cpp'
--- libubuntudownloadmanager/single_download.cpp 2013-09-25 16:08:38 +0000
+++ libubuntudownloadmanager/single_download.cpp 2013-09-25 16:08:38 +0000
@@ -27,7 +27,6 @@
27#include "./hash_algorithm.h"27#include "./hash_algorithm.h"
28#include "./single_download.h"28#include "./single_download.h"
29#include "./network_reply.h"29#include "./network_reply.h"
30#include "./xdg_basedir.h"
3130
32#define DATA_FILE_NAME "data.download"31#define DATA_FILE_NAME "data.download"
33#define METADATA_FILE_NAME "metadata"32#define METADATA_FILE_NAME "metadata"
3433
=== removed file 'libubuntudownloadmanager/xdg_basedir.cpp'
--- libubuntudownloadmanager/xdg_basedir.cpp 2013-07-25 21:28:12 +0000
+++ libubuntudownloadmanager/xdg_basedir.cpp 1970-01-01 00:00:00 +0000
@@ -1,204 +0,0 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of version 3 of the GNU Lesser General Public
6 * License as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17 */
18
19#include <QDebug>
20#include <QDir>
21#include <QFile>
22#include <stdlib.h>
23#include "./xdg_basedir.h"
24
25// definitions of defaults
26#define DEFAULT_CACHE_HOME ".cache"
27#define DEFAULT_CONFIG_PATH "/etc/xdg"
28#define DEFAULT_CONFIG_HOME ".config"
29#define DEFAULT_DATA_PATH "/usr/local/share:/usr/share"
30#define DEFAULT_DATA_HOME ".local/share"
31#define XDG_CACHE_HOME "XDG_CACHE_HOME"
32#define XDG_CONFIG_HOME "XDG_CONFIG_HOME"
33#define XDG_DATA_HOME "XDG_DATA_HOME"
34#define XDG_CONFIG_DIRS "XDG_CONFIG_DIRS"
35#define XDG_DATA_DIRS "XDG_DATA_DIRS"
36
37QString
38XDGBasedir::cacheHome() {
39 QString env_path = QString::fromUtf8(getenv(XDG_CACHE_HOME)).trimmed();
40 if (env_path.isEmpty()) {
41 QString defaultValue = QDir(QDir::homePath()).filePath(
42 DEFAULT_CACHE_HOME);
43 return defaultValue;
44 }
45 return env_path;
46}
47
48QString
49XDGBasedir::configHome() {
50 QString env_path = QString::fromUtf8(getenv(XDG_CONFIG_HOME)).trimmed();
51 if (env_path.isEmpty()) {
52 QString defaultValue = QDir(QDir::homePath()).filePath(
53 DEFAULT_CONFIG_HOME);
54 return defaultValue;
55 }
56 return env_path;
57}
58
59QString
60XDGBasedir::dataHome() {
61 QString env_path = QString::fromUtf8(getenv(XDG_DATA_HOME)).trimmed();
62 if (env_path.isEmpty()) {
63 QString defaultValue = QDir(QDir::homePath()).filePath(
64 DEFAULT_DATA_HOME);
65 return defaultValue;
66 }
67 return env_path;
68}
69
70QList<QString>
71XDGBasedir::configDirs() {
72 QList<QString> result;
73 result.append(XDGBasedir::configHome());
74
75 QString env_path = QString::fromUtf8(getenv(XDG_CONFIG_DIRS)).trimmed();
76 if (env_path.isEmpty()) {
77 return result;
78 }
79
80 QStringList paths = env_path.split(":");
81 result.append(paths);
82
83 return result;
84}
85
86QList<QString>
87XDGBasedir::dataDirs() {
88 QList<QString> result;
89 result.append(XDGBasedir::dataHome());
90
91 QString env_path = QString::fromUtf8(getenv(XDG_DATA_DIRS)).trimmed();
92 if (env_path.isEmpty()) {
93 return result;
94 }
95
96 QStringList paths = env_path.split(":");
97 result.append(paths);
98 return result;
99}
100
101QList<QString>
102XDGBasedir::configPaths(QList<QString> resources) {
103 QList<QString> result;
104 QList<QString> configDirs = XDGBasedir::configDirs();
105 foreach (QString configDir, configDirs) { // NOLINT(whitespace/parens)
106 QStringList pathComponents;
107 pathComponents.append(configDir);
108 pathComponents.append(resources);
109 QString path = pathComponents.join(QDir::separator());
110 if (QFile::exists(path)) {
111 result.append(path);
112 }
113 }
114
115 return result;
116}
117
118QList<QString>
119XDGBasedir::dataPaths(QList<QString> resources) {
120 QList<QString> result;
121 QList<QString> dataDirs = XDGBasedir::dataDirs();
122 foreach (QString dataDir, dataDirs) { // NOLINT(whitespace/parens)
123 QStringList pathComponents;
124 pathComponents.append(dataDir);
125 pathComponents.append(resources);
126 QString path = pathComponents.join(QDir::separator());
127 if (QFile::exists(path)) {
128 result.append(path);
129 }
130 }
131 return result;
132}
133
134QString
135XDGBasedir::loadFirstConfig(QList<QString> resource) {
136 QList<QString> configPaths = XDGBasedir::configPaths(resource);
137 return configPaths.at(0);
138}
139
140QString
141XDGBasedir::saveCachePath(QList<QString> resources){
142 QString home = XDGBasedir::cacheHome();
143 QStringList pathComponents;
144 pathComponents.append(home);
145 pathComponents.append(resources);
146 QString path = pathComponents.join(QDir::separator());
147 QFileInfo info = QFileInfo(path);
148 if (!info.exists() || !info.isDir()) {
149 QDir dir(home);
150 QStringList child;
151 child.append(resources);
152 bool created = dir.mkpath(child.join(QDir::separator()));
153 if (!created) {
154 qCritical() << "Could not create path:"
155 << child.join(QDir::separator());
156 return QString("");
157 }
158 }
159 return path;
160}
161
162QString
163XDGBasedir::saveConfigPath(QList<QString> resources) {
164 QString home = XDGBasedir::configHome();
165 QStringList pathComponents;
166 pathComponents.append(home);
167 pathComponents.append(resources);
168 QString path = pathComponents.join(QDir::separator());
169 QFileInfo info = QFileInfo(path);
170 if (!info.exists() || !info.isDir()) {
171 QDir dir(home);
172 QStringList child;
173 child.append(resources);
174 bool created = dir.mkpath(child.join(QDir::separator()));
175 if (!created) {
176 qCritical() << "Could not create path:"
177 << child.join(QDir::separator());
178 return QString("");
179 }
180 }
181 return path;
182}
183
184QString
185XDGBasedir::saveDataPath(QList<QString> resources) {
186 QString home = XDGBasedir::dataHome();
187 QStringList pathComponents;
188 pathComponents.append(home);
189 pathComponents.append(resources);
190 QString path = pathComponents.join(QDir::separator());
191 QFileInfo info = QFileInfo(path);
192 if (!info.exists() || !info.isDir()) {
193 QDir dir(home);
194 QStringList child;
195 child.append(resources);
196 bool created = dir.mkpath(child.join(QDir::separator()));
197 if (!created) {
198 qCritical() << "Could not create path:"
199 << child.join(QDir::separator());
200 return QString("");
201 }
202 }
203 return path;
204}
2050
=== removed file 'libubuntudownloadmanager/xdg_basedir.h'
--- libubuntudownloadmanager/xdg_basedir.h 2013-07-25 21:28:12 +0000
+++ libubuntudownloadmanager/xdg_basedir.h 1970-01-01 00:00:00 +0000
@@ -1,57 +0,0 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of version 3 of the GNU Lesser General Public
6 * License as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17 */
18
19#ifndef DOWNLOADER_LIB_XDG_BASEDIR_H
20#define DOWNLOADER_LIB_XDG_BASEDIR_H
21
22#include <QList>
23#include <QObject>
24#include <QString>
25#include <stdio.h>
26#include <string>
27
28class XDGBasedir : public QObject {
29 Q_OBJECT
30
31 public:
32 static QString cacheHome();
33 static QString configHome();
34 static QString dataHome();
35 static QList<QString> configDirs();
36 static QList<QString> dataDirs();
37 static QList<QString> configPaths(QList<QString> resource);
38 static QList<QString> dataPaths(QList<QString> resource);
39 static QString loadFirstConfig(QList<QString> resource);
40 static QString saveCachePath(QList<QString> resources);
41 static QString saveConfigPath(QList<QString> resource);
42 static QString saveDataPath(QList<QString> resource);
43
44 private:
45 static QString DEFAULT_CACHE_HOME;
46 static QString DEFAULT_CONFIG_HOME;
47 static QString DEFAULT_CONFIG_PATH;
48 static QString DEFAULT_DATA_PATH;
49 static QString DEFAULT_DATA_HOME;
50 static std::string XDG_CACHE_HOME;
51 static std::string XDG_CONFIG_HOME;
52 static std::string XDG_DATA_HOME;
53 static std::string XDG_CONFIG_DIRS;
54 static std::string XDG_DATA_DIRS;
55};
56
57#endif // DOWNLOADER_LIB_XDG_BASEDIR_H
580
=== modified file 'ubuntu-download-manager-tests/base_testcase.cpp'
--- ubuntu-download-manager-tests/base_testcase.cpp 2013-09-25 16:08:38 +0000
+++ ubuntu-download-manager-tests/base_testcase.cpp 2013-09-25 16:08:38 +0000
@@ -16,7 +16,9 @@
16 * Boston, MA 02110-1301, USA.16 * Boston, MA 02110-1301, USA.
17 */17 */
1818
19#include <QDir>
19#include <QtGlobal>20#include <QtGlobal>
21#include <QStandardPaths>
20#include "./base_testcase.h"22#include "./base_testcase.h"
2123
22void24void
@@ -29,11 +31,59 @@
29 // do nothing31 // do nothing
30}32}
3133
32BaseTestCase::BaseTestCase(QObject *parent)34BaseTestCase::BaseTestCase(const QString& testName, QObject *parent)
33 : QObject(parent) {35 : QObject(parent) {
36 setObjectName(testName);
37}
38
39QString
40BaseTestCase::testDirectory() {
41 // return the test directory using the standard paths
42 QString dataPath = QStandardPaths::writableLocation(
43 QStandardPaths::DataLocation);
44 QStringList pathComponents;
45 pathComponents << dataPath << objectName();
46 QString path = pathComponents.join(QDir::separator());
47
48 if (!QDir().exists(path))
49 QDir().mkpath(path);
50
51 return path;
52}
53
54bool
55BaseTestCase::removeDir(const QString& dirName) {
56 bool result = true;
57 QDir dir(dirName);
58
59 QFlags<QDir::Filter> filter = QDir::NoDotAndDotDot | QDir::System
60 | QDir::Hidden | QDir::AllDirs | QDir::Files;
61 if (dir.exists(dirName)) {
62 foreach(QFileInfo info, dir.entryInfoList(filter, QDir::DirsFirst)) {
63 if (info.isDir()) {
64 result = removeDir(info.absoluteFilePath());
65 } else {
66 result = QFile::remove(info.absoluteFilePath());
67 }
68
69 if (!result) {
70 return result;
71 }
72 }
73 result = dir.rmdir(dirName);
74 }
75
76 return result;
34}77}
3578
36void79void
37BaseTestCase::init() {80BaseTestCase::init() {
38 qInstallMessageHandler(noMessageOutput);81 qInstallMessageHandler(noMessageOutput);
82 QStandardPaths::enableTestMode(true);
83}
84
85void
86BaseTestCase::cleanup() {
87 // remove the test dir if exists
88 removeDir(testDirectory());
39}89}
4090
=== modified file 'ubuntu-download-manager-tests/base_testcase.h'
--- ubuntu-download-manager-tests/base_testcase.h 2013-09-25 16:08:38 +0000
+++ ubuntu-download-manager-tests/base_testcase.h 2013-09-25 16:08:38 +0000
@@ -25,12 +25,17 @@
25{25{
26 Q_OBJECT26 Q_OBJECT
27 public:27 public:
28 explicit BaseTestCase(QObject *parent = 0);28 BaseTestCase(const QString& testName, QObject *parent = 0);
29 29
30 QString testDirectory();
31
30 protected slots: // NOLINT(whitespace/indent)32 protected slots: // NOLINT(whitespace/indent)
3133
32 virtual void init();34 virtual void init();
35 virtual void cleanup();
3336
37 private:
38 bool removeDir(const QString& dirName);
34};39};
3540
36#endif // BASE_TESTCASE_H41#endif // BASE_TESTCASE_H
3742
=== modified file 'ubuntu-download-manager-tests/test_download.cpp'
--- ubuntu-download-manager-tests/test_download.cpp 2013-09-25 16:08:38 +0000
+++ ubuntu-download-manager-tests/test_download.cpp 2013-09-25 16:08:38 +0000
@@ -17,7 +17,6 @@
17 */17 */
1818
19#include <QDebug>19#include <QDebug>
20#include <stdlib.h>
21#include <QNetworkRequest>20#include <QNetworkRequest>
22#include <QSignalSpy>21#include <QSignalSpy>
23#include <QSslError>22#include <QSslError>
@@ -27,50 +26,16 @@
27#include "./test_download.h"26#include "./test_download.h"
2827
29TestDownload::TestDownload(QObject* parent)28TestDownload::TestDownload(QObject* parent)
30 : BaseTestCase(parent) {29 : BaseTestCase("TestDownload", parent) {
31}
32
33bool
34TestDownload::removeDir(const QString& dirName) {
35 bool result = true;
36 QDir dir(dirName);
37
38 QFlags<QDir::Filter> filter = QDir::NoDotAndDotDot | QDir::System
39 | QDir::Hidden | QDir::AllDirs | QDir::Files;
40 if (dir.exists(dirName)) {
41 foreach(QFileInfo info, dir.entryInfoList(filter, QDir::DirsFirst)) {
42 if (info.isDir()) {
43 result = removeDir(info.absoluteFilePath());
44 } else {
45 result = QFile::remove(info.absoluteFilePath());
46 }
47
48 if (!result) {
49 return result;
50 }
51 }
52 result = dir.rmdir(dirName);
53 }
54
55 return result;
56}30}
5731
58void32void
59TestDownload::init() {33TestDownload::init() {
60 BaseTestCase::init();34 BaseTestCase::init();
61 // set the xdg path so that we have control over it35
62 _testDir = QDir("./tests");
63 _testDir.makeAbsolute();
64
65 if (!_testDir.exists()) {
66 _testDir.mkpath(_testDir.absolutePath());
67 }
68
69 setenv("XDG_DATA_HOME",
70 _testDir.absolutePath().toStdString().c_str(), 1);
71 _id = QUuid::createUuid();36 _id = QUuid::createUuid();
72 _isConfined = false;37 _isConfined = false;
73 _rootPath = _testDir.absolutePath();38 _rootPath = testDirectory();
74 _path = "random path to dbus";39 _path = "random path to dbus";
75 _url = QUrl("http://ubuntu.com");40 _url = QUrl("http://ubuntu.com");
76 _algo = "Sha256";41 _algo = "Sha256";
@@ -81,6 +46,8 @@
8146
82void47void
83TestDownload::cleanup() {48TestDownload::cleanup() {
49 BaseTestCase::cleanup();
50
84 if (_networkInfo)51 if (_networkInfo)
85 delete _networkInfo;52 delete _networkInfo;
86 if (_reqFactory)53 if (_reqFactory)
@@ -88,9 +55,6 @@
88 if (_processFactory)55 if (_processFactory)
89 delete _processFactory;56 delete _processFactory;
9057
91 // try to remove the test dir
92 removeDir(_testDir.absolutePath());
93 unsetenv("XDG_DATA_HOME");
94}58}
9559
96void60void
9761
=== modified file 'ubuntu-download-manager-tests/test_download.h'
--- ubuntu-download-manager-tests/test_download.h 2013-09-25 16:08:38 +0000
+++ ubuntu-download-manager-tests/test_download.h 2013-09-25 16:08:38 +0000
@@ -38,7 +38,7 @@
38 private slots: // NOLINT(whitespace/indent)38 private slots: // NOLINT(whitespace/indent)
3939
40 void init() override;40 void init() override;
41 void cleanup();41 void cleanup() override;
4242
43 // constructors tests43 // constructors tests
44 void testNoHashConstructor();44 void testNoHashConstructor();
@@ -132,10 +132,6 @@
132 void testValidHashAlgorithm();132 void testValidHashAlgorithm();
133133
134 private:134 private:
135 bool removeDir(const QString& dirName);
136
137 private:
138 QDir _testDir;
139 QUuid _id;135 QUuid _id;
140 bool _isConfined;136 bool _isConfined;
141 QString _rootPath;137 QString _rootPath;
142138
=== modified file 'ubuntu-download-manager-tests/test_download_daemon.cpp'
--- ubuntu-download-manager-tests/test_download_daemon.cpp 2013-09-25 16:08:38 +0000
+++ ubuntu-download-manager-tests/test_download_daemon.cpp 2013-09-25 16:08:38 +0000
@@ -19,7 +19,7 @@
19#include "./test_download_daemon.h"19#include "./test_download_daemon.h"
2020
21TestDownloadDaemon::TestDownloadDaemon(QObject *parent)21TestDownloadDaemon::TestDownloadDaemon(QObject *parent)
22 : BaseTestCase(parent) {22 : BaseTestCase("TestDownloadDaemon", parent) {
23}23}
2424
25void25void
@@ -37,6 +37,8 @@
3737
38void38void
39TestDownloadDaemon::cleanup() {39TestDownloadDaemon::cleanup() {
40 BaseTestCase::cleanup();
41
40 if (_app != NULL)42 if (_app != NULL)
41 delete _app;43 delete _app;
42 if (_conn != NULL)44 if (_conn != NULL)
4345
=== modified file 'ubuntu-download-manager-tests/test_download_daemon.h'
--- ubuntu-download-manager-tests/test_download_daemon.h 2013-09-25 16:08:38 +0000
+++ ubuntu-download-manager-tests/test_download_daemon.h 2013-09-25 16:08:38 +0000
@@ -37,7 +37,7 @@
37 private slots: // NOLINT(whitespace/indent)37 private slots: // NOLINT(whitespace/indent)
3838
39 void init() override;39 void init() override;
40 void cleanup();40 void cleanup() override;
41 void testStart();41 void testStart();
42 void testStartFailServiceRegister();42 void testStartFailServiceRegister();
43 void testStartFailObjectRegister();43 void testStartFailObjectRegister();
4444
=== modified file 'ubuntu-download-manager-tests/test_download_factory.cpp'
--- ubuntu-download-manager-tests/test_download_factory.cpp 2013-09-25 16:08:38 +0000
+++ ubuntu-download-manager-tests/test_download_factory.cpp 2013-09-25 16:08:38 +0000
@@ -21,7 +21,7 @@
21#include "./test_download_factory.h"21#include "./test_download_factory.h"
2222
23TestDownloadFactory::TestDownloadFactory(QObject *parent)23TestDownloadFactory::TestDownloadFactory(QObject *parent)
24 : BaseTestCase(parent) {24 : BaseTestCase("TestDownloadFactory", parent) {
25}25}
2626
27void27void
@@ -40,6 +40,8 @@
4040
41void41void
42TestDownloadFactory::cleanup() {42TestDownloadFactory::cleanup() {
43 BaseTestCase::cleanup();
44
43 if (_downFactory != NULL)45 if (_downFactory != NULL)
44 delete _downFactory;46 delete _downFactory;
45}47}
4648
=== modified file 'ubuntu-download-manager-tests/test_download_factory.h'
--- ubuntu-download-manager-tests/test_download_factory.h 2013-09-25 16:08:38 +0000
+++ ubuntu-download-manager-tests/test_download_factory.h 2013-09-25 16:08:38 +0000
@@ -38,7 +38,7 @@
38 private slots: // NOLINT(whitespace/indent)38 private slots: // NOLINT(whitespace/indent)
3939
40 void init() override;40 void init() override;
41 void cleanup();41 void cleanup() override;
4242
43 void testCreateDownload();43 void testCreateDownload();
44 void testCreateDownloadWithHash();44 void testCreateDownloadWithHash();
4545
=== modified file 'ubuntu-download-manager-tests/test_download_manager.cpp'
--- ubuntu-download-manager-tests/test_download_manager.cpp 2013-09-25 16:08:38 +0000
+++ ubuntu-download-manager-tests/test_download_manager.cpp 2013-09-25 16:08:38 +0000
@@ -24,7 +24,7 @@
24#include "./test_download_manager.h"24#include "./test_download_manager.h"
2525
26TestDownloadManager::TestDownloadManager(QObject *parent)26TestDownloadManager::TestDownloadManager(QObject *parent)
27 : BaseTestCase(parent) {27 : BaseTestCase("TestDownloadManager", parent) {
28}28}
2929
30void30void
@@ -51,6 +51,8 @@
5151
52void52void
53TestDownloadManager::cleanup() {53TestDownloadManager::cleanup() {
54 BaseTestCase::cleanup();
55
54 if (_networkInfo)56 if (_networkInfo)
55 delete _networkInfo;57 delete _networkInfo;
56 if (_q != NULL)58 if (_q != NULL)
5759
=== modified file 'ubuntu-download-manager-tests/test_download_manager.h'
--- ubuntu-download-manager-tests/test_download_manager.h 2013-09-25 16:08:38 +0000
+++ ubuntu-download-manager-tests/test_download_manager.h 2013-09-25 16:08:38 +0000
@@ -43,7 +43,7 @@
43 private slots: // NOLINT(whitespace/indent)43 private slots: // NOLINT(whitespace/indent)
4444
45 void init() override;45 void init() override;
46 void cleanup();46 void cleanup() override;
4747
48 // data functions48 // data functions
49 void testCreateDownload_data();49 void testCreateDownload_data();
5050
=== modified file 'ubuntu-download-manager-tests/test_download_queue.cpp'
--- ubuntu-download-manager-tests/test_download_queue.cpp 2013-09-25 16:08:38 +0000
+++ ubuntu-download-manager-tests/test_download_queue.cpp 2013-09-25 16:08:38 +0000
@@ -21,7 +21,7 @@
21#include "./test_download_queue.h"21#include "./test_download_queue.h"
2222
23TestDownloadQueue::TestDownloadQueue(QObject *parent)23TestDownloadQueue::TestDownloadQueue(QObject *parent)
24 : BaseTestCase(parent) {24 : BaseTestCase("TestDownloadQueue", parent) {
25}25}
2626
27void27void
@@ -49,6 +49,8 @@
4949
50void50void
51TestDownloadQueue::cleanup() {51TestDownloadQueue::cleanup() {
52 BaseTestCase::cleanup();
53
52 if (_q != NULL)54 if (_q != NULL)
53 delete _q;55 delete _q;
5456
5557
=== modified file 'ubuntu-download-manager-tests/test_download_queue.h'
--- ubuntu-download-manager-tests/test_download_queue.h 2013-09-25 16:08:38 +0000
+++ ubuntu-download-manager-tests/test_download_queue.h 2013-09-25 16:08:38 +0000
@@ -38,7 +38,7 @@
38 private slots: // NOLINT(whitespace/indent)38 private slots: // NOLINT(whitespace/indent)
3939
40 void init() override;40 void init() override;
41 void cleanup();41 void cleanup() override;
4242
43 void testAddDownload();43 void testAddDownload();
44 void testStartDownloadWithNoCurrent();44 void testStartDownloadWithNoCurrent();
4545
=== modified file 'ubuntu-download-manager-tests/test_downloads_db.cpp'
--- ubuntu-download-manager-tests/test_downloads_db.cpp 2013-09-25 16:08:38 +0000
+++ ubuntu-download-manager-tests/test_downloads_db.cpp 2013-09-25 16:08:38 +0000
@@ -38,58 +38,24 @@
38 "FROM SingleDownload WHERE uuid=:uuid;"38 "FROM SingleDownload WHERE uuid=:uuid;"
3939
40TestDownloadsDb::TestDownloadsDb(QObject *parent)40TestDownloadsDb::TestDownloadsDb(QObject *parent)
41 : BaseTestCase(parent) {41 : BaseTestCase("TestDownloadsDb", parent) {
42}
43
44bool
45TestDownloadsDb::removeDir(const QString& dirName) {
46 bool result = true;
47 QDir dir(dirName);
48
49 QFlags<QDir::Filter> filter = QDir::NoDotAndDotDot | QDir::System
50 | QDir::Hidden | QDir::AllDirs | QDir::Files;
51 if (dir.exists(dirName)) {
52 foreach(QFileInfo info, dir.entryInfoList(filter, QDir::DirsFirst)) {
53 qDebug() << "Removing" << info.absoluteFilePath();
54 if (info.isDir()) {
55 result = removeDir(info.absoluteFilePath());
56 } else {
57 result = QFile::remove(info.absoluteFilePath());
58 }
59
60 if (!result) {
61 return result;
62 }
63 }
64 result = dir.rmdir(dirName);
65 }
66
67 return result;
68}42}
6943
70void44void
71TestDownloadsDb::init() {45TestDownloadsDb::init() {
72 BaseTestCase::init();46 BaseTestCase::init();
73 _testDir = QDir("./tests");
74 _testDir.makeAbsolute();
75
76 if (!_testDir.exists()) {
77 _testDir.mkpath(_testDir.absolutePath());
78 }
79
80 setenv("XDG_DATA_HOME",
81 _testDir.absolutePath().toStdString().c_str(), 1);
82
83 _db = new DownloadsDb();47 _db = new DownloadsDb();
84}48}
8549
86void50void
87TestDownloadsDb::cleanup() {51TestDownloadsDb::cleanup() {
88 // try to remove the test dir52 BaseTestCase::cleanup();
53 QString dbFile = _db->filename();
54
89 if (_db != NULL)55 if (_db != NULL)
90 delete _db;56 delete _db;
91 removeDir(_testDir.absolutePath());57
92 unsetenv("XDG_DATA_HOME");58 QFile::remove(dbFile);
93}59}
9460
95void61void
9662
=== modified file 'ubuntu-download-manager-tests/test_downloads_db.h'
--- ubuntu-download-manager-tests/test_downloads_db.h 2013-09-25 16:08:38 +0000
+++ ubuntu-download-manager-tests/test_downloads_db.h 2013-09-25 16:08:38 +0000
@@ -33,7 +33,7 @@
33 private slots: // NOLINT(whitespace/indent)33 private slots: // NOLINT(whitespace/indent)
3434
35 void init() override;35 void init() override;
36 void cleanup();36 void cleanup() override;
3737
38 void testTableCreations_data();38 void testTableCreations_data();
39 void testTableCreations();39 void testTableCreations();
@@ -44,10 +44,6 @@
44 void testStoreSingleDownloadPresent();44 void testStoreSingleDownloadPresent();
4545
46 private:46 private:
47 bool removeDir(const QString& dirName);
48
49 private:
50 QDir _testDir;
51 DownloadsDb* _db;47 DownloadsDb* _db;
52};48};
5349
5450
=== modified file 'ubuntu-download-manager-tests/test_group_download.cpp'
--- ubuntu-download-manager-tests/test_group_download.cpp 2013-09-25 16:08:38 +0000
+++ ubuntu-download-manager-tests/test_group_download.cpp 2013-09-25 16:08:38 +0000
@@ -22,7 +22,7 @@
22#include "./test_group_download.h"22#include "./test_group_download.h"
2323
24TestGroupDownload::TestGroupDownload(QObject *parent)24TestGroupDownload::TestGroupDownload(QObject *parent)
25 : BaseTestCase(parent) {25 : BaseTestCase("TestGroupDownload", parent) {
26}26}
2727
28void28void
@@ -49,6 +49,8 @@
4949
50void50void
51TestGroupDownload::cleanup() {51TestGroupDownload::cleanup() {
52 BaseTestCase::cleanup();
53
52 if (_networkInfo != NULL)54 if (_networkInfo != NULL)
53 delete _networkInfo;55 delete _networkInfo;
54 if (_nam != NULL)56 if (_nam != NULL)
5557
=== modified file 'ubuntu-download-manager-tests/test_group_download.h'
--- ubuntu-download-manager-tests/test_group_download.h 2013-09-25 16:08:38 +0000
+++ ubuntu-download-manager-tests/test_group_download.h 2013-09-25 16:08:38 +0000
@@ -40,7 +40,7 @@
40 private slots: // NOLINT(whitespace/indent)40 private slots: // NOLINT(whitespace/indent)
4141
42 void init() override;42 void init() override;
43 void cleanup();43 void cleanup() override;
4444
45 void testCancelNoDownloads();45 void testCancelNoDownloads();
46 void testCancelAllDownloads();46 void testCancelAllDownloads();
4747
=== modified file 'ubuntu-download-manager-tests/test_network_reply.cpp'
--- ubuntu-download-manager-tests/test_network_reply.cpp 2013-09-25 16:08:38 +0000
+++ ubuntu-download-manager-tests/test_network_reply.cpp 2013-09-25 16:08:38 +0000
@@ -22,7 +22,7 @@
22#include "./fake_qnetwork_reply.h"22#include "./fake_qnetwork_reply.h"
2323
24TestNetworkReply::TestNetworkReply(QObject *parent)24TestNetworkReply::TestNetworkReply(QObject *parent)
25 : BaseTestCase(parent) {25 : BaseTestCase("TestNetworkReply", parent) {
26}26}
2727
28void28void
@@ -34,6 +34,8 @@
3434
35void35void
36TestNetworkReply::cleanup() {36TestNetworkReply::cleanup() {
37 BaseTestCase::cleanup();
38
37 if (_reply != NULL)39 if (_reply != NULL)
38 _reply->deleteLater();40 _reply->deleteLater();
3941
4042
=== modified file 'ubuntu-download-manager-tests/test_network_reply.h'
--- ubuntu-download-manager-tests/test_network_reply.h 2013-09-25 16:08:38 +0000
+++ ubuntu-download-manager-tests/test_network_reply.h 2013-09-25 16:08:38 +0000
@@ -33,7 +33,7 @@
33 private slots: // NOLINT(whitespace/indent)33 private slots: // NOLINT(whitespace/indent)
3434
35 void init() override;35 void init() override;
36 void cleanup();36 void cleanup() override;
3737
38 // data functions used in the tests38 // data functions used in the tests
39 void testDownloadProgressForwarded_data();39 void testDownloadProgressForwarded_data();
4040
=== removed file 'ubuntu-download-manager-tests/test_xdg_basedir.cpp'
--- ubuntu-download-manager-tests/test_xdg_basedir.cpp 2013-09-25 16:08:38 +0000
+++ ubuntu-download-manager-tests/test_xdg_basedir.cpp 1970-01-01 00:00:00 +0000
@@ -1,203 +0,0 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of version 3 of the GNU Lesser General Public
6 * License as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17 */
18
19
20#include <stdlib.h>
21#include <functional>
22#include <QDir>
23#include "./test_xdg_basedir.h"
24
25
26TestXDGBasedir::TestXDGBasedir(QObject *parent)
27 : BaseTestCase(parent) {
28}
29
30void
31TestXDGBasedir::init() {
32 BaseTestCase::init();
33 QList<QString> envVars;
34 envVars << "XDG_CACHE_HOME" << "XDG_CONFIG_HOME" << "XDG_DATA_HOME"
35 << "XDG_CONFIG_DIRS" << "XDG_DATA_DIRS";
36
37 // load all the env data in the has to be later set
38 foreach(QString var, envVars) {
39 char* env_path = getenv(var.toStdString().c_str());
40 if (env_path == NULL) {
41 _envData[var] = "NULL";
42 }
43 _envData[var] = QString(env_path);
44 // clean the data
45 unsetenv(var.toStdString().c_str());
46 }
47}
48
49void
50TestXDGBasedir::cleanup() {
51 // set env data back
52 QList<QString> keys = _envData.keys();
53 foreach(QString key, keys) {
54 QString data = _envData[key];
55 if (data == "NULL") {
56 unsetenv(key.toStdString().c_str());
57 } else {
58 setenv(key.toStdString().c_str(), data.toStdString().c_str(), 1);
59 }
60 }
61}
62
63void
64TestXDGBasedir::testDefault(QString envVar,
65 std::function<QString(void)> callBack,
66 QString expected) {
67 unsetenv(envVar.toStdString().c_str());
68 QString result = callBack();
69 QCOMPARE(expected, result);
70}
71
72void
73TestXDGBasedir::testUserSet(QString envVar,
74 std::function<QString(void)> cb,
75 QString expected) {
76 setenv(envVar.toStdString().c_str(), expected.toStdString().c_str(), 1);
77 QString result = cb();
78 QCOMPARE(expected, result);
79}
80
81void
82TestXDGBasedir::testCacheHomeDefault() {
83 QString expected = QDir(QDir::homePath()).filePath(".cache");
84 std::function<QString(void)> cb = []() {
85 return XDGBasedir::cacheHome();
86 };
87 testDefault(QString("XDG_CACHE_HOME"), cb, expected);
88}
89
90void
91TestXDGBasedir::testCacheHomeEnv() {
92 QString expected = "/path/to/cache";
93 std::function<QString(void)> cb = []() {
94 return XDGBasedir::cacheHome();
95 };
96 testUserSet(QString("XDG_CACHE_HOME"), cb, expected);
97}
98
99void
100TestXDGBasedir::testConfigHomeDefault() {
101 QString expected = QDir(QDir::homePath()).filePath(".config");
102 std::function<QString(void)> cb = []() {
103 return XDGBasedir::configHome();
104 };
105 testDefault(QString("XDG_CONFIG_HOME"), cb, expected);
106}
107
108void
109TestXDGBasedir::testConfigHomeEnv() {
110 QString expected = "/path/to/config/home";
111 std::function<QString(void)> cb = []() {
112 return XDGBasedir::configHome();
113 };
114 testUserSet(QString("XDG_CONFIG_HOME"), cb, expected);
115}
116
117void
118TestXDGBasedir::testDataHomeDefault() {
119 QString expected = QDir(QDir::homePath()).filePath(".local/share");
120 std::function<QString(void)> cb = []() {
121 return XDGBasedir::dataHome();
122 };
123 testDefault(QString("XDG_DATA_HOME"), cb, expected);
124}
125
126void
127TestXDGBasedir::testDataHomeEnv() {
128 QString expected = "/path/to/data";
129 std::function<QString(void)> cb = []() {
130 return XDGBasedir::dataHome();
131 };
132 testUserSet(QString("XDG_DATA_HOME"), cb, expected);
133}
134
135void
136TestXDGBasedir::testCollectionDefault(QString envVar,
137 std::function<QList<QString>()> cb,
138 QString expected) {
139 unsetenv(envVar.toStdString().c_str());
140 QList<QString> dirs = cb();
141 QVERIFY(1 == dirs.length());
142 QVERIFY(dirs.contains(expected));
143}
144
145void
146TestXDGBasedir::testCollectionEnv(QString envVar,
147 std::function<QList<QString>()> cb,
148 QList<QString> expected) {
149 QStringList list = QStringList(expected);
150 QString envData = list.join(":");
151 setenv(envVar.toStdString().c_str(), envData.toStdString().c_str(), 1);
152 QList<QString> dirs = cb();
153 QCOMPARE(dirs.length(), expected.length() + 1); // add +1 for the default
154 foreach(QString data, expected) {
155 QVERIFY(dirs.contains(data));
156 }
157}
158
159void
160TestXDGBasedir::testConfigDirsDefault() {
161 QString envVar = "XDG_CONFIG_DIRS";
162 std::function<QList<QString>()> cb = []() {
163 return XDGBasedir::configDirs();
164 };
165 QString expected = XDGBasedir::configHome();
166 testCollectionDefault(envVar, cb, expected);
167}
168
169void
170TestXDGBasedir::testConfigEnv() {
171 QString envVar = "XDG_CONFIG_DIRS";
172 std::function<QList<QString>()> cb = []() {
173 return XDGBasedir::configDirs();
174 };
175 QList<QString> expected;
176 expected.append(QString("/path/to/config1"));
177 expected.append(QString("/path/to/config2"));
178 expected.append(QString("/path/to/config3"));
179 testCollectionEnv(envVar, cb, expected);
180}
181
182void
183TestXDGBasedir::testDataDirsDefault() {
184 QString envVar = "XDG_DATA_DIRS";
185 std::function<QList<QString>()> cb = []() {
186 return XDGBasedir::dataDirs();
187 };
188 QString expected = XDGBasedir::dataHome();
189 testCollectionDefault(envVar, cb, expected);
190}
191
192void
193TestXDGBasedir::testDataDirsEnv() {
194 QString envVar = "XDG_DATA_DIRS";
195 std::function<QList<QString>()> cb = []() {
196 return XDGBasedir::dataDirs();
197 };
198 QList<QString> expected;
199 expected.append(QString("/path/to/data1"));
200 expected.append(QString("/path/to/data2"));
201 expected.append(QString("/path/to/data3"));
202 testCollectionEnv(envVar, cb, expected);
203}
2040
=== removed file 'ubuntu-download-manager-tests/test_xdg_basedir.h'
--- ubuntu-download-manager-tests/test_xdg_basedir.h 2013-09-25 16:08:38 +0000
+++ ubuntu-download-manager-tests/test_xdg_basedir.h 1970-01-01 00:00:00 +0000
@@ -1,68 +0,0 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of version 3 of the GNU Lesser General Public
6 * License as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17 */
18
19#ifndef TEST_XDG_BASEDIR_H
20#define TEST_XDG_BASEDIR_H
21
22#include <functional>
23#include <QHash>
24#include <QObject>
25#include "./base_testcase.h"
26#include "./xdg_basedir.h"
27#include "./test_runner.h"
28
29class TestXDGBasedir : public BaseTestCase {
30 Q_OBJECT
31
32 public:
33 explicit TestXDGBasedir(QObject *parent = 0);
34
35 private slots: // NOLINT(whitespace/indent)
36
37 void init();
38 void cleanup();
39 void testCacheHomeDefault();
40 void testCacheHomeEnv();
41 void testConfigHomeDefault();
42 void testConfigHomeEnv();
43 void testDataHomeDefault();
44 void testDataHomeEnv();
45 void testConfigDirsDefault();
46 void testConfigEnv();
47 void testDataDirsDefault();
48 void testDataDirsEnv();
49
50 private:
51 void testDefault(QString envVar,
52 std::function<QString(void)> callBack,
53 QString expected);
54 void testUserSet(QString envVar,
55 std::function<QString(void)> cb,
56 QString expected);
57 void testCollectionDefault(QString envVar,
58 std::function<QList<QString>()> cb,
59 QString expected);
60 void testCollectionEnv(QString envVar,
61 std::function<QList<QString>()> cb,
62 QList<QString> expected);
63 QHash<QString, QString> _envData;
64};
65
66DECLARE_TEST(TestXDGBasedir)
67
68#endif // TEST_XDG_BASEDIR_H
690
=== modified file 'ubuntu-download-manager-tests/ubuntu-download-manager-tests.pro'
--- ubuntu-download-manager-tests/ubuntu-download-manager-tests.pro 2013-09-25 16:08:38 +0000
+++ ubuntu-download-manager-tests/ubuntu-download-manager-tests.pro 2013-09-25 16:08:38 +0000
@@ -26,7 +26,6 @@
26 test_download_manager.cpp \26 test_download_manager.cpp \
27 test_download_queue.cpp \27 test_download_queue.cpp \
28 test_network_reply.cpp \28 test_network_reply.cpp \
29 test_xdg_basedir.cpp \
30 fake_download_queue.cpp \29 fake_download_queue.cpp \
31 fake_uuid_factory.cpp \30 fake_uuid_factory.cpp \
32 fake_system_network_info.cpp \31 fake_system_network_info.cpp \
@@ -56,7 +55,6 @@
56 test_download_queue.h \55 test_download_queue.h \
57 test_network_reply.h \56 test_network_reply.h \
58 test_runner.h \57 test_runner.h \
59 test_xdg_basedir.h \
60 fake_download_queue.h \58 fake_download_queue.h \
61 fake_uuid_factory.h \59 fake_uuid_factory.h \
62 fake_system_network_info.h \60 fake_system_network_info.h \

Subscribers

People subscribed via source and target branches