Merge lp:~mandel/ubuntu-download-manager/remove-network-reply-pimpl into lp:ubuntu-download-manager

Proposed by Manuel de la Peña
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 177
Merged at revision: 195
Proposed branch: lp:~mandel/ubuntu-download-manager/remove-network-reply-pimpl
Merge into: lp:ubuntu-download-manager
Diff against target: 392 lines (+57/-252)
5 files modified
libubuntudownloadmanager/system/network_reply.cpp (+52/-98)
libubuntudownloadmanager/system/network_reply.h (+5/-5)
ubuntu-download-manager-tests/system/test_network_reply.cpp (+0/-93)
ubuntu-download-manager-tests/system/test_network_reply.h (+0/-54)
ubuntu-download-manager-tests/ubuntu-download-manager-tests.pro (+0/-2)
To merge this branch: bzr merge lp:~mandel/ubuntu-download-manager/remove-network-reply-pimpl
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Manuel de la Peña (community) Approve
Diego Sarmentero (community) Approve
Review via email: mp+195121@code.launchpad.net

Commit message

Remove pimpl implementation from the NetworkReply object. Moved signals to use new way to connect.

Description of the change

Remove pimpl implementation from the NetworkReply object. Moved signals to use new way to connect.

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
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

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

Approving because it is just a Jenkins error.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Manuel de la Peña (mandel) wrote :

Looks like an issue with the armhf jenkins instance.

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

Remove the need of the tests because the signal connection checks are done at compile time thx to the new connection style.

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

