diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-09-28 09:10:25 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-09-28 13:51:33 +0200 |
commit | f791570b86ce4a0da45bb6e617701a48ee8189b7 (patch) | |
tree | 03c383e66650349a9407f006258eee2e96ff4256 /src/testlib | |
parent | a1bdee4697b7125bd0972284bfb33a56fcb441aa (diff) |
QTestPrivate property tests: don't try to create abstract types
Amends 5743837a26fce1962c0480bc7536b4c2d0e69997, after which Qt
Positioning and Qt SCXML failed to build as some properties operate on
abstract classes.
Check whether we can instantiate the tested class before trying to do so,
otherwise return a default-constructed unique_ptr.
Pick-to: 6.6 6.5
Change-Id: Ida9d4375197a93438062b1e1473b4a2a22cc7054
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/testlib')
-rw-r--r-- | src/testlib/qpropertytesthelper_p.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/testlib/qpropertytesthelper_p.h b/src/testlib/qpropertytesthelper_p.h index b4fc0fb769..06d503f875 100644 --- a/src/testlib/qpropertytesthelper_p.h +++ b/src/testlib/qpropertytesthelper_p.h @@ -108,7 +108,12 @@ void testReadWritePropertyBasics( std::function<char *(const PropertyType &)> represent = [](const PropertyType &val) { return QTest::toString(val); }, std::function<std::unique_ptr<TestedClass>(void)> helperConstructor = - []() { return std::make_unique<TestedClass>(); }) + []() { + if constexpr (std::is_default_constructible_v<TestedClass>) + return std::make_unique<TestedClass>(); + else + return std::unique_ptr<TestedClass>(); + }) { // get the property const QMetaObject *metaObject = instance.metaObject(); @@ -281,7 +286,12 @@ void testWriteOncePropertyBasics( std::function<char *(const PropertyType &)> represent = [](const PropertyType &val) { return QTest::toString(val); }, std::function<std::unique_ptr<TestedClass>(void)> helperConstructor = - []() { return std::make_unique<TestedClass>(); }) + []() { + if constexpr (std::is_default_constructible_v<TestedClass>) + return std::make_unique<TestedClass>(); + else + return std::unique_ptr<TestedClass>(); + }) { Q_UNUSED(helperConstructor); |