tst_QMetaObject: add a test for using Q_ARG with a non-const ref

This is in use in tst_qdbusinterface.cpp, so let's have it here to make
sure it works:

    QVERIFY(QMetaObject::invokeMethod(&iface, "ping",
                                      Q_RETURN_ARG(QDBusVariant, retArg),
                                      Q_ARG(QDBusVariant, arg),
                                      Q_ARG(QDBusVariant, arg2),
                                      Q_ARG(QDBusVariant&, retArg2)));

Change-Id: I36b24183fbd041179f2ffffd170271424c048292
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
bb10
Thiago Macieira 2022-07-16 15:55:42 -07:00
parent b01051dda7
commit 990c18d9c7
1 changed files with 15 additions and 0 deletions

View File

@ -687,6 +687,11 @@ void tst_QMetaObject::invokeMetaMember()
QVERIFY(QMetaObject::invokeMethod(&obj, "testReference", QGenericArgument("QString&", &refStr)));
QCOMPARE(obj.slotResult, QString("testReference:whatever"));
QCOMPARE(refStr, QString("gotcha"));
obj.slotResult.clear();
refStr = "whatever";
QVERIFY(QMetaObject::invokeMethod(&obj, "testReference", Q_ARG(QString&, refStr)));
QCOMPARE(obj.slotResult, QString("testReference:whatever"));
QCOMPARE(refStr, QString("gotcha"));
qint64 ll1 = -1;
quint64 ll2 = 0;
@ -915,6 +920,11 @@ void tst_QMetaObject::invokeQueuedMetaMember()
"Candidates are:\n testReference(QString&)");
QVERIFY(!QMetaObject::invokeMethod(&obj, "testReference", Qt::QueuedConnection, Q_ARG(QString, exp)));
QString refStr = "whatever";
QTest::ignoreMessage(QtWarningMsg, "QMetaMethod::invoke: Unable to handle unregistered datatype 'QString&'");
QVERIFY(!QMetaObject::invokeMethod(&obj, "testReference", Qt::QueuedConnection, Q_ARG(QString&, refStr)));
QCOMPARE(refStr, "whatever");
obj.slotResult.clear();
{
const MyForwardDeclaredType &t = getForwardDeclaredType();
@ -1046,6 +1056,11 @@ void tst_QMetaObject::invokeBlockingQueuedMetaMember()
QVERIFY(QMetaObject::invokeMethod(&obj, "testReference", Qt::BlockingQueuedConnection, QGenericArgument("QString&", &refStr)));
QCOMPARE(obj.slotResult, QString("testReference:whatever"));
QCOMPARE(refStr, QString("gotcha"));
obj.slotResult.clear();
refStr = "whatever";
QVERIFY(QMetaObject::invokeMethod(&obj, "testReference", Qt::BlockingQueuedConnection, Q_ARG(QString&, refStr)));
QCOMPARE(obj.slotResult, QString("testReference:whatever"));
QCOMPARE(refStr, QString("gotcha"));
qint64 ll1 = -1;
quint64 ll2 = 0;