Fix source compatibility with existing toString() extensions
Change-Id: I946ebf0f0fa82450105e720489c4da35a77078d8 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 7dd2c5f91dd62840d37c5e17cc3f1f5ad46d9366) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
1f72315adc
commit
85b7aeaddc
@ -3144,7 +3144,16 @@ char *QTest::toString(const volatile QObject *vo)
|
|||||||
if (vo == nullptr)
|
if (vo == nullptr)
|
||||||
return qstrdup("<null>");
|
return qstrdup("<null>");
|
||||||
|
|
||||||
auto *o = const_cast<const QObject*>(vo);
|
return QTest::toString(const_cast<const QObject*>(vo));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \internal
|
||||||
|
*/
|
||||||
|
char *QTest::toString(const QObject *o)
|
||||||
|
{
|
||||||
|
if (o == nullptr)
|
||||||
|
return qstrdup("<null>");
|
||||||
|
|
||||||
const QString &name = o->objectName();
|
const QString &name = o->objectName();
|
||||||
const char *className = o->metaObject()->className();
|
const char *className = o->metaObject()->className();
|
||||||
char *msg = new char[256];
|
char *msg = new char[256];
|
||||||
@ -3155,6 +3164,7 @@ char *QTest::toString(const volatile QObject *vo)
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! \fn char *QTest::toString(const QColor &color)
|
/*! \fn char *QTest::toString(const QColor &color)
|
||||||
\internal
|
\internal
|
||||||
*/
|
*/
|
||||||
|
@ -1423,7 +1423,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn template<typename T, QTest::Internal::is_suitable_type_v<T> = true> char *QTest::toString(const T &value)
|
\fn template <typename T> char *QTest::toString(const T &value)
|
||||||
|
|
||||||
Returns a textual representation of \a value. This function is used by
|
Returns a textual representation of \a value. This function is used by
|
||||||
\l QCOMPARE() to output verbose information in case of a test failure.
|
\l QCOMPARE() to output verbose information in case of a test failure.
|
||||||
|
@ -81,19 +81,6 @@ inline typename std::enable_if<!QtPrivate::IsQEnumHelper<F>::Value, char*>::type
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
constexpr bool is_suitable_type_helper_v = std::disjunction_v<std::is_same<T, char>,
|
|
||||||
std::is_same<T, void>,
|
|
||||||
std::is_same<T, QObject>
|
|
||||||
>;
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
using is_suitable_type_v =
|
|
||||||
std::enable_if_t<!(std::is_pointer_v<T>
|
|
||||||
&& is_suitable_type_helper_v<
|
|
||||||
std::remove_const_t<std::remove_pointer_t<T>>>),
|
|
||||||
bool>;
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|
||||||
Q_TESTLIB_EXPORT bool compare_string_helper(const char *t1, const char *t2, const char *actual,
|
Q_TESTLIB_EXPORT bool compare_string_helper(const char *t1, const char *t2, const char *actual,
|
||||||
@ -102,11 +89,8 @@ Q_TESTLIB_EXPORT char *formatString(const char *prefix, const char *suffix, size
|
|||||||
Q_TESTLIB_EXPORT char *toHexRepresentation(const char *ba, qsizetype length);
|
Q_TESTLIB_EXPORT char *toHexRepresentation(const char *ba, qsizetype length);
|
||||||
Q_TESTLIB_EXPORT char *toPrettyCString(const char *unicode, qsizetype length);
|
Q_TESTLIB_EXPORT char *toPrettyCString(const char *unicode, qsizetype length);
|
||||||
Q_TESTLIB_EXPORT char *toPrettyUnicode(QStringView string);
|
Q_TESTLIB_EXPORT char *toPrettyUnicode(QStringView string);
|
||||||
Q_TESTLIB_EXPORT char *toString(const char *);
|
|
||||||
Q_TESTLIB_EXPORT char *toString(const volatile void *);
|
|
||||||
Q_TESTLIB_EXPORT char *toString(const volatile QObject *);
|
|
||||||
|
|
||||||
template<typename T, Internal::is_suitable_type_v<T> = true>
|
template <typename T>
|
||||||
inline char *toString(const T &t)
|
inline char *toString(const T &t)
|
||||||
{
|
{
|
||||||
return Internal::toString(t);
|
return Internal::toString(t);
|
||||||
@ -121,6 +105,11 @@ inline char *toString(const std::tuple<Types...> &tuple);
|
|||||||
template <typename Rep, typename Period>
|
template <typename Rep, typename Period>
|
||||||
inline char *toString(std::chrono::duration<Rep, Period> duration);
|
inline char *toString(std::chrono::duration<Rep, Period> duration);
|
||||||
|
|
||||||
|
Q_TESTLIB_EXPORT char *toString(const char *);
|
||||||
|
Q_TESTLIB_EXPORT char *toString(const volatile void *);
|
||||||
|
Q_TESTLIB_EXPORT char *toString(const QObject *);
|
||||||
|
Q_TESTLIB_EXPORT char *toString(const volatile QObject *);
|
||||||
|
|
||||||
#define QTEST_COMPARE_DECL(KLASS)\
|
#define QTEST_COMPARE_DECL(KLASS)\
|
||||||
template<> Q_TESTLIB_EXPORT char *toString<KLASS >(const KLASS &);
|
template<> Q_TESTLIB_EXPORT char *toString<KLASS >(const KLASS &);
|
||||||
#ifndef Q_QDOC
|
#ifndef Q_QDOC
|
||||||
|
Loading…
x
Reference in New Issue
Block a user