I'm removing the problematic tests because the connection of the signals is now performed with the new connections style and that means that the check is done at compile time.

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
1=== modified file 'libubuntudownloadmanager/system/network_reply.cpp'
2--- libubuntudownloadmanager/system/network_reply.cpp 2013-10-29 13:42:44 +0000
3+++ libubuntudownloadmanager/system/network_reply.cpp 2013-12-02 11:34:50 +0000
4@@ -25,126 +25,80 @@
5
6 namespace System {
7
8-/*
9- * PRIVATE IMPLEMENTATION
10- */
11-
12-class NetworkReplyPrivate {
13- Q_DECLARE_PUBLIC(NetworkReply)
14-
15- public:
16- NetworkReplyPrivate(QNetworkReply* reply, NetworkReply* parent)
17- : _reply(reply),
18- q_ptr(parent) {
19- // connect to all the signals so that we foward them
20- Q_Q(NetworkReply);
21- if (_reply != NULL) {
22- q->connect(_reply, SIGNAL(downloadProgress(qint64, qint64)),
23- q, SIGNAL(downloadProgress(qint64, qint64)));
24- q->connect(_reply, SIGNAL(error(QNetworkReply::NetworkError)),
25- q, SIGNAL(error(QNetworkReply::NetworkError)));
26- q->connect(_reply, SIGNAL(finished()),
27- q, SIGNAL(finished()));
28- q->connect(_reply, SIGNAL(sslErrors(const QList<QSslError>&)),
29- q, SIGNAL(sslErrors(const QList<QSslError>&)));
30- }
31- }
32-
33- // public methods used by other parts of the code
34- QByteArray readAll() {
35- return _reply->readAll();
36- }
37-
38- void abort() {
39- _reply->abort();
40- }
41-
42- void setReadBufferSize(uint size) {
43- _reply->setReadBufferSize(size);
44- }
45-
46- void setAcceptedCertificates(const QList<QSslCertificate>& certs) {
47- _certs = certs;
48- // build possible errors
49- foreach(const QSslCertificate& certificate, _certs) {
50- QSslError error(QSslError::SelfSignedCertificate, certificate);
51- _sslErrors.append(error);
52- }
53- }
54-
55- bool canIgnoreSslErrors(const QList<QSslError>& errors) {
56- if (_sslErrors.count() > 0 && errors.count() > 0) {
57- foreach(QSslError error, errors) {
58- QSslError::SslError type = error.error();
59- if (type != QSslError::NoError &&
60- type != QSslError::SelfSignedCertificate) {
61- // we only support self signed certificates all errors
62- // will not be ignored
63- qDebug() << "SSL error type not ignored";
64- return false;
65- } else if (type == QSslError::SelfSignedCertificate) {
66- // just ignore those errors of the added errors
67- if (!_certs.contains(error.certificate())) {
68- qDebug() << "SSL certificate not ignored";
69- return false;
70- }
71- }
72- }
73-
74- if (_reply != NULL) {
75- _reply->ignoreSslErrors(_sslErrors);
76- }
77-
78- return true;
79- }
80- return false;
81- }
82-
83- private:
84- QList<QSslCertificate> _certs;
85- QList<QSslError> _sslErrors;
86- QNetworkReply* _reply;
87- NetworkReply* q_ptr;
88-};
89-
90-/*
91- * PUBLIC IMPLEMENTATION
92- */
93-
94-NetworkReply::NetworkReply(QNetworkReply* reply, QObject *parent)
95+NetworkReply::NetworkReply(QNetworkReply* reply, QObject* parent)
96 : QObject(parent),
97- d_ptr(new NetworkReplyPrivate(reply, this)) {
98+ _reply(reply) {
99+ // connect to all the signals so that we foward them
100+ if (_reply != NULL) {
101+ connect(_reply, &QNetworkReply::downloadProgress,
102+ this, &NetworkReply::downloadProgress);
103+ connect(_reply, &QNetworkReply::finished,
104+ this, &NetworkReply::finished);
105+ connect(_reply, &QNetworkReply::sslErrors,
106+ this, &NetworkReply::sslErrors);
107+ // becuase error is overloaded we need to help the compiler
108+ connect(_reply, static_cast<void(QNetworkReply::*)
109+ (QNetworkReply::NetworkError)>(&QNetworkReply::error),
110+ this, &NetworkReply::error);
111+ }
112 }
113
114+NetworkReply::~NetworkReply() {
115+ delete _reply;
116+}
117
118 QByteArray
119 NetworkReply::readAll() {
120- Q_D(NetworkReply);
121- return d->readAll();
122+ return _reply->readAll();
123 }
124
125 void
126 NetworkReply::abort() {
127- Q_D(NetworkReply);
128- d->abort();
129+ _reply->abort();
130 }
131
132 void
133 NetworkReply::setReadBufferSize(uint size) {
134- Q_D(NetworkReply);
135- d->setReadBufferSize(size);
136+ _reply->setReadBufferSize(size);
137 }
138
139 void
140 NetworkReply::setAcceptedCertificates(const QList<QSslCertificate>& certs) {
141- Q_D(NetworkReply);
142- d->setAcceptedCertificates(certs);
143+ _certs = certs;
144+ // build possible errors
145+ foreach(const QSslCertificate& certificate, _certs) {
146+ QSslError error(QSslError::SelfSignedCertificate, certificate);
147+ _sslErrors.append(error);
148+ }
149 }
150
151 bool
152 NetworkReply::canIgnoreSslErrors(const QList<QSslError>& errors) {
153- Q_D(NetworkReply);
154- return d->canIgnoreSslErrors(errors);
155+ if (_sslErrors.count() > 0 && errors.count() > 0) {
156+ foreach(QSslError error, errors) {
157+ QSslError::SslError type = error.error();
158+ if (type != QSslError::NoError &&
159+ type != QSslError::SelfSignedCertificate) {
160+ // we only support self signed certificates all errors
161+ // will not be ignored
162+ qDebug() << "SSL error type not ignored";
163+ return false;
164+ } else if (type == QSslError::SelfSignedCertificate) {
165+ // just ignore those errors of the added errors
166+ if (!_certs.contains(error.certificate())) {
167+ qDebug() << "SSL certificate not ignored";
168+ return false;
169+ }
170+ }
171+ }
172+
173+ if (_reply != NULL) {
174+ _reply->ignoreSslErrors(_sslErrors);
175+ }
176+
177+ return true;
178+ }
179+ return false;
180 }
181
182 } // System
183
184=== modified file 'libubuntudownloadmanager/system/network_reply.h'
185--- libubuntudownloadmanager/system/network_reply.h 2013-10-29 13:42:44 +0000
186+++ libubuntudownloadmanager/system/network_reply.h 2013-12-02 11:34:50 +0000
187@@ -30,13 +30,12 @@
188
189 namespace System {
190
191-class NetworkReplyPrivate;
192 class NetworkReply : public QObject {
193 Q_OBJECT
194- Q_DECLARE_PRIVATE(NetworkReply)
195
196 public:
197- explicit NetworkReply(QNetworkReply* reply, QObject *parent = 0);
198+ NetworkReply(QNetworkReply* reply, QObject *parent = 0);
199+ virtual ~NetworkReply();
200
201 virtual QByteArray readAll();
202 virtual void abort();
203@@ -52,8 +51,9 @@
204 void sslErrors(const QList<QSslError>& errors);
205
206 private:
207- // use pimpl so that we can mantains ABI compatibility
208- NetworkReplyPrivate* d_ptr;
209+ QList<QSslCertificate> _certs;
210+ QList<QSslError> _sslErrors;
211+ QNetworkReply* _reply;
212 };
213
214 } // System
215
216=== removed directory 'ubuntu-download-manager-tests/system'
217=== removed file 'ubuntu-download-manager-tests/system/test_network_reply.cpp'
218--- ubuntu-download-manager-tests/system/test_network_reply.cpp 2013-10-30 11:04:37 +0000
219+++ ubuntu-download-manager-tests/system/test_network_reply.cpp 1970-01-01 00:00:00 +0000
220@@ -1,93 +0,0 @@
221-/*
222- * Copyright 2013 Canonical Ltd.
223- *
224- * This library is free software; you can redistribute it and/or
225- * modify it under the terms of version 3 of the GNU Lesser General Public
226- * License as published by the Free Software Foundation.
227- *
228- * This program is distributed in the hope that it will be useful,
229- * but WITHOUT ANY WARRANTY; without even the implied warranty of
230- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
231- * General Public License for more details.
232- *
233- * You should have received a copy of the GNU Lesser General Public
234- * License along with this library; if not, write to the
235- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
236- * Boston, MA 02110-1301, USA.
237- */
238-
239-#include <QSslError>
240-#include <QSignalSpy>
241-#include "fakes/fake_qnetwork_reply.h"
242-#include "test_network_reply.h"
243-
244-TestNetworkReply::TestNetworkReply(QObject *parent)
245- : BaseTestCase("TestNetworkReply", parent) {
246-}
247-
248-void
249-TestNetworkReply::init() {
250- BaseTestCase::init();
251- _qReply = new FakeQNetworkReply();
252- _reply = new NetworkReply(_qReply);
253-}
254-
255-void
256-TestNetworkReply::cleanup() {
257- BaseTestCase::cleanup();
258-
259- if (_reply != NULL)
260- _reply->deleteLater();
261-
262- if (_qReply != NULL)
263- _qReply->deleteLater();
264-}
265-
266-void
267-TestNetworkReply::testDownloadProgressForwarded_data() {
268- QTest::addColumn<uint>("received");
269- QTest::addColumn<uint>("total");
270-
271- QTest::newRow("First row") << 67u << 200u;
272- QTest::newRow("Second row") << 45u << 12000u;
273- QTest::newRow("Third row") << 2u << 2345u;
274- QTest::newRow("Last row") << 3434u << 2323u;
275-}
276-
277-void
278-TestNetworkReply::testDownloadProgressForwarded() {
279- QFETCH(uint, received);
280- QFETCH(uint, total);
281-
282- QSignalSpy spy(_reply, SIGNAL(downloadProgress(qint64, qint64)));
283- emit _qReply->downloadProgress(received, total);
284-
285- QCOMPARE(spy.count(), 1);
286- QList<QVariant> arguments = spy.takeFirst();
287- QCOMPARE(arguments.at(0).toUInt(), received);
288- QCOMPARE(arguments.at(1).toUInt(), total);
289-}
290-
291-void
292-TestNetworkReply::testErrorForwarded() {
293- QSignalSpy spy(_reply, SIGNAL(error(QNetworkReply::NetworkError)));
294- emit _qReply->error(QNetworkReply::NoError);
295-
296- QCOMPARE(spy.count(), 1);
297-}
298-
299-void
300-TestNetworkReply::testFinishedForwarded() {
301- QSignalSpy spy(_reply, SIGNAL(finished()));
302- emit _qReply->finished();
303- QCOMPARE(spy.count(), 1);
304-}
305-
306-void
307-TestNetworkReply::testSslErrorsForwarded() {
308- QList<QSslError> errors;
309- QSignalSpy spy(_reply, SIGNAL(sslErrors(const QList<QSslError>&)));
310- emit _qReply->sslErrors(errors);
311-
312- QCOMPARE(spy.count(), 1);
313-}
314
315=== removed file 'ubuntu-download-manager-tests/system/test_network_reply.h'
316--- ubuntu-download-manager-tests/system/test_network_reply.h 2013-10-30 11:04:37 +0000
317+++ ubuntu-download-manager-tests/system/test_network_reply.h 1970-01-01 00:00:00 +0000
318@@ -1,54 +0,0 @@
319-/*
320- * Copyright 2013 Canonical Ltd.
321- *
322- * This library is free software; you can redistribute it and/or
323- * modify it under the terms of version 3 of the GNU Lesser General Public
324- * License as published by the Free Software Foundation.
325- *
326- * This program is distributed in the hope that it will be useful,
327- * but WITHOUT ANY WARRANTY; without even the implied warranty of
328- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
329- * General Public License for more details.
330- *
331- * You should have received a copy of the GNU Lesser General Public
332- * License along with this library; if not, write to the
333- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
334- * Boston, MA 02110-1301, USA.
335- */
336-
337-#ifndef TEST_NETWORK_REPLY_H
338-#define TEST_NETWORK_REPLY_H
339-
340-#include <QObject>
341-#include <system/network_reply.h>
342-#include "base_testcase.h"
343-#include "test_runner.h"
344-
345-using namespace Ubuntu::DownloadManager::System;
346-
347-class TestNetworkReply : public BaseTestCase {
348- Q_OBJECT
349-
350- public:
351- explicit TestNetworkReply(QObject *parent = 0);
352-
353- private slots: // NOLINT(whitespace/indent)
354-
355- void init() override;
356- void cleanup() override;
357-
358- // data functions used in the tests
359- void testDownloadProgressForwarded_data();
360-
361- void testDownloadProgressForwarded();
362- void testErrorForwarded();
363- void testFinishedForwarded();
364- void testSslErrorsForwarded();
365- private:
366- QNetworkReply* _qReply;
367- NetworkReply* _reply;
368-};
369-
370-DECLARE_TEST(TestNetworkReply)
371-
372-#endif // TEST_NETWORK_REPLY_H
373
374=== modified file 'ubuntu-download-manager-tests/ubuntu-download-manager-tests.pro'
375--- ubuntu-download-manager-tests/ubuntu-download-manager-tests.pro 2013-11-11 16:30:03 +0000
376+++ ubuntu-download-manager-tests/ubuntu-download-manager-tests.pro 2013-12-02 11:34:50 +0000
377@@ -38,7 +38,6 @@
378 fakes/fake_download_factory.cpp \
379 fakes/fake_file_manager.cpp \
380 fakes/fake_apparmor.cpp \
381- system/test_network_reply.cpp \
382 main.cpp \
383 base_testcase.cpp \
384 downloads/state_machines/test_network_error_transition.cpp \
385@@ -76,7 +75,6 @@
386 fakes/fake_download_factory.h \
387 fakes/fake_file_manager.h \
388 fakes/fake_apparmor.h \
389- system/test_network_reply.h \
390 test_runner.h \
391 base_testcase.h \
392 downloads/state_machines/test_network_error_transition.h \

Subscribers

People subscribed via source and target branches