author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 0 | 1918ee327afb |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 <QtCore> |
|
44 |
#include <QtTest/QtTest> |
|
45 |
||
46 |
class tst_Subtest: public QObject |
|
47 |
{ |
|
48 |
Q_OBJECT |
|
49 |
public slots: |
|
50 |
void init(); |
|
51 |
void initTestCase(); |
|
52 |
||
53 |
void cleanup(); |
|
54 |
void cleanupTestCase(); |
|
55 |
||
56 |
private slots: |
|
57 |
void test1(); |
|
58 |
void test2_data(); |
|
59 |
void test2(); |
|
60 |
void test3_data(); |
|
61 |
void test3(); |
|
62 |
void floatComparisons() const; |
|
63 |
void floatComparisons_data() const; |
|
64 |
void compareFloatTests() const; |
|
65 |
void compareFloatTests_data() const; |
|
66 |
}; |
|
67 |
||
68 |
||
69 |
void tst_Subtest::initTestCase() |
|
70 |
{ |
|
71 |
printf("initTestCase %s %s\n", |
|
72 |
QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)", |
|
73 |
QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); |
|
74 |
} |
|
75 |
||
76 |
void tst_Subtest::cleanupTestCase() |
|
77 |
{ |
|
78 |
printf("cleanupTestCase %s %s\n", |
|
79 |
QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)", |
|
80 |
QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); |
|
81 |
} |
|
82 |
||
83 |
void tst_Subtest::init() |
|
84 |
{ |
|
85 |
printf("init %s %s\n", |
|
86 |
QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)", |
|
87 |
QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); |
|
88 |
} |
|
89 |
||
90 |
void tst_Subtest::cleanup() |
|
91 |
{ |
|
92 |
printf("cleanup %s %s\n", |
|
93 |
QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)", |
|
94 |
QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); |
|
95 |
} |
|
96 |
||
97 |
void tst_Subtest::test1() |
|
98 |
{ |
|
99 |
printf("test1 %s %s\n", |
|
100 |
QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)", |
|
101 |
QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); |
|
102 |
} |
|
103 |
||
104 |
void tst_Subtest::test2_data() |
|
105 |
{ |
|
106 |
printf("test2_data %s %s\n", |
|
107 |
QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)", |
|
108 |
QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); |
|
109 |
||
110 |
QTest::addColumn<QString>("str"); |
|
111 |
||
112 |
QTest::newRow("data0") << QString("hello0"); |
|
113 |
QTest::newRow("data1") << QString("hello1"); |
|
114 |
QTest::newRow("data2") << QString("hello2"); |
|
115 |
||
116 |
printf("test2_data end\n"); |
|
117 |
} |
|
118 |
||
119 |
void tst_Subtest::test2() |
|
120 |
{ |
|
121 |
printf("test2 %s %s\n", |
|
122 |
QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)", |
|
123 |
QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); |
|
124 |
||
125 |
static int count = 0; |
|
126 |
||
127 |
QFETCH(QString, str); |
|
128 |
QCOMPARE(str, QString("hello%1").arg(count++)); |
|
129 |
||
130 |
printf("test2 end\n"); |
|
131 |
} |
|
132 |
||
133 |
void tst_Subtest::test3_data() |
|
134 |
{ |
|
135 |
printf("test3_data %s %s\n", |
|
136 |
QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)", |
|
137 |
QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); |
|
138 |
||
139 |
QTest::addColumn<QString>("str"); |
|
140 |
||
141 |
QTest::newRow("data0") << QString("hello0"); |
|
142 |
QTest::newRow("data1") << QString("hello1"); |
|
143 |
QTest::newRow("data2") << QString("hello2"); |
|
144 |
||
145 |
printf("test3_data end\n"); |
|
146 |
} |
|
147 |
||
148 |
void tst_Subtest::test3() |
|
149 |
{ |
|
150 |
printf("test2 %s %s\n", |
|
151 |
QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)", |
|
152 |
QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); |
|
153 |
||
154 |
QFETCH(QString, str); |
|
155 |
||
156 |
// second and third time we call this it shoud FAIL |
|
157 |
QCOMPARE(str, QString("hello0")); |
|
158 |
||
159 |
printf("test2 end\n"); |
|
160 |
} |
|
161 |
||
162 |
void tst_Subtest::floatComparisons() const |
|
163 |
{ |
|
164 |
QFETCH(float, operandLeft); |
|
165 |
QFETCH(float, operandRight); |
|
166 |
||
167 |
QCOMPARE(operandLeft, operandRight); |
|
168 |
} |
|
169 |
||
170 |
void tst_Subtest::floatComparisons_data() const |
|
171 |
{ |
|
172 |
QTest::addColumn<float>("operandLeft"); |
|
173 |
QTest::addColumn<float>("operandRight"); |
|
174 |
||
175 |
QTest::newRow("should SUCCEED") |
|
176 |
<< float(0) |
|
177 |
<< float(0); |
|
178 |
||
179 |
QTest::newRow("should FAIL") |
|
180 |
<< float(1.00000) |
|
181 |
<< float(3.00000); |
|
182 |
||
183 |
QTest::newRow("should FAIL") |
|
184 |
<< float(1.00000e-7f) |
|
185 |
<< float(3.00000e-7f); |
|
186 |
||
187 |
QTest::newRow("should FAIL") |
|
188 |
<< float(100001) |
|
189 |
<< float(100002); |
|
190 |
} |
|
191 |
||
192 |
void tst_Subtest::compareFloatTests() const |
|
193 |
{ |
|
194 |
QFETCH(float, t1); |
|
195 |
||
196 |
// Create two more values |
|
197 |
// t2 differs from t1 by 1 ppm (part per million) |
|
198 |
// t3 differs from t1 by 200% |
|
199 |
// we should consider that t1 == t2 and t1 != t3 |
|
200 |
const float t2 = t1 + (t1 / 1e6); |
|
201 |
const float t3 = 3 * t1; |
|
202 |
||
203 |
QCOMPARE(t1, t2); |
|
204 |
||
205 |
/* Should FAIL. */ |
|
206 |
QCOMPARE(t1, t3); |
|
207 |
} |
|
208 |
||
209 |
void tst_Subtest::compareFloatTests_data() const |
|
210 |
{ |
|
211 |
QTest::addColumn<float>("t1"); |
|
212 |
QTest::newRow("1e0") << 1e0f; |
|
213 |
QTest::newRow("1e-7") << 1e-7f; |
|
214 |
QTest::newRow("1e+7") << 1e+7f; |
|
215 |
} |
|
216 |
||
217 |
QTEST_MAIN(tst_Subtest) |
|
218 |
||
219 |
#include "tst_subtest.moc" |