Add some incremental tests
Feed the data one by one to the encoder or decoder to verify that the handling of incremental decoding is correct. Change-Id: I565e4f1872e00859026334f7662b6778772e159d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
4b2edde373
commit
940665eff5
@ -1337,6 +1337,7 @@ void tst_QStringConverter::utf8stateful()
|
|||||||
QFETCH(QByteArray, buffer2);
|
QFETCH(QByteArray, buffer2);
|
||||||
QFETCH(QString, result);
|
QFETCH(QString, result);
|
||||||
|
|
||||||
|
{
|
||||||
QStringDecoder decoder(QStringDecoder::Utf8);
|
QStringDecoder decoder(QStringDecoder::Utf8);
|
||||||
QVERIFY(decoder.isValid());
|
QVERIFY(decoder.isValid());
|
||||||
|
|
||||||
@ -1355,6 +1356,24 @@ void tst_QStringConverter::utf8stateful()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!buffer2.isEmpty()) {
|
||||||
|
QStringDecoder decoder(QStringDecoder::Utf8);
|
||||||
|
QVERIFY(decoder.isValid());
|
||||||
|
|
||||||
|
QString decoded;
|
||||||
|
for (char c : buffer1)
|
||||||
|
decoded += decoder(&c, 1);
|
||||||
|
for (char c : buffer2)
|
||||||
|
decoded += decoder(&c, 1);
|
||||||
|
if (result.isNull()) {
|
||||||
|
QVERIFY(decoder.hasError());
|
||||||
|
} else {
|
||||||
|
QVERIFY(!decoder.hasError());
|
||||||
|
QCOMPARE(decoded, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QStringConverter::utfHeaders_data()
|
void tst_QStringConverter::utfHeaders_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QStringConverter::Encoding>("encoding");
|
QTest::addColumn<QStringConverter::Encoding>("encoding");
|
||||||
@ -1526,19 +1545,43 @@ void tst_QStringConverter::utfHeaders()
|
|||||||
QLatin1String ignoreReverseTestOn = (QSysInfo::ByteOrder == QSysInfo::BigEndian) ? QLatin1String(" le") : QLatin1String(" be");
|
QLatin1String ignoreReverseTestOn = (QSysInfo::ByteOrder == QSysInfo::BigEndian) ? QLatin1String(" le") : QLatin1String(" be");
|
||||||
QString rowName(QTest::currentDataTag());
|
QString rowName(QTest::currentDataTag());
|
||||||
|
|
||||||
|
{
|
||||||
QStringDecoder decode(encoding, flags);
|
QStringDecoder decode(encoding, flags);
|
||||||
QVERIFY(decode.isValid());
|
QVERIFY(decode.isValid());
|
||||||
|
|
||||||
QString result = decode(encoded);
|
QString result = decode(encoded);
|
||||||
QCOMPARE(result.length(), unicode.length());
|
QCOMPARE(result.length(), unicode.length());
|
||||||
QCOMPARE(result, unicode);
|
QCOMPARE(result, unicode);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
QStringDecoder decode(encoding, flags);
|
||||||
|
QVERIFY(decode.isValid());
|
||||||
|
|
||||||
|
QString result;
|
||||||
|
for (char c : encoded)
|
||||||
|
result += decode(&c, 1);
|
||||||
|
QCOMPARE(result.length(), unicode.length());
|
||||||
|
QCOMPARE(result, unicode);
|
||||||
|
}
|
||||||
|
|
||||||
if (!rowName.endsWith("nobom") && !rowName.contains(ignoreReverseTestOn)) {
|
if (!rowName.endsWith("nobom") && !rowName.contains(ignoreReverseTestOn)) {
|
||||||
|
{
|
||||||
QStringEncoder encode(encoding, flags);
|
QStringEncoder encode(encoding, flags);
|
||||||
QVERIFY(encode.isValid());
|
QVERIFY(encode.isValid());
|
||||||
QByteArray reencoded = encode(unicode);
|
QByteArray reencoded = encode(unicode);
|
||||||
QCOMPARE(reencoded, encoded);
|
QCOMPARE(reencoded, encoded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
QStringEncoder encode(encoding, flags);
|
||||||
|
QVERIFY(encode.isValid());
|
||||||
|
QByteArray reencoded;
|
||||||
|
for (QChar c : unicode)
|
||||||
|
reencoded += encode(&c, 1);
|
||||||
|
QCOMPARE(reencoded, encoded);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class LoadAndConvert: public QRunnable
|
class LoadAndConvert: public QRunnable
|
||||||
|
Loading…
x
Reference in New Issue
Block a user