quuid.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/plugin/quuid.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtCore module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
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 http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://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 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "quuid.h"-
35-
36#include "qdatastream.h"-
37#include "qendian.h"-
38#include "qdebug.h"-
39#include "private/qtools_p.h"-
40-
41#ifndef QT_BOOTSTRAPPED-
42#include "qcryptographichash.h"-
43#endif-
44QT_BEGIN_NAMESPACE-
45-
46template <class Char, class Integral>-
47void _q_toHex(Char *&dst, Integral value)-
48{-
49 value = qToBigEndian(value);-
50-
51 const char* p = reinterpret_cast<const char*>(&value);-
52-
53 for (uint i = 0; i < sizeof(Integral); ++i, dst += 2) {
i < sizeof(Integral)Description
TRUEevaluated 20560 times by 4 tests
Evaluated by:
  • tst_QRawFont
  • tst_QUuid
  • tst_QVariant
  • tst_quuid - unknown status
FALSEevaluated 14135 times by 4 tests
Evaluated by:
  • tst_QRawFont
  • tst_QUuid
  • tst_QVariant
  • tst_quuid - unknown status
14135-20560
54 dst[0] = Char(QtMiscUtils::toHexLower((p[i] >> 4) & 0xf));-
55 dst[1] = Char(QtMiscUtils::toHexLower(p[i] & 0xf));-
56 }
executed 20560 times by 4 tests: end of block
Executed by:
  • tst_QRawFont
  • tst_QUuid
  • tst_QVariant
  • tst_quuid - unknown status
20560
57}
executed 14135 times by 4 tests: end of block
Executed by:
  • tst_QRawFont
  • tst_QUuid
  • tst_QVariant
  • tst_quuid - unknown status
14135
58-
59template <class Char, class Integral>-
60bool _q_fromHex(const Char *&src, Integral &value)-
61{-
62 value = 0;-
63-
64 for (uint i = 0; i < sizeof(Integral) * 2; ++i) {
i < sizeof(Integral) * 2Description
TRUEevaluated 810 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
FALSEevaluated 269 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
269-810
65 uint ch = *src++;-
66 int tmp = QtMiscUtils::fromHex(ch);-
67 if (tmp == -1)
tmp == -1Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QUuid
FALSEevaluated 807 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
3-807
68 return false;
executed 3 times by 1 test: return false;
Executed by:
  • tst_QUuid
3
69-
70 value = value * 16 + tmp;-
71 }
executed 807 times by 2 tests: end of block
Executed by:
  • tst_QUuid
  • tst_QVariant
807
72-
73 return true;
executed 269 times by 2 tests: return true;
Executed by:
  • tst_QUuid
  • tst_QVariant
269
74}-
75-
76template <class Char>-
77void _q_uuidToHex(Char *&dst, const uint &d1, const ushort &d2, const ushort &d3, const uchar (&d4)[8])-
78{-
79 *dst++ = Char('{');-
80 _q_toHex(dst, d1);-
81 *dst++ = Char('-');-
82 _q_toHex(dst, d2);-
83 *dst++ = Char('-');-
84 _q_toHex(dst, d3);-
85 *dst++ = Char('-');-
86 for (int i = 0; i < 2; i++)
i < 2Description
TRUEevaluated 2570 times by 4 tests
Evaluated by:
  • tst_QRawFont
  • tst_QUuid
  • tst_QVariant
  • tst_quuid - unknown status
FALSEevaluated 1285 times by 4 tests
Evaluated by:
  • tst_QRawFont
  • tst_QUuid
  • tst_QVariant
  • tst_quuid - unknown status
1285-2570
87 _q_toHex(dst, d4[i]);
executed 2570 times by 4 tests: _q_toHex(dst, d4[i]);
Executed by:
  • tst_QRawFont
  • tst_QUuid
  • tst_QVariant
  • tst_quuid - unknown status
2570
88 *dst++ = Char('-');-
89 for (int i = 2; i < 8; i++)
i < 8Description
TRUEevaluated 7710 times by 4 tests
Evaluated by:
  • tst_QRawFont
  • tst_QUuid
  • tst_QVariant
  • tst_quuid - unknown status
FALSEevaluated 1285 times by 4 tests
Evaluated by:
  • tst_QRawFont
  • tst_QUuid
  • tst_QVariant
  • tst_quuid - unknown status
1285-7710
90 _q_toHex(dst, d4[i]);
executed 7710 times by 4 tests: _q_toHex(dst, d4[i]);
Executed by:
  • tst_QRawFont
  • tst_QUuid
  • tst_QVariant
  • tst_quuid - unknown status
7710
91 *dst = Char('}');-
92}
executed 1285 times by 4 tests: end of block
Executed by:
  • tst_QRawFont
  • tst_QUuid
  • tst_QVariant
  • tst_quuid - unknown status
