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
30#include <QtCore/QCoreApplication>
31#include <QtCore/QDebug>
32#include <QtTest/QtTest>
33
34class tst_Subtest: public QObject
35{
36 Q_OBJECT
37public slots:
38 void init();
39 void initTestCase();
40
41 void cleanup();
42 void cleanupTestCase();
43
44private slots:
45 void test1();
46 void test2_data();
47 void test2();
48 void test3_data();
49 void test3();
50};
51
52
53void tst_Subtest::initTestCase()
54{
55 qDebug() << "initTestCase"
56 << (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)")
57 << (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)");
58}
59
60void tst_Subtest::cleanupTestCase()
61{
62 qDebug() << "cleanupTestCase"
63 << (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)")
64 << (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)");
65}
66
67void tst_Subtest::init()
68{
69 qDebug() << "init"
70 << (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)")
71 << (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)");
72}
73
74void tst_Subtest::cleanup()
75{
76 qDebug() << "cleanup"
77 << (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)")
78 << (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)");
79}
80
81void tst_Subtest::test1()
82{
83 qDebug() << "test1"
84 << (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)")
85 << (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)");
86}
87
88void tst_Subtest::test2_data()
89{
90 qDebug() << "test2_data"
91 << (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)")
92 << (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)");
93
94 QTest::addColumn<QString>(name: "str");
95
96 QTest::newRow(dataTag: "data0") << QString("hello0");
97 QTest::newRow(dataTag: "data1") << QString("hello1");
98 QTest::newRow(dataTag: "data2") << QString("hello2");
99
100 qDebug() << "test2_data end";
101}
102
103void tst_Subtest::test2()
104{
105 qDebug() << "test2"
106 << (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)")
107 << (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)");
108
109 static int count = 0;
110
111 QFETCH(QString, str);
112 QCOMPARE(str, QString("hello%1").arg(count++));
113
114 qDebug() << "test2 end";
115}
116
117void tst_Subtest::test3_data()
118{
119 qDebug() << "test3_data"
120 << (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)")
121 << (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)");
122
123 QTest::addColumn<QString>(name: "str");
124
125 QTest::newRow(dataTag: "data0") << QString("hello0");
126 QTest::newRow(dataTag: "data1") << QString("hello1");
127 QTest::newRow(dataTag: "data2") << QString("hello2");
128
129 qDebug() << "test3_data end";
130}
131
132void tst_Subtest::test3()
133{
134 qDebug() << "test2"
135 << (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)")
136 << (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)");
137
138 QFETCH(QString, str);
139
140 // second and third time we call this it should FAIL
141 QCOMPARE(str, QString("hello0"));
142
143 qDebug() << "test2 end";
144}
145
146QTEST_MAIN(tst_Subtest)
147
148#include "tst_subtest.moc"
149

source code of qtbase/tests/auto/testlib/selftests/subtest/tst_subtest.cpp