Merge lp:~mandel/ubuntu-download-manager/execute-post-download into lp:ubuntu-download-manager

Proposed by Manuel de la Peña
Status: Merged
Merged at revision: 81
Proposed branch: lp:~mandel/ubuntu-download-manager/execute-post-download
Merge into: lp:ubuntu-download-manager
Diff against target: 1620 lines (+834/-89)
23 files modified
libubuntudownloadmanager/download.cpp (+103/-21)
libubuntudownloadmanager/download.h (+9/-2)
libubuntudownloadmanager/download_manager.cpp (+5/-2)
libubuntudownloadmanager/libubuntudownloadmanager.pro (+5/-1)
libubuntudownloadmanager/process.cpp (+95/-0)
libubuntudownloadmanager/process.h (+49/-0)
libubuntudownloadmanager/process_factory.cpp (+63/-0)
libubuntudownloadmanager/process_factory.h (+41/-0)
ubuntu-download-manager-tests/fake.cpp (+21/-0)
ubuntu-download-manager-tests/fake.h (+15/-0)
ubuntu-download-manager-tests/fake_download.cpp (+5/-4)
ubuntu-download-manager-tests/fake_download.h (+3/-2)
ubuntu-download-manager-tests/fake_network_reply.cpp (+5/-0)
ubuntu-download-manager-tests/fake_network_reply.h (+1/-0)
ubuntu-download-manager-tests/fake_process.cpp (+57/-0)
ubuntu-download-manager-tests/fake_process.h (+50/-0)
ubuntu-download-manager-tests/fake_process_factory.cpp (+48/-0)
ubuntu-download-manager-tests/fake_process_factory.h (+36/-0)
ubuntu-download-manager-tests/test_download.cpp (+200/-33)
ubuntu-download-manager-tests/test_download.h (+10/-0)
ubuntu-download-manager-tests/test_download_queue.cpp (+5/-22)
ubuntu-download-manager-tests/test_download_queue.h (+2/-0)
ubuntu-download-manager-tests/ubuntu-download-manager-tests.pro (+6/-2)
To merge this branch: bzr merge lp:~mandel/ubuntu-download-manager/execute-post-download
Reviewer Review Type Date Requested Status
Manuel de la Peña (community) Approve
Alejandro J. Cura (community) Approve
PS Jenkins bot continuous-integration Needs Fixing
Review via email: mp+176072@code.launchpad.net

Commit message

Allow process execution after download.
Fix broken tests.

Description of the change

Allow process execution after download.
Fix broken tests.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alejandro J. Cura (alecu) wrote :

+1