1285
93-
94template <class Char>-
95bool _q_uuidFromHex(const Char *&src, uint &d1, ushort &d2, ushort &d3, uchar (&d4)[8])-
96{-
97 if (*src == Char('{'))
*src == Char('{')Description
TRUEevaluated 19 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
FALSEevaluated 9 times by 1 test
Evaluated by:
  • tst_QUuid
9-19
98 src++;
executed 19 times by 2 tests: src++;
Executed by:
  • tst_QUuid
  • tst_QVariant
19
99 if (!_q_fromHex(src, d1)
!_q_fromHex(src, d1)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QUuid
FALSEevaluated 27 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
1-27
100 || *src++ != Char('-')
*src++ != Char('-')Description
TRUEnever evaluated
FALSEevaluated 27 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
0-27
101 || !_q_fromHex(src, d2)
!_q_fromHex(src, d2)Description
TRUEnever evaluated
FALSEevaluated 27 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
0-27
102 || *src++ != Char('-')
*src++ != Char('-')Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QUuid
FALSEevaluated 25 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
2-25
103 || !_q_fromHex(src, d3)
!_q_fromHex(src, d3)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QUuid
FALSEevaluated 24 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
1-24
104 || *src++ != Char('-')
*src++ != Char('-')Description
TRUEnever evaluated
FALSEevaluated 24 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
0-24
105 || !_q_fromHex(src, d4[0])
!_q_fromHex(src, d4[0])Description
TRUEnever evaluated
FALSEevaluated 24 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
0-24
106 || !_q_fromHex(src, d4[1])
!_q_fromHex(src, d4[1])Description
TRUEnever evaluated
FALSEevaluated 24 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
0-24
107 || *src++ != Char('-')
*src++ != Char('-')Description
TRUEnever evaluated
FALSEevaluated 24 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
0-24
108 || !_q_fromHex(src, d4[2])
!_q_fromHex(src, d4[2])Description
TRUEnever evaluated
FALSEevaluated 24 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
0-24
109 || !_q_fromHex(src, d4[3])
!_q_fromHex(src, d4[3])Description
TRUEnever evaluated
FALSEevaluated 24 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
0-24
110 || !_q_fromHex(src, d4[4])
!_q_fromHex(src, d4[4])Description
TRUEnever evaluated
FALSEevaluated 24 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
0-24
111 || !_q_fromHex(src, d4[5])
!_q_fromHex(src, d4[5])Description
TRUEnever evaluated
FALSEevaluated 24 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
0-24
112 || !_q_fromHex(src, d4[6])
!_q_fromHex(src, d4[6])Description
TRUEnever evaluated
FALSEevaluated 24 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
0-24
113 || !_q_fromHex(src, d4[7])) {
!_q_fromHex(src, d4[7])Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QUuid
FALSEevaluated 23 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
1-23
114 return false;
executed 5 times by 1 test: return false;
Executed by:
  • tst_QUuid
5
115 }-
116-
117 return true;
executed 23 times by 2 tests: return true;
Executed by:
  • tst_QUuid
  • tst_QVariant
23
118}-
119-
120#ifndef QT_BOOTSTRAPPED-
121static QUuid createFromName(const QUuid &ns, const QByteArray &baseData, QCryptographicHash::Algorithm algorithm, int version)-
122{-
123 QByteArray hashResult;-
124-
125 // create a scope so later resize won't reallocate-
126 {-
127 QCryptographicHash hash(algorithm);-
128 hash.addData(ns.toRfc4122());-
129 hash.addData(baseData);-
130 hashResult = hash.result();-
131 }-
132 hashResult.resize(16); // Sha1 will be too long-
133-
134 QUuid result = QUuid::fromRfc4122(hashResult);-
135-
136 result.data3 &= 0x0FFF;-
137 result.data3 |= (version << 12);-
138 result.data4[0] &= 0x3F;-
139 result.data4[0] |= 0x80;-
140-
141 return result;
executed 4 times by 1 test: return result;
Executed by:
  • tst_QUuid
4
142}-
143#endif-
144-
145/*!-
146 \class QUuid-
147 \inmodule QtCore-
148 \brief The QUuid class stores a Universally Unique Identifier (UUID).-
149-
150 \reentrant-
151-
152 Using \e{U}niversally \e{U}nique \e{ID}entifiers (UUID) is a-
153 standard way to uniquely identify entities in a distributed-
154 computing environment. A UUID is a 16-byte (128-bit) number-
155 generated by some algorithm that is meant to guarantee that the-
156 UUID will be unique in the distributed computing environment where-
157 it is used. The acronym GUID is often used instead, \e{G}lobally-
158 \e{U}nique \e{ID}entifiers, but it refers to the same thing.-
159-
160 \target Variant field-
161 Actually, the GUID is one \e{variant} of UUID. Multiple variants-
162 are in use. Each UUID contains a bit field that specifies which-
163 type (variant) of UUID it is. Call variant() to discover which-
164 type of UUID an instance of QUuid contains. It extracts the three-
165 most significant bits of byte 8 of the 16 bytes. In QUuid, byte 8-
166 is \c{QUuid::data4[0]}. If you create instances of QUuid using the-
167 constructor that accepts all the numeric values as parameters, use-
168 the following table to set the three most significant bits of-
169 parameter \c{b1}, which becomes \c{QUuid::data4[0]} and contains-
170 the variant field in its three most significant bits. In the-
171 table, 'x' means \e {don't care}.-
172-
173 \table-
174 \header-
175 \li msb0-
176 \li msb1-
177 \li msb2-
178 \li Variant-
179-
180 \row-
181 \li 0-
182 \li x-
183 \li x-
184 \li NCS (Network Computing System)-
185-
186 \row-
187 \li 1-
188 \li 0-
189 \li x-
190 \li DCE (Distributed Computing Environment)-
191-
192 \row-
193 \li 1-
194 \li 1-
195 \li 0-
196 \li Microsoft (GUID)-
197-
198 \row-
199 \li 1-
200 \li 1-
201 \li 1-
202 \li Reserved for future expansion-
203-
204 \endtable-
205-
206 \target Version field-
207 If variant() returns QUuid::DCE, the UUID also contains a-
208 \e{version} field in the four most significant bits of-
209 \c{QUuid::data3}, and you can call version() to discover which-
210 version your QUuid contains. If you create instances of QUuid-
211 using the constructor that accepts all the numeric values as-
212 parameters, use the following table to set the four most-
213 significant bits of parameter \c{w2}, which becomes-
214 \c{QUuid::data3} and contains the version field in its four most-
215 significant bits.-
216-
217 \table-
218 \header-
219 \li msb0-
220 \li msb1-
221 \li msb2-
222 \li msb3-
223 \li Version-
224-
225 \row-
226 \li 0-
227 \li 0-
228 \li 0-
229 \li 1-
230 \li Time-
231-
232 \row-
233 \li 0-
234 \li 0-
235 \li 1-
236 \li 0-
237 \li Embedded POSIX-
238-
239 \row-
240 \li 0-
241 \li 0-
242 \li 1-
243 \li 1-
244 \li Md5(Name)-
245-
246 \row-
247 \li 0-
248 \li 1-
249 \li 0-
250 \li 0-
251 \li Random-
252-
253 \row-
254 \li 0-
255 \li 1-
256 \li 0-
257 \li 1-
258 \li Sha1-
259-
260 \endtable-
261-
262 The field layouts for the DCE versions listed in the table above-
263 are specified in the \l{http://www.ietf.org/rfc/rfc4122.txt}-
264 {Network Working Group UUID Specification}.-
265-
266 Most platforms provide a tool for generating new UUIDs, e.g. \c-
267 uuidgen and \c guidgen. You can also use createUuid(). UUIDs-
268 generated by createUuid() are of the random type. Their-
269 QUuid::Version bits are set to QUuid::Random, and their-
270 QUuid::Variant bits are set to QUuid::DCE. The rest of the UUID is-
271 composed of random numbers. Theoretically, this means there is a-
272 small chance that a UUID generated by createUuid() will not be-
273 unique. But it is-
274 \l{http://en.wikipedia.org/wiki/Universally_Unique_Identifier#Random_UUID_probability_of_duplicates}-
275 {a \e{very} small chance}.-
276-
277 UUIDs can be constructed from numeric values or from strings, or-
278 using the static createUuid() function. They can be converted to a-
279 string with toString(). UUIDs have a variant() and a version(),-
280 and null UUIDs return true from isNull().-
281*/-
282-
283/*!-
284 \fn QUuid::QUuid(const GUID &guid)-
285-
286 Casts a Windows \a guid to a Qt QUuid.-
287-
288 \warning This function is only for Windows platforms.-
289*/-
290-
291/*!-
292 \fn QUuid &QUuid::operator=(const GUID &guid)-
293-
294 Assigns a Windows \a guid to a Qt QUuid.-
295-
296 \warning This function is only for Windows platforms.-
297*/-
298-
299/*!-
300 \fn QUuid::operator GUID() const-
301-
302 Returns a Windows GUID from a QUuid.-
303-
304 \warning This function is only for Windows platforms.-
305*/-
306-
307/*!-
308 \fn QUuid::QUuid()-
309-
310 Creates the null UUID. toString() will output the null UUID-
311 as "{00000000-0000-0000-0000-000000000000}".-
312*/-
313-
314/*!-
315 \fn QUuid::QUuid(uint l, ushort w1, ushort w2, uchar b1, uchar b2, uchar b3, uchar b4, uchar b5, uchar b6, uchar b7, uchar b8)-
316-
317 Creates a UUID with the value specified by the parameters, \a l,-
318 \a w1, \a w2, \a b1, \a b2, \a b3, \a b4, \a b5, \a b6, \a b7, \a-
319 b8.-
320-
321 Example:-
322 \snippet code/src_corelib_plugin_quuid.cpp 0-
323*/-
324-
325/*!-
326 Creates a QUuid object from the string \a text, which must be-
327 formatted as five hex fields separated by '-', e.g.,-
328 "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" where 'x' is a hex-
329 digit. The curly braces shown here are optional, but it is normal to-
330 include them. If the conversion fails, a null UUID is created. See-
331 toString() for an explanation of how the five hex fields map to the-
332 public data members in QUuid.-
333-
334 \sa toString(), QUuid()-
335*/-
336QUuid::QUuid(const QString &text)-
337{-
338 if (text.length() < 36) {
text.length() < 36Description
TRUEnever evaluated
FALSEevaluated 10 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
0-10
339 *this = QUuid();-
340 return;
never executed: return;
0
341 }-
342-
343 const ushort *data = reinterpret_cast<const ushort *>(text.unicode());-
344-
345 if (*data == '{' && text.length() < 37) {
*data == '{'Description
TRUEevaluated 8 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QUuid
text.length() < 37Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QUuid
FALSEevaluated 7 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
1-8
346 *this = QUuid();-
347 return;
executed 1 time by 1 test: return;
Executed by:
  • tst_QUuid
1
348 }-
349-
350 if (!_q_uuidFromHex(data, data1, data2, data3, data4)) {
!_q_uuidFromHe... data3, data4)Description
TRUEnever evaluated
FALSEevaluated 9 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
0-9
351 *this = QUuid();-
352 return;
never executed: return;
0
353 }-
354}
executed 9 times by 2 tests: end of block
Executed by:
  • tst_QUuid
  • tst_QVariant
