qbuffer.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qbuffer.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 "qbuffer.h"-
35#include <QtCore/qmetaobject.h>-
36#include "private/qiodevice_p.h"-
37-
38QT_BEGIN_NAMESPACE-
39-
40/** QBufferPrivate **/-
41class QBufferPrivate : public QIODevicePrivate-
42{-
43 Q_DECLARE_PUBLIC(QBuffer)-
44-
45public:-
46 QBufferPrivate()-
47 : buf(0)-
48#ifndef QT_NO_QOBJECT-
49 , writtenSinceLastEmit(0), signalConnectionCount(0), signalsEmitted(false)-
50#endif-
51 { }
executed 10588 times by 81 tests: end of block
Executed by:
  • tst_QAbstractItemModel
  • tst_QAbstractNetworkCache
  • tst_QAsn1Element
  • tst_QAuthenticator
  • tst_QBitArray
  • tst_QBrush
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDockWidget
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiVariant
  • tst_QHeaderView
  • tst_QHostAddress
  • tst_QHttpNetworkReply
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • ...
10588
52 ~QBufferPrivate() { }-
53-
54 QByteArray *buf;-
55 QByteArray defaultBuf;-
56-
57 virtual qint64 peek(char *data, qint64 maxSize) Q_DECL_OVERRIDE;-
58 virtual QByteArray peek(qint64 maxSize) Q_DECL_OVERRIDE;-
59-
60#ifndef QT_NO_QOBJECT-
61 // private slots-
62 void _q_emitSignals();-
63-
64 qint64 writtenSinceLastEmit;-
65 int signalConnectionCount;-
66 bool signalsEmitted;-
67#endif-
68};-
69-
70#ifndef QT_NO_QOBJECT-
71void QBufferPrivate::_q_emitSignals()-
72{-
73 Q_Q(QBuffer);-
74 emit q->bytesWritten(writtenSinceLastEmit);-
75 writtenSinceLastEmit = 0;-
76 emit q->readyRead();-
77 signalsEmitted = false;-
78}
executed 30 times by 1 test: end of block
Executed by:
  • tst_QBuffer
