8#include <QtTest/qttestglobal.h>
10#if QT_CONFIG(itemmodel)
11# include <QtCore/qabstractitemmodel.h>
13#include <QtCore/qbitarray.h>
14#include <QtCore/qbytearray.h>
15#include <QtCore/qcborarray.h>
16#include <QtCore/qcborcommon.h>
17#include <QtCore/qcbormap.h>
18#include <QtCore/qcborvalue.h>
19#include <QtCore/qdatetime.h>
20#include <QtCore/qmetaobject.h>
21#include <QtCore/qmetatype.h>
22#include <QtCore/qobject.h>
23#include <QtCore/qpoint.h>
24#include <QtCore/qrect.h>
25#include <QtCore/qsize.h>
26#include <QtCore/qstring.h>
27#include <QtCore/qstringlist.h>
28#include <QtCore/qurl.h>
29#include <QtCore/quuid.h>
30#include <QtCore/qvariant.h>
38inline typename std::enable_if<QtPrivate::IsQEnumHelper<T>::Value,
char*>
::type toString(T e)
45inline typename std::enable_if<!QtPrivate::IsQEnumHelper<T>::Value && std::is_enum_v<T>,
char*>
::type toString(
const T &e)
51inline typename std::enable_if<!QtPrivate::IsQEnumHelper<T>::Value && !std::is_enum_v<T>,
char *>
::type toString(
const T &
t)
54#ifndef QT_NO_DEBUG_STREAM
55 if constexpr (QTypeTraits::has_ostream_operator_v<QDebug, T>) {
59 "Built-in type must implement debug streaming operator "
60 "or provide QTest::toString specialization");
67inline typename std::enable_if<QtPrivate::IsQEnumHelper<F>::Value,
char*>
::type toString(QFlags<F>
f)
69 const QMetaEnum me = QMetaEnum::fromType<F>();
74inline typename std::enable_if<!QtPrivate::IsQEnumHelper<F>::Value,
char*>
::type toString(QFlags<F>
f)
76 const size_t space = 3 + 2 *
sizeof(unsigned);
77 char *msg =
new char[space];
78 qsnprintf(msg, space,
"0x%x",
unsigned(
f.toInt()));
84 std::is_same<T, void>,
85 std::is_same<T, QObject>
90 std::enable_if_t<!(std::is_pointer_v<T>
92 std::remove_const_t<std::remove_pointer_t<T>>>),
99Q_TESTLIB_EXPORT
char *
formatString(
const char *prefix,
const char *suffix,
size_t numArguments, ...);
103Q_TESTLIB_EXPORT
char *
toString(
const char *);
104Q_TESTLIB_EXPORT
char *
toString(
const volatile void *);
107template<
typename T, Internal::is_suitable_type_v<T> = true>
113template <
typename T1,
typename T2>
114inline char *
toString(
const std::pair<T1, T2> &pair);
116template <
class... Types>
117inline char *
toString(
const std::tuple<Types...> &tuple);
119template <
typename Rep,
typename Period>
120inline char *
toString(std::chrono::duration<Rep, Period> duration);
122#define QTEST_COMPARE_DECL(KLASS)\
123 template<> Q_TESTLIB_EXPORT char *toString<KLASS >(const KLASS &);
142#undef QTEST_COMPARE_DECL
167 char *
str =
new char[
size + 1];
174#if QT_CONFIG(datestring)
193 :
qstrdup(
"Invalid QDateTime");
207 char msg[32] = {
'\0'};
208 qsnprintf(msg,
sizeof(msg),
"QChar: '%c' (0x%x)",
char(uc),
unsigned(uc));
214#if QT_CONFIG(itemmodel)
225 char msg[128] = {
'\0'};
226 qsnprintf(msg,
sizeof(msg),
"QPoint(%d,%d)",
p.x(),
p.y());
232 char msg[128] = {
'\0'};
233 qsnprintf(msg,
sizeof(msg),
"QSize(%dx%d)",
s.width(),
s.height());
239 char msg[256] = {
'\0'};
240 qsnprintf(msg,
sizeof(msg),
"QRect(%d,%d %dx%d) (bottomright %d,%d)",
241 s.left(),
s.top(),
s.width(),
s.height(),
s.right(),
s.bottom());
247 char msg[64] = {
'\0'};
248 qsnprintf(msg,
sizeof(msg),
"QPointF(%g,%g)",
p.x(),
p.y());
254 char msg[64] = {
'\0'};
255 qsnprintf(msg,
sizeof(msg),
"QSizeF(%gx%g)",
s.width(),
s.height());
261 char msg[256] = {
'\0'};
262 qsnprintf(msg,
sizeof(msg),
"QRectF(%g,%g %gx%g) (bottomright %g,%g)",
263 s.left(),
s.top(),
s.width(),
s.height(),
s.right(),
s.bottom());
284 if (
type.isEmpty()) {
287 vstring.append(
type);
291 vstring.append(
v.toString().toLocal8Bit());
294 vstring.append(
"<value not representable as string>");
300 return qstrdup(vstring.constData());
329 QScopedArrayPointer<char> hold(
format(taggedValue));
338 int idx = QCborValue::staticMetaObject.indexOfEnumerator(
"Type");
339 return QCborValue::staticMetaObject.enumerator(idx);
343 const char *
typeName = typeEnum.valueToKey(
t);
361 return format(
v.type(),
v.toInteger());
363 return format(
v.type(),
v.toByteArray());
365 return format(
v.type(),
v.toString());
375 return qstrdup(
"QCborValue(true)");
377 return qstrdup(
"QCborValue(false)");
379 return qstrdup(
"QCborValue(nullptr)");
381 return qstrdup(
"QCborValue()");
383 return format(
v.type(),
v.toDouble());
387 return format(
v.type(),
v.taggedValue().toString());
389 return format(
v.type(),
v.toUuid());
391 return qstrdup(
"QCborValue(<invalid>)");
394 if (
v.isSimpleType())
402 const char *comma =
"";
404 QScopedArrayPointer<char>
s(
format(
v));
416 const char *comma =
"";
417 for (
auto pair :
m) {
418 QScopedArrayPointer<char>
key(
format(pair.first));
419 QScopedArrayPointer<char>
value(
format(pair.second));
452template <
typename Rep,
typename Period>
char *
toString(std::chrono::duration<Rep, Period> dur)
457 if constexpr (Period::num != 1 || Period::den != 1) {
459 using namespace std::chrono;
460 d <<
" (" << duration_cast<duration<qreal>>(dur).
count() <<
"s)";
462 return qstrdup(std::move(
r).toUtf8().constData());
465template <
typename T1,
typename T2>
466inline char *
toString(
const std::pair<T1, T2> &pair)
469 const QScopedArrayPointer<char> second(
toString(pair.second));
473template <
typename Tuple, std::size_t... I>
475 using UP = std::unique_ptr<char[]>;
480 UP(
toString(std::get<I>(tuple)))..., UP{}
485template <
class... Types>
486inline char *
toString(
const std::tuple<Types...> &tuple)
488 return tupleToString(tuple, std::make_index_sequence<
sizeof...(Types)>{});
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.
\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.
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...
\variable Qt::partial_ordering::less
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
\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
\keyword 16-bit Floating Point Support\inmodule QtCore \inheaderfile QFloat16
Combined button and popup list for selecting options.
const char * toString(QSizePolicy::Policy p)
std::enable_if_t<!(std::is_pointer_v< T > &&is_suitable_type_helper_v< std::remove_const_t< std::remove_pointer_t< T > > >), bool > is_suitable_type_v
constexpr bool is_suitable_type_helper_v
char * toString(const MyPoint &point)
char * tupleToString(const Tuple &tuple, std::index_sequence< I... >)
char * formatString(const char *prefix, const char *suffix, size_t numArguments,...)
char * toPrettyCString(const char *p, qsizetype length)
char * toHexRepresentation(const char *ba, qsizetype length)
Returns a pointer to a string that is the string ba represented as a space-separated sequence of hex ...
Q_TESTLIB_EXPORT bool compare_string_helper(const char *t1, const char *t2, const char *actual, const char *expected, const char *file, int line)
Q_TESTLIB_EXPORT char * toPrettyUnicode(QStringView string)
Q_CORE_EXPORT int qsnprintf(char *str, size_t n, const char *fmt,...)
Q_CORE_EXPORT char * qstrdup(const char *)
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 GLuint GLenum GLsizei length
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
[4]
GLenum GLuint GLenum GLsizei const GLchar * buf
GLint GLsizei GLsizei GLenum format
#define qPrintable(string)
#define QTEST_COMPARE_DECL(KLASS)
QTextStreamManipulator qSetRealNumberPrecision(int precision)
unsigned long long quint64
QTextStream out(stdout)
[7]
QCborValue(QCborTag(2), QByteArray("\x01\0\0\0\0\0\0\0\0", 9))
[0]
\inmodule QtCore \inheaderfile QtCborCommon \reentrant