Extend QTestPrivate property tests - update signatures [1/2]
Testing for the binding loops requires a second instance of the TestedClass. In general case, we cannot guarantee that the TestedClass is default-constructible, so we introduce a new parameter - a function that returns an std::unique_ptr holding the properly-constructed instance of TestedClass. The default implementation simply creates a unique_ptr using a default constructor, which is good enough for most cases. The user needs to provide a custom function when TestedClass has no default constructor (for now such usecase exists at least in QtScxml and QtPositioning). This patch introduces new signatures for the helper functions, but does not actually provide new implementation. This is an attempt to simplify the CI integration process. The new arguments have default values, so the existing code will not be affected. The idea is that the merge process goes as follows: * this patch gets merged into qtbase. It should not break leaf modules, because the new parameters have default values -> existing tests are unaffected. * it unblocks all patches to the leaf modules that require the new parameter for the test helper functions. These patches are also supposed to fix all the problems with the binding loops. * once these patches are merged, a follow-up patch to qtbase that actually extends the test coverage can be merged. As it is supposed that all problems in the leaf modules are already fixed, merging this patch should not lead to new problems. The actual implementation of the new tests is provided in a follow-up patch. Task-number: QTBUG-116345 Pick-to: 6.5 Change-Id: I0dd5c8c60de01aa960d63673b5d7de97950d9490 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit 5743837a26fce1962c0480bc7536b4c2d0e69997) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
cec3d03d11
commit
e87daa3f32
@ -84,6 +84,12 @@ namespace QTestPrivate {
|
||||
allocate its returned string using \c {new char[]}, so that it can be used
|
||||
in place of \l {QTest::toString()}.
|
||||
|
||||
The \a helperConstructor method is used to create another instance of
|
||||
\c TestedClass. This instance is used to test for binding loops. By default,
|
||||
the method returns a default-constructed \c TestedClass. A custom
|
||||
\a helperConstructor should be provided if \c TestedClass is not
|
||||
default-constructible. (NOTE: The parameter is currently unused!)
|
||||
|
||||
\note Any test calling this method will need to call
|
||||
\code
|
||||
if (QTest::currentTestFailed())
|
||||
@ -100,7 +106,9 @@ void testReadWritePropertyBasics(
|
||||
std::function<bool(const PropertyType &, const PropertyType &)> comparator =
|
||||
[](const PropertyType &lhs, const PropertyType &rhs) { return lhs == rhs; },
|
||||
std::function<char *(const PropertyType &)> represent =
|
||||
[](const PropertyType &val) { return QTest::toString(val); })
|
||||
[](const PropertyType &val) { return QTest::toString(val); },
|
||||
std::function<std::unique_ptr<TestedClass>(void)> helperConstructor =
|
||||
[]() { return std::make_unique<TestedClass>(); })
|
||||
{
|
||||
// get the property
|
||||
const QMetaObject *metaObject = instance.metaObject();
|
||||
@ -189,6 +197,29 @@ void testReadWritePropertyBasics(
|
||||
// value didn't change -> the signal should not be emitted
|
||||
if (spy)
|
||||
QCOMPARE(spy->size(), 4);
|
||||
|
||||
Q_UNUSED(helperConstructor);
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
\overload
|
||||
|
||||
This overload supports the case where the caller only needs to override
|
||||
the default for \a helperConstructor. It uses the defaults for all the other
|
||||
parameters.
|
||||
*/
|
||||
template<typename TestedClass, typename PropertyType>
|
||||
void testReadWritePropertyBasics(
|
||||
TestedClass &instance, const PropertyType &initial, const PropertyType &changed,
|
||||
const char *propertyName,
|
||||
std::function<std::unique_ptr<TestedClass>(void)> helperConstructor)
|
||||
{
|
||||
testReadWritePropertyBasics<TestedClass, PropertyType>(
|
||||
instance, initial, changed, propertyName,
|
||||
[](const PropertyType &lhs, const PropertyType &rhs) { return lhs == rhs; },
|
||||
[](const PropertyType &val) { return QTest::toString(val); },
|
||||
helperConstructor);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -224,6 +255,12 @@ void testReadWritePropertyBasics(
|
||||
allocate its returned string using \c {new char[]}, so that it can be used
|
||||
in place of \l {QTest::toString()}.
|
||||
|
||||
The \a helperConstructor method is used to create another instance of
|
||||
\c TestedClass. This instance is used to test for binding loops. By default,
|
||||
the method returns a default-constructed \c TestedClass. A custom
|
||||
\a helperConstructor should be provided if \c TestedClass is not
|
||||
default-constructible. (NOTE: The parameter is currently unused!)
|
||||
|
||||
\note Any test calling this method will need to call
|
||||
\code
|
||||
if (QTest::currentTestFailed())
|
||||
@ -242,8 +279,12 @@ void testWriteOncePropertyBasics(
|
||||
std::function<bool(const PropertyType &, const PropertyType &)> comparator =
|
||||
[](const PropertyType &lhs, const PropertyType &rhs) { return lhs == rhs; },
|
||||
std::function<char *(const PropertyType &)> represent =
|
||||
[](const PropertyType &val) { return QTest::toString(val); })
|
||||
[](const PropertyType &val) { return QTest::toString(val); },
|
||||
std::function<std::unique_ptr<TestedClass>(void)> helperConstructor =
|
||||
[]() { return std::make_unique<TestedClass>(); })
|
||||
{
|
||||
Q_UNUSED(helperConstructor);
|
||||
|
||||
// get the property
|
||||
const QMetaObject *metaObject = instance.metaObject();
|
||||
QMetaProperty metaProperty = metaObject->property(metaObject->indexOfProperty(propertyName));
|
||||
@ -303,6 +344,27 @@ void testWriteOncePropertyBasics(
|
||||
QVERIFY(!bindable.hasBinding());
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
\overload
|
||||
|
||||
This overload supports the case where the caller only needs to override
|
||||
the default for \a helperConstructor. It uses the defaults for all the other
|
||||
parameters.
|
||||
*/
|
||||
template<typename TestedClass, typename PropertyType>
|
||||
void testWriteOncePropertyBasics(
|
||||
TestedClass &instance, const PropertyType &prior, const PropertyType &changed,
|
||||
const char *propertyName,
|
||||
bool bindingPreservedOnWrite,
|
||||
std::function<std::unique_ptr<TestedClass>(void)> helperConstructor)
|
||||
{
|
||||
testWriteOncePropertyBasics<TestedClass, PropertyType>(
|
||||
instance, prior, changed, propertyName, bindingPreservedOnWrite,
|
||||
[](const PropertyType &lhs, const PropertyType &rhs) { return lhs == rhs; },
|
||||
[](const PropertyType &val) { return QTest::toString(val); },
|
||||
helperConstructor);
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
|
Loading…
x
Reference in New Issue
Block a user