30
79#endif-
80-
81qint64 QBufferPrivate::peek(char *data, qint64 maxSize)-
82{-
83 qint64 readBytes = qMin(maxSize, static_cast<qint64>(buf->size()) - pos);-
84 memcpy(data, buf->constData() + pos, readBytes);-
85 return readBytes;
executed 1423 times by 12 tests: return readBytes;
Executed by:
  • tst_QBrush
  • tst_QDataStream
  • tst_QGuiVariant
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QPixmap
  • tst_QTextDocument
  • tst_QTextDocumentFragment
  • tst_QTextEdit
1423
86}-
87-
88QByteArray QBufferPrivate::peek(qint64 maxSize)-
89{-
90 qint64 readBytes = qMin(maxSize, static_cast<qint64>(buf->size()) - pos);-
91 if (pos == 0 && maxSize >= buf->size())
pos == 0Description
TRUEevaluated 115 times by 10 tests
Evaluated by:
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QMimeDatabase
  • tst_QPixmap
  • tst_QTextDocument
  • tst_QTextDocumentFragment
  • tst_QTextEdit
FALSEevaluated 100 times by 8 tests
Evaluated by:
  • tst_QBrush
  • tst_QDataStream
  • tst_QGuiVariant
  • tst_QIODevice
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QPixmap
maxSize >= buf->size()Description
TRUEevaluated 42 times by 3 tests
Evaluated by:
  • tst_QIODevice
  • tst_QImage
  • tst_QMimeDatabase
FALSEevaluated 73 times by 7 tests
Evaluated by:
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImageReader
  • tst_QPixmap
  • tst_QTextDocument
  • tst_QTextDocumentFragment
  • tst_QTextEdit
42-115
92 return *buf;
executed 42 times by 3 tests: return *buf;
Executed by:
  • tst_QIODevice
  • tst_QImage
  • tst_QMimeDatabase
42
93 return QByteArray(buf->constData() + pos, readBytes);
executed 173 times by 12 tests: return QByteArray(buf->constData() + pos, readBytes);
Executed by:
  • tst_QBrush
  • tst_QDataStream
  • tst_QGuiVariant
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QPixmap
  • tst_QTextDocument
  • tst_QTextDocumentFragment
  • tst_QTextEdit
173
94}-
95-
96/*!-
97 \class QBuffer-
98 \inmodule QtCore-
99 \reentrant-
100 \brief The QBuffer class provides a QIODevice interface for a QByteArray.-
101-
102 \ingroup io-
103-
104 QBuffer allows you to access a QByteArray using the QIODevice-
105 interface. The QByteArray is treated just as a standard random-accessed-
106 file. Example:-
107-
108 \snippet buffer/buffer.cpp 0-
109-
110 By default, an internal QByteArray buffer is created for you when-
111 you create a QBuffer. You can access this buffer directly by-
112 calling buffer(). You can also use QBuffer with an existing-
113 QByteArray by calling setBuffer(), or by passing your array to-
114 QBuffer's constructor.-
115-
116 Call open() to open the buffer. Then call write() or-
117 putChar() to write to the buffer, and read(), readLine(),-
118 readAll(), or getChar() to read from it. size() returns the-
119 current size of the buffer, and you can seek to arbitrary-
120 positions in the buffer by calling seek(). When you are done with-
121 accessing the buffer, call close().-
122-
123 The following code snippet shows how to write data to a-
124 QByteArray using QDataStream and QBuffer:-
125-
126 \snippet buffer/buffer.cpp 1-
127-
128 Effectively, we convert the application's QPalette into a byte-
129 array. Here's how to read the data from the QByteArray:-
130-
131 \snippet buffer/buffer.cpp 2-
132-
133 QTextStream and QDataStream also provide convenience constructors-
134 that take a QByteArray and that create a QBuffer behind the-
135 scenes.-
136-
137 QBuffer emits readyRead() when new data has arrived in the-
138 buffer. By connecting to this signal, you can use QBuffer to-
139 store temporary data before processing it. QBuffer also emits-
140 bytesWritten() every time new data has been written to the buffer.-
141-
142 \sa QFile, QDataStream, QTextStream, QByteArray-
143*/-
144-
145#ifdef QT_NO_QOBJECT-
146QBuffer::QBuffer()-
147 : QIODevice(*new QBufferPrivate)-
148{-
149 Q_D(QBuffer);-
150 d->buf = &d->defaultBuf;-
151}-
152QBuffer::QBuffer(QByteArray *buf)-
153 : QIODevice(*new QBufferPrivate)-
154{-
155 Q_D(QBuffer);-
156 d->buf = buf ? buf : &d->defaultBuf;-
157 d->defaultBuf.clear();-
158}-
159#else-
160/*!-
161 Constructs an empty buffer with the given \a parent. You can call-
162 setData() to fill the buffer with data, or you can open it in-
163 write mode and use write().-
164-
165 \sa open()-
166*/-
167QBuffer::QBuffer(QObject *parent)-
168 : QIODevice(*new QBufferPrivate, parent)-
169{-
170 Q_D(QBuffer);-
171 d->buf = &d->defaultBuf;-
172}
executed 1297 times by 41 tests: end of block
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QAsn1Element
  • tst_QAuthenticator
  • tst_QBitArray
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDockWidget
  • tst_QFont
  • tst_QFtp
  • tst_QGuiVariant
  • tst_QHttpNetworkReply
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QImage
  • tst_QImageReader
  • tst_QLabel
  • tst_QLoggingRegistry
  • tst_QMainWindow
  • tst_QMetaObjectBuilder
  • tst_QNetworkCacheMetaData
  • tst_QNetworkDiskCache
  • tst_QNetworkReply
  • tst_QPicture
  • tst_QPlainTextEdit
  • tst_QPoint
  • ...
1297
173-
174/*!-
175 Constructs a QBuffer that uses the QByteArray pointed to by \a-
176 byteArray as its internal buffer, and with the given \a parent.-
177 The caller is responsible for ensuring that \a byteArray remains-
178 valid until the QBuffer is destroyed, or until setBuffer() is-
179 called to change the buffer. QBuffer doesn't take ownership of-
180 the QByteArray.-
181-
182 If you open the buffer in write-only mode or read-write mode and-
183 write something into the QBuffer, \a byteArray will be modified.-
184-
185 Example:-
186-
187 \snippet buffer/buffer.cpp 3-
188-
189 \sa open(), setBuffer(), setData()-
190*/-
191QBuffer::QBuffer(QByteArray *byteArray, QObject *parent)-
192 : QIODevice(*new QBufferPrivate, parent)-
193{-
194 Q_D(QBuffer);-
195 d->buf = byteArray ? byteArray : &d->defaultBuf;
byteArrayDescription
TRUEevaluated 9291 times by 64 tests
Evaluated by:
  • tst_QAbstractItemModel
  • tst_QAsn1Element
  • tst_QAuthenticator
  • tst_QBrush
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDockWidget
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiVariant
  • tst_QHeaderView
  • tst_QHostAddress
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QImageWriter
  • tst_QKeyEvent
  • tst_QKeySequence
  • tst_QListWidget
  • ...
FALSEnever evaluated
0-9291
196 d->defaultBuf.clear();-
197}
executed 9291 times by 64 tests: end of block
Executed by:
  • tst_QAbstractItemModel
  • tst_QAsn1Element
  • tst_QAuthenticator
  • tst_QBrush
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDockWidget
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiVariant
  • tst_QHeaderView
  • tst_QHostAddress
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QImageWriter
  • tst_QKeyEvent
  • tst_QKeySequence
  • tst_QListWidget
  • ...
