4#ifndef QPROPERTYTESTHELPER_P_H
5#define QPROPERTYTESTHELPER_P_H
18#include <QtCore/QObject>
19#include <QtCore/QProperty>
20#include <QtTest/QSignalSpy>
22#include <private/qglobal_p.h>
45#define QPROPERTY_TEST_COMPARISON_HELPER(actual, expected, comparator, represent) \
47 const size_t maxMsgLen = 1024; \
48 char msg[maxMsgLen] = { '\0' }; \
49 auto actualStr = represent(actual); \
50 auto expectedStr = represent(expected); \
51 const size_t len1 = mbstowcs(nullptr, #actual, maxMsgLen); \
52 const size_t len2 = mbstowcs(nullptr, #expected, maxMsgLen); \
53 qsnprintf(msg, maxMsgLen, "\n%s\n Actual (%s)%*s %s\n Expected (%s)%*s %s\n", \
54 "Comparison failed!", #actual, qMax(len1, len2) - len1 + 1, ":", \
55 actualStr ? actualStr : "<null>", #expected, qMax(len1, len2) - len2 + 1, ":", \
56 expectedStr ? expectedStr : "<null>"); \
58 delete[] expectedStr; \
59 QVERIFY2(comparator(actual, expected), msg); \
96template<
typename TestedClass,
typename PropertyType>
98 TestedClass &instance,
const PropertyType &initial,
const PropertyType &changed,
99 const char *propertyName,
100 std::function<
bool(
const PropertyType &,
const PropertyType &)> comparator =
101 [](
const PropertyType &lhs,
const PropertyType &rhs) {
return lhs == rhs; },
102 std::function<
char *(
const PropertyType &)> represent =
109 QByteArray(
"Preconditions not met for ") + propertyName +
"\n"
110 "The type of initial and changed value does not match the type of the property.\n"
111 "Please ensure that the types match exactly (convertability is not enough).\n"
112 "You can provide the template types to the "
113 "function explicitly to force a certain type.\n"
115 +
" but " + QMetaType::fromType<PropertyType>().name() +
" was provided.");
121 "Preconditions not met for " +
QByteArray(propertyName));
143 propObserverLambda.setBinding(
169 auto handler = bindable.
onValueChanged([&updateCount]() { ++updateCount; });
172 propSetter.setValue(changed);
237template<
typename TestedClass,
typename PropertyType>
239 TestedClass &instance,
const PropertyType &prior,
const PropertyType &changed,
240 const char *propertyName,
241 bool bindingPreservedOnWrite =
true,
242 std::function<
bool(
const PropertyType &,
const PropertyType &)> comparator =
243 [](
const PropertyType &lhs,
const PropertyType &rhs) {
return lhs == rhs; },
244 std::function<
char *(
const PropertyType &)> represent =
255 QByteArray(
"Preconditions not met for ") + propertyName +
"\n"
256 "The type of prior and changed value does not match the type of the property.\n"
257 "Please ensure that the types match exactly (convertability is not enough).\n"
258 "You can provide the template types to the "
259 "function explicitly to force a certain type.\n"
261 +
" but parameters are " + QMetaType::fromType<PropertyType>().name() +
".\n");
300 if (bindingPreservedOnWrite)
341template<
typename TestedClass,
typename PropertyType>
343 TestedClass &instance,
const PropertyType &initial,
const PropertyType &changed,
344 const char *propertyName,
345 std::function<
void()> mutator = []() {
QFAIL(
"Data modifier function must be provided"); },
346 std::function<bool(
const PropertyType &,
const PropertyType &)> comparator =
347 [](
const PropertyType &lhs,
const PropertyType &rhs) {
return lhs == rhs; },
348 std::function<
char *(
const PropertyType &)> represent =
359 QByteArray(
"Preconditions not met for ") + propertyName +
"\n"
360 "The type of initial and changed value does not match the type of the property.\n"
361 "Please ensure that the types match exactly (convertability is not enough).\n"
362 "You can provide the template types to the "
363 "function explicitly to force a certain type.\n"
365 +
" but " + QMetaType::fromType<PropertyType>().name() +
" was provided.");
384 propSetter.setValue(changed);
qsizetype size() const noexcept
QVariant property(const char *name) const
Returns the value of the object's name property.
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object's name property to value.
parameter_type value() const
Returns the value of the property.
QPropertyBinding< T > setBinding(const QPropertyBinding< T > &newBinding)
Associates the value of this property with the provided newBinding expression and returns the previou...
QUntypedPropertyBinding makeBinding(const QPropertyBindingSourceLocation &location=QT_PROPERTY_DEFAULT_BINDING_LOCATION) const
Creates a binding returning the underlying properties' value, using a specified source location.
bool hasBinding() const
Returns true if the underlying property has a binding.
bool setBinding(const QUntypedPropertyBinding &binding)
Sets the underlying property's binding to binding.
QPropertyChangeHandler< Functor > onValueChanged(Functor f) const
Installs f as a change handler.
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
QSignalSpy spy(myCustomObject, SIGNAL(mySignal(int, QString, double)))
[0]
Combined button and popup list for selecting options.
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);})
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 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);})
char * toString(const MyPoint &point)
auto makePropertyBinding(Functor &&f, const QPropertyBindingSourceLocation &location=QT_PROPERTY_DEFAULT_BINDING_LOCATION, std::enable_if_t< std::is_invocable_v< Functor > > *=nullptr)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define QPROPERTY_TEST_COMPARISON_HELPER(actual, expected, comparator, represent)
#define QCOMPARE(actual, expected)
#define QVERIFY(statement)
#define QVERIFY2(statement, description)
obj metaObject() -> className()