Refactor\Extend tst_QString::append_data with additional test cases
During the implementation of QString::append(QUtf8StringView) it has become apparent that the testing is insufficient as it did not warn about an extra growth. The following tests have been added that append: - y-umlaut and greek letter small theta (2 UTF-8 code units => 1 UTF-16) - devanagri letter ssa (3 UTF-8 code units => 1 UTF-16) - chakma digit zero (4 UTF-8 code units => 2 UTF-16 code units) - some combinations of the above Note that this also affects operator_pluseq_data, which is basically a wrapper around append_data. Task-number: QTBUG-103302 Change-Id: I09ed950e3f0e71ae9ae85a455f42e130887f1109 Reviewed-by: Marc Mutz <marc.mutz@qt.io> (cherry picked from commit 4e5f8740635d1d57371b7639d58e9998c0027a04) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
5749fafa1f
commit
ca5b8565ff
@ -56,7 +56,7 @@ class ArgBase
|
||||
protected:
|
||||
QString pinned;
|
||||
explicit ArgBase(const char *str)
|
||||
: pinned(QString::fromLatin1(str)) {}
|
||||
: pinned(QString::fromUtf8(str)) {}
|
||||
};
|
||||
|
||||
template <>
|
||||
@ -276,6 +276,13 @@ static void do_apply1(MemFun mf)
|
||||
class tst_QString : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum DataOption {
|
||||
EmptyIsNoop = 0x1,
|
||||
Latin1Encoded = 0x2
|
||||
};
|
||||
Q_DECLARE_FLAGS(DataOptions, DataOption)
|
||||
private:
|
||||
|
||||
#if QT_CONFIG(regularexpression)
|
||||
template<typename List, class RegExp>
|
||||
@ -288,12 +295,12 @@ class tst_QString : public QObject
|
||||
void append_impl() const { do_apply0<ArgType>(MemFun(&QString::append)); }
|
||||
template <typename ArgType>
|
||||
void append_impl() const { append_impl<ArgType, QString &(QString::*)(const ArgType&)>(); }
|
||||
void append_data(bool emptyIsNoop = false);
|
||||
void append_data(DataOptions options = {});
|
||||
template <typename ArgType, typename MemFun>
|
||||
void operator_pluseq_impl() const { do_apply0<ArgType>(MemFun(&QString::operator+=)); }
|
||||
template <typename ArgType>
|
||||
void operator_pluseq_impl() const { operator_pluseq_impl<ArgType, QString &(QString::*)(const ArgType&)>(); }
|
||||
void operator_pluseq_data(bool emptyIsNoop = false);
|
||||
void operator_pluseq_data(DataOptions options = {});
|
||||
template <typename ArgType, typename MemFun>
|
||||
void prepend_impl() const { do_apply0<ArgType>(MemFun(&QString::prepend)); }
|
||||
template <typename ArgType>
|
||||
@ -390,17 +397,17 @@ private slots:
|
||||
void append_qstring() { append_impl<QString>(); }
|
||||
void append_qstring_data() { append_data(); }
|
||||
void append_qstringview() { append_impl<QStringView, QString &(QString::*)(QStringView)>(); }
|
||||
void append_qstringview_data() { append_data(true); }
|
||||
void append_qstringview_data() { append_data(EmptyIsNoop); }
|
||||
void append_qlatin1string() { append_impl<QLatin1String, QString &(QString::*)(QLatin1String)>(); }
|
||||
void append_qlatin1string_data() { append_data(); }
|
||||
void append_qlatin1string_data() { append_data(Latin1Encoded); }
|
||||
void append_qcharstar_int() { append_impl<QPair<const QChar *, int>, QString&(QString::*)(const QChar *, qsizetype)>(); }
|
||||
void append_qcharstar_int_data() { append_data(true); }
|
||||
void append_qcharstar_int_data() { append_data(EmptyIsNoop); }
|
||||
void append_qchar() { append_impl<QChar, QString &(QString::*)(QChar)>(); }
|
||||
void append_qchar_data() { append_data(true); }
|
||||
void append_qchar_data() { append_data(EmptyIsNoop); }
|
||||
void append_qbytearray() { append_impl<QByteArray>(); }
|
||||
void append_qbytearray_data() { append_data(); }
|
||||
void append_char() { append_impl<char, QString &(QString::*)(QChar)>(); }
|
||||
void append_char_data() { append_data(true); }
|
||||
void append_char_data() { append_data({EmptyIsNoop, Latin1Encoded}); }
|
||||
void append_charstar() { append_impl<const char *, QString &(QString::*)(const char *)>(); }
|
||||
void append_charstar_data() { append_data(); }
|
||||
void append_special_cases();
|
||||
@ -410,11 +417,11 @@ private slots:
|
||||
void operator_pluseq_qstring() { operator_pluseq_impl<QString>(); }
|
||||
void operator_pluseq_qstring_data() { operator_pluseq_data(); }
|
||||
void operator_pluseq_qstringview() { operator_pluseq_impl<QStringView, QString &(QString::*)(QStringView)>(); }
|
||||
void operator_pluseq_qstringview_data() { operator_pluseq_data(true); }
|
||||
void operator_pluseq_qstringview_data() { operator_pluseq_data(EmptyIsNoop); }
|
||||
void operator_pluseq_qlatin1string() { operator_pluseq_impl<QLatin1String, QString &(QString::*)(QLatin1String)>(); }
|
||||
void operator_pluseq_qlatin1string_data() { operator_pluseq_data(); }
|
||||
void operator_pluseq_qlatin1string_data() { operator_pluseq_data(Latin1Encoded); }
|
||||
void operator_pluseq_qchar() { operator_pluseq_impl<QChar, QString &(QString::*)(QChar)>(); }
|
||||
void operator_pluseq_qchar_data() { operator_pluseq_data(true); }
|
||||
void operator_pluseq_qchar_data() { operator_pluseq_data(EmptyIsNoop); }
|
||||
void operator_pluseq_qbytearray() { operator_pluseq_impl<QByteArray>(); }
|
||||
void operator_pluseq_qbytearray_data() { operator_pluseq_data(); }
|
||||
void operator_pluseq_charstar() { operator_pluseq_impl<const char *, QString &(QString::*)(const char *)>(); }
|
||||
@ -587,6 +594,8 @@ private slots:
|
||||
void chopped();
|
||||
void removeIf();
|
||||
};
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(tst_QString::DataOptions)
|
||||
|
||||
|
||||
template <class T> const T &verifyZeroTermination(const T &t) { return t; }
|
||||
|
||||
@ -2738,17 +2747,20 @@ void tst_QString::insert_special_cases()
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QString::append_data(bool emptyIsNoop)
|
||||
void tst_QString::append_data(DataOptions options)
|
||||
{
|
||||
QTest::addColumn<QString>("s");
|
||||
QTest::addColumn<CharStarContainer>("arg");
|
||||
QTest::addColumn<QString>("expected");
|
||||
|
||||
const bool emptyIsNoop = options.testFlag(EmptyIsNoop);
|
||||
|
||||
const CharStarContainer nullC;
|
||||
const CharStarContainer emptyC("");
|
||||
const CharStarContainer aC("a");
|
||||
const CharStarContainer bC("b");
|
||||
//const CharStarContainer abC("ab");
|
||||
const CharStarContainer yumlautC(options.testFlag(Latin1Encoded) ? "\xff" : "\xc3\xbf");
|
||||
|
||||
const QString null;
|
||||
const QString empty("");
|
||||
@ -2756,6 +2768,9 @@ void tst_QString::append_data(bool emptyIsNoop)
|
||||
//const QString b("b");
|
||||
const QString ab("ab");
|
||||
|
||||
const QString yumlaut = QStringLiteral("\u00ff"); // LATIN LETTER SMALL Y WITH UMLAUT
|
||||
const QString aYumlaut = QStringLiteral("a\u00ff");
|
||||
|
||||
QTest::newRow("null + null") << null << nullC << null;
|
||||
QTest::newRow("null + empty") << null << emptyC << (emptyIsNoop ? null : empty);
|
||||
QTest::newRow("null + a") << null << aC << a;
|
||||
@ -2765,6 +2780,64 @@ void tst_QString::append_data(bool emptyIsNoop)
|
||||
QTest::newRow("a + null") << a << nullC << a;
|
||||
QTest::newRow("a + empty") << a << emptyC << a;
|
||||
QTest::newRow("a + b") << a << bC << ab;
|
||||
|
||||
QTest::newRow("null+yumlaut") << null << yumlautC << yumlaut;
|
||||
QTest::newRow("empty+yumlaut") << empty << yumlautC << yumlaut;
|
||||
QTest::newRow("a+yumlaut") << a << yumlautC << aYumlaut;
|
||||
|
||||
if (!options.testFlag(Latin1Encoded)) {
|
||||
const auto smallTheta = QStringLiteral("\u03b8"); // GREEK LETTER SMALL THETA
|
||||
const auto ssa = QStringLiteral("\u0937"); // DEVANAGARI LETTER SSA
|
||||
const auto chakmaZero = QStringLiteral("\U00011136"); // CHAKMA DIGIT ZERO
|
||||
|
||||
const auto aSmallTheta = QStringLiteral("a\u03b8");
|
||||
const auto aSsa = QStringLiteral("a\u0937");
|
||||
const auto aChakmaZero = QStringLiteral("a\U00011136");
|
||||
|
||||
const auto thetaChakma = QStringLiteral("\u03b8\U00011136");
|
||||
const auto chakmaTheta = QStringLiteral("\U00011136\u03b8");
|
||||
const auto ssaTheta = QStringLiteral("\u0937\u03b8");
|
||||
const auto thetaSsa = QStringLiteral("\u03b8\u0937");
|
||||
const auto ssaChakma = QStringLiteral("\u0937\U00011136");
|
||||
const auto chakmaSsa = QStringLiteral("\U00011136\u0937");
|
||||
const auto thetaUmlaut = QStringLiteral("\u03b8\u00ff");
|
||||
const auto umlautTheta = QStringLiteral("\u00ff\u03b8");
|
||||
const auto ssaUmlaut = QStringLiteral("\u0937\u00ff");
|
||||
const auto umlautSsa = QStringLiteral("\u00ff\u0937");
|
||||
const auto chakmaUmlaut = QStringLiteral("\U00011136\u00ff");
|
||||
const auto umlautChakma = QStringLiteral("\u00ff\U00011136");
|
||||
|
||||
const CharStarContainer smallThetaC("\xce\xb8"); // non-Latin1
|
||||
const CharStarContainer ssaC("\xe0\xa4\xb7"); // Higher BMP
|
||||
const CharStarContainer chakmaZeroC("\xf0\x91\x84\xb6"); // Non-BMP
|
||||
|
||||
QTest::newRow("null+smallTheta") << null << smallThetaC << smallTheta;
|
||||
QTest::newRow("empty+smallTheta") << empty << smallThetaC << smallTheta;
|
||||
QTest::newRow("a+smallTheta") << a << smallThetaC << aSmallTheta;
|
||||
|
||||
QTest::newRow("null+ssa") << null << ssaC << ssa;
|
||||
QTest::newRow("empty+ssa") << empty << ssaC << ssa;
|
||||
QTest::newRow("a+ssa") << a << ssaC << aSsa;
|
||||
|
||||
QTest::newRow("null+chakma") << null << chakmaZeroC << chakmaZero;
|
||||
QTest::newRow("empty+chakma") << empty << chakmaZeroC << chakmaZero;
|
||||
QTest::newRow("a+chakma") << a << chakmaZeroC << aChakmaZero;
|
||||
|
||||
QTest::newRow("smallTheta+chakma") << smallTheta << chakmaZeroC << thetaChakma;
|
||||
QTest::newRow("chakma+smallTheta") << chakmaZero << smallThetaC << chakmaTheta;
|
||||
QTest::newRow("smallTheta+ssa") << smallTheta << ssaC << thetaSsa;
|
||||
|
||||
QTest::newRow("ssa+smallTheta") << ssa << smallThetaC << ssaTheta;
|
||||
QTest::newRow("ssa+chakma") << ssa << chakmaZeroC << ssaChakma;
|
||||
QTest::newRow("chakma+ssa") << chakmaZero << ssaC << chakmaSsa;
|
||||
|
||||
QTest::newRow("smallTheta+yumlaut") << smallTheta << yumlautC << thetaUmlaut;
|
||||
QTest::newRow("yumlaut+smallTheta") << yumlaut << smallThetaC << umlautTheta;
|
||||
QTest::newRow("ssa+yumlaut") << ssa << yumlautC << ssaUmlaut;
|
||||
QTest::newRow("yumlaut+ssa") << yumlaut << ssaC << umlautSsa;
|
||||
QTest::newRow("chakma+yumlaut") << chakmaZero << yumlautC << chakmaUmlaut;
|
||||
QTest::newRow("yumlaut+chakma") << yumlaut << chakmaZeroC << umlautChakma;
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QString::append_special_cases()
|
||||
@ -2913,9 +2986,9 @@ void tst_QString::operator_pluseq_special_cases()
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QString::operator_pluseq_data(bool emptyIsNoop)
|
||||
void tst_QString::operator_pluseq_data(DataOptions options)
|
||||
{
|
||||
append_data(emptyIsNoop);
|
||||
append_data(options);
|
||||
}
|
||||
|
||||
void tst_QString::operator_pluseq_bytearray_special_cases_data()
|
||||
|
Loading…
x
Reference in New Issue
Block a user