| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2020 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/QRegularExpression> |
| 32 | #include <QtTest/QtTest> |
| 33 | |
| 34 | class tst_Warnings: public QObject |
| 35 | { |
| 36 | Q_OBJECT |
| 37 | private slots: |
| 38 | void testWarnings(); |
| 39 | void testMissingWarnings(); |
| 40 | void testMissingWarningsRegularExpression(); |
| 41 | void testMissingWarningsWithData_data(); |
| 42 | void testMissingWarningsWithData(); |
| 43 | }; |
| 44 | |
| 45 | void tst_Warnings::testWarnings() |
| 46 | { |
| 47 | qWarning(msg: "Warning" ); |
| 48 | |
| 49 | QTest::ignoreMessage(type: QtWarningMsg, message: "Warning" ); |
| 50 | qWarning(msg: "Warning" ); |
| 51 | |
| 52 | qWarning(msg: "Warning" ); |
| 53 | |
| 54 | qDebug(msg: "Debug" ); |
| 55 | |
| 56 | QTest::ignoreMessage(type: QtDebugMsg, message: "Debug" ); |
| 57 | qDebug(msg: "Debug" ); |
| 58 | |
| 59 | qDebug(msg: "Debug" ); |
| 60 | |
| 61 | qInfo(msg: "Info" ); |
| 62 | |
| 63 | QTest::ignoreMessage(type: QtInfoMsg, message: "Info" ); |
| 64 | qInfo(msg: "Info" ); |
| 65 | |
| 66 | qInfo(msg: "Info" ); |
| 67 | |
| 68 | QTest::ignoreMessage(type: QtDebugMsg, message: "Bubu" ); |
| 69 | qDebug(msg: "Baba" ); |
| 70 | qDebug(msg: "Bubu" ); |
| 71 | qDebug(msg: "Baba" ); |
| 72 | |
| 73 | QTest::ignoreMessage(type: QtDebugMsg, messagePattern: QRegularExpression("^Bubu.*" )); |
| 74 | QTest::ignoreMessage(type: QtWarningMsg, messagePattern: QRegularExpression("^Baba.*" )); |
| 75 | qDebug(msg: "Bubublabla" ); |
| 76 | qWarning(msg: "Babablabla" ); |
| 77 | qDebug(msg: "Bubublabla" ); |
| 78 | qWarning(msg: "Babablabla" ); |
| 79 | |
| 80 | // accept redundant space at end to keep compatibility with Qt < 5.2 |
| 81 | QTest::ignoreMessage(type: QtDebugMsg, message: "Bubu " ); |
| 82 | qDebug() << "Bubu" ; |
| 83 | |
| 84 | // Cope with non-ASCII messages; should be understood as UTF-8 (it comes |
| 85 | // from source code on both sides), even if the system encoding is |
| 86 | // different: |
| 87 | QTest::ignoreMessage(type: QtDebugMsg, message: "Hej v\xc3\xa4rlden" ); |
| 88 | qDebug() << "Hej v\xc3\xa4rlden" ; |
| 89 | QTest::ignoreMessage(type: QtInfoMsg, message: "Hej v\xc3\xa4rlden" ); |
| 90 | qInfo() << "Hej v\xc3\xa4rlden" ; |
| 91 | } |
| 92 | |
| 93 | void tst_Warnings::testMissingWarnings() |
| 94 | { |
| 95 | QTest::ignoreMessage(type: QtWarningMsg, message: "Warning0" ); |
| 96 | QTest::ignoreMessage(type: QtWarningMsg, message: "Warning1" ); |
| 97 | QTest::ignoreMessage(type: QtWarningMsg, message: "Warning2" ); |
| 98 | |
| 99 | qWarning(msg: "Warning2" ); |
| 100 | } |
| 101 | |
| 102 | void tst_Warnings::testMissingWarningsRegularExpression() |
| 103 | { |
| 104 | QTest::ignoreMessage(type: QtWarningMsg, messagePattern: QRegularExpression("Warning\\d\\d" )); |
| 105 | QTest::ignoreMessage(type: QtWarningMsg, messagePattern: QRegularExpression("Warning\\s\\d" )); |
| 106 | |
| 107 | qWarning(msg: "Warning11" ); |
| 108 | } |
| 109 | |
| 110 | void tst_Warnings::testMissingWarningsWithData_data() |
| 111 | { |
| 112 | QTest::addColumn<int>(name: "dummy" ); |
| 113 | |
| 114 | QTest::newRow(dataTag: "first row" ) << 0; |
| 115 | QTest::newRow(dataTag: "second row" ) << 1; |
| 116 | } |
| 117 | |
| 118 | void tst_Warnings::testMissingWarningsWithData() |
| 119 | { |
| 120 | QTest::ignoreMessage(type: QtWarningMsg, message: "Warning0" ); |
| 121 | QTest::ignoreMessage(type: QtWarningMsg, message: "Warning1" ); |
| 122 | QTest::ignoreMessage(type: QtWarningMsg, message: "Warning2" ); |
| 123 | |
| 124 | qWarning(msg: "Warning2" ); |
| 125 | } |
| 126 | |
| 127 | QTEST_MAIN(tst_Warnings) |
| 128 | |
| 129 | #include "tst_warnings.moc" |
| 130 | |