json/qjsondocument.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3QJsonDocument::QJsonDocument() -
4 : d(0) -
5{ -
6}
executed: }
Execution Count:523
523
7 -
8 -
9 -
10 -
11QJsonDocument::QJsonDocument(const QJsonObject &object) -
12 : d(0) -
13{ -
14 setObject(object); -
15}
executed: }
Execution Count:10
10
16 -
17 -
18 -
19 -
20QJsonDocument::QJsonDocument(const QJsonArray &array) -
21 : d(0) -
22{ -
23 setArray(array); -
24}
executed: }
Execution Count:3
3
25 -
26 -
27 -
28 -
29QJsonDocument::QJsonDocument(QJsonPrivate::Data *data) -
30 : d(data) -
31{ -
32 qt_noop(); -
33 d->ref.ref(); -
34}
executed: }
Execution Count:1464
1464
35 -
36 -
37 -
38 -
39 -
40 -
41QJsonDocument::~QJsonDocument() -
42{ -
43 if (d && !d->ref.deref())
evaluated: d
TRUEFALSE
yes
Evaluation Count:1469
yes
Evaluation Count:538
evaluated: !d->ref.deref()
TRUEFALSE
yes
Evaluation Count:1018
yes
Evaluation Count:451
451-1469
44 delete d;
executed: delete d;
Execution Count:1018
1018
45}
executed: }
Execution Count:2007
2007
46 -
47 -
48 -
49 -
50QJsonDocument::QJsonDocument(const QJsonDocument &other) -
51{ -
52 d = other.d; -
53 if (d)
partially evaluated: d
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7
0-7
54 d->ref.ref();
never executed: d->ref.ref();
0
55}
executed: }
Execution Count:7
7
56 -
57 -
58 -
59 -
60 -
61QJsonDocument &QJsonDocument::operator =(const QJsonDocument &other) -
62{ -
63 if (d != other.d) {
evaluated: d != other.d
TRUEFALSE
yes
Evaluation Count:225
yes
Evaluation Count:1
1-225
64 if (d && !d->ref.deref())
evaluated: d
TRUEFALSE
yes
Evaluation Count:223
yes
Evaluation Count:2
evaluated: !d->ref.deref()
TRUEFALSE
yes
Evaluation Count:222
yes
Evaluation Count:1
1-223
65 delete d;
executed: delete d;
Execution Count:222
222
66 d = other.d; -
67 if (d)
evaluated: d
TRUEFALSE
yes
Evaluation Count:209
yes
Evaluation Count:16
16-209
68 d->ref.ref();
executed: d->ref.ref();
Execution Count:209
209
69 }
executed: }
Execution Count:225
225
70 -
71 return *this;
executed: return *this;
Execution Count:226
226
72} -
73QJsonDocument QJsonDocument::fromRawData(const char *data, int size, DataValidation validation) -
74{ -
75 if (quintptr(data) & 3) {
never evaluated: quintptr(data) & 3
0
76 QMessageLogger("json/qjsondocument.cpp", 186, __PRETTY_FUNCTION__).warning() <<"QJsonDocument::fromRawData: data has to have 4 byte alignment"; -
77 return QJsonDocument();
never executed: return QJsonDocument();
0
78 } -
79 -
80 QJsonPrivate::Data *d = new QJsonPrivate::Data((char *)data, size); -
81 d->ownsData = false; -
82 -
83 if (validation != BypassValidation && !d->valid()) {
never evaluated: validation != BypassValidation
never evaluated: !d->valid()
0
84 delete d; -
85 return QJsonDocument();
never executed: return QJsonDocument();
0
86 } -
87 -
88 return QJsonDocument(d);
never executed: return QJsonDocument(d);
0
89} -
90const char *QJsonDocument::rawData(int *size) const -
91{ -
92 if (!d) {
never evaluated: !d
0
93 *size = 0; -
94 return 0;
never executed: return 0;
0
95 } -
96 *size = d->alloc; -
97 return d->rawData;
never executed: return d->rawData;
0
98} -
99QJsonDocument QJsonDocument::fromBinaryData(const QByteArray &data, DataValidation validation) -
100{ -
101 if (data.size() < (int)(sizeof(QJsonPrivate::Header) + sizeof(QJsonPrivate::Base)))
partially evaluated: data.size() < (int)(sizeof(QJsonPrivate::Header) + sizeof(QJsonPrivate::Base))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1881
0-1881
102 return QJsonDocument();
never executed: return QJsonDocument();
0
103 -
104 QJsonPrivate::Header h; -
105 memcpy(&h, data.constData(), sizeof(QJsonPrivate::Header)); -
106 QJsonPrivate::Base root; -
107 memcpy(&root, data.constData() + sizeof(QJsonPrivate::Header), sizeof(QJsonPrivate::Base)); -
108 -
109 -
110 if (h.tag != QJsonDocument::BinaryFormatTag || h.version != 1u ||
evaluated: h.tag != QJsonDocument::BinaryFormatTag
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:1873
evaluated: h.version != 1u
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:1865
8-1873
111 sizeof(QJsonPrivate::Header) + root.size > (uint)data.size())
evaluated: sizeof(QJsonPrivate::Header) + root.size > (uint)data.size()
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:1857
8-1857
112 return QJsonDocument();
executed: return QJsonDocument();
Execution Count:24
24
113 -
114 const uint size = sizeof(QJsonPrivate::Header) + root.size; -
115 char *raw = (char *)malloc(size); -
116 if (!raw)
partially evaluated: !raw
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1857
0-1857
117 return QJsonDocument();
never executed: return QJsonDocument();
0
118 -
119 memcpy(raw, data.constData(), size); -
120 QJsonPrivate::Data *d = new QJsonPrivate::Data(raw, size); -
121 -
122 if (validation != BypassValidation && !d->valid()) {
partially evaluated: validation != BypassValidation
TRUEFALSE
yes
Evaluation Count:1857
no
Evaluation Count:0
evaluated: !d->valid()
TRUEFALSE
yes
Evaluation Count:455
yes
Evaluation Count:1402
0-1857
123 delete d; -
124 return QJsonDocument();
executed: return QJsonDocument();
Execution Count:455
455
125 } -
126 -
127 return QJsonDocument(d);
executed: return QJsonDocument(d);
Execution Count:1402
1402
128} -
129QJsonDocument QJsonDocument::fromVariant(const QVariant &variant) -
130{ -
131 QJsonDocument doc; -
132 if (variant.type() == QVariant::Map) {
never evaluated: variant.type() == QVariant::Map
0
133 doc.setObject(QJsonObject::fromVariantMap(variant.toMap())); -
134 } else if (variant.type() == QVariant::List) {
never executed: }
never evaluated: variant.type() == QVariant::List
0
135 doc.setArray(QJsonArray::fromVariantList(variant.toList())); -
136 } else if (variant.type() == QVariant::StringList) {
never executed: }
never evaluated: variant.type() == QVariant::StringList
0
137 doc.setArray(QJsonArray::fromStringList(variant.toStringList())); -
138 }
never executed: }
0
139 return doc;
never executed: return doc;
0
140} -
141QVariant QJsonDocument::toVariant() const -
142{ -
143 if (!d)
partially evaluated: !d
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
144 return QVariant();
never executed: return QVariant();
0
145 -
146 if (d->header->root()->isArray())
partially evaluated: d->header->root()->isArray()
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
147 return QJsonArray(d, static_cast<QJsonPrivate::Array *>(d->header->root())).toVariantList();
executed: return QJsonArray(d, static_cast<QJsonPrivate::Array *>(d->header->root())).toVariantList();
Execution Count:2
2
148 else -
149 return QJsonObject(d, static_cast<QJsonPrivate::Object *>(d->header->root())).toVariantMap();
never executed: return QJsonObject(d, static_cast<QJsonPrivate::Object *>(d->header->root())).toVariantMap();
0
150} -
151 -
152 -
153 -
154 -
155 -
156 -
157QByteArray QJsonDocument::toJson() const -
158{ -
159 if (!d)
partially evaluated: !d
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1184
0-1184
160 return QByteArray();
never executed: return QByteArray();
0
161 -
162 QByteArray json; -
163 -
164 if (d->header->root()->isArray())
evaluated: d->header->root()->isArray()
TRUEFALSE
yes
Evaluation Count:753
yes
Evaluation Count:431
431-753
165 QJsonPrivate::Writer::arrayToJson(static_cast<QJsonPrivate::Array *>(d->header->root()), json, 0);
executed: QJsonPrivate::Writer::arrayToJson(static_cast<QJsonPrivate::Array *>(d->header->root()), json, 0);
Execution Count:753
753
166 else -
167 QJsonPrivate::Writer::objectToJson(static_cast<QJsonPrivate::Object *>(d->header->root()), json, 0);
executed: QJsonPrivate::Writer::objectToJson(static_cast<QJsonPrivate::Object *>(d->header->root()), json, 0);
Execution Count:431
431
168 -
169 return json;
executed: return json;
Execution Count:1184
1184
170} -
171QJsonDocument QJsonDocument::fromJson(const QByteArray &json, QJsonParseError *error) -
172{ -
173 QJsonPrivate::Parser parser(json.constData(), json.length()); -
174 return parser.parse(error);
executed: return parser.parse(error);
Execution Count:88
88
175} -
176 -
177 -
178 -
179 -
180bool QJsonDocument::isEmpty() const -
181{ -
182 if (!d)
evaluated: !d
TRUEFALSE
yes
Evaluation Count:22
yes
Evaluation Count:51
22-51
183 return true;
executed: return true;
Execution Count:22
22
184 -
185 return false;
executed: return false;
Execution Count:51
51
186} -
187QByteArray QJsonDocument::toBinaryData() const -
188{ -
189 if (!d || !d->rawData)
partially evaluated: !d
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:25
partially evaluated: !d->rawData
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:25
0-25
190 return QByteArray();
never executed: return QByteArray();
0
191 -
192 return QByteArray(d->rawData, d->header->root()->size + sizeof(QJsonPrivate::Header));
executed: return QByteArray(d->rawData, d->header->root()->size + sizeof(QJsonPrivate::Header));
Execution Count:25
25
193} -
194 -
195 -
196 -
197 -
198 -
199 -
200bool QJsonDocument::isArray() const -
201{ -
202 if (!d)
evaluated: !d
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:54
2-54
203 return false;
executed: return false;
Execution Count:2
2
204 -
205 QJsonPrivate::Header *h = (QJsonPrivate::Header *)d->rawData; -
206 return h->root()->isArray();
executed: return h->root()->isArray();
Execution Count:54
54
207} -
208 -
209 -
210 -
211 -
212 -
213 -
214bool QJsonDocument::isObject() const -
215{ -
216 if (!d)
evaluated: !d
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:55
2-55
217 return false;
executed: return false;
Execution Count:2
2
218 -
219 QJsonPrivate::Header *h = (QJsonPrivate::Header *)d->rawData; -
220 return h->root()->isObject();
executed: return h->root()->isObject();
Execution Count:55
55
221} -
222QJsonObject QJsonDocument::object() const -
223{ -
224 if (d) {
partially evaluated: d
TRUEFALSE
yes
Evaluation Count:251
no
Evaluation Count:0
0-251
225 QJsonPrivate::Base *b = d->header->root(); -
226 if (b->isObject())
evaluated: b->isObject()
TRUEFALSE
yes
Evaluation Count:250
yes
Evaluation Count:1
1-250
227 return QJsonObject(d, static_cast<QJsonPrivate::Object *>(b));
executed: return QJsonObject(d, static_cast<QJsonPrivate::Object *>(b));
Execution Count:250
250
228 }
executed: }
Execution Count:1
1
229 return QJsonObject();
executed: return QJsonObject();
Execution Count:1
1
230} -
231QJsonArray QJsonDocument::array() const -
232{ -
233 if (d) {
partially evaluated: d
TRUEFALSE
yes
Evaluation Count:54
no
Evaluation Count:0
0-54
234 QJsonPrivate::Base *b = d->header->root(); -
235 if (b->isArray())
evaluated: b->isArray()
TRUEFALSE
yes
Evaluation Count:53
yes
Evaluation Count:1
1-53
236 return QJsonArray(d, static_cast<QJsonPrivate::Array *>(b));
executed: return QJsonArray(d, static_cast<QJsonPrivate::Array *>(b));
Execution Count:53
53
237 }
executed: }
Execution Count:1
1
238 return QJsonArray();
executed: return QJsonArray();
Execution Count:1
1
239} -
240 -
241 -
242 -
243 -
244 -
245 -
246void QJsonDocument::setObject(const QJsonObject &object) -
247{ -
248 if (d && !d->ref.deref())
evaluated: d
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:14
partially evaluated: !d->ref.deref()
TRUEFALSE
yes
Evaluation Count:4
no
Evaluation Count:0
0-14
249 delete d;
executed: delete d;
Execution Count:4
4
250 -
251 d = object.d; -
252 -
253 if (!d) {
evaluated: !d
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:17
1-17
254 d = new QJsonPrivate::Data(0, QJsonValue::Object); -
255 } else if (d->compactionCounter || object.o != d->header->root()) {
evaluated: d->compactionCounter
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:12
evaluated: object.o != d->header->root()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:9
executed: }
Execution Count:1
1-12
256 QJsonObject o(object); -
257 if (d->compactionCounter)
evaluated: d->compactionCounter
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:3
3-5
258 o.compact();
executed: o.compact();
Execution Count:5
5
259 else -
260 o.detach();
executed: o.detach();
Execution Count:3
3
261 d = o.d; -
262 d->ref.ref(); -
263 return;
executed: return;
Execution Count:8
8
264 } -
265 d->ref.ref(); -
266}
executed: }
Execution Count:10
10
267 -
268 -
269 -
270 -
271 -
272 -
273void QJsonDocument::setArray(const QJsonArray &array) -
274{ -
275 if (d && !d->ref.deref())
evaluated: d
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:5
evaluated: !d->ref.deref()
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:2
2-6
276 delete d;
executed: delete d;
Execution Count:4
4
277 -
278 d = array.d; -
279 -
280 if (!d) {
evaluated: !d
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:10
1-10
281 d = new QJsonPrivate::Data(0, QJsonValue::Array); -
282 } else if (d->compactionCounter || array.a != d->header->root()) {
evaluated: d->compactionCounter
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:7
evaluated: array.a != d->header->root()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:4
executed: }
Execution Count:1
1-7
283 QJsonArray a(array); -
284 if (d->compactionCounter)
evaluated: d->compactionCounter
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:3
3
285 a.compact();
executed: a.compact();
Execution Count:3
3
286 else -
287 a.detach();
executed: a.detach();
Execution Count:3
3
288 d = a.d; -
289 d->ref.ref(); -
290 return;
executed: return;
Execution Count:6
6
291 } -
292 d->ref.ref(); -
293}
executed: }
Execution Count:5
5
294 -
295 -
296 -
297 -
298bool QJsonDocument::operator==(const QJsonDocument &other) const -
299{ -
300 if (d == other.d)
evaluated: d == other.d
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:6
6-8
301 return true;
executed: return true;
Execution Count:8
8
302 -
303 if (!d || !other.d)
partially evaluated: !d
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
partially evaluated: !other.d
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
304 return false;
never executed: return false;
0
305 -
306 if (d->header->root()->isArray() != other.d->header->root()->isArray())
partially evaluated: d->header->root()->isArray() != other.d->header->root()->isArray()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
307 return false;
never executed: return false;
0
308 -
309 if (d->header->root()->isObject())
evaluated: d->header->root()->isObject()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:4
2-4
310 return QJsonObject(d, static_cast<QJsonPrivate::Object *>(d->header->root())) 2
311 == QJsonObject(other.d, static_cast<QJsonPrivate::Object *>(other.d->header->root()));
executed: return QJsonObject(d, static_cast<QJsonPrivate::Object *>(d->header->root())) == QJsonObject(other.d, static_cast<QJsonPrivate::Object *>(other.d->header->root()));
Execution Count:2
2
312 else -
313 return QJsonArray(d, static_cast<QJsonPrivate::Array *>(d->header->root())) 4
314 == QJsonArray(other.d, static_cast<QJsonPrivate::Array *>(other.d->header->root()));
executed: return QJsonArray(d, static_cast<QJsonPrivate::Array *>(d->header->root())) == QJsonArray(other.d, static_cast<QJsonPrivate::Array *>(other.d->header->root()));
Execution Count:4
4
315} -
316bool QJsonDocument::isNull() const -
317{ -
318 return (d == 0);
executed: return (d == 0);
Execution Count:1884
1884
319} -
320 -
321 -
322QDebug operator<<(QDebug dbg, const QJsonDocument &o) -
323{ -
324 if (!o.d) {
evaluated: !o.d
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
2
325 dbg << "QJsonDocument()"; -
326 return dbg;
executed: return dbg;
Execution Count:2
2
327 } -
328 QByteArray json; -
329 if (o.d->header->root()->isArray())
evaluated: o.d->header->root()->isArray()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
330 QJsonPrivate::Writer::arrayToJson(static_cast<QJsonPrivate::Array *>(o.d->header->root()), json, 0, true);
executed: QJsonPrivate::Writer::arrayToJson(static_cast<QJsonPrivate::Array *>(o.d->header->root()), json, 0, true);
Execution Count:1
1
331 else -
332 QJsonPrivate::Writer::objectToJson(static_cast<QJsonPrivate::Object *>(o.d->header->root()), json, 0, true);
executed: QJsonPrivate::Writer::objectToJson(static_cast<QJsonPrivate::Object *>(o.d->header->root()), json, 0, true);
Execution Count:1
1
333 dbg.nospace() << "QJsonDocument(" -
334 << json.constData() -
335 << ")"; -
336 return dbg.space();
executed: return dbg.space();
Execution Count:2
2
337} -
338 -
339 -
340 -
341 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial