Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | class QBufferPrivate : public QIODevicePrivate | - |
6 | { | - |
7 | inline QBuffer* q_func() { return static_cast<QBuffer *>(q_ptr); } inline const QBuffer* q_func() const { return static_cast<const QBuffer *>(q_ptr); } friend class QBuffer; | - |
8 | | - |
9 | public: | - |
10 | QBufferPrivate() | - |
11 | : buf(0) | - |
12 | | - |
13 | , writtenSinceLastEmit(0), signalConnectionCount(0), signalsEmitted(false) | - |
14 | | - |
15 | { } executed: } Execution Count:6999 | 6999 |
16 | ~QBufferPrivate() { } | - |
17 | | - |
18 | QByteArray *buf; | - |
19 | QByteArray defaultBuf; | - |
20 | int ioIndex; | - |
21 | | - |
22 | virtual qint64 peek(char *data, qint64 maxSize); | - |
23 | virtual QByteArray peek(qint64 maxSize); | - |
24 | | - |
25 | | - |
26 | | - |
27 | void _q_emitSignals(); | - |
28 | | - |
29 | qint64 writtenSinceLastEmit; | - |
30 | int signalConnectionCount; | - |
31 | bool signalsEmitted; | - |
32 | | - |
33 | }; | - |
34 | | - |
35 | | - |
36 | void QBufferPrivate::_q_emitSignals() | - |
37 | { | - |
38 | QBuffer * const q = q_func(); | - |
39 | q->bytesWritten(writtenSinceLastEmit); | - |
40 | writtenSinceLastEmit = 0; | - |
41 | q->readyRead(); | - |
42 | signalsEmitted = false; | - |
43 | } executed: } Execution Count:30 | 30 |
44 | | - |
45 | | - |
46 | qint64 QBufferPrivate::peek(char *data, qint64 maxSize) | - |
47 | { | - |
48 | qint64 readBytes = qMin(maxSize, static_cast<qint64>(buf->size()) - pos); | - |
49 | memcpy(data, buf->constData() + pos, readBytes); | - |
50 | return readBytes; executed: return readBytes; Execution Count:1342 | 1342 |
51 | } | - |
52 | | - |
53 | QByteArray QBufferPrivate::peek(qint64 maxSize) | - |
54 | { | - |
55 | qint64 readBytes = qMin(maxSize, static_cast<qint64>(buf->size()) - pos); | - |
56 | if (pos == 0 && maxSize >= buf->size()) evaluated: pos == 0 yes Evaluation Count:88 | yes Evaluation Count:96 |
evaluated: maxSize >= buf->size() yes Evaluation Count:21 | yes Evaluation Count:67 |
| 21-96 |
57 | return *buf; executed: return *buf; Execution Count:21 | 21 |
58 | return QByteArray(buf->constData() + pos, readBytes); executed: return QByteArray(buf->constData() + pos, readBytes); Execution Count:163 | 163 |
59 | } | - |
60 | QBuffer::QBuffer(QObject *parent) | - |
61 | : QIODevice(*new QBufferPrivate, parent) | - |
62 | { | - |
63 | QBufferPrivate * const d = d_func(); | - |
64 | d->buf = &d->defaultBuf; | - |
65 | d->ioIndex = 0; | - |
66 | } executed: } Execution Count:822 | 822 |
67 | QBuffer::QBuffer(QByteArray *byteArray, QObject *parent) | - |
68 | : QIODevice(*new QBufferPrivate, parent) | - |
69 | { | - |
70 | QBufferPrivate * const d = d_func(); | - |
71 | d->buf = byteArray ? byteArray : &d->defaultBuf; partially evaluated: byteArray yes Evaluation Count:6177 | no Evaluation Count:0 |
| 0-6177 |
72 | d->defaultBuf.clear(); | - |
73 | d->ioIndex = 0; | - |
74 | } executed: } Execution Count:6177 | 6177 |
75 | | - |
76 | | - |
77 | | - |
78 | | - |
79 | | - |
80 | | - |
81 | QBuffer::~QBuffer() | - |
82 | { | - |
83 | } | - |
84 | void QBuffer::setBuffer(QByteArray *byteArray) | - |
85 | { | - |
86 | QBufferPrivate * const d = d_func(); | - |
87 | if (isOpen()) { partially evaluated: isOpen() no Evaluation Count:0 | yes Evaluation Count:9 |
| 0-9 |
88 | QMessageLogger("io/qbuffer.cpp", 247, __PRETTY_FUNCTION__).warning("QBuffer::setBuffer: Buffer is open"); | - |
89 | return; | 0 |
90 | } | - |
91 | if (byteArray) { partially evaluated: byteArray yes Evaluation Count:9 | no Evaluation Count:0 |
| 0-9 |
92 | d->buf = byteArray; | - |
93 | } else { executed: } Execution Count:9 | 9 |
94 | d->buf = &d->defaultBuf; | - |
95 | } | 0 |
96 | d->defaultBuf.clear(); | - |
97 | d->ioIndex = 0; | - |
98 | } executed: } Execution Count:9 | 9 |
99 | QByteArray &QBuffer::buffer() | - |
100 | { | - |
101 | QBufferPrivate * const d = d_func(); | - |
102 | return *d->buf; executed: return *d->buf; Execution Count:180 | 180 |
103 | } | - |
104 | | - |
105 | | - |
106 | | - |
107 | | - |
108 | | - |
109 | | - |
110 | | - |
111 | const QByteArray &QBuffer::buffer() const | - |
112 | { | - |
113 | const QBufferPrivate * const d = d_func(); | - |
114 | return *d->buf; executed: return *d->buf; Execution Count:15 | 15 |
115 | } | - |
116 | const QByteArray &QBuffer::data() const | - |
117 | { | - |
118 | const QBufferPrivate * const d = d_func(); | - |
119 | return *d->buf; executed: return *d->buf; Execution Count:24791 | 24791 |
120 | } | - |
121 | void QBuffer::setData(const QByteArray &data) | - |
122 | { | - |
123 | QBufferPrivate * const d = d_func(); | - |
124 | if (isOpen()) { partially evaluated: isOpen() no Evaluation Count:0 | yes Evaluation Count:333 |
| 0-333 |
125 | QMessageLogger("io/qbuffer.cpp", 311, __PRETTY_FUNCTION__).warning("QBuffer::setData: Buffer is open"); | - |
126 | return; | 0 |
127 | } | - |
128 | *d->buf = data; | - |
129 | d->ioIndex = 0; | - |
130 | } executed: } Execution Count:333 | 333 |
131 | bool QBuffer::open(OpenMode flags) | - |
132 | { | - |
133 | QBufferPrivate * const d = d_func(); | - |
134 | | - |
135 | if ((flags & (Append | Truncate)) != 0) evaluated: (flags & (Append | Truncate)) != 0 yes Evaluation Count:57 | yes Evaluation Count:6864 |
| 57-6864 |
136 | flags |= WriteOnly; executed: flags |= WriteOnly; Execution Count:57 | 57 |
137 | if ((flags & (ReadOnly | WriteOnly)) == 0) { evaluated: (flags & (ReadOnly | WriteOnly)) == 0 yes Evaluation Count:3 | yes Evaluation Count:6918 |
| 3-6918 |
138 | QMessageLogger("io/qbuffer.cpp", 337, __PRETTY_FUNCTION__).warning("QBuffer::open: Buffer access not specified"); | - |
139 | return false; executed: return false; Execution Count:3 | 3 |
140 | } | - |
141 | | - |
142 | if ((flags & Truncate) == Truncate) evaluated: (flags & Truncate) == Truncate yes Evaluation Count:31 | yes Evaluation Count:6887 |
| 31-6887 |
143 | d->buf->resize(0); executed: d->buf->resize(0); Execution Count:31 | 31 |
144 | d->ioIndex = (flags & Append) == Append ? d->buf->size() : 0; evaluated: (flags & Append) == Append yes Evaluation Count:26 | yes Evaluation Count:6892 |
| 26-6892 |
145 | | - |
146 | return QIODevice::open(flags); executed: return QIODevice::open(flags); Execution Count:6918 | 6918 |
147 | } | - |
148 | | - |
149 | | - |
150 | | - |
151 | | - |
152 | void QBuffer::close() | - |
153 | { | - |
154 | QIODevice::close(); | - |
155 | } executed: } Execution Count:1583 | 1583 |
156 | | - |
157 | | - |
158 | | - |
159 | | - |
160 | qint64 QBuffer::pos() const | - |
161 | { | - |
162 | return QIODevice::pos(); executed: return QIODevice::pos(); Execution Count:18561 | 18561 |
163 | } | - |
164 | | - |
165 | | - |
166 | | - |
167 | | - |
168 | qint64 QBuffer::size() const | - |
169 | { | - |
170 | const QBufferPrivate * const d = d_func(); | - |
171 | return qint64(d->buf->size()); executed: return qint64(d->buf->size()); Execution Count:20647 | 20647 |
172 | } | - |
173 | | - |
174 | | - |
175 | | - |
176 | | - |
177 | bool QBuffer::seek(qint64 pos) | - |
178 | { | - |
179 | QBufferPrivate * const d = d_func(); | - |
180 | if (pos > d->buf->size() && isWritable()) { evaluated: pos > d->buf->size() yes Evaluation Count:3 | yes Evaluation Count:42322 |
partially evaluated: isWritable() yes Evaluation Count:3 | no Evaluation Count:0 |
| 0-42322 |
181 | if (seek(d->buf->size())) { partially evaluated: seek(d->buf->size()) yes Evaluation Count:3 | no Evaluation Count:0 |
| 0-3 |
182 | const qint64 gapSize = pos - d->buf->size(); | - |
183 | if (write(QByteArray(gapSize, 0)) != gapSize) { partially evaluated: write(QByteArray(gapSize, 0)) != gapSize no Evaluation Count:0 | yes Evaluation Count:3 |
| 0-3 |
184 | QMessageLogger("io/qbuffer.cpp", 383, __PRETTY_FUNCTION__).warning("QBuffer::seek: Unable to fill gap"); | - |
185 | return false; never executed: return false; | 0 |
186 | } | - |
187 | } else { executed: } Execution Count:3 | 3 |
188 | return false; never executed: return false; | 0 |
189 | } | - |
190 | } else if (pos > d->buf->size() || pos < 0) { partially evaluated: pos > d->buf->size() no Evaluation Count:0 | yes Evaluation Count:42322 |
evaluated: pos < 0 yes Evaluation Count:2 | yes Evaluation Count:42320 |
| 0-42322 |
191 | QMessageLogger("io/qbuffer.cpp", 390, __PRETTY_FUNCTION__).warning("QBuffer::seek: Invalid pos: %d", int(pos)); | - |
192 | return false; executed: return false; Execution Count:2 | 2 |
193 | } | - |
194 | d->ioIndex = int(pos); | - |
195 | return QIODevice::seek(pos); executed: return QIODevice::seek(pos); Execution Count:42323 | 42323 |
196 | } | - |
197 | | - |
198 | | - |
199 | | - |
200 | | - |
201 | bool QBuffer::atEnd() const | - |
202 | { | - |
203 | return QIODevice::atEnd(); executed: return QIODevice::atEnd(); Execution Count:5154 | 5154 |
204 | } | - |
205 | | - |
206 | | - |
207 | | - |
208 | | - |
209 | bool QBuffer::canReadLine() const | - |
210 | { | - |
211 | const QBufferPrivate * const d = d_func(); | - |
212 | if (!isOpen()) evaluated: !isOpen() yes Evaluation Count:4 | yes Evaluation Count:59 |
| 4-59 |
213 | return false; executed: return false; Execution Count:4 | 4 |
214 | | - |
215 | return d->buf->indexOf('\n', int(pos())) != -1 || QIODevice::canReadLine(); executed: return d->buf->indexOf('\n', int(pos())) != -1 || QIODevice::canReadLine(); Execution Count:59 | 59 |
216 | } | - |
217 | | - |
218 | | - |
219 | | - |
220 | | - |
221 | qint64 QBuffer::readData(char *data, qint64 len) | - |
222 | { | - |
223 | QBufferPrivate * const d = d_func(); | - |
224 | if ((len = qMin(len, qint64(d->buf->size()) - d->ioIndex)) <= 0) evaluated: (len = qMin(len, qint64(d->buf->size()) - d->ioIndex)) <= 0 yes Evaluation Count:7578 | yes Evaluation Count:21505 |
| 7578-21505 |
225 | return qint64(0); executed: return qint64(0); Execution Count:7578 | 7578 |
226 | memcpy(data, d->buf->constData() + d->ioIndex, len); | - |
227 | d->ioIndex += int(len); | - |
228 | return len; executed: return len; Execution Count:21505 | 21505 |
229 | } | - |
230 | | - |
231 | | - |
232 | | - |
233 | | - |
234 | qint64 QBuffer::writeData(const char *data, qint64 len) | - |
235 | { | - |
236 | QBufferPrivate * const d = d_func(); | - |
237 | int extraBytes = d->ioIndex + len - d->buf->size(); | - |
238 | if (extraBytes > 0) { evaluated: extraBytes > 0 yes Evaluation Count:145516 | yes Evaluation Count:5433 |
| 5433-145516 |
239 | int newSize = d->buf->size() + extraBytes; | - |
240 | d->buf->resize(newSize); | - |
241 | if (d->buf->size() != newSize) { partially evaluated: d->buf->size() != newSize no Evaluation Count:0 | yes Evaluation Count:145516 |
| 0-145516 |
242 | QMessageLogger("io/qbuffer.cpp", 441, __PRETTY_FUNCTION__).warning("QBuffer::writeData: Memory allocation error"); | - |
243 | return -1; never executed: return -1; | 0 |
244 | } | - |
245 | } executed: } Execution Count:145516 | 145516 |
246 | | - |
247 | memcpy(d->buf->data() + d->ioIndex, (uchar *)data, int(len)); | - |
248 | d->ioIndex += int(len); | - |
249 | | - |
250 | | - |
251 | d->writtenSinceLastEmit += len; | - |
252 | if (d->signalConnectionCount && !d->signalsEmitted && !signalsBlocked()) { evaluated: d->signalConnectionCount yes Evaluation Count:40 | yes Evaluation Count:150909 |
evaluated: !d->signalsEmitted yes Evaluation Count:31 | yes Evaluation Count:9 |
partially evaluated: !signalsBlocked() yes Evaluation Count:31 | no Evaluation Count:0 |
| 0-150909 |
253 | d->signalsEmitted = true; | - |
254 | QMetaObject::invokeMethod(this, "_q_emitSignals", Qt::QueuedConnection); | - |
255 | } executed: } Execution Count:31 | 31 |
256 | | - |
257 | return len; executed: return len; Execution Count:150949 | 150949 |
258 | } | - |
259 | | - |
260 | | - |
261 | | - |
262 | | - |
263 | | - |
264 | | - |
265 | void QBuffer::connectNotify(const QMetaMethod &signal) | - |
266 | { | - |
267 | static const QMetaMethod readyReadSignal = QMetaMethod::fromSignal(&QBuffer::readyRead); | - |
268 | static const QMetaMethod bytesWrittenSignal = QMetaMethod::fromSignal(&QBuffer::bytesWritten); | - |
269 | if (signal == readyReadSignal || signal == bytesWrittenSignal) evaluated: signal == readyReadSignal yes Evaluation Count:38 | yes Evaluation Count:1129 |
evaluated: signal == bytesWrittenSignal yes Evaluation Count:4 | yes Evaluation Count:1125 |
| 4-1129 |
270 | d_func()->signalConnectionCount++; executed: d_func()->signalConnectionCount++; Execution Count:42 | 42 |
271 | } executed: } Execution Count:1167 | 1167 |
272 | | - |
273 | | - |
274 | | - |
275 | | - |
276 | | - |
277 | void QBuffer::disconnectNotify(const QMetaMethod &signal) | - |
278 | { | - |
279 | if (signal.isValid()) { partially evaluated: signal.isValid() yes Evaluation Count:532 | no Evaluation Count:0 |
| 0-532 |
280 | static const QMetaMethod readyReadSignal = QMetaMethod::fromSignal(&QBuffer::readyRead); | - |
281 | static const QMetaMethod bytesWrittenSignal = QMetaMethod::fromSignal(&QBuffer::bytesWritten); | - |
282 | if (signal == readyReadSignal || signal == bytesWrittenSignal) evaluated: signal == readyReadSignal yes Evaluation Count:9 | yes Evaluation Count:523 |
partially evaluated: signal == bytesWrittenSignal no Evaluation Count:0 | yes Evaluation Count:523 |
| 0-523 |
283 | d_func()->signalConnectionCount--; executed: d_func()->signalConnectionCount--; Execution Count:9 | 9 |
284 | } else { executed: } Execution Count:532 | 532 |
285 | d_func()->signalConnectionCount = 0; | - |
286 | } | 0 |
287 | } | - |
288 | | - |
289 | | - |
290 | | - |
291 | | - |
292 | | - |
293 | | - |
| | |