|
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 #include <QtCore> |
|
43 #include <QtGui/QPixmap> |
|
44 #include <qtest.h> |
|
45 |
|
46 #define ITERATION_COUNT 1e5 |
|
47 |
|
48 class tst_qvariant : public QObject |
|
49 { |
|
50 Q_OBJECT |
|
51 private slots: |
|
52 void testBound(); |
|
53 |
|
54 void doubleVariantCreation(); |
|
55 void floatVariantCreation(); |
|
56 void rectVariantCreation(); |
|
57 void stringVariantCreation(); |
|
58 void pixmapVariantCreation(); |
|
59 |
|
60 void doubleVariantSetValue(); |
|
61 void floatVariantSetValue(); |
|
62 void rectVariantSetValue(); |
|
63 void stringVariantSetValue(); |
|
64 |
|
65 void doubleVariantAssignment(); |
|
66 void floatVariantAssignment(); |
|
67 void rectVariantAssignment(); |
|
68 void stringVariantAssignment(); |
|
69 }; |
|
70 |
|
71 void tst_qvariant::testBound() |
|
72 { |
|
73 qreal d = qreal(.5); |
|
74 QBENCHMARK { |
|
75 for(int i = 0; i < ITERATION_COUNT; ++i) { |
|
76 d = qBound<qreal>(0, d, 1); |
|
77 } |
|
78 } |
|
79 } |
|
80 |
|
81 template <typename T> |
|
82 static void variantCreation(T val) |
|
83 { |
|
84 QBENCHMARK { |
|
85 for(int i = 0; i < ITERATION_COUNT; ++i) { |
|
86 QVariant v(val); |
|
87 } |
|
88 } |
|
89 } |
|
90 |
|
91 void tst_qvariant::doubleVariantCreation() |
|
92 { |
|
93 variantCreation<double>(0.0); |
|
94 } |
|
95 |
|
96 void tst_qvariant::floatVariantCreation() |
|
97 { |
|
98 variantCreation<float>(0.0f); |
|
99 } |
|
100 |
|
101 void tst_qvariant::rectVariantCreation() |
|
102 { |
|
103 variantCreation<QRect>(QRect(1, 2, 3, 4)); |
|
104 } |
|
105 |
|
106 void tst_qvariant::stringVariantCreation() |
|
107 { |
|
108 variantCreation<QString>(QString()); |
|
109 } |
|
110 |
|
111 void tst_qvariant::pixmapVariantCreation() |
|
112 { |
|
113 variantCreation<QPixmap>(QPixmap()); |
|
114 } |
|
115 |
|
116 template <typename T> |
|
117 static void variantSetValue(T d) |
|
118 { |
|
119 QVariant v; |
|
120 QBENCHMARK { |
|
121 for(int i = 0; i < ITERATION_COUNT; ++i) { |
|
122 qVariantSetValue(v, d); |
|
123 } |
|
124 } |
|
125 } |
|
126 |
|
127 void tst_qvariant::doubleVariantSetValue() |
|
128 { |
|
129 variantSetValue<double>(0.0); |
|
130 } |
|
131 |
|
132 void tst_qvariant::floatVariantSetValue() |
|
133 { |
|
134 variantSetValue<float>(0.0f); |
|
135 } |
|
136 |
|
137 void tst_qvariant::rectVariantSetValue() |
|
138 { |
|
139 variantSetValue<QRect>(QRect()); |
|
140 } |
|
141 |
|
142 void tst_qvariant::stringVariantSetValue() |
|
143 { |
|
144 variantSetValue<QString>(QString()); |
|
145 } |
|
146 |
|
147 template <typename T> |
|
148 static void variantAssignment(T d) |
|
149 { |
|
150 QVariant v; |
|
151 QBENCHMARK { |
|
152 for(int i = 0; i < ITERATION_COUNT; ++i) { |
|
153 v = d; |
|
154 } |
|
155 } |
|
156 } |
|
157 |
|
158 void tst_qvariant::doubleVariantAssignment() |
|
159 { |
|
160 variantAssignment<double>(0.0); |
|
161 } |
|
162 |
|
163 void tst_qvariant::floatVariantAssignment() |
|
164 { |
|
165 variantAssignment<float>(0.0f); |
|
166 } |
|
167 |
|
168 void tst_qvariant::rectVariantAssignment() |
|
169 { |
|
170 variantAssignment<QRect>(QRect()); |
|
171 } |
|
172 |
|
173 void tst_qvariant::stringVariantAssignment() |
|
174 { |
|
175 variantAssignment<QString>(QString()); |
|
176 } |
|
177 |
|
178 QTEST_MAIN(tst_qvariant) |
|
179 |
|
180 #include "tst_qvariant.moc" |