diff options
Diffstat (limited to 'tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp')
-rw-r--r-- | tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp index 72a6427930..fc7247b733 100644 --- a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp +++ b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp @@ -35,6 +35,7 @@ #include <limits.h> #include <private/qtools_p.h> +#include <iterator> #include <stdexcept> #include <string_view> @@ -53,6 +54,7 @@ private slots: void qCompress(); void qUncompressCorruptedData_data(); void qUncompressCorruptedData(); + void qUncompress4GiBPlus(); void qCompressionZeroTermination(); #endif void constByteArray(); @@ -343,6 +345,79 @@ void tst_QByteArray::qUncompressCorruptedData() #endif } +void tst_QByteArray::qUncompress4GiBPlus() +{ + // after three rounds, this decompresses to 4GiB + 1 'X' bytes: + constexpr uchar compressed_3x[] = { + 0x00, 0x00, 0x1a, 0x76, 0x78, 0x9c, 0x63, 0xb0, 0xdf, 0xb4, 0xad, 0x62, + 0xce, 0xdb, 0x3b, 0x0b, 0xf3, 0x26, 0x27, 0x4a, 0xb4, 0x3d, 0x34, 0x5b, + 0xed, 0xb4, 0x41, 0xf1, 0xc0, 0x99, 0x2f, 0x02, 0x05, 0x67, 0x26, 0x88, + 0x6c, 0x66, 0x71, 0x34, 0x62, 0x9c, 0x75, 0x26, 0xb1, 0xa0, 0xe5, 0xcc, + 0xda, 0x94, 0x83, 0xc9, 0x05, 0x73, 0x0e, 0x3c, 0x39, 0xc2, 0xc7, 0xd0, + 0xae, 0x38, 0x53, 0x7b, 0x87, 0xdc, 0x01, 0x91, 0x45, 0x59, 0x4f, 0xda, + 0xbf, 0xca, 0xcc, 0x52, 0xdb, 0xbb, 0xde, 0xbb, 0xf6, 0xd3, 0x55, 0xff, + 0x7d, 0x77, 0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xe9, 0xbf, 0x35, 0x13, 0xca, 0x8c, 0x75, 0xec, 0xec, 0xa4, 0x2f, + 0x7e, 0x2d, 0xf9, 0xf3, 0xf0, 0xee, 0xea, 0xd5, 0xf5, 0xd3, 0x14, 0x57, + 0x06, 0x00, 0x00, 0xb9, 0x1e, 0x35, 0xce + }; + + constexpr qint64 GiB = 1024LL * 1024 * 1024; + + if constexpr (sizeof(qsizetype) == sizeof(int)) { + QSKIP("This is a 64-bit-only test."); + } else { + + // 1st + auto c = ::qUncompress(std::data(compressed_3x), qsizetype(std::size(compressed_3x))); + QVERIFY(!c.isNull()); // check for decompression error + + // 2nd + c = ::qUncompress(c); + QVERIFY(!c.isNull()); + + // 3rd + try { + c = ::qUncompress(c); + if (c.isNull()) // this step (~18MiB -> 4GiB) might have run out of memory + QSKIP("Failed to allocate enough memory."); + } catch (const std::bad_alloc &) { + QSKIP("Failed to allocate enough memory."); + } + + QCOMPARE(c.size(), 4 * GiB + 1); + QCOMPARE(std::string_view{c}.find_first_not_of('X'), + std::string_view::npos); + + // re-compress once + // (produces 18MiB, we shouldn't use much more than that in allocated capacity) + c = ::qCompress(c); + QVERIFY(!c.isNull()); + + // and un-compress again, to make sure compression worked (we + // can't compare with compressed_3x, because zlib may change): + c = ::qUncompress(c); + + QCOMPARE(c.size(), 4 * GiB + 1); + QCOMPARE(std::string_view{c}.find_first_not_of('X'), + std::string_view::npos); + } +} + void tst_QByteArray::qCompressionZeroTermination() { QString s = "Hello, I'm a string."; |