9
355-
356/*!-
357 \internal-
358*/-
359QUuid::QUuid(const char *text)-
360{-
361 if (!text) {
!textDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QUuid
FALSEevaluated 14 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
1-14
362 *this = QUuid();-
363 return;
executed 1 time by 1 test: return;
Executed by:
  • tst_QUuid
1
364 }-
365-
366 if (!_q_uuidFromHex(text, data1, data2, data3, data4)) {
!_q_uuidFromHe... data3, data4)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • tst_QUuid
FALSEevaluated 9 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
5-9
367 *this = QUuid();-
368 return;
executed 5 times by 1 test: return;
Executed by:
  • tst_QUuid
5
369 }-
370}
executed 9 times by 2 tests: end of block
Executed by:
  • tst_QUuid
  • tst_QVariant
9
371-
372/*!-
373 Creates a QUuid object from the QByteArray \a text, which must be-
374 formatted as five hex fields separated by '-', e.g.,-
375 "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" where 'x' is a hex-
376 digit. The curly braces shown here are optional, but it is normal to-
377 include them. If the conversion fails, a null UUID is created. See-
378 toByteArray() for an explanation of how the five hex fields map to the-
379 public data members in QUuid.-
380-
381 \since 4.8-
382-
383 \sa toByteArray(), QUuid()-
384*/-
385QUuid::QUuid(const QByteArray &text)-
386{-
387 if (text.length() < 36) {
text.length() < 36Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_QUuid
0-6
388 *this = QUuid();-
389 return;
never executed: return;
0
390 }-
391-
392 const char *data = text.constData();-
393-
394 if (*data == '{' && text.length() < 37) {
*data == '{'Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QUuid
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QUuid
text.length() < 37Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QUuid
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QUuid
1-4
395 *this = QUuid();-
396 return;
executed 1 time by 1 test: return;
Executed by:
  • tst_QUuid
1
397 }-
398-
399 if (!_q_uuidFromHex(data, data1, data2, data3, data4)) {
!_q_uuidFromHe... data3, data4)Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • tst_QUuid
0-5
400 *this = QUuid();-
401 return;
never executed: return;
0
402 }-
403}
executed 5 times by 1 test: end of block
Executed by:
  • tst_QUuid
