summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/kernel/qobject/tst_qobject.cpp32
-rw-r--r--tests/auto/tools/moc/tst_moc.cpp15
2 files changed, 47 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
index e4677c6e34..5a5c4d3a40 100644
--- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
+++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
@@ -5307,6 +5307,15 @@ void tst_QObject::connectNoDefaultConstructorArg()
QVERIFY(connect(&ob, &NoDefaultContructorArguments::mySignal, &ob, &NoDefaultContructorArguments::mySlot, Qt::QueuedConnection));
}
+struct MoveOnly
+{
+ int value;
+ explicit MoveOnly(int v = 1) : value(v) {}
+ MoveOnly(MoveOnly &&o) : value(o.value) { o.value = -1; }
+ MoveOnly &operator=(MoveOnly &&o) { value = o.value; o.value = -1; return *this; }
+ Q_DISABLE_COPY(MoveOnly);
+};
+
class ReturnValue : public QObject {
friend class tst_QObject;
Q_OBJECT
@@ -5316,6 +5325,7 @@ signals:
int returnInt(int);
void returnVoid(int);
CustomType returnCustomType(int);
+ MoveOnly returnMoveOnly(int);
QObject *returnPointer();
public slots:
@@ -5328,6 +5338,7 @@ public slots:
QString returnHello() { return QStringLiteral("hello"); }
QObject *returnThisSlot1() { return this; }
ReturnValue *returnThisSlot2() { return this; }
+ MoveOnly returnMoveOnlySlot(int i) { return MoveOnly(i); }
public:
struct VariantFunctor {
QVariant operator()(int i) { return i; }
@@ -5344,6 +5355,9 @@ public:
struct VoidFunctor {
void operator()(int) {}
};
+ struct MoveOnlyFunctor {
+ MoveOnly operator()(int i) { return MoveOnly(i); }
+ };
};
QString someFunctionReturningString(int i) {
@@ -5381,6 +5395,7 @@ void tst_QObject::returnValue()
emit r.returnVoid(45);
QCOMPARE((emit r.returnCustomType(45)).value(), CustomType().value());
QCOMPARE((emit r.returnPointer()), static_cast<QObject *>(0));
+ QCOMPARE((emit r.returnMoveOnly(666)).value, MoveOnly().value);
}
{ // connected to a slot returning the same type
CheckInstanceCount checker;
@@ -5395,6 +5410,8 @@ void tst_QObject::returnValue()
QCOMPARE((emit r.returnCustomType(45)).value(), CustomType(45).value());
QVERIFY(connect(&r, &ReturnValue::returnPointer, &receiver, &ReturnValue::returnThisSlot1, type));
QCOMPARE((emit r.returnPointer()), static_cast<QObject *>(&receiver));
+ QVERIFY(connect(&r, &ReturnValue::returnMoveOnly, &receiver, &ReturnValue::returnMoveOnlySlot, type));
+ QCOMPARE((emit r.returnMoveOnly(666)).value, 666);
}
if (!isBlockingQueued) { // connected to simple functions or functor
CheckInstanceCount checker;
@@ -5413,6 +5430,10 @@ void tst_QObject::returnValue()
ReturnValue::IntFunctor intFunctor;
QVERIFY(connect(&r, &ReturnValue::returnInt, intFunctor));
QCOMPARE(emit r.returnInt(45), int(45));
+
+ ReturnValue::MoveOnlyFunctor moveOnlyFunctor;
+ QVERIFY(connect(&r, &ReturnValue::returnMoveOnly, moveOnlyFunctor));
+ QCOMPARE((emit r.returnMoveOnly(666)).value, 666);
}
{ // connected to a slot with different type
CheckInstanceCount checker;
@@ -5451,6 +5472,8 @@ void tst_QObject::returnValue()
QCOMPARE((emit r.returnCustomType(45)).value(), CustomType().value());
QVERIFY(connect(&r, &ReturnValue::returnPointer, &receiver, &ReturnValue::returnVoidSlot, type));
QCOMPARE((emit r.returnPointer()), static_cast<QObject *>(0));
+ QVERIFY(connect(&r, &ReturnValue::returnMoveOnly, &receiver, &ReturnValue::returnVoidSlot, type));
+ QCOMPARE((emit r.returnMoveOnly(666)).value, MoveOnly().value);
}
if (!isBlockingQueued) {
// queued connection should not forward the return value
@@ -5466,6 +5489,8 @@ void tst_QObject::returnValue()
QCOMPARE((emit r.returnCustomType(45)).value(), CustomType().value());
QVERIFY(connect(&r, &ReturnValue::returnPointer, &receiver, &ReturnValue::returnThisSlot1, Qt::QueuedConnection));
QCOMPARE((emit r.returnPointer()), static_cast<QObject *>(0));
+ QVERIFY(connect(&r, &ReturnValue::returnMoveOnly, &receiver, &ReturnValue::returnMoveOnlySlot, Qt::QueuedConnection));
+ QCOMPARE((emit r.returnMoveOnly(666)).value, MoveOnly().value);
QCoreApplication::processEvents();
@@ -5549,6 +5574,8 @@ void tst_QObject::returnValue2()
QCOMPARE(emit r.returnInt(45), int(45));
QVERIFY(connect(&r, SIGNAL(returnCustomType(int)), &receiver, SLOT(returnCustomTypeSlot(int)), type));
QCOMPARE((emit r.returnCustomType(45)).value(), CustomType(45).value());
+ QVERIFY(connect(&r, SIGNAL(returnMoveOnly(int)), &receiver, SLOT(returnMoveOnlySlot(int)), type));
+ QCOMPARE((emit r.returnMoveOnly(45)).value, 45);
}
{ // connected to a slot returning void
CheckInstanceCount checker;
@@ -5561,6 +5588,8 @@ void tst_QObject::returnValue2()
QCOMPARE(emit r.returnInt(45), int());
QVERIFY(connect(&r, SIGNAL(returnCustomType(int)), &receiver, SLOT(returnVoidSlot()), type));
QCOMPARE((emit r.returnCustomType(45)).value(), CustomType().value());
+ QVERIFY(connect(&r, SIGNAL(returnMoveOnly(int)), &receiver, SLOT(returnVoidSlot()), type));
+ QCOMPARE((emit r.returnMoveOnly(45)).value, MoveOnly().value);
}
if (!isBlockingQueued) {
// queued connection should not forward the return value
@@ -5574,6 +5603,9 @@ void tst_QObject::returnValue2()
QCOMPARE(emit r.returnInt(45), int());
QVERIFY(connect(&r, SIGNAL(returnCustomType(int)), &receiver, SLOT(returnCustomTypeSlot(int)), Qt::QueuedConnection));
QCOMPARE((emit r.returnCustomType(45)).value(), CustomType().value());
+ QVERIFY(connect(&r, SIGNAL(returnMoveOnly(int)), &receiver, SLOT(returnMoveOnlySlot(int)), Qt::QueuedConnection));
+ QCOMPARE((emit r.returnMoveOnly(45)).value, MoveOnly().value);
+
QCoreApplication::processEvents();
//Queued conneciton with different return type should be safe
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp
index 5f1a0618ab..8189227cbe 100644
--- a/tests/auto/tools/moc/tst_moc.cpp
+++ b/tests/auto/tools/moc/tst_moc.cpp
@@ -2841,6 +2841,21 @@ void tst_Moc::privateSignalConnection()
// We can't use function pointer connections to private signals which are overloaded because we would have to cast in this case to:
// static_cast<void (ClassWithPrivateSignals::*)(int, ClassWithPrivateSignals::QPrivateSignal)>(&ClassWithPrivateSignals::overloadedMaybePrivate)
// Which doesn't work as ClassWithPrivateSignals::QPrivateSignal is private.
+
+ // Connecting from one private signal to another
+ {
+ ClassWithPrivateSignals classWithPrivateSignals1;
+ ClassWithPrivateSignals classWithPrivateSignals2;
+ SignalConnectionTester tester;
+ QObject::connect(&classWithPrivateSignals1, &ClassWithPrivateSignals::privateSignal1,
+ &classWithPrivateSignals2, &ClassWithPrivateSignals::privateSignal1);
+ QObject::connect(&classWithPrivateSignals2, &ClassWithPrivateSignals::privateSignal1,
+ &tester, &SignalConnectionTester::testSlot);
+
+ QVERIFY(!tester.testPassed);
+ classWithPrivateSignals1.emitPrivateSignals();
+ QVERIFY(tester.testPassed);
+ }
}
void tst_Moc::finalClasses_data()