| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/testlib/qsignaldumper.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 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 QtTest module of the Qt Toolkit. | - | ||||||||||||
| 7 | ** | - | ||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
| 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 Lesser General Public License Usage | - | ||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
| 24 | ** | - | ||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
| 35 | ** | - | ||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 37 | ** | - | ||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | #include <QtTest/private/qsignaldumper_p.h> | - | ||||||||||||
| 41 | - | |||||||||||||
| 42 | #include <QtCore/qlist.h> | - | ||||||||||||
| 43 | #include <QtCore/qmetaobject.h> | - | ||||||||||||
| 44 | #include <QtCore/qmetatype.h> | - | ||||||||||||
| 45 | #include <QtCore/qobject.h> | - | ||||||||||||
| 46 | #include <QtCore/qvariant.h> | - | ||||||||||||
| 47 | - | |||||||||||||
| 48 | #include <QtTest/private/qtestlog_p.h> | - | ||||||||||||
| 49 | - | |||||||||||||
| 50 | #include <QtCore/private/qmetaobject_p.h> | - | ||||||||||||
| 51 | - | |||||||||||||
| 52 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 53 | - | |||||||||||||
| 54 | namespace QTest | - | ||||||||||||
| 55 | { | - | ||||||||||||
| 56 | - | |||||||||||||
| 57 | inline static void qPrintMessage(const QByteArray &ba) | - | ||||||||||||
| 58 | { | - | ||||||||||||
| 59 | QTestLog::info(ba.constData(), 0, 0); | - | ||||||||||||
| 60 | } never executed: end of block | 0 | ||||||||||||
| 61 | - | |||||||||||||
| 62 | Q_GLOBAL_STATIC(QList<QByteArray>, ignoreClasses) never executed: end of blocknever executed: guard.store(QtGlobalStatic::Destroyed);never executed: return &holder.value;
| 0 | ||||||||||||
| 63 | static int iLevel = 0; | - | ||||||||||||
| 64 | static int ignoreLevel = 0; | - | ||||||||||||
| 65 | enum { IndentSpacesCount = 4 }; | - | ||||||||||||
| 66 | - | |||||||||||||
| 67 | static void qSignalDumperCallback(QObject *caller, int signal_index, void **argv) | - | ||||||||||||
| 68 | { | - | ||||||||||||
| 69 | Q_ASSERT(caller); Q_ASSERT(argv); Q_UNUSED(argv); | - | ||||||||||||
| 70 | const QMetaObject *mo = caller->metaObject(); | - | ||||||||||||
| 71 | Q_ASSERT(mo); | - | ||||||||||||
| 72 | QMetaMethod member = QMetaObjectPrivate::signal(mo, signal_index); | - | ||||||||||||
| 73 | Q_ASSERT(member.isValid()); | - | ||||||||||||
| 74 | - | |||||||||||||
| 75 | if (QTest::ignoreClasses() && QTest::ignoreClasses()->contains(mo->className())) {
| 0 | ||||||||||||
| 76 | ++QTest::ignoreLevel; | - | ||||||||||||
| 77 | return; never executed: return; | 0 | ||||||||||||
| 78 | } | - | ||||||||||||
| 79 | - | |||||||||||||
| 80 | QByteArray str; | - | ||||||||||||
| 81 | str.fill(' ', QTest::iLevel++ * QTest::IndentSpacesCount); | - | ||||||||||||
| 82 | str += "Signal: "; | - | ||||||||||||
| 83 | str += mo->className(); | - | ||||||||||||
| 84 | str += '('; | - | ||||||||||||
| 85 | - | |||||||||||||
| 86 | QString objname = caller->objectName(); | - | ||||||||||||
| 87 | str += objname.toLocal8Bit(); | - | ||||||||||||
| 88 | if (!objname.isEmpty())
| 0 | ||||||||||||
| 89 | str += ' '; never executed: str += ' '; | 0 | ||||||||||||
| 90 | str += QByteArray::number(quintptr(caller), 16); | - | ||||||||||||
| 91 | - | |||||||||||||
| 92 | str += ") "; | - | ||||||||||||
| 93 | str += member.name(); | - | ||||||||||||
| 94 | str += " ("; | - | ||||||||||||
| 95 | - | |||||||||||||
| 96 | QList<QByteArray> args = member.parameterTypes(); | - | ||||||||||||
| 97 | for (int i = 0; i < args.count(); ++i) {
| 0 | ||||||||||||
| 98 | const QByteArray &arg = args.at(i); | - | ||||||||||||
| 99 | int typeId = QMetaType::type(args.at(i).constData()); | - | ||||||||||||
| 100 | if (arg.endsWith('*') || arg.endsWith('&')) {
| 0 | ||||||||||||
| 101 | str += '('; | - | ||||||||||||
| 102 | str += arg; | - | ||||||||||||
| 103 | str += ')'; | - | ||||||||||||
| 104 | if (arg.endsWith('&'))
| 0 | ||||||||||||
| 105 | str += '@'; never executed: str += '@'; | 0 | ||||||||||||
| 106 | - | |||||||||||||
| 107 | quintptr addr = quintptr(*reinterpret_cast<void **>(argv[i + 1])); | - | ||||||||||||
| 108 | str.append(QByteArray::number(addr, 16)); | - | ||||||||||||
| 109 | } else if (typeId != QMetaType::UnknownType) { never executed: end of block
| 0 | ||||||||||||
| 110 | Q_ASSERT(typeId != QMetaType::Void); // void parameter => metaobject is corrupt | - | ||||||||||||
| 111 | str.append(arg) | - | ||||||||||||
| 112 | .append('(') | - | ||||||||||||
| 113 | .append(QVariant(typeId, argv[i + 1]).toString().toLocal8Bit()) | - | ||||||||||||
| 114 | .append(')'); | - | ||||||||||||
| 115 | } never executed: end of block | 0 | ||||||||||||
| 116 | str.append(", "); | - | ||||||||||||
| 117 | } never executed: end of block | 0 | ||||||||||||
| 118 | if (str.endsWith(", "))
| 0 | ||||||||||||
| 119 | str.chop(2); never executed: str.chop(2); | 0 | ||||||||||||
| 120 | str.append(')'); | - | ||||||||||||
| 121 | qPrintMessage(str); | - | ||||||||||||
| 122 | } never executed: end of block | 0 | ||||||||||||
| 123 | - | |||||||||||||
| 124 | static void qSignalDumperCallbackSlot(QObject *caller, int method_index, void **argv) | - | ||||||||||||
| 125 | { | - | ||||||||||||
| 126 | Q_ASSERT(caller); Q_ASSERT(argv); Q_UNUSED(argv); | - | ||||||||||||
| 127 | const QMetaObject *mo = caller->metaObject(); | - | ||||||||||||
| 128 | Q_ASSERT(mo); | - | ||||||||||||
| 129 | QMetaMethod member = mo->method(method_index); | - | ||||||||||||
| 130 | if (!member.isValid())
| 0 | ||||||||||||
| 131 | return; never executed: return; | 0 | ||||||||||||
| 132 | - | |||||||||||||
| 133 | if (QTest::ignoreLevel ||
| 0 | ||||||||||||
| 134 | (QTest::ignoreClasses() && QTest::ignoreClasses()->contains(mo->className())))
| 0 | ||||||||||||
| 135 | return; never executed: return; | 0 | ||||||||||||
| 136 | - | |||||||||||||
| 137 | QByteArray str; | - | ||||||||||||
| 138 | str.fill(' ', QTest::iLevel * QTest::IndentSpacesCount); | - | ||||||||||||
| 139 | str += "Slot: "; | - | ||||||||||||
| 140 | str += mo->className(); | - | ||||||||||||
| 141 | str += '('; | - | ||||||||||||
| 142 | - | |||||||||||||
| 143 | QString objname = caller->objectName(); | - | ||||||||||||
| 144 | str += objname.toLocal8Bit(); | - | ||||||||||||
| 145 | if (!objname.isEmpty())
| 0 | ||||||||||||
| 146 | str += ' '; never executed: str += ' '; | 0 | ||||||||||||
| 147 | str += QByteArray::number(quintptr(caller), 16); | - | ||||||||||||
| 148 | - | |||||||||||||
| 149 | str += ") "; | - | ||||||||||||
| 150 | str += member.methodSignature(); | - | ||||||||||||
| 151 | qPrintMessage(str); | - | ||||||||||||
| 152 | } never executed: end of block | 0 | ||||||||||||
| 153 | - | |||||||||||||
| 154 | static void qSignalDumperCallbackEndSignal(QObject *caller, int /*signal_index*/) | - | ||||||||||||
| 155 | { | - | ||||||||||||
| 156 | Q_ASSERT(caller); Q_ASSERT(caller->metaObject()); | - | ||||||||||||
| 157 | if (QTest::ignoreClasses()
| 0 | ||||||||||||
| 158 | && QTest::ignoreClasses()->contains(caller->metaObject()->className())) {
| 0 | ||||||||||||
| 159 | --QTest::ignoreLevel; | - | ||||||||||||
| 160 | Q_ASSERT(QTest::ignoreLevel >= 0); | - | ||||||||||||
| 161 | return; never executed: return; | 0 | ||||||||||||
| 162 | } | - | ||||||||||||
| 163 | --QTest::iLevel; | - | ||||||||||||
| 164 | Q_ASSERT(QTest::iLevel >= 0); | - | ||||||||||||
| 165 | } never executed: end of block | 0 | ||||||||||||
| 166 | - | |||||||||||||
| 167 | } | - | ||||||||||||
| 168 | - | |||||||||||||
| 169 | void QSignalDumper::startDump() | - | ||||||||||||
| 170 | { | - | ||||||||||||
| 171 | static QSignalSpyCallbackSet set = { QTest::qSignalDumperCallback, | - | ||||||||||||
| 172 | QTest::qSignalDumperCallbackSlot, QTest::qSignalDumperCallbackEndSignal, 0 }; | - | ||||||||||||
| 173 | qt_register_signal_spy_callbacks(set); | - | ||||||||||||
| 174 | } never executed: end of block | 0 | ||||||||||||
| 175 | - | |||||||||||||
| 176 | void QSignalDumper::endDump() | - | ||||||||||||
| 177 | { | - | ||||||||||||
| 178 | static QSignalSpyCallbackSet nset = { 0, 0, 0 ,0 }; | - | ||||||||||||
| 179 | qt_register_signal_spy_callbacks(nset); | - | ||||||||||||
| 180 | } executed 1238 times by 508 tests: end of blockExecuted by:
| 1238 | ||||||||||||
| 181 | - | |||||||||||||
| 182 | void QSignalDumper::ignoreClass(const QByteArray &klass) | - | ||||||||||||
| 183 | { | - | ||||||||||||
| 184 | if (QTest::ignoreClasses())
| 0 | ||||||||||||
| 185 | QTest::ignoreClasses()->append(klass); never executed: QTest::ignoreClasses()->append(klass); | 0 | ||||||||||||
| 186 | } never executed: end of block | 0 | ||||||||||||
| 187 | - | |||||||||||||
| 188 | void QSignalDumper::clearIgnoredClasses() | - | ||||||||||||
| 189 | { | - | ||||||||||||
| 190 | if (QTest::ignoreClasses())
| 0 | ||||||||||||
| 191 | QTest::ignoreClasses()->clear(); never executed: QTest::ignoreClasses()->clear(); | 0 | ||||||||||||
| 192 | } never executed: end of block | 0 | ||||||||||||
| 193 | - | |||||||||||||
| 194 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |