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#include <private/qtestlog_p.h>
32
33class tst_Silent : public QObject
34{
35 Q_OBJECT
36
37private slots:
38 void pass();
39 void skip();
40 void fail();
41 void xfail();
42 void xpass();
43
44 // This test function must be last, as it calls qFatal().
45 void messages();
46};
47
48void tst_Silent::pass()
49{
50 QVERIFY(true);
51}
52
53void tst_Silent::skip()
54{
55 QSKIP("This test should skip");
56}
57
58void tst_Silent::fail()
59{
60 QVERIFY2(false, "This test should fail");
61}
62
63void tst_Silent::xfail()
64{
65 QEXPECT_FAIL("", "This test should XFAIL", Abort);
66 QVERIFY(false);
67}
68
69void tst_Silent::xpass()
70{
71 QEXPECT_FAIL("", "This test should XPASS", Abort);
72 QVERIFY2(true, "This test should XPASS");
73}
74
75#ifndef Q_OS_WIN
76#include <signal.h>
77#include <setjmp.h>
78
79static jmp_buf state;
80static void abort_handler(int)
81{
82 longjmp(env: state, val: 1);
83}
84#endif
85
86void tst_Silent::messages()
87{
88 qWarning(msg: "This is a warning that should not appear in silent test output");
89 QWARN("This is an internal testlib warning that should not appear in silent test output");
90 qDebug(msg: "This is a debug message that should not appear in silent test output");
91 qCritical(msg: "This is a critical message that should not appear in silent test output");
92 qInfo(msg: "This is an info message that should not appear in silent test output");
93 QTestLog::info(msg: "This is an internal testlib info message that should not appear in silent test output", __FILE__, __LINE__);
94
95#ifndef Q_OS_WIN
96 // We're testing qFatal, but we don't want to actually std::abort() !
97 auto prior = signal(SIGABRT, handler: abort_handler);
98 if (setjmp(state))
99 signal(SIGABRT, handler: prior);
100 else
101#endif
102 qFatal(msg: "This is a fatal error message that should still appear in silent test output");
103}
104
105int main(int argc, char *argv[])
106{
107 std::vector<const char*> args(argv, argv + argc);
108 args.push_back(x: "-silent");
109 argc = args.size();
110 argv = const_cast<char**>(&args[0]);
111
112 QTEST_MAIN_IMPL(tst_Silent)
113}
114
115#include "tst_silent.moc"
116

source code of qtbase/tests/auto/testlib/selftests/silent/tst_silent.cpp