9291
198#endif-
199-
200/*!-
201 Destroys the buffer.-
202*/-
203-
204QBuffer::~QBuffer()-
205{-
206}-
207-
208/*!-
209 Makes QBuffer uses the QByteArray pointed to by \a-
210 byteArray as its internal buffer. The caller is responsible for-
211 ensuring that \a byteArray remains valid until the QBuffer is-
212 destroyed, or until setBuffer() is called to change the buffer.-
213 QBuffer doesn't take ownership of the QByteArray.-
214-
215 Does nothing if isOpen() is true.-
216-
217 If you open the buffer in write-only mode or read-write mode and-
218 write something into the QBuffer, \a byteArray will be modified.-
219-
220 Example:-
221-
222 \snippet buffer/buffer.cpp 4-
223-
224 If \a byteArray is 0, the buffer creates its own internal-
225 QByteArray to work on. This byte array is initially empty.-
226-
227 \sa buffer(), setData(), open()-
228*/-
229-
230void QBuffer::setBuffer(QByteArray *byteArray)-
231{-
232 Q_D(QBuffer);-
233 if (isOpen()) {
isOpen()Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • tst_QBuffer
0-9
234 qWarning("QBuffer::setBuffer: Buffer is open");-
235 return;
never executed: return;
0
236 }-
237 if (byteArray) {
byteArrayDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • tst_QBuffer
FALSEnever evaluated
0-9
238 d->buf = byteArray;-
239 } else {
executed 9 times by 1 test: end of block
Executed by:
  • tst_QBuffer
9
240 d->buf = &d->defaultBuf;-
241 }
never executed: end of block
0
242 d->defaultBuf.clear();-
243}
executed 9 times by 1 test: end of block
Executed by:
  • tst_QBuffer
9
244-
245/*!-
246 Returns a reference to the QBuffer's internal buffer. You can use-
247 it to modify the QByteArray behind the QBuffer's back.-
248-
249 \sa setBuffer(), data()-
250*/-
251-
252QByteArray &QBuffer::buffer()-
253{-
254 Q_D(QBuffer);-
255 return *d->buf;
executed 492 times by 12 tests: return *d->buf;
Executed by:
  • tst_QBuffer
  • tst_QDataStream
  • tst_QFtp
  • tst_QImageReader
  • tst_QNetworkReply
  • tst_QPicture
  • tst_QPrinter
  • tst_QRingBuffer
  • tst_QTextStream
  • tst_QXmlInputSource
  • tst_QXmlStream
  • tst_Spdy
492
256}-
257-
258/*!-
259 \overload-
260-
261 This is the same as data().-
262*/-
263-
264const QByteArray &QBuffer::buffer() const-
265{-
266 Q_D(const QBuffer);-
267 return *d->buf;
executed 174 times by 3 tests: return *d->buf;
Executed by:
  • tst_QDataStream
  • tst_QLabel
  • tst_QPicture
174
268}-
269-
270-
271/*!-
272 Returns the data contained in the buffer.-
273-
274 This is the same as buffer().-
275-
276 \sa setData(), setBuffer()-
277*/-
278-
279const QByteArray &QBuffer::data() const-
280{-
281 Q_D(const QBuffer);-
282 return *d->buf;
executed 25075 times by 12 tests: return *d->buf;
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QBuffer
  • tst_QDataStream
  • tst_QImage
  • tst_QImageReader
  • tst_QNetworkDiskCache
  • tst_QPixmap
  • tst_QPlainTextEdit
  • tst_QTextEdit
  • tst_QTextStream
  • tst_QVariant
  • tst_QXmlStream
25075
283}-
284-
285/*!-
286 Sets the contents of the internal buffer to be \a data. This is-
287 the same as assigning \a data to buffer().-
288-
289 Does nothing if isOpen() is true.-
290-
291 \sa setBuffer()-
292*/-
293void QBuffer::setData(const QByteArray &data)-
294{-
295 Q_D(QBuffer);-
296 if (isOpen()) {
isOpen()Description
TRUEnever evaluated
FALSEevaluated 528 times by 29 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QAsn1Element
  • tst_QAuthenticator
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDockWidget
  • tst_QGuiVariant
  • tst_QHttpNetworkReply
  • tst_QIcoImageFormat
  • tst_QImage
  • tst_QImageReader
  • tst_QLoggingRegistry
  • tst_QMainWindow
  • tst_QMetaObjectBuilder
  • tst_QNetworkDiskCache
  • tst_QNetworkReply
  • tst_QPicture
  • tst_QSizePolicy
  • tst_QTextStream
  • tst_QTranslator
  • tst_QUrl
  • tst_QVariant
  • tst_QVersionNumber
  • tst_QWidget
  • tst_QXmlInputSource
  • ...
0-528
297 qWarning("QBuffer::setData: Buffer is open");-
298 return;
never executed: return;
0
299 }-
300 *d->buf = data;-
301}
executed 528 times by 29 tests: end of block
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QAsn1Element
  • tst_QAuthenticator
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDockWidget
  • tst_QGuiVariant
  • tst_QHttpNetworkReply
  • tst_QIcoImageFormat
  • tst_QImage
  • tst_QImageReader
  • tst_QLoggingRegistry
  • tst_QMainWindow
  • tst_QMetaObjectBuilder
  • tst_QNetworkDiskCache
  • tst_QNetworkReply
  • tst_QPicture
  • tst_QSizePolicy
  • tst_QTextStream
  • tst_QTranslator
  • tst_QUrl
  • tst_QVariant
  • tst_QVersionNumber
  • tst_QWidget
  • tst_QXmlInputSource
  • ...
