diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2024-01-29 11:57:37 +0100 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2024-02-07 15:02:19 +0100 |
commit | 0aaf7092cd077eb07e62d3742293f146c65c9630 (patch) | |
tree | 6ac9767d33a34d592f8d5e0cbb97c87f17dccefb /tests/manual | |
parent | be04a47a8b371a44b728f7b7a2be2f66749e562b (diff) |
Fix QDataStream::operator<<(const char *) to handle 64-bit length
The operator was not converted to using a new streaming version, so it
supported only 32-bit length.
Fix it and add a manual test for serialization/deserialization of
large c-style strings.
Amends fd48ce0b73c74dafd5db27bc1f2752ef665df7ef
Pick-to: 6.7
Change-Id: I83704edec021d400b992de810feba5da52d5ffe1
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/manual')
-rw-r--r-- | tests/manual/corelib/qdatastream/tst_manualqdatastream.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/manual/corelib/qdatastream/tst_manualqdatastream.cpp b/tests/manual/corelib/qdatastream/tst_manualqdatastream.cpp index 7b242f4519..37e5b80950 100644 --- a/tests/manual/corelib/qdatastream/tst_manualqdatastream.cpp +++ b/tests/manual/corelib/qdatastream/tst_manualqdatastream.cpp @@ -5,6 +5,7 @@ #include <QHash> #include <QList> #include <QMap> +#include <QScopeGuard> #include <QSet> #include <QTest> @@ -33,6 +34,7 @@ private slots: void stream_bigQSet(); void stream_bigQMap(); void stream_bigQHash(); + void stream_bigCString(); }; void tst_QDataStream::initTestCase() @@ -179,6 +181,54 @@ void tst_QDataStream::stream_bigQHash() stream_big<QHash<qsizetype, qsizetype>>(); } +void tst_QDataStream::stream_bigCString() +{ + if constexpr (sizeof(void*) == sizeof(int)) + QSKIP("This test is 64-bit only."); + + QFETCH_GLOBAL(const QDataStream::Version, streamVersion); + constexpr qint64 GiB = 1024 * 1024 * 1024; + constexpr qint64 BaseSize = 4 * GiB + 1; + std::string input; + qDebug("Creating an array with %lld entries", BaseSize); + QElapsedTimer timer; + timer.start(); + try { + input.resize(BaseSize, 'a'); + } catch (const std::bad_alloc &) { + QSKIP("Could not allocate 4 Gi + 2 entries."); + } + qDebug("Created dataset in %lld ms", timer.elapsed()); + QByteArray ba; + QDataStream inputstream(&ba, QIODevice::WriteOnly); + inputstream.setVersion(streamVersion); + timer.start(); + try { + inputstream << input.data(); + } catch (const std::bad_alloc &) { + QSKIP("Not enough memory to copy into QDataStream."); + } + qDebug("Streamed into QDataStream in %lld ms", timer.elapsed()); + if (streamVersion < QDataStream::Qt_6_7) { + // old versions do not support data size more than 4 GiB + QCOMPARE(inputstream.status(), QDataStream::SizeLimitExceeded); + QVERIFY(ba.isEmpty()); + } else { + char *output = nullptr; + auto cleanup = qScopeGuard([&output] { delete [] output; }); + QDataStream outputstream(ba); + timer.start(); + try { + outputstream >> output; + } catch (const std::bad_alloc &) { + QSKIP("Not enough memory to copy out of QDataStream."); + } + qDebug("Streamed out of QDataStream in %lld ms", timer.elapsed()); + QCOMPARE(qstrlen(output), input.size()); + QVERIFY(memcmp(input.data(), output, BaseSize + 1) == 0); + } +} + QTEST_MAIN(tst_QDataStream) #include "tst_manualqdatastream.moc" |