5
404-
405/*!-
406 \since 5.0-
407 \fn QUuid QUuid::createUuidV3(const QUuid &ns, const QByteArray &baseData);-
408-
409 This function returns a new UUID with variant QUuid::DCE and version QUuid::Md5.-
410 \a ns is the namespace and \a baseData is the basic data as described by RFC 4122.-
411-
412 \sa variant(), version(), createUuidV5()-
413*/-
414-
415/*!-
416 \since 5.0-
417 \fn QUuid QUuid::createUuidV3(const QUuid &ns, const QString &baseData);-
418-
419 This function returns a new UUID with variant QUuid::DCE and version QUuid::Md5.-
420 \a ns is the namespace and \a baseData is the basic data as described by RFC 4122.-
421-
422 \sa variant(), version(), createUuidV5()-
423*/-
424-
425/*!-
426 \since 5.0-
427 \fn QUuid QUuid::createUuidV5(const QUuid &ns, const QByteArray &baseData);-
428-
429 This function returns a new UUID with variant QUuid::DCE and version QUuid::Sha1.-
430 \a ns is the namespace and \a baseData is the basic data as described by RFC 4122.-
431-
432 \sa variant(), version(), createUuidV3()-
433*/-
434-
435/*!-
436 \since 5.0-
437 \fn QUuid QUuid::createUuidV5(const QUuid &ns, const QString &baseData);-
438-
439 This function returns a new UUID with variant QUuid::DCE and version QUuid::Sha1.-
440 \a ns is the namespace and \a baseData is the basic data as described by RFC 4122.-
441-
442 \sa variant(), version(), createUuidV3()-
443*/-
444#ifndef QT_BOOTSTRAPPED-
445QUuid QUuid::createUuidV3(const QUuid &ns, const QByteArray &baseData)-
446{-
447 return createFromName(ns, baseData, QCryptographicHash::Md5, 3);
executed 2 times by 1 test: return createFromName(ns, baseData, QCryptographicHash::Md5, 3);
Executed by:
  • tst_QUuid
2
448}-
449-
450QUuid QUuid::createUuidV5(const QUuid &ns, const QByteArray &baseData)-
451{-
452 return createFromName(ns, baseData, QCryptographicHash::Sha1, 5);
executed 2 times by 1 test: return createFromName(ns, baseData, QCryptographicHash::Sha1, 5);
Executed by:
  • tst_QUuid
2
453}-
454#endif-
455-
456/*!-
457 Creates a QUuid object from the binary representation of the UUID, as-
458 specified by RFC 4122 section 4.1.2. See toRfc4122() for a further-
459 explanation of the order of \a bytes required.-
460-
461 The byte array accepted is NOT a human readable format.-
462-
463 If the conversion fails, a null UUID is created.-
464-
465 \since 4.8-
466-
467 \sa toRfc4122(), QUuid()-
468*/-
469QUuid QUuid::fromRfc4122(const QByteArray &bytes)-
470{-
471 if (bytes.isEmpty() || bytes.length() != 16)
bytes.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 10 times by 3 tests
Evaluated by:
  • tst_QMetaType
  • tst_QUuid
  • tst_QVariant
bytes.length() != 16Description
TRUEnever evaluated
FALSEevaluated 10 times by 3 tests
Evaluated by:
  • tst_QMetaType
  • tst_QUuid
  • tst_QVariant
0-10
472 return QUuid();
never executed: return QUuid();
0
473-
474 uint d1;-
475 ushort d2, d3;-
476 uchar d4[8];-
477-
478 const uchar *data = reinterpret_cast<const uchar *>(bytes.constData());-
479-
480 d1 = qFromBigEndian<quint32>(data);-
481 data += sizeof(quint32);-
482 d2 = qFromBigEndian<quint16>(data);-
483 data += sizeof(quint16);-
484 d3 = qFromBigEndian<quint16>(data);-
485 data += sizeof(quint16);-
486-
487 for (int i = 0; i < 8; ++i) {
i < 8Description
TRUEevaluated 80 times by 3 tests
Evaluated by:
  • tst_QMetaType
  • tst_QUuid
  • tst_QVariant
FALSEevaluated 10 times by 3 tests
Evaluated by:
  • tst_QMetaType
  • tst_QUuid
  • tst_QVariant
10-80
488 d4[i] = *(data);-
489 data++;-
490 }
executed 80 times by 3 tests: end of block
Executed by:
  • tst_QMetaType
  • tst_QUuid
  • tst_QVariant
80
491-
492 return QUuid(d1, d2, d3, d4[0], d4[1], d4[2], d4[3], d4[4], d4[5], d4[6], d4[7]);
executed 10 times by 3 tests: return QUuid(d1, d2, d3, d4[0], d4[1], d4[2], d4[3], d4[4], d4[5], d4[6], d4[7]);
Executed by:
  • tst_QMetaType
  • tst_QUuid
  • tst_QVariant
10
493}-
494-
495/*!-
496 \fn bool QUuid::operator==(const QUuid &other) const-
497-
498 Returns \c true if this QUuid and the \a other QUuid are identical;-
499 otherwise returns \c false.-
500*/-
501-
502/*!-
503 \fn bool QUuid::operator!=(const QUuid &other) const-
504-
505 Returns \c true if this QUuid and the \a other QUuid are different;-
506 otherwise returns \c false.-
507*/-
508-
509/*!-
510 Returns the string representation of this QUuid. The string is-
511 formatted as five hex fields separated by '-' and enclosed in-
512 curly braces, i.e., "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" where-
513 'x' is a hex digit. From left to right, the five hex fields are-
514 obtained from the four public data members in QUuid as follows:-
515-
516 \table-
517 \header-
518 \li Field #-
519 \li Source-
520-
521 \row-
522 \li 1-
523 \li data1-
524-
525 \row-
526 \li 2-
527 \li data2-
528-
529 \row-
530 \li 3-
531 \li data3-
532-
533 \row-
534 \li 4-
535 \li data4[0] .. data4[1]-
536-
537 \row-
538 \li 5-
539 \li data4[2] .. data4[7]-
540-
541 \endtable-
542*/-
543QString QUuid::toString() const-
544{-
545 QString result(38, Qt::Uninitialized);-
546 ushort *data = (ushort *)result.data();-
547-
548 _q_uuidToHex(data, data1, data2, data3, data4);-
549-
550 return result;
executed 34 times by 3 tests: return result;
Executed by:
  • tst_QUuid
  • tst_QVariant
  • tst_quuid - unknown status
34
551}-
552-
553/*!-
554 Returns the binary representation of this QUuid. The byte array is-
555 formatted as five hex fields separated by '-' and enclosed in-
556 curly braces, i.e., "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" where-
557 'x' is a hex digit. From left to right, the five hex fields are-
558 obtained from the four public data members in QUuid as follows:-
559-
560 \table-
561 \header-
562 \li Field #-
563 \li Source-
564-
565 \row-
566 \li 1-
567 \li data1-
568-
569 \row-
570 \li 2-
571 \li data2-
572-
573 \row-
574 \li 3-
575 \li data3-
576-
577 \row-
578 \li 4-
579 \li data4[0] .. data4[1]-
580-
581 \row-
582 \li 5-
583 \li data4[2] .. data4[7]-
584-
585 \endtable-
586-
587 \since 4.8-
588*/-
589QByteArray QUuid::toByteArray() const-
590{-
591 QByteArray result(38, Qt::Uninitialized);-
592 char *data = result.data();-
593-
594 _q_uuidToHex(data, data1, data2, data3, data4);-
595-
596 return result;
executed 1251 times by 2 tests: return result;
Executed by:
  • tst_QRawFont
  • tst_QUuid
1251
597}-
598-
599/*!-
600 Returns the binary representation of this QUuid. The byte array is in big-
601 endian format, and formatted according to RFC 4122, section 4.1.2 --
602 "Layout and byte order".-
603-
604 The order is as follows:-
605-
606 \table-
607 \header-
608 \li Field #-
609 \li Source-
610-
611 \row-
612 \li 1-
613 \li data1-
614-
615 \row-
616 \li 2-
617 \li data2-
618-
619 \row-
620 \li 3-
621 \li data3-
622-
623 \row-
624 \li 4-
625 \li data4[0] .. data4[7]-
626-
627 \endtable-
628-
629 \since 4.8-
630*/-
631QByteArray QUuid::toRfc4122() const-
632{-
633 // we know how many bytes a UUID has, I hope :)-
634 QByteArray bytes(16, Qt::Uninitialized);-
635 uchar *data = reinterpret_cast<uchar*>(bytes.data());-
636-
637 qToBigEndian(data1, data);-
638 data += sizeof(quint32);-
639 qToBigEndian(data2, data);-
640 data += sizeof(quint16);-
641 qToBigEndian(data3, data);-
642 data += sizeof(quint16);-
643-
644 for (int i = 0; i < 8; ++i) {
i < 8Description
TRUEevaluated 72 times by 3 tests
Evaluated by:
  • tst_QMetaType
  • tst_QUuid
  • tst_QVariant
FALSEevaluated 9 times by 3 tests
Evaluated by:
  • tst_QMetaType
  • tst_QUuid
  • tst_QVariant
9-72
645 *(data) = data4[i];-
646 data++;-
647 }
executed 72 times by 3 tests: end of block
Executed by:
  • tst_QMetaType
  • tst_QUuid
  • tst_QVariant
72
648-
649 return bytes;
executed 9 times by 3 tests: return bytes;
Executed by:
  • tst_QMetaType
  • tst_QUuid
  • tst_QVariant
9
650}-
651-
652#ifndef QT_NO_DATASTREAM-
653/*!-
654 \relates QUuid-
655 Writes the UUID \a id to the data stream \a s.-
656*/-
657QDataStream &operator<<(QDataStream &s, const QUuid &id)-
658{-
659 QByteArray bytes;-
660 if (s.byteOrder() == QDataStream::BigEndian) {
s.byteOrder() ...eam::BigEndianDescription
TRUEevaluated 3 times by 3 tests
Evaluated by:
  • tst_QMetaType
  • tst_QUuid
  • tst_QVariant
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QUuid
1-3
661 bytes = id.toRfc4122();-
662 } else {
executed 3 times by 3 tests: end of block
Executed by:
  • tst_QMetaType
  • tst_QUuid
  • tst_QVariant
3
663 // we know how many bytes a UUID has, I hope :)-
664 bytes = QByteArray(16, Qt::Uninitialized);-
665 uchar *data = reinterpret_cast<uchar*>(bytes.data());-
666-
667 qToLittleEndian(id.data1, data);-
668 data += sizeof(quint32);-
669 qToLittleEndian(id.data2, data);-
670 data += sizeof(quint16);-
671 qToLittleEndian(id.data3, data);-
672 data += sizeof(quint16);-
673-
674 for (int i = 0; i < 8; ++i) {
i < 8Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • tst_QUuid
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QUuid
1-8
675 *(data) = id.data4[i];-
676 data++;-
677 }
executed 8 times by 1 test: end of block
Executed by:
  • tst_QUuid
8
678 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QUuid
1
679-
680 if (s.writeRawData(bytes.data(), 16) != 16) {
s.writeRawData...a(), 16) != 16Description
TRUEnever evaluated
FALSEevaluated 4 times by 3 tests
Evaluated by:
  • tst_QMetaType
  • tst_QUuid
  • tst_QVariant
0-4
681 s.setStatus(QDataStream::WriteFailed);-
682 }
never executed: end of block
0
683 return s;
executed 4 times by 3 tests: return s;
Executed by:
  • tst_QMetaType
  • tst_QUuid
  • tst_QVariant
4
684}-
685-
686/*!-
687 \relates QUuid-
688 Reads a UUID from the stream \a s into \a id.-
689*/-
690QDataStream &operator>>(QDataStream &s, QUuid &id)-
691{-
692 QByteArray bytes(16, Qt::Uninitialized);-
693 if (s.readRawData(bytes.data(), 16) != 16) {
s.readRawData(...a(), 16) != 16Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMetaType
FALSEevaluated 5 times by 3 tests
Evaluated by:
  • tst_QMetaType
  • tst_QUuid
  • tst_QVariant
2-5
694 s.setStatus(QDataStream::ReadPastEnd);-
695 return s;
executed 2 times by 1 test: return s;
Executed by:
  • tst_QMetaType
2
696 }-
697-
698 if (s.byteOrder() == QDataStream::BigEndian) {
s.byteOrder() ...eam::BigEndianDescription
TRUEevaluated 4 times by 3 tests
Evaluated by:
  • tst_QMetaType
  • tst_QUuid
  • tst_QVariant
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QUuid
1-4
699 id = QUuid::fromRfc4122(bytes);-
700 } else {
executed 4 times by 3 tests: end of block
Executed by:
  • tst_QMetaType
  • tst_QUuid
  • tst_QVariant
4
701 const uchar *data = reinterpret_cast<const uchar *>(bytes.constData());-
702-
703 id.data1 = qFromLittleEndian<quint32>(data);-
704 data += sizeof(quint32);-
705 id.data2 = qFromLittleEndian<quint16>(data);-
706 data += sizeof(quint16);-
707 id.data3 = qFromLittleEndian<quint16>(data);-
708 data += sizeof(quint16);-
709-
710 for (int i = 0; i < 8; ++i) {
i < 8Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • tst_QUuid
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QUuid
1-8
711 id.data4[i] = *(data);-
712 data++;-
713 }
executed 8 times by 1 test: end of block
Executed by:
  • tst_QUuid
8
714 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QUuid
1
715-
716 return s;
executed 5 times by 3 tests: return s;
Executed by:
  • tst_QMetaType
  • tst_QUuid
  • tst_QVariant
5
717}-
718#endif // QT_NO_DATASTREAM-
719-
720/*!-
721 Returns \c true if this is the null UUID-
722 {00000000-0000-0000-0000-000000000000}; otherwise returns \c false.-
723*/-
724bool QUuid::isNull() const Q_DECL_NOTHROW-
725{-
726 return data4[0] == 0 && data4[1] == 0 && data4[2] == 0 && data4[3] == 0 &&
executed 58 times by 2 tests: return data4[0] == 0 && data4[1] == 0 && data4[2] == 0 && data4[3] == 0 && data4[4] == 0 && data4[5] == 0 && data4[6] == 0 && data4[7] == 0 && data1 == 0 && data2 == 0 && data3 == 0;
Executed by:
  • tst_QUuid
  • tst_QVariant
data4[0] == 0Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • tst_QUuid
FALSEevaluated 42 times by 2 tests
Evaluated by:
  • tst_QUuid
  • tst_QVariant
data4[1] == 0Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • tst_QUuid
FALSEnever evaluated
data4[2] == 0Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • tst_QUuid
FALSEnever evaluated
data4[3] == 0Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • tst_QUuid
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QUuid
0-58
727 data4[4] == 0 && data4[5] == 0 && data4[6] == 0 && data4[7] == 0 &&
executed 58 times by 2 tests: return data4[0] == 0 && data4[1] == 0 && data4[2] == 0 && data4[3] == 0 && data4[4] == 0 && data4[5] == 0 && data4[6] == 0 && data4[7] == 0 && data1 == 0 && data2 == 0 && data3 == 0;
Executed by:
  • tst_QUuid
  • tst_QVariant
data4[4] == 0Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • tst_QUuid
FALSEnever evaluated
data4[5] == 0Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • tst_QUuid
FALSEnever evaluated
data4[6] == 0Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • tst_QUuid
FALSEnever evaluated
data4[7] == 0Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • tst_QUuid
FALSEnever evaluated
0-58
728 data1 == 0 && data2 == 0 && data3 == 0;
executed 58 times by 2 tests: return data4[0] == 0 && data4[1] == 0 && data4[2] == 0 && data4[3] == 0 && data4[4] == 0 && data4[5] == 0 && data4[6] == 0 && data4[7] == 0 && data1 == 0 && data2 == 0 && data3 == 0;
Executed by:
  • tst_QUuid
  • tst_QVariant
data1 == 0Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • tst_QUuid
FALSEnever evaluated
data2 == 0Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • tst_QUuid
FALSEnever evaluated
data3 == 0Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • tst_QUuid
FALSEnever evaluated
0-58
729}-
730-
731/*!-
732 \enum QUuid::Variant-
733-
734 This enum defines the values used in the \l{Variant field}-
735 {variant field} of the UUID. The value in the variant field-
736 determines the layout of the 128-bit value.-
737-
738 \value VarUnknown Variant is unknown-
739 \value NCS Reserved for NCS (Network Computing System) backward compatibility-
740 \value DCE Distributed Computing Environment, the scheme used by QUuid-
741 \value Microsoft Reserved for Microsoft backward compatibility (GUID)-
742 \value Reserved Reserved for future definition-
743*/-
744-
745/*!-
746 \enum QUuid::Version-
747-
748 This enum defines the values used in the \l{Version field}-
749 {version field} of the UUID. The version field is meaningful-
750 only if the value in the \l{Variant field} {variant field}-
751 is QUuid::DCE.-
752-
753 \value VerUnknown Version is unknown-
754 \value Time Time-based, by using timestamp, clock sequence, and-
755 MAC network card address (if available) for the node sections-
756 \value EmbeddedPOSIX DCE Security version, with embedded POSIX UUIDs-
757 \value Name Name-based, by using values from a name for all sections-
758 \value Md5 Alias for Name-
759 \value Random Random-based, by using random numbers for all sections-
760 \value Sha1-
761*/-
762-
763/*!-
764 \fn QUuid::Variant QUuid::variant() const-
765-
766 Returns the value in the \l{Variant field} {variant field} of the-
767 UUID. If the return value is QUuid::DCE, call version() to see-
768 which layout it uses. The null UUID is considered to be of an-
769 unknown variant.-
770-
771 \sa version()-
772*/-
773QUuid::Variant QUuid::variant() const Q_DECL_NOTHROW-
774{-
775 if (isNull())
isNull()Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • tst_QUuid
FALSEevaluated 35 times by 1 test
Evaluated by:
  • tst_QUuid
12-35
776 return VarUnknown;
executed 12 times by 1 test: return VarUnknown;
Executed by:
  • tst_QUuid
12
777 // Check the 3 MSB of data4[0]-
778 if ((data4[0] & 0x80) == 0x00) return NCS;
executed 2 times by 1 test: return NCS;
Executed by:
  • tst_QUuid
(data4[0] & 0x80) == 0x00Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QUuid
FALSEevaluated 33 times by 1 test
Evaluated by:
  • tst_QUuid
2-33
779 else if ((data4[0] & 0xC0) == 0x80) return DCE;
executed 33 times by 1 test: return DCE;
Executed by:
  • tst_QUuid
(data4[0] & 0xC0) == 0x80Description
TRUEevaluated 33 times by 1 test
Evaluated by:
  • tst_QUuid
FALSEnever evaluated
0-33
780 else if ((data4[0] & 0xE0) == 0xC0) return Microsoft;
never executed: return Microsoft;
(data4[0] & 0xE0) == 0xC0Description
TRUEnever evaluated
FALSEnever evaluated
0
781 else if ((data4[0] & 0xE0) == 0xE0) return Reserved;
never executed: return Reserved;
(data4[0] & 0xE0) == 0xE0Description
TRUEnever evaluated
FALSEnever evaluated
0
782 return VarUnknown;
never executed: return VarUnknown;
0
783}-
784-
785/*!-
786 \fn QUuid::Version QUuid::version() const-
787-
788 Returns the \l{Version field} {version field} of the UUID, if the-
789 UUID's \l{Variant field} {variant field} is QUuid::DCE. Otherwise-
790 it returns QUuid::VerUnknown.-
791-
792 \sa variant()-
793*/-
794QUuid::Version QUuid::version() const Q_DECL_NOTHROW-
795{-
796 // Check the 4 MSB of data3-
797 Version ver = (Version)(data3>>12);-
798 if (isNull()
isNull()Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QUuid
0-4
799 || (variant() != DCE)
(variant() != DCE)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QUuid
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QUuid
1-3
800 || ver < Time
ver < TimeDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QUuid
0-3
801 || ver > Sha1)
ver > Sha1Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QUuid
0-3
802 return VerUnknown;
executed 1 time by 1 test: return VerUnknown;
Executed by:
  • tst_QUuid
1
803 return ver;
executed 3 times by 1 test: return ver;
Executed by:
  • tst_QUuid
3
804}-
805-
806/*!-
807 \fn bool QUuid::operator<(const QUuid &other) const-
808-
809 Returns \c true if this QUuid has the same \l{Variant field}-
810 {variant field} as the \a other QUuid and is lexicographically-
811 \e{before} the \a other QUuid. If the \a other QUuid has a-
812 different variant field, the return value is determined by-
813 comparing the two \l{QUuid::Variant} {variants}.-
814-
815 \sa variant()-
816*/-
817bool QUuid::operator<(const QUuid &other) const Q_DECL_NOTHROW-
818{-
819 if (variant() != other.variant())
variant() != other.variant()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QUuid
FALSEevaluated 12 times by 1 test
Evaluated by:
  • tst_QUuid
4-12
820 return variant() < other.variant();
executed 4 times by 1 test: return variant() < other.variant();
Executed by:
  • tst_QUuid
4
821-
822#define ISLESS(f1, f2) if (f1!=f2) return (f1<f2);-
823 ISLESS(data1, other.data1);
executed 8 times by 1 test: return (data1<other.data1);
Executed by:
  • tst_QUuid
data1!=other.data1Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • tst_QUuid
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QUuid
4-8
824 ISLESS(data2, other.data2);
never executed: return (data2<other.data2);
data2!=other.data2Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QUuid
0-4
825 ISLESS(data3, other.data3);
never executed: return (data3<other.data3);
data3!=other.data3Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QUuid
0-4
826 for (int n = 0; n < 8; n++) {
n < 8Description
TRUEevaluated 32 times by 1 test
Evaluated by:
  • tst_QUuid
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QUuid
4-32
827 ISLESS(data4[n], other.data4[n]);
never executed: return (data4[n]<other.data4[n]);
data4[n]!=other.data4[n]Description
TRUEnever evaluated
FALSEevaluated 32 times by 1 test
Evaluated by:
  • tst_QUuid
0-32
828 }
executed 32 times by 1 test: end of block
Executed by:
  • tst_QUuid
32
829#undef ISLESS-
830 return false;
executed 4 times by 1 test: return false;
Executed by:
  • tst_QUuid
4
831}-
832-
833/*!-
834 \fn bool QUuid::operator>(const QUuid &other) const-
835-
836 Returns \c true if this QUuid has the same \l{Variant field}-
837 {variant field} as the \a other QUuid and is lexicographically-
838 \e{after} the \a other QUuid. If the \a other QUuid has a-
839 different variant field, the return value is determined by-
840 comparing the two \l{QUuid::Variant} {variants}.-
841-
842 \sa variant()-
843*/-
844bool QUuid::operator>(const QUuid &other) const Q_DECL_NOTHROW-
845{-
846 return other < *this;
executed 3 times by 1 test: return other < *this;
Executed by:
  • tst_QUuid
3
847}-
848-
849/*!-
850 \fn bool operator<=(const QUuid &lhs, const QUuid &rhs)-
851 \relates QUuid-
852 \since 5.5-
853-
854 Returns \c true if \a lhs has the same \l{Variant field}-
855 {variant field} as \a rhs and is lexicographically-
856 \e{not after} \a rhs. If \a rhs has a-
857 different variant field, the return value is determined by-
858 comparing the two \l{QUuid::Variant} {variants}.-
859-
860 \sa {QUuid::}{variant()}-
861*/-
862-
863/*!-
864 \fn bool operator>=(const QUuid &lhs, const QUuid &rhs)-
865 \relates QUuid-
866 \since 5.5-
867-
868 Returns \c true if \a lhs has the same \l{Variant field}-
869 {variant field} as \a rhs and is lexicographically-
870 \e{not before} \a rhs. If \a rhs has a-
871 different variant field, the return value is determined by-
872 comparing the two \l{QUuid::Variant} {variants}.-
873-
874 \sa {QUuid::}{variant()}-
875*/-
876-
877/*!-
878 \fn QUuid QUuid::createUuid()-
879-
880 On any platform other than Windows, this function returns a new-
881 UUID with variant QUuid::DCE and version QUuid::Random. If-
882 the /dev/urandom device exists, then the numbers used to construct-
883 the UUID will be of cryptographic quality, which will make the UUID-
884 unique. Otherwise, the numbers of the UUID will be obtained from-
885 the local pseudo-random number generator (qrand(), which is seeded-
886 by qsrand()) which is usually not of cryptograhic quality, which-
887 means that the UUID can't be guaranteed to be unique.-
888-
889 On a Windows platform, a GUID is generated, which almost certainly-
890 \e{will} be unique, on this or any other system, networked or not.-
891-
892 \sa variant(), version()-
893*/-
894#if defined(Q_OS_WIN)-
895-
896QT_BEGIN_INCLUDE_NAMESPACE-
897#include <objbase.h> // For CoCreateGuid-
898QT_END_INCLUDE_NAMESPACE-
899-
900QUuid QUuid::createUuid()-
901{-
902 GUID guid;-
903 CoCreateGuid(&guid);-
904 QUuid result = guid;-
905 return result;-
906}-
907-
908#else // Q_OS_WIN-
909-
910QT_BEGIN_INCLUDE_NAMESPACE-
911#include "qdatetime.h"-
912#include "qfile.h"-
913#include "qthreadstorage.h"-
914#include <stdlib.h> // for RAND_MAX-
915QT_END_INCLUDE_NAMESPACE-
916-
917#if !defined(QT_BOOTSTRAPPED) && defined(Q_OS_UNIX)-
918Q_GLOBAL_STATIC(QThreadStorage<QFile *>, devUrandomStorage);
executed 4 times by 2 tests: end of block
Executed by:
  • tst_qrawfont - unknown status
  • tst_quuid - unknown status
executed 4 times by 2 tests: guard.store(QtGlobalStatic::Destroyed);
Executed by:
  • tst_qrawfont - unknown status
  • tst_quuid - unknown status
executed 1267 times by 3 tests: return &holder.value;
Executed by:
  • tst_QRawFont
  • tst_QUuid
  • tst_quuid - unknown status
guard.load() =...c::InitializedDescription
TRUEevaluated 4 times by 2 tests
Evaluated by:
  • tst_qrawfont - unknown status
  • tst_quuid - unknown status
FALSEnever evaluated
0-1267
919#endif-
920-
921QUuid QUuid::createUuid()-
922{-
923 QUuid result;-
924 uint *data = &(result.data1);-
925-
926#if defined(Q_OS_UNIX)-
927 QFile *devUrandom;-
928# if !defined(QT_BOOTSTRAPPED)-
929 devUrandom = devUrandomStorage()->localData();-
930 if (!devUrandom) {
!devUrandomDescription
TRUEevaluated 6 times by 3 tests
Evaluated by:
  • tst_QRawFont
  • tst_QUuid
  • tst_quuid - unknown status
FALSEevaluated 1255 times by 3 tests
Evaluated by:
  • tst_QRawFont
  • tst_QUuid
  • tst_quuid - unknown status
6-1255
931 devUrandom = new QFile(QLatin1String("/dev/urandom"));-
932 devUrandom->open(QIODevice::ReadOnly | QIODevice::Unbuffered);-
933 devUrandomStorage()->setLocalData(devUrandom);-
934 }
executed 6 times by 3 tests: end of block
Executed by:
  • tst_QRawFont
  • tst_QUuid
  • tst_quuid - unknown status
6
935# else-
936 QFile file(QLatin1String("/dev/urandom"));-
937 devUrandom = &file;-
938 devUrandom->open(QIODevice::ReadOnly | QIODevice::Unbuffered);-
939# endif-
940 enum { AmountToRead = 4 * sizeof(uint) };-
941 if (devUrandom->isOpen()
devUrandom->isOpen()Description
TRUEevaluated 1261 times by 3 tests
Evaluated by:
  • tst_QRawFont
  • tst_QUuid
  • tst_quuid - unknown status
FALSEnever evaluated
0-1261
942 && devUrandom->read((char *) data, AmountToRead) == AmountToRead) {
devUrandom->re...= AmountToReadDescription
TRUEevaluated 1261 times by 3 tests
Evaluated by:
  • tst_QRawFont
  • tst_QUuid
  • tst_quuid - unknown status
FALSEnever evaluated
0-1261
943 // we got what we wanted, nothing more to do-
944 ;-
945 } else
executed 1261 times by 3 tests: end of block
Executed by:
  • tst_QRawFont
  • tst_QUuid
  • tst_quuid - unknown status
1261
946#endif-
947 {-
948 static const int intbits = sizeof(int)*8;-
949 static int randbits = 0;-
950 if (!randbits) {
!randbitsDescription
TRUEnever evaluated
FALSEnever evaluated
0
951 int r = 0;-
952 int max = RAND_MAX;-
953 do { ++r; } while ((max=max>>1));
never executed: end of block
(max=max>>1)Description
TRUEnever evaluated
FALSEnever evaluated
0
954 randbits = r;-
955 }
never executed: end of block
0
956-
957 // Seed the PRNG once per thread with a combination of current time, a-
958 // stack address and a serial counter (since thread stack addresses are-
959 // re-used).-
960#ifndef QT_BOOTSTRAPPED-
961 static QThreadStorage<int *> uuidseed;-
962 if (!uuidseed.hasLocalData())
!uuidseed.hasLocalData()Description
TRUEnever evaluated
FALSEnever evaluated
0
963 {-
964 int *pseed = new int;-
965 static QBasicAtomicInt serial = Q_BASIC_ATOMIC_INITIALIZER(2);-
966 qsrand(*pseed = QDateTime::currentDateTimeUtc().toTime_t()-
967 + quintptr(&pseed)-
968 + serial.fetchAndAddRelaxed(1));-
969 uuidseed.setLocalData(pseed);-
970 }
never executed: end of block
0
971#else-
972 static bool seeded = false;-
973 if (!seeded)-
974 qsrand(QDateTime::currentDateTimeUtc().toTime_t()-
975 + quintptr(&seeded));-
976#endif-
977-
978 int chunks = 16 / sizeof(uint);-
979 while (chunks--) {
chunks--Description
TRUEnever evaluated
FALSEnever evaluated
0
980 uint randNumber = 0;-
981 for (int filled = 0; filled < intbits; filled += randbits)
filled < intbitsDescription
TRUEnever evaluated
FALSEnever evaluated
0
982 randNumber |= qrand()<<filled;
never executed: randNumber |= qrand()<<filled;
0
983 *(data+chunks) = randNumber;-
984 }
never executed: end of block
0
985 }
never executed: end of block
0
986-
987 result.data4[0] = (result.data4[0] & 0x3F) | 0x80; // UV_DCE-
988 result.data3 = (result.data3 & 0x0FFF) | 0x4000; // UV_Random-
989-
990 return result;
executed 1261 times by 3 tests: return result;
Executed by:
  • tst_QRawFont
  • tst_QUuid
  • tst_quuid - unknown status
1261
991}-
992#endif // !Q_OS_WIN-
993-
994/*!-
995 \fn bool QUuid::operator==(const GUID &guid) const-
996-
997 Returns \c true if this UUID is equal to the Windows GUID \a guid;-
998 otherwise returns \c false.-
999*/-
1000-
1001/*!-
1002 \fn bool QUuid::operator!=(const GUID &guid) const-
1003-
1004 Returns \c true if this UUID is not equal to the Windows GUID \a-
1005 guid; otherwise returns \c false.-
1006*/-
1007-
1008#ifndef QT_NO_DEBUG_STREAM-
1009/*!-
1010 \relates QUuid-
1011 Writes the UUID \a id to the output stream for debugging information \a dbg.-
1012*/-
1013QDebug operator<<(QDebug dbg, const QUuid &id)-
1014{-
1015 QDebugStateSaver saver(dbg);-
1016 dbg.nospace() << "QUuid(" << id.toString() << ')';-
1017 return dbg;
executed 1 time by 1 test: return dbg;
Executed by:
  • tst_QVariant
1
1018}-
1019#endif-
1020-
1021/*!-
1022 \since 5.0-
1023 \relates QUuid-
1024 Returns a hash of the UUID \a uuid, using \a seed to seed the calculation.-
1025*/-
1026uint qHash(const QUuid &uuid, uint seed) Q_DECL_NOTHROW-
1027{-
1028 return uuid.data1 ^ uuid.data2 ^ (uuid.data3 << 16)
executed 3 times by 1 test: return uuid.data1 ^ uuid.data2 ^ (uuid.data3 << 16) ^ ((uuid.data4[0] << 24) | (uuid.data4[1] << 16) | (uuid.data4[2] << 8) | uuid.data4[3]) ^ ((uuid.data4[4] << 24) | (uuid.data4[5] << 16) | (uuid.data4[6] << 8) | uuid.data4[7]) ^ seed;
Executed by:
  • tst_QUuid
3
1029 ^ ((uuid.data4[0] << 24) | (uuid.data4[1] << 16) | (uuid.data4[2] << 8) | uuid.data4[3])
executed 3 times by 1 test: return uuid.data1 ^ uuid.data2 ^ (uuid.data3 << 16) ^ ((uuid.data4[0] << 24) | (uuid.data4[1] << 16) | (uuid.data4[2] << 8) | uuid.data4[3]) ^ ((uuid.data4[4] << 24) | (uuid.data4[5] << 16) | (uuid.data4[6] << 8) | uuid.data4[7]) ^ seed;
Executed by:
  • tst_QUuid
3
1030 ^ ((uuid.data4[4] << 24) | (uuid.data4[5] << 16) | (uuid.data4[6] << 8) | uuid.data4[7])
executed 3 times by 1 test: return uuid.data1 ^ uuid.data2 ^ (uuid.data3 << 16) ^ ((uuid.data4[0] << 24) | (uuid.data4[1] << 16) | (uuid.data4[2] << 8) | uuid.data4[3]) ^ ((uuid.data4[4] << 24) | (uuid.data4[5] << 16) | (uuid.data4[6] << 8) | uuid.data4[7]) ^ seed;
Executed by:
  • tst_QUuid
3
1031 ^ seed;
executed 3 times by 1 test: return uuid.data1 ^ uuid.data2 ^ (uuid.data3 << 16) ^ ((uuid.data4[0] << 24) | (uuid.data4[1] << 16) | (uuid.data4[2] << 8) | uuid.data4[3]) ^ ((uuid.data4[4] << 24) | (uuid.data4[5] << 16) | (uuid.data4[6] << 8) | uuid.data4[7]) ^ seed;
Executed by:
  • tst_QUuid
3
1032}-
1033-
1034-
1035QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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