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
QTestPrivate Namespace Reference

Classes

class  AppNapDisabler
 Disables App Nap by registering a background activity. More...

Typedefs

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

Enumerations

enum  IdentifierPart { TestObject = 0x1 , TestFunction = 0x2 , TestDataTag = 0x4 , AllParts = 0xFFFF }

Functions

bool testDataGuiRoles (QAbstractItemModelTester *tester)
void generateTestIdentifier (QTestCharBuffer *identifier, int parts)
bool appendCharBuffer (QTestCharBuffer *accumulator, const QTestCharBuffer &more)
QByteArray formatTypeWithCRefImpl (QMetaType type, bool isConst, bool isRef, bool isRvalueRef)
template<typename T>
QByteArray formatTypeWithCRef ()
template<typename LeftType, typename RightType = LeftType>
void testEqualityOperatorsCompile ()
template<typename LeftType, typename RightType = LeftType>
void testAllComparisonOperatorsCompile ()
template<typename LeftType, typename RightType>
void testEqualityOperators (LeftType lhs, RightType rhs, bool expectedEqual, const char *lhsExpr, const char *rhsExpr, const char *expected, const char *file, int line)
template<typename LeftType, typename RightType, typename OrderingType>
void testAllComparisonOperators (LeftType lhs, RightType rhs, OrderingType expectedOrdering)
QSet< QByteArrayblacklistKeywords ()
void parseBlackList ()
bool checkBlackLists (const char *slot, const char *data, const char *global)
void disableWindowRestore ()
bool macCrashReporterWillShowDialog ()
static bool isRunningArmOnX86 ()
template<typename TestedClass, typename PropertyType>
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 >();})
template<typename TestedClass, typename PropertyType>
void 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 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 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 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);})
static bool canHandleUnicodeFileNames ()

Variables

Q_TESTLIB_EXPORT Qt::MouseButtons qtestMouseButtons = Qt::NoButton

Typedef Documentation

◆ OptionalWrapper

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

Definition at line 53 of file qpropertytesthelper_p.h.

Enumeration Type Documentation

◆ IdentifierPart

Enumerator
TestObject 
TestFunction 
TestDataTag 
AllParts 

Definition at line 169 of file qabstracttestlogger_p.h.

Function Documentation

◆ appendCharBuffer()

bool QTestPrivate::appendCharBuffer ( QTestCharBuffer * accumulator,
const QTestCharBuffer & more )

Definition at line 468 of file qabstracttestlogger.cpp.

◆ blacklistKeywords()

QSet< QByteArray > QTestPrivate::blacklistKeywords ( )

Definition at line 247 of file qtestblacklist.cpp.

◆ canHandleUnicodeFileNames()

bool QTestPrivate::canHandleUnicodeFileNames ( )
inlinestatic

Definition at line 46 of file qtesthelpers_p.h.

◆ checkBlackLists()

bool QTestPrivate::checkBlackLists ( const char * slot,
const char * data,
const char * global = nullptr )

Definition at line 289 of file qtestblacklist.cpp.

References ignoreAll.

◆ disableWindowRestore()

void QTestPrivate::disableWindowRestore ( )

Disables restoration of previously saved window state. This causes tests to start with a clean slate and prevents the "previous restore failed" dialog from showing if there was a test crash.

Definition at line 20 of file qtestutil_macos.mm.

◆ formatTypeWithCRef()

template<typename T>
QByteArray QTestPrivate::formatTypeWithCRef ( )

Definition at line 39 of file qcomparisontesthelper_p.h.

◆ formatTypeWithCRefImpl()

QByteArray QTestPrivate::formatTypeWithCRefImpl ( QMetaType type,
bool isConst,
bool isRef,
bool isRvalueRef )

Definition at line 10 of file qcomparisontesthelper.cpp.

◆ generateTestIdentifier()

void Q_TESTLIB_EXPORT QTestPrivate::generateTestIdentifier ( QTestCharBuffer * identifier,
int parts )

Definition at line 450 of file qabstracttestlogger.cpp.

References QTest::qt_asprintf().

Here is the call graph for this function:

◆ isRunningArmOnX86()

bool QTestPrivate::isRunningArmOnX86 ( )
static

Definition at line 48 of file qemulationdetector_p.h.

◆ macCrashReporterWillShowDialog()

