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 test suite of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
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 General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #include <QtCore/QCoreApplication> |
30 | #include <QtTest/QtTest> |
31 | |
32 | class tst_Counting : public QObject |
33 | { |
34 | Q_OBJECT |
35 | |
36 | private slots: |
37 | // The following test functions exercise each possible combination of test |
38 | // results for two data rows. |
39 | void testPassPass_data(); |
40 | void testPassPass(); |
41 | |
42 | void testPassSkip_data(); |
43 | void testPassSkip(); |
44 | |
45 | void testPassFail_data(); |
46 | void testPassFail(); |
47 | |
48 | void testSkipPass_data(); |
49 | void testSkipPass(); |
50 | |
51 | void testSkipSkip_data(); |
52 | void testSkipSkip(); |
53 | |
54 | void testSkipFail_data(); |
55 | void testSkipFail(); |
56 | |
57 | void testFailPass_data(); |
58 | void testFailPass(); |
59 | |
60 | void testFailSkip_data(); |
61 | void testFailSkip(); |
62 | |
63 | void testFailFail_data(); |
64 | void testFailFail(); |
65 | |
66 | // The following test functions test skips and fails in the special |
67 | // init() and cleanup() slots. |
68 | void init(); |
69 | void cleanup(); |
70 | void testFailInInit_data(); |
71 | void testFailInInit(); |
72 | void testFailInCleanup_data(); |
73 | void testFailInCleanup(); |
74 | void testSkipInInit_data(); |
75 | void testSkipInInit(); |
76 | void testSkipInCleanup_data(); |
77 | void testSkipInCleanup(); |
78 | |
79 | private: |
80 | void helper(); |
81 | }; |
82 | |
83 | enum TestResult |
84 | { |
85 | Pass, |
86 | Fail, |
87 | Skip |
88 | }; |
89 | |
90 | Q_DECLARE_METATYPE(TestResult); |
91 | |
92 | void tst_Counting::helper() |
93 | { |
94 | QFETCH(TestResult, result); |
95 | |
96 | switch (result) { |
97 | case Pass: |
98 | QVERIFY(true); |
99 | QCOMPARE(2 + 1, 3); |
100 | break; |
101 | case Fail: |
102 | QVERIFY(false); |
103 | break; |
104 | case Skip: |
105 | QSKIP("Skipping" ); |
106 | break; |
107 | } |
108 | } |
109 | |
110 | void tst_Counting::testPassPass_data() |
111 | { |
112 | QTest::addColumn<TestResult>(name: "result" ); |
113 | QTest::newRow(dataTag: "row 1" ) << Pass; |
114 | QTest::newRow(dataTag: "row 2" ) << Pass; |
115 | } |
116 | |
117 | void tst_Counting::testPassPass() |
118 | { |
119 | helper(); |
120 | } |
121 | |
122 | void tst_Counting::testPassSkip_data() |
123 | { |
124 | QTest::addColumn<TestResult>(name: "result" ); |
125 | QTest::newRow(dataTag: "row 1" ) << Pass; |
126 | QTest::newRow(dataTag: "row 2" ) << Skip; |
127 | } |
128 | |
129 | void tst_Counting::testPassSkip() |
130 | { |
131 | helper(); |
132 | } |
133 | |
134 | void tst_Counting::testPassFail_data() |
135 | { |
136 | QTest::addColumn<TestResult>(name: "result" ); |
137 | QTest::newRow(dataTag: "row 1" ) << Pass; |
138 | QTest::newRow(dataTag: "row 2" ) << Fail; |
139 | } |
140 | |
141 | void tst_Counting::testPassFail() |
142 | { |
143 | helper(); |
144 | } |
145 | |
146 | void tst_Counting::testSkipPass_data() |
147 | { |
148 | QTest::addColumn<TestResult>(name: "result" ); |
149 | QTest::newRow(dataTag: "row 1" ) << Skip; |
150 | QTest::newRow(dataTag: "row 2" ) << Pass; |
151 | } |
152 | |
153 | void tst_Counting::testSkipPass() |
154 | { |
155 | helper(); |
156 | } |
157 | |
158 | void tst_Counting::testSkipSkip_data() |
159 | { |
160 | QTest::addColumn<TestResult>(name: "result" ); |
161 | QTest::newRow(dataTag: "row 1" ) << Skip; |
162 | QTest::newRow(dataTag: "row 2" ) << Skip; |
163 | } |
164 | |
165 | void tst_Counting::testSkipSkip() |
166 | { |
167 | helper(); |
168 | } |
169 | |
170 | void tst_Counting::testSkipFail_data() |
171 | { |
172 | QTest::addColumn<TestResult>(name: "result" ); |
173 | QTest::newRow(dataTag: "row 1" ) << Skip; |
174 | QTest::newRow(dataTag: "row 2" ) << Fail; |
175 | } |
176 | |
177 | void tst_Counting::testSkipFail() |
178 | { |
179 | helper(); |
180 | } |
181 | |
182 | void tst_Counting::testFailPass_data() |
183 | { |
184 | QTest::addColumn<TestResult>(name: "result" ); |
185 | QTest::newRow(dataTag: "row 1" ) << Fail; |
186 | QTest::newRow(dataTag: "row 2" ) << Pass; |
187 | } |
188 | |
189 | void tst_Counting::testFailPass() |
190 | { |
191 | helper(); |
192 | } |
193 | |
194 | void tst_Counting::testFailSkip_data() |
195 | { |
196 | QTest::addColumn<TestResult>(name: "result" ); |
197 | QTest::newRow(dataTag: "row 1" ) << Fail; |
198 | QTest::newRow(dataTag: "row 2" ) << Skip; |
199 | } |
200 | |
201 | void tst_Counting::testFailSkip() |
202 | { |
203 | helper(); |
204 | } |
205 | |
206 | void tst_Counting::testFailFail_data() |
207 | { |
208 | QTest::addColumn<TestResult>(name: "result" ); |
209 | QTest::newRow(dataTag: "row 1" ) << Fail; |
210 | QTest::newRow(dataTag: "row 2" ) << Fail; |
211 | } |
212 | |
213 | void tst_Counting::testFailFail() |
214 | { |
215 | helper(); |
216 | } |
217 | |
218 | void tst_Counting::init() |
219 | { |
220 | if (strcmp(s1: QTest::currentTestFunction(), s2: "testFailInInit" ) == 0 && strcmp(s1: QTest::currentDataTag(), s2: "fail" ) == 0) |
221 | QFAIL("Fail in init()" ); |
222 | else if (strcmp(s1: QTest::currentTestFunction(), s2: "testSkipInInit" ) == 0 && strcmp(s1: QTest::currentDataTag(), s2: "skip" ) == 0) |
223 | QSKIP("Skip in init()" ); |
224 | } |
225 | |
226 | void tst_Counting::cleanup() |
227 | { |
228 | if (strcmp(s1: QTest::currentTestFunction(), s2: "testFailInCleanup" ) == 0 && strcmp(s1: QTest::currentDataTag(), s2: "fail" ) == 0) |
229 | QFAIL("Fail in cleanup()" ); |
230 | else if (strcmp(s1: QTest::currentTestFunction(), s2: "testSkipInCleanup" ) == 0 && strcmp(s1: QTest::currentDataTag(), s2: "skip" ) == 0) |
231 | QSKIP("Skip in cleanup()" ); |
232 | } |
233 | |
234 | void tst_Counting::testFailInInit_data() |
235 | { |
236 | QTest::addColumn<bool>(name: "dummy" ); |
237 | QTest::newRow(dataTag: "before" ) << true; |
238 | QTest::newRow(dataTag: "fail" ) << true; |
239 | QTest::newRow(dataTag: "after" ) << true; |
240 | } |
241 | |
242 | void tst_Counting::testFailInInit() |
243 | { |
244 | if (strcmp(s1: QTest::currentDataTag(), s2: "fail" ) == 0) |
245 | QFAIL("This test function should have been skipped due to QFAIL in init()" ); |
246 | } |
247 | |
248 | void tst_Counting::testFailInCleanup_data() |
249 | { |
250 | QTest::addColumn<bool>(name: "dummy" ); |
251 | QTest::newRow(dataTag: "before" ) << true; |
252 | QTest::newRow(dataTag: "fail" ) << true; |
253 | QTest::newRow(dataTag: "after" ) << true; |
254 | } |
255 | |
256 | void tst_Counting::testFailInCleanup() |
257 | { |
258 | if (strcmp(s1: QTest::currentDataTag(), s2: "fail" ) == 0) |
259 | qDebug() << "This test function should execute and then QFAIL in cleanup()" ; |
260 | } |
261 | |
262 | void tst_Counting::testSkipInInit_data() |
263 | { |
264 | QTest::addColumn<bool>(name: "dummy" ); |
265 | QTest::newRow(dataTag: "before" ) << true; |
266 | QTest::newRow(dataTag: "skip" ) << true; |
267 | QTest::newRow(dataTag: "after" ) << true; |
268 | } |
269 | |
270 | void tst_Counting::testSkipInInit() |
271 | { |
272 | if (strcmp(s1: QTest::currentDataTag(), s2: "skip" ) == 0) |
273 | QFAIL("This test function should have been skipped due to QSKIP in init()" ); |
274 | } |
275 | |
276 | void tst_Counting::testSkipInCleanup_data() |
277 | { |
278 | QTest::addColumn<bool>(name: "dummy" ); |
279 | QTest::newRow(dataTag: "before" ) << true; |
280 | QTest::newRow(dataTag: "skip" ) << true; |
281 | QTest::newRow(dataTag: "after" ) << true; |
282 | } |
283 | |
284 | void tst_Counting::testSkipInCleanup() |
285 | { |
286 | if (strcmp(s1: QTest::currentDataTag(), s2: "skip" ) == 0) |
287 | qDebug() << "This test function should execute and then QSKIP in cleanup()" ; |
288 | } |
289 | |
290 | int main(int argc, char *argv[]) |
291 | { |
292 | #ifdef TESTLIB_VERBOSITY_ARG |
293 | std::vector<const char*> args(argv, argv + argc); |
294 | args.push_back(QT_STRINGIFY(TESTLIB_VERBOSITY_ARG)); |
295 | argc = args.size(); |
296 | argv = const_cast<char**>(&args[0]); |
297 | #endif |
298 | |
299 | QTEST_MAIN_IMPL(tst_Counting) |
300 | } |
301 | #include "tst_counting.moc" |
302 | |