tst_QMetaObject: change tests to forward-declared-only
The type MyUnregisteredType needs to be only forward-declared for the
trick to work. The issue is not about registration, because since commit
fa987d4441
("MetaObject: Store the
QMetaType of the methods"), we will record the meta type of the type
anyway, which will eventually allow the meta object to actually find
this type.
Instead, the tests are valid for a type that is only forward-declared.
Change-Id: I36b24183fbd041179f2ffffd1702182746f7c1b2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
parent
1b96b645ec
commit
06c3de5ee3
@ -1,15 +1,13 @@
|
|||||||
# Generated from qmetaobject.pro.
|
set(tst_qmetaobject_SOURCES
|
||||||
|
tst_qmetaobject.cpp
|
||||||
#####################################################################
|
forwarddeclared.h
|
||||||
## tst_qmetaobject Test:
|
forwarddeclared.cpp
|
||||||
#####################################################################
|
)
|
||||||
|
|
||||||
qt_internal_add_test(tst_qmetaobject
|
qt_internal_add_test(tst_qmetaobject
|
||||||
SOURCES
|
SOURCES
|
||||||
tst_qmetaobject.cpp
|
${tst_qmetaobject_SOURCES}
|
||||||
PUBLIC_LIBRARIES
|
PUBLIC_LIBRARIES
|
||||||
Qt::CorePrivate
|
Qt::CorePrivate
|
||||||
)
|
)
|
||||||
|
|
||||||
## Scopes:
|
|
||||||
#####################################################################
|
|
||||||
|
12
tests/auto/corelib/kernel/qmetaobject/forwarddeclared.cpp
Normal file
12
tests/auto/corelib/kernel/qmetaobject/forwarddeclared.cpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright (C) 2022 Intel Corporation.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||||
|
|
||||||
|
#include "forwarddeclared.h"
|
||||||
|
|
||||||
|
struct MyForwardDeclaredType { };
|
||||||
|
static const MyForwardDeclaredType t;
|
||||||
|
|
||||||
|
const MyForwardDeclaredType &getForwardDeclaredType() noexcept
|
||||||
|
{
|
||||||
|
return t;
|
||||||
|
}
|
11
tests/auto/corelib/kernel/qmetaobject/forwarddeclared.h
Normal file
11
tests/auto/corelib/kernel/qmetaobject/forwarddeclared.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// Copyright (C) 2022 Intel Corporation.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||||
|
|
||||||
|
#ifndef FORWARDDECLARED_H
|
||||||
|
#define FORWARDDECLARED_H
|
||||||
|
|
||||||
|
struct MyForwardDeclaredType; // and ONLY forward-declared
|
||||||
|
|
||||||
|
const MyForwardDeclaredType &getForwardDeclaredType() noexcept;
|
||||||
|
|
||||||
|
#endif // FORWARDDECLARED_H
|
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
Q_DECLARE_METATYPE(const QMetaObject *)
|
Q_DECLARE_METATYPE(const QMetaObject *)
|
||||||
|
|
||||||
|
#include "forwarddeclared.h"
|
||||||
|
|
||||||
struct MyStruct
|
struct MyStruct
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -215,8 +217,7 @@ namespace MyNamespace {
|
|||||||
int m_value2 = 0;
|
int m_value2 = 0;
|
||||||
int m_value3 = 0;
|
int m_value3 = 0;
|
||||||
};
|
};
|
||||||
}
|
} // namespace MyNamespace
|
||||||
|
|
||||||
|
|
||||||
class tst_QMetaObject : public QObject
|
class tst_QMetaObject : public QObject
|
||||||
{
|
{
|
||||||
@ -435,8 +436,6 @@ void tst_QMetaObject::connectSlotsByName()
|
|||||||
QCOMPARE(obj2.invokeCount2, 1);
|
QCOMPARE(obj2.invokeCount2, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MyUnregisteredType { };
|
|
||||||
|
|
||||||
static int countedStructObjectsCount = 0;
|
static int countedStructObjectsCount = 0;
|
||||||
struct CountedStruct
|
struct CountedStruct
|
||||||
{
|
{
|
||||||
@ -488,8 +487,8 @@ public slots:
|
|||||||
void moveToThread(QThread *t)
|
void moveToThread(QThread *t)
|
||||||
{ QObject::moveToThread(t); }
|
{ QObject::moveToThread(t); }
|
||||||
|
|
||||||
void slotWithUnregisteredParameterType(MyUnregisteredType);
|
void slotWithUnregisteredParameterType(const MyForwardDeclaredType &);
|
||||||
void slotWithOneUnregisteredParameterType(QString a1, MyUnregisteredType a2);
|
void slotWithOneUnregisteredParameterType(QString a1, const MyForwardDeclaredType &a2);
|
||||||
|
|
||||||
CountedStruct throwingSlot(const CountedStruct &, CountedStruct s2) {
|
CountedStruct throwingSlot(const CountedStruct &, CountedStruct s2) {
|
||||||
#ifndef QT_NO_EXCEPTIONS
|
#ifndef QT_NO_EXCEPTIONS
|
||||||
@ -584,10 +583,10 @@ void QtTestObject::testSender()
|
|||||||
slotResult = QString::asprintf("%p", sender());
|
slotResult = QString::asprintf("%p", sender());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtTestObject::slotWithUnregisteredParameterType(MyUnregisteredType)
|
void QtTestObject::slotWithUnregisteredParameterType(const MyForwardDeclaredType &)
|
||||||
{ slotResult = "slotWithUnregisteredReturnType"; }
|
{ slotResult = "slotWithUnregisteredReturnType"; }
|
||||||
|
|
||||||
void QtTestObject::slotWithOneUnregisteredParameterType(QString a1, MyUnregisteredType)
|
void QtTestObject::slotWithOneUnregisteredParameterType(QString a1, const MyForwardDeclaredType &)
|
||||||
{ slotResult = "slotWithUnregisteredReturnType-" + a1; }
|
{ slotResult = "slotWithUnregisteredReturnType-" + a1; }
|
||||||
|
|
||||||
void QtTestObject::staticFunction0()
|
void QtTestObject::staticFunction0()
|
||||||
@ -864,19 +863,19 @@ void tst_QMetaObject::invokeQueuedMetaMember()
|
|||||||
|
|
||||||
obj.slotResult.clear();
|
obj.slotResult.clear();
|
||||||
{
|
{
|
||||||
MyUnregisteredType t;
|
const MyForwardDeclaredType &t = getForwardDeclaredType();
|
||||||
QTest::ignoreMessage(QtWarningMsg, "QMetaMethod::invoke: Unable to handle unregistered datatype 'MyUnregisteredType'");
|
QTest::ignoreMessage(QtWarningMsg, "QMetaMethod::invoke: Unable to handle unregistered datatype 'MyForwardDeclaredType'");
|
||||||
QVERIFY(!QMetaObject::invokeMethod(&obj, "slotWithUnregisteredParameterType", Qt::QueuedConnection, Q_ARG(MyUnregisteredType, t)));
|
QVERIFY(!QMetaObject::invokeMethod(&obj, "slotWithUnregisteredParameterType", Qt::QueuedConnection, Q_ARG(MyForwardDeclaredType, t)));
|
||||||
QVERIFY(obj.slotResult.isEmpty());
|
QVERIFY(obj.slotResult.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.slotResult.clear();
|
obj.slotResult.clear();
|
||||||
{
|
{
|
||||||
QString a1("Cannot happen");
|
QString a1("Cannot happen");
|
||||||
MyUnregisteredType t;
|
const MyForwardDeclaredType &t = getForwardDeclaredType();
|
||||||
QTest::ignoreMessage(QtWarningMsg, "QMetaMethod::invoke: Unable to handle unregistered datatype 'MyUnregisteredType'");
|
QTest::ignoreMessage(QtWarningMsg, "QMetaMethod::invoke: Unable to handle unregistered datatype 'MyForwardDeclaredType'");
|
||||||
QVERIFY(!QMetaObject::invokeMethod(&obj, "slotWithOneUnregisteredParameterType", Qt::QueuedConnection,
|
QVERIFY(!QMetaObject::invokeMethod(&obj, "slotWithOneUnregisteredParameterType", Qt::QueuedConnection,
|
||||||
Q_ARG(QString, a1), Q_ARG(MyUnregisteredType, t)));
|
Q_ARG(QString, a1), Q_ARG(MyForwardDeclaredType, t)));
|
||||||
QVERIFY(obj.slotResult.isEmpty());
|
QVERIFY(obj.slotResult.isEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user