From ebfe4318b8266c7ea6183ec43d4ea64e4a03f852 Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Thu, 3 Mar 2022 13:52:06 +0100 Subject: [PATCH] Fix tst_qstringapisymmetry::count* to test all argument combinations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use two template parameters for the haystack and needle types, to test all possible combinations of all argument types. Note that the tests for QByteArray::count() are removed: it doesn't make sense to have them in tst_qstringapisymmetry, and we already have the symmetry tests for QByteArray in tst_qbytearrayapisymmetry. Change-Id: I33901fd135eb7433f0d45300a7248aef4d40324a Reviewed-by: Marc Mutz Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Edward Welbourne --- .../tst_qstringapisymmetry.cpp | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp index 53861aab8f7..0bc0ef2efa7 100644 --- a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp +++ b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp @@ -717,15 +717,32 @@ private Q_SLOTS: private: void count_data(); - template void count_impl(); + template + void count_impl(); private Q_SLOTS: - void count_QString_data() { count_data(); } - void count_QString() { count_impl(); } - void count_QStringView_data() { count_data(); } - void count_QStringView() { count_impl(); } - void count_QByteArray_data() { count_data(); } - void count_QByteArray() { count_impl(); } + void count_QString_QString_data() { count_data(); } + void count_QString_QString() { count_impl(); } + void count_QString_QLatin1String_data() { count_data(); } + void count_QString_QLatin1String() { count_impl(); } + void count_QString_QStringView_data() { count_data(); } + void count_QString_QStringView() { count_impl(); } + void count_QString_QChar_data() { count_data(); } + void count_QString_QChar() { count_impl(); } + void count_QString_char16_t_data() { count_data(); } + void count_QString_char16_t() { count_impl(); } + + void count_QStringView_QString_data() { count_data(); } + void count_QStringView_QString() { count_impl(); } + // TODO: enable when QStringView::count(QLatin1String, ...) is implemented + // void count_QStringView_QLatin1String_data() { count_data(); } + // void count_QStringView_QLatin1String() { count_impl(); } + void count_QStringView_QStringView_data() { count_data(); } + void count_QStringView_QStringView() { count_impl(); } + void count_QStringView_QChar_data() { count_data(); } + void count_QStringView_QChar() { count_impl(); } + void count_QStringView_char16_t_data() { count_data(); } + void count_QStringView_char16_t() { count_impl(); } // // UTF-16-only checks: @@ -2183,7 +2200,7 @@ void tst_QStringApiSymmetry::count_data() QTest::addRow("xyzaaaxyz") << QString::fromUtf8("xyzaaaxyz") << QString::fromUtf8("xyz") << qsizetype(2); } -template +template void tst_QStringApiSymmetry::count_impl() { QFETCH(const QString, data); @@ -2195,18 +2212,16 @@ void tst_QStringApiSymmetry::count_impl() const auto l1 = l1s.isNull() ? QLatin1String() : QLatin1String(l1s); const auto ref = data.isNull() ? QStringView() : QStringView(data); - const auto s = make(ref, l1, utf8); + const auto s = make(ref, l1, utf8); const auto nutf8 = needle.toUtf8(); const auto nl1s = needle.toLatin1(); const auto nl1 = nl1s.isNull() ? QLatin1String() : QLatin1String(nl1s); const auto nref = needle.isNull() ? QStringView() : QStringView(needle); - const auto ns = make(nref, nl1, nutf8); + const auto ns = make(nref, nl1, nutf8); QCOMPARE(s.count(ns), result); - if (ns.length() == 1) - QCOMPARE(s.count(ns.data()[0]), result); } //