528
302-
303/*!-
304 \fn void QBuffer::setData(const char *data, int size)-
305-
306 \overload-
307-
308 Sets the contents of the internal buffer to be the first \a size-
309 bytes of \a data.-
310*/-
311-
312/*!-
313 \reimp-
314*/-
315bool QBuffer::open(OpenMode flags)-
316{-
317 Q_D(QBuffer);-
318-
319 if ((flags & (Append | Truncate)) != 0)
(flags & (Appe...runcate)) != 0Description
TRUEevaluated 78 times by 5 tests
Evaluated by:
  • tst_QBuffer
  • tst_QDataStream
  • tst_QMetaObjectBuilder
  • tst_QPicture
  • tst_QPrinter
FALSEevaluated 10592 times by 80 tests
Evaluated by:
  • tst_QAbstractItemModel
  • tst_QAbstractNetworkCache
  • tst_QAsn1Element
  • tst_QAuthenticator
  • tst_QBitArray
  • tst_QBrush
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDockWidget
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiVariant
  • tst_QHeaderView
  • tst_QHostAddress
  • tst_QHttpNetworkReply
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • ...
78-10592
320 flags |= WriteOnly;
executed 78 times by 5 tests: flags |= WriteOnly;
Executed by:
  • tst_QBuffer
  • tst_QDataStream
  • tst_QMetaObjectBuilder
  • tst_QPicture
  • tst_QPrinter
78
321 if ((flags & (ReadOnly | WriteOnly)) == 0) {
(flags & (Read...iteOnly)) == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QBuffer
FALSEevaluated 10667 times by 80 tests
Evaluated by:
  • tst_QAbstractItemModel
  • tst_QAbstractNetworkCache
  • tst_QAsn1Element
  • tst_QAuthenticator
  • tst_QBitArray
  • tst_QBrush
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDockWidget
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiVariant
  • tst_QHeaderView
  • tst_QHostAddress
  • tst_QHttpNetworkReply
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • ...
3-10667
322 qWarning("QBuffer::open: Buffer access not specified");-
323 return false;
executed 3 times by 1 test: return false;
Executed by:
  • tst_QBuffer
3
324 }-
325-
326 if ((flags & Truncate) == Truncate)
(flags & Truncate) == TruncateDescription
TRUEevaluated 52 times by 4 tests
Evaluated by:
  • tst_QBuffer
  • tst_QDataStream
  • tst_QPicture
  • tst_QPrinter
FALSEevaluated 10615 times by 80 tests
Evaluated by:
  • tst_QAbstractItemModel
  • tst_QAbstractNetworkCache
  • tst_QAsn1Element
  • tst_QAuthenticator
  • tst_QBitArray
  • tst_QBrush
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDockWidget
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiVariant
  • tst_QHeaderView
  • tst_QHostAddress
  • tst_QHttpNetworkReply
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • ...
52-10615
327 d->buf->resize(0);
executed 52 times by 4 tests: d->buf->resize(0);
Executed by:
  • tst_QBuffer
  • tst_QDataStream
  • tst_QPicture
  • tst_QPrinter
52
328-
329 return QIODevice::open(flags | QIODevice::Unbuffered);
executed 10667 times by 80 tests: return QIODevice::open(flags | QIODevice::Unbuffered);
Executed by:
  • tst_QAbstractItemModel
  • tst_QAbstractNetworkCache
  • tst_QAsn1Element
  • tst_QAuthenticator
  • tst_QBitArray
  • tst_QBrush
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDockWidget
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiVariant
  • tst_QHeaderView
  • tst_QHostAddress
  • tst_QHttpNetworkReply
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • ...
10667
330}-
331-
332/*!-
333 \reimp-
334*/-
335void QBuffer::close()-
336{-
337 QIODevice::close();-
338}
executed 1836 times by 16 tests: end of block
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QBitArray
  • tst_QBuffer
  • tst_QDataStream
  • tst_QFont
  • tst_QIcoImageFormat
  • tst_QImageReader
  • tst_QMimeDatabase
  • tst_QNetworkDiskCache
  • tst_QNetworkReply
  • tst_QPicture
  • tst_QPlainTextEdit
  • tst_QPrinter
  • tst_QTextEdit
  • tst_QTextStream
  • tst_QXmlStream
