Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qpropertytesthelper_p.h File Reference

(6335685a1b4b16d179264d27227881cffcf9cae9)

#include <QtCore/QObject>
#include <QtCore/QProperty>
#include <QtTest/QSignalSpy>
#include <QTest>
#include <private/qglobal_p.h>
+ 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)
 

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 { \
const size_t maxMsgLen = 1024; \
char msg[maxMsgLen] = { '\0' }; \
auto actualStr = represent(actual); \
auto expectedStr = represent(expected); \
const size_t len1 = mbstowcs(nullptr, #actual, maxMsgLen); \
const size_t len2 = mbstowcs(nullptr, #expected, maxMsgLen); \
qsnprintf(msg, maxMsgLen, "\n%s\n Actual (%s)%*s %s\n Expected (%s)%*s %s\n", \
"Comparison failed!", #actual, qMax(len1, len2) - len1 + 1, ":", \
actualStr ? actualStr : "<null>", #expected, qMax(len1, len2) - len2 + 1, ":", \
expectedStr ? expectedStr : "<null>"); \
delete[] actualStr; \
delete[] expectedStr; \
QVERIFY2(comparator(actual, expected), msg); \
} while (false)
QJSValue expected
Definition qjsengine.cpp:12
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
static constexpr size_t maxMsgLen

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 45 of file qpropertytesthelper_p.h.