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 | |
33 | class tst_Blacklisted : public QObject |
34 | { |
35 | Q_OBJECT |
36 | |
37 | private 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 | |
48 | // All the tests below except pass() have been blacklisted in blacklisted/BLACKLIST |
49 | // Contrast with ../silent/, for the same tests without blacklisting but with -silent |
50 | |
51 | void tst_Blacklisted::pass() |
52 | { |
53 | QVERIFY(true); |
54 | } |
55 | |
56 | void tst_Blacklisted::skip() |
57 | { |
58 | QSKIP("This test should SKIP" ); |
59 | } |
60 | |
61 | void tst_Blacklisted::fail() |
62 | { |
63 | QVERIFY2(false, "This test should BFAIL" ); |
64 | } |
65 | |
66 | void tst_Blacklisted::xfail() |
67 | { |
68 | QEXPECT_FAIL("" , "This test should BXFAIL then BPASS" , Abort); |
69 | QVERIFY(false); |
70 | } |
71 | |
72 | void tst_Blacklisted::xpass() |
73 | { |
74 | QEXPECT_FAIL("" , "This test should BXPASS" , Abort); |
75 | QVERIFY2(true, "This test should BXPASS" ); |
76 | } |
77 | |
78 | #ifndef Q_OS_WIN |
79 | #include <signal.h> |
80 | #include <setjmp.h> |
81 | |
82 | static jmp_buf state; |
83 | static void abort_handler(int) |
84 | { |
85 | longjmp(env: state, val: 1); |
86 | } |
87 | #endif |
88 | |
89 | void tst_Blacklisted::messages() |
90 | { |
91 | qWarning(msg: "This is a warning that should not appear in silent test output" ); |
92 | QWARN("This is an internal testlib warning that should not appear in silent test output" ); |
93 | qDebug(msg: "This is a debug message that should not appear in silent test output" ); |
94 | qCritical(msg: "This is a critical message that should not appear in silent test output" ); |
95 | qInfo(msg: "This is an info message that should not appear in silent test output" ); |
96 | QTestLog::info(msg: "This is an internal testlib info message that should not appear in silent test output" , __FILE__, __LINE__); |
97 | |
98 | #ifndef Q_OS_WIN |
99 | // We're testing qFatal, but we don't want to actually std::abort() ! |
100 | auto prior = signal(SIGABRT, handler: abort_handler); |
101 | if (setjmp(state)) |
102 | signal(SIGABRT, handler: prior); |
103 | else |
104 | #endif |
105 | qFatal(msg: "This is a fatal error message that should still appear in silent test output" ); |
106 | } |
107 | |
108 | QTEST_MAIN(tst_Blacklisted) |
109 | #include "tst_blacklisted.moc" |
110 | |