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) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtCore module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
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 https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://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 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qbuffer.h"-
41#include <QtCore/qmetaobject.h>-
42#include "private/qiodevice_p.h"-
43-
44QT_BEGIN_NAMESPACE-
45-
46/** QBufferPrivate **/-
47class QBufferPrivate : public QIODevicePrivate-
48{-
49 Q_DECLARE_PUBLIC(QBuffer)-
50-
51public:-
52 QBufferPrivate()-
53 : buf(0)-
54#ifndef QT_NO_QOBJECT-
55 , writtenSinceLastEmit(0), signalConnectionCount(0), signalsEmitted(false)-
56#endif-
57 { }
executed 11235 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
  • ...
11235
58 ~QBufferPrivate() { }-
59-
60 QByteArray *buf;-
61 QByteArray defaultBuf;-
62-
63 virtual qint64 peek(char *data, qint64 maxSize) Q_DECL_OVERRIDE;-
64 virtual QByteArray peek(qint64 maxSize) Q_DECL_OVERRIDE;-
65-
66#ifndef QT_NO_QOBJECT-
67 // private slots-
68 void _q_emitSignals();-
69-
70 qint64 writtenSinceLastEmit;-
71 int signalConnectionCount;-
72 bool signalsEmitted;-
73#endif-
74};-
75-
76#ifndef QT_NO_QOBJECT-
77void QBufferPrivate::_q_emitSignals()-
78{-
79 Q_Q(QBuffer);-
80 emit q->bytesWritten(writtenSinceLastEmit);-
81 writtenSinceLastEmit = 0;-
82 emit q->readyRead();-
83 signalsEmitted = false;-
84}
executed 30 times by 1 test: end of block
Executed by:
  • tst_QBuffer
30
85#endif-
86-
87qint64 QBufferPrivate::peek(char *data, qint64 maxSize)-
88{-
89 qint64 readBytes = qMin(maxSize, static_cast<qint64>(buf->size()) - pos);-
90 memcpy(data, buf->constData() + pos, readBytes);-
91 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
92}-
93-
94QByteArray QBufferPrivate::peek(qint64 maxSize)-
95{-
96 qint64 readBytes = qMin(maxSize, static_cast<qint64>(buf->size()) - pos);-
97 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
98 return *buf;
executed 42 times by 3 tests: return *buf;
Executed by:
  • tst_QIODevice
  • tst_QImage
  • tst_QMimeDatabase
42
99 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
100}-
101-
102/*!-
103 \class QBuffer-
104 \inmodule QtCore-
105 \reentrant-
106 \brief The QBuffer class provides a QIODevice interface for a QByteArray.-
107-
108 \ingroup io-
109-
110 QBuffer allows you to access a QByteArray using the QIODevice-
111 interface. The QByteArray is treated just as a standard random-accessed-
112 file. Example:-
113-
114 \snippet buffer/buffer.cpp 0-
115-
116 By default, an internal QByteArray buffer is created for you when-
117 you create a QBuffer. You can access this buffer directly by-
118 calling buffer(). You can also use QBuffer with an existing-
119 QByteArray by calling setBuffer(), or by passing your array to-
120 QBuffer's constructor.-
121-
122 Call open() to open the buffer. Then call write() or-
123 putChar() to write to the buffer, and read(), readLine(),-
124 readAll(), or getChar() to read from it. size() returns the-
125 current size of the buffer, and you can seek to arbitrary-
126 positions in the buffer by calling seek(). When you are done with-
127 accessing the buffer, call close().-
128-
129 The following code snippet shows how to write data to a-
130 QByteArray using QDataStream and QBuffer:-
131-
132 \snippet buffer/buffer.cpp 1-
133-
134 Effectively, we convert the application's QPalette into a byte-
135 array. Here's how to read the data from the QByteArray:-
136-
137 \snippet buffer/buffer.cpp 2-
138-
139 QTextStream and QDataStream also provide convenience constructors-
140 that take a QByteArray and that create a QBuffer behind the-
141 scenes.-
142-
143 QBuffer emits readyRead() when new data has arrived in the-
144 buffer. By connecting to this signal, you can use QBuffer to-
145 store temporary data before processing it. QBuffer also emits-
146 bytesWritten() every time new data has been written to the buffer.-
147-
148 \sa QFile, QDataStream, QTextStream, QByteArray-
149*/-
150-
151#ifdef QT_NO_QOBJECT-
152QBuffer::QBuffer()-
153 : QIODevice(*new QBufferPrivate)-
154{-
155 Q_D(QBuffer);-
156 d->buf = &d->defaultBuf;-
157}-
158QBuffer::QBuffer(QByteArray *buf)-
159 : QIODevice(*new QBufferPrivate)-
160{-
161 Q_D(QBuffer);-
162 d->buf = buf ? buf : &d->defaultBuf;-
163 d->defaultBuf.clear();-
164}-
165#else-
166/*!-
167 Constructs an empty buffer with the given \a parent. You can call-
168 setData() to fill the buffer with data, or you can open it in-
169 write mode and use write().-
170-
171 \sa open()-
172*/-
173QBuffer::QBuffer(QObject *parent)-
174 : QIODevice(*new QBufferPrivate, parent)-
175{-
176 Q_D(QBuffer);-
177 d->buf = &d->defaultBuf;-
178}
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
179-
180/*!-
181 Constructs a QBuffer that uses the QByteArray pointed to by \a-
182 byteArray as its internal buffer, and with the given \a parent.-
183 The caller is responsible for ensuring that \a byteArray remains-
184 valid until the QBuffer is destroyed, or until setBuffer() is-
185 called to change the buffer. QBuffer doesn't take ownership of-
186 the QByteArray.-
187-
188 If you open the buffer in write-only mode or read-write mode and-
189 write something into the QBuffer, \a byteArray will be modified.-
190-
191 Example:-
192-
193 \snippet buffer/buffer.cpp 3-
194-
195 \sa open(), setBuffer(), setData()-
196*/-
197QBuffer::QBuffer(QByteArray *byteArray, QObject *parent)-
198 : QIODevice(*new QBufferPrivate, parent)-
199{-
200 Q_D(QBuffer);-
201 d->buf = byteArray ? byteArray : &d->defaultBuf;
byteArrayDescription
TRUEevaluated 9938 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-9938
202 d->defaultBuf.clear();-
203}
executed 9938 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
  • ...
