diff --git a/src/testlib/qpropertytesthelper_p.h b/src/testlib/qpropertytesthelper_p.h index 54398278997..6bdd1feda12 100644 --- a/src/testlib/qpropertytesthelper_p.h +++ b/src/testlib/qpropertytesthelper_p.h @@ -22,11 +22,38 @@ #include #include +#include +#include QT_BEGIN_NAMESPACE namespace QTestPrivate { +#ifdef Q_OS_VXWORKS +template +class OptionalWrapper : private std::unique_ptr +{ + using Base = std::unique_ptr; + + Base &as_base() { return *this; } + const Base &as_base() const { return *this; } +public: + Q_IMPLICIT OptionalWrapper(std::nullopt_t) : Base() {} + + using Base::operator->; + using Base::operator*; + using Base::operator bool; + + template + T &emplace(Args&&...args) + { as_base() = std::make_unique(std::forward(args)...); return **this; } +}; +#else +template +using OptionalWrapper = std::optional; +#endif // Q_OS_VXWORKS + + /*! \internal @@ -128,9 +155,9 @@ void testReadWritePropertyBasics( QVERIFY2(metaProperty.isBindable() && metaProperty.isWritable(), "Preconditions not met for " + QByteArray(propertyName)); - QScopedPointer spy(nullptr); + QTestPrivate::OptionalWrapper spy = std::nullopt; if (metaProperty.hasNotifySignal()) - spy.reset(new QSignalSpy(&instance, metaProperty.notifySignal())); + spy.emplace(&instance, metaProperty.notifySignal()); testedObj.setProperty(propertyName, QVariant::fromValue(initial)); QPROPERTY_TEST_COMPARISON_HELPER( @@ -321,9 +348,9 @@ void testWriteOncePropertyBasics( QUntypedBindable bindable = metaProperty.bindable(&instance); - QScopedPointer spy(nullptr); + QTestPrivate::OptionalWrapper spy = std::nullopt; if (metaProperty.hasNotifySignal()) - spy.reset(new QSignalSpy(&instance, metaProperty.notifySignal())); + spy.emplace(&instance, metaProperty.notifySignal()); QPROPERTY_TEST_COMPARISON_HELPER( testedObj.property(propertyName).template value(), prior, comparator, @@ -455,9 +482,9 @@ void testReadOnlyPropertyBasics( QUntypedBindable bindable = metaProperty.bindable(&instance); - QScopedPointer spy(nullptr); + QTestPrivate::OptionalWrapper spy = std::nullopt; if (metaProperty.hasNotifySignal()) - spy.reset(new QSignalSpy(&instance, metaProperty.notifySignal())); + spy.emplace(&instance, metaProperty.notifySignal()); QPROPERTY_TEST_COMPARISON_HELPER( testedObj.property(propertyName).template value(), initial, comparator,