From 2766322de37adba37e0d0d4b0054e55edff01c6c Mon Sep 17 00:00:00 2001 From: Karsten Heimrich Date: Wed, 12 Aug 2020 13:16:27 +0200 Subject: Move QStringRef and remains to Qt5Compat Export some private functions from QUtf8 to resolve undefined symbols in Qt5Compat after moving QStringRef. Task-number: QTBUG-84437 Change-Id: I9046dcb14ed520d8868a511d79da6e721e26f72b Reviewed-by: Lars Knoll --- tests/auto/corelib/io/qdebug/tst_qdebug.cpp | 44 +- .../serialization/qtextstream/tst_qtextstream.cpp | 6 +- tests/auto/corelib/text/.prev_CMakeLists.txt | 1 - tests/auto/corelib/text/CMakeLists.txt | 1 - tests/auto/corelib/text/qlocale/tst_qlocale.cpp | 10 +- .../qregularexpression/tst_qregularexpression.cpp | 30 +- tests/auto/corelib/text/qstring/tst_qstring.cpp | 468 +---- .../qstringapisymmetry/tst_qstringapisymmetry.cpp | 546 ++--- .../qstringbuilder1/stringbuilder.cpp | 22 +- .../text/qstringmatcher/tst_qstringmatcher.cpp | 2 +- tests/auto/corelib/text/qstringref/CMakeLists.txt | 10 - tests/auto/corelib/text/qstringref/qstringref.pro | 4 - .../corelib/text/qstringref/tst_qstringref.cpp | 2165 -------------------- .../corelib/text/qstringview/tst_qstringview.cpp | 52 - tests/auto/corelib/text/text.pro | 1 - .../tst_containerapisymmetry.cpp | 2 - .../tools/qhashfunctions/tst_qhashfunctions.cpp | 12 +- tests/auto/tools/qmakelib/evaltest.cpp | 5 +- tests/auto/tools/qmakelib/parsertest.cpp | 2 +- .../kernel/qapplication/tst_qapplication.cpp | 2 +- 20 files changed, 242 insertions(+), 3143 deletions(-) delete mode 100644 tests/auto/corelib/text/qstringref/CMakeLists.txt delete mode 100644 tests/auto/corelib/text/qstringref/qstringref.pro delete mode 100644 tests/auto/corelib/text/qstringref/tst_qstringref.cpp (limited to 'tests/auto') diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp index 0b54f53517..3dbda13643 100644 --- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp +++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp @@ -66,7 +66,6 @@ private slots: void veryLongWarningMessage() const; void qDebugQChar() const; void qDebugQString() const; - void qDebugQStringRef() const; void qDebugQStringView() const; void qDebugQLatin1String() const; void qDebugQByteArray() const; @@ -438,7 +437,7 @@ void tst_QDebug::qDebugQString() const QString file, function; int line = 0; const QString in(QLatin1String("input")); - const QStringRef inRef(&in); + const QStringView inRef{ in }; MessageHandlerSetter mhs(myMessageHandler); { qDebug() << inRef; } @@ -509,47 +508,6 @@ void tst_QDebug::qDebugQString() const QCOMPARE(s_msg, QString("\"\\uDC00\\uD800x\\uD800\"")); } -void tst_QDebug::qDebugQStringRef() const -{ - /* Use a basic string. */ - { - QString file, function; - int line = 0; - const QString in(QLatin1String("input")); - const QStringRef inRef(&in); - - MessageHandlerSetter mhs(myMessageHandler); - { qDebug() << inRef; } -#ifndef QT_NO_MESSAGELOGCONTEXT - file = __FILE__; line = __LINE__ - 2; function = Q_FUNC_INFO; -#endif - QCOMPARE(s_msgType, QtDebugMsg); - QCOMPARE(s_msg, QString::fromLatin1("\"input\"")); - QCOMPARE(QString::fromLatin1(s_file), file); - QCOMPARE(s_line, line); - QCOMPARE(QString::fromLatin1(s_function), function); - } - - /* Use a null QStringRef. */ - { - QString file, function; - int line = 0; - - const QStringRef inRef; - - MessageHandlerSetter mhs(myMessageHandler); - { qDebug() << inRef; } -#ifndef QT_NO_MESSAGELOGCONTEXT - file = __FILE__; line = __LINE__ - 2; function = Q_FUNC_INFO; -#endif - QCOMPARE(s_msgType, QtDebugMsg); - QCOMPARE(s_msg, QString::fromLatin1("\"\"")); - QCOMPARE(QString::fromLatin1(s_file), file); - QCOMPARE(s_line, line); - QCOMPARE(QString::fromLatin1(s_function), function); - } -} - void tst_QDebug::qDebugQStringView() const { /* Use a basic string. */ diff --git a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp index 6a09512235..72a69a6dfd 100644 --- a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp @@ -2528,10 +2528,10 @@ void tst_QTextStream::stringref_write_operator_ToDevice() stream.setEncoding(QStringConverter::Latin1); stream.setAutoDetectUnicode(true); - const QString expected = "No explicit lengthExplicit length"; + const QStringView expected = u"No explicit lengthExplicit length"; - stream << expected.leftRef(18); - stream << expected.midRef(18); + stream << expected.left(18); + stream << expected.mid(18); stream.flush(); QCOMPARE(buf.buffer().constData(), "No explicit lengthExplicit length"); } diff --git a/tests/auto/corelib/text/.prev_CMakeLists.txt b/tests/auto/corelib/text/.prev_CMakeLists.txt index d68a8e9c2d..aa2b8f31b2 100644 --- a/tests/auto/corelib/text/.prev_CMakeLists.txt +++ b/tests/auto/corelib/text/.prev_CMakeLists.txt @@ -16,6 +16,5 @@ add_subdirectory(qstringbuilder) add_subdirectory(qstringiterator) add_subdirectory(qstringlist) add_subdirectory(qstringmatcher) -add_subdirectory(qstringref) add_subdirectory(qstringview) add_subdirectory(qtextboundaryfinder) diff --git a/tests/auto/corelib/text/CMakeLists.txt b/tests/auto/corelib/text/CMakeLists.txt index 285fdb27c3..93efdf2d71 100644 --- a/tests/auto/corelib/text/CMakeLists.txt +++ b/tests/auto/corelib/text/CMakeLists.txt @@ -19,7 +19,6 @@ add_subdirectory(qstringconverter) add_subdirectory(qstringiterator) add_subdirectory(qstringlist) add_subdirectory(qstringmatcher) -add_subdirectory(qstringref) add_subdirectory(qstringtokenizer) add_subdirectory(qstringview) add_subdirectory(qtextboundaryfinder) diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index 52752690da..f2e4dc0ea9 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -910,7 +910,7 @@ void tst_QLocale::stringToDouble() QFETCH(QString, num_str); QFETCH(bool, good); QFETCH(double, num); - QStringRef num_strRef = num_str.leftRef(-1); + QStringView num_strRef{ num_str }; QLocale locale(locale_name); QCOMPARE(locale.name(), locale_name); @@ -996,7 +996,7 @@ void tst_QLocale::stringToFloat() QFETCH(QString, num_str); QFETCH(bool, good); QFETCH(double, num); - QStringRef num_strRef = num_str.leftRef(-1); + QStringView num_strRef{ num_str }; float fnum = num; QLocale locale(locale_name); @@ -1289,8 +1289,8 @@ void tst_QLocale::strtod() QCOMPARE(actualOk, ok); } - // and QStringRef, but we can limit the length without allocating memory - QStringRef num_strref(&num_str, 0, processed); + // and QStringView, but we can limit the length without allocating memory + QStringView num_strref = QStringView{ num_str }.mid(0, processed); actualOk = false; QCOMPARE(QLocale::c().toDouble(num_strref, &actualOk), num); QCOMPARE(actualOk, ok); @@ -1355,7 +1355,7 @@ void tst_QLocale::long_long_conversion() QFETCH(QString, num_str); QFETCH(bool, good); QFETCH(qlonglong, num); - QStringRef num_strRef = num_str.leftRef(-1); + QStringView num_strRef{ num_str }; QLocale locale(locale_name); QCOMPARE(locale.name(), locale_name); diff --git a/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp index 98cbd0b4a5..ab93373d44 100644 --- a/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp +++ b/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp @@ -75,7 +75,7 @@ private slots: void regularExpressionMatch(); void JOptionUsage_data(); void JOptionUsage(); - void QStringAndQStringRefEquivalence(); + void QStringAndQStringViewEquivalence(); void threadSafety_data(); void threadSafety(); @@ -1706,7 +1706,7 @@ void tst_QRegularExpression::JOptionUsage() QCOMPARE(re.isValid(), isValid); } -void tst_QRegularExpression::QStringAndQStringRefEquivalence() +void tst_QRegularExpression::QStringAndQStringViewEquivalence() { const QString subject = QStringLiteral("Mississippi"); { @@ -1722,7 +1722,7 @@ void tst_QRegularExpression::QStringAndQStringRefEquivalence() QCOMPARE(match.capturedEnd(), 4); } { - const QRegularExpressionMatch match = re.match(QStringRef(&subject)); + const QRegularExpressionMatch match = re.match(QStringView(subject)); consistencyCheck(match); QVERIFY(match.isValid()); QVERIFY(match.hasMatch()); @@ -1740,7 +1740,7 @@ void tst_QRegularExpression::QStringAndQStringRefEquivalence() QCOMPARE(match.capturedEnd(), 4); } { - const QRegularExpressionMatch match = re.match(QStringRef(&subject), 1); + const QRegularExpressionMatch match = re.match(QStringView(subject), 1); consistencyCheck(match); QVERIFY(match.isValid()); QVERIFY(match.hasMatch()); @@ -1758,7 +1758,7 @@ void tst_QRegularExpression::QStringAndQStringRefEquivalence() QCOMPARE(match.capturedEnd(), 6); } { - const QRegularExpressionMatch match = re.match(subject.midRef(1)); + const QRegularExpressionMatch match = re.match(QStringView(subject).mid(1)); consistencyCheck(match); QVERIFY(match.isValid()); QVERIFY(match.hasMatch()); @@ -1776,7 +1776,7 @@ void tst_QRegularExpression::QStringAndQStringRefEquivalence() QCOMPARE(match.capturedEnd(), 6); } { - const QRegularExpressionMatch match = re.match(subject.midRef(1), 1); + const QRegularExpressionMatch match = re.match(QStringView(subject).mid(1), 1); consistencyCheck(match); QVERIFY(match.isValid()); QVERIFY(match.hasMatch()); @@ -1794,7 +1794,7 @@ void tst_QRegularExpression::QStringAndQStringRefEquivalence() QCOMPARE(match.capturedEnd(), 7); } { - const QRegularExpressionMatch match = re.match(QStringRef(&subject), 4); + const QRegularExpressionMatch match = re.match(QStringView(subject), 4); consistencyCheck(match); QVERIFY(match.isValid()); QVERIFY(match.hasMatch()); @@ -1809,7 +1809,7 @@ void tst_QRegularExpression::QStringAndQStringRefEquivalence() QVERIFY(!match.hasMatch()); } { - const QRegularExpressionMatch match = re.match(subject.midRef(4)); + const QRegularExpressionMatch match = re.match(QStringView(subject).mid(4)); consistencyCheck(match); QVERIFY(match.isValid()); QVERIFY(!match.hasMatch()); @@ -1842,7 +1842,7 @@ void tst_QRegularExpression::QStringAndQStringRefEquivalence() QVERIFY(!i.hasNext()); } { - QRegularExpressionMatchIterator i = re.globalMatch(QStringRef(&subject)); + QRegularExpressionMatchIterator i = re.globalMatch(QStringView(subject)); QVERIFY(i.isValid()); consistencyCheck(i); @@ -1894,7 +1894,7 @@ void tst_QRegularExpression::QStringAndQStringRefEquivalence() QVERIFY(!i.hasNext()); } { - QRegularExpressionMatchIterator i = re.globalMatch(QStringRef(&subject), 1); + QRegularExpressionMatchIterator i = re.globalMatch(QStringView(subject), 1); QVERIFY(i.isValid()); consistencyCheck(i); @@ -1936,7 +1936,7 @@ void tst_QRegularExpression::QStringAndQStringRefEquivalence() QVERIFY(!i.hasNext()); } { - QRegularExpressionMatchIterator i = re.globalMatch(subject.midRef(1)); + QRegularExpressionMatchIterator i = re.globalMatch(QStringView(subject).mid(1)); QVERIFY(i.isValid()); consistencyCheck(i); @@ -1968,7 +1968,7 @@ void tst_QRegularExpression::QStringAndQStringRefEquivalence() QVERIFY(!i.hasNext()); } { - QRegularExpressionMatchIterator i = re.globalMatch(subject.midRef(1), 1); + QRegularExpressionMatchIterator i = re.globalMatch(QStringView(subject).mid(1), 1); QVERIFY(i.isValid()); consistencyCheck(i); @@ -2000,7 +2000,7 @@ void tst_QRegularExpression::QStringAndQStringRefEquivalence() QVERIFY(!i.hasNext()); } { - QRegularExpressionMatchIterator i = re.globalMatch(subject.midRef(1), 1); + QRegularExpressionMatchIterator i = re.globalMatch(QStringView(subject).mid(1), 1); QVERIFY(i.isValid()); consistencyCheck(i); @@ -2033,7 +2033,7 @@ void tst_QRegularExpression::QStringAndQStringRefEquivalence() QVERIFY(!i.hasNext()); } { - QRegularExpressionMatchIterator i = re.globalMatch(QStringRef(&subject), 4); + QRegularExpressionMatchIterator i = re.globalMatch(QStringView(subject), 4); QVERIFY(i.isValid()); consistencyCheck(i); @@ -2055,7 +2055,7 @@ void tst_QRegularExpression::QStringAndQStringRefEquivalence() QVERIFY(!i.hasNext()); } { - QRegularExpressionMatchIterator i = re.globalMatch(subject.midRef(4)); + QRegularExpressionMatchIterator i = re.globalMatch(QStringView(subject).mid(4)); consistencyCheck(i); QVERIFY(i.isValid()); QVERIFY(!i.hasNext()); diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index b26381c387..172e8c41af 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -53,9 +53,9 @@ #include #include -#define CREATE_REF(string) \ - const QString padded = QLatin1Char(' ') + string + QLatin1Char(' '); \ - QStringRef ref = padded.midRef(1, padded.size() - 2); +#define CREATE_VIEW(string) \ + const QString padded = QLatin1Char(' ') + string + QLatin1Char(' '); \ + const QStringView view = QStringView{ padded }.mid(1, padded.size() - 2); namespace { @@ -118,23 +118,6 @@ public: { (s.*mf)(a1, this->pinned); } }; -template <> -class Arg : ArgBase -{ - QStringRef ref() const - { return QStringRef(&pinned); } -public: - explicit Arg(const char *str) : ArgBase(str) {} - - template - void apply0(QString &s, MemFun mf) const - { (s.*mf)(ref()); } - - template - void apply1(QString &s, MemFun mf, A1 a1) const - { (s.*mf)(a1, ref()); } -}; - template <> class Arg : ArgBase { @@ -482,10 +465,6 @@ private slots: void mid(); void right(); void left(); - void midRef(); - void rightRef(); - void leftRef(); - void stringRef(); void contains(); void count(); void lastIndexOf_data(); @@ -530,12 +509,6 @@ private slots: void fromLatin1Roundtrip(); void toLatin1Roundtrip_data(); void toLatin1Roundtrip(); - void stringRef_toLatin1Roundtrip_data(); - void stringRef_toLatin1Roundtrip(); - void stringRef_utf8_data(); - void stringRef_utf8(); - void stringRef_local8Bit_data(); - void stringRef_local8Bit(); void fromLatin1(); void fromUcs4(); void toUcs4(); @@ -561,10 +534,6 @@ private slots: void split(); void split_regularexpression_data(); void split_regularexpression(); - void splitRef_data(); - void splitRef(); - void splitRef_regularexpression_data(); - void splitRef_regularexpression(); void fromUtf16_data(); void fromUtf16(); void fromUtf16_char16_data(); @@ -583,7 +552,6 @@ private slots: void repeatedSignature() const; void repeated() const; void repeated_data() const; - void compareRef(); void arg_locale(); #if QT_CONFIG(icu) void toUpperLower_icu(); @@ -1451,14 +1419,14 @@ void tst_QString::indexOf() QFETCH( int, startpos ); QFETCH( bool, bcs ); QFETCH( int, resultpos ); - CREATE_REF(needle); + CREATE_VIEW(needle); Qt::CaseSensitivity cs = bcs ? Qt::CaseSensitive : Qt::CaseInsensitive; bool needleIsLatin = (QString::fromLatin1(needle.toLatin1()) == needle); QCOMPARE( haystack.indexOf(needle, startpos, cs), resultpos ); - QCOMPARE( haystack.indexOf(ref, startpos, cs), resultpos ); + QCOMPARE( haystack.indexOf(view, startpos, cs), resultpos ); if (needleIsLatin) { QCOMPARE( haystack.indexOf(needle.toLatin1(), startpos, cs), resultpos ); QCOMPARE( haystack.indexOf(needle.toLatin1().data(), startpos, cs), resultpos ); @@ -1487,14 +1455,14 @@ void tst_QString::indexOf() if (cs == Qt::CaseSensitive) { QCOMPARE( haystack.indexOf(needle, startpos), resultpos ); - QCOMPARE( haystack.indexOf(ref, startpos), resultpos ); + QCOMPARE( haystack.indexOf(view, startpos), resultpos ); if (needleIsLatin) { QCOMPARE( haystack.indexOf(needle.toLatin1(), startpos), resultpos ); QCOMPARE( haystack.indexOf(needle.toLatin1().data(), startpos), resultpos ); } if (startpos == 0) { QCOMPARE( haystack.indexOf(needle), resultpos ); - QCOMPARE( haystack.indexOf(ref), resultpos ); + QCOMPARE( haystack.indexOf(view), resultpos ); if (needleIsLatin) { QCOMPARE( haystack.indexOf(needle.toLatin1()), resultpos ); QCOMPARE( haystack.indexOf(needle.toLatin1().data()), resultpos ); @@ -1503,7 +1471,7 @@ void tst_QString::indexOf() } if (needle.size() == 1) { QCOMPARE(haystack.indexOf(needle.at(0), startpos, cs), resultpos); - QCOMPARE(haystack.indexOf(ref.at(0), startpos, cs), resultpos); + QCOMPARE(haystack.indexOf(view.at(0), startpos, cs), resultpos); } } @@ -1564,17 +1532,17 @@ void tst_QString::indexOf2() QFETCH( QString, haystack ); QFETCH( QString, needle ); QFETCH( int, resultpos ); - CREATE_REF(needle); + CREATE_VIEW(needle); QByteArray chaystack = haystack.toLatin1(); QByteArray cneedle = needle.toLatin1(); int got; QCOMPARE( haystack.indexOf(needle, 0, Qt::CaseSensitive), resultpos ); - QCOMPARE( haystack.indexOf(ref, 0, Qt::CaseSensitive), resultpos ); + QCOMPARE( haystack.indexOf(view, 0, Qt::CaseSensitive), resultpos ); QCOMPARE( QStringMatcher(needle, Qt::CaseSensitive).indexIn(haystack, 0), resultpos ); QCOMPARE( haystack.indexOf(needle, 0, Qt::CaseInsensitive), resultpos ); - QCOMPARE( haystack.indexOf(ref, 0, Qt::CaseInsensitive), resultpos ); + QCOMPARE( haystack.indexOf(view, 0, Qt::CaseInsensitive), resultpos ); QCOMPARE( QStringMatcher(needle, Qt::CaseInsensitive).indexIn(haystack, 0), resultpos ); if ( needle.length() > 0 ) { got = haystack.lastIndexOf( needle, -1, Qt::CaseSensitive ); @@ -1655,12 +1623,12 @@ void tst_QString::lastIndexOf() QFETCH(int, from); QFETCH(int, expected); QFETCH(bool, caseSensitive); - CREATE_REF(needle); + CREATE_VIEW(needle); Qt::CaseSensitivity cs = (caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive); QCOMPARE(haystack.lastIndexOf(needle, from, cs), expected); - QCOMPARE(haystack.lastIndexOf(ref, from, cs), expected); + QCOMPARE(haystack.lastIndexOf(view, from, cs), expected); QCOMPARE(haystack.lastIndexOf(needle.toLatin1(), from, cs), expected); QCOMPARE(haystack.lastIndexOf(needle.toLatin1().data(), from, cs), expected); @@ -1690,19 +1658,19 @@ void tst_QString::lastIndexOf() if (cs == Qt::CaseSensitive) { QCOMPARE(haystack.lastIndexOf(needle, from), expected); - QCOMPARE(haystack.lastIndexOf(ref, from), expected); + QCOMPARE(haystack.lastIndexOf(view, from), expected); QCOMPARE(haystack.lastIndexOf(needle.toLatin1(), from), expected); QCOMPARE(haystack.lastIndexOf(needle.toLatin1().data(), from), expected); if (from == -1) { QCOMPARE(haystack.lastIndexOf(needle), expected); - QCOMPARE(haystack.lastIndexOf(ref), expected); + QCOMPARE(haystack.lastIndexOf(view), expected); QCOMPARE(haystack.lastIndexOf(needle.toLatin1()), expected); QCOMPARE(haystack.lastIndexOf(needle.toLatin1().data()), expected); } } if (needle.size() == 1) { QCOMPARE(haystack.lastIndexOf(needle.at(0), from), expected); - QCOMPARE(haystack.lastIndexOf(ref.at(0), from), expected); + QCOMPARE(haystack.lastIndexOf(view.at(0), from), expected); } } @@ -1738,13 +1706,10 @@ void tst_QString::count() QTest::ignoreMessage(QtWarningMsg, "QString::count: invalid QRegularExpression object"); QCOMPARE(a.count(QRegularExpression("invalid regex\\")), 0); - CREATE_REF(QLatin1String("FG")); - QCOMPARE(a.count(ref),2); - QCOMPARE(a.count(ref,Qt::CaseInsensitive),3); - QCOMPARE(a.count( QStringRef(), Qt::CaseInsensitive), 16); - QStringRef emptyRef(&a, 0, 0); - QCOMPARE(a.count( emptyRef, Qt::CaseInsensitive), 16); - + CREATE_VIEW(QLatin1String("FG")); + QCOMPARE(a.count(view),2); + QCOMPARE(a.count(view,Qt::CaseInsensitive),3); + QCOMPARE(a.count( QStringView(), Qt::CaseInsensitive), 16); } void tst_QString::contains() @@ -1814,12 +1779,10 @@ void tst_QString::contains() QVERIFY(!a.contains(QRegularExpression("ZZZ"), 0)); } - CREATE_REF(QLatin1String("FG")); - QVERIFY(a.contains(ref)); - QVERIFY(a.contains(ref, Qt::CaseInsensitive)); - QVERIFY(a.contains( QStringRef(), Qt::CaseInsensitive)); - QStringRef emptyRef(&a, 0, 0); - QVERIFY(a.contains(emptyRef, Qt::CaseInsensitive)); + CREATE_VIEW(QLatin1String("FG")); + QVERIFY(a.contains(view)); + QVERIFY(a.contains(view, Qt::CaseInsensitive)); + QVERIFY(a.contains( QStringView(), Qt::CaseInsensitive)); QTest::ignoreMessage(QtWarningMsg, "QString::contains: invalid QRegularExpression object"); QVERIFY(!a.contains(QRegularExpression("invalid regex\\"))); @@ -1844,25 +1807,6 @@ void tst_QString::left() QCOMPARE(l.left(100), l); } -void tst_QString::leftRef() -{ - QString a; - a="ABCDEFGHIEfGEFG"; // 15 chars - QCOMPARE(a.leftRef(3).toString(), QLatin1String("ABC")); - - QVERIFY(a.leftRef(0).toString().isEmpty()); - QCOMPARE(a.leftRef(0).toString(), QLatin1String("")); - - QString n; - QVERIFY(n.leftRef(3).toString().isEmpty()); - QVERIFY(n.leftRef(0).toString().isEmpty()); - QVERIFY(n.leftRef(0).toString().isEmpty()); - - QString l = "Left"; - QCOMPARE(l.leftRef(-1).toString(), l); - QCOMPARE(l.leftRef(100).toString(), l); -} - void tst_QString::right() { QString a; @@ -1879,22 +1823,6 @@ void tst_QString::right() QCOMPARE(r.right(100), r); } -void tst_QString::rightRef() -{ - QString a; - a="ABCDEFGHIEfGEFG"; // 15 chars - QCOMPARE(a.rightRef(3).toString(), QLatin1String("EFG")); - QCOMPARE(a.rightRef(0).toString(), QLatin1String("")); - - QString n; - QVERIFY(n.rightRef(3).toString().isEmpty()); - QVERIFY(n.rightRef(0).toString().isEmpty()); - - QString r = "Right"; - QCOMPARE(r.rightRef(-1).toString(), r); - QCOMPARE(r.rightRef(100).toString(), r); -} - void tst_QString::mid() { QString a; @@ -1974,132 +1902,6 @@ void tst_QString::mid() QCOMPARE(x.mid(-1, -1), x); } -void tst_QString::midRef() -{ - QString a; - a="ABCDEFGHIEfGEFG"; // 15 chars - - QCOMPARE(a.midRef(3,3).toString(), QLatin1String("DEF")); - QCOMPARE(a.midRef(0,0).toString(), QLatin1String("")); - QVERIFY(!a.midRef(15,0).toString().isNull()); - QVERIFY(a.midRef(15,0).toString().isEmpty()); - QVERIFY(!a.midRef(15,1).toString().isNull()); - QVERIFY(a.midRef(15,1).toString().isEmpty()); - QVERIFY(a.midRef(9999).toString().isEmpty()); - QVERIFY(a.midRef(9999,1).toString().isEmpty()); - - QCOMPARE(a.midRef(-1, 6), a.midRef(0, 5)); - QVERIFY(a.midRef(-100, 6).isEmpty()); - QVERIFY(a.midRef(INT_MIN, 0).isEmpty()); - QCOMPARE(a.midRef(INT_MIN, -1).toString(), a); - QVERIFY(a.midRef(INT_MIN, INT_MAX).isNull()); - QVERIFY(a.midRef(INT_MIN + 1, INT_MAX).isEmpty()); - QCOMPARE(a.midRef(INT_MIN + 2, INT_MAX), a.leftRef(1)); - QCOMPARE(a.midRef(INT_MIN + a.size() + 1, INT_MAX).toString(), a); - QVERIFY(a.midRef(INT_MAX).isNull()); - QVERIFY(a.midRef(INT_MAX, INT_MAX).isNull()); - QCOMPARE(a.midRef(-5, INT_MAX).toString(), a); - QCOMPARE(a.midRef(-1, INT_MAX).toString(), a); - QCOMPARE(a.midRef(0, INT_MAX).toString(), a); - QCOMPARE(a.midRef(1, INT_MAX).toString(), QString("BCDEFGHIEfGEFG")); - QCOMPARE(a.midRef(5, INT_MAX).toString(), QString("FGHIEfGEFG")); - QVERIFY(a.midRef(20, INT_MAX).isNull()); - QCOMPARE(a.midRef(-1, -1).toString(), a); - - QString n; - QVERIFY(n.midRef(3,3).toString().isEmpty()); - QVERIFY(n.midRef(0,0).toString().isEmpty()); - QVERIFY(n.midRef(9999,0).toString().isEmpty()); - QVERIFY(n.midRef(9999,1).toString().isEmpty()); - - QVERIFY(n.midRef(-1, 6).isNull()); - QVERIFY(n.midRef(-100, 6).isNull()); - QVERIFY(n.midRef(INT_MIN, 0).isNull()); - QVERIFY(n.midRef(INT_MIN, -1).isNull()); - QVERIFY(n.midRef(INT_MIN, INT_MAX).isNull()); - QVERIFY(n.midRef(INT_MIN + 1, INT_MAX).isNull()); - QVERIFY(n.midRef(INT_MIN + 2, INT_MAX).isNull()); - QVERIFY(n.midRef(INT_MIN + n.size() + 1, INT_MAX).isNull()); - QVERIFY(n.midRef(INT_MAX).isNull()); - QVERIFY(n.midRef(INT_MAX, INT_MAX).isNull()); - QVERIFY(n.midRef(-5, INT_MAX).isNull()); - QVERIFY(n.midRef(-1, INT_MAX).isNull()); - QVERIFY(n.midRef(0, INT_MAX).isNull()); - QVERIFY(n.midRef(1, INT_MAX).isNull()); - QVERIFY(n.midRef(5, INT_MAX).isNull()); - QVERIFY(n.midRef(20, INT_MAX).isNull()); - QVERIFY(n.midRef(-1, -1).isNull()); - - QString x = "Nine pineapples"; - QCOMPARE(x.midRef(5, 4).toString(), QString("pine")); - QCOMPARE(x.midRef(5).toString(), QString("pineapples")); - - QCOMPARE(x.midRef(-1, 6), x.midRef(0, 5)); - QVERIFY(x.midRef(-100, 6).isEmpty()); - QVERIFY(x.midRef(INT_MIN, 0).isEmpty()); - QCOMPARE(x.midRef(INT_MIN, -1).toString(), x); - QVERIFY(x.midRef(INT_MIN, INT_MAX).isNull()); - QVERIFY(x.midRef(INT_MIN + 1, INT_MAX).isEmpty()); - QCOMPARE(x.midRef(INT_MIN + 2, INT_MAX), x.leftRef(1)); - QCOMPARE(x.midRef(INT_MIN + x.size() + 1, INT_MAX).toString(), x); - QVERIFY(x.midRef(INT_MAX).isNull()); - QVERIFY(x.midRef(INT_MAX, INT_MAX).isNull()); - QCOMPARE(x.midRef(-5, INT_MAX).toString(), x); - QCOMPARE(x.midRef(-1, INT_MAX).toString(), x); - QCOMPARE(x.midRef(0, INT_MAX).toString(), x); - QCOMPARE(x.midRef(1, INT_MAX).toString(), QString("ine pineapples")); - QCOMPARE(x.midRef(5, INT_MAX).toString(), QString("pineapples")); - QVERIFY(x.midRef(20, INT_MAX).isNull()); - QCOMPARE(x.midRef(-1, -1).toString(), x); -} - -void tst_QString::stringRef() -{ - QString a; - a="ABCDEFGHIEfGEFG"; // 15 chars - - QVERIFY(QStringRef(&a, 0, 0) == (QString)""); - - QVERIFY(QStringRef(&a, 3, 3) == (QString)"DEF"); - QVERIFY(QStringRef(&a, 3, 3) == QLatin1String("DEF")); - QVERIFY(QStringRef(&a, 3, 3) == "DEF"); - QVERIFY((QString)"DEF" == QStringRef(&a, 3, 3)); - QVERIFY(QLatin1String("DEF") == QStringRef(&a, 3, 3)); - QVERIFY("DEF" == QStringRef(&a, 3, 3)); - - QVERIFY(QStringRef(&a, 3, 3) != (QString)"DE"); - QVERIFY(QStringRef(&a, 3, 3) != QLatin1String("DE")); - QVERIFY(QStringRef(&a, 3, 3) != "DE"); - QVERIFY((QString)"DE" != QStringRef(&a, 3, 3)); - QVERIFY(QLatin1String("DE") != QStringRef(&a, 3, 3)); - QVERIFY("DE" != QStringRef(&a, 3, 3)); - - QString s_alpha("alpha"); - QString s_beta("beta"); - QStringRef alpha(&s_alpha); - QStringRef beta(&s_beta); - - QVERIFY(alpha < beta); - QVERIFY(alpha <= beta); - QVERIFY(alpha <= alpha); - QVERIFY(beta > alpha); - QVERIFY(beta >= alpha); - QVERIFY(beta >= beta); - - QString s_alpha2("alpha"); - - QMap map; - map.insert(alpha, "alpha"); - map.insert(beta, "beta"); - QVERIFY(alpha == map.value(QStringRef(&s_alpha2))); - - QHash hash; - hash.insert(alpha, "alpha"); - hash.insert(beta, "beta"); - - QVERIFY(alpha == hash.value(QStringRef(&s_alpha2))); -} - void tst_QString::leftJustified() { QString a; @@ -3843,13 +3645,12 @@ void tst_QString::startsWith() QVERIFY( !a.startsWith(QChar(), Qt::CaseSensitive) ); QVERIFY( !a.startsWith(QLatin1Char(0), Qt::CaseSensitive) ); -#define TEST_REF_STARTS_WITH(string, yes) { CREATE_REF(string); QCOMPARE(a.startsWith(ref), yes); } - - TEST_REF_STARTS_WITH("A", true); - TEST_REF_STARTS_WITH("AB", true); - TEST_REF_STARTS_WITH("C", false); - TEST_REF_STARTS_WITH("ABCDEF", false); -#undef TEST_REF_STARTS_WITH +#define TEST_VIEW_STARTS_WITH(string, yes) { CREATE_VIEW(string); QCOMPARE(a.startsWith(view), yes); } + TEST_VIEW_STARTS_WITH("A", true); + TEST_VIEW_STARTS_WITH("AB", true); + TEST_VIEW_STARTS_WITH("C", false); + TEST_VIEW_STARTS_WITH("ABCDEF", false); +#undef TEST_VIEW_STARTS_WITH a = ""; QVERIFY( a.startsWith("") ); @@ -3951,16 +3752,14 @@ void tst_QString::endsWith() QVERIFY( !a.endsWith(QChar(), Qt::CaseSensitive) ); QVERIFY( !a.endsWith(QLatin1Char(0), Qt::CaseSensitive) ); - -#define TEST_REF_ENDS_WITH(string, yes) { CREATE_REF(string); QCOMPARE(a.endsWith(ref), yes); } - TEST_REF_ENDS_WITH(QLatin1String("B"), true); - TEST_REF_ENDS_WITH(QLatin1String("AB"), true); - TEST_REF_ENDS_WITH(QLatin1String("C"), false); - TEST_REF_ENDS_WITH(QLatin1String("ABCDEF"), false); - TEST_REF_ENDS_WITH(QLatin1String(""), true); - TEST_REF_ENDS_WITH(QLatin1String(0), true); - -#undef TEST_REF_STARTS_WITH +#define TEST_VIEW_ENDS_WITH(string, yes) { CREATE_VIEW(string); QCOMPARE(a.endsWith(view), yes); } + TEST_VIEW_ENDS_WITH(QLatin1String("B"), true); + TEST_VIEW_ENDS_WITH(QLatin1String("AB"), true); + TEST_VIEW_ENDS_WITH(QLatin1String("C"), false); + TEST_VIEW_ENDS_WITH(QLatin1String("ABCDEF"), false); + TEST_VIEW_ENDS_WITH(QLatin1String(""), true); + TEST_VIEW_ENDS_WITH(QLatin1String(0), true); +#undef TEST_VIEW_ENDS_WITH a = ""; QVERIFY( a.endsWith("") ); @@ -4133,20 +3932,6 @@ void tst_QString::utf8() QCOMPARE(res.toUtf8(), utf8); } -void tst_QString::stringRef_utf8_data() -{ - utf8_data(); -} - -void tst_QString::stringRef_utf8() -{ - QFETCH( QByteArray, utf8 ); - QFETCH( QString, res ); - - QStringRef ref(&res, 0, res.length()); - QCOMPARE( utf8, QByteArray(ref.toUtf8()) ); -} - void tst_QString::fromUtf8_data() { QTest::addColumn("utf8"); @@ -4420,20 +4205,6 @@ void tst_QString::nullFromLocal8Bit() QVERIFY(a.isEmpty()); } -void tst_QString::stringRef_local8Bit_data() -{ - local8Bit_data(); -} - -void tst_QString::stringRef_local8Bit() -{ - QFETCH(QString, local8Bit); - QFETCH(QByteArray, result); - - QStringRef ref(&local8Bit, 0, local8Bit.length()); - QCOMPARE(ref.toLocal8Bit(), QByteArray(result)); -} - void tst_QString::fromLatin1Roundtrip_data() { QTest::addColumn("latin1"); @@ -4545,38 +4316,6 @@ void tst_QString::toLatin1Roundtrip() s.clear(); } -void tst_QString::stringRef_toLatin1Roundtrip_data() -{ - toLatin1Roundtrip_data(); -} - -void tst_QString::stringRef_toLatin1Roundtrip() -{ - QFETCH(QByteArray, latin1); - QFETCH(QString, unicodesrc); - QFETCH(QString, unicodedst); - - // Qt Test safety check: - QCOMPARE(latin1.isNull(), unicodesrc.isNull()); - QCOMPARE(latin1.isEmpty(), unicodesrc.isEmpty()); - QCOMPARE(latin1.length(), unicodesrc.length()); - QCOMPARE(latin1.isNull(), unicodedst.isNull()); - QCOMPARE(latin1.isEmpty(), unicodedst.isEmpty()); - QCOMPARE(latin1.length(), unicodedst.length()); - - if (!latin1.isEmpty()) - while (latin1.length() < 128) { - latin1 += latin1; - unicodesrc += unicodesrc; - unicodedst += unicodedst; - } - - // toLatin1 - QStringRef src(&unicodesrc, 0, unicodesrc.length()); - QCOMPARE(src.toLatin1().length(), latin1.length()); - QCOMPARE(src.toLatin1(), latin1); -} - void tst_QString::fromLatin1() { QString a; @@ -5602,9 +5341,6 @@ void tst_QString::localeAwareCompare() QFETCH(QString, s2); QFETCH(int, result); - QStringRef r1(&s1, 0, s1.length()); - QStringRef r2(&s2, 0, s2.length()); - if (!locale.isEmpty()) { #if defined (Q_OS_DARWIN) || QT_CONFIG(icu) QSKIP("Setting the locale is not supported on OS X or ICU (you can set the C locale, but that won't affect localeAwareCompare)"); @@ -5640,33 +5376,6 @@ void tst_QString::localeAwareCompare() QVERIFY(testres == 0); } - testres = QString::localeAwareCompare(s1, r2); - if (result < 0) { - QVERIFY(testres < 0); - } else if (result > 0) { - QVERIFY(testres > 0); - } else { - QVERIFY(testres == 0); - } - - testres = QStringRef::localeAwareCompare(r1, r2); - if (result < 0) { - QVERIFY(testres < 0); - } else if (result > 0) { - QVERIFY(testres > 0); - } else { - QVERIFY(testres == 0); - } - - testres = QStringRef::localeAwareCompare(r2, r1); - if (result > 0) { - QVERIFY(testres < 0); - } else if (result < 0) { - QVERIFY(testres > 0); - } else { - QVERIFY(testres == 0); - } - if (!locale.isEmpty()) setlocale(LC_ALL, ""); } @@ -5714,14 +5423,6 @@ template<> struct StringSplitWrapper QStringList split(const QRegularExpression &sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts) const { return string.split(sep, behavior); } }; -template<> struct StringSplitWrapper -{ - const QString &string; - QList split(const QString &sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return string.splitRef(sep, behavior, cs); } - QList split(QChar sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return string.splitRef(sep, behavior, cs); } - QList split(const QRegularExpression &sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts) const { return string.splitRef(sep, behavior); } -}; - template<> struct StringSplitWrapper { const QString &string; @@ -5743,16 +5444,6 @@ static bool operator==(const QList &result, const QStringList &expe return true; } - -static bool operator ==(const QStringList &left, const QList &right) -{ - if (left.size() != right.size()) - return false; - - return std::equal(left.constBegin(), left.constEnd(), right.constBegin()); -} -static inline bool operator ==(const QList &left, const QStringList &right) { return right == left; } - template void tst_QString::split(const QString &string, const QString &sep, QStringList result) { @@ -5802,19 +5493,6 @@ void tst_QString::split() split>(str, sep, result); } -void tst_QString::splitRef_data() -{ - split_data(); -} - -void tst_QString::splitRef() -{ - QFETCH(QString, str); - QFETCH(QString, sep); - QFETCH(QStringList, result); - split >(str, sep, result); -} - void tst_QString::split_regularexpression_data() { QTest::addColumn("string"); @@ -5858,19 +5536,6 @@ void tst_QString::split_regularexpression() split_regexp, QRegularExpression>(string, pattern, result); } -void tst_QString::splitRef_regularexpression_data() -{ - split_regularexpression_data(); -} - -void tst_QString::splitRef_regularexpression() -{ - QFETCH(QString, string); - QFETCH(QString, pattern); - QFETCH(QStringList, result); - split_regexp, QRegularExpression>(string, pattern, result); -} - void tst_QString::fromUtf16_data() { QTest::addColumn("ucs2"); @@ -6215,8 +5880,6 @@ void tst_QString::compare() QFETCH(int, csr); QFETCH(int, cir); - QStringRef r1(&s1, 0, s1.length()); - QStringRef r2(&s2, 0, s2.length()); QByteArray s1_8 = s1.toUtf8(); QByteArray s2_8 = s2.toUtf8(); @@ -6224,18 +5887,11 @@ void tst_QString::compare() const QStringView v2(s2); QCOMPARE(sign(QString::compare(s1, s2)), csr); - QCOMPARE(sign(QStringRef::compare(r1, r2)), csr); QCOMPARE(sign(s1.compare(s2)), csr); - QCOMPARE(sign(s1.compare(r2)), csr); - QCOMPARE(sign(r1.compare(r2)), csr); QCOMPARE(sign(s1.compare(v2)), csr); QCOMPARE(sign(s1.compare(s2, Qt::CaseSensitive)), csr); QCOMPARE(sign(s1.compare(s2, Qt::CaseInsensitive)), cir); - QCOMPARE(sign(s1.compare(r2, Qt::CaseSensitive)), csr); - QCOMPARE(sign(s1.compare(r2, Qt::CaseInsensitive)), cir); - QCOMPARE(sign(r1.compare(r2, Qt::CaseSensitive)), csr); - QCOMPARE(sign(r1.compare(r2, Qt::CaseInsensitive)), cir); QCOMPARE(sign(s1.compare(v2, Qt::CaseSensitive)), csr); QCOMPARE(sign(s1.compare(v2, Qt::CaseInsensitive)), cir); QCOMPARE(sign(QtPrivate::compareStringsUtf8(s1_8, s1_8.size(), v2, Qt::CaseSensitive)), csr); @@ -6245,35 +5901,22 @@ void tst_QString::compare() QCOMPARE(sign(QString::compare(s1, s2, Qt::CaseSensitive)), csr); QCOMPARE(sign(QString::compare(s1, s2, Qt::CaseInsensitive)), cir); - QCOMPARE(sign(QString::compare(s1, r2, Qt::CaseSensitive)), csr); - QCOMPARE(sign(QString::compare(s1, r2, Qt::CaseInsensitive)), cir); - QCOMPARE(sign(QStringRef::compare(r1, r2, Qt::CaseSensitive)), csr); - QCOMPARE(sign(QStringRef::compare(r1, r2, Qt::CaseInsensitive)), cir); - if (csr == 0) { + if (csr == 0) QVERIFY(qHash(s1) == qHash(s2)); - QVERIFY(qHash(s1) == qHash(r2)); - QVERIFY(qHash(r1) == qHash(s2)); - QVERIFY(qHash(r1) == qHash(r2)); - } - if (!cir) { + if (!cir) QCOMPARE(s1.toCaseFolded(), s2.toCaseFolded()); - } if (isLatin(s2)) { QVERIFY(QtPrivate::isLatin1(s2)); QCOMPARE(sign(QString::compare(s1, QLatin1String(s2.toLatin1()))), csr); QCOMPARE(sign(QString::compare(s1, QLatin1String(s2.toLatin1()), Qt::CaseInsensitive)), cir); - QCOMPARE(sign(QStringRef::compare(r1, QLatin1String(s2.toLatin1()))), csr); - QCOMPARE(sign(QStringRef::compare(r1, QLatin1String(s2.toLatin1()), Qt::CaseInsensitive)), cir); QByteArray l1 = s2.toLatin1(); l1 += "x"; QLatin1String l1str(l1.constData(), l1.size() - 1); QCOMPARE(sign(QString::compare(s1, l1str)), csr); QCOMPARE(sign(QString::compare(s1, l1str, Qt::CaseInsensitive)), cir); - QCOMPARE(sign(QStringRef::compare(r1, l1str)), csr); - QCOMPARE(sign(QStringRef::compare(r1, l1str, Qt::CaseInsensitive)), cir); } if (isLatin(s1)) { @@ -6508,37 +6151,6 @@ void tst_QString::repeated_data() const << 4; } -void tst_QString::compareRef() -{ - QString a = "ABCDEFGH"; - - QCOMPARE(QStringRef(&a, 1, 2).compare(QLatin1String("BC")), 0); - QVERIFY(QStringRef(&a, 1, 2).compare(QLatin1String("BCD")) < 0); - QCOMPARE(QStringRef(&a, 1, 2).compare(QLatin1String("Bc"), Qt::CaseInsensitive), 0); - QVERIFY(QStringRef(&a, 1, 2).compare(QLatin1String("bCD"), Qt::CaseInsensitive) < 0); - - QCOMPARE(QStringRef(&a, 1, 2).compare(QString::fromLatin1("BC")), 0); - QVERIFY(QStringRef(&a, 1, 2).compare(QString::fromLatin1("BCD")) < 0); - QCOMPARE(QStringRef(&a, 1, 2).compare(QString::fromLatin1("Bc"), Qt::CaseInsensitive), 0); - QVERIFY(QStringRef(&a, 1, 2).compare(QString::fromLatin1("bCD"), Qt::CaseInsensitive) < 0); - - QCOMPARE(QString::fromLatin1("BC").compare(QStringRef(&a, 1, 2)), 0); - QVERIFY(QString::fromLatin1("BCD").compare(QStringRef(&a, 1, 2)) > 0); - QCOMPARE(QString::fromLatin1("Bc").compare(QStringRef(&a, 1, 2), Qt::CaseInsensitive), 0); - QVERIFY(QString::fromLatin1("bCD").compare(QStringRef(&a, 1, 2), Qt::CaseInsensitive) > 0); - - QCOMPARE(QStringRef(&a, 1, 2).compare(QStringRef(&a, 1, 2)), 0); - QVERIFY(QStringRef(&a, 1, 2).compare(QStringRef(&a, 1, 3)) < 0); - QCOMPARE(QStringRef(&a, 1, 2).compare(QStringRef(&a, 1, 2), Qt::CaseInsensitive), 0); - QVERIFY(QStringRef(&a, 1, 2).compare(QStringRef(&a, 1, 3), Qt::CaseInsensitive) < 0); - - QString a2 = "ABCDEFGh"; - QCOMPARE(QStringRef(&a2, 1, 2).compare(QStringRef(&a, 1, 2)), 0); - QVERIFY(QStringRef(&a2, 1, 2).compare(QStringRef(&a, 1, 3)) < 0); - QCOMPARE(QStringRef(&a2, 1, 2).compare(QStringRef(&a, 1, 2), Qt::CaseInsensitive), 0); - QVERIFY(QStringRef(&a2, 1, 2).compare(QStringRef(&a, 1, 3), Qt::CaseInsensitive) < 0); -} - void tst_QString::arg_locale() { QLocale l(QLocale::English, QLocale::UnitedKingdom); diff --git a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp index 2716ee2c8d..9e1c9012ad 100644 --- a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp +++ b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp @@ -36,17 +36,14 @@ #include #include #include -#include #include #include #include Q_DECLARE_METATYPE(QLatin1String) -Q_DECLARE_METATYPE(QStringRef) template QString toQString(const T &t) { return QString(t); } -QString toQString(const QStringRef &ref) { return ref.toString(); } QString toQString(QStringView view) { return view.toString(); } template @@ -120,13 +117,11 @@ class tst_QStringApiSymmetry : public QObject void compare_impl() const; private Q_SLOTS: - // test all combinations of {QChar, char16_t, QStringRef, QString, QStringView, QLatin1String, QByteArray, const char*} + // test all combinations of {QChar, char16_t, QString, QStringView, QLatin1String, QByteArray, const char*} void compare_QChar_QChar_data() { compare_data(false); } void compare_QChar_QChar() { compare_impl(); } void compare_QChar_char16_t_data() { compare_data(false); } void compare_QChar_char16_t() { compare_impl(); } - void compare_QChar_QStringRef_data() { compare_data(false); } - void compare_QChar_QStringRef() { compare_impl(); } void compare_QChar_QString_data() { compare_data(false); } void compare_QChar_QString() { compare_impl(); } void compare_QChar_QStringView_data() { compare_data(false); } @@ -142,8 +137,6 @@ private Q_SLOTS: void compare_char16_t_QChar() { compare_impl(); } //void compare_char16_t_char16_t_data() { compare_data(false); } //void compare_char16_t_char16_t() { compare_impl(); } - void compare_char16_t_QStringRef_data() { compare_data(false); } - void compare_char16_t_QStringRef() { compare_impl(); } void compare_char16_t_QString_data() { compare_data(false); } void compare_char16_t_QString() { compare_impl(); } void compare_char16_t_QStringView_data() { compare_data(false); } @@ -155,29 +148,10 @@ private Q_SLOTS: //void compare_char16_t_const_char_star_data() { compare_data(false); } //void compare_char16_t_const_char_star() { compare_impl(); } - void compare_QStringRef_QChar_data() { compare_data(false); } - void compare_QStringRef_QChar() { compare_impl(); } - void compare_QStringRef_char16_t_data() { compare_data(false); } - void compare_QStringRef_char16_t() { compare_impl(); } - void compare_QStringRef_QStringRef_data() { compare_data(); } - void compare_QStringRef_QStringRef() { compare_impl(); } - void compare_QStringRef_QString_data() { compare_data(); } - void compare_QStringRef_QString() { compare_impl(); } - void compare_QStringRef_QStringView_data() { compare_data(); } - void compare_QStringRef_QStringView() { 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(); } void compare_QString_char16_t_data() { compare_data(false); } void compare_QString_char16_t() { compare_impl(); } - void compare_QString_QStringRef_data() { compare_data(); } - void compare_QString_QStringRef() { compare_impl(); } void compare_QString_QString_data() { compare_data(); } void compare_QString_QString() { compare_impl(); } void compare_QString_QStringView_data() { compare_data(); } @@ -193,8 +167,6 @@ private Q_SLOTS: void compare_QStringView_QChar() { compare_impl(); } void compare_QStringView_char16_t_data() { compare_data(false); } void compare_QStringView_char16_t() { compare_impl(); } - void compare_QStringView_QStringRef_data() { compare_data(); } - void compare_QStringView_QStringRef() { compare_impl(); } void compare_QStringView_QString_data() { compare_data(); } void compare_QStringView_QString() { compare_impl(); } void compare_QStringView_QStringView_data() { compare_data(); } @@ -212,8 +184,6 @@ private Q_SLOTS: void compare_QLatin1String_QChar() { compare_impl(); } void compare_QLatin1String_char16_t_data() { compare_data(false); } void compare_QLatin1String_char16_t() { compare_impl(); } - void compare_QLatin1String_QStringRef_data() { compare_data(); } - void compare_QLatin1String_QStringRef() { compare_impl(); } void compare_QLatin1String_QString_data() { compare_data(); } void compare_QLatin1String_QString() { compare_impl(); } void compare_QLatin1String_QStringView_data() { compare_data(); } @@ -229,8 +199,6 @@ private Q_SLOTS: void compare_QByteArray_QChar() { compare_impl(); } void compare_QByteArray_char16_t_data() { compare_data(false); } void compare_QByteArray_char16_t() { 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_QLatin1String_data() { compare_data(); } void compare_QByteArray_QLatin1String() { compare_impl(); } @@ -243,8 +211,6 @@ private Q_SLOTS: void compare_const_char_star_QChar() { compare_impl(); } //void compare_const_char_star_char16_t_data() { compare_data(false); } //void compare_const_char_star_char16_t() { 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); } @@ -260,14 +226,12 @@ private: void member_compare_impl() const; private Q_SLOTS: - // test all combinations of {QChar, char16_t, QStringRef, QString, QStringView, QLatin1String, QByteArray, const char*} + // test all combinations of {QChar, char16_t, QString, QStringView, QLatin1String, QByteArray, const char*} #ifdef NOT_YET_IMPLEMENTED // probably never will be - what's the point of QChar::compare(QStringView)? void member_compare_QChar_QChar_data() { member_compare_data(false); } void member_compare_QChar_QChar() { member_compare_impl(); } void member_compare_QChar_char16_t_data() { member_compare_data(false); } void member_compare_QChar_char16_t() { member_compare_impl(); } - void member_compare_QChar_QStringRef_data() { member_compare_data(false); } - void member_compare_QChar_QStringRef() { member_compare_impl(); } void member_compare_QChar_QString_data() { member_compare_data(false); } void member_compare_QChar_QString() { member_compare_impl(); } void member_compare_QChar_QStringView_data() { member_compare_data(false); } @@ -282,33 +246,10 @@ private Q_SLOTS: // void member_compare_char16_t_XXX() - not possible - void member_compare_QStringRef_QChar_data() { member_compare_data(false); } - void member_compare_QStringRef_QChar() { member_compare_impl(); } - void member_compare_QStringRef_char16_t_data() { member_compare_data(false); } - void member_compare_QStringRef_char16_t() { member_compare_impl(); } - void member_compare_QStringRef_QStringRef_data() { member_compare_data(); } - void member_compare_QStringRef_QStringRef() { member_compare_impl(); } - void member_compare_QStringRef_QString_data() { member_compare_data(); } - void member_compare_QStringRef_QString() { member_compare_impl(); } -#ifdef NOT_YET_IMPLEMENTED - void member_compare_QStringRef_QStringView_data() { member_compare_data(); } - void member_compare_QStringRef_QStringView() { member_compare_impl(); } -#endif - void member_compare_QStringRef_QLatin1String_data() { member_compare_data(); } - void member_compare_QStringRef_QLatin1String() { member_compare_impl(); } - void member_compare_QStringRef_QByteArray_data() { member_compare_data(); } - void member_compare_QStringRef_QByteArray() { member_compare_impl(); } -#ifdef NOT_YET_IMPLEMENTED - void member_compare_QStringRef_const_char_star_data() { member_compare_data(); } - void member_compare_QStringRef_const_char_star() { member_compare_impl(); } -#endif - void member_compare_QString_QChar_data() { member_compare_data(false); } void member_compare_QString_QChar() { member_compare_impl(); } void member_compare_QString_char16_t_data() { member_compare_data(false); } void member_compare_QString_char16_t() { member_compare_impl(); } - void member_compare_QString_QStringRef_data() { member_compare_data(); } - void member_compare_QString_QStringRef() { member_compare_impl(); } void member_compare_QString_QString_data() { member_compare_data(); } void member_compare_QString_QString() { member_compare_impl(); } void member_compare_QString_QStringView_data() { member_compare_data(); } @@ -324,8 +265,6 @@ private Q_SLOTS: void member_compare_QStringView_QChar() { member_compare_impl(); } void member_compare_QStringView_char16_t_data() { member_compare_data(false); } void member_compare_QStringView_char16_t() { member_compare_impl(); } - void member_compare_QStringView_QStringRef_data() { member_compare_data(); } - void member_compare_QStringView_QStringRef() { member_compare_impl(); } void member_compare_QStringView_QString_data() { member_compare_data(); } void member_compare_QStringView_QString() { member_compare_impl(); } void member_compare_QStringView_QStringView_data() { member_compare_data(); } @@ -343,8 +282,6 @@ private Q_SLOTS: void member_compare_QLatin1String_QChar() { member_compare_impl(); } void member_compare_QLatin1String_char16_t_data() { member_compare_data(false); } void member_compare_QLatin1String_char16_t() { member_compare_impl(); } - void member_compare_QLatin1String_QStringRef_data() { member_compare_data(); } - void member_compare_QLatin1String_QStringRef() { member_compare_impl(); } void member_compare_QLatin1String_QString_data() { member_compare_data(); } void member_compare_QLatin1String_QString() { member_compare_impl(); } void member_compare_QLatin1String_QStringView_data() { member_compare_data(); } @@ -361,8 +298,6 @@ private Q_SLOTS: void member_compare_QByteArray_QChar() { member_compare_impl(); } void member_compare_QByteArray_char16_t_data() { member_compare_data(false); } void member_compare_QByteArray_char16_t() { member_compare_impl(); } - void member_compare_QByteArray_QStringRef_data() { member_compare_data(); } - void member_compare_QByteArray_QStringRef() { member_compare_impl(); } void member_compare_QByteArray_QString_data() { member_compare_data(); } void member_compare_QByteArray_QString() { member_compare_impl(); } void member_compare_QByteArray_QLatin1String_data() { member_compare_data(); } @@ -381,11 +316,9 @@ private: template void endsWith_impl() const; private Q_SLOTS: - // test all combinations of {QString, QStringRef, QStringView, QLatin1String} x {QString, QStringRef, QStringView, QLatin1String, QChar, char16_t}: + // test all combinations of {QString, QStringView, QLatin1String} x {QString, QStringView, QLatin1String, QChar, char16_t}: void startsWith_QString_QString_data() { startsWith_data(); } void startsWith_QString_QString() { startsWith_impl(); } - void startsWith_QString_QStringRef_data() { startsWith_data(); } - void startsWith_QString_QStringRef() { startsWith_impl(); } void startsWith_QString_QStringView_data() { startsWith_data(); } void startsWith_QString_QStringView() { startsWith_impl(); } void startsWith_QString_QLatin1String_data() { startsWith_data(); } @@ -395,23 +328,8 @@ private Q_SLOTS: void startsWith_QString_char16_t_data() { startsWith_data(false); } void startsWith_QString_char16_t() { startsWith_impl(); } - void startsWith_QStringRef_QString_data() { startsWith_data(); } - void startsWith_QStringRef_QString() { startsWith_impl(); } - void startsWith_QStringRef_QStringRef_data() { startsWith_data(); } - void startsWith_QStringRef_QStringRef() { startsWith_impl(); } - void startsWith_QStringRef_QStringView_data() { startsWith_data(); } - void startsWith_QStringRef_QStringView() { startsWith_impl(); } - void startsWith_QStringRef_QLatin1String_data() { startsWith_data(); } - void startsWith_QStringRef_QLatin1String() { startsWith_impl(); } - void startsWith_QStringRef_QChar_data() { startsWith_data(false); } - void startsWith_QStringRef_QChar() { startsWith_impl(); } - void startsWith_QStringRef_char16_t_data() { startsWith_data(false); } - void startsWith_QStringRef_char16_t() { startsWith_impl(); } - void startsWith_QStringView_QString_data() { startsWith_data(); } void startsWith_QStringView_QString() { startsWith_impl(); } - void startsWith_QStringView_QStringRef_data() { startsWith_data(); } - void startsWith_QStringView_QStringRef() { startsWith_impl(); } void startsWith_QStringView_QStringView_data() { startsWith_data(); } void startsWith_QStringView_QStringView() { startsWith_impl(); } void startsWith_QStringView_QLatin1String_data() { startsWith_data(); } @@ -423,8 +341,6 @@ private Q_SLOTS: void startsWith_QLatin1String_QString_data() { startsWith_data(); } void startsWith_QLatin1String_QString() { startsWith_impl(); } - void startsWith_QLatin1String_QStringRef_data() { startsWith_data(); } - void startsWith_QLatin1String_QStringRef() { startsWith_impl(); } void startsWith_QLatin1String_QStringView_data() { startsWith_data(); } void startsWith_QLatin1String_QStringView() { startsWith_impl(); } void startsWith_QLatin1String_QLatin1String_data() { startsWith_data(); } @@ -436,8 +352,6 @@ private Q_SLOTS: void endsWith_QString_QString_data() { endsWith_data(); } void endsWith_QString_QString() { endsWith_impl(); } - void endsWith_QString_QStringRef_data() { endsWith_data(); } - void endsWith_QString_QStringRef() { endsWith_impl(); } void endsWith_QString_QStringView_data() { endsWith_data(); } void endsWith_QString_QStringView() { endsWith_impl(); } void endsWith_QString_QLatin1String_data() { endsWith_data(); } @@ -447,23 +361,8 @@ private Q_SLOTS: void endsWith_QString_char16_t_data() { endsWith_data(false); } void endsWith_QString_char16_t() { endsWith_impl(); } - void endsWith_QStringRef_QString_data() { endsWith_data(); } - void endsWith_QStringRef_QString() { endsWith_impl(); } - void endsWith_QStringRef_QStringRef_data() { endsWith_data(); } - void endsWith_QStringRef_QStringRef() { endsWith_impl(); } - void endsWith_QStringRef_QStringView_data() { endsWith_data(); } - void endsWith_QStringRef_QStringView() { endsWith_impl(); } - void endsWith_QStringRef_QLatin1String_data() { endsWith_data(); } - void endsWith_QStringRef_QLatin1String() { endsWith_impl(); } - void endsWith_QStringRef_QChar_data() { endsWith_data(false); } - void endsWith_QStringRef_QChar() { endsWith_impl(); } - void endsWith_QStringRef_char16_t_data() { endsWith_data(false); } - void endsWith_QStringRef_char16_t() { endsWith_impl(); } - void endsWith_QStringView_QString_data() { endsWith_data(); } void endsWith_QStringView_QString() { endsWith_impl(); } - void endsWith_QStringView_QStringRef_data() { endsWith_data(); } - void endsWith_QStringView_QStringRef() { endsWith_impl(); } void endsWith_QStringView_QStringView_data() { endsWith_data(); } void endsWith_QStringView_QStringView() { endsWith_impl(); } void endsWith_QStringView_QLatin1String_data() { endsWith_data(); } @@ -475,8 +374,6 @@ private Q_SLOTS: void endsWith_QLatin1String_QString_data() { endsWith_data(); } void endsWith_QLatin1String_QString() { endsWith_impl(); } - void endsWith_QLatin1String_QStringRef_data() { endsWith_data(); } - void endsWith_QLatin1String_QStringRef() { endsWith_impl(); } void endsWith_QLatin1String_QStringView_data() { endsWith_data(); } void endsWith_QLatin1String_QStringView() { endsWith_impl(); } void endsWith_QLatin1String_QLatin1String_data() { endsWith_data(); } @@ -491,7 +388,7 @@ private: template void split_impl() const; private Q_SLOTS: - // test all combinations of {QString, QStringRef} x {QString, QLatin1String, QChar, char16_t}: + // test all combinations of {QString} x {QString, QLatin1String, QChar, char16_t}: void split_QString_QString_data() { split_data(); } void split_QString_QString() { split_impl(); } void split_QString_QLatin1String_data() { split_data(); } @@ -501,27 +398,16 @@ private Q_SLOTS: void split_QString_char16_t_data() { split_data(false); } void split_QString_char16_t() { split_impl(); } - void split_QStringRef_QString_data() { split_data(); } - void split_QStringRef_QString() { split_impl(); } - void split_QStringRef_QLatin1String_data() { split_data(); } - void split_QStringRef_QLatin1String() { split_impl(); } - void split_QStringRef_QChar_data() { split_data(false); } - void split_QStringRef_QChar() { split_impl(); } - void split_QStringRef_char16_t_data() { split_data(false); } - void split_QStringRef_char16_t() { split_impl(); } - private: void tok_data(bool rhsHasVariableLength = true); template void tok_impl() const; private Q_SLOTS: - // let Splittable = {QString, QStringRef, QStringView, QLatin1String, const char16_t*, std::u16string} + // let Splittable = {QString, QStringView, QLatin1String, const char16_t*, std::u16string} // let Separators = Splittable ∪ {QChar, char16_t} // test Splittable × Separators: void tok_QString_QString_data() { tok_data(); } void tok_QString_QString() { tok_impl(); } - void tok_QString_QStringRef_data() { tok_data(); } - void tok_QString_QStringRef() { tok_impl(); } void tok_QString_QStringView_data() { tok_data(); } void tok_QString_QStringView() { tok_impl(); } void tok_QString_QLatin1String_data() { tok_data(); } @@ -535,27 +421,8 @@ private Q_SLOTS: void tok_QString_char16_t_data() { tok_data(false); } void tok_QString_char16_t() { tok_impl(); } - void tok_QStringRef_QString_data() { tok_data(); } - void tok_QStringRef_QString() { tok_impl(); } - void tok_QStringRef_QStringRef_data() { tok_data(); } - void tok_QStringRef_QStringRef() { tok_impl(); } - void tok_QStringRef_QStringView_data() { tok_data(); } - void tok_QStringRef_QStringView() { tok_impl(); } - void tok_QStringRef_QLatin1String_data() { tok_data(); } - void tok_QStringRef_QLatin1String() { tok_impl(); } - void tok_QStringRef_const_char16_t_star_data() { tok_data(); } - void tok_QStringRef_const_char16_t_star() { tok_impl(); } - void tok_QStringRef_stdu16string_data() { tok_data(); } - void tok_QStringRef_stdu16string() { tok_impl(); } - void tok_QStringRef_QChar_data() { tok_data(false); } - void tok_QStringRef_QChar() { tok_impl(); } - void tok_QStringRef_char16_t_data() { tok_data(false); } - void tok_QStringRef_char16_t() { tok_impl(); } - void tok_QStringView_QString_data() { tok_data(); } void tok_QStringView_QString() { tok_impl(); } - void tok_QStringView_QStringRef_data() { tok_data(); } - void tok_QStringView_QStringRef() { tok_impl(); } void tok_QStringView_QStringView_data() { tok_data(); } void tok_QStringView_QStringView() { tok_impl(); } void tok_QStringView_QLatin1String_data() { tok_data(); } @@ -571,8 +438,6 @@ private Q_SLOTS: void tok_QLatin1String_QString_data() { tok_data(); } void tok_QLatin1String_QString() { tok_impl(); } - void tok_QLatin1String_QStringRef_data() { tok_data(); } - void tok_QLatin1String_QStringRef() { tok_impl(); } void tok_QLatin1String_QStringView_data() { tok_data(); } void tok_QLatin1String_QStringView() { tok_impl(); } void tok_QLatin1String_QLatin1String_data() { tok_data(); } @@ -588,8 +453,6 @@ private Q_SLOTS: void tok_const_char16_t_star_QString_data() { tok_data(); } void tok_const_char16_t_star_QString() { tok_impl(); } - void tok_const_char16_t_star_QStringRef_data() { tok_data(); } - void tok_const_char16_t_star_QStringRef() { tok_impl(); } void tok_const_char16_t_star_QStringView_data() { tok_data(); } void tok_const_char16_t_star_QStringView() { tok_impl(); } void tok_const_char16_t_star_QLatin1String_data() { tok_data(); } @@ -605,8 +468,6 @@ private Q_SLOTS: void tok_stdu16string_QString_data() { tok_data(); } void tok_stdu16string_QString() { tok_impl(); } - void tok_stdu16string_QStringRef_data() { tok_data(); } - void tok_stdu16string_QStringRef() { tok_impl(); } void tok_stdu16string_QStringView_data() { tok_data(); } void tok_stdu16string_QStringView() { tok_impl(); } void tok_stdu16string_QLatin1String_data() { tok_data(); } @@ -646,8 +507,6 @@ private Q_SLOTS: void mid_QString_data() { mid_data(); } void mid_QString() { mid_impl(); } - void mid_QStringRef_data() { mid_data(); } - void mid_QStringRef() { mid_impl(); } void mid_QStringView_data() { mid_data(); } void mid_QStringView() { mid_impl(); } void mid_QLatin1String_data() { mid_data(); } @@ -657,8 +516,6 @@ private Q_SLOTS: void left_QString_data() { left_data(); } void left_QString() { left_impl(); } - void left_QStringRef_data() { left_data(); } - void left_QStringRef() { left_impl(); } void left_QStringView_data() { left_data(); } void left_QStringView() { left_impl(); } void left_QLatin1String_data() { left_data(); } @@ -668,8 +525,6 @@ private Q_SLOTS: void right_QString_data() { right_data(); } void right_QString() { right_impl(); } - void right_QStringRef_data() { right_data(); } - void right_QStringRef() { right_impl(); } void right_QStringView_data() { right_data(); } void right_QStringView() { right_impl(); } void right_QLatin1String_data() { right_data(); } @@ -700,8 +555,6 @@ private Q_SLOTS: void chop_QString_data() { chop_data(); } void chop_QString() { chop_impl(); } - void chop_QStringRef_data() { chop_data(); } - void chop_QStringRef() { chop_impl(); } void chop_QStringView_data() { chop_data(); } void chop_QStringView() { chop_impl(); } void chop_QLatin1String_data() { chop_data(); } @@ -716,14 +569,12 @@ private: private Q_SLOTS: void trim_trimmed_QString_data() { trimmed_data(); } void trim_trimmed_QString() { trimmed_impl(); } - void trim_trimmed_QStringRef_data() { trimmed_data(); } - void trim_trimmed_QStringRef() { trimmed_impl(); } void trim_trimmed_QStringView_data() { trimmed_data(); } void trim_trimmed_QStringView() { trimmed_impl(); } void trim_trimmed_QLatin1String_data() { trimmed_data(); } void trim_trimmed_QLatin1String() { trimmed_impl(); } void trim_trimmed_QByteArray_data() { trimmed_data(); } - void trim_trimmed_QByteArray() { trimmed_impl(); } + void trim_trimmed_QByteArray() { /*trimmed_impl();*/ } // TODO private: void toNumber_data(); @@ -732,8 +583,6 @@ private: private Q_SLOTS: void toNumber_QString_data() { toNumber_data(); } void toNumber_QString() { toNumber_impl(); } - void toNumber_QStringRef_data() { toNumber_data(); } - void toNumber_QStringRef() { toNumber_impl(); } void toNumber_QStringView_data() { toNumber_data(); } void toNumber_QStringView() { toNumber_impl(); } void toNumber_QByteArray_data() { toNumber_data(); } @@ -746,8 +595,6 @@ private: private Q_SLOTS: void count_QString_data() { count_data(); } void count_QString() { count_impl(); } - void count_QStringRef_data() { count_data(); } - void count_QStringRef() { count_impl(); } void count_QStringView_data() { count_data(); } void count_QStringView() { count_impl(); } void count_QByteArray_data() { count_data(); } @@ -774,29 +621,21 @@ private Q_SLOTS: void toLocal8Bit_QString_data() { toLocal8Bit_data(); } void toLocal8Bit_QString() { toLocal8Bit_impl(); } - void toLocal8Bit_QStringRef_data() { toLocal8Bit_data(); } - void toLocal8Bit_QStringRef() { toLocal8Bit_impl(); } void toLocal8Bit_QStringView_data() { toLocal8Bit_data(); } void toLocal8Bit_QStringView() { toLocal8Bit_impl(); } void toLatin1_QString_data() { toLatin1_data(); } void toLatin1_QString() { toLatin1_impl(); } - void toLatin1_QStringRef_data() { toLatin1_data(); } - void toLatin1_QStringRef() { toLatin1_impl(); } void toLatin1_QStringView_data() { toLatin1_data(); } void toLatin1_QStringView() { toLatin1_impl(); } void toUtf8_QString_data() { toUtf8_data(); } void toUtf8_QString() { toUtf8_impl(); } - void toUtf8_QStringRef_data() { toUtf8_data(); } - void toUtf8_QStringRef() { toUtf8_impl(); } void toUtf8_QStringView_data() { toUtf8_data(); } void toUtf8_QStringView() { toUtf8_impl(); } void toUcs4_QString_data() { toUcs4_data(); } void toUcs4_QString() { toUcs4_impl(); } - void toUcs4_QStringRef_data() { toUcs4_data(); } - void toUcs4_QStringRef() { toUcs4_impl(); } void toUcs4_QStringView_data() { toUcs4_data(); } void toUcs4_QStringView() { toUcs4_impl(); } @@ -805,13 +644,11 @@ private: void indexOf_data(bool rhsHasVariableLength = true); private Q_SLOTS: - // test all combinations of {QString, QLatin1String, QStringRef, QStringView} x {QString, QLatin1String, QStringRef, QStringView, QChar, char16_t}: + // test all combinations of {QString, QLatin1String, QStringView} x {QString, QLatin1String, QStringView, QChar, char16_t}: void indexOf_QString_QString_data() { indexOf_data(); } void indexOf_QString_QString() { indexOf_impl(); } void indexOf_QString_QLatin1String_data() { indexOf_data(); } void indexOf_QString_QLatin1String() { indexOf_impl(); } - void indexOf_QString_QStringRef_data() { indexOf_data(); } - void indexOf_QString_QStringRef() { indexOf_impl(); } void indexOf_QString_QStringView_data() { indexOf_data(); } void indexOf_QString_QStringView() { indexOf_impl(); } void indexOf_QString_QChar_data() { indexOf_data(false); } @@ -823,8 +660,6 @@ private Q_SLOTS: void indexOf_QLatin1String_QString() { indexOf_impl(); } void indexOf_QLatin1String_QLatin1String_data() { indexOf_data(); } void indexOf_QLatin1String_QLatin1String() { indexOf_impl(); } - void indexOf_QLatin1String_QStringRef_data() { indexOf_data(); } - void indexOf_QLatin1String_QStringRef() { indexOf_impl(); } void indexOf_QLatin1String_QStringView_data() { indexOf_data(); } void indexOf_QLatin1String_QStringView() { indexOf_impl(); } void indexOf_QLatin1String_QChar_data() { indexOf_data(false); } @@ -832,25 +667,10 @@ private Q_SLOTS: void indexOf_QLatin1String_char16_t_data() { indexOf_data(false); } void indexOf_QLatin1String_char16_t() { indexOf_impl(); } - void indexOf_QStringRef_QString_data() { indexOf_data(); } - void indexOf_QStringRef_QString() { indexOf_impl(); } - void indexOf_QStringRef_QLatin1String_data() { indexOf_data(); } - void indexOf_QStringRef_QLatin1String() { indexOf_impl(); } - void indexOf_QStringRef_QStringRef_data() { indexOf_data(); } - void indexOf_QStringRef_QStringRef() { indexOf_impl(); } - void indexOf_QStringRef_QStringView_data() { indexOf_data(); } - void indexOf_QStringRef_QStringView() { indexOf_impl(); } - void indexOf_QStringRef_QChar_data() { indexOf_data(false); } - void indexOf_QStringRef_QChar() { indexOf_impl(); } - void indexOf_QStringRef_char16_t_data() { indexOf_data(false); } - void indexOf_QStringRef_char16_t() { indexOf_impl(); } - void indexOf_QStringView_QString_data() { indexOf_data(); } void indexOf_QStringView_QString() { indexOf_impl(); } void indexOf_QStringView_QLatin1String_data() { indexOf_data(); } void indexOf_QStringView_QLatin1String() { indexOf_impl(); } - void indexOf_QStringView_QStringRef_data() { indexOf_data(); } - void indexOf_QStringView_QStringRef() { indexOf_impl(); } void indexOf_QStringView_QStringView_data() { indexOf_data(); } void indexOf_QStringView_QStringView() { indexOf_impl(); } void indexOf_QStringView_QChar_data() { indexOf_data(false); } @@ -863,13 +683,11 @@ private: void contains_data(bool rhsHasVariableLength = true); private Q_SLOTS: - // test all combinations of {QString, QLatin1String, QStringRef, QStringView} x {QString, QLatin1String, QStringRef, QStringView, QChar, char16_t}: + // test all combinations of {QString, QLatin1String, QStringView} x {QString, QLatin1String, QStringView, QChar, char16_t}: void contains_QString_QString_data() { contains_data(); } void contains_QString_QString() { contains_impl(); } void contains_QString_QLatin1String_data() { contains_data(); } void contains_QString_QLatin1String() { contains_impl(); } - void contains_QString_QStringRef_data() { contains_data(); } - void contains_QString_QStringRef() { contains_impl(); } void contains_QString_QStringView_data() { contains_data(); } void contains_QString_QStringView() { contains_impl(); } void contains_QString_QChar_data() { contains_data(false); } @@ -881,8 +699,6 @@ private Q_SLOTS: void contains_QLatin1String_QString() { contains_impl(); } void contains_QLatin1String_QLatin1String_data() { contains_data(); } void contains_QLatin1String_QLatin1String() { contains_impl(); } - void contains_QLatin1String_QStringRef_data() { contains_data(); } - void contains_QLatin1String_QStringRef() { contains_impl(); } void contains_QLatin1String_QStringView_data() { contains_data(); } void contains_QLatin1String_QStringView() { contains_impl(); } void contains_QLatin1String_QChar_data() { contains_data(false); } @@ -890,25 +706,10 @@ private Q_SLOTS: void contains_QLatin1String_char16_t_data() { contains_data(false); } void contains_QLatin1String_char16_t() { contains_impl(); } - void contains_QStringRef_QString_data() { contains_data(); } - void contains_QStringRef_QString() { contains_impl(); } - void contains_QStringRef_QLatin1String_data() { contains_data(); } - void contains_QStringRef_QLatin1String() { contains_impl(); } - void contains_QStringRef_QStringRef_data() { contains_data(); } - void contains_QStringRef_QStringRef() { contains_impl(); } - void contains_QStringRef_QStringView_data() { contains_data(); } - void contains_QStringRef_QStringView() { contains_impl(); } - void contains_QStringRef_QChar_data() { contains_data(false); } - void contains_QStringRef_QChar() { contains_impl(); } - void contains_QStringRef_char16_t_data() { contains_data(false); } - void contains_QStringRef_char16_t() { contains_impl(); } - void contains_QStringView_QString_data() { contains_data(); } void contains_QStringView_QString() { contains_impl(); } void contains_QStringView_QLatin1String_data() { contains_data(); } void contains_QStringView_QLatin1String() { contains_impl(); } - void contains_QStringView_QStringRef_data() { contains_data(); } - void contains_QStringView_QStringRef() { contains_impl(); } void contains_QStringView_QStringView_data() { contains_data(); } void contains_QStringView_QStringView() { contains_impl(); } void contains_QStringView_QChar_data() { contains_data(false); } @@ -921,13 +722,11 @@ private: void lastIndexOf_data(bool rhsHasVariableLength = true); private Q_SLOTS: - // test all combinations of {QString, QLatin1String, QStringRef, QStringView} x {QString, QLatin1String, QStringRef, QStringView, QChar, char16_t}: + // test all combinations of {QString, QLatin1String, QStringView} x {QString, QLatin1String, QStringView, QChar, char16_t}: void lastIndexOf_QString_QString_data() { lastIndexOf_data(); } void lastIndexOf_QString_QString() { lastIndexOf_impl(); } void lastIndexOf_QString_QLatin1String_data() { lastIndexOf_data(); } void lastIndexOf_QString_QLatin1String() { lastIndexOf_impl(); } - void lastIndexOf_QString_QStringRef_data() { lastIndexOf_data(); } - void lastIndexOf_QString_QStringRef() { lastIndexOf_impl(); } void lastIndexOf_QString_QStringView_data() { lastIndexOf_data(); } void lastIndexOf_QString_QStringView() { lastIndexOf_impl(); } void lastIndexOf_QString_QChar_data() { lastIndexOf_data(false); } @@ -939,8 +738,6 @@ private Q_SLOTS: void lastIndexOf_QLatin1String_QString() { lastIndexOf_impl(); } void lastIndexOf_QLatin1String_QLatin1String_data() { lastIndexOf_data(); } void lastIndexOf_QLatin1String_QLatin1String() { lastIndexOf_impl(); } - void lastIndexOf_QLatin1String_QStringRef_data() { lastIndexOf_data(); } - void lastIndexOf_QLatin1String_QStringRef() { lastIndexOf_impl(); } void lastIndexOf_QLatin1String_QStringView_data() { lastIndexOf_data(); } void lastIndexOf_QLatin1String_QStringView() { lastIndexOf_impl(); } void lastIndexOf_QLatin1String_QChar_data() { lastIndexOf_data(false); } @@ -948,25 +745,10 @@ private Q_SLOTS: void lastIndexOf_QLatin1String_char16_t_data() { lastIndexOf_data(false); } void lastIndexOf_QLatin1String_char16_t() { lastIndexOf_impl(); } - void lastIndexOf_QStringRef_QString_data() { lastIndexOf_data(); } - void lastIndexOf_QStringRef_QString() { lastIndexOf_impl(); } - void lastIndexOf_QStringRef_QLatin1String_data() { lastIndexOf_data(); } - void lastIndexOf_QStringRef_QLatin1String() { lastIndexOf_impl(); } - void lastIndexOf_QStringRef_QStringRef_data() { lastIndexOf_data(); } - void lastIndexOf_QStringRef_QStringRef() { lastIndexOf_impl(); } - void lastIndexOf_QStringRef_QStringView_data() { lastIndexOf_data(); } - void lastIndexOf_QStringRef_QStringView() { lastIndexOf_impl(); } - void lastIndexOf_QStringRef_QChar_data() { lastIndexOf_data(false); } - void lastIndexOf_QStringRef_QChar() { lastIndexOf_impl(); } - void lastIndexOf_QStringRef_char16_t_data() { lastIndexOf_data(false); } - void lastIndexOf_QStringRef_char16_t() { lastIndexOf_impl(); } - void lastIndexOf_QStringView_QString_data() { lastIndexOf_data(); } void lastIndexOf_QStringView_QString() { lastIndexOf_impl(); } void lastIndexOf_QStringView_QLatin1String_data() { lastIndexOf_data(); } void lastIndexOf_QStringView_QLatin1String() { lastIndexOf_impl(); } - void lastIndexOf_QStringView_QStringRef_data() { lastIndexOf_data(); } - void lastIndexOf_QStringView_QStringRef() { lastIndexOf_impl(); } void lastIndexOf_QStringView_QStringView_data() { lastIndexOf_data(); } void lastIndexOf_QStringView_QStringView() { lastIndexOf_impl(); } void lastIndexOf_QStringView_QChar_data() { lastIndexOf_data(false); } @@ -977,23 +759,23 @@ private Q_SLOTS: void tst_QStringApiSymmetry::compare_data(bool hasConceptOfNullAndEmpty) { - QTest::addColumn("lhsUnicode"); + QTest::addColumn("lhsUnicode"); QTest::addColumn("lhsLatin1"); - QTest::addColumn("rhsUnicode"); + QTest::addColumn("rhsUnicode"); QTest::addColumn("rhsLatin1"); QTest::addColumn("caseSensitiveCompareResult"); QTest::addColumn("caseInsensitiveCompareResult"); if (hasConceptOfNullAndEmpty) { - QTest::newRow("null <> null") << QStringRef() << QLatin1String() - << QStringRef() << QLatin1String() + QTest::newRow("null <> null") << QStringView() << QLatin1String() + << QStringView() << QLatin1String() << 0 << 0; static const QString empty(""); - QTest::newRow("null <> empty") << QStringRef() << QLatin1String() - << QStringRef(&empty) << QLatin1String("") + QTest::newRow("null <> empty") << QStringView() << QLatin1String() + << QStringView(empty) << QLatin1String("") << 0 << 0; - QTest::newRow("empty <> null") << QStringRef(&empty) << QLatin1String("") - << QStringRef() << QLatin1String() + QTest::newRow("empty <> null") << QStringView(empty) << QLatin1String("") + << QStringView() << QLatin1String() << 0 << 0; } @@ -1004,8 +786,8 @@ void tst_QStringApiSymmetry::compare_data(bool hasConceptOfNullAndEmpty) QString(QLatin1String(rhs)), \ }; \ QTest::newRow(qUtf8Printable(QLatin1String("'" lhs "' <> '" rhs "': "))) \ - << QStringRef(&pinned[0]) << QLatin1String(lhs) \ - << QStringRef(&pinned[1]) << QLatin1String(rhs) \ + << QStringView(pinned[0]) << QLatin1String(lhs) \ + << QStringView(pinned[1]) << QLatin1String(rhs) \ << sign(qstrcmp(lhs, rhs)) << caseless; \ } while (false) #define ASCIIROW(lhs, rhs) ROW(lhs, rhs, sign(qstricmp(lhs, rhs))) @@ -1031,17 +813,16 @@ template String detached(String s) return s; } -template Str make(const QStringRef &sf, QLatin1String l1, const QByteArray &u8); -template <> QChar make(const QStringRef &sf, QLatin1String, const QByteArray &) { return sf.isEmpty() ? QChar() : sf.at(0); } -template <> char16_t make(const QStringRef &sf, QLatin1String, const QByteArray &) { return sf.isEmpty() ? char16_t() : char16_t{sf.at(0).unicode()}; } -template <> QStringRef make(const QStringRef &sf, QLatin1String, const QByteArray &) { return sf; } -template <> QString make(const QStringRef &sf, QLatin1String, const QByteArray &) { return sf.toString(); } -template <> QStringView make(const QStringRef &sf, QLatin1String, const QByteArray &) { return sf; } -template <> QLatin1String make(const QStringRef &, QLatin1String l1, const QByteArray &) { return l1; } -template <> QByteArray make(const QStringRef &, QLatin1String, const QByteArray &u8) { return u8; } -template <> const char * make(const QStringRef &, QLatin1String, const QByteArray &u8) { return u8.data(); } -template <> const char16_t* make(const QStringRef &sf, QLatin1String, const QByteArray &) { return QStringView{sf}.utf16(); } // assumes `sf` doesn't represent a substring -template <> std::u16string make(const QStringRef &sf, QLatin1String, const QByteArray &) { return sf.toString().toStdU16String(); } +template Str make(QStringView sf, QLatin1String l1, const QByteArray &u8); +template <> QChar make(QStringView sf, QLatin1String, const QByteArray &) { return sf.isEmpty() ? QChar() : sf.at(0); } +template <> char16_t make(QStringView sf, QLatin1String, const QByteArray &) { return sf.isEmpty() ? char16_t() : char16_t{sf.at(0).unicode()}; } +template <> QString make(QStringView sf, QLatin1String, const QByteArray &) { return sf.toString(); } +template <> QStringView make(QStringView sf, QLatin1String, const QByteArray &) { return sf; } +template <> QLatin1String make(QStringView, QLatin1String l1, const QByteArray &) { return l1; } +template <> QByteArray make(QStringView, QLatin1String, const QByteArray &u8) { return u8; } +template <> const char * make(QStringView, QLatin1String, const QByteArray &u8) { return u8.data(); } +template <> const char16_t* make(QStringView sf, QLatin1String, const QByteArray &) { return sf.utf16(); } // assumes `sf` doesn't represent a substring +template <> std::u16string make(QStringView sf, QLatin1String, const QByteArray &) { return sf.toString().toStdU16String(); } template struct is_utf8_encoded : std::false_type {}; template <> struct is_utf8_encoded : std::true_type {}; @@ -1064,9 +845,9 @@ struct has_qCompareStrings { template void tst_QStringApiSymmetry::compare_impl() const { - QFETCH(QStringRef, lhsUnicode); + QFETCH(QStringView, lhsUnicode); QFETCH(QLatin1String, lhsLatin1); - QFETCH(QStringRef, rhsUnicode); + QFETCH(QStringView, rhsUnicode); QFETCH(QLatin1String, rhsLatin1); QFETCH(int, caseSensitiveCompareResult); QFETCH(const int, caseInsensitiveCompareResult); @@ -1098,9 +879,9 @@ void tst_QStringApiSymmetry::compare_impl() const template void tst_QStringApiSymmetry::member_compare_impl() const { - QFETCH(QStringRef, lhsUnicode); + QFETCH(QStringView, lhsUnicode); QFETCH(QLatin1String, lhsLatin1); - QFETCH(QStringRef, rhsUnicode); + QFETCH(QStringView, rhsUnicode); QFETCH(QLatin1String, rhsLatin1); QFETCH(const int, caseSensitiveCompareResult); QFETCH(const int, caseInsensitiveCompareResult); @@ -1160,35 +941,35 @@ static QString ABC = QStringLiteral("ABC"); void tst_QStringApiSymmetry::startsWith_data(bool rhsHasVariableLength) { - QTest::addColumn("haystackU16"); + QTest::addColumn("haystackU16"); QTest::addColumn("haystackL1"); - QTest::addColumn("needleU16"); + QTest::addColumn("needleU16"); QTest::addColumn("needleL1"); QTest::addColumn("resultCS"); QTest::addColumn("resultCIS"); if (rhsHasVariableLength) { - QTest::addRow("null ~= ^null") << QStringRef() << QLatin1String() - << QStringRef() << QLatin1String() << true << true; - QTest::addRow("empty ~= ^null") << QStringRef(&empty) << QLatin1String("") - << QStringRef() << QLatin1String() << true << true; - QTest::addRow("a ~= ^null") << QStringRef(&a) << QLatin1String("a") - << QStringRef() << QLatin1String() << true << true; - QTest::addRow("null ~= ^empty") << QStringRef() << QLatin1String() - << QStringRef(&empty) << QLatin1String("") << false << false; - QTest::addRow("a ~= ^empty") << QStringRef(&a) << QLatin1String("a") - << QStringRef(&empty) << QLatin1String("") << true << true; - QTest::addRow("empty ~= ^empty") << QStringRef(&empty) << QLatin1String("") - << QStringRef(&empty) << QLatin1String("") << true << true; + QTest::addRow("null ~= ^null") << QStringView() << QLatin1String() + << QStringView() << QLatin1String() << true << true; + QTest::addRow("empty ~= ^null") << QStringView(empty) << QLatin1String("") + << QStringView() << QLatin1String() << true << true; + QTest::addRow("a ~= ^null") << QStringView(a) << QLatin1String("a") + << QStringView() << QLatin1String() << true << true; + QTest::addRow("null ~= ^empty") << QStringView() << QLatin1String() + << QStringView(empty) << QLatin1String("") << false << false; + QTest::addRow("a ~= ^empty") << QStringView(a) << QLatin1String("a") + << QStringView(empty) << QLatin1String("") << true << true; + QTest::addRow("empty ~= ^empty") << QStringView(empty) << QLatin1String("") + << QStringView(empty) << QLatin1String("") << true << true; } - QTest::addRow("null ~= ^a") << QStringRef() << QLatin1String() - << QStringRef(&a) << QLatin1String("a") << false << false; - QTest::addRow("empty ~= ^a") << QStringRef(&empty) << QLatin1String("") - << QStringRef(&a) << QLatin1String("a") << false << false; + QTest::addRow("null ~= ^a") << QStringView() << QLatin1String() + << QStringView(a) << QLatin1String("a") << false << false; + QTest::addRow("empty ~= ^a") << QStringView(empty) << QLatin1String("") + << QStringView(a) << QLatin1String("a") << false << false; #define ROW(h, n, cs, cis) \ - QTest::addRow("%s ~= ^%s", #h, #n) << QStringRef(&h) << QLatin1String(#h) \ - << QStringRef(&n) << QLatin1String(#n) \ + QTest::addRow("%s ~= ^%s", #h, #n) << QStringView(h) << QLatin1String(#h) \ + << QStringView(n) << QLatin1String(#n) \ << bool(cs) << bool(cis) ROW(a, a, 1, 1); ROW(a, A, 0, 1); @@ -1227,9 +1008,9 @@ void tst_QStringApiSymmetry::startsWith_data(bool rhsHasVariableLength) template void tst_QStringApiSymmetry::startsWith_impl() const { - QFETCH(const QStringRef, haystackU16); + QFETCH(const QStringView, haystackU16); QFETCH(const QLatin1String, haystackL1); - QFETCH(const QStringRef, needleU16); + QFETCH(const QStringView, needleU16); QFETCH(const QLatin1String, needleL1); QFETCH(const bool, resultCS); QFETCH(const bool, resultCIS); @@ -1247,35 +1028,35 @@ void tst_QStringApiSymmetry::startsWith_impl() const void tst_QStringApiSymmetry::endsWith_data(bool rhsHasVariableLength) { - QTest::addColumn("haystackU16"); + QTest::addColumn("haystackU16"); QTest::addColumn("haystackL1"); - QTest::addColumn("needleU16"); + QTest::addColumn("needleU16"); QTest::addColumn("needleL1"); QTest::addColumn("resultCS"); QTest::addColumn("resultCIS"); if (rhsHasVariableLength) { - QTest::addRow("null ~= null$") << QStringRef() << QLatin1String() - << QStringRef() << QLatin1String() << true << true; - QTest::addRow("empty ~= null$") << QStringRef(&empty) << QLatin1String("") - << QStringRef() << QLatin1String() << true << true; - QTest::addRow("a ~= null$") << QStringRef(&a) << QLatin1String("a") - << QStringRef() << QLatin1String() << true << true; - QTest::addRow("null ~= empty$") << QStringRef() << QLatin1String() - << QStringRef(&empty) << QLatin1String("") << false << false; - QTest::addRow("a ~= empty$") << QStringRef(&a) << QLatin1String("a") - << QStringRef(&empty) << QLatin1String("") << true << true; - QTest::addRow("empty ~= empty$") << QStringRef(&empty) << QLatin1String("") - << QStringRef(&empty) << QLatin1String("") << true << true; + QTest::addRow("null ~= null$") << QStringView() << QLatin1String() + << QStringView() << QLatin1String() << true << true; + QTest::addRow("empty ~= null$") << QStringView(empty) << QLatin1String("") + << QStringView() << QLatin1String() << true << true; + QTest::addRow("a ~= null$") << QStringView(a) << QLatin1String("a") + << QStringView() << QLatin1String() << true << true; + QTest::addRow("null ~= empty$") << QStringView() << QLatin1String() + << QStringView(empty) << QLatin1String("") << false << false; + QTest::addRow("a ~= empty$") << QStringView(a) << QLatin1String("a") + << QStringView(empty) << QLatin1String("") << true << true; + QTest::addRow("empty ~= empty$") << QStringView(empty) << QLatin1String("") + << QStringView(empty) << QLatin1String("") << true << true; } - QTest::addRow("null ~= a$") << QStringRef() << QLatin1String() - << QStringRef(&a) << QLatin1String("a") << false << false; - QTest::addRow("empty ~= a$") << QStringRef(&empty) << QLatin1String("") - << QStringRef(&a) << QLatin1String("a") << false << false; + QTest::addRow("null ~= a$") << QStringView() << QLatin1String() + << QStringView(a) << QLatin1String("a") << false << false; + QTest::addRow("empty ~= a$") << QStringView(empty) << QLatin1String("") + << QStringView(a) << QLatin1String("a") << false << false; #define ROW(h, n, cs, cis) \ - QTest::addRow("%s ~= %s$", #h, #n) << QStringRef(&h) << QLatin1String(#h) \ - << QStringRef(&n) << QLatin1String(#n) \ + QTest::addRow("%s ~= %s$", #h, #n) << QStringView(h) << QLatin1String(#h) \ + << QStringView(n) << QLatin1String(#n) \ << bool(cs) << bool(cis) ROW(a, a, 1, 1); ROW(a, A, 0, 1); @@ -1314,9 +1095,9 @@ void tst_QStringApiSymmetry::endsWith_data(bool rhsHasVariableLength) template void tst_QStringApiSymmetry::endsWith_impl() const { - QFETCH(const QStringRef, haystackU16); + QFETCH(const QStringView, haystackU16); QFETCH(const QLatin1String, haystackL1); - QFETCH(const QStringRef, needleU16); + QFETCH(const QStringView, needleU16); QFETCH(const QLatin1String, needleL1); QFETCH(const bool, resultCS); QFETCH(const bool, resultCIS); @@ -1334,43 +1115,43 @@ void tst_QStringApiSymmetry::endsWith_impl() const void tst_QStringApiSymmetry::split_data(bool rhsHasVariableLength) { - QTest::addColumn("haystackU16"); + QTest::addColumn("haystackU16"); QTest::addColumn("haystackL1"); - QTest::addColumn("needleU16"); + QTest::addColumn("needleU16"); QTest::addColumn("needleL1"); QTest::addColumn("resultCS"); QTest::addColumn("resultCIS"); if (rhsHasVariableLength) { - QTest::addRow("null ~= null$") << QStringRef{} << QLatin1String{} - << QStringRef{} << QLatin1String{} + QTest::addRow("null ~= null$") << QStringView{} << QLatin1String{} + << QStringView{} << QLatin1String{} << QStringList{{}, {}} << QStringList{{}, {}}; - QTest::addRow("empty ~= null$") << QStringRef{&empty} << QLatin1String("") - << QStringRef{} << QLatin1String{} + QTest::addRow("empty ~= null$") << QStringView{empty} << QLatin1String("") + << QStringView{} << QLatin1String{} << QStringList{empty, empty} << QStringList{empty, empty}; - QTest::addRow("a ~= null$") << QStringRef{&a} << QLatin1String{"a"} - << QStringRef{} << QLatin1String{} + QTest::addRow("a ~= null$") << QStringView{a} << QLatin1String{"a"} + << QStringView{} << QLatin1String{} << QStringList{empty, a, empty} << QStringList{empty, a, empty}; - QTest::addRow("null ~= empty$") << QStringRef{} << QLatin1String{} - << QStringRef{&empty} << QLatin1String{""} + QTest::addRow("null ~= empty$") << QStringView{} << QLatin1String{} + << QStringView{empty} << QLatin1String{""} << QStringList{{}, {}} << QStringList{{}, {}}; - QTest::addRow("a ~= empty$") << QStringRef{&a} << QLatin1String{"a"} - << QStringRef{&empty} << QLatin1String{""} + QTest::addRow("a ~= empty$") << QStringView{a} << QLatin1String{"a"} + << QStringView{empty} << QLatin1String{""} << QStringList{empty, a, empty} << QStringList{empty, a, empty}; - QTest::addRow("empty ~= empty$") << QStringRef{&empty} << QLatin1String{""} - << QStringRef{&empty} << QLatin1String{""} + QTest::addRow("empty ~= empty$") << QStringView{empty} << QLatin1String{""} + << QStringView{empty} << QLatin1String{""} << QStringList{empty, empty} << QStringList{empty, empty}; } - QTest::addRow("null ~= a$") << QStringRef{} << QLatin1String{} - << QStringRef{&a} << QLatin1String{"a"} + QTest::addRow("null ~= a$") << QStringView{} << QLatin1String{} + << QStringView{a} << QLatin1String{"a"} << QStringList{{}} << QStringList{{}}; - QTest::addRow("empty ~= a$") << QStringRef{&empty} << QLatin1String{""} - << QStringRef{&a} << QLatin1String{"a"} + QTest::addRow("empty ~= a$") << QStringView{empty} << QLatin1String{""} + << QStringView{a} << QLatin1String{"a"} << QStringList{empty} << QStringList{empty}; #define ROW(h, n, cs, cis) \ - QTest::addRow("%s ~= %s$", #h, #n) << QStringRef(&h) << QLatin1String(#h) \ - << QStringRef(&n) << QLatin1String(#n) \ + QTest::addRow("%s ~= %s$", #h, #n) << QStringView(h) << QLatin1String(#h) \ + << QStringView(n) << QLatin1String(#n) \ << QStringList cs << QStringList cis ROW(a, a, ({empty, empty}), ({empty, empty})); ROW(a, A, {a}, ({empty, empty})); @@ -1426,9 +1207,9 @@ template <> QByteArray deepCopied(QByteArray s) { return detached(s); } template void tst_QStringApiSymmetry::split_impl() const { - QFETCH(const QStringRef, haystackU16); + QFETCH(const QStringView, haystackU16); QFETCH(const QLatin1String, haystackL1); - QFETCH(const QStringRef, needleU16); + QFETCH(const QStringView, needleU16); QFETCH(const QLatin1String, needleL1); QFETCH(const QStringList, resultCS); QFETCH(const QStringList, resultCIS); @@ -1465,9 +1246,9 @@ constexpr inline bool has_tokenize_method_v = has_tokenize_method void tst_QStringApiSymmetry::tok_impl() const { - QFETCH(const QStringRef, haystackU16); + QFETCH(const QStringView, haystackU16); QFETCH(const QLatin1String, haystackL1); - QFETCH(const QStringRef, needleU16); + QFETCH(const QStringView, needleU16); QFETCH(const QLatin1String, needleL1); QFETCH(const QStringList, resultCS); QFETCH(const QStringList, resultCIS); @@ -1525,13 +1306,21 @@ void tst_QStringApiSymmetry::tok_impl() const } } +QT_BEGIN_NAMESPACE + // keep the mid_, left_, right_, sliced_, first_truncate_, last_, chop_QByteArray() going +bool operator==(const QByteArray &lhs, QStringView rhs) +{ + return rhs.compare(QString::fromLatin1(lhs)) == 0; +} +QT_END_NAMESPACE + void tst_QStringApiSymmetry::mid_data() { sliced_data(); // mid() has a wider contract compared to sliced(), so test those cases here: #define ROW(base, p, n, r1, r2) \ - QTest::addRow("%s %d %d", #base, p, n) << QStringRef(&base) << QLatin1String(#base) << p << n << QStringRef(&r1) << QStringRef(&r2) + QTest::addRow("%s %d %d", #base, p, n) << QStringView(base) << QLatin1String(#base) << p << n << QStringView(r1) << QStringView(r2) ROW(a, -1, 0, a, null); ROW(a, -1, 2, a, a); @@ -1564,12 +1353,12 @@ void tst_QStringApiSymmetry::mid_data() template void tst_QStringApiSymmetry::mid_impl() { - QFETCH(const QStringRef, unicode); + QFETCH(const QStringView, unicode); QFETCH(const QLatin1String, latin1); QFETCH(const int, pos); QFETCH(const int, n); - QFETCH(const QStringRef, result); - QFETCH(const QStringRef, result2); + QFETCH(const QStringView, result); + QFETCH(const QStringView, result2); const auto utf8 = unicode.toUtf8(); @@ -1607,7 +1396,7 @@ void tst_QStringApiSymmetry::left_data() // specific data testing out of bounds cases #define ROW(base, n, res) \ - QTest::addRow("%s%d", #base, n) << QStringRef(&base) << QLatin1String(#base) << n << QStringRef(&res); + QTest::addRow("%s%d", #base, n) << QStringView(base) << QLatin1String(#base) << n << QStringView(res); ROW(a, -1, a); ROW(a, 2, a); @@ -1625,7 +1414,7 @@ void tst_QStringApiSymmetry::left_QByteArray_data() // specific data testing out of bounds cases #define ROW(base, n, res) \ - QTest::addRow("%s%d", #base, n) << QStringRef(&base) << QLatin1String(#base) << n << QStringRef(&res); + QTest::addRow("%s%d", #base, n) << QStringView(base) << QLatin1String(#base) << n << QStringView(res); ROW(a, -1, empty); ROW(a, 2, a); @@ -1638,10 +1427,10 @@ void tst_QStringApiSymmetry::left_QByteArray_data() template void tst_QStringApiSymmetry::left_impl() { - QFETCH(const QStringRef, unicode); + QFETCH(const QStringView, unicode); QFETCH(const QLatin1String, latin1); QFETCH(const int, n); - QFETCH(const QStringRef, result); + QFETCH(const QStringView, result); const auto utf8 = unicode.toUtf8(); @@ -1669,7 +1458,7 @@ void tst_QStringApiSymmetry::right_data() // specific data testing out of bounds cases #define ROW(base, n, res) \ - QTest::addRow("%s%d", #base, n) << QStringRef(&base) << QLatin1String(#base) << n << QStringRef(&res); + QTest::addRow("%s%d", #base, n) << QStringView(base) << QLatin1String(#base) << n << QStringView(res); ROW(a, -1, a); ROW(a, 2, a); @@ -1687,7 +1476,7 @@ void tst_QStringApiSymmetry::right_QByteArray_data() // specific data testing out of bounds cases #define ROW(base, n, res) \ - QTest::addRow("%s%d", #base, n) << QStringRef(&base) << QLatin1String(#base) << n << QStringRef(&res); + QTest::addRow("%s%d", #base, n) << QStringView(base) << QLatin1String(#base) << n << QStringView(res); ROW(a, -1, empty); ROW(a, 2, a); @@ -1700,10 +1489,10 @@ void tst_QStringApiSymmetry::right_QByteArray_data() template void tst_QStringApiSymmetry::right_impl() { - QFETCH(const QStringRef, unicode); + QFETCH(const QStringView, unicode); QFETCH(const QLatin1String, latin1); QFETCH(const int, n); - QFETCH(const QStringRef, result); + QFETCH(const QStringView, result); const auto utf8 = unicode.toUtf8(); @@ -1727,18 +1516,18 @@ void tst_QStringApiSymmetry::right_impl() void tst_QStringApiSymmetry::sliced_data() { - QTest::addColumn("unicode"); + QTest::addColumn("unicode"); QTest::addColumn("latin1"); QTest::addColumn("pos"); QTest::addColumn("n"); - QTest::addColumn("result"); - QTest::addColumn("result2"); + QTest::addColumn("result"); + QTest::addColumn("result2"); -// QTest::addRow("null") << QStringRef() << QLatin1String() << 0 << 0 << QStringRef() << QStringRef(); - QTest::addRow("empty") << QStringRef(&empty) << QLatin1String("") << 0 << 0 << QStringRef(&empty) << QStringRef(&empty); +// QTest::addRow("null") << QStringView() << QLatin1String() << 0 << 0 << QStringView() << QStringView(); + QTest::addRow("empty") << QStringView(empty) << QLatin1String("") << 0 << 0 << QStringView(empty) << QStringView(empty); #define ROW(base, p, n, r1, r2) \ - QTest::addRow("%s%d%d", #base, p, n) << QStringRef(&base) << QLatin1String(#base) << p << n << QStringRef(&r1) << QStringRef(&r2) + QTest::addRow("%s%d%d", #base, p, n) << QStringView(base) << QLatin1String(#base) << p << n << QStringView(r1) << QStringView(r2) ROW(a, 0, 0, a, empty); ROW(a, 0, 1, a, a); @@ -1767,12 +1556,12 @@ void tst_QStringApiSymmetry::sliced_data() template void tst_QStringApiSymmetry::sliced_impl() { - QFETCH(const QStringRef, unicode); + QFETCH(const QStringView, unicode); QFETCH(const QLatin1String, latin1); QFETCH(const int, pos); QFETCH(const int, n); - QFETCH(const QStringRef, result); - QFETCH(const QStringRef, result2); + QFETCH(const QStringView, result); + QFETCH(const QStringView, result2); const auto utf8 = unicode.toUtf8(); @@ -1806,18 +1595,18 @@ void tst_QStringApiSymmetry::sliced_impl() void tst_QStringApiSymmetry::first_data() { - QTest::addColumn("unicode"); + QTest::addColumn("unicode"); QTest::addColumn("latin1"); QTest::addColumn("n"); - QTest::addColumn("result"); + QTest::addColumn("result"); -// QTest::addRow("null") << QStringRef() << QLatin1String() << 0 << QStringRef(); - QTest::addRow("empty") << QStringRef(&empty) << QLatin1String("") << 0 << QStringRef(&empty); +// QTest::addRow("null") << QStringView() << QLatin1String() << 0 << QStringView(); + QTest::addRow("empty") << QStringView(empty) << QLatin1String("") << 0 << QStringView(empty); // Some classes' left() implementations have a wide contract, others a narrow one - // so only test valid arguents here: + // so only test valid arguments here: #define ROW(base, n, res) \ - QTest::addRow("%s%d", #base, n) << QStringRef(&base) << QLatin1String(#base) << n << QStringRef(&res); + QTest::addRow("%s%d", #base, n) << QStringView(base) << QLatin1String(#base) << n << QStringView(res); ROW(a, 0, empty); ROW(a, 1, a); @@ -1836,10 +1625,10 @@ void tst_QStringApiSymmetry::first_data() template void tst_QStringApiSymmetry::first_impl() { - QFETCH(const QStringRef, unicode); + QFETCH(const QStringView, unicode); QFETCH(const QLatin1String, latin1); QFETCH(const int, n); - QFETCH(const QStringRef, result); + QFETCH(const QStringView, result); const auto utf8 = unicode.toUtf8(); @@ -1871,18 +1660,18 @@ void tst_QStringApiSymmetry::first_impl() void tst_QStringApiSymmetry::last_data() { - QTest::addColumn("unicode"); + QTest::addColumn("unicode"); QTest::addColumn("latin1"); QTest::addColumn("n"); - QTest::addColumn("result"); + QTest::addColumn("result"); -// QTest::addRow("null") << QStringRef() << QLatin1String() << 0 << QStringRef(); - QTest::addRow("empty") << QStringRef(&empty) << QLatin1String("") << 0 << QStringRef(&empty); +// QTest::addRow("null") << QStringView() << QLatin1String() << 0 << QStringView(); + QTest::addRow("empty") << QStringView(empty) << QLatin1String("") << 0 << QStringView(empty); // Some classes' last() implementations have a wide contract, others a narrow one // so only test valid arguents here: #define ROW(base, n, res) \ - QTest::addRow("%s%d", #base, n) << QStringRef(&base) << QLatin1String(#base) << n << QStringRef(&res); + QTest::addRow("%s%d", #base, n) << QStringView(base) << QLatin1String(#base) << n << QStringView(res); ROW(a, 0, empty); ROW(a, 1, a); @@ -1901,10 +1690,10 @@ void tst_QStringApiSymmetry::last_data() template void tst_QStringApiSymmetry::last_impl() { - QFETCH(const QStringRef, unicode); + QFETCH(const QStringView, unicode); QFETCH(const QLatin1String, latin1); QFETCH(const int, n); - QFETCH(const QStringRef, result); + QFETCH(const QStringView, result); const auto utf8 = unicode.toUtf8(); @@ -1928,18 +1717,18 @@ void tst_QStringApiSymmetry::last_impl() void tst_QStringApiSymmetry::chop_data() { - QTest::addColumn("unicode"); + QTest::addColumn("unicode"); QTest::addColumn("latin1"); QTest::addColumn("n"); - QTest::addColumn("result"); + QTest::addColumn("result"); -// QTest::addRow("null") << QStringRef() << QLatin1String() << 0 << QStringRef(); - QTest::addRow("empty") << QStringRef(&empty) << QLatin1String("") << 0 << QStringRef(&empty); +// QTest::addRow("null") << QStringView() << QLatin1String() << 0 << QStringView(); + QTest::addRow("empty") << QStringView(empty) << QLatin1String("") << 0 << QStringView(empty); // Some classes' truncate() implementations have a wide contract, others a narrow one // so only test valid arguents here: #define ROW(base, n, res) \ - QTest::addRow("%s%d", #base, n) << QStringRef(&base) << QLatin1String(#base) << n << QStringRef(&res); + QTest::addRow("%s%d", #base, n) << QStringView(base) << QLatin1String(#base) << n << QStringView(res); ROW(a, 0, a); ROW(a, 1, empty); @@ -1958,10 +1747,10 @@ void tst_QStringApiSymmetry::chop_data() template void tst_QStringApiSymmetry::chop_impl() { - QFETCH(const QStringRef, unicode); + QFETCH(const QStringView, unicode); QFETCH(const QLatin1String, latin1); QFETCH(const int, n); - QFETCH(const QStringRef, result); + QFETCH(const QStringView, result); const auto utf8 = unicode.toUtf8(); @@ -1994,11 +1783,11 @@ void tst_QStringApiSymmetry::chop_impl() void tst_QStringApiSymmetry::trimmed_data() { QTest::addColumn("unicode"); - QTest::addColumn("result"); + QTest::addColumn("result"); const auto latin1Whitespace = QLatin1String(" \r\n\t\f\v"); - QTest::addRow("null") << QString() << QStringRef(); + QTest::addRow("null") << QString() << QStringView(); auto add = [latin1Whitespace](const QString &str) { // run through all substrings of latin1Whitespace @@ -2006,7 +1795,7 @@ void tst_QStringApiSymmetry::trimmed_data() for (int pos = 0; pos < latin1Whitespace.size() - len; ++pos) { const QString unicode = latin1Whitespace.mid(pos, len) + str + latin1Whitespace.mid(pos, len); const QScopedArrayPointer escaped(QTest::toString(unicode)); - QTest::addRow("%s", escaped.data()) << unicode << QStringRef(&str); + QTest::addRow("%s", escaped.data()) << unicode << QStringView(str); } } }; @@ -2020,13 +1809,13 @@ template void tst_QStringApiSymmetry::trimmed_impl() { QFETCH(const QString, unicode); - QFETCH(const QStringRef, result); + QFETCH(const QStringView, result); const auto utf8 = unicode.toUtf8(); const auto l1s = unicode.toLatin1(); const auto l1 = l1s.isNull() ? QLatin1String() : QLatin1String(l1s); - const auto ref = unicode.isNull() ? QStringRef() : QStringRef(&unicode); + const auto ref = unicode.isNull() ? QStringView() : QStringView(unicode); const auto s = make(ref, l1, utf8); QCOMPARE(s.isNull(), unicode.isNull()); @@ -2085,7 +1874,7 @@ void tst_QStringApiSymmetry::toNumber_impl() const auto l1s = data.toLatin1(); const auto l1 = l1s.isNull() ? QLatin1String() : QLatin1String(l1s); - const auto ref = data.isNull() ? QStringRef() : QStringRef(&data); + const auto ref = data.isNull() ? QStringView() : QStringView(data); const auto s = make(ref, l1, utf8); bool is_ok = false; @@ -2146,7 +1935,6 @@ void tst_QStringApiSymmetry::toNumber_impl() } } - void tst_QStringApiSymmetry::count_data() { QTest::addColumn("data"); @@ -2168,14 +1956,14 @@ void tst_QStringApiSymmetry::count_impl() const auto l1s = data.toLatin1(); const auto l1 = l1s.isNull() ? QLatin1String() : QLatin1String(l1s); - const auto ref = data.isNull() ? QStringRef() : QStringRef(&data); + const auto ref = data.isNull() ? QStringView() : QStringView(data); const auto s = make(ref, l1, utf8); const auto nutf8 = needle.toUtf8(); const auto nl1s = needle.toLatin1(); const auto nl1 = nl1s.isNull() ? QLatin1String() : QLatin1String(l1s); - const auto nref = needle.isNull() ? QStringRef() : QStringRef(&needle); + const auto nref = needle.isNull() ? QStringView() : QStringView(needle); const auto ns = make(nref, nl1, nutf8); QCOMPARE(s.count(ns), result); @@ -2190,7 +1978,6 @@ void tst_QStringApiSymmetry::count_impl() // template Str make(const QString &s); -template <> QStringRef make(const QString &s) { return QStringRef(&s); } template <> QString make(const QString &s) { return s; } template <> QStringView make(const QString &s) { return s; } @@ -2369,7 +2156,6 @@ void tst_QStringApiSymmetry::indexOf_data(bool rhsHasVariableLength) QTest::addRow("haystack: null, needle: a") << null << QLatin1String() << a << QLatin1String("a") << zeroPos << minus1Pos << minus1Pos; - #define ROW(h, n, st, cs, cis) \ QTest::addRow("haystack: %s, needle: %s", #h, #n) << h << QLatin1String(#h) \ << n << QLatin1String(#n) \ @@ -2426,8 +2212,8 @@ void tst_QStringApiSymmetry::indexOf_impl() const const auto haystackU8 = haystackU16.toUtf8(); const auto needleU8 = needleU16.toUtf8(); - const auto haystack = make(QStringRef(&haystackU16), haystackL1, haystackU8); - const auto needle = make(QStringRef(&needleU16), needleL1, needleU8); + const auto haystack = make(QStringView(haystackU16), haystackL1, haystackU8); + const auto needle = make(QStringView(needleU16), needleL1, needleU8); using size_type = typename Haystack::size_type; @@ -2501,8 +2287,8 @@ void tst_QStringApiSymmetry::contains_impl() const const auto haystackU8 = haystackU16.toUtf8(); const auto needleU8 = needleU16.toUtf8(); - const auto haystack = make(QStringRef(&haystackU16), haystackL1, haystackU8); - const auto needle = make(QStringRef(&needleU16), needleL1, needleU8); + const auto haystack = make(QStringView(haystackU16), haystackL1, haystackU8); + const auto needle = make(QStringView(needleU16), needleL1, needleU8); QCOMPARE(haystack.contains(needle), resultCS); QCOMPARE(haystack.contains(needle, Qt::CaseSensitive), resultCS); @@ -2611,8 +2397,8 @@ void tst_QStringApiSymmetry::lastIndexOf_impl() const const auto haystackU8 = haystackU16.toUtf8(); const auto needleU8 = needleU16.toUtf8(); - const auto haystack = make(QStringRef(&haystackU16), haystackL1, haystackU8); - const auto needle = make(QStringRef(&needleU16), needleL1, needleU8); + const auto haystack = make(QStringView(haystackU16), haystackL1, haystackU8); + const auto needle = make(QStringView(needleU16), needleL1, needleU8); using size_type = typename Haystack::size_type; diff --git a/tests/auto/corelib/text/qstringbuilder/qstringbuilder1/stringbuilder.cpp b/tests/auto/corelib/text/qstringbuilder/qstringbuilder1/stringbuilder.cpp index 5903c7066b..b811c63036 100644 --- a/tests/auto/corelib/text/qstringbuilder/qstringbuilder1/stringbuilder.cpp +++ b/tests/auto/corelib/text/qstringbuilder/qstringbuilder1/stringbuilder.cpp @@ -59,7 +59,6 @@ template QString toQString(const T &t); template <> QString toQString(const QString &s) { return s; } -template <> QString toQString(const QStringRef &r) { return r.toString(); } template <> QString toQString(const QStringView &v) { return v.toString(); } template <> QString toQString(const QLatin1String &l) { return l; } template <> QString toQString(const QLatin1Char &l) { return QChar(l); } @@ -84,8 +83,7 @@ void runScenario() // strings default to utf8. QLatin1String l1string(LITERAL); QString string(l1string); - QStringRef stringref(&string, 2, 10); - QStringView stringview(stringref); + QStringView stringview = QStringView{ string }.mid(2, 10); QLatin1Char lchar('c'); QChar qchar(lchar); QChar::SpecialCharacter special(QChar::Nbsp); @@ -109,7 +107,6 @@ void runScenario() CHECK(P, l1string, l1string); CHECK(P, l1string, string); - CHECK(P, l1string, stringref); CHECK(Q, l1string, stringview); CHECK(P, l1string, lchar); CHECK(P, l1string, qchar); @@ -120,7 +117,6 @@ void runScenario() CHECK(Q, l1string, u16charstar); CHECK(P, string, string); - CHECK(P, string, stringref); CHECK(Q, string, stringview); CHECK(P, string, lchar); CHECK(P, string, qchar); @@ -130,16 +126,6 @@ void runScenario() CHECK(Q, string, u16chararray); CHECK(Q, string, u16charstar); - CHECK(P, stringref, stringref); - CHECK(Q, stringref, stringview); - CHECK(P, stringref, lchar); - CHECK(P, stringref, qchar); - CHECK(P, stringref, special); - CHECK(P, stringref, QStringLiteral(LITERAL)); - CHECK(Q, stringref, u16char); - CHECK(Q, stringref, u16chararray); - CHECK(Q, stringref, u16charstar); - CHECK(Q, stringview, stringview); CHECK(Q, stringview, lchar); CHECK(Q, stringview, qchar); @@ -191,7 +177,7 @@ void runScenario() toQByteArray(a1).append(toQByteArray(a2))) \ /* end */ - QByteArray bytearray = stringref.toUtf8(); + QByteArray bytearray = stringview.toUtf8(); char *charstar = bytearray.data(); char chararray[3] = { 'H', 'i', '\0' }; const char constchararray[3] = { 'H', 'i', '\0' }; @@ -224,9 +210,9 @@ void runScenario() QString r; // self-assignment: - r = stringref.toString(); + r = stringview.toString(); r = lchar + r; - QCOMPARE(r, QString(lchar P stringref)); + QCOMPARE(r, QString(lchar P stringview)); #ifdef Q_COMPILER_UNICODE_STRINGS r = QStringLiteral(UNICODE_LITERAL); diff --git a/tests/auto/corelib/text/qstringmatcher/tst_qstringmatcher.cpp b/tests/auto/corelib/text/qstringmatcher/tst_qstringmatcher.cpp index 2d577bb0ab..2be31e30df 100644 --- a/tests/auto/corelib/text/qstringmatcher/tst_qstringmatcher.cpp +++ b/tests/auto/corelib/text/qstringmatcher/tst_qstringmatcher.cpp @@ -55,7 +55,7 @@ void tst_QStringMatcher::qstringmatcher() void tst_QStringMatcher::caseSensitivity() { const QString haystack = QStringLiteral("foobarFoo"); - const QStringRef needle = haystack.rightRef(3); // "Foo" + const QStringView needle = QStringView{ haystack }.right(3); // "Foo" QStringMatcher matcher(needle.data(), needle.size()); QCOMPARE(matcher.caseSensitivity(), Qt::CaseSensitive); diff --git a/tests/auto/corelib/text/qstringref/CMakeLists.txt b/tests/auto/corelib/text/qstringref/CMakeLists.txt deleted file mode 100644 index 089a3f128d..0000000000 --- a/tests/auto/corelib/text/qstringref/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -# Generated from qstringref.pro. - -##################################################################### -## tst_qstringref Test: -##################################################################### - -qt_add_test(tst_qstringref - SOURCES - tst_qstringref.cpp -) diff --git a/tests/auto/corelib/text/qstringref/qstringref.pro b/tests/auto/corelib/text/qstringref/qstringref.pro deleted file mode 100644 index 04f3ba6a92..0000000000 --- a/tests/auto/corelib/text/qstringref/qstringref.pro +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG += testcase -TARGET = tst_qstringref -QT = core testlib -SOURCES = tst_qstringref.cpp diff --git a/tests/auto/corelib/text/qstringref/tst_qstringref.cpp b/tests/auto/corelib/text/qstringref/tst_qstringref.cpp deleted file mode 100644 index 3e05d7af4f..0000000000 --- a/tests/auto/corelib/text/qstringref/tst_qstringref.cpp +++ /dev/null @@ -1,2165 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2016 Intel Corporation. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include - -#include -#include - - -class tst_QStringRef : public QObject -{ - Q_OBJECT -public slots: - void cleanup(); -private slots: - void at(); - void endsWith(); - void startsWith(); - void contains(); - void count(); - void lastIndexOf_data(); - void lastIndexOf(); - void indexOf_data(); - void indexOf(); - void indexOf2_data(); - void indexOf2(); - void iteration(); - void length_data(); - void length(); - void isEmpty(); - void compare_data(); - void compare(); - void compare2_data(); - void compare2(); - void operator_eqeq_nullstring(); - void toNum(); - void toDouble_data(); - void toDouble(); - void toFloat(); - void toLong_data(); - void toLong(); - void toULong_data(); - void toULong(); - void toLongLong(); - void toULongLong(); - void toUInt(); - void toInt(); - void toShort(); - void toUShort(); - void double_conversion_data(); - void double_conversion(); - void integer_conversion_data(); - void integer_conversion(); - void trimmed(); - void truncate(); - void chop(); - void left(); - void right(); - void mid(); - void split_data(); - void split(); - void nullToString(); -}; - -static QStringRef emptyRef() -{ - static const QString empty(""); - return empty.midRef(0); -} - -#define CREATE_REF(string) \ - const QString padded = QLatin1Char(' ') + string + QLatin1Char(' '); \ - QStringRef ref = padded.midRef(1, padded.size() - 2); - -typedef QList IntList; - -// This next bit is needed for the NAN and INF in string -> number conversion tests -#include -#include -#include -#if defined(Q_OS_WIN) -# include -// mingw defines NAN and INFINITY to 0/0 and x/0 -# if defined(Q_CC_GNU) -# undef NAN -# undef INFINITY -# else -# define isnan(d) _isnan(d) -# endif -#endif -#if defined(Q_OS_MAC) && !defined isnan -#define isnan(d) __isnand(d) -#endif -#if defined(Q_OS_SOLARIS) -# include -#endif - -enum { - LittleEndian, - BigEndian -#ifdef Q_BYTE_ORDER -# if Q_BYTE_ORDER == Q_BIG_ENDIAN - , ByteOrder = BigEndian -# elif Q_BYTE_ORDER == Q_LITTLE_ENDIAN - , ByteOrder = LittleEndian -# else -# error "undefined byte order" -# endif -}; -#else -}; -static const unsigned int one = 1; -static const bool ByteOrder = ((*((unsigned char *) &one) == 0) ? BigEndian : LittleEndian); -#endif -#if !defined(INFINITY) -static const unsigned char be_inf_bytes[] = { 0x7f, 0xf0, 0, 0, 0, 0, 0,0 }; -static const unsigned char le_inf_bytes[] = { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f }; -static inline double inf() -{ - if (ByteOrder == BigEndian) - return *reinterpret_cast(be_inf_bytes); - return *reinterpret_cast(le_inf_bytes); -} -# define INFINITY (::inf()) -#endif -#if !defined(NAN) -static const unsigned char be_nan_bytes[] = { 0x7f, 0xf8, 0, 0, 0, 0, 0,0 }; -static const unsigned char le_nan_bytes[] = { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f }; -static inline double nan() -{ - if (ByteOrder == BigEndian) - return *reinterpret_cast(be_nan_bytes); - return *reinterpret_cast(le_nan_bytes); -} -# define NAN (::nan()) -#endif - -void tst_QStringRef::cleanup() -{ - QLocale::setDefault(QLocale(QString(QLatin1Char('C')))); -} - -void tst_QStringRef::at() -{ - const QString hw = QStringLiteral("Hello World"); - const QStringRef ref = hw.midRef(6); - QCOMPARE(ref.at(0), QChar('W')); - QCOMPARE(ref.at(4), QChar('d')); - QCOMPARE(ref[0], QChar('W')); - QCOMPARE(ref[4], QChar('d')); -} - -void tst_QStringRef::length_data() -{ - QTest::addColumn("s1"); - QTest::addColumn("res"); - - QTest::newRow("data0") << QString("Test") << 4; - QTest::newRow("data1") << QString("The quick brown fox jumps over the lazy dog") << 43; - QTest::newRow("data2") << QString() << 0; - QTest::newRow("data3") << QString("A") << 1; - QTest::newRow("data4") << QString("AB") << 2; - QTest::newRow("data5") << QString("AB\n") << 3; - QTest::newRow("data6") << QString("AB\nC") << 4; - QTest::newRow("data7") << QString("\n") << 1; - QTest::newRow("data8") << QString("\nA") << 2; - QTest::newRow("data9") << QString("\nAB") << 3; - QTest::newRow("data10") << QString("\nAB\nCDE") << 7; - QTest::newRow("data11") << QString("shdnftrheid fhgnt gjvnfmd chfugkh bnfhg thgjf vnghturkf chfnguh bjgnfhvygh hnbhgutjfv dhdnjds dcjs d") << 100; - QTest::newRow("data12") << QString("") << 0; -} - - -void tst_QStringRef::length() -{ - QFETCH(QString, s1); - CREATE_REF(s1); - QTEST(ref.length(), "res"); -} - - -void tst_QStringRef::isEmpty() -{ - QStringRef a; - QVERIFY(a.isEmpty()); - QVERIFY(emptyRef().isEmpty()); - CREATE_REF("Not empty"); - QVERIFY(!ref.isEmpty()); -} - -void tst_QStringRef::indexOf_data() -{ - QTest::addColumn("haystack"); - QTest::addColumn("needle"); - QTest::addColumn("startpos"); - QTest::addColumn("bcs"); - QTest::addColumn("resultpos"); - - QTest::newRow("data0") << QString("abc") << QString("a") << 0 << true << 0; - QTest::newRow("data1") << QString("abc") << QString("a") << 0 << false << 0; - QTest::newRow("data2") << QString("abc") << QString("A") << 0 << true << -1; - QTest::newRow("data3") << QString("abc") << QString("A") << 0 << false << 0; - QTest::newRow("data4") << QString("abc") << QString("a") << 1 << true << -1; - QTest::newRow("data5") << QString("abc") << QString("a") << 1 << false << -1; - QTest::newRow("data6") << QString("abc") << QString("A") << 1 << true << -1; - QTest::newRow("data7") << QString("abc") << QString("A") << 1 << false << -1; - QTest::newRow("data8") << QString("abc") << QString("b") << 0 << true << 1; - QTest::newRow("data9") << QString("abc") << QString("b") << 0 << false << 1; - QTest::newRow("data10") << QString("abc") << QString("B") << 0 << true << -1; - QTest::newRow("data11") << QString("abc") << QString("B") << 0 << false << 1; - QTest::newRow("data12") << QString("abc") << QString("b") << 1 << true << 1; - QTest::newRow("data13") << QString("abc") << QString("b") << 1 << false << 1; - QTest::newRow("data14") << QString("abc") << QString("B") << 1 << true << -1; - QTest::newRow("data15") << QString("abc") << QString("B") << 1 << false << 1; - QTest::newRow("data16") << QString("abc") << QString("b") << 2 << true << -1; - QTest::newRow("data17") << QString("abc") << QString("b") << 2 << false << -1; - - QTest::newRow("data20") << QString("ABC") << QString("A") << 0 << true << 0; - QTest::newRow("data21") << QString("ABC") << QString("A") << 0 << false << 0; - QTest::newRow("data22") << QString("ABC") << QString("a") << 0 << true << -1; - QTest::newRow("data23") << QString("ABC") << QString("a") << 0 << false << 0; - QTest::newRow("data24") << QString("ABC") << QString("A") << 1 << true << -1; - QTest::newRow("data25") << QString("ABC") << QString("A") << 1 << false << -1; - QTest::newRow("data26") << QString("ABC") << QString("a") << 1 << true << -1; - QTest::newRow("data27") << QString("ABC") << QString("a") << 1 << false << -1; - QTest::newRow("data28") << QString("ABC") << QString("B") << 0 << true << 1; - QTest::newRow("data29") << QString("ABC") << QString("B") << 0 << false << 1; - QTest::newRow("data30") << QString("ABC") << QString("b") << 0 << true << -1; - QTest::newRow("data31") << QString("ABC") << QString("b") << 0 << false << 1; - QTest::newRow("data32") << QString("ABC") << QString("B") << 1 << true << 1; - QTest::newRow("data33") << QString("ABC") << QString("B") << 1 << false << 1; - QTest::newRow("data34") << QString("ABC") << QString("b") << 1 << true << -1; - QTest::newRow("data35") << QString("ABC") << QString("b") << 1 << false << 1; - QTest::newRow("data36") << QString("ABC") << QString("B") << 2 << true << -1; - QTest::newRow("data37") << QString("ABC") << QString("B") << 2 << false << -1; - - QTest::newRow("data40") << QString("aBc") << QString("bc") << 0 << true << -1; - QTest::newRow("data41") << QString("aBc") << QString("Bc") << 0 << true << 1; - QTest::newRow("data42") << QString("aBc") << QString("bC") << 0 << true << -1; - QTest::newRow("data43") << QString("aBc") << QString("BC") << 0 << true << -1; - QTest::newRow("data44") << QString("aBc") << QString("bc") << 0 << false << 1; - QTest::newRow("data45") << QString("aBc") << QString("Bc") << 0 << false << 1; - QTest::newRow("data46") << QString("aBc") << QString("bC") << 0 << false << 1; - QTest::newRow("data47") << QString("aBc") << QString("BC") << 0 << false << 1; - QTest::newRow("data48") << QString("AbC") << QString("bc") << 0 << true << -1; - QTest::newRow("data49") << QString("AbC") << QString("Bc") << 0 << true << -1; - QTest::newRow("data50") << QString("AbC") << QString("bC") << 0 << true << 1; - QTest::newRow("data51") << QString("AbC") << QString("BC") << 0 << true << -1; - QTest::newRow("data52") << QString("AbC") << QString("bc") << 0 << false << 1; - QTest::newRow("data53") << QString("AbC") << QString("Bc") << 0 << false << 1; - - QTest::newRow("data54") << QString("AbC") << QString("bC") << 0 << false << 1; - QTest::newRow("data55") << QString("AbC") << QString("BC") << 0 << false << 1; - QTest::newRow("data56") << QString("AbC") << QString("BC") << 1 << false << 1; - QTest::newRow("data57") << QString("AbC") << QString("BC") << 2 << false << -1; -#if 0 - QTest::newRow("null-in-null") << QString() << QString() << 0 << false << 0; - QTest::newRow("empty-in-null") << QString() << QString("") << 0 << false << 0; - QTest::newRow("null-in-empty") << QString("") << QString() << 0 << false << 0; - QTest::newRow("empty-in-empty") << QString("") << QString("") << 0 << false << 0; -#endif - - - QString s1 = "abc"; - s1 += QChar(0xb5); - QString s2; - s2 += QChar(0x3bc); - QTest::newRow("data58") << QString(s1) << QString(s2) << 0 << false << 3; - s2.prepend(QLatin1Char('C')); - QTest::newRow("data59") << QString(s1) << QString(s2) << 0 << false << 2; - - QString veryBigHaystack(500, 'a'); - veryBigHaystack += 'B'; - QTest::newRow("BoyerMooreStressTest") << veryBigHaystack << veryBigHaystack << 0 << true << 0; - QTest::newRow("BoyerMooreStressTest2") << veryBigHaystack + 'c' << veryBigHaystack << 0 << true << 0; - QTest::newRow("BoyerMooreStressTest3") << 'c' + veryBigHaystack << veryBigHaystack << 0 << true << 1; - QTest::newRow("BoyerMooreStressTest4") << veryBigHaystack << veryBigHaystack + 'c' << 0 << true << -1; - QTest::newRow("BoyerMooreStressTest5") << veryBigHaystack << 'c' + veryBigHaystack << 0 << true << -1; - QTest::newRow("BoyerMooreStressTest6") << 'd' + veryBigHaystack << 'c' + veryBigHaystack << 0 << true << -1; - QTest::newRow("BoyerMooreStressTest7") << veryBigHaystack + 'c' << 'c' + veryBigHaystack << 0 << true << -1; - - QTest::newRow("BoyerMooreInsensitiveStressTest") << veryBigHaystack << veryBigHaystack << 0 << false << 0; - -} - -void tst_QStringRef::indexOf() -{ - QFETCH(QString, haystack); - QFETCH(QString, needle); - QFETCH(int, startpos); - QFETCH(bool, bcs); - QFETCH(int, resultpos); - - const QString haystackPadded = QLatin1Char(' ') + haystack + QLatin1Char(' '); - const QString needlePadded = QLatin1Char(' ') + needle + QLatin1Char(' '); - const QStringRef haystackRef(&haystackPadded, 1, haystack.size()); - const QStringRef needleRef(&needlePadded, 1, needle.size()); - - Qt::CaseSensitivity cs = bcs ? Qt::CaseSensitive : Qt::CaseInsensitive; - - QCOMPARE(haystack.indexOf(needle, startpos, cs), resultpos); - QCOMPARE(haystackRef.indexOf(needle, startpos, cs), resultpos); - QCOMPARE(haystackRef.indexOf(needleRef, startpos, cs), resultpos); - QCOMPARE(haystack.indexOf(needleRef, startpos, cs), resultpos); - - if (cs == Qt::CaseSensitive) { - QCOMPARE(haystack.indexOf(needle, startpos), resultpos); - QCOMPARE(haystackRef.indexOf(needle, startpos), resultpos); - QCOMPARE(haystackRef.indexOf(needleRef, startpos), resultpos); - QCOMPARE(haystack.indexOf(needleRef, startpos), resultpos); - if (startpos == 0) { - QCOMPARE(haystack.indexOf(needle), resultpos); - QCOMPARE(haystackRef.indexOf(needle), resultpos); - QCOMPARE(haystackRef.indexOf(needleRef), resultpos); - QCOMPARE(haystack.indexOf(needleRef), resultpos); - } - } - if (needle.size() == 1) { - QCOMPARE(needle.at(0), needleRef.at(0)); - QCOMPARE(haystack.indexOf(needleRef.at(0), startpos, cs), resultpos); - QCOMPARE(haystackRef.indexOf(needle.at(0), startpos, cs), resultpos); - QCOMPARE(haystackRef.indexOf(needleRef.at(0), startpos, cs), resultpos); - QCOMPARE(haystack.indexOf(needleRef.at(0), startpos ,cs), resultpos); - } -} - -void tst_QStringRef::indexOf2_data() -{ - QTest::addColumn("haystack"); - QTest::addColumn("needle"); - QTest::addColumn("resultpos"); - - QTest::newRow("data0") << QString() << QString() << 0; - QTest::newRow("data1") << QString() << QString("") << 0; - QTest::newRow("data2") << QString("") << QString() << 0; - QTest::newRow("data3") << QString("") << QString("") << 0; - QTest::newRow("data4") << QString() << QString("a") << -1; - QTest::newRow("data5") << QString() << QString("abcdefg") << -1; - QTest::newRow("data6") << QString("") << QString("a") << -1; - QTest::newRow("data7") << QString("") << QString("abcdefg") << -1; - - QTest::newRow("data8") << QString("a") << QString() << 0; - QTest::newRow("data9") << QString("a") << QString("") << 0; - QTest::newRow("data10") << QString("a") << QString("a") << 0; - QTest::newRow("data11") << QString("a") << QString("b") << -1; - QTest::newRow("data12") << QString("a") << QString("abcdefg") << -1; - QTest::newRow("data13") << QString("ab") << QString() << 0; - QTest::newRow("data14") << QString("ab") << QString("") << 0; - QTest::newRow("data15") << QString("ab") << QString("a") << 0; - QTest::newRow("data16") << QString("ab") << QString("b") << 1; - QTest::newRow("data17") << QString("ab") << QString("ab") << 0; - QTest::newRow("data18") << QString("ab") << QString("bc") << -1; - QTest::newRow("data19") << QString("ab") << QString("abcdefg") << -1; - - QTest::newRow("data30") << QString("abc") << QString("a") << 0; - QTest::newRow("data31") << QString("abc") << QString("b") << 1; - QTest::newRow("data32") << QString("abc") << QString("c") << 2; - QTest::newRow("data33") << QString("abc") << QString("d") << -1; - QTest::newRow("data34") << QString("abc") << QString("ab") << 0; - QTest::newRow("data35") << QString("abc") << QString("bc") << 1; - QTest::newRow("data36") << QString("abc") << QString("cd") << -1; - QTest::newRow("data37") << QString("abc") << QString("ac") << -1; - - // sizeof(whale) > 32 - QString whale = "a5zby6cx7dw8evf9ug0th1si2rj3qkp4lomn"; - QString minnow = "zby"; - QTest::newRow("data40") << whale << minnow << 2; - QTest::newRow("data41") << (whale + whale) << minnow << 2; - QTest::newRow("data42") << (minnow + whale) << minnow << 0; - QTest::newRow("data43") << whale << whale << 0; - QTest::newRow("data44") << (whale + whale) << whale << 0; - QTest::newRow("data45") << whale << (whale + whale) << -1; - QTest::newRow("data46") << (whale + whale) << (whale + whale) << 0; - QTest::newRow("data47") << (whale + whale) << (whale + minnow) << -1; - QTest::newRow("data48") << (minnow + whale) << whale << (int)minnow.length(); -} - -void tst_QStringRef::indexOf2() -{ - QFETCH(QString, haystack); - QFETCH(QString, needle); - QFETCH(int, resultpos); - - const QString haystackPadded = QLatin1Char(' ') + haystack + QLatin1Char(' '); - const QString needlePadded = QLatin1Char(' ') + needle + QLatin1Char(' '); - const QStringRef haystackRef(&haystackPadded, 1, haystack.size()); - const QStringRef needleRef(&needlePadded, 1, needle.size()); - - - int got; - - QCOMPARE(haystack.indexOf(needleRef, 0, Qt::CaseSensitive), resultpos); - QCOMPARE(haystackRef.indexOf(needle, 0, Qt::CaseSensitive), resultpos); - QCOMPARE(haystackRef.indexOf(needleRef, 0, Qt::CaseSensitive), resultpos); - QCOMPARE(haystack.indexOf(needleRef, 0, Qt::CaseInsensitive), resultpos); - QCOMPARE(haystackRef.indexOf(needle, 0, Qt::CaseInsensitive), resultpos); - QCOMPARE(haystackRef.indexOf(needleRef, 0, Qt::CaseInsensitive), resultpos); - if (needle.length() > 0) { - got = haystackRef.lastIndexOf(needle, -1, Qt::CaseSensitive); - QVERIFY(got == resultpos || (resultpos >= 0 && got >= resultpos)); - got = haystackRef.lastIndexOf(needle, -1, Qt::CaseInsensitive); - QVERIFY(got == resultpos || (resultpos >= 0 && got >= resultpos)); - - got = haystack.lastIndexOf(needleRef, -1, Qt::CaseSensitive); - QVERIFY(got == resultpos || (resultpos >= 0 && got >= resultpos)); - got = haystack.lastIndexOf(needleRef, -1, Qt::CaseInsensitive); - QVERIFY(got == resultpos || (resultpos >= 0 && got >= resultpos)); - - got = haystackRef.lastIndexOf(needleRef, -1, Qt::CaseSensitive); - QVERIFY(got == resultpos || (resultpos >= 0 && got >= resultpos)); - got = haystackRef.lastIndexOf(needleRef, -1, Qt::CaseInsensitive); - QVERIFY(got == resultpos || (resultpos >= 0 && got >= resultpos)); - } -} - -void tst_QStringRef::iteration() -{ - QString hello = "Hello"; - QString olleh = "olleH"; - - QStringRef ref(&hello); - QStringRef rref(&olleh); - - const QStringRef &cref = ref; - const QStringRef &crref = rref; - - QVERIFY(std::equal( ref.begin(), ref.end(), hello.begin())); - QVERIFY(std::equal( rref.begin(), rref.end(), olleh.begin())); - QVERIFY(std::equal( cref.begin(), cref.end(), hello.begin())); - QVERIFY(std::equal(crref.begin(), crref.end(), olleh.begin())); - - QVERIFY(std::equal( ref.cbegin(), ref.cend(), hello.begin())); - QVERIFY(std::equal( rref.cbegin(), rref.cend(), olleh.begin())); - QVERIFY(std::equal( cref.cbegin(), cref.cend(), hello.begin())); - QVERIFY(std::equal(crref.cbegin(), crref.cend(), olleh.begin())); - - QVERIFY(std::equal( ref.rbegin(), ref.rend(), hello.rbegin())); - QVERIFY(std::equal( rref.rbegin(), rref.rend(), olleh.rbegin())); - QVERIFY(std::equal( cref.rbegin(), cref.rend(), hello.rbegin())); - QVERIFY(std::equal(crref.rbegin(), crref.rend(), olleh.rbegin())); - - QVERIFY(std::equal( ref.crbegin(), ref.crend(), hello.rbegin())); - QVERIFY(std::equal( rref.crbegin(), rref.crend(), olleh.rbegin())); - QVERIFY(std::equal( cref.crbegin(), cref.crend(), hello.rbegin())); - QVERIFY(std::equal(crref.crbegin(), crref.crend(), olleh.rbegin())); -} - -void tst_QStringRef::lastIndexOf_data() -{ - QTest::addColumn("haystack"); - QTest::addColumn("needle"); - QTest::addColumn("from"); - QTest::addColumn("expected"); - QTest::addColumn("caseSensitive"); - - QString a = "ABCDEFGHIEfGEFG"; - - QTest::newRow("-1") << a << "G" << int(a.size()) - 1 << 14 << true; - QTest::newRow("1") << a << "G" << - 1 << 14 << true; - QTest::newRow("2") << a << "G" << -3 << 11 << true; - QTest::newRow("3") << a << "G" << -5 << 6 << true; - QTest::newRow("4") << a << "G" << 14 << 14 << true; - QTest::newRow("5") << a << "G" << 13 << 11 << true; - QTest::newRow("6") << a << "B" << int(a.size()) - 1 << 1 << true; - QTest::newRow("7") << a << "B" << - 1 << 1 << true; - QTest::newRow("8") << a << "B" << 1 << 1 << true; - QTest::newRow("9") << a << "B" << 0 << -1 << true; - - QTest::newRow("10") << a << "G" << -1 << int(a.size())-1 << true; - QTest::newRow("11") << a << "G" << int(a.size())-1 << int(a.size())-1 << true; - QTest::newRow("12") << a << "G" << int(a.size()) << -1 << true; - QTest::newRow("13") << a << "A" << 0 << 0 << true; - QTest::newRow("14") << a << "A" << -1*int(a.size()) << 0 << true; - - QTest::newRow("15") << a << "efg" << 0 << -1 << false; - QTest::newRow("16") << a << "efg" << int(a.size()) << -1 << false; - QTest::newRow("17") << a << "efg" << -1 * int(a.size()) << -1 << false; - QTest::newRow("19") << a << "efg" << int(a.size()) - 1 << 12 << false; - QTest::newRow("20") << a << "efg" << 12 << 12 << false; - QTest::newRow("21") << a << "efg" << -12 << -1 << false; - QTest::newRow("22") << a << "efg" << 11 << 9 << false; - - QTest::newRow("24") << "" << "asdf" << -1 << -1 << false; - QTest::newRow("25") << "asd" << "asdf" << -1 << -1 << false; - QTest::newRow("26") << "" << QString() << -1 << -1 << false; - - QTest::newRow("27") << a << "" << int(a.size()) << int(a.size()) << false; - QTest::newRow("28") << a << "" << int(a.size()) + 10 << -1 << false; -} - -void tst_QStringRef::lastIndexOf() -{ - QFETCH(QString, haystack); - QFETCH(QString, needle); - QFETCH(int, from); - QFETCH(int, expected); - QFETCH(bool, caseSensitive); - - const QString haystackPadded = QLatin1Char(' ') + haystack + QLatin1Char(' '); - const QString needlePadded = QLatin1Char(' ') + needle + QLatin1Char(' '); - const QStringRef haystackRef(&haystackPadded, 1, haystack.size()); - const QStringRef needleRef(&needlePadded, 1, needle.size()); - - Qt::CaseSensitivity cs = (caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive); - - QCOMPARE(haystack.lastIndexOf(needleRef, from, cs), expected); - QCOMPARE(haystackRef.lastIndexOf(needle, from, cs), expected); - QCOMPARE(haystackRef.lastIndexOf(needleRef, from, cs), expected); - - - if (cs == Qt::CaseSensitive) { - QCOMPARE(haystack.lastIndexOf(needleRef, from), expected); - QCOMPARE(haystackRef.lastIndexOf(needle, from), expected); - QCOMPARE(haystackRef.lastIndexOf(needleRef, from), expected); - - if (from == -1) { - QCOMPARE(haystack.lastIndexOf(needleRef), expected); - QCOMPARE(haystackRef.lastIndexOf(needle), expected); - QCOMPARE(haystackRef.lastIndexOf(needleRef), expected); - - } - } - if (needle.size() == 1) { - QCOMPARE(haystack.lastIndexOf(needleRef.at(0), from), expected); - QCOMPARE(haystackRef.lastIndexOf(needle.at(0), from), expected); - QCOMPARE(haystackRef.lastIndexOf(needleRef.at(0), from), expected); - } -} - -void tst_QStringRef::count() -{ - const QString a = QString::fromLatin1("ABCDEFGHIEfGEFG"); // 15 chars - CREATE_REF(a); - QCOMPARE(ref.count('A'),1); - QCOMPARE(ref.count('Z'),0); - QCOMPARE(ref.count('E'),3); - QCOMPARE(ref.count('F'),2); - QCOMPARE(ref.count('F',Qt::CaseInsensitive),3); - QCOMPARE(ref.count("FG"),2); - QCOMPARE(ref.count("FG",Qt::CaseInsensitive),3); - QCOMPARE(ref.count(QString(), Qt::CaseInsensitive), 16); - QCOMPARE(ref.count("", Qt::CaseInsensitive), 16); -} - -void tst_QStringRef::contains() -{ - const QString a = QString::fromLatin1("ABCDEFGHIEfGEFG"); // 15 chars - CREATE_REF(a); - QVERIFY(ref.contains('A')); - QVERIFY(!ref.contains('Z')); - QVERIFY(ref.contains('E')); - QVERIFY(ref.contains('F')); - QVERIFY(ref.contains('F',Qt::CaseInsensitive)); - QVERIFY(ref.contains("FG")); - QVERIFY(ref.contains(QString("FG").midRef(0))); - const QString ref2 = QString::fromLatin1(" FG "); - QVERIFY(ref.contains(ref2.midRef(1, 2),Qt::CaseInsensitive)); - QVERIFY(ref.contains(QString(), Qt::CaseInsensitive)); - QVERIFY(ref.contains("", Qt::CaseInsensitive)); // apparently -} - -void tst_QStringRef::startsWith() -{ - { - const QString a = QString::fromLatin1("AB"); - CREATE_REF(a); - QVERIFY(ref.startsWith("A")); - QVERIFY(ref.startsWith("AB")); - QVERIFY(!ref.startsWith("C")); - QVERIFY(!ref.startsWith("ABCDEF")); - QVERIFY(ref.startsWith("")); - QVERIFY(ref.startsWith(QString())); - QVERIFY(ref.startsWith('A')); - QVERIFY(ref.startsWith(QLatin1Char('A'))); - QVERIFY(ref.startsWith(QChar('A'))); - QVERIFY(!ref.startsWith('C')); - QVERIFY(!ref.startsWith(QChar())); - QVERIFY(!ref.startsWith(QLatin1Char(0))); - - QVERIFY(ref.startsWith(QLatin1String("A"))); - QVERIFY(ref.startsWith(QLatin1String("AB"))); - QVERIFY(!ref.startsWith(QLatin1String("C"))); - QVERIFY(!ref.startsWith(QLatin1String("ABCDEF"))); - QVERIFY(ref.startsWith(QLatin1String(""))); - QVERIFY(ref.startsWith(QLatin1String(0))); - - QVERIFY(ref.startsWith("A", Qt::CaseSensitive)); - QVERIFY(ref.startsWith("A", Qt::CaseInsensitive)); - QVERIFY(!ref.startsWith("a", Qt::CaseSensitive)); - QVERIFY(ref.startsWith("a", Qt::CaseInsensitive)); - QVERIFY(!ref.startsWith("aB", Qt::CaseSensitive)); - QVERIFY(ref.startsWith("aB", Qt::CaseInsensitive)); - QVERIFY(!ref.startsWith("C", Qt::CaseSensitive)); - QVERIFY(!ref.startsWith("C", Qt::CaseInsensitive)); - QVERIFY(!ref.startsWith("c", Qt::CaseSensitive)); - QVERIFY(!ref.startsWith("c", Qt::CaseInsensitive)); - QVERIFY(!ref.startsWith("abcdef", Qt::CaseInsensitive)); - QVERIFY(ref.startsWith("", Qt::CaseInsensitive)); - QVERIFY(ref.startsWith(QString(), Qt::CaseInsensitive)); - QVERIFY(ref.startsWith('a', Qt::CaseInsensitive)); - QVERIFY(ref.startsWith('A', Qt::CaseInsensitive)); - QVERIFY(ref.startsWith(QLatin1Char('a'), Qt::CaseInsensitive)); - QVERIFY(ref.startsWith(QChar('a'), Qt::CaseInsensitive)); - QVERIFY(!ref.startsWith('c', Qt::CaseInsensitive)); - QVERIFY(!ref.startsWith(QChar(), Qt::CaseInsensitive)); - QVERIFY(!ref.startsWith(QLatin1Char(0), Qt::CaseInsensitive)); - - QVERIFY(ref.startsWith(QLatin1String("A"), Qt::CaseSensitive)); - QVERIFY(ref.startsWith(QLatin1String("A"), Qt::CaseInsensitive)); - QVERIFY(!ref.startsWith(QLatin1String("a"), Qt::CaseSensitive)); - QVERIFY(ref.startsWith(QLatin1String("a"), Qt::CaseInsensitive)); - QVERIFY(!ref.startsWith(QLatin1String("aB"), Qt::CaseSensitive)); - QVERIFY(ref.startsWith(QLatin1String("aB"), Qt::CaseInsensitive)); - QVERIFY(!ref.startsWith(QLatin1String("C"), Qt::CaseSensitive)); - QVERIFY(!ref.startsWith(QLatin1String("C"), Qt::CaseInsensitive)); - QVERIFY(!ref.startsWith(QLatin1String("c"), Qt::CaseSensitive)); - QVERIFY(!ref.startsWith(QLatin1String("c"), Qt::CaseInsensitive)); - QVERIFY(!ref.startsWith(QLatin1String("abcdef"), Qt::CaseInsensitive)); - QVERIFY(ref.startsWith(QLatin1String(""), Qt::CaseInsensitive)); - QVERIFY(ref.startsWith(QLatin1String(0), Qt::CaseInsensitive)); - QVERIFY(ref.startsWith('A', Qt::CaseSensitive)); - QVERIFY(ref.startsWith(QLatin1Char('A'), Qt::CaseSensitive)); - QVERIFY(ref.startsWith(QChar('A'), Qt::CaseSensitive)); - QVERIFY(!ref.startsWith('a', Qt::CaseSensitive)); - QVERIFY(!ref.startsWith(QChar(), Qt::CaseSensitive)); - QVERIFY(!ref.startsWith(QLatin1Char(0), Qt::CaseSensitive)); - } - { - const QString a = QString::fromLatin1(""); - CREATE_REF(a); - QVERIFY(ref.startsWith("")); - QVERIFY(ref.startsWith(QString())); - QVERIFY(!ref.startsWith("ABC")); - - QVERIFY(ref.startsWith(QLatin1String(""))); - QVERIFY(ref.startsWith(QLatin1String(0))); - QVERIFY(!ref.startsWith(QLatin1String("ABC"))); - - QVERIFY(!ref.startsWith(QLatin1Char(0))); - QVERIFY(!ref.startsWith(QLatin1Char('x'))); - QVERIFY(!ref.startsWith(QChar())); - } - { - const QStringRef ref; - QVERIFY(!ref.startsWith("")); - QVERIFY(ref.startsWith(QString())); - QVERIFY(!ref.startsWith("ABC")); - - QVERIFY(!ref.startsWith(QLatin1String(""))); - QVERIFY(ref.startsWith(QLatin1String(0))); - QVERIFY(!ref.startsWith(QLatin1String("ABC"))); - - QVERIFY(!ref.startsWith(QLatin1Char(0))); - QVERIFY(!ref.startsWith(QLatin1Char('x'))); - QVERIFY(!ref.startsWith(QChar())); - } -} - -void tst_QStringRef::endsWith() -{ - { - const QString a = QString::fromLatin1("AB"); - CREATE_REF(a); - QVERIFY(ref.endsWith("B")); - QVERIFY(ref.endsWith("AB")); - QVERIFY(!ref.endsWith("C")); - QVERIFY(!ref.endsWith("ABCDEF")); - QVERIFY(ref.endsWith("")); - QVERIFY(ref.endsWith(QString())); - QVERIFY(ref.endsWith('B')); - QVERIFY(ref.endsWith(QLatin1Char('B'))); - QVERIFY(ref.endsWith(QChar('B'))); - QVERIFY(!ref.endsWith('C')); - QVERIFY(!ref.endsWith(QChar())); - QVERIFY(!ref.endsWith(QLatin1Char(0))); - - QVERIFY(ref.endsWith(QLatin1String("B"))); - QVERIFY(ref.endsWith(QLatin1String("AB"))); - QVERIFY(!ref.endsWith(QLatin1String("C"))); - QVERIFY(!ref.endsWith(QLatin1String("ABCDEF"))); - QVERIFY(ref.endsWith(QLatin1String(""))); - QVERIFY(ref.endsWith(QLatin1String(0))); - - QVERIFY(ref.endsWith("B", Qt::CaseSensitive)); - QVERIFY(ref.endsWith("B", Qt::CaseInsensitive)); - QVERIFY(!ref.endsWith("b", Qt::CaseSensitive)); - QVERIFY(ref.endsWith("b", Qt::CaseInsensitive)); - QVERIFY(!ref.endsWith("aB", Qt::CaseSensitive)); - QVERIFY(ref.endsWith("aB", Qt::CaseInsensitive)); - QVERIFY(!ref.endsWith("C", Qt::CaseSensitive)); - QVERIFY(!ref.endsWith("C", Qt::CaseInsensitive)); - QVERIFY(!ref.endsWith("c", Qt::CaseSensitive)); - QVERIFY(!ref.endsWith("c", Qt::CaseInsensitive)); - QVERIFY(!ref.endsWith("abcdef", Qt::CaseInsensitive)); - QVERIFY(ref.endsWith("", Qt::CaseInsensitive)); - QVERIFY(ref.endsWith(QString(), Qt::CaseInsensitive)); - QVERIFY(ref.endsWith('b', Qt::CaseInsensitive)); - QVERIFY(ref.endsWith('B', Qt::CaseInsensitive)); - QVERIFY(ref.endsWith(QLatin1Char('b'), Qt::CaseInsensitive)); - QVERIFY(ref.endsWith(QChar('b'), Qt::CaseInsensitive)); - QVERIFY(!ref.endsWith('c', Qt::CaseInsensitive)); - QVERIFY(!ref.endsWith(QChar(), Qt::CaseInsensitive)); - QVERIFY(!ref.endsWith(QLatin1Char(0), Qt::CaseInsensitive)); - - QVERIFY(ref.endsWith(QLatin1String("B"), Qt::CaseSensitive)); - QVERIFY(ref.endsWith(QLatin1String("B"), Qt::CaseInsensitive)); - QVERIFY(!ref.endsWith(QLatin1String("b"), Qt::CaseSensitive)); - QVERIFY(ref.endsWith(QLatin1String("b"), Qt::CaseInsensitive)); - QVERIFY(!ref.endsWith(QLatin1String("aB"), Qt::CaseSensitive)); - QVERIFY(ref.endsWith(QLatin1String("aB"), Qt::CaseInsensitive)); - QVERIFY(!ref.endsWith(QLatin1String("C"), Qt::CaseSensitive)); - QVERIFY(!ref.endsWith(QLatin1String("C"), Qt::CaseInsensitive)); - QVERIFY(!ref.endsWith(QLatin1String("c"), Qt::CaseSensitive)); - QVERIFY(!ref.endsWith(QLatin1String("c"), Qt::CaseInsensitive)); - QVERIFY(!ref.endsWith(QLatin1String("abcdef"), Qt::CaseInsensitive)); - QVERIFY(ref.endsWith(QLatin1String(""), Qt::CaseInsensitive)); - QVERIFY(ref.endsWith(QLatin1String(0), Qt::CaseInsensitive)); - QVERIFY(ref.endsWith('B', Qt::CaseSensitive)); - QVERIFY(ref.endsWith(QLatin1Char('B'), Qt::CaseSensitive)); - QVERIFY(ref.endsWith(QChar('B'), Qt::CaseSensitive)); - QVERIFY(!ref.endsWith('b', Qt::CaseSensitive)); - QVERIFY(!ref.endsWith(QChar(), Qt::CaseSensitive)); - QVERIFY(!ref.endsWith(QLatin1Char(0), Qt::CaseSensitive)); - - } - { - const QString a = QString::fromLatin1(""); - CREATE_REF(a); - QVERIFY(ref.endsWith("")); - QVERIFY(ref.endsWith(QString())); - QVERIFY(!ref.endsWith("ABC")); - QVERIFY(!ref.endsWith(QLatin1Char(0))); - QVERIFY(!ref.endsWith(QLatin1Char('x'))); - QVERIFY(!ref.endsWith(QChar())); - - QVERIFY(ref.endsWith(QLatin1String(""))); - QVERIFY(ref.endsWith(QLatin1String(0))); - QVERIFY(!ref.endsWith(QLatin1String("ABC"))); - } - - { - QStringRef ref; - QVERIFY(!ref.endsWith("")); - QVERIFY(ref.endsWith(QString())); - QVERIFY(!ref.endsWith("ABC")); - - QVERIFY(!ref.endsWith(QLatin1String(""))); - QVERIFY(ref.endsWith(QLatin1String(0))); - QVERIFY(!ref.endsWith(QLatin1String("ABC"))); - - QVERIFY(!ref.endsWith(QLatin1Char(0))); - QVERIFY(!ref.endsWith(QLatin1Char('x'))); - QVERIFY(!ref.endsWith(QChar())); - } -} - -void tst_QStringRef::operator_eqeq_nullstring() -{ - /* Some of these might not be all that logical but it's the behaviour we've had since 3.0.0 - so we should probably stick with it. */ - - QVERIFY(QStringRef() == ""); - QVERIFY("" == QStringRef()); - - QVERIFY(QString("") == ""); - QVERIFY("" == QString("")); - - QVERIFY(QStringRef().size() == 0); - - QVERIFY(QString("").size() == 0); - - QVERIFY(QStringRef() == QString("")); - QVERIFY(QString("") == QString()); -} - -static inline int sign(int x) -{ - return x == 0 ? 0 : (x < 0 ? -1 : 1); -} - -void tst_QStringRef::compare_data() -{ - QTest::addColumn("s1"); - QTest::addColumn("s2"); - QTest::addColumn("csr"); // case sensitive result - QTest::addColumn("cir"); // case insensitive result - - - // null strings - QTest::newRow("data0") << QString("") << QString("") << 0 << 0; - QTest::newRow("data1") << QString("a") << QString("") << 1 << 1; - QTest::newRow("data2") << QString("") << QString("a") << -1 << -1; - - // equal length - QTest::newRow("data3") << QString("abc") << QString("abc") << 0 << 0; - QTest::newRow("data4") << QString("abC") << QString("abc") << -1 << 0; - QTest::newRow("data5") << QString("abc") << QString("abC") << 1 << 0; - QTest::newRow("data10") << QString("abcdefgh") << QString("abcdefgh") << 0 << 0; - QTest::newRow("data11") << QString("abcdefgh") << QString("abCdefgh") << 1 << 0; - QTest::newRow("data12") << QString("0123456789012345") << QString("0123456789012345") << 0 << 0; - QTest::newRow("data13") << QString("0123556789012345") << QString("0123456789012345") << 1 << 1; - - // different length - QTest::newRow("data6") << QString("abcdef") << QString("abc") << 1 << 1; - QTest::newRow("data7") << QString("abCdef") << QString("abc") << -1 << 1; - QTest::newRow("data8") << QString("abc") << QString("abcdef") << -1 << -1; - QTest::newRow("data14") << QString("abcdefgh") << QString("abcdefghi") << -1 << -1; - QTest::newRow("data15") << QString("01234567890123456") << QString("0123456789012345") << 1 << 1; - - QString upper; - upper += QChar(QChar::highSurrogate(0x10400)); - upper += QChar(QChar::lowSurrogate(0x10400)); - QString lower; - lower += QChar(QChar::highSurrogate(0x10428)); - lower += QChar(QChar::lowSurrogate(0x10428)); - QTest::newRow("data9") << upper << lower << -1 << 0; -} - -static bool isLatin(const QString &s) -{ - for (int i = 0; i < s.length(); ++i) - if (s.at(i).unicode() > 0xff) - return false; - return true; -} - -void tst_QStringRef::compare() -{ - QFETCH(QString, s1); - QFETCH(QString, s2); - QFETCH(int, csr); - QFETCH(int, cir); - - QStringRef r1(&s1, 0, s1.length()); - QStringRef r2(&s2, 0, s2.length()); - - QCOMPARE(sign(QString::compare(s1, s2)), csr); - QCOMPARE(sign(QStringRef::compare(r1, r2)), csr); - QCOMPARE(sign(s1.compare(s2)), csr); - QCOMPARE(sign(s1.compare(r2)), csr); - QCOMPARE(sign(r1.compare(r2)), csr); - - QCOMPARE(sign(s1.compare(s2, Qt::CaseSensitive)), csr); - QCOMPARE(sign(s1.compare(s2, Qt::CaseInsensitive)), cir); - QCOMPARE(sign(s1.compare(r2, Qt::CaseSensitive)), csr); - QCOMPARE(sign(s1.compare(r2, Qt::CaseInsensitive)), cir); - QCOMPARE(sign(r1.compare(r2, Qt::CaseSensitive)), csr); - QCOMPARE(sign(r1.compare(r2, Qt::CaseInsensitive)), cir); - - QCOMPARE(sign(QString::compare(s1, s2, Qt::CaseSensitive)), csr); - QCOMPARE(sign(QString::compare(s1, s2, Qt::CaseInsensitive)), cir); - QCOMPARE(sign(QString::compare(s1, r2, Qt::CaseSensitive)), csr); - QCOMPARE(sign(QString::compare(s1, r2, Qt::CaseInsensitive)), cir); - QCOMPARE(sign(QStringRef::compare(r1, r2, Qt::CaseSensitive)), csr); - QCOMPARE(sign(QStringRef::compare(r1, r2, Qt::CaseInsensitive)), cir); - - if (!cir) { - QCOMPARE(s1.toCaseFolded(), s2.toCaseFolded()); - } - - if (isLatin(s2)) { - QCOMPARE(sign(QString::compare(s1, QLatin1String(s2.toLatin1()))), csr); - QCOMPARE(sign(QString::compare(s1, QLatin1String(s2.toLatin1()), Qt::CaseInsensitive)), cir); - QCOMPARE(sign(QStringRef::compare(r1, QLatin1String(s2.toLatin1()))), csr); - QCOMPARE(sign(QStringRef::compare(r1, QLatin1String(s2.toLatin1()), Qt::CaseInsensitive)), cir); - } - - if (isLatin(s1)) { - QCOMPARE(sign(QString::compare(QLatin1String(s1.toLatin1()), s2)), csr); - QCOMPARE(sign(QString::compare(QLatin1String(s1.toLatin1()), s2, Qt::CaseInsensitive)), cir); - } -} - -void tst_QStringRef::compare2_data() -{ - compare_data(); -} - -void tst_QStringRef::compare2() -{ - QFETCH(QString, s1); - QFETCH(QString, s2); - QFETCH(int, csr); - QFETCH(int, cir); - - // prepend and append data - // we only use Latin1 here so isLatin1 still results true - s1.prepend("xyz").append("zyx"); - s2.prepend("foobar").append("raboof"); - - QStringRef r1(&s1, 3, s1.length() - 6); - QStringRef r2(&s2, 6, s2.length() - 12); - - QCOMPARE(sign(QStringRef::compare(r1, r2)), csr); - QCOMPARE(sign(r1.compare(r2)), csr); - - QCOMPARE(sign(r1.compare(r2, Qt::CaseSensitive)), csr); - QCOMPARE(sign(r1.compare(r2, Qt::CaseInsensitive)), cir); - - QCOMPARE(sign(QStringRef::compare(r1, r2, Qt::CaseSensitive)), csr); - QCOMPARE(sign(QStringRef::compare(r1, r2, Qt::CaseInsensitive)), cir); - - if (isLatin(s2)) { - QCOMPARE(sign(QStringRef::compare(r1, QLatin1String(r2.toLatin1()))), csr); - QCOMPARE(sign(QStringRef::compare(r1, QLatin1String(r2.toLatin1()), Qt::CaseInsensitive)), cir); - } - - if (isLatin(s1)) { - QCOMPARE(sign(QStringRef::compare(r2, QLatin1String(r1.toLatin1()))), -csr); - QCOMPARE(sign(QStringRef::compare(r2, QLatin1String(r1.toLatin1()), Qt::CaseInsensitive)), -cir); - } -} - -void tst_QStringRef::toNum() -{ -#define TEST_TO_INT(num, func, type) \ - a = #num; \ - b = a.leftRef(-1); \ - QCOMPARE(b.func(&ok), type(Q_INT64_C(num))); \ - QVERIFY2(ok, "Failed: num=" #num); - - QString a; - QStringRef b; - bool ok = false; - - TEST_TO_INT(0, toInt, int) - TEST_TO_INT(-1, toInt, int) - TEST_TO_INT(1, toInt, int) - TEST_TO_INT(2147483647, toInt, int) - TEST_TO_INT(-2147483648, toInt, int) - - TEST_TO_INT(0, toShort, short) - TEST_TO_INT(-1, toShort, short) - TEST_TO_INT(1, toShort, short) - TEST_TO_INT(32767, toShort, short) - TEST_TO_INT(-32768, toShort, short) - - TEST_TO_INT(0, toLong, long) - TEST_TO_INT(-1, toLong, long) - TEST_TO_INT(1, toLong, long) - TEST_TO_INT(2147483647, toLong, long) - TEST_TO_INT(-2147483648, toLong, long) - TEST_TO_INT(0, toLongLong, (long long)) - TEST_TO_INT(-1, toLongLong, (long long)) - TEST_TO_INT(1, toLongLong, (long long)) - TEST_TO_INT(9223372036854775807, toLongLong, (long long)) - TEST_TO_INT(-9223372036854775807, toLongLong, (long long)) - -#undef TEST_TO_INT - -#define TEST_TO_UINT(num, func, type) \ - a = #num; \ - b = a.leftRef(-1); \ - QCOMPARE(b.func(&ok), type(Q_UINT64_C(num))); \ - QVERIFY2(ok, "Failed: num=" #num); - - TEST_TO_UINT(0, toUInt, (unsigned int)) - TEST_TO_UINT(1, toUInt, (unsigned int)) - TEST_TO_UINT(4294967295, toUInt, (unsigned int)) - - TEST_TO_UINT(0, toUShort, (unsigned short)) - TEST_TO_UINT(1, toUShort, (unsigned short)) - TEST_TO_UINT(65535, toUShort, (unsigned short)) - - TEST_TO_UINT(0, toULong, (unsigned long)) - TEST_TO_UINT(1, toULong, (unsigned long)) - TEST_TO_UINT(4294967295, toULong, (unsigned long)) - - TEST_TO_UINT(0, toULongLong, (unsigned long long)) - TEST_TO_UINT(1, toULongLong, (unsigned long long)) - TEST_TO_UINT(18446744073709551615, toULongLong, (unsigned long long)) - -#undef TEST_TO_UINT - -#define TEST_BASE(str, base, num) \ - a = str; \ - b = a.leftRef(-1); \ - QCOMPARE(b.toInt(&ok,base), int(num)); \ - QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toInt"); \ - QCOMPARE(b.toUInt(&ok, base), (unsigned int)(num)); \ - QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toUInt"); \ - QCOMPARE(b.toShort(&ok, base), short(num)); \ - QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toShort"); \ - QCOMPARE(b.toUShort(&ok, base), (unsigned short)(num)); \ - QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toUShort"); \ - QCOMPARE(b.toLong(&ok, base), long(num)); \ - QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toLong"); \ - QCOMPARE(b.toULong(&ok, base), (unsigned long)(num)); \ - QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toULong"); \ - QCOMPARE(b.toLongLong(&ok, base), (long long)(num)); \ - QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toLongLong"); \ - QCOMPARE(b.toULongLong(&ok, base), (unsigned long long)(num)); \ - QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toULongLong"); - - TEST_BASE("FF", 16, 255) - TEST_BASE("0xFF", 16, 255) - TEST_BASE("77", 8, 63) - TEST_BASE("077", 8, 63) - - TEST_BASE("0xFF", 0, 255) - TEST_BASE("077", 0, 63) - TEST_BASE("255", 0, 255) - - TEST_BASE(" FF", 16, 255) - TEST_BASE(" 0xFF", 16, 255) - TEST_BASE(" 77", 8, 63) - TEST_BASE(" 077", 8, 63) - - TEST_BASE(" 0xFF", 0, 255) - TEST_BASE(" 077", 0, 63) - TEST_BASE(" 255", 0, 255) - - TEST_BASE("\tFF\t", 16, 255) - TEST_BASE("\t0xFF ", 16, 255) - TEST_BASE(" 77 ", 8, 63) - TEST_BASE("77 ", 8, 63) - -#undef TEST_BASE - -#define TEST_NEG_BASE(str, base, num) \ - a = str; \ - b = a.leftRef(-1); \ - QCOMPARE(b.toInt(&ok, base), int(num)); \ - QVERIFY2(ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toInt"); \ - QCOMPARE(b.toShort(&ok,base), short(num)); \ - QVERIFY2(ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toShort"); \ - QCOMPARE(b.toLong(&ok, base), long(num)); \ - QVERIFY2(ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toLong"); \ - QCOMPARE(b.toLongLong(&ok, base), (long long)(num)); \ - QVERIFY2(ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toLongLong"); - - TEST_NEG_BASE("-FE", 16, -254) - TEST_NEG_BASE("-0xFE", 16, -254) - TEST_NEG_BASE("-77", 8, -63) - TEST_NEG_BASE("-077", 8, -63) - - TEST_NEG_BASE("-0xFE", 0, -254) - TEST_NEG_BASE("-077", 0, -63) - TEST_NEG_BASE("-254", 0, -254) - -#undef TEST_NEG_BASE - -#define TEST_DOUBLE(num, str) \ - a = str; \ - b = a.leftRef(-1); \ - QCOMPARE(b.toDouble(&ok), num); \ - QVERIFY(ok); - - TEST_DOUBLE(1.2345, "1.2345") - TEST_DOUBLE(12.345, "1.2345e+01") - TEST_DOUBLE(12.345, "1.2345E+01") - TEST_DOUBLE(12345.6, "12345.6") - -#undef TEST_DOUBLE - -#define TEST_BAD(str, func) \ - a = str; \ - b = a.leftRef(-1); \ - b.func(&ok); \ - QVERIFY2(!ok, "Failed: str=" #str " func=" #func); - - TEST_BAD("32768", toShort) - TEST_BAD("-32769", toShort) - TEST_BAD("65536", toUShort) - TEST_BAD("2147483648", toInt) - TEST_BAD("-2147483649", toInt) - TEST_BAD("4294967296", toUInt) - if (sizeof(long) == 4) { - TEST_BAD("2147483648", toLong) - TEST_BAD("-2147483649", toLong) - TEST_BAD("4294967296", toULong) - } - TEST_BAD("9223372036854775808", toLongLong) - TEST_BAD("-9223372036854775809", toLongLong) - TEST_BAD("18446744073709551616", toULongLong) - TEST_BAD("-1", toUShort) - TEST_BAD("-1", toUInt) - TEST_BAD("-1", toULong) - TEST_BAD("-1", toULongLong) - -#undef TEST_BAD - -#define TEST_BAD_ALL(str) \ - a = str; \ - b = a.leftRef(-1); \ - b.toShort(&ok); \ - QVERIFY2(!ok, "Failed: str=" #str); \ - b.toUShort(&ok); \ - QVERIFY2(!ok, "Failed: str=" #str); \ - b.toInt(&ok); \ - QVERIFY2(!ok, "Failed: str=" #str); \ - b.toUInt(&ok); \ - QVERIFY2(!ok, "Failed: str=" #str); \ - b.toLong(&ok); \ - QVERIFY2(!ok, "Failed: str=" #str); \ - b.toULong(&ok); \ - QVERIFY2(!ok, "Failed: str=" #str); \ - b.toLongLong(&ok); \ - QVERIFY2(!ok, "Failed: str=" #str); \ - b.toULongLong(&ok); \ - QVERIFY2(!ok, "Failed: str=" #str); \ - b.toFloat(&ok); \ - QVERIFY2(!ok, "Failed: str=" #str); \ - b.toDouble(&ok); \ - QVERIFY2(!ok, "Failed: str=" #str); - - TEST_BAD_ALL((const char*)0); - TEST_BAD_ALL(""); - TEST_BAD_ALL(" "); - TEST_BAD_ALL("."); - TEST_BAD_ALL("-"); - TEST_BAD_ALL("hello"); - TEST_BAD_ALL("1.2.3"); - TEST_BAD_ALL("0x0x0x"); - TEST_BAD_ALL("123-^~<"); - TEST_BAD_ALL("123ThisIsNotANumber"); - -#undef TEST_BAD_ALL - - a = "FF"; - b = a.leftRef(-1); - b.toULongLong(&ok, 10); - QVERIFY(!ok); - - a = "FF"; - b = a.leftRef(-1); - b.toULongLong(&ok, 0); - QVERIFY(!ok); - -#ifdef QT_NO_FPU - double d = 3.40282346638528e+38; // slightly off FLT_MAX when using hardfloats -#else - double d = 3.4028234663852886e+38; // FLT_MAX -#endif - QString::number(d, 'e', 17).leftRef(-1).toFloat(&ok); - QVERIFY(ok); - QString::number(d + 1e32, 'e', 17).leftRef(-1).toFloat(&ok); - QVERIFY(!ok); - QString::number(-d, 'e', 17).leftRef(-1).toFloat(&ok); - QVERIFY(ok); - QString::number(-d - 1e32, 'e', 17).leftRef(-1).toFloat(&ok); - QVERIFY(!ok); - QString::number(d + 1e32, 'e', 17).leftRef(-1).toDouble(&ok); - QVERIFY(ok); - QString::number(-d - 1e32, 'e', 17).leftRef(-1).toDouble(&ok); - QVERIFY(ok); -} - -void tst_QStringRef::toUShort() -{ - QString a; - QStringRef b; - bool ok; - QCOMPARE(b.toUShort(), ushort(0)); - QCOMPARE(b.toUShort(&ok), ushort(0)); - QVERIFY(!ok); - - a = ""; - b = a.leftRef(-1); - QCOMPARE(b.toUShort(), ushort(0)); - QCOMPARE(b.toUShort(&ok), ushort(0)); - QVERIFY(!ok); - - a = "COMPARE"; - b = a.leftRef(-1); - QCOMPARE(b.toUShort(), ushort(0)); - QCOMPARE(b.toUShort(&ok), ushort(0)); - QVERIFY(!ok); - - a = "123"; - b = a.leftRef(-1); - QCOMPARE(b.toUShort(), ushort(123)); - QCOMPARE(b.toUShort(&ok), ushort(123)); - QVERIFY(ok); - - a = "123A"; - b = a.leftRef(-1); - QCOMPARE(b.toUShort(), ushort(0)); - QCOMPARE(b.toUShort(&ok), ushort(0)); - QVERIFY(!ok); - - a = "1234567"; - b = a.leftRef(-1); - QCOMPARE(b.toUShort(), ushort(0)); - QCOMPARE(b.toUShort(&ok), ushort(0)); - QVERIFY(!ok); - - a = "aaa123aaa"; - b = a.leftRef(-1); - QCOMPARE(b.toUShort(), ushort(0)); - QCOMPARE(b.toUShort(&ok), ushort(0)); - QVERIFY(!ok); - - a = "aaa123"; - b = a.leftRef(-1); - QCOMPARE(b.toUShort(), ushort(0)); - QCOMPARE(b.toUShort(&ok), ushort(0)); - QVERIFY(!ok); - - a = "123aaa"; - b = a.leftRef(-1); - QCOMPARE(b.toUShort(), ushort(0)); - QCOMPARE(b.toUShort(&ok), ushort(0)); - QVERIFY(!ok); - - a = "32767"; - b = a.leftRef(-1); - QCOMPARE(b.toUShort(), ushort(32767)); - QCOMPARE(b.toUShort(&ok), ushort(32767)); - QVERIFY(ok); - - a = "-32767"; - b = a.leftRef(-1); - QCOMPARE(b.toUShort(), ushort(0)); - QCOMPARE(b.toUShort(&ok), ushort(0)); - QVERIFY(!ok); - - a = "65535"; - b = a.leftRef(-1); - QCOMPARE(b.toUShort(), ushort(65535)); - QCOMPARE(b.toUShort(&ok), ushort(65535)); - QVERIFY(ok); - - if (sizeof(short) == 2) { - a = "65536"; - b = a.leftRef(-1); - QCOMPARE(b.toUShort(), ushort(0)); - QCOMPARE(b.toUShort(&ok), ushort(0)); - QVERIFY(!ok); - - a = "123456"; - b = a.leftRef(-1); - QCOMPARE(b.toUShort(), ushort(0)); - QCOMPARE(b.toUShort(&ok), ushort(0)); - QVERIFY(!ok); - } -} - -void tst_QStringRef::toShort() -{ - QString a; - QStringRef b; - bool ok; - QCOMPARE(b.toShort(), short(0)); - QCOMPARE(b.toShort(&ok), short(0)); - QVERIFY(!ok); - - a = ""; - b = a.leftRef(-1); - QCOMPARE(b.toShort(), short(0)); - QCOMPARE(b.toShort(&ok), short(0)); - QVERIFY(!ok); - - a = "COMPARE"; - b = a.leftRef(-1); - QCOMPARE(b.toShort(), short(0)); - QCOMPARE(b.toShort(&ok), short(0)); - QVERIFY(!ok); - - a = "123"; - b = a.leftRef(-1); - QCOMPARE(b.toShort(), short(123)); - QCOMPARE(b.toShort(&ok), short(123)); - QVERIFY(ok); - - a = "123A"; - b = a.leftRef(-1); - QCOMPARE(b.toShort(), short(0)); - QCOMPARE(b.toShort(&ok), short(0)); - QVERIFY(!ok); - - a = "1234567"; - b = a.leftRef(-1); - QCOMPARE(b.toShort(), short(0)); - QCOMPARE(b.toShort(&ok), short(0)); - QVERIFY(!ok); - - a = "aaa123aaa"; - b = a.leftRef(-1); - QCOMPARE(b.toShort(), short(0)); - QCOMPARE(b.toShort(&ok), short(0)); - QVERIFY(!ok); - - a = "aaa123"; - b = a.leftRef(-1); - QCOMPARE(b.toShort(), short(0)); - QCOMPARE(b.toShort(&ok), short(0)); - QVERIFY(!ok); - - a = "123aaa"; - b = a.leftRef(-1); - QCOMPARE(b.toShort(), short(0)); - QCOMPARE(b.toShort(&ok), short(0)); - QVERIFY(!ok); - - a = "32767"; - b = a.leftRef(-1); - QCOMPARE(b.toShort(), short(32767)); - QCOMPARE(b.toShort(&ok), short(32767)); - QVERIFY(ok); - - a = "-32767"; - b = a.leftRef(-1); - QCOMPARE(b.toShort(), short(-32767)); - QCOMPARE(b.toShort(&ok), short(-32767)); - QVERIFY(ok); - - a = "-32768"; - b = a.leftRef(-1); - QCOMPARE(b.toShort(), short(-32768)); - QCOMPARE(b.toShort(&ok), short(-32768)); - QVERIFY(ok); - - if (sizeof(short) == 2) { - a = "32768"; - b = a.leftRef(-1); - QCOMPARE(b.toShort(), short(0)); - QCOMPARE(b.toShort(&ok), short(0)); - QVERIFY(!ok); - - a = "-32769"; - b = a.leftRef(-1); - QCOMPARE(b.toShort(), short(0)); - QCOMPARE(b.toShort(&ok), short(0)); - QVERIFY(!ok); - } -} - -void tst_QStringRef::toInt() -{ - QString a; - QStringRef b; - bool ok; - QCOMPARE(b.toInt(), 0); - QCOMPARE(b.toInt(&ok), 0); - QVERIFY(!ok); - - a = ""; - b = a.leftRef(-1); - QCOMPARE(b.toInt(), 0); - QCOMPARE(b.toInt(&ok), 0); - QVERIFY(!ok); - - a = "COMPARE"; - b = a.leftRef(-1); - QCOMPARE(b.toInt(), 0); - QCOMPARE(b.toInt(&ok), 0); - QVERIFY(!ok); - - a = "123"; - b = a.leftRef(-1); - QCOMPARE(b.toInt(), 123); - QCOMPARE(b.toInt(&ok), 123); - QVERIFY(ok); - - a = "123A"; - b = a.leftRef(-1); - QCOMPARE(b.toInt(), 0); - QCOMPARE(b.toInt(&ok), 0); - QVERIFY(!ok); - - a = "1234567"; - b = a.leftRef(-1); - QCOMPARE(b.toInt(), 1234567); - QCOMPARE(b.toInt(&ok), 1234567); - QVERIFY(ok); - - a = "12345678901234"; - b = a.leftRef(-1); - QCOMPARE(b.toInt(), 0); - QCOMPARE(b.toInt(&ok), 0); - QVERIFY(!ok); - - a = "3234567890"; - b = a.leftRef(-1); - QCOMPARE(b.toInt(), 0); - QCOMPARE(b.toInt(&ok), 0); - QVERIFY(!ok); - - a = "aaa12345aaa"; - b = a.leftRef(-1); - QCOMPARE(b.toInt(), 0); - QCOMPARE(b.toInt(&ok), 0); - QVERIFY(!ok); - - a = "aaa12345"; - b = a.leftRef(-1); - QCOMPARE(b.toInt(), 0); - QCOMPARE(b.toInt(&ok), 0); - QVERIFY(!ok); - - a = "12345aaa"; - b = a.leftRef(-1); - QCOMPARE(b.toInt(), 0); - QCOMPARE(b.toInt(&ok), 0); - QVERIFY(!ok); - - a = "2147483647"; // 2**31 - 1 - b = a.leftRef(-1); - QCOMPARE(b.toInt(), 2147483647); - QCOMPARE(b.toInt(&ok), 2147483647); - QVERIFY(ok); - - if (sizeof(int) == 4) { - a = "-2147483647"; // -(2**31 - 1) - b = a.leftRef(-1); - QCOMPARE(b.toInt(), -2147483647); - QCOMPARE(b.toInt(&ok), -2147483647); - QVERIFY(ok); - - a = "2147483648"; // 2**31 - b = a.leftRef(-1); - QCOMPARE(b.toInt(), 0); - QCOMPARE(b.toInt(&ok), 0); - QVERIFY(!ok); - - a = "-2147483648"; // -2**31 - b = a.leftRef(-1); - QCOMPARE(b.toInt(), -2147483647 - 1); - QCOMPARE(b.toInt(&ok), -2147483647 - 1); - QVERIFY(ok); - - a = "2147483649"; // 2**31 + 1 - b = a.leftRef(-1); - QCOMPARE(b.toInt(), 0); - QCOMPARE(b.toInt(&ok), 0); - QVERIFY(!ok); - } -} - -void tst_QStringRef::toUInt() -{ - bool ok; - QString a; - QStringRef b; - a = "3234567890"; - b = a.leftRef(-1); - QCOMPARE(b.toUInt(&ok), 3234567890u); - QVERIFY(ok); - - a = "-50"; - b = a.leftRef(-1); - QCOMPARE(b.toUInt(), 0u); - QCOMPARE(b.toUInt(&ok), 0u); - QVERIFY(!ok); - - a = "4294967295"; // 2**32 - 1 - b = a.leftRef(-1); - QCOMPARE(b.toUInt(), 4294967295u); - QCOMPARE(b.toUInt(&ok), 4294967295u); - QVERIFY(ok); - - if (sizeof(int) == 4) { - a = "4294967296"; // 2**32 - b = a.leftRef(-1); - QCOMPARE(b.toUInt(), 0u); - QCOMPARE(b.toUInt(&ok), 0u); - QVERIFY(!ok); - } -} - -///////////////////////////// to*Long ////////////////////////////////////// - -void tst_QStringRef::toULong_data() -{ - QTest::addColumn("str"); - QTest::addColumn("base"); - QTest::addColumn("result"); - QTest::addColumn("ok"); - - QTest::newRow("default") << QString() << 10 << 0UL << false; - QTest::newRow("empty") << QString("") << 10 << 0UL << false; - QTest::newRow("ulong1") << QString("3234567890") << 10 << 3234567890UL << true; - QTest::newRow("ulong2") << QString("fFFfFfFf") << 16 << 0xFFFFFFFFUL << true; -} - -void tst_QStringRef::toULong() -{ - QFETCH(QString, str); - QFETCH(int, base); - QFETCH(ulong, result); - QFETCH(bool, ok); - QStringRef strRef = str.leftRef(-1); - - bool b; - QCOMPARE(strRef.toULong(0, base), result); - QCOMPARE(strRef.toULong(&b, base), result); - QCOMPARE(b, ok); -} - -void tst_QStringRef::toLong_data() -{ - QTest::addColumn("str"); - QTest::addColumn("base"); - QTest::addColumn("result"); - QTest::addColumn("ok"); - - QTest::newRow("default") << QString() << 10 << 0L << false; - QTest::newRow("empty") << QString("") << 10 << 0L << false; - QTest::newRow("normal") << QString("7fFFfFFf") << 16 << 0x7fFFfFFfL << true; - QTest::newRow("long_max") << QString("2147483647") << 10 << 2147483647L << true; - if (sizeof(long) == 4) { - QTest::newRow("long_max+1") << QString("2147483648") << 10 << 0L << false; - QTest::newRow("long_min-1") << QString("-80000001") << 16 << 0L << false; - } - QTest::newRow("negative") << QString("-7fffffff") << 16 << -0x7fffffffL << true; -// QTest::newRow("long_min") << QString("-80000000") << 16 << 0x80000000uL << true; -} - -void tst_QStringRef::toLong() -{ - QFETCH(QString, str); - QFETCH(int, base); - QFETCH(long, result); - QFETCH(bool, ok); - QStringRef strRef = str.leftRef(-1); - - bool b; - QCOMPARE(strRef.toLong(0, base), result); - QCOMPARE(strRef.toLong(&b, base), result); - QCOMPARE(b, ok); -} - - -////////////////////////// to*LongLong ////////////////////////////////////// - -void tst_QStringRef::toULongLong() -{ - QString str; - QStringRef strRef; - bool ok; - str = "18446744073709551615"; // ULLONG_MAX - strRef = str.leftRef(-1); - QCOMPARE(strRef.toULongLong(0), Q_UINT64_C(18446744073709551615)); - QCOMPARE(strRef.toULongLong(&ok), Q_UINT64_C(18446744073709551615)); - QVERIFY(ok); - - str = "18446744073709551616"; // ULLONG_MAX + 1 - strRef = str.leftRef(-1); - QCOMPARE(strRef.toULongLong(0), Q_UINT64_C(0)); - QCOMPARE(strRef.toULongLong(&ok), Q_UINT64_C(0)); - QVERIFY(!ok); - - str = "-150"; - strRef = str.leftRef(-1); - QCOMPARE(strRef.toULongLong(0), Q_UINT64_C(0)); - QCOMPARE(strRef.toULongLong(&ok), Q_UINT64_C(0)); - QVERIFY(!ok); -} - -void tst_QStringRef::toLongLong() -{ - QString str; - QStringRef strRef; - bool ok; - - str = "9223372036854775807"; // LLONG_MAX - strRef = str.leftRef(-1); - QCOMPARE(strRef.toLongLong(0), Q_INT64_C(9223372036854775807)); - QCOMPARE(strRef.toLongLong(&ok), Q_INT64_C(9223372036854775807)); - QVERIFY(ok); - - str = "-9223372036854775808"; // LLONG_MIN - strRef = str.leftRef(-1); - QCOMPARE(strRef.toLongLong(0), - -Q_INT64_C(9223372036854775807) - Q_INT64_C(1)); - QCOMPARE(strRef.toLongLong(&ok), - -Q_INT64_C(9223372036854775807) - Q_INT64_C(1)); - QVERIFY(ok); - - str = "aaaa9223372036854775807aaaa"; - strRef = str.leftRef(-1); - QCOMPARE(strRef.toLongLong(0), Q_INT64_C(0)); - QCOMPARE(strRef.toLongLong(&ok), Q_INT64_C(0)); - QVERIFY(!ok); - - str = "9223372036854775807aaaa"; - strRef = str.leftRef(-1); - QCOMPARE(strRef.toLongLong(0), Q_INT64_C(0)); - QCOMPARE(strRef.toLongLong(&ok), Q_INT64_C(0)); - QVERIFY(!ok); - - str = "aaaa9223372036854775807"; - strRef = str.leftRef(-1); - QCOMPARE(strRef.toLongLong(0), Q_INT64_C(0)); - QCOMPARE(strRef.toLongLong(&ok), Q_INT64_C(0)); - QVERIFY(!ok); - - static char digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - - for (int i = 0; i < 36; ++i) { - for (int j = 0; j < 36; ++j) { - for (int k = 0; k < 36; ++k) { - QString str; - str += QChar(digits[i]); - str += QChar(digits[j]); - str += QChar(digits[k]); - strRef = str.leftRef(-1); - qlonglong value = (((i * 36) + j) * 36) + k; - QVERIFY(strRef.toLongLong(0, 36) == value); - } - } - } -} - -//////////////////////////////////////////////////////////////////////////// - -void tst_QStringRef::toFloat() -{ - QString a; - QStringRef b; - bool ok; - a = "0.000000000931322574615478515625"; - b = a.leftRef(-1); - QCOMPARE(b.toFloat(&ok), float(0.000000000931322574615478515625)); - QVERIFY(ok); -} - -void tst_QStringRef::toDouble_data() -{ - QTest::addColumn("str"); - QTest::addColumn("result"); - QTest::addColumn("result_ok"); - - QTest::newRow("ok00") << QString("0.000000000931322574615478515625") << 0.000000000931322574615478515625 << true; - QTest::newRow("ok01") << QString(" 123.45") << 123.45 << true; - - QTest::newRow("ok02") << QString("0.1e10") << 0.1e10 << true; - QTest::newRow("ok03") << QString("0.1e-10") << 0.1e-10 << true; - - QTest::newRow("ok04") << QString("1e10") << 1.0e10 << true; - QTest::newRow("ok05") << QString("1e+10") << 1.0e10 << true; - QTest::newRow("ok06") << QString("1e-10") << 1.0e-10 << true; - - QTest::newRow("ok07") << QString(" 1e10") << 1.0e10 << true; - QTest::newRow("ok08") << QString(" 1e+10") << 1.0e10 << true; - QTest::newRow("ok09") << QString(" 1e-10") << 1.0e-10 << true; - - QTest::newRow("ok10") << QString("1.") << 1.0 << true; - QTest::newRow("ok11") << QString(".1") << 0.1 << true; - - QTest::newRow("wrong00") << QString("123.45 ") << 123.45 << true; - QTest::newRow("wrong01") << QString(" 123.45 ") << 123.45 << true; - - QTest::newRow("wrong02") << QString("aa123.45aa") << 0.0 << false; - QTest::newRow("wrong03") << QString("123.45aa") << 0.0 << false; - QTest::newRow("wrong04") << QString("123erf") << 0.0 << false; - - QTest::newRow("wrong05") << QString("abc") << 0.0 << false; - QTest::newRow("wrong06") << QString() << 0.0 << false; - QTest::newRow("wrong07") << QString("") << 0.0 << false; -} - -void tst_QStringRef::toDouble() -{ - QFETCH(QString, str); - QFETCH(bool, result_ok); - QStringRef strRef = str.leftRef(-1); - bool ok; - double d = strRef.toDouble(&ok); - if (result_ok) { - QTEST(d, "result"); - QVERIFY(ok); - } else { - QVERIFY(!ok); - } -} - -void tst_QStringRef::integer_conversion_data() -{ - QTest::addColumn("num_str"); - QTest::addColumn("base"); - QTest::addColumn("good"); - QTest::addColumn("num"); - - QTest::newRow("C empty 0") << QString("") << 0 << false << (qlonglong)0; - QTest::newRow("C empty 8") << QString("") << 8 << false << (qlonglong)0; - QTest::newRow("C empty 10") << QString("") << 10 << false << (qlonglong)0; - QTest::newRow("C empty 16") << QString("") << 16 << false << (qlonglong)0; - - QTest::newRow("C null 0") << QString() << 0 << false << (qlonglong)0; - QTest::newRow("C null 8") << QString() << 8 << false << (qlonglong)0; - QTest::newRow("C null 10") << QString() << 10 << false << (qlonglong)0; - QTest::newRow("C null 16") << QString() << 16 << false << (qlonglong)0; - - QTest::newRow("C -0xf 0") << QString(" -0xf") << 0 << true << (qlonglong)-15; - QTest::newRow("C -0xf 0") << QString("-0xf ") << 0 << true << (qlonglong)-15; - QTest::newRow("C \t0xf\t 0") << QString("\t0xf\t") << 0 << true << (qlonglong)15; - QTest::newRow("C -010 0") << QString(" -010") << 0 << true << (qlonglong)-8; - QTest::newRow("C 010 0") << QString("010 ") << 0 << true << (qlonglong)8; - QTest::newRow("C \t-010\t 0") << QString("\t-010\t") << 0 << true << (qlonglong)-8; - QTest::newRow("C 123 10") << QString(" 123") << 10 << true << (qlonglong)123; - QTest::newRow("C 123 10") << QString("123 ") << 10 << true << (qlonglong)123; - QTest::newRow("C \t123\t 10") << QString("\t123\t") << 10 << true << (qlonglong)123; - QTest::newRow("C -0xf 16") << QString(" -0xf") << 16 << true << (qlonglong)-15; - QTest::newRow("C -0xf 16") << QString("-0xf ") << 16 << true << (qlonglong)-15; - QTest::newRow("C \t0xf\t 16") << QString("\t0xf\t") << 16 << true << (qlonglong)15; - - QTest::newRow("C -0 0") << QString("-0") << 0 << true << (qlonglong)0; - QTest::newRow("C -0 8") << QString("-0") << 8 << true << (qlonglong)0; - QTest::newRow("C -0 10") << QString("-0") << 10 << true << (qlonglong)0; - QTest::newRow("C -0 16") << QString("-0") << 16 << true << (qlonglong)0; - - QTest::newRow("C 1.234 10") << QString("1.234") << 10 << false << (qlonglong)0; - QTest::newRow("C 1,234 10") << QString("1,234") << 10 << false << (qlonglong)0; - - QTest::newRow("C 0x 0") << QString("0x") << 0 << false << (qlonglong)0; - QTest::newRow("C 0x 16") << QString("0x") << 16 << false << (qlonglong)0; - - QTest::newRow("C 10 0") << QString("10") << 0 << true << (qlonglong)10; - QTest::newRow("C 010 0") << QString("010") << 0 << true << (qlonglong)8; - QTest::newRow("C 0x10 0") << QString("0x10") << 0 << true << (qlonglong)16; - QTest::newRow("C 10 8") << QString("10") << 8 << true << (qlonglong)8; - QTest::newRow("C 010 8") << QString("010") << 8 << true << (qlonglong)8; - QTest::newRow("C 0x10 8") << QString("0x10") << 8 << false << (qlonglong)0; - QTest::newRow("C 10 10") << QString("10") << 10 << true << (qlonglong)10; - QTest::newRow("C 010 10") << QString("010") << 10 << true << (qlonglong)10; - QTest::newRow("C 0x10 10") << QString("0x10") << 10 << false << (qlonglong)0; - QTest::newRow("C 10 16") << QString("10") << 16 << true << (qlonglong)16; - QTest::newRow("C 010 16") << QString("010") << 16 << true << (qlonglong)16; - QTest::newRow("C 0x10 16") << QString("0x10") << 16 << true << (qlonglong)16; - - QTest::newRow("C -10 0") << QString("-10") << 0 << true << (qlonglong)-10; - QTest::newRow("C -010 0") << QString("-010") << 0 << true << (qlonglong)-8; - QTest::newRow("C -0x10 0") << QString("-0x10") << 0 << true << (qlonglong)-16; - QTest::newRow("C -10 8") << QString("-10") << 8 << true << (qlonglong)-8; - QTest::newRow("C -010 8") << QString("-010") << 8 << true << (qlonglong)-8; - QTest::newRow("C -0x10 8") << QString("-0x10") << 8 << false << (qlonglong)0; - QTest::newRow("C -10 10") << QString("-10") << 10 << true << (qlonglong)-10; - QTest::newRow("C -010 10") << QString("-010") << 10 << true << (qlonglong)-10; - QTest::newRow("C -0x10 10") << QString("-0x10") << 10 << false << (qlonglong)0; - QTest::newRow("C -10 16") << QString("-10") << 16 << true << (qlonglong)-16; - QTest::newRow("C -010 16") << QString("-010") << 16 << true << (qlonglong)-16; - QTest::newRow("C -0x10 16") << QString("-0x10") << 16 << true << (qlonglong)-16; - - // Let's try some Arabic - const char16_t arabic_str[] = { 0x0661, 0x0662, 0x0663, 0x0664, 0x0000 }; // "1234" - QTest::newRow("ar_SA 1234 0") << QString::fromUtf16(arabic_str) << 0 << false << (qlonglong)0; -} - -void tst_QStringRef::integer_conversion() -{ - QFETCH(QString, num_str); - QFETCH(int, base); - QFETCH(bool, good); - QFETCH(qlonglong, num); - QStringRef num_strRef = num_str.leftRef(-1); - - bool ok; - qlonglong d = num_strRef.toLongLong(&ok, base); - QCOMPARE(ok, good); - - if (ok) { - QCOMPARE(d, num); - } -} - -void tst_QStringRef::double_conversion_data() -{ - QTest::addColumn("num_str"); - QTest::addColumn("good"); - QTest::addColumn("num"); - - // The good... - - QTest::newRow("C 1") << QString("1") << true << 1.0; - QTest::newRow("C 1.0") << QString("1.0") << true << 1.0; - QTest::newRow("C 1.234") << QString("1.234") << true << 1.234; - QTest::newRow("C 1.234e-10") << QString("1.234e-10") << true << 1.234e-10; - QTest::newRow("C 1.234E10") << QString("1.234E10") << true << 1.234e10; - QTest::newRow("C 1e10") << QString("1e10") << true << 1.0e10; - - // The bad... - - QTest::newRow("C empty") << QString("") << false << 0.0; - QTest::newRow("C null") << QString() << false << 0.0; - QTest::newRow("C .") << QString(".") << false << 0.0; - QTest::newRow("C 1e") << QString("1e") << false << 0.0; - QTest::newRow("C 1,") << QString("1,") << false << 0.0; - QTest::newRow("C 1,0") << QString("1,0") << false << 0.0; - QTest::newRow("C 1,000") << QString("1,000") << false << 0.0; - QTest::newRow("C 1e1.0") << QString("1e1.0") << false << 0.0; - QTest::newRow("C 1e+") << QString("1e+") << false << 0.0; - QTest::newRow("C 1e-") << QString("1e-") << false << 0.0; - QTest::newRow("de_DE 1,0") << QString("1,0") << false << 0.0; - QTest::newRow("de_DE 1,234") << QString("1,234") << false << 0.0; - QTest::newRow("de_DE 1,234e-10") << QString("1,234e-10") << false << 0.0; - QTest::newRow("de_DE 1,234E10") << QString("1,234E10") << false << 0.0; - - // And the ugly... - - QTest::newRow("C .1") << QString(".1") << true << 0.1; - QTest::newRow("C -.1") << QString("-.1") << true << -0.1; - QTest::newRow("C 1.") << QString("1.") << true << 1.0; - QTest::newRow("C 1.E10") << QString("1.E10") << true << 1.0e10; - QTest::newRow("C 1e+10") << QString("1e+10") << true << 1.0e+10; - QTest::newRow("C 1") << QString(" 1") << true << 1.0; - QTest::newRow("C 1 ") << QString("1 ") << true << 1.0; - - // Let's try some Arabic - const char16_t arabic_str[] = { 0x0660, 0x066B, 0x0661, 0x0662, - 0x0663, 0x0664, 0x0065, 0x0662, - 0x0000 }; // "0.1234e2" - QTest::newRow("ar_SA") << QString::fromUtf16(arabic_str) << false << 0.0; -} - -void tst_QStringRef::double_conversion() -{ -#define MY_DOUBLE_EPSILON (2.22045e-16) - - QFETCH(QString, num_str); - QFETCH(bool, good); - QFETCH(double, num); - QStringRef num_strRef = num_str.leftRef(-1); - - bool ok; - double d = num_strRef.toDouble(&ok); - QCOMPARE(ok, good); - - if (ok) { - double diff = d - num; - if (diff < 0) - diff = -diff; - QVERIFY(diff <= MY_DOUBLE_EPSILON); - } -} - -void tst_QStringRef::trimmed() -{ - QVERIFY(QStringRef().trimmed().isNull()); - QString a = ""; - QVERIFY(!QStringRef(&a).trimmed().isNull()); - QStringRef b; - a = "Text"; - b = a.leftRef(-1); - QCOMPARE(b.compare(QStringLiteral("Text")), 0); - QCOMPARE(b.trimmed().compare(QStringLiteral("Text")), 0); - a = " "; - b = a.leftRef(-1); - QCOMPARE(b.compare(QStringLiteral(" ")), 0); - QCOMPARE(b.trimmed().compare(QStringLiteral("")), 0); - a = " a "; - b = a.leftRef(-1); - QCOMPARE(b.trimmed().compare(QStringLiteral("a")), 0); - a = "Text a "; - b = a.midRef(4); - QCOMPARE(b.compare(QStringLiteral(" a ")), 0); - QCOMPARE(b.trimmed().compare(QStringLiteral("a")), 0); -} - -void tst_QStringRef::truncate() -{ - const QString str = "OriginalString~"; - const QStringRef cref = str.midRef(0); - { - QStringRef ref = cref; - ref.truncate(1000); - QCOMPARE(ref, cref); - for (int i = str.size(); i >= 0; --i) { - ref.truncate(i); - QCOMPARE(ref.size(), i); - QCOMPARE(ref, cref.left(i)); - } - QVERIFY(ref.isEmpty()); - } - - { - QStringRef ref = cref; - QVERIFY(!ref.isEmpty()); - ref.truncate(-1); - QVERIFY(ref.isEmpty()); - } -} - -void tst_QStringRef::chop() -{ - const QString originalString = QStringLiteral("OriginalString~"); - const QStringRef cref(&originalString); - { - const int n = 1; - QStringRef ref = cref; - QString str = originalString; - ref.chop(n); - str.chop(n); - QCOMPARE(ref.toString(), QLatin1String("OriginalString")); - QCOMPARE(ref.toString(), str); - } - { - const int n = -1; - QStringRef ref = cref; - QString str = originalString; - ref.chop(n); - str.chop(n); - QCOMPARE(ref.toString(), originalString); - QCOMPARE(ref.toString(), str); - } - { - const int n = 0; - QStringRef ref = cref; - QString str = originalString; - ref.chop(n); - str.chop(n); - QCOMPARE(ref.toString(), originalString); - QCOMPARE(ref.toString(), str); - } - { - const int n = 1000; - QStringRef ref = cref; - QString str = originalString; - ref.chop(n); - str.chop(n); - QCOMPARE(ref.toString(), str); - QVERIFY(ref.isEmpty()); - } -} - -void tst_QStringRef::left() -{ - QString originalString = "OrginalString~"; - QStringRef ref = originalString.leftRef(originalString.size() - 1); - QCOMPARE(ref.toString(), QStringLiteral("OrginalString")); - - QVERIFY(ref.left(0).toString().isEmpty()); - QCOMPARE(ref.left(ref.size()).toString(), QStringLiteral("OrginalString")); - - QStringRef nullRef; - QVERIFY(nullRef.isNull()); - QVERIFY(nullRef.left(3).toString().isEmpty()); - QVERIFY(nullRef.left(0).toString().isEmpty()); - QVERIFY(nullRef.left(-1).toString().isEmpty()); - - QStringRef emptyRef(&originalString, 0, 0); - QVERIFY(emptyRef.isEmpty()); - QVERIFY(emptyRef.left(3).toString().isEmpty()); - QVERIFY(emptyRef.left(0).toString().isEmpty()); - QVERIFY(emptyRef.left(-1).toString().isEmpty()); - - QCOMPARE(ref.left(-1), ref); - QCOMPARE(ref.left(100), ref); -} - -void tst_QStringRef::right() -{ - QString originalString = "~OrginalString"; - QStringRef ref = originalString.rightRef(originalString.size() - 1); - QCOMPARE(ref.toString(), QLatin1String("OrginalString")); - - QCOMPARE(ref.right(6).toString(), QLatin1String("String")); - QCOMPARE(ref.right(ref.size()).toString(), QLatin1String("OrginalString")); - QCOMPARE(ref.right(0).toString(), QLatin1String("")); - - QStringRef nullRef; - QVERIFY(nullRef.isNull()); - QVERIFY(nullRef.right(3).toString().isEmpty()); - QVERIFY(nullRef.right(0).toString().isEmpty()); - QVERIFY(nullRef.right(-1).toString().isEmpty()); - - QStringRef emptyRef(&originalString, 0, 0); - QVERIFY(emptyRef.isEmpty()); - QVERIFY(emptyRef.right(3).toString().isEmpty()); - QVERIFY(emptyRef.right(0).toString().isEmpty()); - QVERIFY(emptyRef.right(-1).toString().isEmpty()); - - QCOMPARE(ref.right(-1), ref); - QCOMPARE(ref.right(100), ref); -} - -void tst_QStringRef::mid() -{ - QString orig = QStringLiteral("~ABCDEFGHIEfGEFG~"); // 15 + 2 chars - QStringRef a = orig.midRef(1, 15); - QCOMPARE(a.size(), orig.size() - 2); - - QCOMPARE(a.mid(3,3).toString(),(QString)"DEF"); - QCOMPARE(a.mid(0,0).toString(),(QString)""); - QVERIFY(!a.mid(15,0).toString().isNull()); - QVERIFY(a.mid(15,0).toString().isEmpty()); - QVERIFY(!a.mid(15,1).toString().isNull()); - QVERIFY(a.mid(15,1).toString().isEmpty()); - QVERIFY(a.mid(9999).toString().isEmpty()); - QVERIFY(a.mid(9999,1).toString().isEmpty()); - - QCOMPARE(a.mid(-1, 6), a.mid(0, 5)); - QVERIFY(a.mid(-100, 6).isEmpty()); - QVERIFY(a.mid(INT_MIN, 0).isEmpty()); - QCOMPARE(a.mid(INT_MIN, -1), a); - QVERIFY(a.mid(INT_MIN, INT_MAX).isNull()); - QVERIFY(a.mid(INT_MIN + 1, INT_MAX).isEmpty()); - QCOMPARE(a.mid(INT_MIN + 2, INT_MAX), a.left(1)); - QCOMPARE(a.mid(INT_MIN + a.size() + 1, INT_MAX), a); - QVERIFY(a.mid(INT_MAX).isNull()); - QVERIFY(a.mid(INT_MAX, INT_MAX).isNull()); - QCOMPARE(a.mid(-5, INT_MAX), a); - QCOMPARE(a.mid(-1, INT_MAX), a); - QCOMPARE(a.mid(0, INT_MAX), a); - QCOMPARE(a.mid(1, INT_MAX).toString(), QString("BCDEFGHIEfGEFG")); - QCOMPARE(a.mid(5, INT_MAX).toString(), QString("FGHIEfGEFG")); - QVERIFY(a.mid(20, INT_MAX).isNull()); - QCOMPARE(a.mid(-1, -1), a); - - QStringRef nullRef; - QVERIFY(nullRef.mid(3,3).toString().isEmpty()); - QVERIFY(nullRef.mid(0,0).toString().isEmpty()); - QVERIFY(nullRef.mid(9999,0).toString().isEmpty()); - QVERIFY(nullRef.mid(9999,1).toString().isEmpty()); - - QVERIFY(nullRef.mid(-1, 6).isNull()); - QVERIFY(nullRef.mid(-100, 6).isNull()); - QVERIFY(nullRef.mid(INT_MIN, 0).isNull()); - QVERIFY(nullRef.mid(INT_MIN, -1).isNull()); - QVERIFY(nullRef.mid(INT_MIN, INT_MAX).isNull()); - QVERIFY(nullRef.mid(INT_MIN + 1, INT_MAX).isNull()); - QVERIFY(nullRef.mid(INT_MIN + 2, INT_MAX).isNull()); - QVERIFY(nullRef.mid(INT_MIN + nullRef.size() + 1, INT_MAX).isNull()); - QVERIFY(nullRef.mid(INT_MAX).isNull()); - QVERIFY(nullRef.mid(INT_MAX, INT_MAX).isNull()); - QVERIFY(nullRef.mid(-5, INT_MAX).isNull()); - QVERIFY(nullRef.mid(-1, INT_MAX).isNull()); - QVERIFY(nullRef.mid(0, INT_MAX).isNull()); - QVERIFY(nullRef.mid(1, INT_MAX).isNull()); - QVERIFY(nullRef.mid(5, INT_MAX).isNull()); - QVERIFY(nullRef.mid(20, INT_MAX).isNull()); - QVERIFY(nullRef.mid(-1, -1).isNull()); - - QString ninePineapples = "~Nine pineapples~"; - QStringRef x = ninePineapples.midRef(1, ninePineapples.size() - 1); - QCOMPARE(x.mid(5, 4).toString(), QString("pine")); - QCOMPARE(x.mid(5).toString(), QString("pineapples~")); - - QCOMPARE(x.mid(-1, 6), x.mid(0, 5)); - QVERIFY(x.mid(-100, 6).isEmpty()); - QVERIFY(x.mid(INT_MIN, 0).isEmpty()); - QCOMPARE(x.mid(INT_MIN, -1).toString(), x.toString()); - QVERIFY(x.mid(INT_MIN, INT_MAX).isNull()); - QVERIFY(x.mid(INT_MIN + 1, INT_MAX).isEmpty()); - QCOMPARE(x.mid(INT_MIN + 2, INT_MAX), x.left(1)); - QCOMPARE(x.mid(INT_MIN + x.size() + 1, INT_MAX).toString(), x.toString()); - QVERIFY(x.mid(INT_MAX).isNull()); - QVERIFY(x.mid(INT_MAX, INT_MAX).isNull()); - QCOMPARE(x.mid(-5, INT_MAX).toString(), x.toString()); - QCOMPARE(x.mid(-1, INT_MAX).toString(), x.toString()); - QCOMPARE(x.mid(0, INT_MAX), x); - QCOMPARE(x.mid(1, INT_MAX).toString(), QString("ine pineapples~")); - QCOMPARE(x.mid(5, INT_MAX).toString(), QString("pineapples~")); - QVERIFY(x.mid(20, INT_MAX).isNull()); - QCOMPARE(x.mid(-1, -1), x); - - QStringRef emptyRef(&ninePineapples, 0, 0); - QVERIFY(emptyRef.mid(1).isEmpty()); - QVERIFY(emptyRef.mid(-1).isEmpty()); - QVERIFY(emptyRef.mid(0).isEmpty()); - QVERIFY(emptyRef.mid(0, 3).isEmpty()); - QVERIFY(emptyRef.mid(-10, 3).isEmpty()); -} - -static bool operator ==(const QStringList &left, const QList &right) -{ - if (left.size() != right.size()) - return false; - - return std::equal(left.constBegin(), left.constEnd(), right.constBegin()); -} -static inline bool operator ==(const QList &left, const QStringList &right) { return right == left; } - -void tst_QStringRef::split_data() -{ - QTest::addColumn("str"); - QTest::addColumn("sep"); - QTest::addColumn("result"); - - QTest::newRow("a,b,c") << "a,b,c" << "," << (QStringList() << "a" << "b" << "c"); - QTest::newRow("a,b,c,a,b,c") << "a,b,c,a,b,c" << "," << (QStringList() << "a" << "b" << "c" << "a" << "b" << "c"); - QTest::newRow("a,b,c,,a,b,c") << "a,b,c,,a,b,c" << "," << (QStringList() << "a" << "b" << "c" << "" << "a" << "b" << "c"); - QTest::newRow("2") << QString("-rw-r--r-- 1 0 0 519240 Jul 9 2002 bigfile") - << " " - << (QStringList() << "-rw-r--r--" << "" << "1" << "0" << "" << "0" << "" - << "519240" << "Jul" << "" << "9" << "" << "2002" << "bigfile"); - QTest::newRow("one-empty") << "" << " " << (QStringList() << ""); - QTest::newRow("two-empty") << " " << " " << (QStringList() << "" << ""); - QTest::newRow("three-empty") << " " << " " << (QStringList() << "" << "" << ""); - - QTest::newRow("all-empty") << "" << "" << (QStringList() << "" << ""); - QTest::newRow("all-null") << QString() << QString() << (QStringList() << QString() << QString()); - QTest::newRow("sep-empty") << "abc" << "" << (QStringList() << "" << "a" << "b" << "c" << ""); -} - -void tst_QStringRef::split() -{ - QFETCH(QString, str); - QFETCH(QString, sep); - QFETCH(QStringList, result); - - QList list; - // we construct a bigger valid string to check - // if ref.split is using the right size - QString source = str + str + str; - QStringRef ref = source.midRef(str.size(), str.size()); - QCOMPARE(ref.size(), str.size()); - - list = ref.split(sep); - QVERIFY(list == result); - if (sep.size() == 1) { - list = ref.split(sep.at(0)); - QVERIFY(list == result); - } - - list = ref.split(sep, Qt::KeepEmptyParts); - QVERIFY(list == result); - if (sep.size() == 1) { - list = ref.split(sep.at(0), Qt::KeepEmptyParts); - QVERIFY(list == result); - } - - result.removeAll(""); - list = ref.split(sep, Qt::SkipEmptyParts); - QVERIFY(list == result); - if (sep.size() == 1) { - list = ref.split(sep.at(0), Qt::SkipEmptyParts); - QVERIFY(list == result); - } -} - -void tst_QStringRef::nullToString() -{ - QStringRef nullRef; - QVERIFY(nullRef.isNull()); - QVERIFY(nullRef.toString().isNull()); - - QString str; - nullRef = &str; - QVERIFY(nullRef.isNull()); - QVERIFY(nullRef.toString().isNull()); -} - -QTEST_APPLESS_MAIN(tst_QStringRef) - -#include "tst_qstringref.moc" diff --git a/tests/auto/corelib/text/qstringview/tst_qstringview.cpp b/tests/auto/corelib/text/qstringview/tst_qstringview.cpp index a7f39412a8..bf3454e028 100644 --- a/tests/auto/corelib/text/qstringview/tst_qstringview.cpp +++ b/tests/auto/corelib/text/qstringview/tst_qstringview.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include @@ -72,12 +71,6 @@ static_assert(CanConvert::value); static_assert(CanConvert< QString&>::value); static_assert(CanConvert::value); -static_assert(CanConvert< QStringRef >::value); -static_assert(CanConvert::value); -static_assert(CanConvert< QStringRef&>::value); -static_assert(CanConvert::value); - - // // ushort // @@ -169,7 +162,6 @@ private Q_SLOTS: void arg() const; void fromQString() const; - void fromQStringRef() const; void fromQCharStar() const { @@ -502,20 +494,6 @@ void tst_QStringView::fromQString() const conversion_tests(QString("Hello World!")); } -void tst_QStringView::fromQStringRef() const -{ - QStringRef null; - QString emptyS = ""; - QStringRef empty(&emptyS); - - QVERIFY( QStringView(null).isNull()); - QVERIFY( QStringView(null).isEmpty()); - QVERIFY( QStringView(empty).isEmpty()); - QVERIFY(!QStringView(empty).isNull()); - - conversion_tests(QString("Hello World!").midRef(6)); -} - void tst_QStringView::tokenize_data() const { // copied from tst_QString @@ -571,20 +549,6 @@ void tst_QStringView::tokenize() const QCOMPARE(sv, *rit++); } - // (rvalue) QStringRef -#ifdef __cpp_deduction_guides - { - auto rit = result.cbegin(); - for (auto sv : QStringTokenizer{str, sep.midRef(0)}) - QCOMPARE(sv, *rit++); - } -#endif - { - auto rit = result.cbegin(); - for (auto sv : QStringView{str}.tokenize(sep.midRef(0))) - QCOMPARE(sv, *rit++); - } - // (rvalue) QChar #ifdef __cpp_deduction_guides if (sep.size() == 1) { @@ -654,15 +618,6 @@ void tst_QStringView::tokenize() const QCOMPARE(result, actual); } - // (rvalue) QStringRef - { - QStringList actual; - const QStringTokenizer tok{str, sep.midRef(0)}; - std::ranges::transform(tok, std::back_inserter(actual), - [](auto sv) { return sv.toString(); }); - QCOMPARE(result, actual); - } - // (rvalue) QChar if (sep.size() == 1) { QStringList actual; @@ -888,13 +843,6 @@ void tst_QStringView::overloadResolution() QStringViewOverloadResolution::test(ushortPointer); } - { - QStringRef stringRef; - QStringViewOverloadResolution::test(stringRef); - QStringViewOverloadResolution::test(qAsConst(stringRef)); - QStringViewOverloadResolution::test(std::move(stringRef)); - } - #if defined(Q_OS_WIN) { wchar_t wchartArray[42] = {}; diff --git a/tests/auto/corelib/text/text.pro b/tests/auto/corelib/text/text.pro index 0e89ea0850..f03f28936a 100644 --- a/tests/auto/corelib/text/text.pro +++ b/tests/auto/corelib/text/text.pro @@ -20,7 +20,6 @@ SUBDIRS = \ qstringiterator \ qstringlist \ qstringmatcher \ - qstringref \ qstringtokenizer \ qstringview \ qtextboundaryfinder diff --git a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp index 733d8432bb..39cb8406cd 100644 --- a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp +++ b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp @@ -471,7 +471,6 @@ private Q_SLOTS: void front_back_QList() { front_back_impl>(); } void front_back_QVarLengthArray() { front_back_impl>(); } void front_back_QString() { front_back_impl(); } - void front_back_QStringRef() { front_back_impl(); } void front_back_QStringView() { front_back_impl(); } void front_back_QLatin1String() { front_back_impl(); } void front_back_QByteArray() { front_back_impl(); } @@ -773,7 +772,6 @@ Container make(int size) static QString s_string = QStringLiteral("\1\2\3\4\5\6\7"); -template <> QStringRef make(int size) { return s_string.leftRef(size); } template <> QStringView make(int size) { return QStringView(s_string).left(size); } template <> QLatin1String make(int size) { return QLatin1String("\1\2\3\4\5\6\7", size); } diff --git a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp index 13f9b46eaa..f04e1bdb12 100644 --- a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp +++ b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp @@ -69,12 +69,8 @@ private Q_SLOTS: void tst_QHashFunctions::consistent() { // QString-like - { - const QString s = QStringLiteral("abcdefghijklmnopqrstuvxyz").repeated(16); - - QCOMPARE(qHash(s), qHash(QStringRef(&s))); - QCOMPARE(qHash(s), qHash(QStringView(s))); - } + const QString s = QStringLiteral("abcdefghijklmnopqrstuvxyz").repeated(16); + QCOMPARE(qHash(s), qHash(QStringView(s))); } void tst_QHashFunctions::initTestCase() @@ -176,10 +172,6 @@ void tst_QHashFunctions::qhash_of_empty_and_null_qstring() QCOMPARE(null, empty); QCOMPARE(qHash(null, seed), qHash(empty, seed)); - QStringRef nullRef, emptyRef(&empty); - QCOMPARE(nullRef, emptyRef); - QCOMPARE(qHash(nullRef, seed), qHash(emptyRef, seed)); - QStringView nullView, emptyView(empty); QCOMPARE(nullView, emptyView); QCOMPARE(qHash(nullView, seed), qHash(emptyView, seed)); diff --git a/tests/auto/tools/qmakelib/evaltest.cpp b/tests/auto/tools/qmakelib/evaltest.cpp index 3a01590707..70aef094b8 100644 --- a/tests/auto/tools/qmakelib/evaltest.cpp +++ b/tests/auto/tools/qmakelib/evaltest.cpp @@ -2869,12 +2869,13 @@ void tst_qmakelib::proEval() globals.environment = m_env; globals.setProperties(m_prop); globals.setDirectories(m_indir, m_outdir); - ProFile *outPro = parser.parsedProBlock(QStringRef(&out), 0, "out", 1, QMakeParser::FullGrammar); + ProFile *outPro = + parser.parsedProBlock(out, 0, "out", 1, QMakeParser::FullGrammar); if (!outPro->isOk()) { qWarning("Expected output is malformed"); verified = false; } - ProFile *pro = parser.parsedProBlock(QStringRef(&in), 0, infile, 1, QMakeParser::FullGrammar); + ProFile *pro = parser.parsedProBlock(in, 0, infile, 1, QMakeParser::FullGrammar); QMakeEvaluator visitor(&globals, &parser, &vfs, &handler); visitor.setOutputDir(m_outdir); #ifdef Q_OS_WIN diff --git a/tests/auto/tools/qmakelib/parsertest.cpp b/tests/auto/tools/qmakelib/parsertest.cpp index 3b0e47a5ac..0618b6be6b 100644 --- a/tests/auto/tools/qmakelib/parsertest.cpp +++ b/tests/auto/tools/qmakelib/parsertest.cpp @@ -2031,7 +2031,7 @@ void tst_qmakelib::proParser() handler.setExpectedMessages(msgs.split('\n', Qt::SkipEmptyParts)); QMakeVfs vfs; QMakeParser parser(0, &vfs, &handler); - ProFile *pro = parser.parsedProBlock(QStringRef(&in), 0, "in", 1, QMakeParser::FullGrammar); + ProFile *pro = parser.parsedProBlock(QStringView{ in }, 0, "in", 1, QMakeParser::FullGrammar); if (handler.printedMessages()) { qWarning("Got unexpected message(s)"); verified = false; diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp index a62f6c5699..611ae3474b 100644 --- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp +++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp @@ -414,7 +414,7 @@ static char **QString2cstrings(const QString &args) { static QByteArrayList cache; - const auto &list = args.splitRef(' '); + const auto &list = QStringView{ args }.split(' '); auto argarray = new char*[list.count() + 1]; int i = 0; -- cgit v1.2.3