9938
204#endif-
205-
206/*!-
207 Destroys the buffer.-
208*/-
209-
210QBuffer::~QBuffer()-
211{-
212}-
213-
214/*!-
215 Makes QBuffer uses the QByteArray pointed to by \a-
216 byteArray as its internal buffer. The caller is responsible for-
217 ensuring that \a byteArray remains valid until the QBuffer is-
218 destroyed, or until setBuffer() is called to change the buffer.-
219 QBuffer doesn't take ownership of the QByteArray.-
220-
221 Does nothing if isOpen() is true.-
222-
223 If you open the buffer in write-only mode or read-write mode and-
224 write something into the QBuffer, \a byteArray will be modified.-
225-
226 Example:-
227-
228 \snippet buffer/buffer.cpp 4-
229-
230 If \a byteArray is 0, the buffer creates its own internal-
231 QByteArray to work on. This byte array is initially empty.-
232-
233 \sa buffer(), setData(), open()-
234*/-
235-
236void QBuffer::setBuffer(QByteArray *byteArray)-
237{-
238 Q_D(QBuffer);-
239 if (isOpen()) {
isOpen()Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • tst_QBuffer
0-9
240 qWarning("QBuffer::setBuffer: Buffer is open");-
241 return;
never executed: return;
0
242 }-
243 if (byteArray) {
byteArrayDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • tst_QBuffer
FALSEnever evaluated
0-9
244 d->buf = byteArray;-
245 } else {
executed 9 times by 1 test: end of block
Executed by:
  • tst_QBuffer
9
246 d->buf = &d->defaultBuf;-
247 }
never executed: end of block
0
248 d->defaultBuf.clear();-
249}
executed 9 times by 1 test: end of block
Executed by:
  • tst_QBuffer
