summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2023-10-23 22:47:09 +0300
committerAhmad Samir <a.samirh78@gmail.com>2024-05-08 19:22:46 +0200
commitc878a51509d22d4ef774ebb81b90e385ded6f885 (patch)
tree7b54714730da50a9260ac9689670dbd130d5a851 /tests/auto
parent519a47e870dddc16879bad9a3f8398e0349fb76a (diff)
QLatin1StringMatcher: add indexIn(QStringView) overload
Drive-by changes, remove a redundant typedef. [ChangeLog][QtCore][QLatin1StringMatcher] Added indexIn(QStringView) overload. Task-number: QTBUG-117054 Change-Id: I5a8426cb0f9d9111f086015902ffe2185a267c86 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Øystein Heskestad <oystein.heskestad@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/text/qlatin1stringmatcher/tst_qlatin1stringmatcher.cpp75
1 files changed, 58 insertions, 17 deletions
diff --git a/tests/auto/corelib/text/qlatin1stringmatcher/tst_qlatin1stringmatcher.cpp b/tests/auto/corelib/text/qlatin1stringmatcher/tst_qlatin1stringmatcher.cpp
index 82e12bdfca..23ea54658b 100644
--- a/tests/auto/corelib/text/qlatin1stringmatcher/tst_qlatin1stringmatcher.cpp
+++ b/tests/auto/corelib/text/qlatin1stringmatcher/tst_qlatin1stringmatcher.cpp
@@ -44,6 +44,12 @@ void tst_QLatin1StringMatcher::overloads()
QCOMPARE(m.indexIn("Hellohello"_L1), 5);
QCOMPARE(m.indexIn("helloHello"_L1), 0);
QCOMPARE(m.indexIn("helloHello"_L1, 1), -1);
+
+ QCOMPARE(m.indexIn(u"hello"), 0);
+ QCOMPARE(m.indexIn(u"Hello"), -1);
+ QCOMPARE(m.indexIn(u"Hellohello"), 5);
+ QCOMPARE(m.indexIn(u"helloHello"), 0);
+ QCOMPARE(m.indexIn(u"helloHello", 1), -1);
}
{
QLatin1StringMatcher m("Hello"_L1, Qt::CaseSensitive);
@@ -53,6 +59,12 @@ void tst_QLatin1StringMatcher::overloads()
QCOMPARE(m.indexIn("Hellohello"_L1), 0);
QCOMPARE(m.indexIn("helloHello"_L1), 5);
QCOMPARE(m.indexIn("helloHello"_L1, 6), -1);
+
+ QCOMPARE(m.indexIn(u"hello"), -1);
+ QCOMPARE(m.indexIn(u"Hello"), 0);
+ QCOMPARE(m.indexIn(u"Hellohello"), 0);
+ QCOMPARE(m.indexIn(u"helloHello"), 5);
+ QCOMPARE(m.indexIn(u"helloHello", 6), -1);
}
{
QLatin1StringMatcher m("hello"_L1, Qt::CaseInsensitive);
@@ -63,6 +75,13 @@ void tst_QLatin1StringMatcher::overloads()
QCOMPARE(m.indexIn("helloHello"_L1), 0);
QCOMPARE(m.indexIn("helloHello"_L1, 1), 5);
QCOMPARE(m.indexIn("helloHello"_L1, 6), -1);
+
+ QCOMPARE(m.indexIn(u"hello"), 0);
+ QCOMPARE(m.indexIn(u"Hello"), 0);
+ QCOMPARE(m.indexIn(u"Hellohello"), 0);
+ QCOMPARE(m.indexIn(u"helloHello"), 0);
+ QCOMPARE(m.indexIn(u"helloHello", 1), 5);
+ QCOMPARE(m.indexIn(u"helloHello", 6), -1);
}
{
QLatin1StringMatcher m("Hello"_L1, Qt::CaseInsensitive);
@@ -73,6 +92,13 @@ void tst_QLatin1StringMatcher::overloads()
QCOMPARE(m.indexIn("helloHello"_L1), 0);
QCOMPARE(m.indexIn("helloHello"_L1, 1), 5);
QCOMPARE(m.indexIn("helloHello"_L1, 6), -1);
+
+ QCOMPARE(m.indexIn(u"hello"), 0);
+ QCOMPARE(m.indexIn(u"Hello"), 0);
+ QCOMPARE(m.indexIn(u"Hellohello"), 0);
+ QCOMPARE(m.indexIn(u"helloHello"), 0);
+ QCOMPARE(m.indexIn(u"helloHello", 1), 5);
+ QCOMPARE(m.indexIn(u"helloHello", 6), -1);
}
{
QLatin1StringMatcher m(hello, Qt::CaseSensitive);
@@ -81,6 +107,11 @@ void tst_QLatin1StringMatcher::overloads()
QCOMPARE(m.indexIn(hello, 1), -1);
QCOMPARE(m.indexIn(hello2, 1), hello.size());
QCOMPARE(m.indexIn(hello2, 6), -1);
+
+ QCOMPARE(m.indexIn(QString::fromLatin1(hello)), 0);
+ QCOMPARE(m.indexIn(QString::fromLatin1(hello), 1), -1);
+ QCOMPARE(m.indexIn(QString::fromLatin1(hello2), 1), hello.size());
+ QCOMPARE(m.indexIn(QString::fromLatin1(hello2), 6), -1);
}
}
@@ -387,25 +418,35 @@ void tst_QLatin1StringMatcher::haystacksWithMoreThan4GiBWork()
QCOMPARE(large.size(), BaseSize + needle.size());
qDebug("created dataset in %lld ms", timer.elapsed());
- using MaybeThread = std::thread;
-
- //
- // WHEN: trying to match an occurrence past the 4GiB mark
- //
-
- qsizetype dynamicResult;
-
- auto t = MaybeThread{ [&] {
- QLatin1StringMatcher m(QLatin1StringView(needle), Qt::CaseSensitive);
- dynamicResult = m.indexIn(QLatin1StringView(large));
- } };
- t.join();
+ {
+ //
+ // WHEN: trying to match an occurrence past the 4GiB mark
+ //
+ qsizetype dynamicResult;
+ auto t = std::thread{ [&] {
+ QLatin1StringMatcher m(QLatin1StringView(needle), Qt::CaseSensitive);
+ dynamicResult = m.indexIn(QLatin1StringView(large));
+ } };
+ t.join();
+
+ //
+ // THEN: the result index is not truncated
+ //
+
+ QCOMPARE(dynamicResult, qsizetype(BaseSize));
+ }
- //
- // THEN: the result index is not trucated
- //
+ {
+ qsizetype dynamicResult;
+ auto t = std::thread{ [&] {
+ QLatin1StringMatcher m(QLatin1StringView(needle), Qt::CaseSensitive);
+ dynamicResult = m.indexIn(QStringView(QString::fromLatin1(large)));
+ } };
+ t.join();
+
+ QCOMPARE(dynamicResult, qsizetype(BaseSize));
+ }
- QCOMPARE(dynamicResult, qsizetype(BaseSize));
#else
QSKIP("This test is 64-bit only.");
#endif