1/****************************************************************************
2**
3** Copyright (C) 2018 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#include <QProcess>
29#include <QtTest>
30
31class tst_TestFiltering : public QObject
32{
33 Q_OBJECT
34private slots:
35 void noFilters();
36 void oneMatchingFilter();
37 void filterThatDoesntMatch();
38 void twoFilters();
39 void twoFiltersWithOneMatch();
40 void manyFilters();
41 void filterTestWithDefaultDataTags();
42 void filterTestWithDataTags();
43 void filterTestByDataTag();
44 void filterInvalidDataTag();
45};
46
47
48const QString testExe =
49#if defined(Q_OS_WIN)
50 QFINDTESTDATA("quicktestmain/quicktestmain.exe");
51#else
52 QFINDTESTDATA("quicktestmain/quicktestmain");
53#endif
54
55void tst_TestFiltering::noFilters()
56{
57 QProcess process;
58 process.start(command: testExe);
59
60 QVERIFY(process.waitForFinished());
61
62 const QString output = process.readAll();
63 QVERIFY(output.contains(QLatin1String("Totals: 17 passed")));
64 QVERIFY(output.contains(QLatin1String(", 3 skipped")));
65 QCOMPARE(process.exitStatus(), QProcess::NormalExit);
66 QCOMPARE(process.exitCode(), 0);
67}
68
69void tst_TestFiltering::oneMatchingFilter()
70{
71 QProcess process;
72 process.start(program: testExe, arguments: {QLatin1String("First::test_bar")});
73
74 QVERIFY(process.waitForFinished());
75
76 const QString output = process.readAll();
77 QVERIFY(output.contains(QLatin1String("Totals: 3 passed")));
78 QCOMPARE(process.exitStatus(), QProcess::NormalExit);
79 QCOMPARE(process.exitCode(), 0);
80}
81
82void tst_TestFiltering::filterThatDoesntMatch()
83{
84 QProcess process;
85 process.start(program: testExe, arguments: {QLatin1String("First::test_nonexisting")});
86
87 QVERIFY(process.waitForFinished());
88
89 QCOMPARE(process.exitStatus(), QProcess::NormalExit);
90 QCOMPARE(process.exitCode(), 1);
91}
92
93void tst_TestFiltering::twoFilters()
94{
95 QProcess process;
96 process.start(program: testExe,
97 arguments: {QLatin1String("Second::test_dupfoo"), QLatin1String("Second::test_dupbaz")});
98
99 QVERIFY(process.waitForFinished());
100
101 const QString output = process.readAll();
102 QVERIFY(output.contains(QLatin1String("Totals: 4 passed")));
103 QCOMPARE(process.exitStatus(), QProcess::NormalExit);
104 QCOMPARE(process.exitCode(), 0);
105}
106
107void tst_TestFiltering::twoFiltersWithOneMatch()
108{
109 QProcess process;
110 process.start(program: testExe,
111 arguments: {QLatin1String("First::test_foo"), QLatin1String("Second::test_nonexisting")});
112
113 QVERIFY(process.waitForFinished());
114
115 const QString output = process.readAll();
116 QVERIFY(output.contains(QLatin1String("Totals: 3 passed")));
117 QCOMPARE(process.exitStatus(), QProcess::NormalExit);
118 QCOMPARE(process.exitCode(), 1);
119}
120
121void tst_TestFiltering::manyFilters()
122{
123 QProcess process;
124 process.start(program: testExe,
125 arguments: {QLatin1String("First::test_foo"),
126 QLatin1String("First::test_baz"),
127 QLatin1String("Second::test_dupfoo"),
128 QLatin1String("Second::test_dupbaz")});
129
130 QVERIFY(process.waitForFinished());
131
132 const QString output = process.readAll();
133 QVERIFY(output.contains(QLatin1String("Totals: 8 passed")));
134 QCOMPARE(process.exitStatus(), QProcess::NormalExit);
135 QCOMPARE(process.exitCode(), 0);
136}
137
138void tst_TestFiltering::filterTestWithDefaultDataTags()
139{
140 QProcess process;
141 process.start(program: testExe, arguments: { QLatin1String("Third::test_default_tags"), });
142
143 QVERIFY(process.waitForFinished());
144
145 const QString output = process.readAll();
146 QVERIFY(output.contains(QLatin1String("Totals: 5 passed")));
147 QVERIFY(output.contains(QLatin1String(" 2 skipped")));
148 QCOMPARE(process.exitStatus(), QProcess::NormalExit);
149 QCOMPARE(process.exitCode(), 0);
150}
151
152void tst_TestFiltering::filterTestWithDataTags()
153{
154 QProcess process;
155 process.start(program: testExe, arguments: { QLatin1String("Third::test_tags"), });
156
157 QVERIFY(process.waitForFinished());
158
159 const QString output = process.readAll();
160 QVERIFY(output.contains(QLatin1String("Totals: 4 passed")));
161 QVERIFY(output.contains(QLatin1String(" 1 skipped")));
162 QCOMPARE(process.exitStatus(), QProcess::NormalExit);
163 QCOMPARE(process.exitCode(), 0);
164}
165
166void tst_TestFiltering::filterTestByDataTag()
167{
168 QProcess process;
169 process.start(program: testExe, arguments: { QLatin1String("Third::test_default_tags:init_2"),
170 QLatin1String("Third::test_default_tags:skip_3"),
171 QLatin1String("Third::test_tags:baz"),
172 QLatin1String("Third::test_tags:bar"), });
173
174 QVERIFY(process.waitForFinished());
175
176 const QString output = process.readAll();
177 QVERIFY(output.contains(QLatin1String("Totals: 4 passed")));
178 QVERIFY(output.contains(QLatin1String(" 2 skipped")));
179 QCOMPARE(process.exitStatus(), QProcess::NormalExit);
180 QCOMPARE(process.exitCode(), 0);
181}
182
183void tst_TestFiltering::filterInvalidDataTag()
184{
185 QProcess process;
186 process.start(program: testExe, arguments: { QLatin1String("Third::test_tags:invalid_tag") });
187
188 QVERIFY(process.waitForFinished());
189
190 QCOMPARE(process.exitStatus(), QProcess::NormalExit);
191 QCOMPARE(process.exitCode(), 1);
192}
193
194QTEST_MAIN(tst_TestFiltering);
195
196#include "tst_testfiltering.moc"
197

source code of qtdeclarative/tests/auto/quicktest/testfiltering/tst_testfiltering.cpp