review: Approve
Revision history for this message
Manuel de la Peña (mandel) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'libubuntudownloadmanager/download.cpp'
--- libubuntudownloadmanager/download.cpp 2013-07-20 18:26:02 +0000
+++ libubuntudownloadmanager/download.cpp 2013-07-21 19:10:31 +0000
@@ -41,6 +41,8 @@
41#define ALGO "algo"41#define ALGO "algo"
42#define DATA_FILE_NAME "data"42#define DATA_FILE_NAME "data"
43#define METADATA_FILE_NAME "metadata"43#define METADATA_FILE_NAME "metadata"
44#define METADATA_COMMAND_KEY "post-download-command"
45#define METADATA_COMMAND_FILE_KEY "$file"
4446
4547
46/**48/**
@@ -52,10 +54,11 @@
52 Q_DECLARE_PUBLIC(Download)54 Q_DECLARE_PUBLIC(Download)
53public:55public:
54 explicit DownloadPrivate(const QUuid& id, const QString& path, const QUrl& url, const QVariantMap& metadata,56 explicit DownloadPrivate(const QUuid& id, const QString& path, const QUrl& url, const QVariantMap& metadata,
55 const QMap<QString, QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, Download* parent);57 const QMap<QString, QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, ProcessFactory* processFactory,
58 Download* parent);
56 explicit DownloadPrivate(const QUuid& id, const QString& path, const QUrl& url, const QString& hash,59 explicit DownloadPrivate(const QUuid& id, const QString& path, const QUrl& url, const QString& hash,
57 QCryptographicHash::Algorithm algo, const QVariantMap& metadata, const QMap<QString, QString>& headers,60 QCryptographicHash::Algorithm algo, const QVariantMap& metadata, const QMap<QString, QString>& headers,
58 SystemNetworkInfo* networkInfo, RequestFactory* nam,61 SystemNetworkInfo* networkInfo, RequestFactory* nam, ProcessFactory* processFactory,
59 Download* parent);62 Download* parent);
60 ~DownloadPrivate();63 ~DownloadPrivate();
6164
@@ -97,6 +100,10 @@
97 void onFinished();100 void onFinished();
98 void onSslErrors(const QList<QSslError>& errors);101 void onSslErrors(const QList<QSslError>& errors);
99102
103 // slots executed to keep track of the post download process
104 void onProcessError(QProcess::ProcessError error);
105 void onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
106
100private:107private:
101 void init();108 void init();
102 void connectToReplySignals();109 void connectToReplySignals();
@@ -123,6 +130,7 @@
123 QMap<QString, QString> _headers;130 QMap<QString, QString> _headers;
124 SystemNetworkInfo* _networkInfo;131 SystemNetworkInfo* _networkInfo;
125 RequestFactory* _requestFactory;132 RequestFactory* _requestFactory;
133 ProcessFactory* _processFactory;
126 NetworkReply* _reply;134 NetworkReply* _reply;
127 QFile* _currentData;135 QFile* _currentData;
128 Download* q_ptr;136 Download* q_ptr;
@@ -130,7 +138,8 @@
130};138};
131139
132DownloadPrivate::DownloadPrivate(const QUuid& id, const QString& path, const QUrl& url, const QVariantMap& metadata,140DownloadPrivate::DownloadPrivate(const QUuid& id, const QString& path, const QUrl& url, const QVariantMap& metadata,
133 const QMap<QString, QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, Download* parent):141 const QMap<QString, QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, ProcessFactory* processFactory,
142 Download* parent):
134 _id(id),143 _id(id),
135 _totalSize(0),144 _totalSize(0),
136 _throttle(0),145 _throttle(0),
@@ -144,6 +153,7 @@
144 _headers(headers),153 _headers(headers),
145 _networkInfo(networkInfo),154 _networkInfo(networkInfo),
146 _requestFactory(nam),155 _requestFactory(nam),
156 _processFactory(processFactory),
147 q_ptr(parent)157 q_ptr(parent)
148{158{
149 init();159 init();
@@ -151,7 +161,7 @@
151161
152DownloadPrivate::DownloadPrivate(const QUuid& id, const QString& path, const QUrl& url, const QString& hash,162DownloadPrivate::DownloadPrivate(const QUuid& id, const QString& path, const QUrl& url, const QString& hash,
153 QCryptographicHash::Algorithm algo, const QVariantMap& metadata, const QMap<QString, QString>& headers,163 QCryptographicHash::Algorithm algo, const QVariantMap& metadata, const QMap<QString, QString>& headers,
154 SystemNetworkInfo* networkInfo, RequestFactory* nam, Download* parent):164 SystemNetworkInfo* networkInfo, RequestFactory* nam, ProcessFactory* processFactory, Download* parent):
155 _id(id),165 _id(id),
156 _totalSize(0),166 _totalSize(0),
157 _throttle(0),167 _throttle(0),
@@ -165,6 +175,7 @@
165 _headers(headers),175 _headers(headers),
166 _networkInfo(networkInfo),176 _networkInfo(networkInfo),
167 _requestFactory(nam),177 _requestFactory(nam),
178 _processFactory(processFactory),
168 q_ptr(parent)179 q_ptr(parent)
169{180{
170 init();181 init();
@@ -496,7 +507,6 @@
496507
497 qDebug() << "Starting download.";508 qDebug() << "Starting download.";
498 // create file that will be used to mantain the state of the download when resumed.509 // create file that will be used to mantain the state of the download when resumed.
499 // TODO: Use a better name
500 _currentData = new QFile(saveFileName());510 _currentData = new QFile(saveFileName());
501 _currentData->open(QIODevice::ReadWrite | QFile::Append);511 _currentData->open(QIODevice::ReadWrite | QFile::Append);
502512
@@ -655,23 +665,94 @@
655 return;665 return;
656 }666 }
657 }667 }
668
669 // there are two possible cases, the first, we do no have the metadata info to execute a
670 // commnad once the download was finished and that means we are done here else we execute the
671 // command AND raise the finish signals once the command was done (or an error ocurred in the
672 // command execution.
673 if (_metadata.contains(METADATA_COMMAND_KEY))
674 {
675 // toStringList will return an empty list if it cannot be converted
676 QStringList commandData = _metadata[METADATA_COMMAND_KEY].toStringList();
677 if (commandData.count() == 0)
678 {
679 // raise error, command metadata was passed without the commnad
680 qCritical() << "COMMAND DATA MISSING";
681 _state = Download::FINISHED;
682 emit q->stateChanged();
683 emit q->error("COMMAND ERROR");
684 return;
685 }
686 else
687 {
688 // first item of the string list is the commnad, rest is the arguments
689 QString command = commandData.at(0);
690 commandData.removeAt(0);
691 QStringList args;
692
693 foreach(const QString& arg, commandData)
694 {
695 if (arg == METADATA_COMMAND_FILE_KEY)
696 args << filePath();
697 else
698 args << arg;
699 }
700
701 Process* postDownloadProcess = _processFactory->createProcess();
702
703 // connect to signals so that we can tell the clients that the operation succeed
704
705 q->connect(postDownloadProcess, SIGNAL(finished(int, QProcess::ExitStatus)),
706 q, SLOT(onProcessFinished(int, QProcess::ExitStatus)));
707 q->connect(postDownloadProcess, SIGNAL(error(QProcess::ProcessError)),
708 q, SLOT(onProcessError(QProcess::ProcessError)));
709
710 qDebug() << "Executing" << command << args;
711 postDownloadProcess->start(command, args);
712 return;
713 }
714 }
715 else
716 {
717 _state = Download::FINISHED;
718 qDebug() << "EMIT stateChanged";
719 emit q->stateChanged();
720 qDebug() << "EMIT finished" << filePath();
721 emit q->finished(filePath());
722 }
723
724 // clean the reply
725 _reply->deleteLater();
726 _reply = NULL;
727}
728
729void DownloadPrivate::onSslErrors(const QList<QSslError>& errors)
730{
731 qDebug() << __FUNCTION__ << _url;
732 // TODO: emit ssl errors signal?
733 Q_UNUSED(errors);
734 Q_Q(Download);
735 emit q->error("SSL ERROR");
736}
737
738void DownloadPrivate::onProcessError(QProcess::ProcessError error)
739{
740 // TODO: better error fowarding
741 Q_UNUSED(error);
742 Q_Q(Download);
743 emit q->error("COMMAND ERROR");
744}
745
746void DownloadPrivate::onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
747{
748 qDebug() << __FUNCTION__ << exitCode << exitStatus;
749 // TODO: send the command exit code and status
750 Q_Q(Download);
658 _state = Download::FINISHED;751 _state = Download::FINISHED;
659 qDebug() << "EMIT stateChanged";752 qDebug() << "EMIT stateChanged";
660 emit q->stateChanged();753 emit q->stateChanged();
661 qDebug() << "EMIT finished" << filePath();754 qDebug() << "EMIT finished" << filePath();
662 emit q->finished(filePath());755 emit q->finished(filePath());
663 _reply->deleteLater();
664 _reply = NULL;
665
666}
667
668void DownloadPrivate::onSslErrors(const QList<QSslError>& errors)
669{
670 qDebug() << __FUNCTION__ << _url;
671 // TODO: emit ssl errors signal?
672 Q_UNUSED(errors);
673 Q_Q(Download);
674 emit q->error("SSL ERROR");
675}756}
676757
677/**758/**
@@ -679,16 +760,17 @@
679 */760 */
680761
681Download::Download(const QUuid& id, const QString& path, const QUrl& url, const QVariantMap& metadata,762Download::Download(const QUuid& id, const QString& path, const QUrl& url, const QVariantMap& metadata,
682 const QMap<QString, QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, QObject* parent):763 const QMap<QString, QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, ProcessFactory* processFactory, QObject* parent):
683 QObject(parent),764 QObject(parent),
684 d_ptr(new DownloadPrivate(id, path, url, metadata, headers, networkInfo, nam, this))765 d_ptr(new DownloadPrivate(id, path, url, metadata, headers, networkInfo, nam, processFactory, this))
685{766{
686}767}
687768
688Download::Download(const QUuid& id, const QString& path, const QUrl& url, const QString& hash, QCryptographicHash::Algorithm algo,769Download::Download(const QUuid& id, const QString& path, const QUrl& url, const QString& hash, QCryptographicHash::Algorithm algo,
689 const QVariantMap& metadata, const QMap<QString, QString> &headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, QObject* parent):770 const QVariantMap& metadata, const QMap<QString, QString> &headers, SystemNetworkInfo* networkInfo, RequestFactory* nam,
771 ProcessFactory* processFactory, QObject* parent):
690 QObject(parent),772 QObject(parent),
691 d_ptr(new DownloadPrivate(id, path, url, hash, algo, metadata, headers, networkInfo, nam, this))773 d_ptr(new DownloadPrivate(id, path, url, hash, algo, metadata, headers, networkInfo, nam, processFactory, this))
692{774{
693}775}
694776
695777
=== modified file 'libubuntudownloadmanager/download.h'
--- libubuntudownloadmanager/download.h 2013-07-20 18:26:02 +0000
+++ libubuntudownloadmanager/download.h 2013-07-21 19:10:31 +0000
@@ -24,9 +24,11 @@
24#include <QBuffer>24#include <QBuffer>
25#include <QCryptographicHash>25#include <QCryptographicHash>
26#include <QNetworkReply>26#include <QNetworkReply>
27#include <QProcess>
27#include <QUrl>28#include <QUrl>
28#include <QUuid>29#include <QUuid>
29#include "system_network_info.h"30#include "system_network_info.h"
31#include "process_factory.h"
30#include "request_factory.h"32#include "request_factory.h"
31#include "app-downloader-lib_global.h"33#include "app-downloader-lib_global.h"
3234
@@ -48,10 +50,10 @@
48 };50 };
4951
50 explicit Download(const QUuid& id, const QString& path, const QUrl& url, const QVariantMap& metadata,52 explicit Download(const QUuid& id, const QString& path, const QUrl& url, const QVariantMap& metadata,
51 const QMap<QString, QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, QObject* parent=0);53 const QMap<QString, QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, ProcessFactory* processFactory, QObject* parent=0);
52 explicit Download(const QUuid& id, const QString& path, const QUrl& url, const QString& hash, QCryptographicHash::Algorithm algo,54 explicit Download(const QUuid& id, const QString& path, const QUrl& url, const QString& hash, QCryptographicHash::Algorithm algo,
53 const QVariantMap& metadata, const QMap<QString, QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam,55 const QVariantMap& metadata, const QMap<QString, QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam,
54 QObject* parent=0);56 ProcessFactory* processFactory, QObject* parent=0);
5557
56 // gets for internal state58 // gets for internal state
57 QUuid downloadId();59 QUuid downloadId();
@@ -110,6 +112,11 @@
110 Q_PRIVATE_SLOT(d_func(), void onFinished())112 Q_PRIVATE_SLOT(d_func(), void onFinished())
111 Q_PRIVATE_SLOT(d_func(), void onSslErrors(const QList<QSslError>&))113 Q_PRIVATE_SLOT(d_func(), void onSslErrors(const QList<QSslError>&))
112114
115 // private slots used to keep track of the post download command
116
117 Q_PRIVATE_SLOT(d_func(), void onProcessError(QProcess::ProcessError error))
118 Q_PRIVATE_SLOT(d_func(), void onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus))
119
113private:120private:
114 // use pimpl so that we can mantains ABI compatibility121 // use pimpl so that we can mantains ABI compatibility
115 DownloadPrivate* d_ptr;122 DownloadPrivate* d_ptr;
116123
=== modified file 'libubuntudownloadmanager/download_manager.cpp'
--- libubuntudownloadmanager/download_manager.cpp 2013-07-20 18:26:02 +0000
+++ libubuntudownloadmanager/download_manager.cpp 2013-07-21 19:10:31 +0000
@@ -18,6 +18,7 @@
1818
19#include <QRegExp>19#include <QRegExp>
20#include "request_factory.h"20#include "request_factory.h"
21#include "process_factory.h"
21#include "download_adaptor.h"22#include "download_adaptor.h"
22#include "download_queue.h"23#include "download_queue.h"
23#include "download_manager.h"24#include "download_manager.h"
@@ -58,6 +59,7 @@
58 DownloadQueue* _downloadsQueue;59 DownloadQueue* _downloadsQueue;
59 DBusConnection* _conn;60 DBusConnection* _conn;
60 RequestFactory* _reqFactory;61 RequestFactory* _reqFactory;
62 ProcessFactory* _processFactory;
61 UuidFactory* _uuidFactory;63 UuidFactory* _uuidFactory;
62 DownloadManager* q_ptr;64 DownloadManager* q_ptr;
63};65};
@@ -98,6 +100,7 @@
98 q, SLOT(onDownloadRemoved(QString)));100 q, SLOT(onDownloadRemoved(QString)));
99101
100 _reqFactory = new RequestFactory();102 _reqFactory = new RequestFactory();
103 _processFactory = new ProcessFactory();
101}104}
102105
103void DownloadManagerPrivate::addDownload(Download* download)106void DownloadManagerPrivate::addDownload(Download* download)
@@ -141,9 +144,9 @@
141 {144 {
142 Download* download;145 Download* download;
143 if (hash.isEmpty())146 if (hash.isEmpty())
144 download = new Download(id, path, url, metadata, headers, _networkInfo, _reqFactory);147 download = new Download(id, path, url, metadata, headers, _networkInfo, _reqFactory, _processFactory);
145 else148 else
146 download = new Download(id, path, url, hash, algo, metadata, headers, _networkInfo, _reqFactory);149 download = new Download(id, path, url, hash, algo, metadata, headers, _networkInfo, _reqFactory, _processFactory);
147150
148 download->setThrottle(_throttle);151 download->setThrottle(_throttle);
149 DownloadAdaptor* adaptor = new DownloadAdaptor(download);152 DownloadAdaptor* adaptor = new DownloadAdaptor(download);
150153
=== modified file 'libubuntudownloadmanager/libubuntudownloadmanager.pro'
--- libubuntudownloadmanager/libubuntudownloadmanager.pro 2013-07-20 14:08:52 +0000
+++ libubuntudownloadmanager/libubuntudownloadmanager.pro 2013-07-21 19:10:31 +0000
@@ -19,7 +19,9 @@
19 request_factory.cpp \19 request_factory.cpp \
20 system_network_info.cpp \20 system_network_info.cpp \
21 uuid_factory.cpp \21 uuid_factory.cpp \
22 xdg_basedir.cpp22 xdg_basedir.cpp \
23 process.cpp \
24 process_factory.cpp
2325
24HEADERS +=\26HEADERS +=\
25 app-downloader-lib_global.h \27 app-downloader-lib_global.h \
@@ -35,6 +37,8 @@
35 system_network_info.h \37 system_network_info.h \
36 uuid_factory.h \38 uuid_factory.h \
37 xdg_basedir.h \39 xdg_basedir.h \
40 process.h \
41 process_factory.h \
38 metatypes.h42 metatypes.h
3943
40OTHER_FILES += \44OTHER_FILES += \
4145
=== added file 'libubuntudownloadmanager/process.cpp'
--- libubuntudownloadmanager/process.cpp 1970-01-01 00:00:00 +0000
+++ libubuntudownloadmanager/process.cpp 2013-07-21 19:10:31 +0000
@@ -0,0 +1,95 @@
1/*
2 * Copyright 2013 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 <QProcess>
20#include "process.h"
21
22/*
23 * PRIVATE IMPLEMENTATION
24 */
25
26class ProcessPrivate
27{
28 Q_DECLARE_PUBLIC(Process)
29public:
30 explicit ProcessPrivate(Process* parent);
31 ~ProcessPrivate();
32
33 void start(const QString& program, const QStringList& arguments, QProcess::OpenMode mode = QProcess::ReadWrite);
34
35 void onError(QProcess::ProcessError error);
36 void onFinished(int exitCode, QProcess::ExitStatus exitStatus);
37
38private:
39 QProcess* _process;
40 Process* q_ptr;
41
42};
43
44ProcessPrivate::ProcessPrivate(Process* parent) :
45 q_ptr(parent)
46{
47 Q_Q(Process);
48 _process = new QProcess();
49
50 q->connect(_process, SIGNAL(finished(int, QProcess::ExitStatus)),
51 q, SLOT(onFinished(int, QProcess::ExitStatus)));
52 q->connect(_process, SIGNAL(error(QProcess::ProcessError)),
53 q, SLOT(onError(QProcess::ProcessError)));
54}
55
56ProcessPrivate::~ProcessPrivate()
57{
58 if (_process != NULL)
59 delete _process;
60}
61
62void ProcessPrivate::start(const QString& program, const QStringList& arguments, QProcess::OpenMode mode)
63{
64 _process->start(program, arguments, mode);
65}
66
67void ProcessPrivate::onError(QProcess::ProcessError error)
68{
69 Q_Q(Process);
70 emit q->error(error);
71}
72
73void ProcessPrivate::onFinished(int exitCode, QProcess::ExitStatus exitStatus)
74{
75 Q_Q(Process);
76 emit q->finished(exitCode, exitStatus);
77}
78
79/*
80 * PUBLIC IMPLEMENTATION
81 */
82
83Process::Process(QObject *parent) :
84 QObject(parent),
85 d_ptr(new ProcessPrivate(this))
86{
87}
88
89void Process::start(const QString& program, const QStringList& arguments, QProcess::OpenMode mode)
90{
91 Q_D(Process);
92 d->start(program, arguments, mode);
93}
94
95#include "moc_process.cpp"
096
=== added file 'libubuntudownloadmanager/process.h'
--- libubuntudownloadmanager/process.h 1970-01-01 00:00:00 +0000
+++ libubuntudownloadmanager/process.h 2013-07-21 19:10:31 +0000
@@ -0,0 +1,49 @@
1/*
2 * Copyright 2013 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_PROCESS_H
20#define DOWNLOADER_LIB_PROCESS_H
21
22#include <QObject>
23#include <QProcess>
24
25class ProcessPrivate;
26class Process : public QObject
27{
28 Q_OBJECT
29 Q_DECLARE_PRIVATE(Process)
30
31public:
32 explicit Process(QObject *parent = 0);
33
34 virtual void start(const QString& program, const QStringList& arguments, QProcess::OpenMode mode = QProcess::ReadWrite);
35
36signals:
37 void error(QProcess::ProcessError error);
38 void finished(int exitCode, QProcess::ExitStatus exitStatus);
39
40private:
41 Q_PRIVATE_SLOT(d_func(), void onError(QProcess::ProcessError error))
42 Q_PRIVATE_SLOT(d_func(), void onFinished(int exitCode, QProcess::ExitStatus exitStatus))
43
44private:
45 // use pimpl so that we can mantains ABI compatibility
46 ProcessPrivate* d_ptr;
47};
48
49#endif // PROCESS_H
050
=== added file 'libubuntudownloadmanager/process_factory.cpp'
--- libubuntudownloadmanager/process_factory.cpp 1970-01-01 00:00:00 +0000
+++ libubuntudownloadmanager/process_factory.cpp 2013-07-21 19:10:31 +0000
@@ -0,0 +1,63 @@
1/*
2 * Copyright 2013 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 "process_factory.h"
20
21/*
22 * PRIVATE IMPLEMENTATION
23 */
24
25class ProcessFactoryPrivate
26{
27 Q_DECLARE_PUBLIC(ProcessFactory)
28public:
29 explicit ProcessFactoryPrivate(ProcessFactory* parent);
30
31 Process* createProcess();
32
33private:
34 ProcessFactory* q_ptr;
35
36};
37
38
39ProcessFactoryPrivate::ProcessFactoryPrivate(ProcessFactory* parent):
40 q_ptr(parent)
41{
42}
43
44Process* ProcessFactoryPrivate::createProcess()
45{
46 return new Process();
47}
48
49/*
50 * PUBLIC IMPLEMENTATION
51 */
52
53ProcessFactory::ProcessFactory(QObject *parent) :
54 QObject(parent),
55 d_ptr(new ProcessFactoryPrivate(this))
56{
57}
58
59Process* ProcessFactory::createProcess()
60{
61 Q_D(ProcessFactory);
62 return d->createProcess();
63}
064
=== added file 'libubuntudownloadmanager/process_factory.h'
--- libubuntudownloadmanager/process_factory.h 1970-01-01 00:00:00 +0000
+++ libubuntudownloadmanager/process_factory.h 2013-07-21 19:10:31 +0000
@@ -0,0 +1,41 @@
1/*
2 * Copyright 2013 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_PROCESS_FACTORY_H
20#define DOWNLOADER_LIB_PROCESS_FACTORY_H
21
22#include <QObject>
23#include "process.h"
24
25class ProcessFactoryPrivate;
26class ProcessFactory : public QObject
27{
28 Q_OBJECT
29 Q_DECLARE_PRIVATE(ProcessFactory)
30
31public:
32 explicit ProcessFactory(QObject *parent = 0);
33
34 virtual Process* createProcess();
35
36private:
37 // use pimpl so that we can mantains ABI compatibility
38 ProcessFactoryPrivate* d_ptr;
39};
40
41#endif
042
=== modified file 'ubuntu-download-manager-tests/fake.cpp'
--- ubuntu-download-manager-tests/fake.cpp 2013-07-08 16:46:16 +0000
+++ ubuntu-download-manager-tests/fake.cpp 2013-07-21 19:10:31 +0000
@@ -60,6 +60,27 @@
60}60}
6161
62/*62/*
63 * STRING LIST WRAPPER
64 */
65
66
67StringListWrapper::StringListWrapper(const QStringList& list, QObject* parent) :
68 QObject(parent)
69{
70 _value = list;
71}
72
73QStringList StringListWrapper::value()
74{
75 return _value;
76}
77
78void StringListWrapper::setValue(const QStringList& value)
79{
80 _value = value;
81}
82
83/*
63 * UINT WRAPPER84 * UINT WRAPPER
64 */85 */
6586
6687
=== modified file 'ubuntu-download-manager-tests/fake.h'
--- ubuntu-download-manager-tests/fake.h 2013-07-08 16:46:16 +0000
+++ ubuntu-download-manager-tests/fake.h 2013-07-21 19:10:31 +0000
@@ -22,6 +22,7 @@
22#include <QList>22#include <QList>
23#include <QObject>23#include <QObject>
24#include <QPair>24#include <QPair>
25#include <QStringList>
2526
2627
27class BoolWrapper : public QObject28class BoolWrapper : public QObject
@@ -52,6 +53,20 @@
52};53};
5354
5455
56class StringListWrapper : public QObject
57{
58 Q_OBJECT
59
60public:
61 StringListWrapper(const QStringList& list, QObject* parent=0);
62
63 QStringList value();
64 void setValue(const QStringList& value);
65
66private:
67 QStringList _value;
68};
69
55class UintWrapper : public QObject70class UintWrapper : public QObject
56{71{
57 Q_OBJECT72 Q_OBJECT
5873
=== modified file 'ubuntu-download-manager-tests/fake_download.cpp'
--- ubuntu-download-manager-tests/fake_download.cpp 2013-07-20 18:26:02 +0000
+++ ubuntu-download-manager-tests/fake_download.cpp 2013-07-21 19:10:31 +0000
@@ -19,15 +19,16 @@
19#include "fake_download.h"19#include "fake_download.h"
2020
21FakeDownload::FakeDownload(const QUuid& id, const QString& path, const QUrl& url, const QVariantMap& metadata,21FakeDownload::FakeDownload(const QUuid& id, const QString& path, const QUrl& url, const QVariantMap& metadata,
22 const QMap<QString, QString> &headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, QObject* parent):22 const QMap<QString, QString> &headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, ProcessFactory* processFactory, QObject* parent):
23 Download(id, path, url, metadata, headers, networkInfo, nam, parent),23 Download(id, path, url, metadata, headers, networkInfo, nam, processFactory, parent),
24 _canDownload(true)24 _canDownload(true)
25{25{
26}26}
2727
28FakeDownload::FakeDownload(const QUuid& id, const QString& path, const QUrl& url, const QString& hash, QCryptographicHash::Algorithm algo,28FakeDownload::FakeDownload(const QUuid& id, const QString& path, const QUrl& url, const QString& hash, QCryptographicHash::Algorithm algo,
29 const QVariantMap& metadata, const QMap<QString ,QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, QObject* parent) :29 const QVariantMap& metadata, const QMap<QString ,QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam,
30 Download(id, path, url, hash, algo, metadata, headers, networkInfo, nam, parent),30 ProcessFactory* processFactory, QObject* parent) :
31 Download(id, path, url, hash, algo, metadata, headers, networkInfo, nam, processFactory, parent),
31 _canDownload(true)32 _canDownload(true)
32{33{
33}34}
3435
=== modified file 'ubuntu-download-manager-tests/fake_download.h'
--- ubuntu-download-manager-tests/fake_download.h 2013-07-20 18:26:02 +0000
+++ ubuntu-download-manager-tests/fake_download.h 2013-07-21 19:10:31 +0000
@@ -28,10 +28,11 @@
28 Q_OBJECT28 Q_OBJECT
29public:29public:
30 explicit FakeDownload(const QUuid& id, const QString& path, const QUrl& url, const QVariantMap& metadata,30 explicit FakeDownload(const QUuid& id, const QString& path, const QUrl& url, const QVariantMap& metadata,
31 const QMap<QString, QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, QObject* parent=0);31 const QMap<QString, QString>& headers, SystemNetworkInfo* networkInfo, RequestFactory* nam, ProcessFactory* processFactory,
32 QObject* parent=0);
32 explicit FakeDownload(const QUuid& id, const QString& path, const QUrl& url, const QString& hash,33 explicit FakeDownload(const QUuid& id, const QString& path, const QUrl& url, const QString& hash,
33 QCryptographicHash::Algorithm algo, const QVariantMap& metadata, const QMap<QString, QString> &headers,34 QCryptographicHash::Algorithm algo, const QVariantMap& metadata, const QMap<QString, QString> &headers,
34 SystemNetworkInfo* networkInfo, RequestFactory* nam, QObject* parent=0);35 SystemNetworkInfo* networkInfo, RequestFactory* nam, ProcessFactory* processFactory, QObject* parent=0);
3536
36 bool canDownload() override;37 bool canDownload() override;
37 void setCanDownload(bool canDownload);38 void setCanDownload(bool canDownload);
3839
=== modified file 'ubuntu-download-manager-tests/fake_network_reply.cpp'
--- ubuntu-download-manager-tests/fake_network_reply.cpp 2013-07-08 16:46:16 +0000
+++ ubuntu-download-manager-tests/fake_network_reply.cpp 2013-07-21 19:10:31 +0000
@@ -69,3 +69,8 @@
69 _called.append(methodData);69 _called.append(methodData);
70 }70 }
71}71}
72
73void FakeNetworkReply::emitFinished()
74{
75 emit finished();
76}
7277
=== modified file 'ubuntu-download-manager-tests/fake_network_reply.h'
--- ubuntu-download-manager-tests/fake_network_reply.h 2013-07-08 16:46:16 +0000
+++ ubuntu-download-manager-tests/fake_network_reply.h 2013-07-21 19:10:31 +0000
@@ -38,6 +38,7 @@
38 QByteArray readAll() override;38 QByteArray readAll() override;
39 void abort() override;39 void abort() override;
40 void setReadBufferSize(uint size) override;40 void setReadBufferSize(uint size) override;
41 void emitFinished();
4142
42private:43private:
43 QByteArray _data;44 QByteArray _data;
4445
=== added file 'ubuntu-download-manager-tests/fake_process.cpp'
--- ubuntu-download-manager-tests/fake_process.cpp 1970-01-01 00:00:00 +0000
+++ ubuntu-download-manager-tests/fake_process.cpp 2013-07-21 19:10:31 +0000
@@ -0,0 +1,57 @@
1/*
2 * Copyright 2013 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 "fake_process.h"
20
21OpenModeWrapper::OpenModeWrapper(QProcess::OpenMode mode, QObject* parent) :
22 QObject(parent)
23{
24 _value = mode;
25}
26
27QProcess::OpenMode OpenModeWrapper::value()
28{
29 return _value;
30}
31
32void OpenModeWrapper::setValue(QProcess::OpenMode value)
33{
34 _value = value;
35}
36
37FakeProcess::FakeProcess(QObject *parent) :
38 Process(parent),
39 Fake()
40{
41}
42
43void FakeProcess::start(const QString& program, const QStringList& arguments, QProcess::OpenMode mode)
44{
45 if (_recording)
46 {
47 QList<QObject*> inParams;
48 inParams.append(new StringWrapper(program));
49 inParams.append(new StringListWrapper(arguments));
50 inParams.append(new OpenModeWrapper(mode));
51
52 QList<QObject*> outParams;
53 MethodParams params(inParams, outParams);
54 MethodData methodData("start", params);
55 _called.append(methodData);
56 }
57}
058
=== added file 'ubuntu-download-manager-tests/fake_process.h'
--- ubuntu-download-manager-tests/fake_process.h 1970-01-01 00:00:00 +0000
+++ ubuntu-download-manager-tests/fake_process.h 2013-07-21 19:10:31 +0000
@@ -0,0 +1,50 @@
1/*
2 * Copyright 2013 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 FAKE_PROCESS_H
20#define FAKE_PROCESS_H
21
22#include <QObject>
23#include <process.h>
24#include "fake.h"
25
26class OpenModeWrapper: public QObject
27{
28 Q_OBJECT
29
30public:
31 OpenModeWrapper(QProcess::OpenMode mode, QObject* parent=0);
32
33 QProcess::OpenMode value();
34 void setValue(QProcess::OpenMode value);
35
36private:
37 QProcess::OpenMode _value;
38};
39
40class FakeProcess : public Process, public Fake
41{
42 Q_OBJECT
43public:
44 explicit FakeProcess(QObject *parent = 0);
45
46 void start(const QString& program, const QStringList& arguments, QProcess::OpenMode mode = QProcess::ReadWrite) override;
47
48};
49
50#endif // FAKE_PROCESS_H
051
=== added file 'ubuntu-download-manager-tests/fake_process_factory.cpp'
--- ubuntu-download-manager-tests/fake_process_factory.cpp 1970-01-01 00:00:00 +0000
+++ ubuntu-download-manager-tests/fake_process_factory.cpp 2013-07-21 19:10:31 +0000
@@ -0,0 +1,48 @@
1/*
2 * Copyright 2013 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 "fake_process_factory.h"
20#include "fake_process.h"
21
22FakeProcessFactory::FakeProcessFactory(QObject *parent) :
23 ProcessFactory(parent),
24 Fake()
25{
26}
27
28Process* FakeProcessFactory::createProcess()
29{
30
31 FakeProcess* process = new FakeProcess();
32
33 if (_recording)
34 {
35 QList<QObject*> inParams;
36
37 QList<QObject*> outParams;
38 outParams.append(process);
39 MethodParams params(inParams, outParams);
40
41 MethodData methodData("createProcess", params);
42 _called.append(methodData);
43
44 // if we are recording we do set the recording of the returned process
45 process->record();
46 }
47 return process;
48}
049
=== added file 'ubuntu-download-manager-tests/fake_process_factory.h'
--- ubuntu-download-manager-tests/fake_process_factory.h 1970-01-01 00:00:00 +0000
+++ ubuntu-download-manager-tests/fake_process_factory.h 2013-07-21 19:10:31 +0000
@@ -0,0 +1,36 @@
1/*
2 * Copyright 2013 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 FAKE_PROCESS_FACTORY_H
20#define FAKE_PROCESS_FACTORY_H
21
22#include <QObject>
23#include <process_factory.h>
24#include "fake.h"
25
26class FakeProcessFactory : public ProcessFactory, public Fake
27{
28 Q_OBJECT
29public:
30 explicit FakeProcessFactory(QObject *parent = 0);
31
32 Process* createProcess() override;
33
34};
35
36#endif // FAKE_PROCESS_FACTORY_H
037
=== modified file 'ubuntu-download-manager-tests/test_download.cpp'
--- ubuntu-download-manager-tests/test_download.cpp 2013-07-20 18:26:02 +0000
+++ ubuntu-download-manager-tests/test_download.cpp 2013-07-21 19:10:31 +0000
@@ -22,6 +22,7 @@
22#include <QSignalSpy>22#include <QSignalSpy>
23#include <QSslError>23#include <QSslError>
24#include "fake_network_reply.h"24#include "fake_network_reply.h"
25#include "fake_process.h"
25#include "test_download.h"26#include "test_download.h"
2627
27TestDownload::TestDownload(QObject* parent) :28TestDownload::TestDownload(QObject* parent) :
@@ -73,6 +74,7 @@
73 _algo = QCryptographicHash::Sha256;74 _algo = QCryptographicHash::Sha256;
74 _networkInfo = new FakeSystemNetworkInfo();75 _networkInfo = new FakeSystemNetworkInfo();
75 _reqFactory = new FakeRequestFactory();76 _reqFactory = new FakeRequestFactory();
77 _processFactory = new FakeProcessFactory();
76}78}
7779
78void TestDownload::cleanup()80void TestDownload::cleanup()
@@ -81,6 +83,8 @@
81 delete _networkInfo;83 delete _networkInfo;
82 if (_reqFactory)84 if (_reqFactory)
83 delete _reqFactory;85 delete _reqFactory;
86 if (_processFactory)
87 delete _processFactory;
8488
85 // try to remove the test dir89 // try to remove the test dir
86 removeDir(_testDir.absolutePath());90 removeDir(_testDir.absolutePath());
@@ -105,7 +109,7 @@
105 QFETCH(QString, path);109 QFETCH(QString, path);
106 QFETCH(QUrl, url);110 QFETCH(QUrl, url);
107111
108 Download* download = new Download(id, path, url, _metadata, _headers, _networkInfo, _reqFactory);112 Download* download = new Download(id, path, url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
109113
110 // assert that we did set the intial state correctly114 // assert that we did set the intial state correctly
111 // gets for internal state115 // gets for internal state
@@ -147,7 +151,7 @@
147 QFETCH(int, algo);151 QFETCH(int, algo);
148152
149 Download* download = new Download(id, path, url, hash, (QCryptographicHash::Algorithm)algo, _metadata, _headers, _networkInfo,153 Download* download = new Download(id, path, url, hash, (QCryptographicHash::Algorithm)algo, _metadata, _headers, _networkInfo,
150 _reqFactory);154 _reqFactory, _processFactory);
151155
152 QCOMPARE(download->downloadId(), id);156 QCOMPARE(download->downloadId(), id);
153 QCOMPARE(download->path(), path);157 QCOMPARE(download->path(), path);
@@ -176,7 +180,7 @@
176{180{
177 // create an app download and assert that the returned data is correct181 // create an app download and assert that the returned data is correct
178 QFETCH(QString, path);182 QFETCH(QString, path);
179 Download* download = new Download(_id, path, _url, _metadata, _headers, _networkInfo, _reqFactory);183 Download* download = new Download(_id, path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
180 QCOMPARE(download->path(), path);184 QCOMPARE(download->path(), path);
181}185}
182186
@@ -195,7 +199,7 @@
195{199{
196 // create an app download and assert that the returned data is correct200 // create an app download and assert that the returned data is correct
197 QFETCH(QUrl, url);201 QFETCH(QUrl, url);
198 Download* download = new Download(_id, _path, url, _metadata, _headers, _networkInfo, _reqFactory);202 Download* download = new Download(_id, _path, url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
199 QCOMPARE(download->url(), url);203 QCOMPARE(download->url(), url);
200 delete download;204 delete download;
201}205}
@@ -219,7 +223,7 @@
219 QFETCH(qulonglong, total);223 QFETCH(qulonglong, total);
220224
221 _reqFactory->record();225 _reqFactory->record();
222 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory);226 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
223 QSignalSpy spy(download , SIGNAL(progress(qulonglong, qulonglong)));227 QSignalSpy spy(download , SIGNAL(progress(qulonglong, qulonglong)));
224228
225 // start the download so that we do have access to the reply229 // start the download so that we do have access to the reply
@@ -248,7 +252,7 @@
248252
249 // assert that the total size is just set once by emitting two signals with diff sizes253 // assert that the total size is just set once by emitting two signals with diff sizes
250 _reqFactory->record();254 _reqFactory->record();
251 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory);255 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
252 QSignalSpy spy(download , SIGNAL(progress(qulonglong, qulonglong)));256 QSignalSpy spy(download , SIGNAL(progress(qulonglong, qulonglong)));
253257
254 // start the download so that we do have access to the reply258 // start the download so that we do have access to the reply
@@ -267,7 +271,7 @@
267271
268void TestDownload::testTotalSizeNoProgress()272void TestDownload::testTotalSizeNoProgress()
269{273{
270 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory);274 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
271 QCOMPARE(0ULL, download->totalSize());275 QCOMPARE(0ULL, download->totalSize());
272 delete download;276 delete download;
273}277}
@@ -285,7 +289,7 @@
285void TestDownload::testSetThrottleNoReply()289void TestDownload::testSetThrottleNoReply()
286{290{
287 QFETCH(qulonglong, speed);291 QFETCH(qulonglong, speed);
288 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory);292 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
289 download->setThrottle(speed);293 download->setThrottle(speed);
290 QCOMPARE(speed, download->throttle());294 QCOMPARE(speed, download->throttle());
291}295}
@@ -305,7 +309,7 @@
305 QFETCH(uint, speed);309 QFETCH(uint, speed);
306310
307 _reqFactory->record();311 _reqFactory->record();
308 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory);312 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
309 download->setThrottle(speed);313 download->setThrottle(speed);
310314
311 download->start(); // change state315 download->start(); // change state
@@ -332,7 +336,7 @@
332{336{
333 QFETCH(bool, value);337 QFETCH(bool, value);
334338
335 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory);339 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
336 download->allowGSMDownload(value);340 download->allowGSMDownload(value);
337 QSignalSpy spy(download , SIGNAL(stateChanged()));341 QSignalSpy spy(download , SIGNAL(stateChanged()));
338342
@@ -354,7 +358,7 @@
354 QFETCH(bool, oldValue);358 QFETCH(bool, oldValue);
355 QFETCH(bool, newValue);359 QFETCH(bool, newValue);
356360
357 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory);361 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
358 download->allowGSMDownload(oldValue);362 download->allowGSMDownload(oldValue);
359 QSignalSpy spy(download , SIGNAL(stateChanged()));363 QSignalSpy spy(download , SIGNAL(stateChanged()));
360364
@@ -395,7 +399,7 @@
395 _networkInfo->setMode(mode.value<QNetworkInfo::NetworkMode>());399 _networkInfo->setMode(mode.value<QNetworkInfo::NetworkMode>());
396 _networkInfo->record();400 _networkInfo->record();
397401
398 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory);402 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
399 download->allowGSMDownload(true);403 download->allowGSMDownload(true);
400 QVERIFY(download->canDownload());404 QVERIFY(download->canDownload());
401 QList<MethodData> calledMethods = _networkInfo->calledMethods();405 QList<MethodData> calledMethods = _networkInfo->calledMethods();
@@ -439,7 +443,7 @@
439 _networkInfo->setMode(mode.value<QNetworkInfo::NetworkMode>());443 _networkInfo->setMode(mode.value<QNetworkInfo::NetworkMode>());
440 _networkInfo->record();444 _networkInfo->record();
441445
442 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory);446 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
443 download->allowGSMDownload(false);447 download->allowGSMDownload(false);
444448
445 QCOMPARE(result, download->canDownload());449 QCOMPARE(result, download->canDownload());
@@ -449,7 +453,7 @@
449453
450void TestDownload::testCancel()454void TestDownload::testCancel()
451{455{
452 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory);456 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
453 QSignalSpy spy(download , SIGNAL(stateChanged()));457 QSignalSpy spy(download , SIGNAL(stateChanged()));
454 download->cancel();458 download->cancel();
455459
@@ -460,7 +464,7 @@
460464
461void TestDownload::testPause()465void TestDownload::testPause()
462{466{
463 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory);467 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
464 QSignalSpy spy(download , SIGNAL(stateChanged()));468 QSignalSpy spy(download , SIGNAL(stateChanged()));
465 download->pause();469 download->pause();
466470
@@ -471,7 +475,7 @@
471475
472void TestDownload::testResume()476void TestDownload::testResume()
473{477{
474 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory);478 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
475 QSignalSpy spy(download , SIGNAL(stateChanged()));479 QSignalSpy spy(download , SIGNAL(stateChanged()));
476 download->resume();480 download->resume();
477481
@@ -482,7 +486,7 @@
482486
483void TestDownload::testStart()487void TestDownload::testStart()
484{488{
485 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory);489 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
486 QSignalSpy spy(download , SIGNAL(stateChanged()));490 QSignalSpy spy(download , SIGNAL(stateChanged()));
487 download->start();491 download->start();
488492
@@ -496,7 +500,7 @@
496 // tell the fake nam to record so that we can access the reply500 // tell the fake nam to record so that we can access the reply
497501
498 _reqFactory->record();502 _reqFactory->record();
499 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory);503 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
500 QSignalSpy spy(download , SIGNAL(canceled(bool)));504 QSignalSpy spy(download , SIGNAL(canceled(bool)));
501505
502 download->start(); // change state506 download->start(); // change state
@@ -526,7 +530,7 @@
526void TestDownload::testCancelDownloadNotStarted()530void TestDownload::testCancelDownloadNotStarted()
527{531{
528 _reqFactory->record();532 _reqFactory->record();
529 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory);533 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
530 QSignalSpy spy(download , SIGNAL(canceled(bool)));534 QSignalSpy spy(download , SIGNAL(canceled(bool)));
531535
532 download->cancel(); // change state536 download->cancel(); // change state
@@ -545,7 +549,7 @@
545void TestDownload::testPauseDownload()549void TestDownload::testPauseDownload()
546{550{
547 _reqFactory->record();551 _reqFactory->record();
548 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory);552 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
549 QSignalSpy spy(download , SIGNAL(paused(bool)));553 QSignalSpy spy(download , SIGNAL(paused(bool)));
550554
551 download->start(); // change state555 download->start(); // change state
@@ -579,7 +583,7 @@
579583
580void TestDownload::testPauseDownloadNotStarted()584void TestDownload::testPauseDownloadNotStarted()
581{585{
582 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory);586 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
583 QSignalSpy spy(download , SIGNAL(paused(bool)));587 QSignalSpy spy(download , SIGNAL(paused(bool)));
584588
585 download->pause();589 download->pause();
@@ -594,7 +598,7 @@
594598
595void TestDownload::testResumeRunning()599void TestDownload::testResumeRunning()
596{600{
597 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory);601 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
598 QSignalSpy spy(download , SIGNAL(resumed(bool)));602 QSignalSpy spy(download , SIGNAL(resumed(bool)));
599603
600 download->start();604 download->start();
@@ -612,7 +616,7 @@
612void TestDownload::testResumeDownload()616void TestDownload::testResumeDownload()
613{617{
614 _reqFactory->record();618 _reqFactory->record();
615 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory);619 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
616 QSignalSpy spy(download , SIGNAL(paused(bool)));620 QSignalSpy spy(download , SIGNAL(paused(bool)));
617621
618 download->start(); // change state622 download->start(); // change state
@@ -645,7 +649,7 @@
645void TestDownload::testStartDownload()649void TestDownload::testStartDownload()
646{650{
647 _reqFactory->record();651 _reqFactory->record();
648 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory);652 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
649 QSignalSpy spy(download , SIGNAL(started(bool)));653 QSignalSpy spy(download , SIGNAL(started(bool)));
650654
651 download->start(); // change state655 download->start(); // change state
@@ -665,7 +669,7 @@
665void TestDownload::testStartDownloadAlreadyStarted()669void TestDownload::testStartDownloadAlreadyStarted()
666{670{
667 _reqFactory->record();671 _reqFactory->record();
668 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory);672 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
669 QSignalSpy spy(download , SIGNAL(started(bool)));673 QSignalSpy spy(download , SIGNAL(started(bool)));
670674
671 download->start(); // change state675 download->start(); // change state
@@ -686,7 +690,7 @@
686void TestDownload::testOnSuccessNoHash()690void TestDownload::testOnSuccessNoHash()
687{691{
688 _reqFactory->record();692 _reqFactory->record();
689 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory);693 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
690 QSignalSpy spy(download , SIGNAL(finished(QString)));694 QSignalSpy spy(download , SIGNAL(finished(QString)));
691695
692 download->start(); // change state696 download->start(); // change state
@@ -706,7 +710,7 @@
706{710{
707 _reqFactory->record();711 _reqFactory->record();
708 Download* download = new Download(_id, _path, _url, "imposible-hash-is-not-hex", _algo, _metadata, _headers,712 Download* download = new Download(_id, _path, _url, "imposible-hash-is-not-hex", _algo, _metadata, _headers,
709 _networkInfo, _reqFactory);713 _networkInfo, _reqFactory, _processFactory);
710 QSignalSpy spy(download , SIGNAL(error(QString)));714 QSignalSpy spy(download , SIGNAL(error(QString)));
711715
712 download->start(); // change state716 download->start(); // change state
@@ -763,7 +767,8 @@
763 QFETCH(QString, hash);767 QFETCH(QString, hash);
764768
765 _reqFactory->record();769 _reqFactory->record();
766 Download* download = new Download(_id, _path, _url, hash, _algo, _metadata, _headers, _networkInfo, _reqFactory);770 Download* download = new Download(_id, _path, _url, hash, _algo, _metadata, _headers, _networkInfo, _reqFactory,
771 _processFactory);
767 QSignalSpy spy(download , SIGNAL(finished(QString)));772 QSignalSpy spy(download , SIGNAL(finished(QString)));
768773
769 download->start(); // change state774 download->start(); // change state
@@ -797,7 +802,7 @@
797void TestDownload::testOnHttpError()802void TestDownload::testOnHttpError()
798{803{
799 _reqFactory->record();804 _reqFactory->record();
800 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory);805 Download* download = new Download(_id, _path, _url, _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
801 QSignalSpy spy(download , SIGNAL(error(QString)));806 QSignalSpy spy(download , SIGNAL(error(QString)));
802807
803 download->start(); // change state808 download->start(); // change state
@@ -845,7 +850,7 @@
845{850{
846 QFETCH(StringMap, headers);851 QFETCH(StringMap, headers);
847 _reqFactory->record();852 _reqFactory->record();
848 Download* download = new Download(_id, _path, _url, _metadata, headers, _networkInfo, _reqFactory);853 Download* download = new Download(_id, _path, _url, _metadata, headers, _networkInfo, _reqFactory, _processFactory);
849854
850 download->start(); // change state855 download->start(); // change state
851 download->startDownload();856 download->startDownload();
@@ -898,7 +903,7 @@
898 // similar to the previous test but we want to ensure that range is not set903 // similar to the previous test but we want to ensure that range is not set
899 QFETCH(StringMap, headers);904 QFETCH(StringMap, headers);
900 _reqFactory->record();905 _reqFactory->record();
901 Download* download = new Download(_id, _path, _url, _metadata, headers, _networkInfo, _reqFactory);906 Download* download = new Download(_id, _path, _url, _metadata, headers, _networkInfo, _reqFactory, _processFactory);
902907
903 download->start(); // change state908 download->start(); // change state
904 download->startDownload();909 download->startDownload();
@@ -943,7 +948,7 @@
943 QFETCH(StringMap, headers);948 QFETCH(StringMap, headers);
944949
945 _reqFactory->record();950 _reqFactory->record();
946 Download* download = new Download(_id, _path, _url, _metadata, headers, _networkInfo, _reqFactory);951 Download* download = new Download(_id, _path, _url, _metadata, headers, _networkInfo, _reqFactory, _processFactory);
947 QSignalSpy spy(download , SIGNAL(paused(bool)));952 QSignalSpy spy(download , SIGNAL(paused(bool)));
948953
949 download->start(); // change state954 download->start(); // change state
@@ -1017,7 +1022,7 @@
1017 QFETCH(StringMap, headers);1022 QFETCH(StringMap, headers);
10181023
1019 _reqFactory->record();1024 _reqFactory->record();
1020 Download* download = new Download(_id, _path, _url, _metadata, headers, _networkInfo, _reqFactory);1025 Download* download = new Download(_id, _path, _url, _metadata, headers, _networkInfo, _reqFactory, _processFactory);
1021 QSignalSpy spy(download , SIGNAL(paused(bool)));1026 QSignalSpy spy(download , SIGNAL(paused(bool)));
10221027
1023 download->start(); // change state1028 download->start(); // change state
@@ -1047,3 +1052,165 @@
1047 QByteArray rangeHeaderValue = "bytes=" + QByteArray::number(reply->data().size()) + "-";1052 QByteArray rangeHeaderValue = "bytes=" + QByteArray::number(reply->data().size()) + "-";
1048 QCOMPARE(rangeHeaderValue, request.rawHeader("Range"));1053 QCOMPARE(rangeHeaderValue, request.rawHeader("Range"));
1049}1054}
1055
1056void TestDownload::testProcessExecutedNoParams_data()
1057{
1058 QTest::addColumn<QString>("command");
1059 QTest::addColumn<QVariantMap>("metadata");
1060 QVariantMap first, second, third;
1061 QStringList firstCommand, secondCommand, thirdCommand;
1062
1063 firstCommand << "touch";
1064 first["post-download-command"] = firstCommand;
1065
1066 QTest::newRow("First row") << firstCommand[0] << first;
1067
1068 secondCommand << "sudo";
1069 second["post-download-command"] = secondCommand;
1070
1071 QTest::newRow("Second row") << secondCommand[0] << second;
1072
1073 thirdCommand << "grep";
1074 third["post-download-command"] = thirdCommand;
1075
1076 QTest::newRow("Third row") << thirdCommand[0] << third;
1077}
1078
1079void TestDownload::testProcessExecutedNoParams()
1080{
1081 QFETCH(QString, command);
1082 QFETCH(QVariantMap, metadata);
1083
1084 _processFactory->record();
1085 _reqFactory->record();
1086 Download* download = new Download(_id, _path, _url, metadata, _headers, _networkInfo, _reqFactory, _processFactory);
1087
1088 download->start(); // change state
1089 download->startDownload();
1090
1091 // we need to set the data before we pause!!!
1092 QList<MethodData> calledMethods = _reqFactory->calledMethods();
1093 QCOMPARE(1, calledMethods.count());
1094 FakeNetworkReply* reply = (FakeNetworkReply*) calledMethods[0].params().outParams()[0];
1095
1096 // makes the process to be executed
1097 reply->emitFinished();
1098
1099 calledMethods = _processFactory->calledMethods();
1100 QCOMPARE(1, calledMethods.count());
1101 FakeProcess* process = (FakeProcess*) calledMethods[0].params().outParams()[0];
1102
1103 calledMethods = process->calledMethods();
1104 QString processCommand = ((StringWrapper*)calledMethods[0].params().inParams()[0])->value();
1105 QStringList processArgs = ((StringListWrapper*)calledMethods[0].params().inParams()[1])->value();
1106 QCOMPARE(processCommand, command);
1107 QCOMPARE(0, processArgs.count());
1108}
1109
1110void TestDownload::testProcessExecutedWithParams_data()
1111{
1112 QTest::addColumn<QString>("command");
1113 QTest::addColumn<QVariantMap>("metadata");
1114 QVariantMap first, second, third;
1115 QStringList firstCommand, secondCommand, thirdCommand;
1116
1117 firstCommand << "touch" << "test-file";
1118 first["post-download-command"] = firstCommand;
1119
1120 QTest::newRow("First row") << firstCommand[0] << first;
1121
1122 secondCommand << "sudo" << "apt-get" << "install" << "click";
1123 second["post-download-command"] = secondCommand;
1124
1125 QTest::newRow("Second row") << secondCommand[0] << second;
1126
1127 thirdCommand << "grep" << "." << "-Rn";
1128 third["post-download-command"] = thirdCommand;
1129
1130 QTest::newRow("Third row") << thirdCommand[0] << third;
1131}
1132
1133void TestDownload::testProcessExecutedWithParams()
1134{
1135 QFETCH(QString, command);
1136 QFETCH(QVariantMap, metadata);
1137
1138 _processFactory->record();
1139 _reqFactory->record();
1140 Download* download = new Download(_id, _path, _url, metadata, _headers, _networkInfo, _reqFactory, _processFactory);
1141
1142 download->start(); // change state
1143 download->startDownload();
1144
1145 // we need to set the data before we pause!!!
1146 QList<MethodData> calledMethods = _reqFactory->calledMethods();
1147 QCOMPARE(1, calledMethods.count());
1148 FakeNetworkReply* reply = (FakeNetworkReply*) calledMethods[0].params().outParams()[0];
1149
1150 // makes the process to be executed
1151 reply->emitFinished();
1152
1153 calledMethods = _processFactory->calledMethods();
1154 QCOMPARE(1, calledMethods.count());
1155 FakeProcess* process = (FakeProcess*) calledMethods[0].params().outParams()[0];
1156
1157 calledMethods = process->calledMethods();
1158 QString processCommand = ((StringWrapper*)calledMethods[0].params().inParams()[0])->value();
1159 QStringList processArgs = ((StringListWrapper*)calledMethods[0].params().inParams()[1])->value();
1160 QCOMPARE(processCommand, command);
1161 QVERIFY(0 != processArgs.count());
1162}
1163
1164void TestDownload::testProcessExecutedWithParamsFile_data()
1165{
1166 QTest::addColumn<QString>("command");
1167 QTest::addColumn<QVariantMap>("metadata");
1168 QVariantMap first, second, third;
1169 QStringList firstCommand, secondCommand, thirdCommand;
1170
1171 firstCommand << "touch" << "$file";
1172 first["post-download-command"] = firstCommand;
1173
1174 QTest::newRow("First row") << firstCommand[0] << first;
1175
1176 secondCommand << "sudo" << "apt-get" << "install" << "$file";
1177 second["post-download-command"] = secondCommand;
1178
1179 QTest::newRow("Second row") << secondCommand[0] << second;
1180
1181 thirdCommand << "grep" << "$file" << "-Rn";
1182 third["post-download-command"] = thirdCommand;
1183
1184 QTest::newRow("Third row") << thirdCommand[0] << third;
1185}
1186
1187void TestDownload::testProcessExecutedWithParamsFile()
1188{
1189 QFETCH(QString, command);
1190 QFETCH(QVariantMap, metadata);
1191
1192 _processFactory->record();
1193 _reqFactory->record();
1194 Download* download = new Download(_id, _path, _url, metadata, _headers, _networkInfo, _reqFactory, _processFactory);
1195
1196 download->start(); // change state
1197 download->startDownload();
1198
1199 // we need to set the data before we pause!!!
1200 QList<MethodData> calledMethods = _reqFactory->calledMethods();
1201 QCOMPARE(1, calledMethods.count());
1202 FakeNetworkReply* reply = (FakeNetworkReply*) calledMethods[0].params().outParams()[0];
1203
1204 // makes the process to be executed
1205 reply->emitFinished();
1206
1207 calledMethods = _processFactory->calledMethods();
1208 QCOMPARE(1, calledMethods.count());
1209 FakeProcess* process = (FakeProcess*) calledMethods[0].params().outParams()[0];
1210
1211 calledMethods = process->calledMethods();
1212 QString processCommand = ((StringWrapper*)calledMethods[0].params().inParams()[0])->value();
1213 QStringList processArgs = ((StringListWrapper*)calledMethods[0].params().inParams()[1])->value();
1214 QCOMPARE(processCommand, command);
1215 QVERIFY(processArgs.contains(download->filePath()));
1216}
10501217
=== modified file 'ubuntu-download-manager-tests/test_download.h'
--- ubuntu-download-manager-tests/test_download.h 2013-07-20 14:08:52 +0000
+++ ubuntu-download-manager-tests/test_download.h 2013-07-21 19:10:31 +0000
@@ -25,6 +25,7 @@
25#include <metatypes.h>25#include <metatypes.h>
26#include "fake_system_network_info.h"26#include "fake_system_network_info.h"
27#include "fake_request_factory.h"27#include "fake_request_factory.h"
28#include "fake_process_factory.h"
28#include "test_runner.h"29#include "test_runner.h"
2930
30class TestDownload: public QObject31class TestDownload: public QObject
@@ -59,6 +60,9 @@
59 void testSetGSMDownloadDiff_data();60 void testSetGSMDownloadDiff_data();
60 void testCanDownloadGSM_data();61 void testCanDownloadGSM_data();
61 void testCanDownloadNoGSM_data();62 void testCanDownloadNoGSM_data();
63 void testProcessExecutedNoParams_data();
64 void testProcessExecutedWithParams_data();
65 void testProcessExecutedWithParamsFile_data();
6266
63 // accessor methods67 // accessor methods
64 void testPath();68 void testPath();
@@ -97,6 +101,11 @@
97 void testSetRawHeadersResume();101 void testSetRawHeadersResume();
98 void testSetRawHeadersWithRangeResume();102 void testSetRawHeadersWithRangeResume();
99103
104 // process related tests
105 void testProcessExecutedNoParams();
106 void testProcessExecutedWithParams();
107 void testProcessExecutedWithParamsFile();
108
100private:109private:
101 bool removeDir(const QString& dirName);110 bool removeDir(const QString& dirName);
102111
@@ -110,6 +119,7 @@
110 QCryptographicHash::Algorithm _algo;119 QCryptographicHash::Algorithm _algo;
111 FakeSystemNetworkInfo* _networkInfo;120 FakeSystemNetworkInfo* _networkInfo;
112 FakeRequestFactory* _reqFactory;121 FakeRequestFactory* _reqFactory;
122 FakeProcessFactory* _processFactory;
113123
114};124};
115125
116126
=== modified file 'ubuntu-download-manager-tests/test_download_queue.cpp'
--- ubuntu-download-manager-tests/test_download_queue.cpp 2013-07-20 15:53:38 +0000
+++ ubuntu-download-manager-tests/test_download_queue.cpp 2013-07-21 19:10:31 +0000
@@ -29,9 +29,12 @@
29{29{
30 _networkInfo = new FakeSystemNetworkInfo();30 _networkInfo = new FakeSystemNetworkInfo();
31 _reqFactory = new FakeRequestFactory();31 _reqFactory = new FakeRequestFactory();
32 _first = new FakeDownload(QUuid::createUuid(), "first-path", QUrl(), QVariantMap(), QMap<QString, QString>(), _networkInfo, _reqFactory);32 _processFactory = new FakeProcessFactory();
33 _first = new FakeDownload(QUuid::createUuid(), "first-path", QUrl(), QVariantMap(), QMap<QString, QString>(), _networkInfo,
34 _reqFactory, _processFactory);
33 _firstAdaptor = new DownloadAdaptor(_first);35 _firstAdaptor = new DownloadAdaptor(_first);
34 _second = new FakeDownload(QUuid::createUuid(), "second-path", QUrl(), QVariantMap(), QMap<QString, QString>(), _networkInfo, _reqFactory);36 _second = new FakeDownload(QUuid::createUuid(), "second-path", QUrl(), QVariantMap(), QMap<QString, QString>(), _networkInfo,
37 _reqFactory, _processFactory);
35 _secondAdaptor = new DownloadAdaptor(_second);38 _secondAdaptor = new DownloadAdaptor(_second);
36 _q = new DownloadQueue(_networkInfo);39 _q = new DownloadQueue(_networkInfo);
37}40}
@@ -339,7 +342,6 @@
339 // cancel the download and expect it to be done342 // cancel the download and expect it to be done
340 _first->record();343 _first->record();
341 QSignalSpy changedSpy(_q, SIGNAL(currentChanged(QString)));344 QSignalSpy changedSpy(_q, SIGNAL(currentChanged(QString)));
342 QSignalSpy removedSpy(_q, SIGNAL(downloadRemoved(QString)));
343 _q->add(_first, _firstAdaptor);345 _q->add(_first, _firstAdaptor);
344346
345 QVERIFY(_q->currentDownload().isEmpty());347 QVERIFY(_q->currentDownload().isEmpty());
@@ -349,16 +351,12 @@
349 QVERIFY(_q->currentDownload().isEmpty());351 QVERIFY(_q->currentDownload().isEmpty());
350352
351 QCOMPARE(changedSpy.count(), 2);353 QCOMPARE(changedSpy.count(), 2);
352 QCOMPARE(removedSpy.count(), 1);
353354
354 QList<QVariant> arguments = changedSpy.takeFirst();355 QList<QVariant> arguments = changedSpy.takeFirst();
355 QCOMPARE(arguments.at(0).toString(), _first->path());356 QCOMPARE(arguments.at(0).toString(), _first->path());
356 arguments = changedSpy.takeFirst();357 arguments = changedSpy.takeFirst();
357 QVERIFY(arguments.at(0).toString().isEmpty());358 QVERIFY(arguments.at(0).toString().isEmpty());
358359
359 arguments = removedSpy.takeFirst();
360 QCOMPARE(arguments.at(0).toString(), _first->path());
361
362 QList<MethodData> calledMethods = _first->calledMethods();360 QList<MethodData> calledMethods = _first->calledMethods();
363 QCOMPARE(3, calledMethods.count());361 QCOMPARE(3, calledMethods.count());
364 QCOMPARE(QString("canDownload"), calledMethods[0].methodName());362 QCOMPARE(QString("canDownload"), calledMethods[0].methodName());
@@ -373,7 +371,6 @@
373 _second->record();371 _second->record();
374372
375 QSignalSpy changedSpy(_q, SIGNAL(currentChanged(QString)));373 QSignalSpy changedSpy(_q, SIGNAL(currentChanged(QString)));
376 QSignalSpy removedSpy(_q, SIGNAL(downloadRemoved(QString)));
377 _q->add(_first, _firstAdaptor);374 _q->add(_first, _firstAdaptor);
378 _q->add(_second, _firstAdaptor);375 _q->add(_second, _firstAdaptor);
379376
@@ -386,16 +383,12 @@
386 QCOMPARE(_q->currentDownload(), _second->path());383 QCOMPARE(_q->currentDownload(), _second->path());
387384
388 QCOMPARE(changedSpy.count(), 2);385 QCOMPARE(changedSpy.count(), 2);
389 QCOMPARE(removedSpy.count(), 1);
390386
391 QList<QVariant> arguments = changedSpy.takeFirst();387 QList<QVariant> arguments = changedSpy.takeFirst();
392 QCOMPARE(arguments.at(0).toString(), _first->path());388 QCOMPARE(arguments.at(0).toString(), _first->path());
393 arguments = changedSpy.takeFirst();389 arguments = changedSpy.takeFirst();
394 QCOMPARE(arguments.at(0).toString(), _second->path());390 QCOMPARE(arguments.at(0).toString(), _second->path());
395391
396 arguments = removedSpy.takeFirst();
397 QCOMPARE(arguments.at(0).toString(), _first->path());
398
399 QList<MethodData> calledMethods = _first->calledMethods();392 QList<MethodData> calledMethods = _first->calledMethods();
400 QCOMPARE(3, calledMethods.count());393 QCOMPARE(3, calledMethods.count());
401 QCOMPARE(QString("canDownload"), calledMethods[0].methodName());394 QCOMPARE(QString("canDownload"), calledMethods[0].methodName());
@@ -416,7 +409,6 @@
416 _second->record();409 _second->record();
417410
418 QSignalSpy changedSpy(_q, SIGNAL(currentChanged(QString)));411 QSignalSpy changedSpy(_q, SIGNAL(currentChanged(QString)));
419 QSignalSpy removedSpy(_q, SIGNAL(downloadRemoved(QString)));
420 _q->add(_first, _firstAdaptor);412 _q->add(_first, _firstAdaptor);
421 _q->add(_second, _firstAdaptor);413 _q->add(_second, _firstAdaptor);
422414
@@ -429,16 +421,12 @@
429 QCOMPARE(_q->currentDownload(), QString(""));421 QCOMPARE(_q->currentDownload(), QString(""));
430422
431 QCOMPARE(changedSpy.count(), 2);423 QCOMPARE(changedSpy.count(), 2);
432 QCOMPARE(removedSpy.count(), 1);
433424
434 QList<QVariant> arguments = changedSpy.takeFirst();425 QList<QVariant> arguments = changedSpy.takeFirst();
435 QCOMPARE(arguments.at(0).toString(), _first->path());426 QCOMPARE(arguments.at(0).toString(), _first->path());
436 arguments = changedSpy.takeFirst();427 arguments = changedSpy.takeFirst();
437 QCOMPARE(arguments.at(0).toString(), QString(""));428 QCOMPARE(arguments.at(0).toString(), QString(""));
438429
439 arguments = removedSpy.takeFirst();
440 QCOMPARE(arguments.at(0).toString(), _first->path());
441
442 QList<MethodData> calledMethods = _first->calledMethods();430 QList<MethodData> calledMethods = _first->calledMethods();
443 QCOMPARE(3, calledMethods.count());431 QCOMPARE(3, calledMethods.count());
444 QCOMPARE(QString("canDownload"), calledMethods[0].methodName());432 QCOMPARE(QString("canDownload"), calledMethods[0].methodName());
@@ -461,11 +449,6 @@
461449
462 _first->cancel();450 _first->cancel();
463 QVERIFY(_q->currentDownload().isEmpty());451 QVERIFY(_q->currentDownload().isEmpty());
464
465 QCOMPARE(removedSpy.count(), 1);
466
467 QList<QVariant> arguments = removedSpy.takeFirst();
468 QCOMPARE(arguments.at(0).toString(), _first->path());
469}452}
470453
471void TestDownloadQueue::testDownloads()454void TestDownloadQueue::testDownloads()
472455
=== modified file 'ubuntu-download-manager-tests/test_download_queue.h'
--- ubuntu-download-manager-tests/test_download_queue.h 2013-07-20 15:53:38 +0000
+++ ubuntu-download-manager-tests/test_download_queue.h 2013-07-21 19:10:31 +0000
@@ -25,6 +25,7 @@
25#include "test_runner.h"25#include "test_runner.h"
26#include "fake_download.h"26#include "fake_download.h"
27#include "fake_request_factory.h"27#include "fake_request_factory.h"
28#include "fake_process_factory.h"
28#include "fake_system_network_info.h"29#include "fake_system_network_info.h"
2930
30class TestDownloadQueue : public QObject31class TestDownloadQueue : public QObject
@@ -57,6 +58,7 @@
57private:58private:
58 FakeSystemNetworkInfo* _networkInfo;59 FakeSystemNetworkInfo* _networkInfo;
59 FakeRequestFactory* _reqFactory;60 FakeRequestFactory* _reqFactory;
61 FakeProcessFactory* _processFactory;
60 FakeDownload* _first;62 FakeDownload* _first;
61 DownloadAdaptor* _firstAdaptor;63 DownloadAdaptor* _firstAdaptor;
62 FakeDownload* _second;64 FakeDownload* _second;
6365
=== modified file 'ubuntu-download-manager-tests/ubuntu-download-manager-tests.pro'
--- ubuntu-download-manager-tests/ubuntu-download-manager-tests.pro 2013-07-18 20:37:08 +0000
+++ ubuntu-download-manager-tests/ubuntu-download-manager-tests.pro 2013-07-21 19:10:31 +0000
@@ -29,7 +29,9 @@
29 test_xdg_basedir.cpp \29 test_xdg_basedir.cpp \
30 fake_download_queue.cpp \30 fake_download_queue.cpp \
31 fake_uuid_factory.cpp \31 fake_uuid_factory.cpp \
32 fake_system_network_info.cpp32 fake_system_network_info.cpp \
33 fake_process.cpp \
34 fake_process_factory.cpp
3335
34HEADERS += \36HEADERS += \
35 fake.h \37 fake.h \
@@ -47,7 +49,9 @@
47 test_xdg_basedir.h \49 test_xdg_basedir.h \
48 fake_download_queue.h \50 fake_download_queue.h \
49 fake_uuid_factory.h \51 fake_uuid_factory.h \
50 fake_system_network_info.h52 fake_system_network_info.h \
53 fake_process.h \
54 fake_process_factory.h
5155
52LIBS += -L$$OUT_PWD/../libubuntudownloadmanager/ -lubuntudownloadmanager56LIBS += -L$$OUT_PWD/../libubuntudownloadmanager/ -lubuntudownloadmanager
5357

Subscribers

People subscribed via source and target branches