1836
339-
340/*!-
341 \reimp-
342*/-
343qint64 QBuffer::pos() const-
344{-
345 return QIODevice::pos();
executed 9742750 times by 80 tests: return QIODevice::pos();
Executed by:
  • tst_QAbstractItemModel
  • tst_QAbstractNetworkCache
  • tst_QAsn1Element
  • tst_QAuthenticator
  • tst_QBitArray
  • tst_QBrush
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDockWidget
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiVariant
  • tst_QHeaderView
  • tst_QHostAddress
  • tst_QHttpNetworkReply
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • ...
9742750
346}-
347-
348/*!-
349 \reimp-
350*/-
351qint64 QBuffer::size() const-
352{-
353 Q_D(const QBuffer);-
354 return qint64(d->buf->size());
executed 24433 times by 42 tests: return qint64(d->buf->size());
Executed by:
  • tst_QAbstractItemModel
  • tst_QAbstractNetworkCache
  • tst_QAuthenticator
  • tst_QBrush
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDockWidget
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QFtp
  • tst_QGuiVariant
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QKeySequence
  • tst_QLoggingRegistry
  • tst_QMainWindow
  • tst_QMetaObjectBuilder
  • tst_QNetworkCacheMetaData
  • tst_QNetworkDiskCache
  • tst_QNetworkReply
  • tst_QPicture
  • tst_QPixmap
  • ...
24433
355}-
356-
357/*!-
358 \reimp-
359*/-
360bool QBuffer::seek(qint64 pos)-
361{-
362 Q_D(QBuffer);-
363 if (pos > d->buf->size() && isWritable()) {
pos > d->buf->size()Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QBuffer
FALSEevaluated 45561 times by 29 tests
Evaluated by:
  • tst_QAuthenticator
  • tst_QBitArray
  • tst_QBrush
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDate
  • tst_QFont
  • tst_QGuiVariant
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QLocalSocket
  • tst_QMetaType
  • tst_QNetworkCacheMetaData
  • tst_QNetworkReply
  • tst_QPicture
  • tst_QPixmap
  • tst_QPlainTextEdit
  • tst_QPoint
  • tst_QPointF
  • tst_QPrinter
  • tst_QRingBuffer
  • tst_QTextDocument
  • ...
isWritable()Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QBuffer
FALSEnever evaluated
0-45561
364 if (seek(d->buf->size())) {
seek(d->buf->size())Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QBuffer
FALSEnever evaluated
0-3
365 const qint64 gapSize = pos - d->buf->size();-
366 if (write(QByteArray(gapSize, 0)) != gapSize) {
write(QByteArr...0)) != gapSizeDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QBuffer
0-3
367 qWarning("QBuffer::seek: Unable to fill gap");-
368 return false;
never executed: return false;
0
369 }-
370 } else {
executed 3 times by 1 test: end of block
Executed by:
  • tst_QBuffer
3
371 return false;
never executed: return false;
0
372 }-
373 } else if (pos > d->buf->size() || pos < 0) {
pos > d->buf->size()Description
TRUEnever evaluated
FALSEevaluated 45561 times by 29 tests
Evaluated by:
  • tst_QAuthenticator
  • tst_QBitArray
  • tst_QBrush
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDate
  • tst_QFont
  • tst_QGuiVariant
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QLocalSocket
  • tst_QMetaType
  • tst_QNetworkCacheMetaData
  • tst_QNetworkReply
  • tst_QPicture
  • tst_QPixmap
  • tst_QPlainTextEdit
  • tst_QPoint
  • tst_QPointF
  • tst_QPrinter
  • tst_QRingBuffer
  • tst_QTextDocument
  • ...
pos < 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QBuffer
FALSEevaluated 45559 times by 29 tests
Evaluated by:
  • tst_QAuthenticator
  • tst_QBitArray
  • tst_QBrush
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDate
  • tst_QFont
  • tst_QGuiVariant
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QLocalSocket
  • tst_QMetaType
  • tst_QNetworkCacheMetaData
  • tst_QNetworkReply
  • tst_QPicture
  • tst_QPixmap
  • tst_QPlainTextEdit
  • tst_QPoint
  • tst_QPointF
  • tst_QPrinter
  • tst_QRingBuffer
  • tst_QTextDocument
  • ...
0-45561
374 qWarning("QBuffer::seek: Invalid pos: %d", int(pos));-
375 return false;
executed 2 times by 1 test: return false;
Executed by:
  • tst_QBuffer
2
376 }-
377 return QIODevice::seek(pos);
executed 45562 times by 29 tests: return QIODevice::seek(pos);
Executed by:
  • tst_QAuthenticator
  • tst_QBitArray
  • tst_QBrush
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDate
  • tst_QFont
  • tst_QGuiVariant
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QLocalSocket
  • tst_QMetaType
  • tst_QNetworkCacheMetaData
  • tst_QNetworkReply
  • tst_QPicture
  • tst_QPixmap
  • tst_QPlainTextEdit
  • tst_QPoint
  • tst_QPointF
  • tst_QPrinter
  • tst_QRingBuffer
  • tst_QTextDocument
  • ...
