12#include <QtTest/qttestglobal.h>
13#include <QtTest/qtestcase.h>
14#include <QtTest/qtestdata.h>
15#include <QtTest/qbenchmark.h>
17#include <QtCore/qbitarray.h>
18#include <QtCore/qbytearray.h>
19#include <QtCore/qcborarray.h>
20#include <QtCore/qcborcommon.h>
21#include <QtCore/qcbormap.h>
22#include <QtCore/qcborvalue.h>
23#include <QtCore/qstring.h>
24#include <QtCore/qstringlist.h>
25#include <QtCore/qcborcommon.h>
26#include <QtCore/qdatetime.h>
27#if QT_CONFIG(itemmodel)
28#include <QtCore/qabstractitemmodel.h>
30#include <QtCore/qobject.h>
31#include <QtCore/qvariant.h>
32#include <QtCore/qurl.h>
33#include <QtCore/quuid.h>
35#if defined(TESTCASE_LOWDPI)
36#include <QtCore/qcoreapplication.h>
39#include <QtCore/qpoint.h>
40#include <QtCore/qsize.h>
41#include <QtCore/qrect.h>
43#include <initializer_list>
81#if QT_CONFIG(datestring)
100 :
qstrdup(
"Invalid QDateTime");
114 char msg[32] = {
'\0'};
115 qsnprintf(msg,
sizeof(msg),
"QChar: '%c' (0x%x)",
char(uc),
unsigned(uc));
121#if QT_CONFIG(itemmodel)
132 char msg[128] = {
'\0'};
133 qsnprintf(msg,
sizeof(msg),
"QPoint(%d,%d)",
p.x(),
p.y());
139 char msg[128] = {
'\0'};
140 qsnprintf(msg,
sizeof(msg),
"QSize(%dx%d)",
s.width(),
s.height());
146 char msg[256] = {
'\0'};
147 qsnprintf(msg,
sizeof(msg),
"QRect(%d,%d %dx%d) (bottomright %d,%d)",
148 s.left(),
s.top(),
s.width(),
s.height(),
s.right(),
s.bottom());
154 char msg[64] = {
'\0'};
155 qsnprintf(msg,
sizeof(msg),
"QPointF(%g,%g)",
p.x(),
p.y());
161 char msg[64] = {
'\0'};
162 qsnprintf(msg,
sizeof(msg),
"QSizeF(%gx%g)",
s.width(),
s.height());
168 char msg[256] = {
'\0'};
169 qsnprintf(msg,
sizeof(msg),
"QRectF(%g,%g %gx%g) (bottomright %g,%g)",
170 s.left(),
s.top(),
s.width(),
s.height(),
s.right(),
s.bottom());
191 if (
type.isEmpty()) {
198 vstring.
append(
v.toString().toLocal8Bit());
201 vstring.
append(
"<value not representable as string>");
245 int idx = QCborValue::staticMetaObject.indexOfEnumerator(
"Type");
246 return QCborValue::staticMetaObject.enumerator(idx);
268 return format(
v.type(),
v.toInteger());
270 return format(
v.type(),
v.toByteArray());
272 return format(
v.type(),
v.toString());
282 return qstrdup(
"QCborValue(true)");
284 return qstrdup(
"QCborValue(false)");
286 return qstrdup(
"QCborValue(nullptr)");
288 return qstrdup(
"QCborValue()");
290 return format(
v.type(),
v.toDouble());
294 return format(
v.type(),
v.taggedValue().toString());
296 return format(
v.type(),
v.toUuid());
298 return qstrdup(
"QCborValue(<invalid>)");
301 if (
v.isSimpleType())
309 const char *comma =
"";
323 const char *comma =
"";
324 for (
auto pair :
m) {
359template <
typename Rep,
typename Period>
char *
toString(std::chrono::duration<Rep, Period> dur)
364 if constexpr (Period::num != 1 || Period::den != 1) {
366 using namespace std::chrono;
367 d <<
" (" << duration_cast<duration<qreal>>(dur).
count() <<
"s)";
369 return qstrdup(std::move(
r).toUtf8().constData());
372template <
typename T1,
typename T2>
373inline char *
toString(
const std::pair<T1, T2> &pair)
380template <
typename Tuple,
int... I>
382 using UP = std::unique_ptr<char[]>;
387 UP(
toString(std::get<I>(tuple)))..., UP{}
392template <
class...
Types>
393inline char *
toString(
const std::tuple<Types...> &tuple)
395 static const std::size_t params_count =
sizeof...(Types);
418template <
typename ActualIterator,
typename ExpectedIterator>
420 ExpectedIterator expectedBegin, ExpectedIterator expectedEnd,
421 const char *actual,
const char *
expected,
427 const qsizetype actualSize = actualEnd - actualIt;
428 const qsizetype expectedSize = expectedEnd - expectedBegin;
429 bool isOk = actualSize == expectedSize;
432 qsnprintf(msg,
sizeof(msg),
"Compared lists have different sizes.\n"
433 " Actual (%s) size: %zd\n"
434 " Expected (%s) size: %zd", actual, actualSize,
438 for (
auto expectedIt = expectedBegin; isOk && expectedIt < expectedEnd; ++actualIt, ++expectedIt) {
439 if (!(*actualIt == *expectedIt)) {
444 qsnprintf(msg,
sizeof(msg),
"Compared lists differ at index %zd.\n"
446 " Expected (%s): %s",
i, actual, val1 ? val1 :
"<null>",
459#if defined(TESTCASE_LOWDPI)
462 qputenv(
"QT_ENABLE_HIGHDPI_SCALING",
"0");
477template <
typename T,
int N>
479 const char *actual,
const char *
expected,
487template <
typename T,
int N>
489 const char *actual,
const char *
expected,
559 using YesType =
char[1];
560 using NoType =
char[2];
562 template <
typename C>
static YesType& test(
decltype(&C::initMain) ) ;
563 template <
typename C>
static NoType& test(...);
566 enum {
value =
sizeof(test<T>(
nullptr)) ==
sizeof(YesType) };
585#ifdef QT_TESTCASE_BUILDDIR
586# define QTEST_SET_MAIN_SOURCE_PATH QTest::setMainSourcePath(__FILE__, QT_TESTCASE_BUILDDIR);
588# define QTEST_SET_MAIN_SOURCE_PATH QTest::setMainSourcePath(__FILE__);
592#if QT_CONFIG(testlib_selfcover) && defined(__COVERAGESCANNER__)
593struct QtCoverageScanner
595 QtCoverageScanner(
const char *
name)
597 __coveragescanner_clear();
598 __coveragescanner_testname(
name);
602 __coveragescanner_save();
603 __coveragescanner_testname(
"");
606#define TESTLIB_SELFCOVERAGE_START(name) QtCoverageScanner _qtCoverageScanner(name);
608#define TESTLIB_SELFCOVERAGE_START(name)
611#if !defined(QTEST_BATCH_TESTS)
615#define QTEST_MAIN_WRAPPER(TestObject, ...) \
616int main(int argc, char *argv[]) \
618 TESTLIB_SELFCOVERAGE_START(#TestObject) \
619 QT_PREPEND_NAMESPACE(QTest::Internal::callInitMain)<TestObject>(); \
622 QTEST_SET_MAIN_SOURCE_PATH \
623 return QTest::qExec(&tc, argc, argv); \
629#if !defined(BATCHED_TEST_NAME)
630#define BATCHED_TEST_NAME "other"
632#define QTEST_MAIN_WRAPPER(TestObject, ...) \
634void qRegister##TestObject() \
636 auto runTest = [](int argc, char** argv) -> int { \
637 TESTLIB_SELFCOVERAGE_START(TestObject) \
638 QT_PREPEND_NAMESPACE(QTest::Internal::callInitMain)<TestObject>(); \
641 QTEST_SET_MAIN_SOURCE_PATH \
642 return QTest::qExec(&tc, argc, argv); \
644 QTest::qRegisterTestCase(QStringLiteral(BATCHED_TEST_NAME), runTest); \
647Q_CONSTRUCTOR_FUNCTION(qRegister##TestObject)
651#define QTEST_APPLESS_MAIN(TestObject) QTEST_MAIN_WRAPPER(TestObject)
653#include <QtTest/qtestsystem.h>
655#if defined(QT_NETWORK_LIB)
656# include <QtTest/qtest_network.h>
660#define QTEST_QAPP_SETUP(klaz) \
661 klaz app(argc, argv); \
662 app.setAttribute(Qt::AA_Use96Dpi, true);
664#if defined(QT_WIDGETS_LIB)
665# include <QtTest/qtest_widgets.h>
666# ifdef QT_KEYPAD_NAVIGATION
667# define QTEST_DISABLE_KEYPAD_NAVIGATION QApplication::setNavigationMode(Qt::NavigationModeNone);
669# define QTEST_DISABLE_KEYPAD_NAVIGATION
672# define QTEST_MAIN_SETUP() QTEST_QAPP_SETUP(QApplication) QTEST_DISABLE_KEYPAD_NAVIGATION
673#elif defined(QT_GUI_LIB)
674# include <QtTest/qtest_gui.h>
676# define QTEST_MAIN_SETUP() QTEST_QAPP_SETUP(QGuiApplication)
679# define QTEST_MAIN_SETUP() QTEST_QAPP_SETUP(QCoreApplication)
683#define QTEST_MAIN(TestObject) QTEST_MAIN_WRAPPER(TestObject, QTEST_MAIN_SETUP())
686#define QTEST_GUILESS_MAIN(TestObject) \
687 QTEST_MAIN_WRAPPER(TestObject, QTEST_QAPP_SETUP(QCoreApplication))
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
static QByteArray number(int, int base=10)
Returns a byte-array representing the whole number n as text.
QByteArray & append(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
Type
This enum represents the QCborValue type.
\inmodule QtCore\reentrant
bool isValid() const
Returns true if this datetime represents a definite moment, otherwise false.
\inmodule QtCore \reentrant
constexpr bool isValid() const
Returns true if this date is valid; otherwise returns false.
std::conditional< std::is_unsigned< typenamestd::underlying_type< Enum >::type >::value, unsignedint, signedint >::type Int
constexpr int row() const noexcept
Returns the row this model index refers to.
constexpr const QAbstractItemModel * model() const noexcept
Returns a pointer to the model containing the item that this index refers to.
constexpr int column() const noexcept
Returns the column this model index refers to.
void * internalPointer() const noexcept
Returns a {void} {*} pointer used by the model to associate the index with the internal data structur...
static const QPartialOrdering Less
static const QPartialOrdering Greater
static const QPartialOrdering Equivalent
static const QPartialOrdering Unordered
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
T * data() const noexcept
Returns the value of the pointer referenced by this object.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
\inmodule QtCore \reentrant
bool isValid() const
Returns true if the time is valid; otherwise returns false.
bool isValid() const
Returns true if the URL is non-empty and valid; otherwise returns false.
QByteArray toEncoded(FormattingOptions options=FullyEncoded) const
Returns the encoded representation of the URL if it's valid; otherwise an empty QByteArray is returne...
QString errorString() const
QByteArray toByteArray(StringFormat mode=WithBraces) const
Combined button and popup list for selecting options.
std::enable_if< HasInitMain< T >::value, void >::type callInitMain()
char * toString(const MyPoint &point)
Q_TESTLIB_EXPORT bool compare_helper(bool success, const char *failureMsg, qxp::function_ref< const char *()> actualVal, qxp::function_ref< const char *()> expectedVal, const char *actual, const char *expected, const char *file, int line)
bool _q_compareSequence(ActualIterator actualIt, ActualIterator actualEnd, ExpectedIterator expectedBegin, ExpectedIterator expectedEnd, const char *actual, const char *expected, const char *file, int line)
char * formatString(const char *prefix, const char *suffix, size_t numArguments,...)
char * toPrettyCString(const char *p, qsizetype length)
bool qCompare(QString const &t1, QLatin1StringView const &t2, const char *actual, const char *expected, const char *file, int line)
char * toPrettyUnicode(QStringView string)
Q_CORE_EXPORT int qsnprintf(char *str, size_t n, const char *fmt,...)
Q_CORE_EXPORT char * qstrdup(const char *)
Q_CONSTRUCTOR_FUNCTION(initializeStandardUserDefaults)
AudioChannelLayoutTag tag
static QDBusError::ErrorType get(const char *name)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLsizei const GLfloat * v
[13]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLenum GLsizei count
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
[4]
GLenum GLuint GLenum GLsizei const GLchar * buf
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei GLsizei GLenum format
#define qPrintable(string)
#define QStringLiteral(str)
bool qputenv(const char *varName, QByteArrayView raw)
QTextStreamManipulator qSetRealNumberPrecision(int precision)
unsigned long long quint64
QTextStream out(stdout)
[7]
\inmodule QtCore \inheaderfile QtCborCommon \reentrant
makeIndexSequence< N > Value