9
250-
251/*!-
252 Returns a reference to the QBuffer's internal buffer. You can use-
253 it to modify the QByteArray behind the QBuffer's back.-
254-
255 \sa setBuffer(), data()-
256*/-
257-
258QByteArray &QBuffer::buffer()-
259{-
260 Q_D(QBuffer);-
261 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
262}-
263-
264/*!-
265 \overload-
266-
267 This is the same as data().-
268*/-
269-
270const QByteArray &QBuffer::buffer() const-
271{-
272 Q_D(const QBuffer);-
273 return *d->buf;
executed 174 times by 3 tests: return *d->buf;
Executed by:
  • tst_QDataStream
  • tst_QLabel
  • tst_QPicture
174
274}-
275-
276-
277/*!-
278 Returns the data contained in the buffer.-
279-
280 This is the same as buffer().-
281-
282 \sa setData(), setBuffer()-
283*/-
284-
285const QByteArray &QBuffer::data() const-
286{-
287 Q_D(const QBuffer);-
288 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
289}-
290-
291/*!-
292 Sets the contents of the internal buffer to be \a data. This is-
293 the same as assigning \a data to buffer().-
294-
295 Does nothing if isOpen() is true.-
296-
297 \sa setBuffer()-
298*/-
299void QBuffer::setData(const QByteArray &data)-
300{-
301 Q_D(QBuffer);-
302 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
303 qWarning("QBuffer::setData: Buffer is open");-
304 return;
never executed: return;
0
305 }-
306 *d->buf = data;-
307}
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
308-
309/*!-
310 \fn void QBuffer::setData(const char *data, int size)-
311-
312 \overload-
313-
314 Sets the contents of the internal buffer to be the first \a size-
315 bytes of \a data.-
316*/-
317-
318/*!-
319 \reimp-
320*/-
321bool QBuffer::open(OpenMode flags)-
322{-
323 Q_D(QBuffer);-
324-
325 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 11239 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-11239
326 flags |= WriteOnly;
executed 78 times by 5 tests: flags |= WriteOnly;
Executed by:
  • tst_QBuffer
  • tst_QDataStream
  • tst_QMetaObjectBuilder
  • tst_QPicture
  • tst_QPrinter
78
327 if ((flags & (ReadOnly | WriteOnly)) == 0) {
(flags & (Read...iteOnly)) == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QBuffer
FALSEevaluated 11314 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-11314
328 qWarning("QBuffer::open: Buffer access not specified");-
329 return false;
executed 3 times by 1 test: return false;
Executed by:
  • tst_QBuffer
3
330 }-
331-
332 if ((flags & Truncate) == Truncate)
(flags & Truncate) == TruncateDescription
TRUEevaluated 52 times by 4 tests
Evaluated by:
  • tst_QBuffer
  • tst_QDataStream
  • tst_QPicture
  • tst_QPrinter
FALSEevaluated 11262 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-11262
333 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
334-
335 return QIODevice::open(flags | QIODevice::Unbuffered);
executed 11314 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
  • ...
11314
336}-
337-
338/*!-
339 \reimp-
340*/-
341void QBuffer::close()-
342{-
343 QIODevice::close();-
344}
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
345-
346/*!-
347 \reimp-
348*/-
349qint64 QBuffer::pos() const-
350{-
351 return QIODevice::pos();
executed 9749910 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
  • ...
9749910
352}-
353-
354/*!-
355 \reimp-
356*/-
357qint64 QBuffer::size() const-
358{-
359 Q_D(const QBuffer);-
360 return qint64(d->buf->size());
executed 25099 times by 37 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_QNetworkDiskCache
  • tst_QNetworkReply
  • tst_QPicture
  • tst_QPixmap
  • tst_QPlainTextEdit
  • ...
25099
361}-
362-
363/*!-
364 \reimp-
365*/-
366bool QBuffer::seek(qint64 pos)-
367{-
368 Q_D(QBuffer);-
369 if (pos > d->buf->size() && isWritable()) {
pos > d->buf->size()Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QBuffer
FALSEevaluated 45716 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-45716
370 if (seek(d->buf->size())) {
seek(d->buf->size())Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QBuffer
FALSEnever evaluated
0-3
371 const qint64 gapSize = pos - d->buf->size();-
372 if (write(QByteArray(gapSize, 0)) != gapSize) {
write(QByteArr...0)) != gapSizeDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QBuffer
0-3
373 qWarning("QBuffer::seek: Unable to fill gap");-
374 return false;
never executed: return false;
0
375 }-
376 } else {
executed 3 times by 1 test: end of block
Executed by:
  • tst_QBuffer
3
377 return false;
never executed: return false;
0
378 }-
379 } else if (pos > d->buf->size() || pos < 0) {
pos > d->buf->size()Description
TRUEnever evaluated
FALSEevaluated 45716 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 45714 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-45716
380 qWarning("QBuffer::seek: Invalid pos: %d", int(pos));-
381 return false;
executed 2 times by 1 test: return false;
Executed by:
  • tst_QBuffer
2
382 }-
383 return QIODevice::seek(pos);
executed 45717 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
  • ...
45717
384}-
385-
386/*!-
387 \reimp-
388*/-
389bool QBuffer::atEnd() const-
390{-
391 return QIODevice::atEnd();
executed 5890 times by 26 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_QNetworkDiskCache
  • tst_QNetworkReply
  • tst_QPicture
  • tst_QPixmap
  • tst_QPrinter
  • tst_QStandardItemModel
  • tst_QTextStream
  • tst_QTranslator
  • tst_QXmlStream
  • ...
5890
392}-
393-
394/*!-
395 \reimp-
396*/-
397bool QBuffer::canReadLine() const-
398{-
399 Q_D(const QBuffer);-
400 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
401 return false;
executed 4 times by 1 test: return false;
Executed by:
  • tst_QBuffer
4
402-
403 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
59
404}-
405-
406/*!-
407 \reimp-
408*/-
409qint64 QBuffer::readData(char *data, qint64 len)-
410{-
411 Q_D(QBuffer);-
412 if ((len = qMin(len, qint64(d->buf->size()) - pos())) <= 0)
(len = qMin(le...- pos())) <= 0Description
TRUEevaluated 1473 times by 21 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
  • tst_languageChange
FALSEevaluated 4647285 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
  • ...
1473-4647285
413 return qint64(0);
executed 1473 times by 21 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
  • tst_languageChange
1473
414 memcpy(data, d->buf->constData() + pos(), len);-
415 return len;
executed 4647285 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
  • ...
4647285
416}-
417-
418/*!-
419 \reimp-
420*/-
421qint64 QBuffer::writeData(const char *data, qint64 len)-
422{-
423 Q_D(QBuffer);-
424 int extraBytes = pos() + len - d->buf->size();-
425 if (extraBytes > 0) { // overflow
extraBytes > 0Description
TRUEevaluated 212303 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-212303
426 int newSize = d->buf->size() + extraBytes;-
427 d->buf->resize(newSize);-
428 if (d->buf->size() != newSize) { // could not resize
d->buf->size() != newSizeDescription
TRUEnever evaluated
FALSEevaluated 212303 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-212303
429 qWarning("QBuffer::writeData: Memory allocation error");-
430 return -1;
never executed: return -1;
0
431 }-
432 }
executed 212303 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
  • ...
212303
433-
434 memcpy(d->buf->data() + pos(), data, int(len));-
435-
436#ifndef QT_NO_QOBJECT-
437 d->writtenSinceLastEmit += len;-
438 if (d->signalConnectionCount && !d->signalsEmitted && !signalsBlocked()) {
d->signalConnectionCountDescription
TRUEevaluated 40 times by 1 test
Evaluated by:
  • tst_QBuffer
FALSEevaluated 220563 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-220563
439 d->signalsEmitted = true;-
440 QMetaObject::invokeMethod(this, "_q_emitSignals", Qt::QueuedConnection);-
441 }
executed 31 times by 1 test: end of block
Executed by:
  • tst_QBuffer
31
442#endif-
443 return len;
executed 220603 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
  • ...
220603
444}-
445-
446#ifndef QT_NO_QOBJECT-
447/*!-
448 \reimp-
449 \internal-
450*/-
451void QBuffer::connectNotify(const QMetaMethod &signal)-
452{-
453 static const QMetaMethod readyReadSignal = QMetaMethod::fromSignal(&QBuffer::readyRead);-
454 static const QMetaMethod bytesWrittenSignal = QMetaMethod::fromSignal(&QBuffer::bytesWritten);-
455 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
456 d_func()->signalConnectionCount++;
executed 44 times by 3 tests: d_func()->signalConnectionCount++;
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QBuffer
  • tst_QNetworkReply
44
457}
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
458-
459/*!-
460 \reimp-
461 \internal-
462*/-
463void QBuffer::disconnectNotify(const QMetaMethod &signal)-
464{-
465 if (signal.isValid()) {
signal.isValid()Description
TRUEevaluated 472 times by 3 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
  • tst_QTextStream
FALSEnever evaluated
0-472
466 static const QMetaMethod readyReadSignal = QMetaMethod::fromSignal(&QBuffer::readyRead);-
467 static const QMetaMethod bytesWrittenSignal = QMetaMethod::fromSignal(&QBuffer::bytesWritten);-
468 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
469 d_func()->signalConnectionCount--;
executed 9 times by 2 tests: d_func()->signalConnectionCount--;
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
9
470 } else {
executed 472 times by 3 tests: end of block
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
  • tst_QTextStream
472
471 d_func()->signalConnectionCount = 0;-
472 }
never executed: end of block
0
473}-
474#endif-
475-
476QT_END_NAMESPACE-
477-
478#ifndef QT_NO_QOBJECT-
479# include "moc_qbuffer.cpp"-
480#endif-
481-
Source codeSwitch to Preprocessed file

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