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 <QtTest/QtTest>
32#include <QDebug>
33
34class tst_globaldata: public QObject
35{
36 Q_OBJECT
37public slots:
38 void init();
39 void initTestCase();
40 void initTestCase_data();
41
42 void cleanup();
43 void cleanupTestCase();
44
45private slots:
46 void testGlobal_data();
47 void testGlobal();
48
49 void skip_data();
50 void skip();
51
52 void skipLocal_data() { testGlobal_data(); }
53 void skipLocal();
54
55 void skipSingle_data() { testGlobal_data(); }
56 void skipSingle();
57};
58
59
60void tst_globaldata::initTestCase()
61{
62 qDebug() << "initTestCase"
63 << (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)")
64 << (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)");
65}
66
67void tst_globaldata::initTestCase_data()
68{
69 // QFETCH_GLOBAL shall iterate these, for every test:
70 QTest::addColumn<bool>(name: "global");
71 QTest::newRow(dataTag: "global=false") << false;
72 QTest::newRow(dataTag: "global=true") << true;
73}
74
75void tst_globaldata::cleanupTestCase()
76{
77 qDebug() << "cleanupTestCase"
78 << (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)")
79 << (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)");
80}
81
82void tst_globaldata::init()
83{
84 qDebug() << "init"
85 << (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)")
86 << (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)");
87}
88
89void tst_globaldata::cleanup()
90{
91 qDebug() << "cleanup"
92 << (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)")
93 << (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)");
94}
95
96void tst_globaldata::testGlobal_data()
97{
98 QTest::addColumn<bool>(name: "local");
99 QTest::newRow(dataTag: "local=false") << false;
100 QTest::newRow(dataTag: "local=true") << true;
101}
102
103void tst_globaldata::testGlobal()
104{
105 QFETCH_GLOBAL(bool, global);
106 qDebug() << "global:" << global;
107 QFETCH(bool, local);
108 qDebug() << "local:" << local;
109}
110
111void tst_globaldata::skip_data()
112{
113 testGlobal_data();
114 QSKIP("skipping");
115}
116
117void tst_globaldata::skip()
118{
119 // A skip in _data() causes the whole test to be skipped, for all global rows.
120 QVERIFY(!"This line should never be reached.");
121}
122
123void tst_globaldata::skipSingle()
124{
125 QFETCH_GLOBAL(bool, global);
126 QFETCH(bool, local);
127
128 // A skip in the last run of one global row used to suppress the test in the
129 // next global row (where a skip in an earlier run of the first row did not).
130 if (global ^ local)
131 QSKIP("Skipping");
132 qDebug() << "global:" << global << "local:" << local;
133 QCOMPARE(global, local);
134}
135
136void tst_globaldata::skipLocal()
137{
138 QSKIP("skipping");
139}
140
141QTEST_MAIN(tst_globaldata)
142
143#include "tst_globaldata.moc"
144

source code of qtbase/tests/auto/testlib/selftests/globaldata/tst_globaldata.cpp