45562
378}-
379-
380/*!-
381 \reimp-
382*/-
383bool QBuffer::atEnd() const-
384{-
385 return QIODevice::atEnd();
executed 4798 times by 32 tests: return QIODevice::atEnd();
Executed by:
  • tst_QAbstractItemModel
  • tst_QAbstractNetworkCache
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDockWidget
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QFtp
  • tst_QGuiVariant
  • tst_QIODevice
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QKeySequence
  • tst_QLoggingRegistry
  • tst_QMainWindow
  • tst_QMetaObjectBuilder
  • tst_QNetworkCacheMetaData
  • tst_QNetworkDiskCache
  • tst_QNetworkReply
  • tst_QPicture
  • tst_QPixmap
  • tst_QPrinter
  • tst_QSettings
  • tst_QSplitter
  • ...
4798
386}-
387-
388/*!-
389 \reimp-
390*/-
391bool QBuffer::canReadLine() const-
392{-
393 Q_D(const QBuffer);-
394 if (!isOpen())
!isOpen()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QBuffer
FALSEevaluated 59 times by 3 tests
Evaluated by:
  • tst_QBuffer
  • tst_QIODevice
  • tst_QXmlSimpleReader
4-59
395 return false;
executed 4 times by 1 test: return false;
Executed by:
  • tst_QBuffer
4
396-
397 return d->buf->indexOf('\n', int(pos())) != -1 || QIODevice::canReadLine();
executed 59 times by 3 tests: return d->buf->indexOf('\n', int(pos())) != -1 || QIODevice::canReadLine();
Executed by:
  • tst_QBuffer
  • tst_QIODevice
  • tst_QXmlSimpleReader
d->buf->indexO...(pos())) != -1Description
TRUEevaluated 55 times by 3 tests
Evaluated by:
  • tst_QBuffer
  • tst_QIODevice
  • tst_QXmlSimpleReader
FALSEevaluated 4 times by 2 tests
Evaluated by:
  • tst_QBuffer
  • tst_QXmlSimpleReader
QIODevice::canReadLine()Description
TRUEnever evaluated
FALSEevaluated 4 times by 2 tests
Evaluated by:
  • tst_QBuffer
  • tst_QXmlSimpleReader
