Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qpropertytesthelper_p.h File Reference

(7bd47fb70881e7240c027cd2844866c99f8f096d)

#include <QtCore/QObject>
#include <QtCore/QProperty>
#include <QtTest/QSignalSpy>
#include <QTest>
#include <private/qglobal_p.h>
#include <cstdio>
#include <memory>
#include <optional>
+ Include dependency graph for qpropertytesthelper_p.h:

Go to the source code of this file.

Namespaces

namespace  QTestPrivate
 

Macros

#define QPROPERTY_TEST_COMPARISON_HELPER(actual, expected, comparator, represent)
 

Typedefs

template<typename T>
using QTestPrivate::OptionalWrapper = std::optional<T>
 

Functions

template<typename TestedClass, typename PropertyType>
void QTestPrivate::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 >();})
 
template<typename TestedClass, typename PropertyType>
void QTestPrivate::testReadWritePropertyBasics (TestedClass &instance, const PropertyType &initial, const PropertyType &changed, const char *propertyName, std::function< std::unique_ptr< TestedClass >(void)> helperConstructor)
 
template<typename TestedClass, typename PropertyType>
void QTestPrivate::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 >();})
 
template<typename TestedClass, typename PropertyType>
void QTestPrivate::testWriteOncePropertyBasics (TestedClass &instance, const PropertyType &prior, const PropertyType &changed, const char *propertyName, bool bindingPreservedOnWrite, std::function< std::unique_ptr< TestedClass >(void)> helperConstructor)
 
template<typename TestedClass, typename PropertyType>
void QTestPrivate::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);})
 

Macro Definition Documentation

◆ QPROPERTY_TEST_COMPARISON_HELPER

#define QPROPERTY_TEST_COMPARISON_HELPER ( actual,
expected,
comparator,
represent )
Value:
do { \
char qprop_tst_cmp_hlp_buf[1024]; \
const auto qprop_tst_cmp_hlp_act = std::unique_ptr<char[]>(represent(actual)); \
const auto qprop_tst_cmp_hlp_exp = std::unique_ptr<char[]>(represent(expected)); \
QVERIFY2(comparator(actual, expected), \
sizeof qprop_tst_cmp_hlp_buf, \
qprop_tst_cmp_hlp_act.get(), \
qprop_tst_cmp_hlp_exp.get(), \
#actual, #expected)); \
} while (false)
QJSValue expected
Definition qjsengine.cpp:12
Q_TESTLIB_EXPORT Q_DECL_COLD_FUNCTION const char * formatPropertyTestHelperFailure(char *msg, size_t maxMsgLen, const char *actual, const char *expected, const char *actualExpr, const char *expectedExpr)

This helper macro is used as a wrapper around \l QVERIFY2() to provide a detailed error message in case of failure. It is intended to be used only in the helper functions below.

The custom comparator method is used to check if the actual and expected values are equal or not.

The macro uses a custom represent callback to generate the string representation of actual and expected.

The error message is close to the one provided by the \l QCOMPARE() macro. Specifically the implementation is taken from the formatFailMessage() function, which is defined in the qtestresult.cpp file.

Definition at line 74 of file qpropertytesthelper_p.h.