qnoncontiguousbytedevice.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qnoncontiguousbytedevice.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtCore module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "qnoncontiguousbytedevice_p.h"-
35#include <qbuffer.h>-
36#include <qdebug.h>-
37#include <qfile.h>-
38-
39QT_BEGIN_NAMESPACE-
40-
41/*!-
42 \class QNonContiguousByteDevice-
43 \inmodule QtCore-
44 \brief A QNonContiguousByteDevice is a representation of a-
45 file, array or buffer that allows access with a read pointer.-
46 \since 4.6-
47-
48 The goal of this class is to have a data representation that-
49 allows us to avoid doing a memcpy as we have to do with QIODevice.-
50-
51 \sa QNonContiguousByteDeviceFactory-
52-
53 \internal-
54*/-
55/*!-
56 \fn virtual const char* QNonContiguousByteDevice::readPointer(qint64 maximumLength, qint64 &len)-
57-
58 Return a byte pointer for at most \a maximumLength bytes of that device.-
59 if \a maximumLength is -1, the caller does not care about the length and-
60 the device may return what it desires to.-
61 The actual number of bytes the pointer is valid for is returned in-
62 the \a len variable.-
63 \a len will be -1 if EOF or an error occurs.-
64 If it was really EOF can then afterwards be checked with atEnd()-
65 Returns 0 if it is not possible to read at that position.-
66-
67 \sa atEnd()-
68-
69 \internal-
70*/-
71/*!-
72 \fn virtual bool QNonContiguousByteDevice::advanceReadPointer(qint64 amount)-
73-
74 will advance the internal read pointer by \a amount bytes.-
75 The old readPointer is invalid after this call.-
76-
77 \sa readPointer()-
78-
79 \internal-
80*/-
81/*!-
82 \fn virtual bool QNonContiguousByteDevice::atEnd()-
83-
84 Returns \c true if everything has been read and the read-
85 pointer cannot be advanced anymore.-
86-
87 \sa readPointer(), advanceReadPointer(), reset()-
88-
89 \internal-
90*/-
91/*!-
92 \fn virtual bool QNonContiguousByteDevice::reset()-
93-
94 Moves the internal read pointer back to the beginning.-
95 Returns \c false if this was not possible.-
96-
97 \sa atEnd()-
98-
99 \internal-
100*/-
101/*!-
102 \fn virtual qint64 QNonContiguousByteDevice::size()-
103-
104 Returns the size of the complete device or -1 if unknown.-
105 May also return less/more than what can be actually read with readPointer()-
106-
107 \internal-
108*/-
109/*!-
110 \fn void QNonContiguousByteDevice::readyRead()-
111-
112 Emitted when there is data available-
113-
114 \internal-
115*/-
116/*!-
117 \fn void QNonContiguousByteDevice::readProgress(qint64 current, qint64 total)-
118-
119 Emitted when data has been "read" by advancing the read pointer-
120-
121 \internal-
122*/-
123-
124QNonContiguousByteDevice::QNonContiguousByteDevice() : QObject((QObject*)0)-
125{-
126}
executed 494 times by 4 tests: end of block
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
494
127-
128QNonContiguousByteDevice::~QNonContiguousByteDevice()-
129{-
130}-
131-
132// FIXME we should scrap this whole implementation and instead change the ByteArrayImpl to be able to cope with sub-arrays?-
133QNonContiguousByteDeviceBufferImpl::QNonContiguousByteDeviceBufferImpl(QBuffer *b) : QNonContiguousByteDevice()-
134{-
135 buffer = b;-
136 byteArray = QByteArray::fromRawData(buffer->buffer().constData() + buffer->pos(), buffer->size() - buffer->pos());-
137 arrayImpl = new QNonContiguousByteDeviceByteArrayImpl(&byteArray);-
138 arrayImpl->setParent(this);-
139 connect(arrayImpl, SIGNAL(readyRead()), SIGNAL(readyRead()));-
140 connect(arrayImpl, SIGNAL(readProgress(qint64,qint64)), SIGNAL(readProgress(qint64,qint64)));-
141}
executed 79 times by 3 tests: end of block
Executed by:
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
79
142-
143QNonContiguousByteDeviceBufferImpl::~QNonContiguousByteDeviceBufferImpl()-
144{-
145}-
146-
147const char* QNonContiguousByteDeviceBufferImpl::readPointer(qint64 maximumLength, qint64 &len)-
148{-
149 return arrayImpl->readPointer(maximumLength, len);
executed 1306 times by 3 tests: return arrayImpl->readPointer(maximumLength, len);
Executed by:
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
1306
150}-
151-
152bool QNonContiguousByteDeviceBufferImpl::advanceReadPointer(qint64 amount)-
153{-
154 return arrayImpl->advanceReadPointer(amount);
executed 1273 times by 2 tests: return arrayImpl->advanceReadPointer(amount);
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
1273
155}-
156-
157bool QNonContiguousByteDeviceBufferImpl::atEnd()-
158{-
159 return arrayImpl->atEnd();
executed 1051 times by 3 tests: return arrayImpl->atEnd();
Executed by:
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
1051
160}-
161-
162bool QNonContiguousByteDeviceBufferImpl::reset()-
163{-
164 return arrayImpl->reset();
executed 3 times by 1 test: return arrayImpl->reset();
Executed by:
  • tst_QNetworkReply
3
165}-
166-
167qint64 QNonContiguousByteDeviceBufferImpl::size()-
168{-
169 return arrayImpl->size();
executed 1100 times by 3 tests: return arrayImpl->size();
Executed by:
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
1100
170}-
171-
172QNonContiguousByteDeviceByteArrayImpl::QNonContiguousByteDeviceByteArrayImpl(QByteArray *ba) : QNonContiguousByteDevice(), currentPosition(0)-
173{-
174 byteArray = ba;-
175}
executed 84 times by 4 tests: end of block
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
84
176-
177QNonContiguousByteDeviceByteArrayImpl::~QNonContiguousByteDeviceByteArrayImpl()-
178{-
179}-
180-
181const char* QNonContiguousByteDeviceByteArrayImpl::readPointer(qint64 maximumLength, qint64 &len)-
182{-
183 if (atEnd()) {
atEnd()Description
TRUEevaluated 32 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
FALSEevaluated 1278 times by 4 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
32-1278
184 len = -1;-
185 return 0;
executed 32 times by 2 tests: return 0;
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
32
186 }-
187-
188 if (maximumLength != -1)
maximumLength != -1Description
TRUEevaluated 1272 times by 4 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_QNetworkReply
6-1272
189 len = qMin(maximumLength, size() - currentPosition);
executed 1272 times by 4 tests: len = qMin(maximumLength, size() - currentPosition);
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
1272
190 else-
191 len = size() - currentPosition;
executed 6 times by 1 test: len = size() - currentPosition;
Executed by:
  • tst_QNetworkReply
6
192-
193 return byteArray->constData() + currentPosition;
executed 1278 times by 4 tests: return byteArray->constData() + currentPosition;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
1278
194}-
195-
196bool QNonContiguousByteDeviceByteArrayImpl::advanceReadPointer(qint64 amount)-
197{-
198 currentPosition += amount;-
199 emit readProgress(currentPosition, size());-
200 return true;
executed 1277 times by 3 tests: return true;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
1277
201}-
202-
203bool QNonContiguousByteDeviceByteArrayImpl::atEnd()-
204{-
205 return currentPosition >= size();
executed 2361 times by 4 tests: return currentPosition >= size();
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
2361
206}-
207-
208bool QNonContiguousByteDeviceByteArrayImpl::reset()-
209{-
210 currentPosition = 0;-
211 return true;
executed 3 times by 1 test: return true;
Executed by:
  • tst_QNetworkReply
3
212}-
213-
214qint64 QNonContiguousByteDeviceByteArrayImpl::size()-
215{-
216 return byteArray->size();
executed 6028 times by 4 tests: return byteArray->size();
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
6028
217}-
218-
219qint64 QNonContiguousByteDeviceByteArrayImpl::pos()-
220{-
221 return currentPosition;
executed 4 times by 1 test: return currentPosition;
Executed by:
  • tst_QHttpNetworkConnection
4
222}-
223-
224QNonContiguousByteDeviceRingBufferImpl::QNonContiguousByteDeviceRingBufferImpl(QSharedPointer<QRingBuffer> rb)-
225 : QNonContiguousByteDevice(), currentPosition(0)-
226{-
227 ringBuffer = rb;-
228}
executed 99 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
99
229-
230QNonContiguousByteDeviceRingBufferImpl::~QNonContiguousByteDeviceRingBufferImpl()-
231{-
232}-
233-
234const char* QNonContiguousByteDeviceRingBufferImpl::readPointer(qint64 maximumLength, qint64 &len)-
235{-
236 if (atEnd()) {
atEnd()Description
TRUEnever evaluated
FALSEevaluated 892 times by 1 test
Evaluated by:
  • tst_QNetworkReply
0-892
237 len = -1;-
238 return 0;
never executed: return 0;
0
239 }-
240-
241 const char *returnValue = ringBuffer->readPointerAtPosition(currentPosition, len);-
242-
243 if (maximumLength != -1)
maximumLength != -1Description
TRUEevaluated 892 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEnever evaluated
0-892
244 len = qMin(len, maximumLength);
executed 892 times by 1 test: len = qMin(len, maximumLength);
Executed by:
  • tst_QNetworkReply
892
245-
246 return returnValue;
executed 892 times by 1 test: return returnValue;
Executed by:
  • tst_QNetworkReply
892
247}-
248-
249bool QNonContiguousByteDeviceRingBufferImpl::advanceReadPointer(qint64 amount)-
250{-
251 currentPosition += amount;-
252 emit readProgress(currentPosition, size());-
253 return true;
executed 892 times by 1 test: return true;
Executed by:
  • tst_QNetworkReply
892
254}-
255-
256bool QNonContiguousByteDeviceRingBufferImpl::atEnd()-
257{-
258 return currentPosition >= size();
executed 1126 times by 1 test: return currentPosition >= size();
Executed by:
  • tst_QNetworkReply
1126
259}-
260-
261qint64 QNonContiguousByteDeviceRingBufferImpl::pos()-
262{-
263 return currentPosition;
executed 716 times by 1 test: return currentPosition;
Executed by:
  • tst_QNetworkReply
716
264}-
265-
266bool QNonContiguousByteDeviceRingBufferImpl::reset()-
267{-
268 currentPosition = 0;-
269 return true;
executed 117 times by 1 test: return true;
Executed by:
  • tst_QNetworkReply
117
270}-
271-
272qint64 QNonContiguousByteDeviceRingBufferImpl::size()-
273{-
274 return ringBuffer->size();
executed 2334 times by 1 test: return ringBuffer->size();
Executed by:
  • tst_QNetworkReply
2334
275}-
276-
277QNonContiguousByteDeviceIoDeviceImpl::QNonContiguousByteDeviceIoDeviceImpl(QIODevice *d)-
278 : QNonContiguousByteDevice(),-
279 currentReadBuffer(0), currentReadBufferSize(16*1024),-
280 currentReadBufferAmount(0), currentReadBufferPosition(0), totalAdvancements(0),-
281 eof(false)-
282{-
283 device = d;-
284 initialPosition = d->pos();-
285 connect(device, SIGNAL(readyRead()), this, SIGNAL(readyRead()), Qt::QueuedConnection);-
286 connect(device, SIGNAL(readChannelFinished()), this, SIGNAL(readyRead()), Qt::QueuedConnection);-
287}
executed 77 times by 2 tests: end of block
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
77
288-
289QNonContiguousByteDeviceIoDeviceImpl::~QNonContiguousByteDeviceIoDeviceImpl()-
290{-
291 delete currentReadBuffer;-
292}
executed 77 times by 2 tests: end of block
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
77
293-
294const char* QNonContiguousByteDeviceIoDeviceImpl::readPointer(qint64 maximumLength, qint64 &len)-
295{-
296 if (eof == true) {
eof == trueDescription
TRUEnever evaluated
FALSEevaluated 2250 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
0-2250
297 len = -1;-
298 return 0;
never executed: return 0;
0
299 }-
300-
301 if (currentReadBuffer == 0)
currentReadBuffer == 0Description
TRUEevaluated 77 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
FALSEevaluated 2173 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
77-2173
302 currentReadBuffer = new QByteArray(currentReadBufferSize, '\0'); // lazy alloc
executed 77 times by 2 tests: currentReadBuffer = new QByteArray(currentReadBufferSize, '\0');
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
77
303-
304 if (maximumLength == -1)
maximumLength == -1Description
TRUEevaluated 698 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 1552 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
698-1552
305 maximumLength = currentReadBufferSize;
executed 698 times by 1 test: maximumLength = currentReadBufferSize;
Executed by:
  • tst_QNetworkReply
698
306-
307 if (currentReadBufferAmount - currentReadBufferPosition > 0) {
currentReadBuf...erPosition > 0Description
TRUEnever evaluated
FALSEevaluated 2250 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
0-2250
308 len = currentReadBufferAmount - currentReadBufferPosition;-
309 return currentReadBuffer->data() + currentReadBufferPosition;
never executed: return currentReadBuffer->data() + currentReadBufferPosition;
0
310 }-
311-
312 qint64 haveRead = device->read(currentReadBuffer->data(), qMin(maximumLength, currentReadBufferSize));-
313-
314 if ((haveRead == -1) || (haveRead == 0 && device->atEnd() && !device->isSequential())) {
(haveRead == -1)Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 2222 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
haveRead == 0Description
TRUEevaluated 100 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
FALSEevaluated 2122 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
device->atEnd()Description
TRUEevaluated 96 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QNetworkReply
!device->isSequential()Description
TRUEevaluated 11 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
FALSEevaluated 85 times by 1 test
Evaluated by:
  • tst_QNetworkReply
4-2222
315 eof = true;-
316 len = -1;-
317 // size was unknown before, emit a readProgress with the final size-
318 if (size() == -1)
size() == -1Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 11 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
11-28
319 emit readProgress(totalAdvancements, totalAdvancements);
executed 28 times by 1 test: readProgress(totalAdvancements, totalAdvancements);
Executed by:
  • tst_QNetworkReply
28
320 return 0;
executed 39 times by 2 tests: return 0;
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
39
321 }-
322-
323 currentReadBufferAmount = haveRead;-
324 currentReadBufferPosition = 0;-
325-
326 len = haveRead;-
327 return currentReadBuffer->data();
executed 2211 times by 2 tests: return currentReadBuffer->data();
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
2211
328}-
329-
330bool QNonContiguousByteDeviceIoDeviceImpl::advanceReadPointer(qint64 amount)-
331{-
332 totalAdvancements += amount;-
333-
334 // normal advancement-
335 currentReadBufferPosition += amount;-
336-
337 if (size() == -1)
size() == -1Description
TRUEevaluated 577 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 1545 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
577-1545
338 emit readProgress(totalAdvancements, totalAdvancements);
executed 577 times by 1 test: readProgress(totalAdvancements, totalAdvancements);
Executed by:
  • tst_QNetworkReply
577
339 else-
340 emit readProgress(totalAdvancements, size());
executed 1545 times by 2 tests: readProgress(totalAdvancements, size());
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
1545
341-
342 // advancing over that what has actually been read before-
343 if (currentReadBufferPosition > currentReadBufferAmount) {
currentReadBuf...adBufferAmountDescription
TRUEnever evaluated
FALSEevaluated 2122 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
0-2122
344 qint64 i = currentReadBufferPosition - currentReadBufferAmount;-
345 while (i > 0) {
i > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
346 if (device->getChar(0) == false) {
device->getChar(0) == falseDescription
TRUEnever evaluated
FALSEnever evaluated
0
347 emit readProgress(totalAdvancements - i, size());-
348 return false; // ### FIXME handle eof
never executed: return false;
0
349 }-
350 i--;-
351 }
never executed: end of block
0
352-
353 currentReadBufferPosition = 0;-
354 currentReadBufferAmount = 0;-
355 }
never executed: end of block
0
356-
357-
358 return true;
executed 2122 times by 2 tests: return true;
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
2122
359}-
360-
361bool QNonContiguousByteDeviceIoDeviceImpl::atEnd()-
362{-
363 return eof == true;
executed 1580 times by 2 tests: return eof == true;
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
1580
364}-
365-
366bool QNonContiguousByteDeviceIoDeviceImpl::reset()-
367{-
368 bool reset = (initialPosition == 0) ? device->reset() : device->seek(initialPosition);
(initialPosition == 0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_QNetworkReply
1-6
369 if (reset) {
resetDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkReply
1-6
370 eof = false; // assume eof is false, it will be true after a read has been attempted-
371 totalAdvancements = 0; //reset the progress counter-
372 if (currentReadBuffer) {
currentReadBufferDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QNetworkReply
2-4
373 delete currentReadBuffer;-
374 currentReadBuffer = 0;-
375 }
executed 2 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
2
376 currentReadBufferAmount = 0;-
377 currentReadBufferPosition = 0;-
378 return true;
executed 6 times by 1 test: return true;
Executed by:
  • tst_QNetworkReply
6
379 }-
380-
381 return false;
executed 1 time by 1 test: return false;
Executed by:
  • tst_QNetworkReply
1
382}-
383-
384qint64 QNonContiguousByteDeviceIoDeviceImpl::size()-
385{-
386 // note that this is different from the size() implementation of QIODevice!-
387-
388 if (device->isSequential())
device->isSequential()Description
TRUEevaluated 607 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 4707 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
607-4707
389 return -1;
executed 607 times by 1 test: return -1;
Executed by:
  • tst_QNetworkReply
607
390-
391 return device->size() - initialPosition;
executed 4707 times by 2 tests: return device->size() - initialPosition;
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
4707
392}-
393-
394qint64 QNonContiguousByteDeviceIoDeviceImpl::pos()-
395{-
396 if (device->isSequential())
device->isSequential()Description
TRUEnever evaluated
FALSEnever evaluated
0
397 return -1;
never executed: return -1;
0
398-
399 return device->pos();
never executed: return device->pos();
0
400}-
401-
402QByteDeviceWrappingIoDevice::QByteDeviceWrappingIoDevice(QNonContiguousByteDevice *bd) : QIODevice((QObject*)0)-
403{-
404 byteDevice = bd;-
405 connect(bd, SIGNAL(readyRead()), SIGNAL(readyRead()));-
406-
407 open(ReadOnly);-
408}
executed 13 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
13
409-
410QByteDeviceWrappingIoDevice::~QByteDeviceWrappingIoDevice()-
411{-
412-
413}-
414-
415bool QByteDeviceWrappingIoDevice::isSequential() const-
416{-
417 return (byteDevice->size() == -1);
executed 55 times by 1 test: return (byteDevice->size() == -1);
Executed by:
  • tst_QNetworkReply
55
418}-
419-
420bool QByteDeviceWrappingIoDevice::atEnd() const-
421{-
422 return byteDevice->atEnd();
never executed: return byteDevice->atEnd();
0
423}-
424-
425bool QByteDeviceWrappingIoDevice::reset()-
426{-
427 return byteDevice->reset();
never executed: return byteDevice->reset();
0
428}-
429-
430qint64 QByteDeviceWrappingIoDevice::size() const-
431{-
432 if (isSequential())
isSequential()Description
TRUEnever evaluated
FALSEevaluated 22 times by 1 test
Evaluated by:
  • tst_QNetworkReply
0-22
433 return 0;
never executed: return 0;
0
434-
435 return byteDevice->size();
executed 22 times by 1 test: return byteDevice->size();
Executed by:
  • tst_QNetworkReply
22
436}-
437-
438-
439qint64 QByteDeviceWrappingIoDevice::readData( char * data, qint64 maxSize)-
440{-
441 qint64 len;-
442 const char *readPointer = byteDevice->readPointer(maxSize, len);-
443 if (len == -1)
len == -1Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 147 times by 1 test
Evaluated by:
  • tst_QNetworkReply
11-147
444 return -1;
executed 11 times by 1 test: return -1;
Executed by:
  • tst_QNetworkReply
11
445-
446 memcpy(data, readPointer, len);-
447 byteDevice->advanceReadPointer(len);-
448 return len;
executed 147 times by 1 test: return len;
Executed by:
  • tst_QNetworkReply
147
449}-
450-
451qint64 QByteDeviceWrappingIoDevice::writeData( const char* data, qint64 maxSize)-
452{-
453 Q_UNUSED(data);-
454 Q_UNUSED(maxSize);-
455 return -1;
never executed: return -1;
0
456}-
457-
458/*!-
459 \class QNonContiguousByteDeviceFactory-
460 \inmodule QtCore-
461 \since 4.6-
462-
463 Creates a QNonContiguousByteDevice out of a QIODevice,-
464 QByteArray etc.-
465-
466 \sa QNonContiguousByteDevice-
467-
468 \internal-
469*/-
470-
471/*!-
472 \fn static QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QIODevice *device)-
473-
474 Create a QNonContiguousByteDevice out of a QIODevice.-
475 For QFile, QBuffer and all other QIoDevice, sequential or not.-
476-
477 \internal-
478*/-
479QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QIODevice *device)-
480{-
481 // shortcut if it is a QBuffer-
482 if (QBuffer* buffer = qobject_cast<QBuffer*>(device)) {
QBuffer* buffe...ffer*>(device)Description
TRUEnever evaluated
FALSEnever evaluated
0
483 return new QNonContiguousByteDeviceBufferImpl(buffer);
never executed: return new QNonContiguousByteDeviceBufferImpl(buffer);
0
484 }-
485-
486 // ### FIXME special case if device is a QFile that supports map()-
487 // then we can actually deal with the file without using read/peek-
488-
489 // generic QIODevice-
490 return new QNonContiguousByteDeviceIoDeviceImpl(device); // FIXME
never executed: return new QNonContiguousByteDeviceIoDeviceImpl(device);
0
491}-
492-
493/*!-
494 Create a QNonContiguousByteDevice out of a QIODevice, return it in a QSharedPointer.-
495 For QFile, QBuffer and all other QIODevice, sequential or not.-
496-
497 \internal-
498*/-
499QSharedPointer<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(QIODevice *device)-
500{-
501 // shortcut if it is a QBuffer-
502 if (QBuffer *buffer = qobject_cast<QBuffer*>(device))
QBuffer *buffe...ffer*>(device)Description
TRUEevaluated 79 times by 3 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
FALSEevaluated 77 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
77-79
503 return QSharedPointer<QNonContiguousByteDeviceBufferImpl>::create(buffer);
executed 79 times by 3 tests: return QSharedPointer<QNonContiguousByteDeviceBufferImpl>::create(buffer);
Executed by:
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
79
504-
505 // ### FIXME special case if device is a QFile that supports map()-
506 // then we can actually deal with the file without using read/peek-
507-
508 // generic QIODevice-
509 return QSharedPointer<QNonContiguousByteDeviceIoDeviceImpl>::create(device); // FIXME
executed 77 times by 2 tests: return QSharedPointer<QNonContiguousByteDeviceIoDeviceImpl>::create(device);
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
77
510}-
511-
512/*!-
513 \fn static QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QSharedPointer<QRingBuffer> ringBuffer)-
514-
515 Create a QNonContiguousByteDevice out of a QRingBuffer.-
516-
517 \internal-
518*/-
519QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QSharedPointer<QRingBuffer> ringBuffer)-
520{-
521 return new QNonContiguousByteDeviceRingBufferImpl(ringBuffer);
never executed: return new QNonContiguousByteDeviceRingBufferImpl(ringBuffer);
0
522}-
523-
524/*!-
525 Create a QNonContiguousByteDevice out of a QRingBuffer, return it in a QSharedPointer.-
526-
527 \internal-
528*/-
529QSharedPointer<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(QSharedPointer<QRingBuffer> ringBuffer)-
530{-
531 return QSharedPointer<QNonContiguousByteDeviceRingBufferImpl>::create(qMove(ringBuffer));
executed 99 times by 1 test: return QSharedPointer<QNonContiguousByteDeviceRingBufferImpl>::create(std::move(ringBuffer));
Executed by:
  • tst_QNetworkReply
99
532}-
533-
534/*!-
535 \fn static QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QByteArray *byteArray)-
536-
537 Create a QNonContiguousByteDevice out of a QByteArray.-
538-
539 \internal-
540*/-
541QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QByteArray *byteArray)-
542{-
543 return new QNonContiguousByteDeviceByteArrayImpl(byteArray);
executed 5 times by 1 test: return new QNonContiguousByteDeviceByteArrayImpl(byteArray);
Executed by:
  • tst_QHttpNetworkConnection
5
544}-
545-
546/*!-
547 Create a QNonContiguousByteDevice out of a QByteArray.-
548-
549 \internal-
550*/-
551QSharedPointer<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(QByteArray *byteArray)-
552{-
553 return QSharedPointer<QNonContiguousByteDeviceByteArrayImpl>::create(byteArray);
never executed: return QSharedPointer<QNonContiguousByteDeviceByteArrayImpl>::create(byteArray);
0
554}-
555-
556/*!-
557 \fn static QIODevice* QNonContiguousByteDeviceFactory::wrap(QNonContiguousByteDevice* byteDevice)-
558-
559 Wrap the \a byteDevice (possibly again) into a QIODevice.-
560-
561 \internal-
562*/-
563QIODevice* QNonContiguousByteDeviceFactory::wrap(QNonContiguousByteDevice* byteDevice)-
564{-
565 // ### FIXME if it already has been based on QIoDevice, we could that one out again-
566 // and save some calling-
567-
568 // needed for FTP backend-
569-
570 return new QByteDeviceWrappingIoDevice(byteDevice);
executed 13 times by 1 test: return new QByteDeviceWrappingIoDevice(byteDevice);
Executed by:
  • tst_QNetworkReply
13
571}-
572-
573QT_END_NAMESPACE-
574-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9