0-59
398}-
399-
400/*!-
401 \reimp-
402*/-
403qint64 QBuffer::readData(char *data, qint64 len)-
404{-
405 Q_D(QBuffer);-
406 if ((len = qMin(len, qint64(d->buf->size()) - pos())) <= 0)
(len = qMin(le...- pos())) <= 0Description
TRUEevaluated 1348 times by 20 tests
Evaluated by:
  • tst_QAsn1Element
  • tst_QBuffer
  • tst_QDataStream
  • tst_QFtp
  • tst_QGuiVariant
  • tst_QHeaderView
  • tst_QIODevice
  • tst_QImage
  • tst_QImageReader
  • tst_QLoggingRegistry
  • tst_QMainWindow
  • tst_QMetaObjectBuilder
  • tst_QMetaType
  • tst_QNetworkReply
  • tst_QPixmap
  • tst_QPrinter
  • tst_QTextStream
  • tst_QXmlInputSource
  • tst_QXmlSimpleReader
  • tst_QXmlStream
FALSEevaluated 4641005 times by 72 tests
Evaluated by:
  • tst_QAbstractItemModel
  • tst_QAbstractNetworkCache
  • tst_QAsn1Element
  • tst_QAuthenticator
  • tst_QBitArray
  • tst_QBrush
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDockWidget
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiVariant
  • tst_QHeaderView
  • tst_QHostAddress
  • tst_QHttpNetworkReply
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • ...
1348-4641005
407 return qint64(0);
executed 1348 times by 20 tests: return qint64(0);
Executed by:
  • tst_QAsn1Element
  • tst_QBuffer
  • tst_QDataStream
  • tst_QFtp
  • tst_QGuiVariant
  • tst_QHeaderView
  • tst_QIODevice
  • tst_QImage
  • tst_QImageReader
  • tst_QLoggingRegistry
  • tst_QMainWindow
  • tst_QMetaObjectBuilder
  • tst_QMetaType
  • tst_QNetworkReply
  • tst_QPixmap
  • tst_QPrinter
  • tst_QTextStream
  • tst_QXmlInputSource
  • tst_QXmlSimpleReader
  • tst_QXmlStream
1348
408 memcpy(data, d->buf->constData() + pos(), len);-
409 return len;
executed 4641005 times by 72 tests: return len;
Executed by:
  • tst_QAbstractItemModel
  • tst_QAbstractNetworkCache
  • tst_QAsn1Element
  • tst_QAuthenticator
  • tst_QBitArray
  • tst_QBrush
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDockWidget
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiVariant
  • tst_QHeaderView
  • tst_QHostAddress
  • tst_QHttpNetworkReply
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • ...
4641005
410}-
411-
412/*!-
413 \reimp-
414*/-
415qint64 QBuffer::writeData(const char *data, qint64 len)-
416{-
417 Q_D(QBuffer);-
418 int extraBytes = pos() + len - d->buf->size();-
419 if (extraBytes > 0) { // overflow
extraBytes > 0Description
TRUEevaluated 211904 times by 69 tests
Evaluated by:
  • tst_QAbstractItemModel
  • tst_QAbstractNetworkCache
  • tst_QAsn1Element
  • tst_QAuthenticator
  • tst_QBitArray
  • tst_QBrush
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDockWidget
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiVariant
  • tst_QHeaderView
  • tst_QHostAddress
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QImageWriter
  • ...
FALSEevaluated 8300 times by 14 tests
Evaluated by:
  • tst_QAsn1Element
  • tst_QAuthenticator
  • tst_QBuffer
  • tst_QDataStream
  • tst_QIODevice
  • tst_QLocalSocket
  • tst_QPicture
  • tst_QPlainTextEdit
  • tst_QPrinter
  • tst_QTextEdit
  • tst_QTextStream
  • tst_QTimeZone
  • tst_QUuid
  • tst_QXmlStream
8300-211904
420 int newSize = d->buf->size() + extraBytes;-
421 d->buf->resize(newSize);-
422 if (d->buf->size() != newSize) { // could not resize
d->buf->size() != newSizeDescription
TRUEnever evaluated
FALSEevaluated 211904 times by 69 tests
Evaluated by:
  • tst_QAbstractItemModel
  • tst_QAbstractNetworkCache
  • tst_QAsn1Element
  • tst_QAuthenticator
  • tst_QBitArray
  • tst_QBrush
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDockWidget
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiVariant
  • tst_QHeaderView
  • tst_QHostAddress
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QImageWriter
  • ...
0-211904
423 qWarning("QBuffer::writeData: Memory allocation error");-
424 return -1;
never executed: return -1;
0
425 }-
426 }
executed 211904 times by 69 tests: end of block
Executed by:
  • tst_QAbstractItemModel
  • tst_QAbstractNetworkCache
  • tst_QAsn1Element
  • tst_QAuthenticator
  • tst_QBitArray
  • tst_QBrush
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDockWidget
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiVariant
  • tst_QHeaderView
  • tst_QHostAddress
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QImageWriter
  • ...
211904
427-
428 memcpy(d->buf->data() + pos(), data, int(len));-
429-
430#ifndef QT_NO_QOBJECT-
431 d->writtenSinceLastEmit += len;-
432 if (d->signalConnectionCount && !d->signalsEmitted && !signalsBlocked()) {
d->signalConnectionCountDescription
TRUEevaluated 40 times by 1 test
Evaluated by:
  • tst_QBuffer
FALSEevaluated 220164 times by 69 tests
Evaluated by:
  • tst_QAbstractItemModel
  • tst_QAbstractNetworkCache
  • tst_QAsn1Element
  • tst_QAuthenticator
  • tst_QBitArray
  • tst_QBrush
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDockWidget
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiVariant
  • tst_QHeaderView
  • tst_QHostAddress
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QImageWriter
  • ...
!d->signalsEmittedDescription
TRUEevaluated 31 times by 1 test
Evaluated by:
  • tst_QBuffer
FALSEevaluated 9 times by 1 test
Evaluated by:
  • tst_QBuffer
!signalsBlocked()Description
TRUEevaluated 31 times by 1 test
Evaluated by:
  • tst_QBuffer
FALSEnever evaluated
0-220164
433 d->signalsEmitted = true;-
434 QMetaObject::invokeMethod(this, "_q_emitSignals", Qt::QueuedConnection);-
435 }
executed 31 times by 1 test: end of block
Executed by:
  • tst_QBuffer
31
436#endif-
437 return len;
executed 220204 times by 69 tests: return len;
Executed by:
  • tst_QAbstractItemModel
  • tst_QAbstractNetworkCache
  • tst_QAsn1Element
  • tst_QAuthenticator
  • tst_QBitArray
  • tst_QBrush
  • tst_QBuffer
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDockWidget
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiVariant
  • tst_QHeaderView
  • tst_QHostAddress
  • tst_QIODevice
  • tst_QIcoImageFormat
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QImageWriter
  • ...
220204
438}-
439-
440#ifndef QT_NO_QOBJECT-
441/*!-
442 \reimp-
443 \internal-
444*/-
445void QBuffer::connectNotify(const QMetaMethod &signal)-
446{-
447 static const QMetaMethod readyReadSignal = QMetaMethod::fromSignal(&QBuffer::readyRead);-
448 static const QMetaMethod bytesWrittenSignal = QMetaMethod::fromSignal(&QBuffer::bytesWritten);-
449 if (signal == readyReadSignal || signal == bytesWrittenSignal)
signal == readyReadSignalDescription
TRUEevaluated 40 times by 3 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QBuffer
  • tst_QNetworkReply
FALSEevaluated 1349 times by 11 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QBuffer
  • tst_QKeyEvent
  • tst_QLoggingRegistry
  • tst_QNetworkReply
  • tst_QString
  • tst_QTextStream
  • tst_QXmlStream
  • tst_qdbusxml2cpp - unknown status
  • tst_qmakelib
  • tst_qtextstream - unknown status
signal == bytesWrittenSignalDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QBuffer
FALSEevaluated 1345 times by 10 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QKeyEvent
  • tst_QLoggingRegistry
  • tst_QNetworkReply
  • tst_QString
  • tst_QTextStream
  • tst_QXmlStream
  • tst_qdbusxml2cpp - unknown status
  • tst_qmakelib
  • tst_qtextstream - unknown status
4-1349
450 d_func()->signalConnectionCount++;
executed 44 times by 3 tests: d_func()->signalConnectionCount++;
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QBuffer
  • tst_QNetworkReply
44
451}
executed 1389 times by 11 tests: end of block
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QBuffer
  • tst_QKeyEvent
  • tst_QLoggingRegistry
  • tst_QNetworkReply
  • tst_QString
  • tst_QTextStream
  • tst_QXmlStream
  • tst_qdbusxml2cpp - unknown status
  • tst_qmakelib
  • tst_qtextstream - unknown status