bool QTestPrivate::macCrashReporterWillShowDialog ( )

Definition at line 27 of file qtestutil_macos.mm.

◆ parseBlackList()

void QTestPrivate::parseBlackList ( )

Definition at line 252 of file qtestblacklist.cpp.

References ignoreAll, and ignoredTests.

◆ testAllComparisonOperators()

template<typename LeftType, typename RightType, typename OrderingType>
void QTestPrivate::testAllComparisonOperators ( LeftType lhs,
RightType rhs,
OrderingType expectedOrdering )

Basic testing of equality and relation operators.

The helper function tests all six relation and equality operators (==, !=, <, >, <=, >=) for the lhs operand of type {LeftType} and the rhs operand of type {RightType} and all six for the reverse order of the operands.

If compiled in C++20 mode, also checks {operator<=>()} if that is implemented.

When compiled in C++17 mode, the OrderingType must be one of Qt::partial_ordering, Qt::strong_ordering, or Qt::weak_ordering. In C++20 mode, also the {std::*_ordering} types can be used.

The expectedOrdering parameter provides the expected relation between lhs and rhs.

Note
Any test calling this method will need to check the test state after doing so, if there is any later code in the test.
QDateTime later = now.addMSec(1);
QTestPrivate::testComparisonOperators(now, later, Qt::weak_ordering::less);
if (QTest:currentTestFailed())
return;
\inmodule QtCore\reentrant
Definition qdatetime.h:318
static QDateTime currentDateTime()
This is an overloaded member function, provided for convenience. It differs from the above function o...
static const weak_ordering less
Definition qcompare.h:263

Definition at line 230 of file qcomparisontesthelper_p.h.

◆ testAllComparisonOperatorsCompile()

template<typename LeftType, typename RightType = LeftType>
void QTestPrivate::testAllComparisonOperatorsCompile ( )

This function checks that the types LeftType and RightType properly define all comparison operators (==, !=, <, >, <=, >=). The checks are performed for all combinations of cvref-qualified lvalues and rvalues.

If compiled in C++20 mode, also checks {operator<=>()} if that is implemented.

Definition at line 102 of file qcomparisontesthelper_p.h.

◆ testDataGuiRoles()

bool QTestPrivate::testDataGuiRoles ( QAbstractItemModelTester * tester)
inline

◆ testEqualityOperators()

template<typename LeftType, typename RightType>
void QTestPrivate::testEqualityOperators ( LeftType lhs,
RightType rhs,
bool expectedEqual,
const char * lhsExpr,
const char * rhsExpr,
const char * expected,
const char * file,
int line )

Basic testing of equality operators.

The helper function tests {in}equality operators (== and !=) for the lhs operand of type {LeftType} and the rhs operand of type {RightType}, plus the reverse order of the operands.

The expectedEqual parameter is an expected result for {operator==()}.

Note
Any test calling this method will need to check the test state after doing so, if there is any later code in the test.
QTime early(12, 34, 56, 00);
QTime later(12, 34, 56, 01);
if (QTest:currentTestFailed())
return;
\inmodule QtCore \reentrant
Definition qdatetime.h:250
void testEqualityOperators(LeftType lhs, RightType rhs, bool expectedEqual, const char *lhsExpr, const char *rhsExpr, const char *expected, const char *file, int line)

Definition at line 176 of file qcomparisontesthelper_p.h.

◆ testEqualityOperatorsCompile()

template<typename LeftType, typename RightType = LeftType>
void QTestPrivate::testEqualityOperatorsCompile ( )

This function checks that the types LeftType and RightType properly define {in}equality operators (== and !=). The checks are performed for all combinations of cvref-qualified lvalues and rvalues.

Definition at line 85 of file qcomparisontesthelper_p.h.

◆ testReadOnlyPropertyBasics()

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); } )

Basic testing of a read-only bindable property.

This helper function tests the behavior of bindable read-only property propertyName, of type PropertyType, in class TestedClass. The caller must supply an instance of TestedClass and two distinct values, initial and changed, of PropertyType.

When this function is called, the property's value must be initial. The mutator must, when called, cause the property's value to be revised to changed.

By default {operator==()} is used to compare values of the property and {QTest::toString()} is used to generate proper error messages.

If such comparison is not supported for PropertyType, or the comparison it supports is not appropriate to this property, a custom comparator can be supplied.

