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