| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qbuffer.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 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 | - | |||||||||||||||||||
| 44 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 45 | - | |||||||||||||||||||
| 46 | /** QBufferPrivate **/ | - | ||||||||||||||||||
| 47 | class QBufferPrivate : public QIODevicePrivate | - | ||||||||||||||||||
| 48 | { | - | ||||||||||||||||||
| 49 | Q_DECLARE_PUBLIC(QBuffer) | - | ||||||||||||||||||
| 50 | - | |||||||||||||||||||
| 51 | public: | - | ||||||||||||||||||
| 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 blockExecuted by:
| 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 | - | ||||||||||||||||||
| 77 | void 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 blockExecuted by:
| 30 | ||||||||||||||||||
| 85 | #endif | - | ||||||||||||||||||
| 86 | - | |||||||||||||||||||
| 87 | qint64 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:
| 1423 | ||||||||||||||||||
| 92 | } | - | ||||||||||||||||||
| 93 | - | |||||||||||||||||||
| 94 | QByteArray QBufferPrivate::peek(qint64 maxSize) | - | ||||||||||||||||||
| 95 | { | - | ||||||||||||||||||
| 96 | qint64 readBytes = qMin(maxSize, static_cast<qint64>(buf->size()) - pos); | - | ||||||||||||||||||
| 97 | if (pos == 0 && maxSize >= buf->size())
| 42-115 | ||||||||||||||||||
| 98 | return *buf; executed 42 times by 3 tests: return *buf;Executed by:
| 42 | ||||||||||||||||||
| 99 | return QByteArray(buf->constData() + pos, readBytes); executed 173 times by 12 tests: return QByteArray(buf->constData() + pos, readBytes);Executed by:
| 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 | - | ||||||||||||||||||
| 152 | QBuffer::QBuffer() | - | ||||||||||||||||||
| 153 | : QIODevice(*new QBufferPrivate) | - | ||||||||||||||||||
| 154 | { | - | ||||||||||||||||||
| 155 | Q_D(QBuffer); | - | ||||||||||||||||||
| 156 | d->buf = &d->defaultBuf; | - | ||||||||||||||||||
| 157 | } | - | ||||||||||||||||||
| 158 | QBuffer::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 | */ | - | ||||||||||||||||||
| 173 | QBuffer::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 blockExecuted by:
| 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 | */ | - | ||||||||||||||||||
| 197 | QBuffer::QBuffer(QByteArray *byteArray, QObject *parent) | - | ||||||||||||||||||
| 198 | : QIODevice(*new QBufferPrivate, parent) | - | ||||||||||||||||||
| 199 | { | - | ||||||||||||||||||
| 200 | Q_D(QBuffer); | - | ||||||||||||||||||
| 201 | d->buf = byteArray ? byteArray : &d->defaultBuf;
| 0-9938 | ||||||||||||||||||
| 202 | d->defaultBuf.clear(); | - | ||||||||||||||||||
| 203 | } executed 9938 times by 64 tests: end of blockExecuted by:
| 9938 | ||||||||||||||||||
| 204 | #endif | - | ||||||||||||||||||
| 205 | - | |||||||||||||||||||
| 206 | /*! | - | ||||||||||||||||||
| 207 | Destroys the buffer. | - | ||||||||||||||||||
| 208 | */ | - | ||||||||||||||||||
| 209 | - | |||||||||||||||||||
| 210 | QBuffer::~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 | - | |||||||||||||||||||
| 236 | void QBuffer::setBuffer(QByteArray *byteArray) | - | ||||||||||||||||||
| 237 | { | - | ||||||||||||||||||
| 238 | Q_D(QBuffer); | - | ||||||||||||||||||
| 239 | if (isOpen()) {
| 0-9 | ||||||||||||||||||
| 240 | qWarning("QBuffer::setBuffer: Buffer is open"); | - | ||||||||||||||||||
| 241 | return; never executed: return; | 0 | ||||||||||||||||||
| 242 | } | - | ||||||||||||||||||
| 243 | if (byteArray) {
| 0-9 | ||||||||||||||||||
| 244 | d->buf = byteArray; | - | ||||||||||||||||||
| 245 | } else { executed 9 times by 1 test: end of blockExecuted by:
| 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 blockExecuted by:
| 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 | - | |||||||||||||||||||
| 258 | QByteArray &QBuffer::buffer() | - | ||||||||||||||||||
| 259 | { | - | ||||||||||||||||||
| 260 | Q_D(QBuffer); | - | ||||||||||||||||||
| 261 | return *d->buf; executed 492 times by 12 tests: return *d->buf;Executed by:
| 492 | ||||||||||||||||||
| 262 | } | - | ||||||||||||||||||
| 263 | - | |||||||||||||||||||
| 264 | /*! | - | ||||||||||||||||||
| 265 | \overload | - | ||||||||||||||||||
| 266 | - | |||||||||||||||||||
| 267 | This is the same as data(). | - | ||||||||||||||||||
| 268 | */ | - | ||||||||||||||||||
| 269 | - | |||||||||||||||||||
| 270 | const 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:
| 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 | - | |||||||||||||||||||
| 285 | const 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:
| 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 | */ | - | ||||||||||||||||||
| 299 | void QBuffer::setData(const QByteArray &data) | - | ||||||||||||||||||
| 300 | { | - | ||||||||||||||||||
| 301 | Q_D(QBuffer); | - | ||||||||||||||||||
| 302 | if (isOpen()) {
| 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 blockExecuted by:
| 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 | */ | - | ||||||||||||||||||
| 321 | bool QBuffer::open(OpenMode flags) | - | ||||||||||||||||||
| 322 | { | - | ||||||||||||||||||
| 323 | Q_D(QBuffer); | - | ||||||||||||||||||
| 324 | - | |||||||||||||||||||
| 325 | if ((flags & (Append | Truncate)) != 0)
| 78-11239 | ||||||||||||||||||
| 326 | flags |= WriteOnly; executed 78 times by 5 tests: flags |= WriteOnly;Executed by:
| 78 | ||||||||||||||||||
| 327 | if ((flags & (ReadOnly | WriteOnly)) == 0) {
| 3-11314 | ||||||||||||||||||
| 328 | qWarning("QBuffer::open: Buffer access not specified"); | - | ||||||||||||||||||
| 329 | return false; executed 3 times by 1 test: return false;Executed by:
| 3 | ||||||||||||||||||
| 330 | } | - | ||||||||||||||||||
| 331 | - | |||||||||||||||||||
| 332 | if ((flags & Truncate) == Truncate)
| 52-11262 | ||||||||||||||||||
| 333 | d->buf->resize(0); executed 52 times by 4 tests: d->buf->resize(0);Executed by:
| 52 | ||||||||||||||||||
| 334 | - | |||||||||||||||||||
| 335 | return QIODevice::open(flags | QIODevice::Unbuffered); executed 11314 times by 80 tests: return QIODevice::open(flags | QIODevice::Unbuffered);Executed by:
| 11314 | ||||||||||||||||||
| 336 | } | - | ||||||||||||||||||
| 337 | - | |||||||||||||||||||
| 338 | /*! | - | ||||||||||||||||||
| 339 | \reimp | - | ||||||||||||||||||
| 340 | */ | - | ||||||||||||||||||
| 341 | void QBuffer::close() | - | ||||||||||||||||||
| 342 | { | - | ||||||||||||||||||
| 343 | QIODevice::close(); | - | ||||||||||||||||||
| 344 | } executed 1836 times by 16 tests: end of blockExecuted by:
| 1836 | ||||||||||||||||||
| 345 | - | |||||||||||||||||||
| 346 | /*! | - | ||||||||||||||||||
| 347 | \reimp | - | ||||||||||||||||||
| 348 | */ | - | ||||||||||||||||||
| 349 | qint64 QBuffer::pos() const | - | ||||||||||||||||||
| 350 | { | - | ||||||||||||||||||
| 351 | return QIODevice::pos(); executed 9749910 times by 80 tests: return QIODevice::pos();Executed by:
| 9749910 | ||||||||||||||||||
| 352 | } | - | ||||||||||||||||||
| 353 | - | |||||||||||||||||||
| 354 | /*! | - | ||||||||||||||||||
| 355 | \reimp | - | ||||||||||||||||||
| 356 | */ | - | ||||||||||||||||||
| 357 | qint64 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:
| 25099 | ||||||||||||||||||
| 361 | } | - | ||||||||||||||||||
| 362 | - | |||||||||||||||||||
| 363 | /*! | - | ||||||||||||||||||
| 364 | \reimp | - | ||||||||||||||||||
| 365 | */ | - | ||||||||||||||||||
| 366 | bool QBuffer::seek(qint64 pos) | - | ||||||||||||||||||
| 367 | { | - | ||||||||||||||||||
| 368 | Q_D(QBuffer); | - | ||||||||||||||||||
| 369 | if (pos > d->buf->size() && isWritable()) {
| 0-45716 | ||||||||||||||||||
| 370 | if (seek(d->buf->size())) {
| 0-3 | ||||||||||||||||||
| 371 | const qint64 gapSize = pos - d->buf->size(); | - | ||||||||||||||||||
| 372 | if (write(QByteArray(gapSize, 0)) != gapSize) {
| 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 blockExecuted by:
| 3 | ||||||||||||||||||
| 377 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 378 | } | - | ||||||||||||||||||
| 379 | } else if (pos > d->buf->size() || pos < 0) {
| 0-45716 | ||||||||||||||||||
| 380 | qWarning("QBuffer::seek: Invalid pos: %d", int(pos)); | - | ||||||||||||||||||
| 381 | return false; executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||||||||
| 382 | } | - | ||||||||||||||||||
| 383 | return QIODevice::seek(pos); executed 45717 times by 29 tests: return QIODevice::seek(pos);Executed by:
| 45717 | ||||||||||||||||||
| 384 | } | - | ||||||||||||||||||
| 385 | - | |||||||||||||||||||
| 386 | /*! | - | ||||||||||||||||||
| 387 | \reimp | - | ||||||||||||||||||
| 388 | */ | - | ||||||||||||||||||
| 389 | bool QBuffer::atEnd() const | - | ||||||||||||||||||
| 390 | { | - | ||||||||||||||||||
| 391 | return QIODevice::atEnd(); executed 5890 times by 26 tests: return QIODevice::atEnd();Executed by:
| 5890 | ||||||||||||||||||
| 392 | } | - | ||||||||||||||||||
| 393 | - | |||||||||||||||||||
| 394 | /*! | - | ||||||||||||||||||
| 395 | \reimp | - | ||||||||||||||||||
| 396 | */ | - | ||||||||||||||||||
| 397 | bool QBuffer::canReadLine() const | - | ||||||||||||||||||
| 398 | { | - | ||||||||||||||||||
| 399 | Q_D(const QBuffer); | - | ||||||||||||||||||
| 400 | if (!isOpen())
| 4-59 | ||||||||||||||||||
| 401 | return false; executed 4 times by 1 test: return false;Executed by:
| 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:
| 59 | ||||||||||||||||||
| 404 | } | - | ||||||||||||||||||
| 405 | - | |||||||||||||||||||
| 406 | /*! | - | ||||||||||||||||||
| 407 | \reimp | - | ||||||||||||||||||
| 408 | */ | - | ||||||||||||||||||
| 409 | qint64 QBuffer::readData(char *data, qint64 len) | - | ||||||||||||||||||
| 410 | { | - | ||||||||||||||||||
| 411 | Q_D(QBuffer); | - | ||||||||||||||||||
| 412 | if ((len = qMin(len, qint64(d->buf->size()) - pos())) <= 0)
| 1473-4647285 | ||||||||||||||||||
| 413 | return qint64(0); executed 1473 times by 21 tests: return qint64(0);Executed by:
| 1473 | ||||||||||||||||||
| 414 | memcpy(data, d->buf->constData() + pos(), len); | - | ||||||||||||||||||
| 415 | return len; executed 4647285 times by 72 tests: return len;Executed by:
| 4647285 | ||||||||||||||||||
| 416 | } | - | ||||||||||||||||||
| 417 | - | |||||||||||||||||||
| 418 | /*! | - | ||||||||||||||||||
| 419 | \reimp | - | ||||||||||||||||||
| 420 | */ | - | ||||||||||||||||||
| 421 | qint64 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
| 8300-212303 | ||||||||||||||||||
| 426 | int newSize = d->buf->size() + extraBytes; | - | ||||||||||||||||||
| 427 | d->buf->resize(newSize); | - | ||||||||||||||||||
| 428 | if (d->buf->size() != newSize) { // could not resize
| 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 blockExecuted by:
| 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()) {
| 0-220563 | ||||||||||||||||||
| 439 | d->signalsEmitted = true; | - | ||||||||||||||||||
| 440 | QMetaObject::invokeMethod(this, "_q_emitSignals", Qt::QueuedConnection); | - | ||||||||||||||||||
| 441 | } executed 31 times by 1 test: end of blockExecuted by:
| 31 | ||||||||||||||||||
| 442 | #endif | - | ||||||||||||||||||
| 443 | return len; executed 220603 times by 69 tests: return len;Executed by:
| 220603 | ||||||||||||||||||
| 444 | } | - | ||||||||||||||||||
| 445 | - | |||||||||||||||||||
| 446 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||
| 447 | /*! | - | ||||||||||||||||||
| 448 | \reimp | - | ||||||||||||||||||
| 449 | \internal | - | ||||||||||||||||||
| 450 | */ | - | ||||||||||||||||||
| 451 | void 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)
| 4-1349 | ||||||||||||||||||
| 456 | d_func()->signalConnectionCount++; executed 44 times by 3 tests: d_func()->signalConnectionCount++;Executed by:
| 44 | ||||||||||||||||||
| 457 | } executed 1389 times by 11 tests: end of blockExecuted by:
| 1389 | ||||||||||||||||||
| 458 | - | |||||||||||||||||||
| 459 | /*! | - | ||||||||||||||||||
| 460 | \reimp | - | ||||||||||||||||||
| 461 | \internal | - | ||||||||||||||||||
| 462 | */ | - | ||||||||||||||||||
| 463 | void QBuffer::disconnectNotify(const QMetaMethod &signal) | - | ||||||||||||||||||
| 464 | { | - | ||||||||||||||||||
| 465 | if (signal.isValid()) {
| 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)
| 0-463 | ||||||||||||||||||
| 469 | d_func()->signalConnectionCount--; executed 9 times by 2 tests: d_func()->signalConnectionCount--;Executed by:
| 9 | ||||||||||||||||||
| 470 | } else { executed 472 times by 3 tests: end of blockExecuted by:
| 472 | ||||||||||||||||||
| 471 | d_func()->signalConnectionCount = 0; | - | ||||||||||||||||||
| 472 | } never executed: end of block | 0 | ||||||||||||||||||
| 473 | } | - | ||||||||||||||||||
| 474 | #endif | - | ||||||||||||||||||
| 475 | - | |||||||||||||||||||
| 476 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 477 | - | |||||||||||||||||||
| 478 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||
| 479 | # include "moc_qbuffer.cpp" | - | ||||||||||||||||||
| 480 | #endif | - | ||||||||||||||||||
| 481 | - | |||||||||||||||||||
| Source code | Switch to Preprocessed file |