106 TestedClass &instance,
const PropertyType &initial,
const PropertyType &changed,
107 const char *propertyName,
108 std::function<
bool(
const PropertyType &,
const PropertyType &)> comparator =
109 [](
const PropertyType &lhs,
const PropertyType &rhs) {
return lhs == rhs; },
110 std::function<
char *(
const PropertyType &)> represent =
112 std::function<std::unique_ptr<TestedClass>(
void)> helperConstructor =
113 []() {
return std::make_unique<TestedClass>(); })
119 QByteArray(
"Preconditions not met for ") + propertyName +
"\n"
120 "The type of initial and changed value does not match the type of the property.\n"
121 "Please ensure that the types match exactly (convertability is not enough).\n"
122 "You can provide the template types to the "
123 "function explicitly to force a certain type.\n"
125 +
" but " + QMetaType::fromType<PropertyType>().name() +
" was provided.");
131 "Preconditions not met for " +
QByteArray(propertyName));
133 QScopedPointer<QSignalSpy>
spy(
nullptr);
139 testedObj.property(propertyName).template value<PropertyType>(), initial, comparator,
148 QProperty<PropertyType> propObserver(changed);
152 QProperty<PropertyType> propObserverLambda(changed);
153 propObserverLambda.setBinding(
154 [&]() {
return testedObj.property(propertyName).
template value<PropertyType>(); });
164 QProperty<PropertyType> propSetter(initial);
170 testedObj.property(propertyName).template value<PropertyType>(), initial, comparator,
179 auto handler = bindable.
onValueChanged([&updateCount]() { ++updateCount; });
182 propSetter.setValue(changed);
184 testedObj.property(propertyName).template value<PropertyType>(), changed, comparator,
204 if (std::unique_ptr<TestedClass> helperObj = helperConstructor()) {
209 const QPropertyBinding<PropertyType> binding([&]() {
212 return obj->property(propertyName).template value<PropertyType>();
216 testedObj.property(propertyName).template value<PropertyType>(), changed,
217 comparator, represent);
296 TestedClass &instance,
const PropertyType &prior,
const PropertyType &changed,
297 const char *propertyName,
298 bool bindingPreservedOnWrite =
true,
299 std::function<
bool(
const PropertyType &,
const PropertyType &)> comparator =
300 [](
const PropertyType &lhs,
const PropertyType &rhs) {
return lhs == rhs; },
301 std::function<
char *(
const PropertyType &)> represent =
303 std::function<std::unique_ptr<TestedClass>(
void)> helperConstructor =
304 []() {
return std::make_unique<TestedClass>(); })
314 QByteArray(
"Preconditions not met for ") + propertyName +
"\n"
315 "The type of prior and changed value does not match the type of the property.\n"
316 "Please ensure that the types match exactly (convertability is not enough).\n"
317 "You can provide the template types to the "
318 "function explicitly to force a certain type.\n"
320 +
" but parameters are " + QMetaType::fromType<PropertyType>().name() +
".\n");
326 QScopedPointer<QSignalSpy>
spy(
nullptr);
331 testedObj.property(propertyName).template value<PropertyType>(), prior, comparator,
334 QProperty<PropertyType> propObserver;
341 std::unique_ptr<TestedClass> helperObj = helperConstructor();
342 QProperty<PropertyType> propSetter(changed);
343 const QPropertyBinding<PropertyType> binding = helperObj
347 return obj->property(propertyName).template value<PropertyType>();
354 testedObj.property(propertyName).template value<PropertyType>(), changed, comparator,
363 testedObj.property(propertyName).template value<PropertyType>(), changed, comparator,
368 if (bindingPreservedOnWrite)
432 TestedClass &instance,
const PropertyType &initial,
const PropertyType &changed,
433 const char *propertyName,
434 std::function<
void()> mutator = []() {
QFAIL(
"Data modifier function must be provided"); },
435 std::function<bool(
const PropertyType &,
const PropertyType &)> comparator =
436 [](
const PropertyType &lhs,
const PropertyType &rhs) {
return lhs == rhs; },
437 std::function<
char *(
const PropertyType &)> represent =
448 QByteArray(
"Preconditions not met for ") + propertyName +
"\n"
449 "The type of initial and changed value does not match the type of the property.\n"
450 "Please ensure that the types match exactly (convertability is not enough).\n"
451 "You can provide the template types to the "
452 "function explicitly to force a certain type.\n"
454 +
" but " + QMetaType::fromType<PropertyType>().name() +
" was provided.");
460 QScopedPointer<QSignalSpy>
spy(
nullptr);
465 testedObj.property(propertyName).template value<PropertyType>(), initial, comparator,
469 QProperty<PropertyType> propSetter(initial);
473 propSetter.setValue(changed);
475 testedObj.property(propertyName).template value<PropertyType>(), initial, comparator,
480 QProperty<PropertyType> propObserver;
489 testedObj.property(propertyName).template value<PropertyType>(), changed, comparator,
void testReadWritePropertyBasics(TestedClass &instance, const PropertyType &initial, const PropertyType &changed, const char *propertyName, 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);}, std::function< std::unique_ptr< TestedClass >(void)> helperConstructor=[]() { return std::make_unique< TestedClass >();})
void testReadOnlyPropertyBasics(TestedClass &instance, const PropertyType &initial, const PropertyType &changed, const char *propertyName, std::function< void()> mutator=[]() { QFAIL("Data modifier function must be provided");}, 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);})
void testWriteOncePropertyBasics(TestedClass &instance, const PropertyType &prior, const PropertyType &changed, const char *propertyName, bool bindingPreservedOnWrite=true, 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);}, std::function< std::unique_ptr< TestedClass >(void)> helperConstructor=[]() { return std::make_unique< TestedClass >();})