1389
452-
453/*!-
454 \reimp-
455 \internal-
456*/-
457void QBuffer::disconnectNotify(const QMetaMethod &signal)-
458{-
459 if (signal.isValid()) {
signal.isValid()Description
TRUEevaluated 472 times by 3 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
  • tst_QTextStream
FALSEnever evaluated
0-472
460 static const QMetaMethod readyReadSignal = QMetaMethod::fromSignal(&QBuffer::readyRead);-
461 static const QMetaMethod bytesWrittenSignal = QMetaMethod::fromSignal(&QBuffer::bytesWritten);-
462 if (signal == readyReadSignal || signal == bytesWrittenSignal)
signal == readyReadSignalDescription
TRUEevaluated 9 times by 2 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
FALSEevaluated 463 times by 3 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
  • tst_QTextStream
signal == bytesWrittenSignalDescription
TRUEnever evaluated
FALSEevaluated 463 times by 3 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
  • tst_QTextStream
0-463
463 d_func()->signalConnectionCount--;
executed 9 times by 2 tests: d_func()->signalConnectionCount--;
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
9
464 } else {
executed 472 times by 3 tests: end of block
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
  • tst_QTextStream
472
465 d_func()->signalConnectionCount = 0;-
466 }
never executed: end of block
0
467}-
468#endif-
469-
470QT_END_NAMESPACE-
471-
472#ifndef QT_NO_QOBJECT-
473# include "moc_qbuffer.cpp"-
474#endif-
475-
Source codeSwitch to Preprocessed file

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