|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 |
|
43 #include <QtTest/QtTest> |
|
44 |
|
45 #include <qcoreapplication.h> |
|
46 #include <quuid.h> |
|
47 |
|
48 |
|
49 |
|
50 #include <quuid.h> |
|
51 |
|
52 //TESTED_CLASS= |
|
53 //TESTED_FILES= |
|
54 |
|
55 class tst_QUuid : public QObject |
|
56 { |
|
57 Q_OBJECT |
|
58 |
|
59 public: |
|
60 tst_QUuid(); |
|
61 |
|
62 private slots: |
|
63 void toString(); |
|
64 void isNull(); |
|
65 void equal(); |
|
66 void notEqual(); |
|
67 |
|
68 // Only in Qt > 3.2.x |
|
69 void generate(); |
|
70 void less(); |
|
71 void more(); |
|
72 void variants(); |
|
73 void versions(); |
|
74 |
|
75 void threadUniqueness(); |
|
76 |
|
77 public: |
|
78 // Variables |
|
79 QUuid uuidA; |
|
80 QUuid uuidB; |
|
81 }; |
|
82 |
|
83 tst_QUuid::tst_QUuid() |
|
84 { |
|
85 uuidA = "{fc69b59e-cc34-4436-a43c-ee95d128b8c5}"; |
|
86 uuidB = "{1ab6e93a-b1cb-4a87-ba47-ec7e99039a7b}"; |
|
87 } |
|
88 |
|
89 |
|
90 void tst_QUuid::toString() |
|
91 { |
|
92 QCOMPARE(uuidA.toString(), QString("{fc69b59e-cc34-4436-a43c-ee95d128b8c5}")); |
|
93 } |
|
94 |
|
95 |
|
96 void tst_QUuid::isNull() |
|
97 { |
|
98 QVERIFY( !uuidA.isNull() ); |
|
99 |
|
100 QUuid should_be_null_uuid; |
|
101 QVERIFY( should_be_null_uuid.isNull() ); |
|
102 } |
|
103 |
|
104 |
|
105 void tst_QUuid::equal() |
|
106 { |
|
107 QVERIFY( !(uuidA == uuidB) ); |
|
108 |
|
109 QUuid copy(uuidA); |
|
110 QVERIFY(uuidA == copy); |
|
111 |
|
112 QUuid assigned; |
|
113 assigned = uuidA; |
|
114 QVERIFY(uuidA == assigned); |
|
115 } |
|
116 |
|
117 |
|
118 void tst_QUuid::notEqual() |
|
119 { |
|
120 QVERIFY( uuidA != uuidB ); |
|
121 } |
|
122 |
|
123 |
|
124 void tst_QUuid::generate() |
|
125 { |
|
126 QUuid shouldnt_be_null_uuidA = QUuid::createUuid(); |
|
127 QUuid shouldnt_be_null_uuidB = QUuid::createUuid(); |
|
128 QVERIFY( !shouldnt_be_null_uuidA.isNull() ); |
|
129 QVERIFY( !shouldnt_be_null_uuidB.isNull() ); |
|
130 QVERIFY( shouldnt_be_null_uuidA != shouldnt_be_null_uuidB ); |
|
131 } |
|
132 |
|
133 |
|
134 void tst_QUuid::less() |
|
135 { |
|
136 QVERIFY( !(uuidA < uuidB) ); |
|
137 |
|
138 QUuid null_uuid; |
|
139 QVERIFY(null_uuid < uuidA); // Null uuid is always less than a valid one |
|
140 } |
|
141 |
|
142 |
|
143 void tst_QUuid::more() |
|
144 { |
|
145 QVERIFY( uuidA > uuidB ); |
|
146 |
|
147 QUuid null_uuid; |
|
148 QVERIFY( !(null_uuid > uuidA) ); // Null uuid is always less than a valid one |
|
149 } |
|
150 |
|
151 |
|
152 void tst_QUuid::variants() |
|
153 { |
|
154 QVERIFY( uuidA.variant() == QUuid::DCE ); |
|
155 QVERIFY( uuidB.variant() == QUuid::DCE ); |
|
156 |
|
157 QUuid NCS = "{3a2f883c-4000-000d-0000-00fb40000000}"; |
|
158 QVERIFY( NCS.variant() == QUuid::NCS ); |
|
159 } |
|
160 |
|
161 |
|
162 void tst_QUuid::versions() |
|
163 { |
|
164 QVERIFY( uuidA.version() == QUuid::Random ); |
|
165 QVERIFY( uuidB.version() == QUuid::Random ); |
|
166 |
|
167 QUuid DCE_time= "{406c45a0-3b7e-11d0-80a3-0000c08810a7}"; |
|
168 QVERIFY( DCE_time.version() == QUuid::Time ); |
|
169 |
|
170 QUuid NCS = "{3a2f883c-4000-000d-0000-00fb40000000}"; |
|
171 QVERIFY( NCS.version() == QUuid::VerUnknown ); |
|
172 } |
|
173 |
|
174 class UuidThread : public QThread |
|
175 { |
|
176 public: |
|
177 QUuid uuid; |
|
178 |
|
179 void run() |
|
180 { |
|
181 uuid = QUuid::createUuid(); |
|
182 } |
|
183 }; |
|
184 |
|
185 void tst_QUuid::threadUniqueness() |
|
186 { |
|
187 QVector<UuidThread *> threads(qMax(2, QThread::idealThreadCount())); |
|
188 for (int i = 0; i < threads.count(); ++i) |
|
189 threads[i] = new UuidThread; |
|
190 for (int i = 0; i < threads.count(); ++i) |
|
191 threads[i]->start(); |
|
192 for (int i = 0; i < threads.count(); ++i) |
|
193 QVERIFY(threads[i]->wait(1000)); |
|
194 for (int i = 1; i < threads.count(); ++i) |
|
195 QVERIFY(threads[0]->uuid != threads[i]->uuid); |
|
196 qDeleteAll(threads); |
|
197 } |
|
198 |
|
199 QTEST_MAIN(tst_QUuid) |
|
200 #include "tst_quuid.moc" |