Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/dbus/qdbusdemarshaller.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 QtDBus 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 "qdbusargument_p.h" | - | ||||||
41 | #include "qdbusconnection.h" | - | ||||||
42 | - | |||||||
43 | #include <qscopedpointer.h> | - | ||||||
44 | - | |||||||
45 | #include <stdlib.h> | - | ||||||
46 | - | |||||||
47 | QT_BEGIN_NAMESPACE | - | ||||||
48 | - | |||||||
49 | template <typename T> | - | ||||||
50 | static inline T qIterGet(DBusMessageIter *it) | - | ||||||
51 | { | - | ||||||
52 | // Use a union of expected and largest type q_dbus_message_iter_get_basic | - | ||||||
53 | // will return to ensure reading the wrong basic type does not result in | - | ||||||
54 | // stack overwrite | - | ||||||
55 | union { | - | ||||||
56 | // The value to be extracted | - | ||||||
57 | T t; | - | ||||||
58 | // Largest type that q_dbus_message_iter_get_basic will return | - | ||||||
59 | // according to dbus_message_iter_get_basic API documentation | - | ||||||
60 | dbus_uint64_t maxValue; | - | ||||||
61 | // A pointer to ensure no stack overwrite in case there is a platform | - | ||||||
62 | // where sizeof(void*) > sizeof(dbus_uint64_t) | - | ||||||
63 | void* ptr; | - | ||||||
64 | } value; | - | ||||||
65 | - | |||||||
66 | // Initialize the value in case a narrower type is extracted to it. | - | ||||||
67 | // Note that the result of extracting a narrower type in place of a wider | - | ||||||
68 | // one and vice-versa will be platform-dependent. | - | ||||||
69 | value.t = T(); | - | ||||||
70 | - | |||||||
71 | q_dbus_message_iter_get_basic(it, &value); | - | ||||||
72 | q_dbus_message_iter_next(it); | - | ||||||
73 | return value.t; executed 10427 times by 282 tests: return value.t; Executed by:
| 10427 | ||||||
74 | } | - | ||||||
75 | - | |||||||
76 | QDBusDemarshaller::~QDBusDemarshaller() | - | ||||||
77 | { | - | ||||||
78 | } | - | ||||||
79 | - | |||||||
80 | inline QString QDBusDemarshaller::currentSignature() | - | ||||||
81 | { | - | ||||||
82 | char *sig = q_dbus_message_iter_get_signature(&iterator); | - | ||||||
83 | QString retval = QString::fromUtf8(sig); | - | ||||||
84 | q_dbus_free(sig); | - | ||||||
85 | - | |||||||
86 | return retval; executed 1086 times by 5 tests: return retval; Executed by:
| 1086 | ||||||
87 | } | - | ||||||
88 | - | |||||||
89 | inline uchar QDBusDemarshaller::toByte() | - | ||||||
90 | { | - | ||||||
91 | return qIterGet<uchar>(&iterator); executed 17 times by 1 test: return qIterGet<uchar>(&iterator); Executed by:
| 17 | ||||||
92 | } | - | ||||||
93 | - | |||||||
94 | inline bool QDBusDemarshaller::toBool() | - | ||||||
95 | { | - | ||||||
96 | return bool(qIterGet<dbus_bool_t>(&iterator)); executed 875 times by 150 tests: return bool(qIterGet<dbus_bool_t>(&iterator)); Executed by:
| 875 | ||||||
97 | } | - | ||||||
98 | - | |||||||
99 | inline ushort QDBusDemarshaller::toUShort() | - | ||||||
100 | { | - | ||||||
101 | return qIterGet<dbus_uint16_t>(&iterator); executed 37 times by 1 test: return qIterGet<dbus_uint16_t>(&iterator); Executed by:
| 37 | ||||||
102 | } | - | ||||||
103 | - | |||||||
104 | inline short QDBusDemarshaller::toShort() | - | ||||||
105 | { | - | ||||||
106 | return qIterGet<dbus_int16_t>(&iterator); executed 57 times by 2 tests: return qIterGet<dbus_int16_t>(&iterator); Executed by:
| 57 | ||||||
107 | } | - | ||||||
108 | - | |||||||
109 | inline int QDBusDemarshaller::toInt() | - | ||||||
110 | { | - | ||||||
111 | return qIterGet<dbus_int32_t>(&iterator); executed 664 times by 26 tests: return qIterGet<dbus_int32_t>(&iterator); Executed by:
| 664 | ||||||
112 | } | - | ||||||
113 | - | |||||||
114 | inline uint QDBusDemarshaller::toUInt() | - | ||||||
115 | { | - | ||||||
116 | return qIterGet<dbus_uint32_t>(&iterator); executed 511 times by 27 tests: return qIterGet<dbus_uint32_t>(&iterator); Executed by:
| 511 | ||||||
117 | } | - | ||||||
118 | - | |||||||
119 | inline qlonglong QDBusDemarshaller::toLongLong() | - | ||||||
120 | { | - | ||||||
121 | return qIterGet<qlonglong>(&iterator); executed 57 times by 3 tests: return qIterGet<qlonglong>(&iterator); Executed by:
| 57 | ||||||
122 | } | - | ||||||
123 | - | |||||||
124 | inline qulonglong QDBusDemarshaller::toULongLong() | - | ||||||
125 | { | - | ||||||
126 | return qIterGet<qulonglong>(&iterator); executed 51 times by 17 tests: return qIterGet<qulonglong>(&iterator); Executed by:
| 51 | ||||||
127 | } | - | ||||||
128 | - | |||||||
129 | inline double QDBusDemarshaller::toDouble() | - | ||||||
130 | { | - | ||||||
131 | return qIterGet<double>(&iterator); executed 73 times by 1 test: return qIterGet<double>(&iterator); Executed by:
| 73 | ||||||
132 | } | - | ||||||
133 | - | |||||||
134 | inline QString QDBusDemarshaller::toStringUnchecked() | - | ||||||
135 | { | - | ||||||
136 | return QString::fromUtf8(qIterGet<char *>(&iterator)); executed 7356 times by 282 tests: return QString::fromUtf8(qIterGet<char *>(&iterator)); Executed by:
| 7356 | ||||||
137 | } | - | ||||||
138 | - | |||||||
139 | inline QString QDBusDemarshaller::toString() | - | ||||||
140 | { | - | ||||||
141 | if (isCurrentTypeStringLike())
| 10-2630 | ||||||
142 | return toStringUnchecked(); executed 2630 times by 21 tests: return toStringUnchecked(); Executed by:
| 2630 | ||||||
143 | else | - | ||||||
144 | return QString(); executed 10 times by 1 test: return QString(); Executed by:
| 10 | ||||||
145 | } | - | ||||||
146 | - | |||||||
147 | inline QDBusObjectPath QDBusDemarshaller::toObjectPathUnchecked() | - | ||||||
148 | { | - | ||||||
149 | return QDBusObjectPath(QString::fromUtf8(qIterGet<char *>(&iterator))); executed 680 times by 18 tests: return QDBusObjectPath(QString::fromUtf8(qIterGet<char *>(&iterator))); Executed by:
| 680 | ||||||
150 | } | - | ||||||
151 | - | |||||||
152 | inline QDBusObjectPath QDBusDemarshaller::toObjectPath() | - | ||||||
153 | { | - | ||||||
154 | if (isCurrentTypeStringLike())
| 10-141 | ||||||
155 | return toObjectPathUnchecked(); executed 141 times by 18 tests: return toObjectPathUnchecked(); Executed by:
| 141 | ||||||
156 | else | - | ||||||
157 | return QDBusObjectPath(); executed 10 times by 1 test: return QDBusObjectPath(); Executed by:
| 10 | ||||||
158 | } | - | ||||||
159 | - | |||||||
160 | inline QDBusSignature QDBusDemarshaller::toSignatureUnchecked() | - | ||||||
161 | { | - | ||||||
162 | return QDBusSignature(QString::fromUtf8(qIterGet<char *>(&iterator))); executed 32 times by 1 test: return QDBusSignature(QString::fromUtf8(qIterGet<char *>(&iterator))); Executed by:
| 32 | ||||||
163 | } | - | ||||||
164 | - | |||||||
165 | inline QDBusSignature QDBusDemarshaller::toSignature() | - | ||||||
166 | { | - | ||||||
167 | if (isCurrentTypeStringLike())
| 10-14 | ||||||
168 | return toSignatureUnchecked(); executed 14 times by 1 test: return toSignatureUnchecked(); Executed by:
| 14 | ||||||
169 | else | - | ||||||
170 | return QDBusSignature(); executed 10 times by 1 test: return QDBusSignature(); Executed by:
| 10 | ||||||
171 | } | - | ||||||
172 | - | |||||||
173 | inline QDBusUnixFileDescriptor QDBusDemarshaller::toUnixFileDescriptor() | - | ||||||
174 | { | - | ||||||
175 | QDBusUnixFileDescriptor fd; | - | ||||||
176 | fd.giveFileDescriptor(qIterGet<dbus_int32_t>(&iterator)); | - | ||||||
177 | return fd; executed 17 times by 1 test: return fd; Executed by:
| 17 | ||||||
178 | } | - | ||||||
179 | - | |||||||
180 | inline QDBusVariant QDBusDemarshaller::toVariant() | - | ||||||
181 | { | - | ||||||
182 | QDBusDemarshaller sub(capabilities); | - | ||||||
183 | sub.message = q_dbus_message_ref(message); | - | ||||||
184 | q_dbus_message_iter_recurse(&iterator, &sub.iterator); | - | ||||||
185 | q_dbus_message_iter_next(&iterator); | - | ||||||
186 | - | |||||||
187 | return QDBusVariant( sub.toVariantInternal() ); executed 2995 times by 150 tests: return QDBusVariant( sub.toVariantInternal() ); Executed by:
| 2995 | ||||||
188 | } | - | ||||||
189 | - | |||||||
190 | QDBusArgument::ElementType QDBusDemarshaller::currentType() | - | ||||||
191 | { | - | ||||||
192 | switch (q_dbus_message_iter_get_arg_type(&iterator)) { | - | ||||||
193 | case DBUS_TYPE_BYTE: executed 1 time by 1 test: case ((int) 'y'): Executed by:
| 1 | ||||||
194 | case DBUS_TYPE_INT16: executed 13 times by 1 test: case ((int) 'n'): Executed by:
| 13 | ||||||
195 | case DBUS_TYPE_UINT16: executed 11 times by 1 test: case ((int) 'q'): Executed by:
| 11 | ||||||
196 | case DBUS_TYPE_INT32: executed 160 times by 1 test: case ((int) 'i'): Executed by:
| 160 | ||||||
197 | case DBUS_TYPE_UINT32: executed 9 times by 1 test: case ((int) 'u'): Executed by:
| 9 | ||||||
198 | case DBUS_TYPE_INT64: executed 9 times by 1 test: case ((int) 'x'): Executed by:
| 9 | ||||||
199 | case DBUS_TYPE_UINT64: executed 7 times by 1 test: case ((int) 't'): Executed by:
| 7 | ||||||
200 | case DBUS_TYPE_BOOLEAN: executed 8 times by 1 test: case ((int) 'b'): Executed by:
| 8 | ||||||
201 | case DBUS_TYPE_DOUBLE: executed 27 times by 1 test: case ((int) 'd'): Executed by:
| 27 | ||||||
202 | case DBUS_TYPE_STRING: executed 40 times by 1 test: case ((int) 's'): Executed by:
| 40 | ||||||
203 | case DBUS_TYPE_OBJECT_PATH: executed 3 times by 1 test: case ((int) 'o'): Executed by:
| 3 | ||||||
204 | case DBUS_TYPE_SIGNATURE: executed 1 time by 1 test: case ((int) 'g'): Executed by:
| 1 | ||||||
205 | return QDBusArgument::BasicType; executed 289 times by 1 test: return QDBusArgument::BasicType; Executed by:
| 289 | ||||||
206 | - | |||||||
207 | case DBUS_TYPE_VARIANT: executed 62 times by 1 test: case ((int) 'v'): Executed by:
| 62 | ||||||
208 | return QDBusArgument::VariantType; executed 62 times by 1 test: return QDBusArgument::VariantType; Executed by:
| 62 | ||||||
209 | - | |||||||
210 | case DBUS_TYPE_ARRAY: executed 148 times by 1 test: case ((int) 'a'): Executed by:
| 148 | ||||||
211 | switch (q_dbus_message_iter_get_element_type(&iterator)) { | - | ||||||
212 | case DBUS_TYPE_BYTE: executed 7 times by 1 test: case ((int) 'y'): Executed by:
| 7 | ||||||
213 | case DBUS_TYPE_STRING: executed 5 times by 1 test: case ((int) 's'): Executed by:
| 5 | ||||||
214 | // QByteArray and QStringList | - | ||||||
215 | return QDBusArgument::BasicType; executed 12 times by 1 test: return QDBusArgument::BasicType; Executed by:
| 12 | ||||||
216 | case DBUS_TYPE_DICT_ENTRY: executed 27 times by 1 test: case ((int) 'e'): Executed by:
| 27 | ||||||
217 | return QDBusArgument::MapType; executed 27 times by 1 test: return QDBusArgument::MapType; Executed by:
| 27 | ||||||
218 | default: executed 109 times by 1 test: default: Executed by:
| 109 | ||||||
219 | return QDBusArgument::ArrayType; executed 109 times by 1 test: return QDBusArgument::ArrayType; Executed by:
| 109 | ||||||
220 | } | - | ||||||
221 | - | |||||||
222 | case DBUS_TYPE_STRUCT: executed 90 times by 1 test: case ((int) 'r'): Executed by:
| 90 | ||||||
223 | return QDBusArgument::StructureType; executed 90 times by 1 test: return QDBusArgument::StructureType; Executed by:
| 90 | ||||||
224 | case DBUS_TYPE_DICT_ENTRY: executed 79 times by 1 test: case ((int) 'e'): Executed by:
| 79 | ||||||
225 | return QDBusArgument::MapEntryType; executed 79 times by 1 test: return QDBusArgument::MapEntryType; Executed by:
| 79 | ||||||
226 | - | |||||||
227 | case DBUS_TYPE_UNIX_FD: executed 5 times by 1 test: case ((int) 'h'): Executed by:
| 5 | ||||||
228 | return capabilities & QDBusConnection::UnixFileDescriptorPassing ? executed 5 times by 1 test: return capabilities & QDBusConnection::UnixFileDescriptorPassing ? QDBusArgument::BasicType : QDBusArgument::UnknownType; Executed by:
| 5 | ||||||
229 | QDBusArgument::BasicType : QDBusArgument::UnknownType; executed 5 times by 1 test: return capabilities & QDBusConnection::UnixFileDescriptorPassing ? QDBusArgument::BasicType : QDBusArgument::UnknownType; Executed by:
| 5 | ||||||
230 | - | |||||||
231 | case DBUS_TYPE_INVALID: executed 21 times by 1 test: case ((int) '\0'): Executed by:
| 21 | ||||||
232 | return QDBusArgument::UnknownType; executed 21 times by 1 test: return QDBusArgument::UnknownType; Executed by:
| 21 | ||||||
233 | - | |||||||
234 | // default: | - | ||||||
235 | // qWarning("QDBusDemarshaller: Found unknown D-Bus type %d '%c'", | - | ||||||
236 | // q_dbus_message_iter_get_arg_type(&iterator), | - | ||||||
237 | // q_dbus_message_iter_get_arg_type(&iterator)); | - | ||||||
238 | } | - | ||||||
239 | return QDBusArgument::UnknownType; never executed: return QDBusArgument::UnknownType; | 0 | ||||||
240 | } | - | ||||||
241 | - | |||||||
242 | QVariant QDBusDemarshaller::toVariantInternal() | - | ||||||
243 | { | - | ||||||
244 | switch (q_dbus_message_iter_get_arg_type(&iterator)) { | - | ||||||
245 | case DBUS_TYPE_BYTE: executed 7 times by 1 test: case ((int) 'y'): Executed by:
| 7 | ||||||
246 | return QVariant::fromValue(toByte()); executed 7 times by 1 test: return QVariant::fromValue(toByte()); Executed by:
| 7 | ||||||
247 | case DBUS_TYPE_INT16: executed 35 times by 2 tests: case ((int) 'n'): Executed by:
| 35 | ||||||
248 | return QVariant::fromValue(toShort()); executed 35 times by 2 tests: return QVariant::fromValue(toShort()); Executed by:
| 35 | ||||||
249 | case DBUS_TYPE_UINT16: executed 17 times by 1 test: case ((int) 'q'): Executed by:
| 17 | ||||||
250 | return QVariant::fromValue(toUShort()); executed 17 times by 1 test: return QVariant::fromValue(toUShort()); Executed by:
| 17 | ||||||
251 | case DBUS_TYPE_INT32: executed 404 times by 26 tests: case ((int) 'i'): Executed by:
| 404 | ||||||
252 | return toInt(); executed 404 times by 26 tests: return toInt(); Executed by:
| 404 | ||||||
253 | case DBUS_TYPE_UINT32: executed 493 times by 27 tests: case ((int) 'u'): Executed by:
| 493 | ||||||
254 | return toUInt(); executed 493 times by 27 tests: return toUInt(); Executed by:
| 493 | ||||||
255 | case DBUS_TYPE_DOUBLE: executed 37 times by 1 test: case ((int) 'd'): Executed by:
| 37 | ||||||
256 | return toDouble(); executed 37 times by 1 test: return toDouble(); Executed by:
| 37 | ||||||
257 | case DBUS_TYPE_BOOLEAN: executed 859 times by 150 tests: case ((int) 'b'): Executed by:
| 859 | ||||||
258 | return toBool(); executed 859 times by 150 tests: return toBool(); Executed by:
| 859 | ||||||
259 | case DBUS_TYPE_INT64: executed 29 times by 2 tests: case ((int) 'x'): Executed by:
| 29 | ||||||
260 | return toLongLong(); executed 29 times by 2 tests: return toLongLong(); Executed by:
| 29 | ||||||
261 | case DBUS_TYPE_UINT64: executed 35 times by 17 tests: case ((int) 't'): Executed by:
| 35 | ||||||
262 | return toULongLong(); executed 35 times by 17 tests: return toULongLong(); Executed by:
| 35 | ||||||
263 | case DBUS_TYPE_STRING: executed 2535 times by 282 tests: case ((int) 's'): Executed by:
| 2535 | ||||||
264 | return toStringUnchecked(); executed 2535 times by 282 tests: return toStringUnchecked(); Executed by:
| 2535 | ||||||
265 | case DBUS_TYPE_OBJECT_PATH: executed 539 times by 17 tests: case ((int) 'o'): Executed by:
| 539 | ||||||
266 | return QVariant::fromValue(toObjectPathUnchecked()); executed 539 times by 17 tests: return QVariant::fromValue(toObjectPathUnchecked()); Executed by:
| 539 | ||||||
267 | case DBUS_TYPE_SIGNATURE: executed 18 times by 1 test: case ((int) 'g'): Executed by:
| 18 | ||||||
268 | return QVariant::fromValue(toSignatureUnchecked()); executed 18 times by 1 test: return QVariant::fromValue(toSignatureUnchecked()); Executed by:
| 18 | ||||||
269 | case DBUS_TYPE_VARIANT: executed 475 times by 135 tests: case ((int) 'v'): Executed by:
| 475 | ||||||
270 | return QVariant::fromValue(toVariant()); executed 475 times by 135 tests: return QVariant::fromValue(toVariant()); Executed by:
| 475 | ||||||
271 | - | |||||||
272 | case DBUS_TYPE_ARRAY: executed 724 times by 28 tests: case ((int) 'a'): Executed by:
| 724 | ||||||
273 | switch (q_dbus_message_iter_get_element_type(&iterator)) { | - | ||||||
274 | case DBUS_TYPE_BYTE: executed 33 times by 4 tests: case ((int) 'y'): Executed by:
| 33 | ||||||
275 | // QByteArray | - | ||||||
276 | return toByteArrayUnchecked(); executed 33 times by 4 tests: return toByteArrayUnchecked(); Executed by:
| 33 | ||||||
277 | case DBUS_TYPE_STRING: executed 37 times by 8 tests: case ((int) 's'): Executed by:
| 37 | ||||||
278 | return toStringListUnchecked(); executed 37 times by 8 tests: return toStringListUnchecked(); Executed by:
| 37 | ||||||
279 | case DBUS_TYPE_DICT_ENTRY: executed 219 times by 21 tests: case ((int) 'e'): Executed by:
| 219 | ||||||
280 | return QVariant::fromValue(duplicate()); executed 219 times by 21 tests: return QVariant::fromValue(duplicate()); Executed by:
| 219 | ||||||
281 | - | |||||||
282 | default: executed 435 times by 22 tests: default: Executed by:
| 435 | ||||||
283 | return QVariant::fromValue(duplicate()); executed 435 times by 22 tests: return QVariant::fromValue(duplicate()); Executed by:
| 435 | ||||||
284 | } | - | ||||||
285 | - | |||||||
286 | case DBUS_TYPE_STRUCT: executed 542 times by 21 tests: case ((int) 'r'): Executed by:
| 542 | ||||||
287 | return QVariant::fromValue(duplicate()); executed 542 times by 21 tests: return QVariant::fromValue(duplicate()); Executed by:
| 542 | ||||||
288 | - | |||||||
289 | case DBUS_TYPE_UNIX_FD: executed 16 times by 1 test: case ((int) 'h'): Executed by:
| 16 | ||||||
290 | if (capabilities & QDBusConnection::UnixFileDescriptorPassing)
| 3-13 | ||||||
291 | return QVariant::fromValue(toUnixFileDescriptor()); executed 13 times by 1 test: return QVariant::fromValue(toUnixFileDescriptor()); Executed by:
| 13 | ||||||
292 | // fall through | - | ||||||
293 | - | |||||||
294 | default: code before this statement executed 3 times by 1 test: default: Executed by:
never executed: default: | 0-3 | ||||||
295 | // qWarning("QDBusDemarshaller: Found unknown D-Bus type %d '%c'", | - | ||||||
296 | // q_dbus_message_iter_get_arg_type(&iterator), | - | ||||||
297 | // q_dbus_message_iter_get_arg_type(&iterator)); | - | ||||||
298 | char *ptr = 0; | - | ||||||
299 | ptr += q_dbus_message_iter_get_arg_type(&iterator); | - | ||||||
300 | q_dbus_message_iter_next(&iterator); | - | ||||||
301 | - | |||||||
302 | // I hope you never dereference this pointer! | - | ||||||
303 | return QVariant::fromValue<void *>(ptr); executed 3 times by 1 test: return QVariant::fromValue<void *>(ptr); Executed by:
| 3 | ||||||
304 | }; | - | ||||||
305 | } | - | ||||||
306 | - | |||||||
307 | bool QDBusDemarshaller::isCurrentTypeStringLike() | - | ||||||
308 | { | - | ||||||
309 | const int type = q_dbus_message_iter_get_arg_type(&iterator); | - | ||||||
310 | switch (type) { | - | ||||||
311 | case DBUS_TYPE_STRING: //FALLTHROUGH executed 2636 times by 21 tests: case ((int) 's'): Executed by:
| 2636 | ||||||
312 | case DBUS_TYPE_OBJECT_PATH: //FALLTHROUGH executed 138 times by 18 tests: case ((int) 'o'): Executed by:
| 138 | ||||||
313 | case DBUS_TYPE_SIGNATURE: executed 11 times by 1 test: case ((int) 'g'): Executed by:
| 11 | ||||||
314 | return true; executed 2785 times by 21 tests: return true; Executed by:
| 2785 | ||||||
315 | default: executed 30 times by 1 test: default: Executed by:
| 30 | ||||||
316 | return false; executed 30 times by 1 test: return false; Executed by:
| 30 | ||||||
317 | } | - | ||||||
318 | } | - | ||||||
319 | - | |||||||
320 | QStringList QDBusDemarshaller::toStringListUnchecked() | - | ||||||
321 | { | - | ||||||
322 | QStringList list; | - | ||||||
323 | - | |||||||
324 | QDBusDemarshaller sub(capabilities); | - | ||||||
325 | q_dbus_message_iter_recurse(&iterator, &sub.iterator); | - | ||||||
326 | q_dbus_message_iter_next(&iterator); | - | ||||||
327 | while (!sub.atEnd())
| 42-2191 | ||||||
328 | list.append(sub.toStringUnchecked()); executed 2191 times by 8 tests: list.append(sub.toStringUnchecked()); Executed by:
| 2191 | ||||||
329 | - | |||||||
330 | return list; executed 42 times by 8 tests: return list; Executed by:
| 42 | ||||||
331 | } | - | ||||||
332 | - | |||||||
333 | QStringList QDBusDemarshaller::toStringList() | - | ||||||
334 | { | - | ||||||
335 | if (q_dbus_message_iter_get_arg_type(&iterator) == DBUS_TYPE_ARRAY
| 9-15 | ||||||
336 | && q_dbus_message_iter_get_element_type(&iterator) == DBUS_TYPE_STRING)
| 4-5 | ||||||
337 | return toStringListUnchecked(); executed 5 times by 1 test: return toStringListUnchecked(); Executed by:
| 5 | ||||||
338 | else | - | ||||||
339 | return QStringList(); executed 19 times by 1 test: return QStringList(); Executed by:
| 19 | ||||||
340 | } | - | ||||||
341 | - | |||||||
342 | QByteArray QDBusDemarshaller::toByteArrayUnchecked() | - | ||||||
343 | { | - | ||||||
344 | DBusMessageIter sub; | - | ||||||
345 | q_dbus_message_iter_recurse(&iterator, &sub); | - | ||||||
346 | q_dbus_message_iter_next(&iterator); | - | ||||||
347 | int len; | - | ||||||
348 | char* data; | - | ||||||
349 | q_dbus_message_iter_get_fixed_array(&sub,&data,&len); | - | ||||||
350 | return QByteArray(data,len); executed 40 times by 4 tests: return QByteArray(data,len); Executed by:
| 40 | ||||||
351 | } | - | ||||||
352 | - | |||||||
353 | QByteArray QDBusDemarshaller::toByteArray() | - | ||||||
354 | { | - | ||||||
355 | if (q_dbus_message_iter_get_arg_type(&iterator) == DBUS_TYPE_ARRAY
| 11-15 | ||||||
356 | && q_dbus_message_iter_get_element_type(&iterator) == DBUS_TYPE_BYTE) {
| 4-7 | ||||||
357 | return toByteArrayUnchecked(); executed 7 times by 1 test: return toByteArrayUnchecked(); Executed by:
| 7 | ||||||
358 | } | - | ||||||
359 | return QByteArray(); executed 19 times by 1 test: return QByteArray(); Executed by:
| 19 | ||||||
360 | } | - | ||||||
361 | - | |||||||
362 | bool QDBusDemarshaller::atEnd() | - | ||||||
363 | { | - | ||||||
364 | // dbus_message_iter_has_next is broken if the list has one single element | - | ||||||
365 | return q_dbus_message_iter_get_arg_type(&iterator) == DBUS_TYPE_INVALID; executed 14919 times by 282 tests: return q_dbus_message_iter_get_arg_type(&iterator) == ((int) '\0'); Executed by:
| 14919 | ||||||
366 | } | - | ||||||
367 | - | |||||||
368 | inline QDBusDemarshaller *QDBusDemarshaller::beginStructure() | - | ||||||
369 | { | - | ||||||
370 | return beginCommon(); executed 371 times by 5 tests: return beginCommon(); Executed by:
| 371 | ||||||
371 | } | - | ||||||
372 | - | |||||||
373 | inline QDBusDemarshaller *QDBusDemarshaller::beginArray() | - | ||||||
374 | { | - | ||||||
375 | return beginCommon(); executed 339 times by 22 tests: return beginCommon(); Executed by:
| 339 | ||||||
376 | } | - | ||||||
377 | - | |||||||
378 | inline QDBusDemarshaller *QDBusDemarshaller::beginMap() | - | ||||||
379 | { | - | ||||||
380 | return beginCommon(); executed 274 times by 21 tests: return beginCommon(); Executed by:
| 274 | ||||||
381 | } | - | ||||||
382 | - | |||||||
383 | inline QDBusDemarshaller *QDBusDemarshaller::beginMapEntry() | - | ||||||
384 | { | - | ||||||
385 | return beginCommon(); executed 2678 times by 21 tests: return beginCommon(); Executed by:
| 2678 | ||||||
386 | } | - | ||||||
387 | - | |||||||
388 | QDBusDemarshaller *QDBusDemarshaller::beginCommon() | - | ||||||
389 | { | - | ||||||
390 | QDBusDemarshaller *d = new QDBusDemarshaller(capabilities); | - | ||||||
391 | d->parent = this; | - | ||||||
392 | d->message = q_dbus_message_ref(message); | - | ||||||
393 | - | |||||||
394 | // recurse | - | ||||||
395 | q_dbus_message_iter_recurse(&iterator, &d->iterator); | - | ||||||
396 | q_dbus_message_iter_next(&iterator); | - | ||||||
397 | return d; executed 4418 times by 23 tests: return d; Executed by:
| 4418 | ||||||
398 | } | - | ||||||
399 | - | |||||||
400 | inline QDBusDemarshaller *QDBusDemarshaller::endStructure() | - | ||||||
401 | { | - | ||||||
402 | return endCommon(); executed 371 times by 5 tests: return endCommon(); Executed by:
| 371 | ||||||
403 | } | - | ||||||
404 | - | |||||||
405 | inline QDBusDemarshaller *QDBusDemarshaller::endArray() | - | ||||||
406 | { | - | ||||||
407 | return endCommon(); executed 339 times by 22 tests: return endCommon(); Executed by:
| 339 | ||||||
408 | } | - | ||||||
409 | - | |||||||
410 | inline QDBusDemarshaller *QDBusDemarshaller::endMap() | - | ||||||
411 | { | - | ||||||
412 | return endCommon(); executed 274 times by 21 tests: return endCommon(); Executed by:
| 274 | ||||||
413 | } | - | ||||||
414 | - | |||||||
415 | inline QDBusDemarshaller *QDBusDemarshaller::endMapEntry() | - | ||||||
416 | { | - | ||||||
417 | return endCommon(); executed 2678 times by 21 tests: return endCommon(); Executed by:
| 2678 | ||||||
418 | } | - | ||||||
419 | - | |||||||
420 | QDBusDemarshaller *QDBusDemarshaller::endCommon() | - | ||||||
421 | { | - | ||||||
422 | QDBusDemarshaller *retval = parent; | - | ||||||
423 | delete this; | - | ||||||
424 | return retval; executed 3662 times by 23 tests: return retval; Executed by:
| 3662 | ||||||
425 | } | - | ||||||
426 | - | |||||||
427 | QDBusArgument QDBusDemarshaller::duplicate() | - | ||||||
428 | { | - | ||||||
429 | QScopedPointer<QDBusDemarshaller> d(new QDBusDemarshaller(capabilities)); | - | ||||||
430 | d->iterator = iterator; | - | ||||||
431 | d->message = q_dbus_message_ref(message); | - | ||||||
432 | - | |||||||
433 | q_dbus_message_iter_next(&iterator); | - | ||||||
434 | return QDBusArgumentPrivate::create(d.take()); executed 1196 times by 23 tests: return QDBusArgumentPrivate::create(d.take()); Executed by:
| 1196 | ||||||
435 | } | - | ||||||
436 | - | |||||||
437 | QT_END_NAMESPACE | - | ||||||
Source code | Switch to Preprocessed file |