Apart from that, a custom represent callback can also be specified to generate a string representation of PropertyType. If supplied, it must allocate its returned string using {new char[]}, so that it can be used in place of \l {QTest::toString()}.

Note
Any test calling this method will need to call
return;
Q_TESTLIB_EXPORT bool currentTestFailed()
Returns true if the current test function has failed, otherwise false.
after doing so, if there is any later code in the test. If testing several properties in one test method, emitting a warning message saying which property failed, before returning, is a kindness to readers of the output.

Definition at line 456 of file qpropertytesthelper_p.h.

◆ testReadWritePropertyBasics() [1/2]

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>(); } )

Basic testing of a bindable property.

This helper function tests the behavior of bindable read/write property propertyName, of type PropertyType, in class TestedClass. The caller must supply an instance of TestedClass and two distinct values, initial and changed, of PropertyType.

Since the first part of the test sets the property to initial, it {must not} be the default value of the property, or the check that it was set will be vacuous.

By default {operator==()} is used to compare values of the property and {QTest::toString()} is used to generate proper error messages.

If such comparison is not supported for PropertyType, or the comparison it supports is not appropriate to this property, a custom comparator can be supplied.

Apart from that, a custom represent callback can also be specified to generate a string representation of PropertyType. If supplied, it must allocate its returned string using {new char[]}, so that it can be used in place of \l {QTest::toString()}.

The helperConstructor method is used to create another instance of TestedClass. This instance is used to test for binding loops. By default, the method returns a default-constructed TestedClass. A custom helperConstructor should be provided if TestedClass is not default-constructible. Some very specific properties cannot be tested for binding loops. Pass a lambda that returns an {std::nullptr} as helperConstructor in such case.

Note
Any test calling this method will need to call
return;
after doing so, if there is any later code in the test. If testing several properties in one test method, emitting a warning message saying which property failed, before returning, is a kindness to readers of the output.

Definition at line 130 of file qpropertytesthelper_p.h.

◆ testReadWritePropertyBasics() [2/2]

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 )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This overload supports the case where the caller only needs to override the default for helperConstructor. It uses the defaults for all the other parameters.

Definition at line 256 of file qpropertytesthelper_p.h.

◆ testWriteOncePropertyBasics() [1/2]

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 )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This overload supports the case where the caller only needs to override the default for helperConstructor. It uses the defaults for all the other parameters.

Definition at line 408 of file qpropertytesthelper_p.h.

◆ testWriteOncePropertyBasics() [2/2]

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>(); } )

Basic testing of a bindable property that is writable only once.

The write-once properties are writable properties which accept only one valid setting of the value ("write"), after which later attempts are ignored.

This helper function tests the behavior of bindable write-once property propertyName, of type PropertyType, in class TestedClass. The caller must supply an instance of TestedClass and two distinct values, initial and changed, of PropertyType.

The property of instance must not yet have been set when this function is called. The value it has before being set should be passed as prior and a distinct value, that this test can set it to, as changed.

The bindingPreservedOnWrite parameter controls whether this function expects the binding set by this function to be preserved when setting a value directly. The default value is 'true'.

By default {operator==()} is used to compare values of the property and {QTest::toString()} is used to generate proper error messages.

If such comparison is not supported for PropertyType, or the comparison it supports is not appropriate to this property, a custom comparator can be supplied.

Apart from that, a custom represent callback can also be specified to generate a string representation of PropertyType. If supplied, it must allocate its returned string using {new char[]}, so that it can be used in place of \l {QTest::toString()}.

The helperConstructor method is used to create another instance of TestedClass. This instance is used to test for binding loops. By default, the method returns a default-constructed TestedClass. A custom helperConstructor should be provided if TestedClass is not default-constructible. Some very specific properties cannot be tested for binding loops. Pass a lambda that returns an {std::nullptr} as helperConstructor in such case.

Note
Any test calling this method will need to call
return;
after doing so, if there is any later code in the test. If testing several properties in one test method, emitting a warning message saying which property failed, before returning, is a kindness to readers of the output.

Definition at line 320 of file qpropertytesthelper_p.h.

Variable Documentation

◆ qtestMouseButtons

Q_TESTLIB_EXPORT Qt::MouseButtons QTestPrivate::qtestMouseButtons = Qt::NoButton

Definition at line 164 of file qtestcase.cpp.