From 0843ce852451028c27034fb1ea9abb00790b2484 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 6 Apr 2016 12:35:29 +0200 Subject: [PATCH] tst_qstringapisymmetry: cover QByteArray, const char*, too As in 032efc2cb20e163a2daf8aef9eb8df2b757d17dc, which added the API-symmetry test, define the missing relational operators locally in the test harness until they are fixed in the library. Change-Id: Ic2688e6b6b3e028a9c29f1a5eb01058375ef3fe9 Reviewed-by: Edward Welbourne --- .../tst_qstringapisymmetry.cpp | 89 ++++++++++++++++++- 1 file changed, 87 insertions(+), 2 deletions(-) diff --git a/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp index f6d2579074..10cf13f698 100644 --- a/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp +++ b/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp @@ -44,6 +44,32 @@ template QString toQString(const T &t) { return QString(t); } QString toQString(const QStringRef &ref) { return ref.toString(); } +// FIXME: these are missing at the time of writing, add them, then remove the dummies here: +#define MAKE_RELOP(op, A1, A2) \ + static bool operator op (A1 lhs, A2 rhs) \ + { return toQString(lhs) op toQString(rhs); } \ + /*end*/ +#define MAKE_ALL(A1, A2) \ + MAKE_RELOP(==, A1, A2) \ + MAKE_RELOP(!=, A1, A2) \ + MAKE_RELOP(<, A1, A2) \ + MAKE_RELOP(>, A1, A2) \ + MAKE_RELOP(<=, A1, A2) \ + MAKE_RELOP(>=, A1, A2) \ + /*end*/ + +MAKE_ALL(QStringRef, QByteArray) +MAKE_ALL(QByteArray, QStringRef) + +MAKE_ALL(QByteArray, QChar) +MAKE_ALL(QByteArray, QLatin1String) + +MAKE_ALL(const char*, QChar) + +#undef MAKE_ALL +#undef MAKE_RELOP +// END FIXME + class tst_QStringApiSymmetry : public QObject { Q_OBJECT @@ -53,7 +79,7 @@ class tst_QStringApiSymmetry : public QObject void compare_impl() const; private Q_SLOTS: - // test all combinations of {QChar, QStringRef, QString, QLatin1String} + // test all combinations of {QChar, QStringRef, QString, QLatin1String, QByteArray, const char*} void compare_QChar_QChar_data() { compare_data(false); } void compare_QChar_QChar() { compare_impl(); } void compare_QChar_QStringRef_data() { compare_data(false); } @@ -62,6 +88,10 @@ private Q_SLOTS: void compare_QChar_QString() { compare_impl(); } void compare_QChar_QLatin1String_data() { compare_data(false); } void compare_QChar_QLatin1String() { compare_impl(); } + void compare_QChar_QByteArray_data() { compare_data(false); } + void compare_QChar_QByteArray() { compare_impl(); } + void compare_QChar_const_char_star_data() { compare_data(false); } + void compare_QChar_const_char_star() { compare_impl(); } void compare_QStringRef_QChar_data() { compare_data(false); } void compare_QStringRef_QChar() { compare_impl(); } @@ -71,6 +101,10 @@ private Q_SLOTS: void compare_QStringRef_QString() { compare_impl(); } void compare_QStringRef_QLatin1String_data() { compare_data(); } void compare_QStringRef_QLatin1String() { compare_impl(); } + void compare_QStringRef_QByteArray_data() { compare_data(); } + void compare_QStringRef_QByteArray() { compare_impl(); } + void compare_QStringRef_const_char_star_data() { compare_data(); } + void compare_QStringRef_const_char_star() { compare_impl(); } void compare_QString_QChar_data() { compare_data(false); } void compare_QString_QChar() { compare_impl(); } @@ -80,6 +114,10 @@ private Q_SLOTS: void compare_QString_QString() { compare_impl(); } void compare_QString_QLatin1String_data() { compare_data(); } void compare_QString_QLatin1String() { compare_impl(); } + void compare_QString_QByteArray_data() { compare_data(); } + void compare_QString_QByteArray() { compare_impl(); } + void compare_QString_const_char_star_data() { compare_data(); } + void compare_QString_const_char_star() { compare_impl(); } void compare_QLatin1String_QChar_data() { compare_data(false); } void compare_QLatin1String_QChar() { compare_impl(); } @@ -89,6 +127,36 @@ private Q_SLOTS: void compare_QLatin1String_QString() { compare_impl(); } void compare_QLatin1String_QLatin1String_data() { compare_data(); } void compare_QLatin1String_QLatin1String() { compare_impl(); } + void compare_QLatin1String_QByteArray_data() { compare_data(); } + void compare_QLatin1String_QByteArray() { compare_impl(); } + void compare_QLatin1String_const_char_star_data() { compare_data(); } + void compare_QLatin1String_const_char_star() { compare_impl(); } + + void compare_QByteArray_QChar_data() { compare_data(false); } + void compare_QByteArray_QChar() { compare_impl(); } + void compare_QByteArray_QStringRef_data() { compare_data(); } + void compare_QByteArray_QStringRef() { compare_impl(); } + void compare_QByteArray_QString_data() { compare_data(); } + void compare_QByteArray_QString() { compare_impl(); } + void compare_QByteArray_QLatin1String_data() { compare_data(); } + void compare_QByteArray_QLatin1String() { compare_impl(); } + void compare_QByteArray_QByteArray_data() { compare_data(); } + void compare_QByteArray_QByteArray() { compare_impl(); } + void compare_QByteArray_const_char_star_data() { compare_data(); } + void compare_QByteArray_const_char_star() { compare_impl(); } + + void compare_const_char_star_QChar_data() { compare_data(false); } + void compare_const_char_star_QChar() { compare_impl(); } + void compare_const_char_star_QStringRef_data() { compare_data(); } + void compare_const_char_star_QStringRef() { compare_impl(); } + void compare_const_char_star_QString_data() { compare_data(); } + void compare_const_char_star_QString() { compare_impl(); } + void compare_const_char_star_QLatin1String_data() { compare_data(false); } + void compare_const_char_star_QLatin1String() { compare_impl(); } + void compare_const_char_star_QByteArray_data() { compare_data(); } + void compare_const_char_star_QByteArray() { compare_impl(); } + //void compare_const_char_star_const_char_star_data() { compare_data(); } + //void compare_const_char_star_const_char_star() { compare_impl(); } }; @@ -135,6 +203,20 @@ template <> QChar make(const QStringRef &sf, QLatin1String) template <> QStringRef make(const QStringRef &sf, QLatin1String) { return sf; } template <> QString make(const QStringRef &sf, QLatin1String) { return sf.toString(); } template <> QLatin1String make(const QStringRef &, QLatin1String l1) { return l1; } +template <> QByteArray make(const QStringRef &sf, QLatin1String) { return sf.toUtf8(); } +template <> const char *make(const QStringRef &, QLatin1String l1) { return l1.data(); } + +template struct is_utf8_encoded : std::false_type {}; +template <> struct is_utf8_encoded : std::true_type {}; +template <> struct is_utf8_encoded : std::true_type {}; + +template struct is_latin1_encoded : std::false_type {}; +template <> struct is_latin1_encoded : std::true_type {}; + +template +struct has_nothrow_compare { + enum { value = is_utf8_encoded::value == is_utf8_encoded::value }; +}; template void tst_QStringApiSymmetry::compare_impl() const @@ -149,7 +231,10 @@ void tst_QStringApiSymmetry::compare_impl() const const RHS rhs = make(rhsUnicode, rhsLatin1); #ifdef Q_COMPILER_NOEXCEPT -# define QVERIFY_NOEXCEPT(expr) QVERIFY(noexcept(expr)) +# define QVERIFY_NOEXCEPT(expr) do { \ + if (has_nothrow_compare::value) {} else \ + QEXPECT_FAIL("", "Qt is missing a nothrow utf8-utf16 comparator", Continue); \ + QVERIFY(noexcept(expr)); } while (0) #else # define QVERIFY_NOEXCEPT(expr) #endif