tst_qstringapisymmetry: also check potential rvalue overloads of transformations

For transformations, regardless of whether they're currently
overloaded on rvalue-this or not, check the results of calls to const
lvalues as well as mutable rvalues.

Use the new mixed-type QCOMPARE more.

Change-Id: Ibaa436cd88b40e5c0823c3bbe5b04a9964e7e987
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Marc Mutz 2017-04-27 13:08:40 +02:00
parent 64967461ee
commit 96edd0e440

View File

@ -430,6 +430,15 @@ void tst_QStringApiSymmetry::compare_data(bool hasConceptOfNullAndEmpty)
#undef ROW
}
template <typename String> String detached(String s)
{
if (!s.isNull()) { // detaching loses nullness, but we need to preserve it
auto d = s.data();
Q_UNUSED(d);
}
return s;
}
template <class Str> 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 <> QStringRef make(const QStringRef &sf, QLatin1String, const QByteArray &) { return sf; }
@ -783,16 +792,30 @@ void tst_QStringApiSymmetry::mid_impl()
const auto s = make<String>(unicode, latin1, utf8);
const auto mid = s.mid(pos);
const auto mid2 = s.mid(pos, n);
{
const auto mid = s.mid(pos);
const auto mid2 = s.mid(pos, n);
QVERIFY(mid == result);
QCOMPARE(mid.isNull(), result.isNull());
QCOMPARE(mid.isEmpty(), result.isEmpty());
QCOMPARE(mid, result);
QCOMPARE(mid.isNull(), result.isNull());
QCOMPARE(mid.isEmpty(), result.isEmpty());
QVERIFY(mid2 == result2);
QCOMPARE(mid2.isNull(), result2.isNull());
QCOMPARE(mid2.isEmpty(), result2.isEmpty());
QCOMPARE(mid2, result2);
QCOMPARE(mid2.isNull(), result2.isNull());
QCOMPARE(mid2.isEmpty(), result2.isEmpty());
}
{
const auto mid = detached(s).mid(pos);
const auto mid2 = detached(s).mid(pos, n);
QCOMPARE(mid, result);
QCOMPARE(mid.isNull(), result.isNull());
QCOMPARE(mid.isEmpty(), result.isEmpty());
QCOMPARE(mid2, result2);
QCOMPARE(mid2.isNull(), result2.isNull());
QCOMPARE(mid2.isEmpty(), result2.isEmpty());
}
}
void tst_QStringApiSymmetry::left_data()
@ -843,6 +866,13 @@ void tst_QStringApiSymmetry::left_impl()
QCOMPARE(left.isNull(), result.isNull());
QCOMPARE(left.isEmpty(), result.isEmpty());
}
{
const auto left = detached(s).left(n);
QCOMPARE(left, result);
QCOMPARE(left.isNull(), result.isNull());
QCOMPARE(left.isEmpty(), result.isEmpty());
}
{
auto left = s;
left.truncate(n);
@ -894,11 +924,20 @@ void tst_QStringApiSymmetry::right_impl()
const auto s = make<String>(unicode, latin1, utf8);
const auto right = s.right(n);
{
const auto right = s.right(n);
QVERIFY(right == result);
QCOMPARE(right.isNull(), result.isNull());
QCOMPARE(right.isEmpty(), result.isEmpty());
QCOMPARE(right, result);
QCOMPARE(right.isNull(), result.isNull());
QCOMPARE(right.isEmpty(), result.isEmpty());
}
{
const auto right = detached(s).right(n);
QCOMPARE(right, result);
QCOMPARE(right.isNull(), result.isNull());
QCOMPARE(right.isEmpty(), result.isEmpty());
}
}
void tst_QStringApiSymmetry::chop_data()
@ -945,16 +984,22 @@ void tst_QStringApiSymmetry::chop_impl()
{
const auto chopped = s.chopped(n);
QVERIFY(chopped == result);
QCOMPARE(chopped, result);
QCOMPARE(chopped.isNull(), result.isNull());
QCOMPARE(chopped.isEmpty(), result.isEmpty());
}
{
const auto chopped = detached(s).chopped(n);
QCOMPARE(chopped, result);
QCOMPARE(chopped.isNull(), result.isNull());
QCOMPARE(chopped.isEmpty(), result.isEmpty());
}
{
auto chopped = s;
chopped.chop(n);
QVERIFY(chopped == result);
QCOMPARE(chopped, result);
QCOMPARE(chopped.isNull(), result.isNull());
QCOMPARE(chopped.isEmpty(), result.isEmpty());
}